struct-vectors: update unit test to use new structs
parent
7bdd819d51
commit
1efcf36083
|
@ -1,11 +1,11 @@
|
|||
IN: struct-vectors
|
||||
USING: help.markup help.syntax alien strings math ;
|
||||
USING: help.markup help.syntax classes.struct alien strings math ;
|
||||
|
||||
HELP: struct-vector
|
||||
{ $class-description "The class of growable C struct and union arrays." } ;
|
||||
|
||||
HELP: <struct-vector>
|
||||
{ $values { "capacity" integer } { "c-type" string } { "struct-vector" struct-vector } }
|
||||
{ $values { "capacity" integer } { "struct-class" struct-class } { "struct-vector" struct-vector } }
|
||||
{ $description "Creates a new vector with the given initial capacity." } ;
|
||||
|
||||
ARTICLE: "struct-vectors" "C struct and union vectors"
|
||||
|
|
|
@ -1,21 +1,16 @@
|
|||
IN: struct-vectors.tests
|
||||
USING: struct-vectors tools.test alien.c-types alien.syntax
|
||||
USING: struct-vectors tools.test alien.c-types classes.struct accessors
|
||||
namespaces kernel sequences ;
|
||||
|
||||
C-STRUCT: point
|
||||
{ "float" "x" }
|
||||
{ "float" "y" } ;
|
||||
STRUCT: point { x float } { y float } ;
|
||||
|
||||
: make-point ( x y -- point )
|
||||
"point" <c-object>
|
||||
[ set-point-y ] keep
|
||||
[ set-point-x ] keep ;
|
||||
: make-point ( x y -- point ) point <struct-boa> ;
|
||||
|
||||
[ ] [ 1 "point" <struct-vector> "v" set ] unit-test
|
||||
[ ] [ 1 point <struct-vector> "v" set ] unit-test
|
||||
|
||||
[ 1.5 6.0 ] [
|
||||
1.0 2.0 make-point "v" get push
|
||||
3.0 4.5 make-point "v" get push
|
||||
1.5 6.0 make-point "v" get push
|
||||
"v" get pop [ point-x ] [ point-y ] bi
|
||||
"v" get pop [ x>> ] [ y>> ] bi
|
||||
] unit-test
|
|
@ -9,10 +9,11 @@ TUPLE: struct-vector
|
|||
{ length array-capacity }
|
||||
{ c-type read-only } ;
|
||||
|
||||
: <struct-vector> ( capacity c-type -- struct-vector )
|
||||
: <struct-vector> ( capacity struct-class -- struct-vector )
|
||||
[ <struct-array> 0 ] keep struct-vector boa ; inline
|
||||
|
||||
M: struct-vector byte-length underlying>> byte-length ;
|
||||
|
||||
M: struct-vector new-sequence
|
||||
[ c-type>> <struct-array> ] [ [ >fixnum ] [ c-type>> ] bi* ] 2bi
|
||||
struct-vector boa ;
|
||||
|
|
Loading…
Reference in New Issue