]> gitweb.factorcode.org Git - factor.git/blobdiff - basis/alien/parser/parser.factor
alien.enums: allow enum members to be given values based on other enum symbols' values
[factor.git] / basis / alien / parser / parser.factor
index 332683a0ac02218a9400b0463ac0b16eb3dc24d3..baca25e07836896904fb678f4a48a1e6075627db 100755 (executable)
@@ -4,7 +4,7 @@ USING: accessors alien alien.c-types alien.libraries arrays
 assocs classes combinators combinators.short-circuit
 compiler.units effects grouping kernel parser sequences
 splitting words fry locals lexer namespaces summary math
-vocabs.parser words.constant ;
+vocabs.parser words.constant alien.enums ;
 IN: alien.parser
 
 SYMBOL: current-library
@@ -75,8 +75,12 @@ M: pointer return-type-name to>> return-type-name CHAR: * suffix ;
     "*" ?head
     [ [ <pointer> ] dip parse-pointers ] when ;
 
+: define-enum-value ( class value -- )
+    enum>number "enum-value" set-word-prop ;
+
 : next-enum-member ( members name value -- members value' )
-    [ 2array suffix! ] [ 1 + ] bi ;
+    [ define-enum-value ]
+    [ [ 2array suffix! ] [ enum>number 1 + ] bi ] 2bi ;
 
 : parse-enum-name ( -- name )
     scan (CREATE-C-TYPE) dup save-location ;