commit e7a1268b5c7412c80fbeb684403ea5a44eaa9b53
parent f2601e7e636350aef580acba054935488ae7ae70
Author: Brian Swetland <swetland@frotz.net>
Date: Thu, 12 Oct 2023 15:08:09 -0700
compiler0: improve enum handling
Diffstat:
2 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/compiler0.c b/compiler0.c
@@ -1435,17 +1435,17 @@ void parse_enum_def(void) {
if (sym != nil) {
error("cannot redefine %s as enum tag\n", name->text);
}
+ symbol_make_global(name, ctx.type_u32)->kind = SYMBOL_DEF;
+ emit_impl("#define c$%s ", name->text, val);
if (ctx.tok == tASSIGN) {
next();
- if (ctx.tok != tNUM) {
- error("enum value not a number");
- }
- val = ctx.num;
+ parse_expr();
+ emit_impl("\n");
+ } else {
+ emit_impl("0x%x\n", val);
+ val++;
}
require(tCOMMA);
- symbol_make_global(name, ctx.type_u32)->kind = SYMBOL_DEF;
- emit_decl("#define c$%s = 0x%x;\n", name->text, val);
- val++;
}
require(tCBRACE);
require(tSEMI);
diff --git a/test/1050-enums.src b/test/1050-enums.src
@@ -3,7 +3,7 @@ var i i32 = 3;
enum { ZERO, ONE, TWO, };
-enum { A = 5, B, C = 0x10000000, D, E = 50 + 50, F = ONE * TWO, };
+enum { A = 5, B = 6, C = 0x10000000, D = 0x10000001, E = 50 + 50, F = ONE * TWO, };
func start() i32 {
_hexout_(ZERO);