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 ] ;
: 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? ;
! 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*
")" 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>> ;