From: Brendan Hansen Date: Mon, 14 Sep 2020 22:44:19 +0000 (-0500) Subject: bugfixes for polymorphic structs X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=25918f2c36958a1220be5cfafd740c57de067606;p=onyx.git bugfixes for polymorphic structs --- diff --git a/core/i32map.onyx b/core/i32map.onyx index e0932fac..967b0d52 100644 --- a/core/i32map.onyx +++ b/core/i32map.onyx @@ -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 c0f66a7c..600acc29 100755 Binary files a/onyx and b/onyx differ diff --git a/progs/poly_struct.onyx b/progs/poly_struct.onyx index 9e32c695..68c968d0 100644 --- a/progs/poly_struct.onyx +++ b/progs/poly_struct.onyx @@ -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)); diff --git a/src/onyxclone.c b/src/onyxclone.c index ab4068bc..a4e95d97 100644 --- a/src/onyxclone.c +++ b/src/onyxclone.c @@ -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;