 ! (c)2010 Joe Groff, Erik Charlebois bsd license
 USING: accessors alien.c-types arrays combinators delegate fry
-generic.parser kernel macros math parser sequences words words.symbol ;
+generic.parser kernel macros math parser sequences words words.symbol
+classes.singleton assocs ;
 IN: alien.enums
 
 <PRIVATE


: define-enum ( word base-type members -- )
    [ dup define-enum-constructor ] 2dip
    dup define-enum-members
    <enum-c-type> swap typedef ;
    
PREDICATE: enum-c-type-word < c-type-word
    "c-type" word-prop enum-c-type? ;

: define-enum-value ( class value -- )
    "enum-value" set-word-prop ;

: define-enum-members ( members -- )
    [
        [ drop define-singleton-class ]
        [ define-enum-value ] 2bi
    ] assoc-each ;

: define-enum-constructor ( word -- )
    [ name>> "<" ">" surround create-in ] keep
