literal syntax for struct-arrays

db4
Joe Groff 2009-08-26 18:09:02 -05:00
parent f4c90fdabe
commit 2d66dc9f29
3 changed files with 20 additions and 2 deletions

View File

@ -0,0 +1,2 @@
USING: struct-arrays ;
IN: struct-arrays.prettyprint

View File

@ -37,4 +37,10 @@ STRUCT: test-struct-array
[ 15 ] [ 15 10 test-struct-array <struct-array> resize length ] unit-test
[ S{ test-struct-array f 12 20 } ] [
struct-array{ test-struct-array
S{ test-struct-array f 4 20 }
S{ test-struct-array f 12 20 }
S{ test-struct-array f 20 20 }
} second
] unit-test

View File

@ -1,7 +1,7 @@
! Copyright (C) 2008 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
USING: accessors alien alien.c-types alien.structs byte-arrays
classes.struct kernel libc math sequences sequences.private ;
classes.struct kernel libc math parser sequences sequences.private ;
IN: struct-arrays
: c-type-struct-class ( c-type -- class )
@ -64,3 +64,13 @@ M: struct-type <c-type-direct-array> ( alien len c-type -- array )
[ execute( alien len -- array ) ]
[ <direct-struct-array> ] ?if ; inline
: >struct-array ( sequence class -- struct-array )
[ dup length ] dip <struct-array>
[ 0 swap copy ] keep ; inline
SYNTAX: struct-array{
\ } scan-word [ >struct-array ] curry parse-literal ;
USING: vocabs vocabs.loader ;
"prettyprint" vocab [ "struct-arrays.prettyprint" require ] when