]> gitweb.factorcode.org Git - factor.git/commitdiff
prettyprint ENUM: definitions
authorJoe Groff <arcata@gmail.com>
Tue, 13 Apr 2010 07:13:18 +0000 (00:13 -0700)
committerErik Charlebois <erikcharlebois@gmail.com>
Tue, 20 Apr 2010 03:07:18 +0000 (20:07 -0700)
basis/alien/enums/enums.factor
basis/alien/prettyprint/prettyprint.factor

index 7cef34369d93ea5ee89066b31200b330ead9875c..bd508df07537e41f43080f0ea089c239778f6acd 100644 (file)
@@ -8,8 +8,10 @@ TUPLE: enum-c-type base-type members ;
 CONSULT: c-type-protocol enum-c-type
     base-type>> ;
 
+<PRIVATE
 : map-to-case ( quot: ( x -- y ) -- case )
     { } map-as [ ] suffix ; inline
+PRIVATE>
 
 : enum-unboxer ( members -- quot )
     [ first2 '[ _ ] 2array ] map-to-case '[ _ case ] ;
@@ -36,3 +38,5 @@ PRIVATE>
 : define-enum ( word base-type members -- )
     [ define-enum-members ] [ <enum-c-type> swap typedef ] bi ;
 
+PREDICATE: enum-c-type-word < c-type-word
+    "c-type" word-prop enum-c-type? ;
index c47dafbfce05f46b8f0ffe83320e3f4770044ca4..8ba1328dcd793e22dc8e550a43384d3fb48dc6ec 100644 (file)
@@ -1,9 +1,10 @@
 ! Copyright (C) 2008 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: accessors kernel combinators alien alien.strings alien.c-types
-alien.parser alien.syntax arrays assocs effects math.parser
-prettyprint.backend prettyprint.custom prettyprint.sections
-definitions see see.private sequences strings words ;
+USING: accessors kernel combinators alien alien.enums
+alien.strings alien.c-types alien.parser alien.syntax arrays
+assocs effects math.parser prettyprint.backend prettyprint.custom
+prettyprint.sections definitions see see.private sequences
+strings words ;
 IN: alien.prettyprint
 
 M: alien pprint*
@@ -110,3 +111,15 @@ M: alien-callback-type-word synopsis*
             ")" text block>
         ]
     } cleave ;
+
+M: enum-c-type-word definer
+    drop \ ENUM: \ ; ;
+M: enum-c-type-word synopsis*
+    {
+        [ seeing-word ]
+        [ definer. ]
+        [ pprint-word ]
+        [ c-type base-type>> dup int eq? [ drop ] [ "<" text pprint-word ] if ]
+    } cleave ;
+M: enum-c-type-word definition
+    c-type members>> ;