diff --git a/module/language/c99/compiler.mes b/module/language/c99/compiler.mes index ae7369c4..0bc82582 100644 --- a/module/language/c99/compiler.mes +++ b/module/language/c99/compiler.mes @@ -1776,24 +1776,20 @@ (int->bv32 (+ d (data-offset ,value g))) (list-tail data (+ here 4)))))))))))) - ;; enum + ;; enum foo { }; ((decl (decl-spec-list (type-spec (enum-def (ident ,name) (enum-def-list . ,fields))))) (let ((type (enum->type name fields)) - (constants (let loop ((fields fields) (i 0) (constants constants)) - (if (null? fields) constants - (let* ((field (car fields)) - (name (pmatch field - ((enum-defn (ident ,name) . _) name))) - (i (pmatch field - ((enum-defn ,name (p-expr (fixed ,value))) (cstring->number value)) - ((enum-defn ,name) i)))) - (loop (cdr fields) - (1+ i) - (append constants (list (ident->constant name i))))))))) + (constants (enum-def-list->constants constants fields))) (clone info #:types (append (.types info) (list type)) #:constants (append constants (.constants info))))) + ;; enum {}; + ((decl (decl-spec-list (type-spec (enum-def (enum-def-list . ,fields))))) + (let ((constants (enum-def-list->constants constants fields))) + (clone info + #:constants (append constants (.constants info))))) + ;; struct ((decl (decl-spec-list (type-spec (struct-def (ident ,name) (field-list . ,fields))))) (let ((type (struct->type (list "struct" name) (map struct-field fields)))) @@ -2035,6 +2031,19 @@ (_ (let ((info ((expr->accu info) o))) (append-text info (wrap-as (i386:accu-zero?))))))))) +(define (enum-def-list->constants constants fields) + (let loop ((fields fields) (i 0) (constants constants)) + (if (null? fields) constants + (let* ((field (car fields)) + (name (pmatch field + ((enum-defn (ident ,name) . _) name))) + (i (pmatch field + ((enum-defn ,name (p-expr (fixed ,value))) (cstring->number value)) + ((enum-defn ,name) i)))) + (loop (cdr fields) + (1+ i) + (append constants (list (ident->constant name i)))))))) + (define (initzer->non-const info) (lambda (o) (pmatch o