bugfixes for polymorphic structs
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Mon, 14 Sep 2020 22:44:19 +0000 (17:44 -0500)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Mon, 14 Sep 2020 22:44:19 +0000 (17:44 -0500)
core/i32map.onyx
onyx
progs/poly_struct.onyx
src/onyxclone.c

index e0932facd0a5b2e1b7de6ddc9183942092369b1e..967b0d52d644ee1a6075edcd4e6464833fa926a9 100644 (file)
@@ -46,11 +46,11 @@ i32map_has :: proc (imap: ^I32Map($T), key: i32) -> bool {
     return lr.entry_index >= 0;
 }
 
-i32map_get :: proc (imap: ^I32Map($T), key: i32) -> i32 {
+i32map_get :: proc (imap: ^I32Map($T), key: i32, default := cast(T) 0) -> T {
     lr := i32map_lookup(imap, key);
     if lr.entry_index >= 0 do return imap.entries[lr.entry_index].value;
 
-    return null;
+    return default;
 }
 
 i32map_delete :: proc (imap: ^I32Map($T), key: i32) {
diff --git a/onyx b/onyx
index c0f66a7c0b4feffa46812bda08fafa01c1626186..600acc296ddaf8c80a1097d4c4d8a6cb62e7f394 100755 (executable)
Binary files a/onyx and b/onyx differ
index 9e32c6952334ed3ea33b9b99a7d0904c5a9bd617..68c968d0f2841a25928f5a413f31620f6ceba23a 100644 (file)
@@ -6,12 +6,11 @@ use package core
 
 
 main :: proc (args: [] cstring) {
-
-    imap : I32Map(string);
+    imap : I32Map(i32);
     i32map_init(^imap);
 
-    i32map_put(^imap, 50, "Hello ");
-    i32map_put(^imap, 1234, "World!");
+    i32map_put(^imap, 50, 1234);
+    i32map_put(^imap, 1234, 5678);
 
     print(i32map_get(^imap, 50));
     print(i32map_get(^imap, 1234));
index ab4068bcd736ba53b5fd8fbe0c4276585e8491d0..a4e95d97620e7d9574af42b6e06f52d7fcc36998 100644 (file)
@@ -290,9 +290,25 @@ AstNode* ast_clone(bh_allocator a, void* n) {
         }
 
         case Ast_Kind_Struct_Member:
+                       ((AstStructMember *) nn)->type_node = (AstType *) ast_clone(a, ((AstStructMember *) node)->type_node);
             ((AstStructMember *) nn)->initial_value = (AstTyped *) ast_clone(a, ((AstStructMember *) node)->initial_value);
             break;
 
+        case Ast_Kind_Poly_Call_Type: {
+            AstPolyCallType* pcd = (AstPolyCallType *) nn;
+            AstPolyCallType* pcs = (AstPolyCallType *) node;
+
+            pcd->callee = (AstType *) ast_clone(a, pcs->callee);
+            pcd->params = NULL;
+            bh_arr_new(global_heap_allocator, pcd->params, bh_arr_length(pcs->params));
+
+            bh_arr_each(AstType *, param, pcs->params) {
+                bh_arr_push(pcd->params, (AstType *) ast_clone(a, *param));
+            }
+
+            break;
+        }
+
                case Ast_Kind_Function_Type:
                        ((AstFunctionType *) nn)->return_type = (AstType *) ast_clone(a, ((AstFunctionType *) node)->return_type);
                        ((AstFunctionType *) nn)->param_count = ((AstFunctionType *) node)->param_count;