get classes.struct tests passing
parent
4896d6b9a3
commit
4461a63e1d
|
@ -1,5 +1,6 @@
|
|||
USING: classes.struct tools.test ;
|
||||
IN: classes.struct.test
|
||||
USING: accessors alien.c-types classes.c-types classes.struct
|
||||
combinators kernel tools.test ;
|
||||
IN: classes.struct.tests
|
||||
|
||||
STRUCT: foo
|
||||
{ x char }
|
||||
|
@ -14,3 +15,13 @@ STRUCT: bar
|
|||
[ 16 ] [ bar heap-size ] unit-test
|
||||
[ 123 ] [ foo new y>> ] unit-test
|
||||
[ 123 ] [ bar new foo>> y>> ] unit-test
|
||||
|
||||
[ 1 2 3 t ] [
|
||||
1 2 3 t foo boa bar boa
|
||||
{
|
||||
[ w>> ]
|
||||
[ foo>> x>> ]
|
||||
[ foo>> y>> ]
|
||||
[ foo>> z>> ]
|
||||
} cleave
|
||||
] unit-test
|
||||
|
|
|
@ -22,7 +22,7 @@ M: struct >c-ptr
|
|||
|
||||
: memory>struct ( ptr class -- struct )
|
||||
over c-ptr? [ swap \ c-ptr bad-slot-value ] unless
|
||||
tuple-layout <tuple-boa> ; inline
|
||||
tuple-layout <tuple> [ 2 set-slot ] keep ;
|
||||
|
||||
: malloc-struct ( class -- struct )
|
||||
[ heap-size malloc ] keep memory>struct ; inline
|
||||
|
@ -100,7 +100,7 @@ M: struct-class heap-size
|
|||
|
||||
: struct-prototype ( class -- prototype )
|
||||
[ heap-size <byte-array> ]
|
||||
[ tuple-layout <tuple> [ 2 set-slot ] keep ]
|
||||
[ memory>struct ]
|
||||
[ "struct-slots" word-prop ] tri
|
||||
[
|
||||
[ initial>> ]
|
||||
|
@ -122,7 +122,7 @@ M: struct-class heap-size
|
|||
: define-struct-class ( class slots -- )
|
||||
[ drop struct f define-tuple-class ] [
|
||||
make-slots dup
|
||||
[ check-struct-slots ] [ struct-offsets ] [ struct-align ] tri
|
||||
[ check-struct-slots ] [ struct-offsets ] [ struct-align [ align ] keep ] tri
|
||||
(define-struct-class)
|
||||
] [ drop dup struct-prototype "prototype" set-word-prop ] 2tri ;
|
||||
|
||||
|
|
Loading…
Reference in New Issue