prettyprint ENUM: definitions

db4
Joe Groff 2010-04-13 00:13:18 -07:00 committed by Erik Charlebois
parent d3f770d545
commit 52903ee597
2 changed files with 21 additions and 4 deletions

View 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? ;

View 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>> ;