]> gitweb.factorcode.org Git - factor.git/commitdiff
alien.*: moving the c-type-string word to the alien.c-types vocab
authorBjörn Lindqvist <bjourne@gmail.com>
Wed, 10 Aug 2016 12:26:09 +0000 (14:26 +0200)
committerBjörn Lindqvist <bjourne@gmail.com>
Wed, 10 Aug 2016 19:34:38 +0000 (21:34 +0200)
This way it can be used in alien.parser instead of return-type-name.

basis/alien/c-types/c-types-tests.factor
basis/alien/c-types/c-types.factor
basis/alien/parser/parser-tests.factor
basis/alien/parser/parser.factor
basis/alien/prettyprint/prettyprint.factor

index 04a18dbb70e8141d998e33da3e4d23f10c89925d..7abbfc4e93a3d36054faae4fa997609d1edabb43 100644 (file)
@@ -59,6 +59,23 @@ C-TYPE: opaque
 { t } [ void* lookup-c-type pointer: opaque lookup-c-type = ] unit-test
 [ opaque lookup-c-type ] [ no-c-type? ] must-fail-with
 
+! c-type-string
+{
+    "c-string[ascii]"
+    "foo*"
+    "int[5]"
+    "int**"
+    "MyFunkyString*"
+    "opaque*"
+} [
+    { c-string ascii } c-type-string
+    pointer: foo c-type-string
+    { int 5 } c-type-string
+    pointer: pointer: int c-type-string
+    pointer: MyFunkyString c-type-string
+    pointer: opaque c-type-string
+] unit-test
+
 [ "
     USING: alien.syntax ;
     IN: alien.c-types.tests
index ba7fc0e0298aaaffb92e7505b088572224f1ea64..495f3ed5d76c877f08c7c2b1e1f1048fc0ce5b07 100644 (file)
@@ -1,9 +1,9 @@
 ! Copyright (C) 2004, 2010 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: accessors alien alien.accessors arrays byte-arrays
-classes combinators compiler.units cpu.architecture delegate
-fry kernel layouts locals macros math math.order quotations
-sequences system words words.symbol summary ;
+USING: accessors alien alien.accessors arrays classes combinators
+compiler.units cpu.architecture delegate fry kernel layouts macros
+math math.order prettyprint quotations sequences summary system words
+words.symbol ;
 IN: alien.c-types
 
 SYMBOLS:
@@ -499,3 +499,19 @@ M: double-2-rep rep-component-type drop double ;
 : c-type-clamp ( value c-type -- value' )
     dup { float double } member-eq?
     [ drop ] [ c-type-interval clamp ] if ; inline
+
+GENERIC: pointer-string ( pointer -- string/f )
+M: object pointer-string drop f ;
+M: word pointer-string name>> ;
+M: pointer pointer-string to>> pointer-string [ CHAR: * suffix ] [ f ] if* ;
+
+GENERIC: c-type-string ( c-type -- string )
+
+M: word c-type-string name>> ;
+M: pointer c-type-string pointer-string ;
+M: wrapper c-type-string wrapped>> c-type-string ;
+M: array c-type-string
+    unclip
+    [ [ unparse "[" "]" surround ] map ]
+    [ c-type-string ] bi*
+    prefix concat ;
index 6fd8dc3cd7babc873b9a4a50da77b06cd0c6fed7..2b10cc48f50c9ce04f2cf088eb94378398c8a163 100644 (file)
@@ -46,11 +46,6 @@ IN: alien.parser.tests
     { "ayae" } [ parse-enum-name new-definitions get first in? ] with-parsing
 ] unit-test
 
-! return-type-name
-{ "void" } [
-    void return-type-name
-] unit-test
-
 >>
 
 TYPEDEF: char char2
index 447b082488b2babc067e79143b8c70b1e800f8bf..74103a0d9d7a3ea946e73ac52d63217ebf0ff108 100755 (executable)
@@ -71,10 +71,6 @@ ERROR: *-in-c-type-name name ;
     scan-token (CREATE-C-TYPE) ;
 
 <PRIVATE
-GENERIC: return-type-name ( type -- name )
-
-M: word return-type-name name>> ;
-M: pointer return-type-name to>> return-type-name CHAR: * suffix ;
 
 : parse-pointers ( type name -- type' name' )
     "*" ?head
@@ -122,7 +118,7 @@ PRIVATE>
     ] until drop types names [ >array ] bi@ ;
 
 : function-effect ( names return -- effect )
-    [ { } ] [ return-type-name 1array ] if-void <effect> ;
+    [ { } ] [ c-type-string 1array ] if-void <effect> ;
 
 : create-function ( name -- word )
     create-word-in dup reset-generic ;
index 48d9fcb2e0d78c68f1d331d47c70ddf93fa915ee..3417d6d1b8fd0dcd748117b91e95784cff7a2ff9 100644 (file)
@@ -2,7 +2,7 @@
 ! See http://factorcode.org/license.txt for BSD license.
 USING: accessors alien alien.c-types alien.enums alien.strings
 alien.syntax arrays assocs combinators combinators.short-circuit
-definitions effects kernel math.parser prettyprint prettyprint.backend
+definitions effects kernel math.parser prettyprint.backend
 prettyprint.custom prettyprint.sections see see.private sequences
 words ;
 IN: alien.prettyprint
@@ -21,25 +21,20 @@ M: c-type-word definition drop f ;
 M: c-type-word declarations. drop ;
 
 <PRIVATE
-GENERIC: pointer-string ( pointer -- string/f )
-M: object pointer-string drop f ;
-M: word pointer-string [ record-vocab ] [ name>> ] bi ;
-M: pointer pointer-string to>> pointer-string [ CHAR: * suffix ] [ f ] if* ;
-
-GENERIC: c-type-string ( c-type -- string )
-
-M: word c-type-string [ record-vocab ] [ name>> ] bi ;
-M: pointer c-type-string dup pointer-string [ ] [ unparse ] ?if ;
-M: wrapper c-type-string wrapped>> c-type-string ;
-M: array c-type-string
-    unclip
-    [ [ unparse "[" "]" surround ] map ]
-    [ c-type-string ] bi*
-    prefix concat ;
+GENERIC: record-pointer ( pointer -- )
+M: object record-pointer drop ;
+M: word record-pointer record-vocab ;
+M: pointer record-pointer to>> record-pointer ;
+
+GENERIC: record-c-type ( c-type -- )
+M: word record-c-type record-vocab ;
+M: pointer record-c-type record-pointer ;
+M: wrapper record-c-type wrapped>> record-c-type ;
+M: array record-c-type first record-c-type ;
 PRIVATE>
 
 : pprint-c-type ( c-type -- )
-    [ c-type-string ] keep present-text ;
+    [ record-c-type ] [ c-type-string ] [ ] tri present-text ;
 
 M: pointer pprint*
     <flow \ pointer: pprint-word to>> pprint* block> ;