From 2d66dc9f297747b4cc94b9bbf6564239025c921e Mon Sep 17 00:00:00 2001 From: Joe Groff Date: Wed, 26 Aug 2009 18:09:02 -0500 Subject: [PATCH] literal syntax for struct-arrays --- basis/struct-arrays/prettyprint/prettyprint.factor | 2 ++ basis/struct-arrays/struct-arrays-tests.factor | 8 +++++++- basis/struct-arrays/struct-arrays.factor | 12 +++++++++++- 3 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 basis/struct-arrays/prettyprint/prettyprint.factor diff --git a/basis/struct-arrays/prettyprint/prettyprint.factor b/basis/struct-arrays/prettyprint/prettyprint.factor new file mode 100644 index 0000000000..b0de966adb --- /dev/null +++ b/basis/struct-arrays/prettyprint/prettyprint.factor @@ -0,0 +1,2 @@ +USING: struct-arrays ; +IN: struct-arrays.prettyprint diff --git a/basis/struct-arrays/struct-arrays-tests.factor b/basis/struct-arrays/struct-arrays-tests.factor index f4da63544c..64639c7ca1 100755 --- a/basis/struct-arrays/struct-arrays-tests.factor +++ b/basis/struct-arrays/struct-arrays-tests.factor @@ -37,4 +37,10 @@ STRUCT: test-struct-array [ 15 ] [ 15 10 test-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 diff --git a/basis/struct-arrays/struct-arrays.factor b/basis/struct-arrays/struct-arrays.factor index 4243f314d7..c8a1f5f802 100755 --- a/basis/struct-arrays/struct-arrays.factor +++ b/basis/struct-arrays/struct-arrays.factor @@ -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 ( alien len c-type -- array ) [ execute( alien len -- array ) ] [ ] ?if ; inline +: >struct-array ( sequence class -- struct-array ) + [ dup length ] dip + [ 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