various little bug fixes around the code
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Fri, 8 Jan 2021 23:19:30 +0000 (17:19 -0600)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Fri, 8 Jan 2021 23:19:30 +0000 (17:19 -0600)
bin/onyx
onyx.exe
progs/odin_example.onyx
src/onyxchecker.c
src/onyxlex.c
src/onyxutils.c
tests/poly_structs_with_values
tests/poly_structs_with_values.onyx

index ab0104e39b578d7e8abbed2657d232d967436051..797a3f47d78f163fda8311d79fd092f8e4ad1d0c 100755 (executable)
Binary files a/bin/onyx and b/bin/onyx differ
index 4f9b9084d8d6ce6a9af49d11f9910320f30565c6..14ae340661a312359aaf70cdc16a62355a377d87 100644 (file)
Binary files a/onyx.exe and b/onyx.exe differ
index 8791accbe0f1140152af30a6f4031a1f12f9d174..42cfc5618df31b340065a8f4791627ae2f1b3d85 100644 (file)
@@ -69,9 +69,9 @@ f :: proc () -> [5] [2] u32 #export "IAMTHEFUNCTION" {
     return mem;
 }
 
-compress :: proc (arr: [5] $T, f : proc (T, T) -> T) -> T {
+compress :: proc (arr: [$N] $T, f : proc (T, T) -> T) -> T {
     val := arr[0];
-    for i: 1 .. 5 do val = f(val, arr[i]);
+    for i: 1..N do val = f(val, arr[i]);
     return val;
 }
 
@@ -86,7 +86,6 @@ Vec2   :: struct { x: i32; y: i32; }
 Entity :: struct { use pos: Vec2; }
 
 array_literal_optim :: proc () #export {
-    // This needs to be optimized
     bar : [5] u32;
     bar = u32.[ 1, 2, 3, 4, 5 ];
     bar[2] = 1234;
index 54f074b2e78736195502579551120acb55ad4edb..77c8ae8f663e84ea0f002471bed6d251db5c4380 100644 (file)
@@ -1308,7 +1308,12 @@ CheckStatus check_align_of(AstAlignOf* ao) {
 CheckStatus check_expression(AstTyped** pexpr) {
     AstTyped* expr = *pexpr;
     if (expr->kind > Ast_Kind_Type_Start && expr->kind < Ast_Kind_Type_End) {
-        onyx_report_error(expr->token->pos, "Type used as part of an expression.");
+        if (expr->token) {
+            onyx_report_error(expr->token->pos, "Type used as part of an expression.");
+        }
+        else {
+            onyx_report_error((OnyxFilePos) { 0 }, "Type used as part of an expression somewhere in the program.");
+        }
         return Check_Error;
     }
 
index cf1d286bbaea5749694b79cd3745a2878e1afafe..c88a31a47cab5e0cec8f87e3a53853931860a902 100644 (file)
@@ -254,7 +254,8 @@ whitespace_skipped:
         if (*tokenizer->curr == '.') hit_decimal = 1;
 
         u32 len = 1;
-        while (char_is_num(*(tokenizer->curr + 1)) || (!hit_decimal && *(tokenizer->curr + 1) == '.')) {
+        while (char_is_num(*(tokenizer->curr + 1))
+            || (!hit_decimal && *(tokenizer->curr + 1) == '.' && *(tokenizer->curr + 2) != '.')) {
             len++;
             INCREMENT_CURR_TOKEN(tokenizer);
 
index 1813e98a45999062ec94a749abb8a5d55c3fd678..47a3407a0a2f78378cb3a7a852508f330a7911d0 100644 (file)
@@ -428,6 +428,27 @@ void promote_numlit_to_larger(AstNumLit* num) {
     }
 }
 
+static void insert_poly_slns_into_scope(Scope* scope, bh_arr(AstPolySolution) slns) {
+    bh_arr_each(AstPolySolution, sln, slns) {
+        AstNode *node = NULL;
+
+        switch (sln->kind) {
+            case PSK_Type:
+                node = onyx_ast_node_new(semstate.node_allocator, sizeof(AstTypeRawAlias), Ast_Kind_Type_Raw_Alias);
+                ((AstTypeRawAlias *) node)->token = sln->poly_sym->token;
+                ((AstTypeRawAlias *) node)->to = sln->type;
+                break;
+
+            case PSK_Value:
+                // CLEANUP: Maybe clone this?
+                node = (AstNode *) sln->value;
+                break;
+        }
+
+        symbol_introduce(scope, sln->poly_sym->token, node);
+    }
+}
+
 typedef struct PolySolveResult {
     PolySolutionKind kind;
     union {
@@ -730,23 +751,7 @@ AstFunction* polymorphic_proc_solidify(AstPolyProc* pp, bh_arr(AstPolySolution)
     }
 
     Scope* poly_scope = scope_create(semstate.node_allocator, pp->poly_scope, pos);
-    bh_arr_each(AstPolySolution, sln, slns) {
-        AstNode *node = NULL;
-
-        switch (sln->kind) {
-            case PSK_Type:
-                node = onyx_ast_node_new(semstate.node_allocator, sizeof(AstTypeRawAlias), Ast_Kind_Type_Raw_Alias);
-                ((AstTypeRawAlias *) node)->to = sln->type;
-                break;
-
-            case PSK_Value:
-                // CLEANUP: Maybe clone this?
-                node = (AstNode *) sln->value;
-                break;
-        }
-
-        symbol_introduce(poly_scope, sln->poly_sym->token, node);
-    }
+    insert_poly_slns_into_scope(poly_scope, slns);
 
     AstFunction* func = (AstFunction *) ast_clone(semstate.node_allocator, pp->base_func);
     bh_table_put(AstFunction *, pp->concrete_funcs, unique_key, func);
@@ -936,26 +941,10 @@ AstStructType* polymorphic_struct_lookup(AstPolyStructType* ps_type, bh_arr(AstP
     }
 
     scope_clear(ps_type->scope);
-
-    bh_arr_each(AstPolySolution, sln, slns) {
-        AstNode *node = NULL;
-        
-        switch (sln->kind) {
-            case PSK_Type:
-                node = onyx_ast_node_new(semstate.node_allocator, sizeof(AstTypeRawAlias), Ast_Kind_Type_Raw_Alias);
-                ((AstTypeRawAlias *) node)->to = sln->type;
-                break;
-
-            case PSK_Value:
-                // CLEANUP: Maybe clone this?
-                node = (AstNode *) sln->value;
-                break;
-        }
-
-        symbol_introduce(ps_type->scope, sln->poly_sym->token, node);
-    }
+    insert_poly_slns_into_scope(ps_type->scope, slns);
 
     AstStructType* concrete_struct = (AstStructType *) ast_clone(semstate.node_allocator, ps_type->base_struct);
+    bh_table_put(AstStructType *, ps_type->concrete_structs, unique_key, concrete_struct);
 
     Entity struct_entity = {
         .state = Entity_State_Resolve_Symbols,
@@ -980,8 +969,6 @@ AstStructType* polymorphic_struct_lookup(AstPolyStructType* ps_type, bh_arr(AstP
         return NULL;
     }
 
-    bh_table_put(AstStructType *, ps_type->concrete_structs, unique_key, concrete_struct);
-
     Type* cs_type = type_build_from_ast(semstate.node_allocator, (AstType *) concrete_struct);
     cs_type->Struct.poly_sln = NULL;
     bh_arr_new(global_heap_allocator, cs_type->Struct.poly_sln, bh_arr_length(slns));
index 3d8fae79a0cfa71742f3b2cf9ba246b7c6cd8170..72e3b7971718d941fb274db026246d6b94d36888 100644 (file)
@@ -4,3 +4,4 @@
 12345
 1234
 Hello World!
+Hello World!
index 38eb53ec2b1b98edc37d75c62299246322e5d07c..7ca5541b410886e860eca9c384220973b28601d0 100644 (file)
@@ -3,7 +3,6 @@
 use package core
 
 main :: proc (args: [] cstr) {
-
     NewPolyStruct :: struct (T: type_expr, N: i32) {
         x : [N] T; 
         y : [N] f32;
@@ -16,6 +15,10 @@ main :: proc (args: [] cstr) {
 
     for x: nps.x do println(x);
 
+
+
+    
+
     SimpleWithDefault :: struct (T: type_expr, default: str) {
         x : T;
         str_member : str = default; 
@@ -24,4 +27,7 @@ main :: proc (args: [] cstr) {
     swd := <SimpleWithDefault(i32, #value "Hello World!")>.{ x = 1234 };
     println(swd.x);
     println(swd.str_member);
+    poly_match(swd);
+
+    poly_match :: proc (swd: SimpleWithDefault($T, $D)) do println(D);
 }
\ No newline at end of file