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;
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
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) {
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
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: $
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);
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);
}
}
- 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: {
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;
+ba[10] is 10.
[0] -> 0
[1] -> 1
[2] -> 2
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);