From: Brendan Hansen Date: Mon, 17 Aug 2020 03:43:29 +0000 (-0500) Subject: small bugfixes X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=974b146d10d609c12d3aba98cd84b14a00ede869;p=onyx.git small bugfixes --- diff --git a/onyx b/onyx index d7ff95ab..d1e7a979 100755 Binary files a/onyx and b/onyx differ diff --git a/progs/stack_based.onyx b/progs/stack_based.onyx index 372f5814..3c8d28ff 100644 --- a/progs/stack_based.onyx +++ b/progs/stack_based.onyx @@ -46,10 +46,14 @@ summing :: proc (x: ^i32) -> i32 { return s; } +get_value :: proc (x: i32, y: i32) -> i32 { + return x + 2 * y; +} + Vec3 :: struct { - x: i32; - y: i32; - z: i32; + x: i32 = get_value(10, 20); + y: i32 = 0; + z: i32 = 0; } mag_squared :: proc (use v: Vec3) -> i32 { @@ -149,8 +153,8 @@ start :: proc #export { mag_squared(varr[2]) |> print(); - v1 := Vec3 .{ 1, 2, 4 }; - v2 := *vadd(v1, Vec3.{ 1, 2, 4 }); + v1 := Vec3.{}; + v2 := *vadd(v1, Vec3.{ 0, 0, 0 }); print(v2.x); print(v2.y); diff --git a/src/onyxsymres.c b/src/onyxsymres.c index 87fa5a61..3739f72f 100644 --- a/src/onyxsymres.c +++ b/src/onyxsymres.c @@ -220,7 +220,7 @@ static void symres_struct_literal(AstStructLiteral* sl) { sl->type_node = (AstType *) sl->stnode; sl->type = type_build_from_ast(semstate.allocator, sl->type_node); - if (bh_arr_length(sl->named_values) > 0) { + if (bh_arr_length(sl->values) == 0) { bh_arr_set_length(sl->values, sl->type->Struct.mem_count); StructMember s; @@ -256,7 +256,7 @@ static void symres_struct_literal(AstStructLiteral* sl) { st->members[idx]->token->length); return; } - + sl->values[idx] = st->members[idx]->initial_value; } } diff --git a/src/onyxutils.c b/src/onyxutils.c index 2cc65668..f4bd1703 100644 --- a/src/onyxutils.c +++ b/src/onyxutils.c @@ -10,6 +10,8 @@ bh_allocator global_scratch_allocator; bh_managed_heap global_heap; bh_allocator global_heap_allocator; +static AstNode empty_node = { Ast_Kind_Error, 0, NULL, NULL }; + static const char* ast_node_names[] = { "ERROR", "PROGRAM", @@ -171,7 +173,7 @@ AstNode* symbol_resolve(Scope* start_scope, OnyxToken* tkn) { tkn->text); token_toggle_end(tkn); - return NULL; + return &empty_node; } if (res->kind == Ast_Kind_Symbol) {