]> gitweb.factorcode.org Git - factor.git/commitdiff
classes.struct: adding a read-struct word.
authorJohn Benediktsson <mrjbq7@gmail.com>
Wed, 18 Apr 2012 23:00:29 +0000 (16:00 -0700)
committerJohn Benediktsson <mrjbq7@gmail.com>
Wed, 18 Apr 2012 23:00:29 +0000 (16:00 -0700)
basis/classes/struct/struct.factor

index db65ecab3a0f65446c8326fcfc5ebb7703d15d2e..84e1dacc36239b0b83febe16123ca4c7d1648dec 100644 (file)
@@ -5,7 +5,7 @@ USING: accessors alien alien.c-types alien.data alien.parser
 arrays byte-arrays classes classes.parser classes.private
 classes.struct.bit-accessors classes.tuple classes.tuple.parser
 combinators combinators.smart cpu.architecture definitions fry
-functors.backend generalizations generic generic.parser kernel
+functors.backend generalizations generic generic.parser io kernel
 kernel.private lexer libc locals macros math math.order parser
 quotations sequences slots slots.private specialized-arrays
 stack-checker.dependencies summary vectors vocabs.loader
@@ -71,6 +71,9 @@ M: struct hashcode*
     ! optimized down to efficient code if it is.
     '[ _ boa ] call( ptr -- struct ) ; inline
 
+: read-struct ( class -- struct )
+    [ heap-size read ] [ memory>struct ] bi ;
+
 <PRIVATE
 : (init-struct) ( class with-prototype: ( prototype -- alien ) sans-prototype: ( class -- alien ) -- alien )
     '[ dup struct-prototype _ _ ?if ] keep memory>struct ; inline