Merge branch 'master' of git://factorcode.org/git/factor

db4
Slava Pestov 2009-08-27 00:06:30 -05:00
commit 1f58ca9e2a
3 changed files with 16 additions and 2 deletions
basis

View File

@ -65,3 +65,6 @@ M: struct-type stack-size
: offset-of ( field struct -- offset )
c-types get at fields>>
[ name>> = ] with find nip offset>> ;
USE: vocabs.loader
"struct-arrays" require

View File

@ -5,7 +5,8 @@ destructors io.encodings.utf8 io.pathnames io.streams.string
kernel libc literals math multiline namespaces prettyprint
prettyprint.config see sequences specialized-arrays.ushort
system tools.test compiler.tree.debugger struct-arrays
classes.tuple.private specialized-arrays.direct.int ;
classes.tuple.private specialized-arrays.direct.int
compiler.units ;
IN: classes.struct.tests
<<
@ -22,6 +23,11 @@ IN: classes.struct.tests
"f-stdcall" libfactor-ffi-tests-path "stdcall" add-library
>>
SYMBOL: struct-test-empty
[ [ struct-test-empty { } define-struct-class ] with-compilation-unit ]
[ struct-must-have-slots? ] must-fail-with
STRUCT: struct-test-foo
{ x char }
{ y int initial: 123 }

View File

@ -12,6 +12,8 @@ IN: classes.struct
! struct class
ERROR: struct-must-have-slots ;
TUPLE: struct
{ (underlying) c-ptr read-only } ;
@ -207,7 +209,10 @@ M: struct-class heap-size
[ c-type>> c-type drop ] each ;
: (define-struct-class) ( class slots offsets-quot -- )
[ drop struct f define-tuple-class ]
[
[ struct-must-have-slots ]
[ drop struct f define-tuple-class ] if-empty
]
swap '[
make-slots dup
[ check-struct-slots ] _ [ struct-align [ align ] keep ] tri