bugfixes with struct literals and core libraries
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Tue, 29 Sep 2020 03:38:03 +0000 (22:38 -0500)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Tue, 29 Sep 2020 03:38:03 +0000 (22:38 -0500)
core/alloc.onyx
core/memory.onyx
misc/onyx.vim
onyx
src/onyxsymres.c
src/onyxutils.c

index 3d6614aa871d1a0ac47ef6a7a4a212c3c34ed29c..bc7d2566a0b66c08c24c3ef194d66627fe2ea9fe 100644 (file)
@@ -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 {
index 91da91da69f50b76e6351ed18d364c02346a1d2b..e28d087d9855d1756fc8c128222d48a4a40035e7 100644 (file)
@@ -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;
+}
index e06ab001bd60d0a90e94220582e636b4bf683ff0..261049fba499dfaa569c796d5203231aa42fa748 100644 (file)
@@ -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 d1898c4eb835a8234c6da71778b0dc2646ed9e8b..f046cfd1decc3408d585fed83e754c5285d7936e 100755 (executable)
Binary files a/onyx and b/onyx differ
index c7545d47cc4dc577a46a85c1beba99105ee3deef..af88d6f9f22d8252446208cb2a27864e2372718f 100644 (file)
@@ -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));
 
index 0b66aaabd204ca1b9c0149305204e1f208b881b8..c39768d46d7612c6bfeb2e63637dd47bcd07de6b 100644 (file)
@@ -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);