M: struct equal?
over struct? [
- 2dup [ class-of ] bi@ = [
+ 2dup [ class-of ] same? [
2dup [ >c-ptr ] both?
[ [ >c-ptr ] [ binary-object ] bi* memory= ]
[ [ >c-ptr not ] both? ]
drop [ >c-ptr ] ;
MACRO: read-struct-slot ( slot -- )
- dup type>> depends-on-c-type
+ dup type>> add-depends-on-c-type
(reader-quot) ;
MACRO: write-struct-slot ( slot -- )
- dup type>> depends-on-c-type
+ dup type>> add-depends-on-c-type
(writer-quot) ;
PRIVATE>
1 [ 0 >>offset type>> heap-size max ] reduce ;
: struct-alignment ( slots -- align )
- [ struct-bit-slot-spec? not ] filter
+ [ struct-bit-slot-spec? ] reject
1 [ dup offset>> c-type-align-at max ] reduce ;
PRIVATE>
-M: struct byte-length class-of "struct-size" word-prop ; foldable
+: struct-size ( class -- n ) "struct-size" word-prop ; inline
+
+M: struct byte-length class-of struct-size ; inline foldable
M: struct binary-zero? binary-object uchar <c-direct-array> [ 0 = ] all? ; inline
! class definition
<PRIVATE
-ERROR: bad-type-for-bits type ;
-
:: set-bits ( slot-spec n -- slot-spec )
struct-bit-slot-spec new
n >>bits
- slot-spec type>> {
- { int [ t ] }
- { uint [ f ] }
- [ bad-type-for-bits ]
- } case >>signed?
+ slot-spec type>> c-type-signed >>signed?
slot-spec name>> >>name
slot-spec class>> >>class
slot-spec type>> >>type