From: Brendan Hansen Date: Tue, 19 Jan 2021 02:58:35 +0000 (-0600) Subject: bug fix with solidify directives X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=efbfbbb56d6c9b49efff7fa65e0ee7d2f88ab906;p=onyx.git bug fix with solidify directives --- diff --git a/bin/onyx b/bin/onyx index 29b9c441..2aa21033 100755 Binary files a/bin/onyx and b/bin/onyx differ diff --git a/core/memory.onyx b/core/memory.onyx index fd7f0805..6502d264 100644 --- a/core/memory.onyx +++ b/core/memory.onyx @@ -14,4 +14,11 @@ set :: proc (start: rawptr, length: u32, value: u8) { alloc_slice :: proc (sl: ^[] $T, count: i32) { sl.data = calloc(sizeof T * count); sl.count = count; +} + +make_slice :: proc ($T: type_expr, count: i32) -> [] T { + return <[] T>.{ + data = calloc(sizeof T * count), + count = count + }; } \ No newline at end of file diff --git a/onyx.exe b/onyx.exe index f188c723..06ab89e1 100644 Binary files a/onyx.exe and b/onyx.exe differ diff --git a/progs/poly_solidify.onyx b/progs/poly_solidify.onyx index ca4db5c6..686f20df 100644 --- a/progs/poly_solidify.onyx +++ b/progs/poly_solidify.onyx @@ -22,10 +22,8 @@ main :: proc (args: [] cstr) { proc (b: f32) -> f64 { return ~~(b + 6); })); - arr1 : [..] f32; - arr2 : [..] i32; - array.init(^arr1); - array.init(^arr2); + arr1 := array.make(f32); + arr2 := array.make(i32); defer array.free(^arr1); defer array.free(^arr2); @@ -71,7 +69,7 @@ array_map :: proc (arr: [..] $T, f: proc (T) -> T) { } } - InternalStruct :: struct ($SOMETHING) { + InternalStruct :: struct (SOMETHING: type_expr) { foo : SOMETHING; } } diff --git a/src/onyxparser.c b/src/onyxparser.c index 7cf8789a..a896c54d 100644 --- a/src/onyxparser.c +++ b/src/onyxparser.c @@ -548,11 +548,8 @@ static AstTyped* parse_factor(OnyxParser* parser) { expect_token(parser, '='); AstType* poly_type = parse_type(parser); - PolySolutionKind sln_kind = PSK_Type; - if (!node_is_type((AstNode *) poly_type)) sln_kind = PSK_Value; - bh_arr_push(solid->known_polyvars, ((AstPolySolution) { - .kind = sln_kind, + .kind = PSK_Undefined, .poly_sym = poly_var, .ast_type = poly_type, .type = NULL diff --git a/src/onyxsymres.c b/src/onyxsymres.c index c61fc523..fbf1f092 100644 --- a/src/onyxsymres.c +++ b/src/onyxsymres.c @@ -565,8 +565,17 @@ static void symres_directive_solidify(AstDirectiveSolidify** psolid) { } bh_arr_each(AstPolySolution, sln, solid->known_polyvars) { - sln->ast_type = symres_type(sln->ast_type); - sln->type = type_build_from_ast(semstate.node_allocator, sln->ast_type); + // HACK: This assumes that 'ast_type' and 'value' are at the same offset. + symres_expression(&sln->value); + if (onyx_has_errors()) return; + + if (node_is_type(sln->value)) { + sln->type = type_build_from_ast(semstate.node_allocator, sln->ast_type); + sln->kind = PSK_Type; + } else { + sln->kind = PSK_Value; + } + if (onyx_has_errors()) return; }