{ foo struct-test-foo } ;
[ 12 ] [ struct-test-foo heap-size ] unit-test
+[ 12 ] [ struct-test-foo <struct> byte-length ] unit-test
[ 16 ] [ struct-test-bar heap-size ] unit-test
[ 123 ] [ struct-test-foo <struct> y>> ] unit-test
[ 123 ] [ struct-test-bar <struct> foo>> y>> ] unit-test
[ \ struct-slot-values create-method-in ]
[ struct-slot-values-quot ] bi define ;
+: (define-byte-length-method) ( class -- )
+ [ \ byte-length create-method-in ]
+ [ heap-size \ drop swap [ ] 2sequence ] bi define ;
+
! Struct as c-type
: slot>field ( slot -- field )
over [ swapd [ call( value struct -- ) ] curry keep ] [ 2drop ] if
] each ;
+: (struct-methods) ( class -- )
+ [ (define-struct-slot-values-method) ]
+ [ (define-byte-length-method) ] bi ;
+
: (struct-word-props) ( class slots size align -- )
[
[ "struct-slots" set-word-prop ]
[ "struct-align" set-word-prop ] tri-curry*
[ tri ] 3curry
[ dup struct-prototype "prototype" set-word-prop ]
- [ (define-struct-slot-values-method) ] tri ;
+ [ (struct-methods) ] tri ;
: check-struct-slots ( slots -- )
[ c-type>> c-type drop ] each ;