return h;
}
-init :: (use heap: ^Heap($T), cmp: (T, T) -> i32 = null_proc) {
+init :: (use heap: ^Heap, cmp: (heap.T, heap.T) -> i32 = null_proc) {
array.init(^data);
compare = cmp;
}
-insert :: (use heap: ^Heap($T), v: T) {
+insert :: (use heap: ^Heap, v: heap.T) {
data << v;
shift_up(heap, data.count - 1);
}
T == T;
}
-Set :: struct (T: type_expr) where SetValue(T) {
+Set :: struct (Elem_Type: type_expr) where SetValue(Elem_Type) {
allocator : Allocator;
hashes : [] i32;
- entries : [..] Entry(T);
+ entries : [..] Entry(Elem_Type);
- default_value: T;
+ default_value: Elem_Type;
Entry :: struct (T: type_expr) {
next : i32;
array.free(^entries);
}
-insert :: (use set: ^Set($T), value: T) {
+insert :: (use set: ^Set, value: set.Elem_Type) {
if hashes.data == null do init(set);
lr := lookup(set, value);
#operator << macro (set: Set($T), value: T) do (package core.set).insert(^set, value);
-has :: (use set: ^Set($T), value: T) -> bool {
+has :: (use set: ^Set, value: set.Elem_Type) -> bool {
lr := lookup(set, value);
return lr.entry_index >= 0;
}
-get :: (use set: ^Set($T), value: T) -> T {
+get :: (use set: ^Set, value: set.Elem_Type) -> set.Elem_Type {
lr := lookup(set, value);
return entries[lr.entry_index].value if lr.entry_index >= 0 else __zero_value(T);
}
-remove :: (use set: ^Set($T), value: T) {
+remove :: (use set: ^Set, value: set.Elem_Type) {
lr := lookup(set, value);
if lr.entry_index < 0 do return;
context.set = set;
context.position = 0;
- next :: ($T: type_expr, use context: ^Context(T)) -> (T, bool) {
+ next :: (use context: ^Context($T)) -> (T, bool) {
if position < set.entries.count {
defer position += 1;
return set.entries[position].value, true;
}
}
- close :: (context: rawptr) {
- cfree(context);
- }
-
return .{
data = context,
next = #solidify next { T = T },
- close = close,
+ close = cfree,
};
}
entry_prev : i32 = -1;
}
- lookup :: (use set: ^Set($T), value: T) -> SetLookupResult {
+ lookup :: (use set: ^Set, value: set.Elem_Type) -> SetLookupResult {
lr := SetLookupResult.{};
hash_value: u32 = hash.to_u32(value); // You cannot have a set of this type without defining a to_u32 hash.
arguments_remove_baked(&call->args);
callee = new_callee;
- } else if (callee->kind == Ast_Kind_Polymorphic_Proc) {
+ } else while (callee->kind == Ast_Kind_Polymorphic_Proc) {
AstTyped* new_callee = (AstTyped *) polymorphic_proc_lookup((AstFunction *) callee, PPLM_By_Arguments, &call->args, call->token);
if (new_callee == NULL) return Check_Error;
if (new_callee == (AstTyped *) &node_that_signals_a_yield) {
if (dont_copy_structs) {
if (node->kind == Ast_Kind_Struct_Type) return 0;
+ if (node->kind == Ast_Kind_Function) return 0;
+ if (node->kind == Ast_Kind_Polymorphic_Proc) return 0;
}
switch (node->kind) {
dont_copy_structs = 1;
new_param.local = (AstLocal *) ast_clone(a, param->local);
new_param.local->flags &= ~Ast_Flag_Param_Symbol_Dirty;
+ new_param.default_value = (AstTyped *) ast_clone(a, param->default_value);
dont_copy_structs = 0;
- new_param.default_value = (AstTyped *) ast_clone(a, param->default_value);
new_param.vararg_kind = param->vararg_kind;
new_param.is_used = param->is_used;
bh_arr_push(df->params, new_param);
dont_copy_structs = 1;
new_param.local = (AstLocal *) ast_clone(a, param->local);
new_param.local->flags &= ~Ast_Flag_Param_Symbol_Dirty;
+ new_param.default_value = (AstTyped *) ast_clone(a, param->default_value);
dont_copy_structs = 0;
- new_param.default_value = (AstTyped *) ast_clone(a, param->default_value);
new_param.vararg_kind = param->vararg_kind;
new_param.is_used = param->is_used;
bh_arr_push(new_func->params, new_param);
bh_arena_init(&entities->entity_arena, global_heap_allocator, 32 * 1024);
}
+static u32 next_entity_id = 0;
+
// Allocates the entity in the entity heap. Don't quite feel this is necessary...
Entity* entity_heap_register(EntityHeap* entities, Entity e) {
bh_allocator alloc = bh_arena_allocator(&entities->entity_arena);
Entity* entity = bh_alloc_item(alloc, Entity);
*entity = e;
+ entity->id = next_entity_id++;
entity->macro_attempts = 0;
entity->micro_attempts = 0;
entity->entered_in_queue = 0;
if (ss > Symres_Errors_Start) return ss; \
} while (0)
+#define SYMRES_INVISIBLE(kind, node, ...) do { \
+ (node)->flags |= Ast_Flag_Symbol_Invisible; \
+ SymresStatus ss = symres_ ## kind (__VA_ARGS__); \
+ (node)->flags &= ~Ast_Flag_Symbol_Invisible; \
+ if (ss > Symres_Errors_Start) return ss; \
+ } while (0)
+
typedef enum SymresStatus {
Symres_Success,
Symres_Complete,
case Ast_Kind_Alias: {
AstAlias* alias = (AstAlias *) *type;
- alias->flags |= Ast_Flag_Symbol_Invisible;
- SymresStatus ss = symres_type((AstType **) &alias->alias);
- alias->flags &= ~Ast_Flag_Symbol_Invisible;
- if (ss > Symres_Errors_Start) return ss;
+ SYMRES_INVISIBLE(type, alias, &alias->alias);
break;
}
case Ast_Kind_Size_Of: SYMRES(size_of, (AstSizeOf *)*expr); break;
case Ast_Kind_Align_Of: SYMRES(align_of, (AstAlignOf *)*expr); break;
case Ast_Kind_Alias: {
- (*expr)->flags |= Ast_Flag_Symbol_Invisible;
- SymresStatus ss = symres_expression((AstTyped **) &((AstAlias *) *expr)->alias);
- (*expr)->flags &= ~Ast_Flag_Symbol_Invisible;
- if (ss > Symres_Errors_Start) return ss;
+ AstAlias *alias = (AstAlias *) *expr;
+ SYMRES_INVISIBLE(expression, alias, &alias->alias);
break;
}
bh_arr_each(AstParam, param, func->params) {
symbol_introduce(curr_scope, param->local->token, (AstNode *) param->local);
+ }
+ bh_arr_each(AstParam, param, func->params) {
if (param->local->type_node != NULL) {
- SYMRES(type, ¶m->local->type_node);
+ SYMRES_INVISIBLE(type, param->local, ¶m->local->type_node);
}
}
}
static SymresStatus symres_macro(AstMacro* macro) {
+ macro->flags |= Ast_Flag_Comptime;
+
if (macro->body->kind == Ast_Kind_Function) {
SYMRES(function_header, (AstFunction *) macro->body);
}
SYMRES(polyproc, (AstFunction *) macro->body);
}
- macro->flags |= Ast_Flag_Comptime;
-
return Symres_Success;
}
char* closest = NULL;
fori (i, 0, shlen(scope->symbols)) {
+ if (scope->symbols[i].value->flags & Ast_Flag_Symbol_Invisible) continue;
+
char *key = scope->symbols[i].key;
u32 d = levenshtein_distance(key, sym);
if (d < *out_distance) {