added name to polymorphic structs so error messsages look better
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Tue, 15 Sep 2020 02:17:11 +0000 (21:17 -0500)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Tue, 15 Sep 2020 02:17:11 +0000 (21:17 -0500)
docs/plan
onyx
progs/poly_struct.onyx
src/onyxutils.c

index 61ec68d568c5d7075ce077d5127d5adc76661dc1..bbf3a28d2bd9a36ef2a6ecd93af61142bfef0101 100644 (file)
--- 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 146b26681895975c82400c4619eead529cd62f28..5c8bea0ae8daf596f83d0236a10ef05f49016cfa 100755 (executable)
Binary files a/onyx and b/onyx differ
index c3b784988698c41c6b020d28883571f150d48c53..5941a5bf6c15e093e4d6b9901961df595bc7caf2 100644 (file)
@@ -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");
 }
index a19babb009d927a59f7ca9c5f2883d528f369c57..f15c09300703913e72a05ce466437961205161d9 100644 (file)
@@ -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;
 }