array.free(^entries);
}
-put :: (use map: ^Map($K, $V), key: map.Key_Type, value: map.Value_Type) {
+put :: (use map: ^Map, key: map.Key_Type, value: map.Value_Type) {
if map.hashes.data == null do init(map);
lr := lookup(map, key);
if full(map) do grow(map);
}
-has :: (use map: ^Map($K, $V), key: K) -> bool {
+has :: (use map: ^Map, key: map.Key_Type) -> bool {
lr := lookup(map, key);
return lr.entry_index >= 0;
}
-get :: (use map: ^Map($K, $V), key: K) -> V {
+get :: (use map: ^Map, key: map.Key_Type) -> map.Value_Type {
lr := lookup(map, key);
if lr.entry_index >= 0 do return entries[lr.entry_index].value;
#operator []= macro (map: Map($K, $V), key: K, value: V) do (package core.map).put(^map, key, value);
#operator ^[] macro (map: Map($K, $V), key: K) -> ^V do return (package core.map).get_ptr(^map, key);
-get_ptr :: (use map: ^Map($K, $V), key: K) -> ^V {
+get_ptr :: (use map: ^Map, key: map.Key_Type) -> ^map.Value_Type {
lr := lookup(map, key);
if lr.entry_index >= 0 do return ^entries[lr.entry_index].value;
return null;
}
-delete :: (use map: ^Map($K, $V), key: K) {
+delete :: (use map: ^Map, key: map.Key_Type) {
lr := lookup(map, key);
if lr.entry_index < 0 do return;
else do hashes[last.hash_index] = lr.entry_index;
}
-update :: macro (map: ^Map($K, $V), key: K, body: Code) {
+update :: macro (map: ^Map, key: map.Key_Type, body: Code) {
@Hack // Weird hack because 'lookup' exists at file scope.
lookup_ :: lookup
entry_prev : i32 = -1;
}
- lookup :: (use map: ^Map($K, $V), key: K) -> MapLookupResult {
+ lookup :: (use map: ^Map, key: map.Key_Type) -> MapLookupResult {
if hashes.data == null do init(map);
lr := MapLookupResult.{};
Ast_Flag_Header_Check_No_Error = BH_BIT(19),
Ast_Flag_Decl_Followed_By_Init = BH_BIT(20),
+
+ Ast_Flag_Param_Symbol_Dirty = BH_BIT(21),
} AstFlags;
typedef enum UnaryOp {
#include "parser.h"
#include "utils.h"
+// Weird flags that shouldn't be used too often because they complicate things
+static b32 dont_copy_structs = 0;
+
static inline b32 should_clone(AstNode* node) {
if (node->flags & Ast_Flag_No_Clone) return 0;
+ if (dont_copy_structs) {
+ if (node->kind == Ast_Kind_Struct_Type) return 0;
+ }
+
switch (node->kind) {
// List of nodes that should not be copied
case Ast_Kind_Global:
bh_arr_each(AstParam, param, sf->params) {
AstParam new_param = { 0 };
+
+ dont_copy_structs = 1;
new_param.local = (AstLocal *) ast_clone(a, param->local);
+ new_param.local->flags &= ~Ast_Flag_Param_Symbol_Dirty;
+ 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_new(global_heap_allocator, new_func->params, bh_arr_length(func->params));
bh_arr_each(AstParam, param, func->params) {
AstParam new_param;
+
+ dont_copy_structs = 1;
new_param.local = (AstLocal *) ast_clone(a, param->local);
+ new_param.local->flags &= ~Ast_Flag_Param_Symbol_Dirty;
+ 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;
}
convert_function_to_polyproc(func);
+
+ bh_arr_each(AstParam, param, func->params) {
+ param->local->flags |= Ast_Flag_Param_Symbol_Dirty;
+ }
+
return 1;
}
char *closest = find_closest_symbol_in_scope_and_parents(curr_scope, token->text);
token_toggle_end(token);
- onyx_report_error(token->pos, Error_Critical,
- "Unable to resolve symbol '%b'. Did you mean '%s'?",
- token->text,
- token->length,
- closest);
+ if (closest) onyx_report_error(token->pos, Error_Critical, "Unable to resolve symbol '%b'. Did you mean '%s'?", token->text, token->length, closest);
+ else onyx_report_error(token->pos, Error_Critical, "Unable to resolve symbol '%b'.", token->text, token->length);
return Symres_Error;
} else {
SYMRES(block, ((AstDoBlock *) *expr)->block);
break;
+ case Ast_Kind_Param:
+ if ((*expr)->flags & Ast_Flag_Param_Symbol_Dirty) {
+ assert((*expr)->token->type == Token_Type_Symbol);
+ *expr = make_symbol(context.ast_alloc, (*expr)->token);
+ SYMRES(expression, expr);
+ }
+ break;
+
default: break;
}