From b2a8719fe3a4e55aad6662c78d4860ee60f826c3 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Astor?= Date: Sun, 10 Jan 2021 21:59:20 +0100 Subject: [PATCH] :art: use mstr for string objects --- src/emit/emit.c | 6 ++++-- src/import/import_cdef.c | 2 +- src/lib/foreach.c | 2 +- src/lib/object.c | 4 ++-- src/lib/ptr.c | 1 - src/lib/shred.c | 1 - src/lib/string.c | 12 ++++++++---- 7 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/emit/emit.c b/src/emit/emit.c index 46f6e18a..b8ee6971 100644 --- a/src/emit/emit.c +++ b/src/emit/emit.c @@ -347,7 +347,7 @@ ANN m_bool emit_array_extend(const Emitter emit, const Type t, const Exp e) { regpop(emit, SZ_INT); const Instr instr = emit_add_instr(emit, Reg2Reg); instr->m_val = -SZ_INT; - emit_add_instr(emit, RegAddRef); +// emit_add_instr(emit, RegAddRef); return GW_OK; } @@ -638,7 +638,7 @@ ANN static inline void interp_size(const Emitter emit, const Type t) { instr->m_val2 = SZ_INT; } -ANN static m_bool emit_interp(const Emitter emit, const Exp exp) { +ANN /*static*/ m_bool emit_interp(const Emitter emit, const Exp exp) { regpushi(emit, 0); Exp e = exp, next = NULL; do { @@ -895,6 +895,8 @@ ANN static m_bool emit_exp_call(const Emitter emit, const Exp_Call* exp_call) { if(isa(t, emit->gwion->type[et_function]) > 0) CHECK_BB(emit_exp_call1(emit, t->info->func)) else { +printf("call type %s %p\n", exp_call->func->type->name, actual_type(emit->gwion, exp_call->func->type)); +printf("call type %s %p\n", exp_call->func->type->name, exp_call->func->type); struct Op_Import opi = { .op=insert_symbol("@ctor"), .rhs=t, .data=(uintptr_t)exp_call, .pos=exp_self(exp_call)->pos, .op_type=op_exp }; CHECK_BB(op_emit(emit, &opi)) diff --git a/src/import/import_cdef.c b/src/import/import_cdef.c index 7bd34371..8d936416 100644 --- a/src/import/import_cdef.c +++ b/src/import/import_cdef.c @@ -99,7 +99,7 @@ ANN Type gwi_struct_ini(const Gwi gwi, const m_str name) { t->info->tuple = new_tupleform(gwi->gwion->mp, NULL); t->info->parent = NULL; t->info->cdef->cflag |= cflag_struct; - set_tflag(t, tflag_tmpl); + set_tflag(t, tflag_tmpl | tflag_ntmpl); } return type_finish(gwi, t); } diff --git a/src/lib/foreach.c b/src/lib/foreach.c index 56616401..3160d3ac 100644 --- a/src/lib/foreach.c +++ b/src/lib/foreach.c @@ -30,7 +30,7 @@ OP_CHECK(opck_foreach_scan) { GWION_IMPORT(foreach) { const Type t_foreach = gwi_struct_ini(gwi, "@Foreach:[A]"); - set_tflag(t_foreach, tflag_ntmpl | tflag_infer); + set_tflag(t_foreach, tflag_infer); GWI_BB(gwi_item_ini(gwi, "@internal", "val")) GWI_BB(gwi_item_end(gwi, ae_flag_none, num, 0)) GWI_BB(gwi_struct_end(gwi)) diff --git a/src/lib/object.c b/src/lib/object.c index f7ab81ac..fcea517f 100644 --- a/src/lib/object.c +++ b/src/lib/object.c @@ -41,13 +41,13 @@ M_Object new_object(MemPool p, const VM_Shred shred, const Type t) { M_Object new_string(MemPool p, const VM_Shred shred, const m_str str) { const M_Object o = new_object(p, shred, shred->info->vm->gwion->type[et_string]); - STRING(o) = s_name(insert_symbol(shred->info->vm->gwion->st, str)); + STRING(o) = mstrdup(p, str); return o; } M_Object new_string2(const struct Gwion_ *gwion, const VM_Shred shred, const m_str str) { const M_Object o = new_object(gwion->mp, shred, gwion->type[et_string]); - STRING(o) = str; + STRING(o) = mstrdup(gwion->mp, str); return o; } diff --git a/src/lib/ptr.c b/src/lib/ptr.c index 325d956f..896c3cdb 100644 --- a/src/lib/ptr.c +++ b/src/lib/ptr.c @@ -176,7 +176,6 @@ GWION_IMPORT(ptr) { GWI_BB(gwi_item_ini(gwi, "@internal", "@val")) GWI_BB(gwi_item_end(gwi, 0, num, 0)) GWI_BB(gwi_class_end(gwi)) - set_tflag(t_ptr, tflag_ntmpl); GWI_BB(gwi_oper_ini(gwi, "Ptr", NULL, NULL)) GWI_BB(gwi_oper_add(gwi, opck_ptr_scan)) GWI_BB(gwi_oper_end(gwi, "@scan", NULL)) diff --git a/src/lib/shred.c b/src/lib/shred.c index a52cc879..c67a0f3f 100644 --- a/src/lib/shred.c +++ b/src/lib/shred.c @@ -409,6 +409,5 @@ GWION_IMPORT(shred) { GWI_BB((gwi_item_end(gwi, ae_flag_const, num, 0))) GWI_BB(gwi_class_end(gwi)) SET_FLAG(t_typed, abstract | ae_flag_final); - set_tflag(t_typed, tflag_ntmpl); return GW_OK; } diff --git a/src/lib/string.c b/src/lib/string.c index 651f2d25..560694de 100644 --- a/src/lib/string.c +++ b/src/lib/string.c @@ -22,11 +22,15 @@ static INSTR(String_##name) { \ const M_Object rhs = *(M_Object*)REG(0); \ *(m_int*)REG(-SZ_INT) = action; \ } -describe_string_logical(eq, (lhs && rhs && STRING(lhs) == STRING(rhs)) || (!lhs && !rhs)) -describe_string_logical(neq, !(lhs && rhs && STRING(lhs) == STRING(rhs)) || (!lhs && !rhs)) +describe_string_logical(eq, (!strcmp(STRING(lhs), STRING(rhs)))) +describe_string_logical(neq, (strcmp(STRING(lhs), STRING(rhs)))) static CTOR(string_ctor) { - STRING(o) = ""; + STRING(o) = _mp_calloc(shred->info->vm->gwion->mp, 1); +} + +static DTOR(string_dtor) { + free_mstr(shred->info->vm->gwion->mp, STRING(o)); } ID_CHECK(check_funcpp) { @@ -360,7 +364,7 @@ static MFUN(string_erase) { GWION_IMPORT(string) { const Type t_string = gwi_class_ini(gwi, "string", NULL); gwi->gwion->type[et_string] = t_string; // use func - gwi_class_xtor(gwi, string_ctor, NULL); + gwi_class_xtor(gwi, string_ctor, string_dtor); GWI_BB(gwi_gack(gwi, t_string, gack_string)) gwi_item_ini(gwi, "@internal", "@data"); -- 2.43.0