diff --git a/base_arena.cpp b/base_arena.cpp index 1133cbe..83cb045 100644 --- a/base_arena.cpp +++ b/base_arena.cpp @@ -79,7 +79,6 @@ arena_push_size(Arena *a, size_t size) { #define push_struct_copy(a, T, p) (T *)push_copy(a, p, sizeof(T)) CORE_Static void * push_copy(Arena *a, void *p, size_t size) { - if (p == 0) return 0; void *result = arena_push_size(a, size); memory_copy(result, p, size); return result; diff --git a/base_data_structures.cpp b/base_data_structures.cpp index a960789..e3a0ad2 100644 --- a/base_data_structures.cpp +++ b/base_data_structures.cpp @@ -76,6 +76,7 @@ struct Array { allocator = a; data = allocate_array(a, T, size); cap = size; + len = 0; } Array copy(Allocator *a) { diff --git a/core_codegen_c_language.cpp b/core_codegen_c_language.cpp index b84a870..2b65aaf 100644 --- a/core_codegen_c_language.cpp +++ b/core_codegen_c_language.cpp @@ -834,9 +834,15 @@ compile_to_c_code() { String core_stringify(Ast *); For(pctx->ordered_decls) { + Ast *copy = ast_copy(it, 0); String r = core_stringify(it); + printf("\n-----REAL!!!------\n"); + printf("%s\n", r.str); + r = core_stringify(copy); + printf("\n-----COPY!!!------\n"); printf("%s\n", r.str); } + pctx->gen.reset(); #if 0 int di = 0; diff --git a/core_polymorph.cpp b/core_polymorph.cpp index 2aec667..7806db6 100644 --- a/core_polymorph.cpp +++ b/core_polymorph.cpp @@ -227,6 +227,7 @@ end_of_switch: #define ast_create_copy(parent_scope, T, ast) (T *)ast__create_copy(parent_scope, sizeof(T), ast) Ast *ast__create_copy(Ast_Scope *parent_scope, size_t size, Ast *ast) { + if (ast == 0) return 0; Ast *result = (Ast *)push_copy(pctx->perm, ast, size); result->parent_scope = parent_scope; result->di = ++pctx->unique_ids; @@ -242,9 +243,9 @@ Ast *ast_copy(Ast *ast, Ast_Scope *parent_scope) { Ast_Scope *src = (Ast_Scope *)ast; Ast_Scope *dst = ast_create_copy(parent_scope, Ast_Scope, src); - free_all_nodes(&dst->decls); + dst->decls = {}; For(src->decls) { - Ast_Decl *copy = (Ast_Decl *)ast_copy(it, dst); + Ast_Decl *copy = (Ast_Decl *)ast_copy(it, src); add(pctx->perm, &dst->decls, copy); } diff --git a/core_printer.cpp b/core_printer.cpp index 81babd8..b22c665 100644 --- a/core_printer.cpp +++ b/core_printer.cpp @@ -93,6 +93,7 @@ void core__stringify(Ast *ast) { Ast_Scope *n = (Ast_Scope *)ast; global_indent += 1; + genln("@%u", n->di); For(n->decls) { genln(""); core__stringify(it); @@ -109,11 +110,12 @@ void core__stringify(Ast *ast) { case AST_IDENT: { Ast_Atom *n = (Ast_Atom *)ast; - gen("%Q", n->intern_val); + gen("%Q@%u", n->intern_val, n->di); } break; + case AST_VALUE: { - Ast_Atom *n = (Ast_Atom *)ast; - gen("@%Q", n->pos->string); + Ast_Atom *n = (Ast_Atom *)ast; //@todo: proper value + gen("%Q@%u", n->pos->string, n->di); } break; case AST_INDEX: { @@ -121,13 +123,13 @@ void core__stringify(Ast *ast) { core__stringify(n->expr); gen("["); core__stringify(n->index); - gen("]"); + gen("]@%u", n->di); } break; case AST_UNARY: { Ast_Unary *n = (Ast_Unary *)ast; - gen("%Q", n->pos->string); core__stringify(n->expr); + gen("%Q@%u", n->pos->string, n->di); } break; case AST_BINARY: { @@ -135,6 +137,7 @@ void core__stringify(Ast *ast) { core__stringify(n->left); gen("%Q", n->pos->string); core__stringify(n->right); + gen("@%u", n->di); } break; case AST_CALL_ITEM: { @@ -148,7 +151,7 @@ void core__stringify(Ast *ast) { gen(" = "); } core__stringify(n->item); - + gen("@%u", n->di); } break; case AST_CALL: { @@ -160,6 +163,7 @@ void core__stringify(Ast *ast) { if (!n->exprs.is_last(&it)) gen(","); } gen(")"); + gen("@%u", n->di); } break; case AST_COMPOUND: { Ast_Call *n = (Ast_Call *)ast; @@ -174,6 +178,7 @@ void core__stringify(Ast *ast) { } global_indent -= 1; genln("}"); + gen("@%u", n->di); } break; case AST_TYPE_OF: @@ -200,6 +205,7 @@ void core__stringify(Ast *ast) { gen("("); core__stringify(n->expr); gen(")"); + gen("@%u", n->di); } break; case AST_SWITCH: { @@ -210,6 +216,7 @@ void core__stringify(Ast *ast) { core__stringify(it); } core__stringify(n->default_scope); + gen("@%u", n->di); } break; case AST_SWITCH_CASE: { @@ -219,6 +226,7 @@ void core__stringify(Ast *ast) { core__stringify(it); } core__stringify(n->scope); + gen("@%u", n->di); } break; case AST_VAR_UNPACK: { @@ -233,10 +241,12 @@ void core__stringify(Ast *ast) { case AST_PASS: { genln("pass"); + gen("@%u", ast->di); } break; case AST_BREAK: { genln("break"); + gen("@%u", ast->di); } break; case AST_NAMESPACE: {