implement clone on struct classes to copy the struct contents

db4
Joe Groff 2009-08-29 22:54:56 -05:00
parent 4d8ed23db5
commit 20aa00f8df
2 changed files with 6 additions and 1 deletions

View File

@ -1,5 +1,5 @@
! (c)Joe Groff bsd license
USING: accessors alien.c-types alien.libraries
USING: accessors alien alien.c-types alien.libraries
alien.structs.fields alien.syntax ascii classes.struct combinators
destructors io.encodings.utf8 io.pathnames io.streams.string
kernel libc literals math multiline namespaces prettyprint
@ -203,3 +203,5 @@ STRUCT: struct-test-optimization
] unit-test
[ f ] [ [ memory>struct y>> ] { memory>struct y>> } inlined? ] unit-test
[ f ] [ struct-test-foo <struct> dup clone [ >c-ptr ] bi@ eq? ] unit-test

View File

@ -46,6 +46,9 @@ M: struct equal?
dup struct-class? [ '[ _ boa ] ] [ drop f ] if
] 1 define-partial-eval
M: struct clone
[ >c-ptr ] [ byte-length memory>byte-array ] [ class memory>struct ] tri ;
: (init-struct) ( class with-prototype: ( prototype -- alien ) sans-prototype: ( class -- alien ) -- alien )
'[ dup struct-prototype _ _ ?if ] keep memory>struct ; inline