From: Brendan Hansen Date: Sun, 27 Dec 2020 23:01:35 +0000 (-0600) Subject: bugfix with reducing comptime enum expressions X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=a5affea7bf91b3d8dd3c3cce025cf3f8215a81d5;p=onyx.git bugfix with reducing comptime enum expressions --- diff --git a/onyx b/onyx index 90cf0736..4856420f 100755 Binary files a/onyx and b/onyx differ diff --git a/progs/poly_solidify.onyx b/progs/poly_solidify.onyx index 3437f761..d03475f1 100644 --- a/progs/poly_solidify.onyx +++ b/progs/poly_solidify.onyx @@ -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 diff --git a/src/onyxutils.c b/src/onyxutils.c index a43d497d..c88e6378 100644 --- a/src/onyxutils.c +++ b/src/onyxutils.c @@ -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; } }