From 4461a63e1d76f58f05b46d3b2f3ad1eed098cd57 Mon Sep 17 00:00:00 2001 From: Joe Groff Date: Wed, 12 Aug 2009 10:01:32 -0400 Subject: [PATCH] get classes.struct tests passing --- extra/classes/struct/struct-tests.factor | 15 +++++++++++++-- extra/classes/struct/struct.factor | 6 +++--- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/extra/classes/struct/struct-tests.factor b/extra/classes/struct/struct-tests.factor index 9d0c18feb4..6e739edb5f 100644 --- a/extra/classes/struct/struct-tests.factor +++ b/extra/classes/struct/struct-tests.factor @@ -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 diff --git a/extra/classes/struct/struct.factor b/extra/classes/struct/struct.factor index 94932f89d9..b4132c6816 100644 --- a/extra/classes/struct/struct.factor +++ b/extra/classes/struct/struct.factor @@ -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 ; inline + tuple-layout [ 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 ] - [ tuple-layout [ 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 ;