random bugfixes and changes
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Fri, 15 Oct 2021 03:00:31 +0000 (22:00 -0500)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Fri, 15 Oct 2021 03:00:31 +0000 (22:00 -0500)
bin/onyx
core/container/bucket_array.onyx
core/random.onyx
include/astnodes.h
misc/onyx.sublime-syntax
src/polymorph.c
src/types.c
src/utils.c
tests/bucket_array
tests/bucket_array.onyx

index 6fa13f9163fa200f8ba1a688c691d7518ecde651..4cea0fe177a853269df8d3abfe4d77ba522ee6ad 100755 (executable)
Binary files a/bin/onyx and b/bin/onyx differ
index e11ad9aca6cb0740d5f32a3b78b06e450dc4302d..6947ff728c2c59ff8b061c7ffad81677b62cb6d7 100644 (file)
@@ -45,6 +45,11 @@ clear :: (use b: ^Bucket_Array($T)) {
     array.clear(^buckets);
 }
 
+#operator [] macro (b: Bucket_Array($T), idx: i32) -> T {
+    get :: get
+    return get(^b, idx);
+}
+
 get :: (use b: ^Bucket_Array($T), idx: i32) -> T {
     bucket_index := idx / elements_per_bucket;
     elem_index   := idx % elements_per_bucket;
index bd8ba8b3bc6de8b3fdb657c5f99a11a7b1bac9a1..0bc3e50e9ba9252db79e2a98e303e63a0de78db3 100644 (file)
@@ -21,3 +21,7 @@ between :: (lo: i32, hi: i32) -> i32 do return int () % (hi + 1 - lo) + lo;
 float :: (lo := 0.0f, hi := 1.0f) -> f32 {
     return (cast(f32) (int() % (1 << 20)) / cast(f32) (1 << 20)) * (hi - lo) + lo;
 }
+
+choice :: (a: [] $T) -> T {
+    return a[between(0, a.count - 1)];
+}
\ No newline at end of file
index c6da28568a26261bdac2e345e4d3cbfa79e925cf..20966dd9aae33c0565f9cdda2b21554c6d6aae3e 100644 (file)
@@ -1419,7 +1419,7 @@ void report_unable_to_match_overload(AstCall* call);
 void expand_macro(AstCall** pcall, AstFunction* template);
 AstFunction* macro_resolve_header(AstMacro* macro, Arguments* args, OnyxToken* callsite);
 
-AstStructType* polymorphic_struct_lookup(AstPolyStructType* ps_type, bh_arr(AstPolySolution) slns, OnyxFilePos pos);
+Type* polymorphic_struct_lookup(AstPolyStructType* ps_type, bh_arr(AstPolySolution) slns, OnyxFilePos pos);
 
 // NOTE: Useful inlined functions
 static inline b32 is_lval(AstNode* node) {
index d07244e5ccb9e52d859587089df25b1560fe8387..1dd0907205fab88372aa1aa71ce2cd5211a2c4cd 100644 (file)
@@ -9,6 +9,9 @@ contexts:
   main:
     # Strings begin and end with quotes, and use backslashes as an escape
     # character
+    - match: '"""'
+      scope: punctuation.definition.string.begin.onyx
+      push: triple_quoted_string
     - match: '"'
       scope: punctuation.definition.string.begin.onyx
       push: double_quoted_string
@@ -97,6 +100,12 @@ contexts:
       scope: punctuation.definition.string.end.onyx
       pop: true
 
+  triple_quoted_string:
+    - meta_scope: string.quoted.triple.onyx
+    - match: '"""'
+      scope: punctuation.definition.string.end.onyx
+      pop: true
+
   line_comment:
     - meta_scope: comment.line.onyx
     - match: $
index 335eec9db8a4d6a5ab401ec5cd308945f84febd0..cd479e9eff16461f5036fc42f1a489242d5aa27e 100644 (file)
@@ -814,7 +814,7 @@ char* build_poly_struct_name(AstPolyStructType* ps_type, Type* cs_type) {
     return bh_aprintf(global_heap_allocator, "%s", name_buf);
 }
 
-AstStructType* polymorphic_struct_lookup(AstPolyStructType* ps_type, bh_arr(AstPolySolution) slns, OnyxFilePos pos) {
+Type* polymorphic_struct_lookup(AstPolyStructType* ps_type, bh_arr(AstPolySolution) slns, OnyxFilePos pos) {
     // @Cleanup
     assert(ps_type->scope != NULL);
 
@@ -890,7 +890,7 @@ AstStructType* polymorphic_struct_lookup(AstPolyStructType* ps_type, bh_arr(AstP
         if (cs_type->Struct.poly_sln == NULL) cs_type->Struct.poly_sln = bh_arr_copy(global_heap_allocator, slns);
         if (cs_type->Struct.name == NULL)     cs_type->Struct.name = build_poly_struct_name(ps_type, cs_type);
 
-        return concrete_struct;
+        return cs_type;
     }
 
     Scope* sln_scope = scope_create(context.ast_alloc, ps_type->scope, ps_type->token->pos);
index 58e3dc08aae1720207f62febd7a3ba6bd5833c69..dcb3d041f6879d802d28ffa3b6dfe090e148a366 100644 (file)
@@ -550,16 +550,15 @@ Type* type_build_from_ast(bh_allocator alloc, AstType* type_node) {
                 }
             }
 
-            AstStructType* concrete = polymorphic_struct_lookup(ps_type, slns, pc_type->token->pos);
+            Type* concrete = polymorphic_struct_lookup(ps_type, slns, pc_type->token->pos);
 
             // This should be copied in the previous function.
             // CLEANUP: Maybe don't copy it and just use this one since it is allocated on the heap?
             bh_arr_free(slns);
 
             if (!concrete) return NULL;
-            Type* struct_type = type_build_from_ast(alloc, (AstType *) concrete);
-            struct_type->Struct.constructed_from = (AstType *) ps_type;
-            return struct_type;
+            concrete->Struct.constructed_from = (AstType *) ps_type;
+            return concrete;
         }
 
         case Ast_Kind_Type_Compound: {
index 52fbb2cff992898667a1fe5c5287ad81bc40d726..ef91b57c446bfcda0c0e1649ea5d56e0ea52e429 100644 (file)
@@ -229,6 +229,11 @@ all_types_peeled_off:
             AstStructType* stype = ((AstPolyStructType *) node)->base_struct;
             return symbol_raw_resolve(stype->scope, symbol);
         }
+
+        case Ast_Kind_Poly_Call_Type: {
+            AstNode* callee = (AstNode *) ((AstPolyCallType *) node)->callee;
+            return try_symbol_raw_resolve_from_node(callee, symbol);
+        }
     }
 
     return NULL;
index 0daca9e21522d9d9788c8f19213562196e0e1eba..2f8f1c0b2286a621b65f0c8d07459f272229deb6 100644 (file)
@@ -1,3 +1,4 @@
+ba[10] is 10.
 [0] -> 0
 [1] -> 1
 [2] -> 2
index d94ae5186b7e96cfeed7d91471c8553a65b585ad..9307dca91e379b6a61c770a180135a4ada557d39 100644 (file)
@@ -6,6 +6,8 @@ main :: (args: [] cstr) {
     ba := bucket_array.make(i32, 4);
     for i: 24 do ba << i;
 
+    printf("ba[10] is {}.\n", ba[10]);
+
     sum := 0;
     bucket_array.for_each(ba, #code {
         printf("[{}] -> {}\n", bucket_index, *it);