]> gitweb.factorcode.org Git - factor.git/blobdiff - basis/alien/enums/enums.factor
Remove ENUM: f and replace uses with CONSTANTs.
[factor.git] / basis / alien / enums / enums.factor
index 7cef34369d93ea5ee89066b31200b330ead9875c..97b694f890ba58f87d2a227d52a77ed5dc0f47af 100644 (file)
@@ -1,6 +1,6 @@
 ! (c)2010 Joe Groff bsd license
 USING: accessors alien.c-types arrays combinators delegate fry
-kernel quotations sequences words.symbol ;
+kernel quotations sequences words.symbol words ;
 IN: alien.enums
 
 TUPLE: enum-c-type base-type members ;
@@ -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 ] ;
@@ -26,6 +28,12 @@ M: enum-c-type c-type-setter
 
 C: <enum-c-type> enum-c-type
 
+: enum>int ( enum enum-c-type -- int )
+    c-type-unboxer-quot call( x -- y ) ; inline
+
+: int>enum ( int enum-c-type -- enum )
+    c-type-boxer-quot call( x -- y ) ; inline
+
 <PRIVATE
 
 : define-enum-members ( member-names -- )
@@ -36,3 +44,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? ;