enum values are compile time known
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Tue, 22 Dec 2020 04:21:45 +0000 (22:21 -0600)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Tue, 22 Dec 2020 04:21:45 +0000 (22:21 -0600)
onyx
src/onyxsymres.c
src/onyxutils.c
src/onyxwasm.c

diff --git a/onyx b/onyx
index c7d6c45aaa4694e90ee1875ecd3d406f1c9c7a47..f45df9c9b494527408c6ab1da2d9c4538321941d 100755 (executable)
Binary files a/onyx and b/onyx differ
index 873fa80ee9b32ef52c65ce0564a84e8f1527af7a..e3327c8eb61923c542bc5a07a8335aeb8e661176 100644 (file)
@@ -832,9 +832,12 @@ static void symres_enum(AstEnumType* enum_node) {
             num->value.l = next_assign_value;
             num->type_node = enum_node->backing;
             num->type = enum_node->backing_type;
+            num->flags |= Ast_Flag_Comptime;
             (*value)->value = num;
         }
 
+        (*value)->flags |= Ast_Flag_Comptime;
+
         if (enum_node->flags & Ast_Flag_Enum_Is_Flags) {
             next_assign_value <<= 1;
         } else {
index 9111404ea3c33e03c1c6014714198cb01db347f6..714f47f460cbfdf85ef33d9ba24a8d7f9eb8bae5 100644 (file)
@@ -380,10 +380,11 @@ AstTyped* ast_reduce(bh_allocator a, AstTyped* node) {
     assert(node->flags & Ast_Flag_Comptime);
 
     switch (node->kind) {
-        case Ast_Kind_Binary_Op: return (AstTyped *) ast_reduce_binop(a, (AstBinaryOp *) node);
-        case Ast_Kind_Unary_Op:  return (AstTyped *) ast_reduce_unaryop(a, (AstUnaryOp *) node);
-        case Ast_Kind_NumLit:    return node;
-        default:                 return NULL;
+        case Ast_Kind_Binary_Op:  return (AstTyped *) ast_reduce_binop(a, (AstBinaryOp *) node);
+        case Ast_Kind_Unary_Op:   return (AstTyped *) ast_reduce_unaryop(a, (AstUnaryOp *) node);
+        case Ast_Kind_NumLit:     return node;
+        case Ast_Kind_Enum_Value: return (AstTyped *) ast_reduce(a, (AstTyped *) ((AstEnumValue *) node)->value);
+        default:                  return NULL;
     }
 }
 
index 357fa0629ae629cb3725c318fe8c9fb198b84f06..a8773361a0227147f9d02da4b19247d710fb1585 100644 (file)
@@ -3004,6 +3004,12 @@ static void emit_raw_data(OnyxWasmModule* mod, ptr data, AstTyped* node) {
         break;
     }
 
+    case Ast_Kind_Enum_Value: {
+        AstEnumValue* ev = (AstEnumValue *) node;
+        emit_raw_data(mod, data, (AstTyped *) ev->value);
+        break;
+    }
+
     case Ast_Kind_NumLit: {
         // NOTE: This makes a big assumption that we are running on a
         // little endian machine, since WebAssembly is little endian