bugfix with reducing comptime enum expressions
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Sun, 27 Dec 2020 23:01:35 +0000 (17:01 -0600)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Sun, 27 Dec 2020 23:01:35 +0000 (17:01 -0600)
onyx
progs/poly_solidify.onyx
src/onyxutils.c

diff --git a/onyx b/onyx
index 90cf0736fe79d3ebf3fdbdb33dfce98c88b2125a..4856420fc52d8ef561ee0d3a5809e0ae148e4da5 100755 (executable)
Binary files a/onyx and b/onyx differ
index 3437f76193e95b2b7fb58f3462e48285509a7ad0..d03475f1d39286dc01c093db9b5a50402b51131d 100644 (file)
@@ -6,8 +6,9 @@ max_f32 :: #solidify math.max { T = f32 };
 
 compose :: proc (a: $A, f: proc (A) -> $B, g: proc (B) -> $C) -> C do return g(f(a));
 
-specific_compose_0 :: #solidify compose { B = u32 };
+specific_compose_0 :: #solidify compose { B = f32 };
 specific_compose_1 :: #solidify specific_compose_0 { A = f32 };
+specific_compose_2 :: #solidify specific_compose_1 { C = f64 };
 
 main :: proc (args: [] cstr) {
        printf("max(1, 2) = %i\n", math.max(1, 2));
@@ -15,8 +16,8 @@ main :: proc (args: [] cstr) {
 
        // printf("max_f32(1, 2) = %i\n", max_f32(cast(u32) 1, cast(u32) 2));
 
-       println(specific_compose_1(
+       println(specific_compose_2(
                2,
-               proc (a: f32) -> i32 { return ~~(a * 2); },
-               proc (b: i32) -> i32 { return ~~(b + 6); }));
+               proc (a: f32) -> f32 { return ~~(a * 2); },
+               proc (b: f32) -> f64 { return ~~(b + 6); }));
 }
\ No newline at end of file
index a43d497dca62804d5f72b67634049da4d66c9aa7..c88e6378b7ee5eb4d60a50b931439330f5a1419a 100644 (file)
@@ -265,7 +265,9 @@ void scope_clear(Scope* scope) {
 #define REDUCE_BINOP_ALL(op) \
     if (type_is_small_integer(res->type) || type_is_bool(res->type)) { \
         res->value.i = left->value.i op right->value.i; \
-    } else if (type_is_integer(res->type) || res->type->Basic.kind == Basic_Kind_Int_Unsized) { \
+    } else if (type_is_integer(res->type) \
+        || res->type->Basic.kind == Basic_Kind_Int_Unsized \
+        || res->type->kind == Type_Kind_Enum) { \
         res->value.l = left->value.l op right->value.l; \
     } else if (res->type->Basic.kind == Basic_Kind_F32) { \
         res->value.f = left->value.f op right->value.f; \
@@ -277,7 +279,9 @@ void scope_clear(Scope* scope) {
 #define REDUCE_BINOP_INT(op) \
     if (type_is_small_integer(res->type) || type_is_bool(res->type)) { \
         res->value.i = left->value.i op right->value.i; \
-    } else if (type_is_integer(res->type) || res->type->Basic.kind == Basic_Kind_Int_Unsized) { \
+    } else if (type_is_integer(res->type) \
+        || res->type->Basic.kind == Basic_Kind_Int_Unsized \
+        || res->type->kind == Type_Kind_Enum) { \
         res->value.l = left->value.l op right->value.l; \
     } \
     break;
@@ -387,7 +391,7 @@ AstTyped* ast_reduce(bh_allocator a, AstTyped* node) {
         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);
+        case Ast_Kind_Enum_Value: return (AstTyped *) ((AstEnumValue *) node)->value;
         default:                  return NULL;
     }
 }