From: Brendan Hansen Date: Tue, 29 Sep 2020 03:38:03 +0000 (-0500) Subject: bugfixes with struct literals and core libraries X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=cdd89d09afb279d87208eb198d2d17a67ca3843a;p=onyx.git bugfixes with struct literals and core libraries --- diff --git a/core/alloc.onyx b/core/alloc.onyx index 3d6614aa..bc7d2566 100644 --- a/core/alloc.onyx +++ b/core/alloc.onyx @@ -124,7 +124,6 @@ heap_alloc_proc :: proc (data: rawptr, aa: AllocAction, size: u32, align: u32, o } -#private ScratchState :: struct { base_ptr : rawptr; size : u32; @@ -139,7 +138,7 @@ scratch_alloc_proc :: proc (data: rawptr, aa: AllocAction, size: u32, align: u32 retval := null; rem := ss.size - cast(u32) ss.curr_ptr + cast(u32) ss.base_ptr; - if size >= rem { + if size <= rem { retval = ss.curr_ptr; ss.curr_ptr = cast(rawptr) (cast(u32) ss.curr_ptr + size); } else { diff --git a/core/memory.onyx b/core/memory.onyx index 91da91da..e28d087d 100644 --- a/core/memory.onyx +++ b/core/memory.onyx @@ -5,3 +5,8 @@ memory_copy :: proc (dst_: rawptr, src_: rawptr, len: u32) { src := cast(^u8) src_; for i: 0 .. len do dst[i] = src[i]; } + +memory_set :: proc (start: rawptr, length: u32, value: u8) { + s := cast(^u8) start; + for i: 0 .. length do s[i] = value; +} diff --git a/misc/onyx.vim b/misc/onyx.vim index e06ab001..261049fb 100644 --- a/misc/onyx.vim +++ b/misc/onyx.vim @@ -40,6 +40,9 @@ syn region onyxComment start="/\*" end="\*/" contains=onyxCommentStart syn match onyxDefinitionGroup "\<[a-zA-Z_][a-zA-Z0-9_]*\> *:" contains=onyxDefinition syn match onyxDefinition "\<[a-zA-Z_][a-zA-Z0-9_]*\>" contained +syn match onyxCallGroup "\<[a-zA-Z_][a-zA-Z0-9_\.]*\> *(" contains=onyxCall +syn match onyxCall "\<[a-zA-Z_][a-zA-Z0-9_\.]*\>" contained + syn match onyxDirective "\#[a-zA-Z_]\+" syn region onyxString display start=+"+ skip=+\\\\\|\\"+ end=+"+ keepend @@ -53,6 +56,8 @@ hi def link onyxDirective Constant hi def link onyxString String hi def link onyxNumber Number hi def link onyxDefinition Identifier +hi def link onyxCall Function +hi def link onyxOperator Operator let b:current_syntax = "onyx" let &cpo = s:cpo_save diff --git a/onyx b/onyx index d1898c4e..f046cfd1 100755 Binary files a/onyx and b/onyx differ diff --git a/src/onyxsymres.c b/src/onyxsymres.c index c7545d47..af88d6f9 100644 --- a/src/onyxsymres.c +++ b/src/onyxsymres.c @@ -103,12 +103,20 @@ AstType* symres_type(AstType* type) { member->type_node = symres_type(member->type_node); if (member->flags & Ast_Flag_Struct_Mem_Used) { - if (member->type_node->kind != Ast_Kind_Struct_Type) { - onyx_report_error(member->token->pos, - "Can only 'use' members of struct type."); + AstStructType *used = (AstStructType *) member->type_node; + + while (used->kind == Ast_Kind_Type_Alias) { + // NOTE: Maybe not a struct type. + used = (AstStructType *) ((AstTypeAlias *) used)->to; } - AstStructType *used = (AstStructType *) member->type_node; + if (used->kind != Ast_Kind_Struct_Type) { + onyx_report_error(member->token->pos, + "Can only 'use' members of struct type, got '%s'.", + onyx_ast_node_kind_string(used->kind)); + + return type; + } bh_arr_insertn(s_node->members, i, bh_arr_length(used->members)); diff --git a/src/onyxutils.c b/src/onyxutils.c index 0b66aaab..c39768d4 100644 --- a/src/onyxutils.c +++ b/src/onyxutils.c @@ -48,12 +48,13 @@ static const char* ast_node_names[] = { "ARRAY TYPE", "SLICE TYPE", "DYNARR TYPE", + "VARARG TYPE", "STRUCT TYPE", "POLYMORPHIC STRUCT TYPE", "POLYMORPHIC STRUCT CALL TYPE", "ENUM TYPE", "TYPE_ALIAS", - "TYPE RAW ALIAS" + "TYPE RAW ALIAS", "TYPE_END (BAD)", "STRUCT MEMBER", @@ -587,7 +588,7 @@ AstStructType* polymorphic_struct_lookup(AstPolyStructType* ps_type, bh_arr(Type symbol_introduce(ps_type->scope, ps_type->poly_params[i], (AstNode *) raw); } - static char key_buf[1024]; + char key_buf[1024]; fori (i, 0, 1024) key_buf[i] = 0; bh_table_each_start(AstNode *, ps_type->scope->symbols); strncat(key_buf, key, 1023);