diff --git a/module/language/c99/compiler.mes b/module/language/c99/compiler.mes index cb426fa0..13b0f8d1 100644 --- a/module/language/c99/compiler.mes +++ b/module/language/c99/compiler.mes @@ -89,20 +89,33 @@ ((fctn-defn _ (ptr-declr (pointer) (ftn-declr (ident ,name) _)) (compd-stmt (block-item-list . ,statements))) statements))) (define ') +(define ') +(define ') (define ') (define ') (define ') (define ') (define ') -(define* (make o #:key (functions '()) (globals '()) (locals '()) (function #f) (text '())) + +(define* (make o #:key (types '()) (constants '()) (functions '()) (globals '()) (locals '()) (function #f) (text '())) (pmatch o ( (list + (cons types) + (cons constants) (cons functions) (cons globals) (cons locals) (cons function) (cons text))))) +(define (.types o) + (pmatch o + (( . ,alist) (assq-ref alist )))) + +(define (.constants o) + (pmatch o + (( . ,alist) (assq-ref alist )))) + (define (.functions o) (pmatch o (( . ,alist) (assq-ref alist )))) @@ -128,19 +141,23 @@ (define (clone o . rest) (cond ((info? o) - (let ((functions (.functions o)) + (let ((types (.types o)) + (constants (.constants o)) + (functions (.functions o)) (globals (.globals o)) (locals (.locals o)) (function (.function o)) (text (.text o))) (let-keywords rest #f - ((functions functions) + ((types types) + (constants constants) + (functions functions) (globals globals) (locals locals) (function function) (text text)) - (make #:functions functions #:globals globals #:locals locals #:function function #:text text)))))) + (make #:types types #:constants constants #:functions functions #:globals globals #:locals locals #:function function #:text text)))))) (define (push-global-ref globals) (lambda (o) @@ -258,6 +275,12 @@ (define (ident->global name value) (cons name (int->bv32 value))) +(define (ident->constant name value) + (cons name value)) + +(define (ident->type name value) + (cons name value)) + (define (expr->global o) (pmatch o ((p-expr (string ,string)) (string->global string)) @@ -863,6 +886,13 @@ (append (.text info) ((accu->ident info) name)))))) + ;; enum + ((decl (decl-spec-list (type-spec (enum-def (ident ,name) (enum-def-list . ,fields))))) + (let ((type (ident->type name "enum")) + (constants (map ident->constant (map cadadr fields) (iota (length fields))))) + (clone info #:types (append (.types info) (list type)) + #:constants (append constants (.constants info))))) + ;; i = 0; ((expr-stmt (assn-expr (p-expr (ident ,name)) (op _) (p-expr (fixed ,value)))) ;;(stderr "RET LOCAL[~a]: ~a\n" name (assoc-ref locals name))