struct-arrays: remove support for arrays of old-style structs
parent
2037667473
commit
7bdd819d51
|
@ -7,11 +7,11 @@ $nl
|
||||||
"The " { $slot "underlying" } " slot holds a " { $link c-ptr } " with the raw data. This pointer can be passed to C functions." } ;
|
"The " { $slot "underlying" } " slot holds a " { $link c-ptr } " with the raw data. This pointer can be passed to C functions." } ;
|
||||||
|
|
||||||
HELP: <struct-array>
|
HELP: <struct-array>
|
||||||
{ $values { "length" integer } { "c-type" string } { "struct-array" struct-array } }
|
{ $values { "length" integer } { "struct-class" struct-class } { "struct-array" struct-array } }
|
||||||
{ $description "Creates a new array for holding values of the specified C type." } ;
|
{ $description "Creates a new array for holding values of the specified struct type." } ;
|
||||||
|
|
||||||
HELP: <direct-struct-array>
|
HELP: <direct-struct-array>
|
||||||
{ $values { "alien" c-ptr } { "length" integer } { "c-type" string } { "struct-array" struct-array } }
|
{ $values { "alien" c-ptr } { "length" integer } { "struct-class" struct-class } { "struct-array" struct-array } }
|
||||||
{ $description "Creates a new array for holding values of the specified C type, backed by the memory at " { $snippet "alien" } "." } ;
|
{ $description "Creates a new array for holding values of the specified C type, backed by the memory at " { $snippet "alien" } "." } ;
|
||||||
|
|
||||||
HELP: struct-array-on
|
HELP: struct-array-on
|
||||||
|
|
|
@ -5,9 +5,6 @@ classes classes.struct kernel libc math parser sequences
|
||||||
sequences.private words fry memoize compiler.units ;
|
sequences.private words fry memoize compiler.units ;
|
||||||
IN: struct-arrays
|
IN: struct-arrays
|
||||||
|
|
||||||
: c-type-struct-class ( c-type -- class )
|
|
||||||
c-type boxed-class>> ; foldable
|
|
||||||
|
|
||||||
TUPLE: struct-array
|
TUPLE: struct-array
|
||||||
{ underlying c-ptr read-only }
|
{ underlying c-ptr read-only }
|
||||||
{ length array-capacity read-only }
|
{ length array-capacity read-only }
|
||||||
|
@ -15,35 +12,36 @@ TUPLE: struct-array
|
||||||
{ class read-only }
|
{ class read-only }
|
||||||
{ ctor read-only } ;
|
{ ctor read-only } ;
|
||||||
|
|
||||||
M: struct-array length length>> ; inline
|
<PRIVATE
|
||||||
M: struct-array byte-length [ length>> ] [ element-size>> ] bi * ; inline
|
|
||||||
|
|
||||||
: (nth-ptr) ( i struct-array -- alien )
|
: (nth-ptr) ( i struct-array -- alien )
|
||||||
[ element-size>> * >fixnum ] [ underlying>> ] bi <displaced-alien> ; inline
|
[ element-size>> * >fixnum ] [ underlying>> ] bi <displaced-alien> ; inline
|
||||||
|
|
||||||
|
: (struct-element-constructor) ( struct-class -- word )
|
||||||
|
[
|
||||||
|
"struct-array-ctor" f <word>
|
||||||
|
[ swap '[ _ memory>struct ] (( alien -- object )) define-inline ] keep
|
||||||
|
] with-compilation-unit ;
|
||||||
|
|
||||||
|
! Foldable memo word. This is an optimization; by precompiling a
|
||||||
|
! constructor for array elements, we avoid memory>struct's slow path.
|
||||||
|
MEMO: struct-element-constructor ( struct-class -- word )
|
||||||
|
(struct-element-constructor) ; foldable
|
||||||
|
|
||||||
|
PRIVATE>
|
||||||
|
|
||||||
|
M: struct-array length length>> ; inline
|
||||||
|
|
||||||
|
M: struct-array byte-length [ length>> ] [ element-size>> ] bi * ; inline
|
||||||
|
|
||||||
M: struct-array nth-unsafe
|
M: struct-array nth-unsafe
|
||||||
[ (nth-ptr) ] [ ctor>> ] bi execute( alien -- object ) ; inline
|
[ (nth-ptr) ] [ ctor>> ] bi execute( alien -- object ) ; inline
|
||||||
|
|
||||||
M: struct-array set-nth-unsafe
|
M: struct-array set-nth-unsafe
|
||||||
[ (nth-ptr) swap ] [ element-size>> ] bi memcpy ; inline
|
[ (nth-ptr) swap ] [ element-size>> ] bi memcpy ; inline
|
||||||
|
|
||||||
: (struct-element-constructor) ( c-type -- word )
|
: <direct-struct-array> ( alien length struct-class -- struct-array )
|
||||||
[
|
[ heap-size ] [ ] [ struct-element-constructor ]
|
||||||
"struct-array-ctor" f <word>
|
|
||||||
[
|
|
||||||
swap dup struct-class?
|
|
||||||
[ '[ _ memory>struct ] [ ] like ] [ drop [ ] ] if
|
|
||||||
(( alien -- object )) define-inline
|
|
||||||
] keep
|
|
||||||
] with-compilation-unit ;
|
|
||||||
|
|
||||||
! Foldable memo word. This is an optimization; by precompiling a
|
|
||||||
! constructor for array elements, we avoid memory>struct's slow path.
|
|
||||||
MEMO: struct-element-constructor ( c-type -- word )
|
|
||||||
(struct-element-constructor) ; foldable
|
|
||||||
|
|
||||||
: <direct-struct-array> ( alien length c-type -- struct-array )
|
|
||||||
[ heap-size ] [ c-type-struct-class ] [ struct-element-constructor ]
|
|
||||||
tri struct-array boa ; inline
|
tri struct-array boa ; inline
|
||||||
|
|
||||||
M: struct-array new-sequence
|
M: struct-array new-sequence
|
||||||
|
|
Loading…
Reference in New Issue