]> gitweb.factorcode.org Git - factor.git/commitdiff
literal syntax for struct-arrays
authorJoe Groff <arcata@gmail.com>
Wed, 26 Aug 2009 23:09:02 +0000 (18:09 -0500)
committerJoe Groff <arcata@gmail.com>
Wed, 26 Aug 2009 23:09:02 +0000 (18:09 -0500)
basis/struct-arrays/prettyprint/prettyprint.factor [new file with mode: 0644]
basis/struct-arrays/struct-arrays-tests.factor
basis/struct-arrays/struct-arrays.factor

diff --git a/basis/struct-arrays/prettyprint/prettyprint.factor b/basis/struct-arrays/prettyprint/prettyprint.factor
new file mode 100644 (file)
index 0000000..b0de966
--- /dev/null
@@ -0,0 +1,2 @@
+USING: struct-arrays ;
+IN: struct-arrays.prettyprint
index f4da63544c961fa7031d7d386a51887b8100f07c..64639c7ca1edfb836bcd40d5592e8ad789c78856 100755 (executable)
@@ -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
index 4243f314d71cb7e31ea174013488c85cb32092b4..c8a1f5f8024f46405738649b0e7d6f0e42526d85 100755 (executable)
@@ -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