From: Brendan Hansen Date: Tue, 15 Sep 2020 02:17:11 +0000 (-0500) Subject: added name to polymorphic structs so error messsages look better X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=8cc683e9542c0f9fb0a97b38737f2e634de77380;p=onyx.git added name to polymorphic structs so error messsages look better --- diff --git a/docs/plan b/docs/plan index 61ec68d5..bbf3a28d 100644 --- a/docs/plan +++ b/docs/plan @@ -259,14 +259,14 @@ HOW: - Removes the argument from the list and replaces the function with the baked function - [ ] Add SIMD intrinsics + [X] Add SIMD intrinsics - This also requires adding the v128 SIMD type [ ] Add threading intrinsics - This will actually be fairly easy since I think all that is needed is to implement the intrinsics. - [ ] Type parameterized structs + [X] Type parameterized structs [ ] Array literals diff --git a/onyx b/onyx index 146b2668..5c8bea0a 100755 Binary files a/onyx and b/onyx differ diff --git a/progs/poly_struct.onyx b/progs/poly_struct.onyx index c3b78498..5941a5bf 100644 --- a/progs/poly_struct.onyx +++ b/progs/poly_struct.onyx @@ -5,18 +5,23 @@ package main use package core main :: proc (args: [] cstring) { - imap : I32Map(i32); + imap : I32Map(^string); i32map_init(^imap); - i32map_put(^imap, 50, 1234); - i32map_put(^imap, 1234, 5678); + hello := "Hello "; + world := "World!"; + + i32map_put(^imap, 50, ^hello); + i32map_put(^imap, 1234, ^world); print(i32map_has(^imap, 50)); print("\n"); print(i32map_has(^imap, 51)); print("\n"); - print(i32map_get(^imap, 50)); - print(i32map_get(^imap, 1234)); + // i32map_delete(^imap, 50); + + print(*i32map_get(^imap, 50)); + print(*i32map_get(^imap, 1234)); print("\n"); } diff --git a/src/onyxutils.c b/src/onyxutils.c index a19babb0..f15c0930 100644 --- a/src/onyxutils.c +++ b/src/onyxutils.c @@ -611,6 +611,20 @@ no_errors: fori (i, 0, bh_arr_length(params)) bh_arr_push(cs_type->Struct.poly_args, params[i]); + char name_buf[256]; + fori (i, 0, 256) name_buf[i] = 0; + + strncat(name_buf, ps_type->name, 255); + strncat(name_buf, "(", 255); + bh_arr_each(Type *, ptype, cs_type->Struct.poly_args) { + if (ptype != cs_type->Struct.poly_args) + strncat(name_buf, ", ", 255); + + strncat(name_buf, type_get_name(*ptype), 255); + } + strncat(name_buf, ")", 255); + cs_type->Struct.name = bh_aprintf(semstate.node_allocator, "%s", name_buf); + return concrete_struct; }