}
contains :: #match {
- // Uses '==' to compare for equality.
- (arr: [] $T, x: T) -> bool {
- for it: arr do if it == x do return true;
+ macro (arr: [] $T, $cmp: Code) -> bool {
+ for it: arr do if #unquote cmp do return true;
return false;
},
- macro (arr: [] $T, $cmp: Code) -> bool {
- for it: arr do if #unquote cmp do return true;
+ // Uses '==' to compare for equality.
+ (arr: [] $T, x: T) -> bool {
+ for it: arr do if it == x do return true;
return false;
}
}
return null;
}
+first_where :: macro (arr: [] $T, cond: Code) -> ^T {
+ // This is to preserve the semantics that "it" is
+ // not a pointer (same as contains)
+ for^ it_: arr {
+ it := *it_;
+ if #unquote cond do return it_;
+ }
+
+ return null;
+}
+
count_where :: #match {
(arr: [] $T, predicate: (T) -> bool) -> u32 {
count: u32 = 0;
type: type_expr;
tags: [] any;
}
+
+get_tags_for_procedure :: (func: $T) -> [] any {
+ if get_type_info(T).kind != .Function do return .[];
+
+ for tagged_procedures {
+ if it.func == func do return it.tags;
+ }
+
+ return .[];
+}
+
+#local GPWT_Result :: struct (T: type_expr) {
+ func: () -> void;
+ type: type_expr;
+ tag : ^T;
+}
+
+get_procedures_with_tag :: ($tag_type: type_expr) -> [] GPWT_Result(tag_type) {
+ array :: package core.array
+ results := make([..] GPWT_Result(tag_type));
+
+ for proc: tagged_procedures {
+ if tag := array.first_where(proc.tags, #(it.type == tag_type)); tag != null {
+ array.push(^results, .{
+ func = proc.func,
+ type = proc.type,
+ tag = cast(^tag_type) tag.data
+ });
+ }
+ }
+
+ return results;
+}
extern bh_arr(OverloadOption) operator_overloads[Binary_Op_Count];
void initialize_builtins(bh_allocator a);
+void initalize_special_globals();
void introduce_build_options(bh_allocator a);
bh_arr_new(global_heap_allocator, init_procedures, 4);
- p = package_lookup("runtime.info");
- if (p != NULL) {
- type_table_node = (AstTyped *) symbol_raw_resolve(p->scope, "type_table");
- foreign_blocks_node = (AstTyped *) symbol_raw_resolve(p->scope, "foreign_blocks");
- foreign_block_type = (AstType *) symbol_raw_resolve(p->scope, "foreign_block");
- tagged_procedures_node = (AstTyped *) symbol_raw_resolve(p->scope, "tagged_procedures");
- }
-
fori (i, 0, Binary_Op_Count) {
bh_arr_new(global_heap_allocator, operator_overloads[i], 4);
}
}
}
+void initalize_special_globals() {
+ Package *p = package_lookup("runtime.info");
+ if (p != NULL) {
+ type_table_node = (AstTyped *) symbol_raw_resolve(p->scope, "type_table");
+ foreign_blocks_node = (AstTyped *) symbol_raw_resolve(p->scope, "foreign_blocks");
+ foreign_block_type = (AstType *) symbol_raw_resolve(p->scope, "foreign_block");
+ tagged_procedures_node = (AstTyped *) symbol_raw_resolve(p->scope, "tagged_procedures");
+ }
+}
+
void introduce_build_options(bh_allocator a) {
Package* p = package_lookup_or_create("runtime", context.global_scope, a);
return include_node;
}
+// HACK
+static u32 special_global_entities_remaining = 3;
+static Entity *runtime_info_types_entity;
+static Entity *runtime_info_foreign_entity;
+static Entity *runtime_info_proc_tags_entity;
+
static void context_init(CompileOptions* opts) {
types_init();
.state = Entity_State_Parse_Builtin,
.type = Entity_Type_Load_File,
.package = NULL,
- .include = create_load(context.ast_alloc, "core/runtime/info/types"),
+ .include = create_load(context.ast_alloc, "core/runtime/build_opts"),
}));
- entity_heap_insert(&context.entities, ((Entity) {
- .state = Entity_State_Parse_Builtin,
+
+ runtime_info_types_entity = entity_heap_insert(&context.entities, ((Entity) {
+ .state = Entity_State_Parse,
.type = Entity_Type_Load_File,
.package = NULL,
- .include = create_load(context.ast_alloc, "core/runtime/info/foreign_blocks"),
+ .include = create_load(context.ast_alloc, "core/runtime/info/types"),
}));
- entity_heap_insert(&context.entities, ((Entity) {
- .state = Entity_State_Parse_Builtin,
+ runtime_info_foreign_entity = entity_heap_insert(&context.entities, ((Entity) {
+ .state = Entity_State_Parse,
.type = Entity_Type_Load_File,
.package = NULL,
- .include = create_load(context.ast_alloc, "core/runtime/info/proc_tags"),
+ .include = create_load(context.ast_alloc, "core/runtime/info/foreign_blocks"),
}));
-
- entity_heap_insert(&context.entities, ((Entity) {
- .state = Entity_State_Parse_Builtin,
+ runtime_info_proc_tags_entity = entity_heap_insert(&context.entities, ((Entity) {
+ .state = Entity_State_Parse,
.type = Entity_Type_Load_File,
.package = NULL,
- .include = create_load(context.ast_alloc, "core/runtime/build_opts"),
+ .include = create_load(context.ast_alloc, "core/runtime/info/proc_tags"),
}));
add_entities_for_node(NULL, (AstNode *) &builtin_stack_top, context.global_scope, NULL);
introduce_build_options(context.ast_alloc);
}
+ // GROSS
+ if (special_global_entities_remaining == 0) {
+ special_global_entities_remaining--;
+ initalize_special_globals();
+ }
+
if (process_load_entity(ent)) {
+ // GROSS
+ if (ent == runtime_info_types_entity
+ || ent == runtime_info_proc_tags_entity
+ || ent == runtime_info_foreign_entity) {
+ special_global_entities_remaining--;
+ }
+
ent->state = Entity_State_Finalized;
} else {
ent->macro_attempts++;
static WasmType onyx_type_to_wasm_type(Type* type) {
if (type->kind == Type_Kind_Struct) {
+ if (type_linear_member_count(type) == 1) {
+ return onyx_type_to_wasm_type(type->Struct.linear_members[0].type);
+ }
+
return WASM_TYPE_VOID;
}
return WASM_TYPE_VOID;
}
+ if (type->kind == Type_Kind_Compound) {
+ return WASM_TYPE_VOID;
+ }
+
if (type->kind == Type_Kind_Enum) {
return onyx_type_to_wasm_type(type->Enum.backing);
}
type->return_type = return_type;
type->param_count = param_count;
- // HACK ish thing
- memcpy(type->param_types, type_repr_buf, type->param_count);
+ fori (i, 0, type->param_count) {
+ type->param_types[i] = type_repr_buf[i];
+ }
bh_arr_push(mod->types, type);
}
if (context.options->verbose_output == 1) {
- bh_printf("Foreign blocks size: %d bytes.\n", tag_proc_buffer.length);
+ bh_printf("Tagged procedure size: %d bytes.\n", tag_proc_buffer.length);
}
u32 offset = module->next_datum_offset;