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