From: Brendan Hansen Date: Tue, 29 Dec 2020 20:03:45 +0000 (-0600) Subject: #solidify in polyproc fix; bindings don't require semicolons X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=7f218310a72af269e1ca15b4fc38f50c80eab55e;p=onyx.git #solidify in polyproc fix; bindings don't require semicolons --- diff --git a/onyx b/onyx index 92f06c4e..3764f3ba 100755 Binary files a/onyx and b/onyx differ diff --git a/progs/poly_solidify.onyx b/progs/poly_solidify.onyx index 24462e93..3e067055 100644 --- a/progs/poly_solidify.onyx +++ b/progs/poly_solidify.onyx @@ -22,16 +22,30 @@ main :: proc (args: [] cstr) { proc (b: f32) -> f64 { return ~~(b + 6); })); - arr : [..] f32; - array.init(^arr); - defer array.free(^arr); - - - for i: 0 .. 10 do array.push(^arr, ~~i); - print_array(arr); - - array_map(arr, double); - print_array(arr); + arr1 : [..] f32; + arr2 : [..] i32; + array.init(^arr1); + array.init(^arr2); + defer array.free(^arr1); + defer array.free(^arr2); + + for i: 0 .. 10 { + array.push(^arr1, ~~i); + array.push(^arr2, ~~i); + } + print_arrays(arr1, arr2); + + array_map(arr1, double); + array_map(arr2, double); + + print_arrays(arr1, arr2); + + print_arrays :: proc (arr1: [..] $T, arr2: [..] $R) { + println("=================================================="); + print_array(arr1); + print_array(arr2); + println("=================================================="); + } } array_map :: proc (arr: [..] $T, f: proc (T) -> T) { @@ -43,12 +57,18 @@ array_map :: proc (arr: [..] $T, f: proc (T) -> T) { for ^v: arr do *v = f(*v); - test2 :: proc () { test(); println("WORLD!!!!"); }; - test :: proc () { println("HELLO!!!"); }; + test2 :: proc () { + test(); + println("WORLD!!!!"); + } + + test :: proc () { + println("HELLO!!!"); + } InternalStruct :: struct ($SOMETHING) { foo : SOMETHING; - }; + } } double :: proc (v: $V) -> V do return v * 2; \ No newline at end of file diff --git a/src/onyxclone.c b/src/onyxclone.c index 0cfd8a5d..b731efe3 100644 --- a/src/onyxclone.c +++ b/src/onyxclone.c @@ -380,6 +380,26 @@ AstNode* ast_clone(bh_allocator a, void* n) { ((AstUse *) nn)->expr = (AstTyped *) ast_clone(a, ((AstUse *) node)->expr); break; } + + case Ast_Kind_Directive_Solidify: { + AstDirectiveSolidify* dd = (AstDirectiveSolidify *) nn; + AstDirectiveSolidify* sd = (AstDirectiveSolidify *) node; + + dd->poly_proc = (AstPolyProc *) ast_clone(a, (AstNode *) sd->poly_proc); + dd->resolved_proc = NULL; + + dd->known_polyvars = NULL; + bh_arr_new(global_heap_allocator, dd->known_polyvars, bh_arr_length(sd->known_polyvars)); + + bh_arr_each(AstPolySolution, sln, sd->known_polyvars) { + AstPolySolution new_sln; + new_sln.poly_sym = (AstNode *) ast_clone(a, (AstNode *) sln->poly_sym); + new_sln.ast_type = (AstType *) ast_clone(a, (AstNode *) sln->ast_type); + bh_arr_push(dd->known_polyvars, new_sln); + } + + break; + } } return nn; diff --git a/src/onyxparser.c b/src/onyxparser.c index b1d1e736..37479335 100644 --- a/src/onyxparser.c +++ b/src/onyxparser.c @@ -32,7 +32,7 @@ static AstIfWhile* parse_if_stmt(OnyxParser* parser); static AstIfWhile* parse_while_stmt(OnyxParser* parser); static AstFor* parse_for_stmt(OnyxParser* parser); static AstSwitch* parse_switch_stmt(OnyxParser* parser); -static b32 parse_possible_symbol_declaration(OnyxParser* parser, AstNode** ret); +static i32 parse_possible_symbol_declaration(OnyxParser* parser, AstNode** ret); static AstReturn* parse_return_stmt(OnyxParser* parser); static AstNode* parse_use_stmt(OnyxParser* parser); static AstBlock* parse_block(OnyxParser* parser); @@ -116,7 +116,7 @@ static void add_node_to_process(OnyxParser* parser, AstNode* node) { if (!bh_arr_is_empty(parser->block_stack)) { Scope* binding_scope = parser->block_stack[bh_arr_length(parser->block_stack) - 1]->binding_scope; - + if (binding_scope != NULL) scope = binding_scope; } @@ -1003,13 +1003,16 @@ static AstSwitch* parse_switch_stmt(OnyxParser* parser) { return switch_node; } -// Returns 1 if the symbol was consumed. Returns 0 otherwise +// Returns: +// 0 - if this was not a symbol declaration. +// 1 - if this was a local declaration. +// 2 - if this was binding declaration. // ret is set to the statement to insert // : = // : : // := // :: -static b32 parse_possible_symbol_declaration(OnyxParser* parser, AstNode** ret) { +static i32 parse_possible_symbol_declaration(OnyxParser* parser, AstNode** ret) { if (parser->curr->type != Token_Type_Symbol) return 0; if ((parser->curr + 1)->type != ':') return 0; @@ -1032,7 +1035,7 @@ static b32 parse_possible_symbol_declaration(OnyxParser* parser, AstNode** ret) AstBinding* binding = parse_top_level_binding(parser, symbol); symbol_introduce(current_block->binding_scope, symbol, binding->node); - return 1; + return 2; } // NOTE: var: type @@ -1185,9 +1188,13 @@ static AstNode* parse_statement(OnyxParser* parser) { retval = (AstNode *) parse_block(parser); break; - case Token_Type_Symbol: - if (parse_possible_symbol_declaration(parser, &retval)) break; + case Token_Type_Symbol: { + i32 symbol_res = parse_possible_symbol_declaration(parser, &retval); + if (symbol_res == 2) needs_semicolon = 0; + if (symbol_res != 0) break; + // fallthrough + } case '(': case '+':