struct-arrays: remove support for arrays of old-style structs

db4
Slava Pestov 2009-09-01 14:46:24 -05:00
parent 2037667473
commit 7bdd819d51
2 changed files with 23 additions and 25 deletions

View File

@ -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." } ;
HELP: <struct-array>
{ $values { "length" integer } { "c-type" string } { "struct-array" struct-array } }
{ $description "Creates a new array for holding values of the specified C type." } ;
{ $values { "length" integer } { "struct-class" struct-class } { "struct-array" struct-array } }
{ $description "Creates a new array for holding values of the specified struct type." } ;
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" } "." } ;
HELP: struct-array-on

View File

@ -5,9 +5,6 @@ classes classes.struct kernel libc math parser sequences
sequences.private words fry memoize compiler.units ;
IN: struct-arrays
: c-type-struct-class ( c-type -- class )
c-type boxed-class>> ; foldable
TUPLE: struct-array
{ underlying c-ptr read-only }
{ length array-capacity read-only }
@ -15,35 +12,36 @@ TUPLE: struct-array
{ class read-only }
{ ctor read-only } ;
M: struct-array length length>> ; inline
M: struct-array byte-length [ length>> ] [ element-size>> ] bi * ; inline
<PRIVATE
: (nth-ptr) ( i struct-array -- alien )
[ 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
[ (nth-ptr) ] [ ctor>> ] bi execute( alien -- object ) ; inline
M: struct-array set-nth-unsafe
[ (nth-ptr) swap ] [ element-size>> ] bi memcpy ; inline
: (struct-element-constructor) ( c-type -- word )
[
"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 ]
: <direct-struct-array> ( alien length struct-class -- struct-array )
[ heap-size ] [ ] [ struct-element-constructor ]
tri struct-array boa ; inline
M: struct-array new-sequence