From: fennecdjay Date: Wed, 26 Oct 2022 12:37:29 +0000 (+0200) Subject: WIP on ctor/and/stuff: 414129d0 :art: Improve code->instr X-Git-Tag: nightly~207^2~116 X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=4bb666cfa7c417aa34e925fd919c80d5e52ce9e1;p=gwion.git WIP on ctor/and/stuff: 414129d0 :art: Improve code->instr --- 4bb666cfa7c417aa34e925fd919c80d5e52ce9e1 diff --cc src/emit/emit.c index f213a2b6,f213a2b6..aab4a820 --- a/src/emit/emit.c +++ b/src/emit/emit.c @@@ -975,11 -975,11 +975,17 @@@ ANN static m_bool struct_finish(const E const Type t = decl->type; const bool emit_addr = exp_getvar(exp_self(decl)); if (decl->args) { ++//exp_setvar(decl->args, emit_addr); const Instr instr = (Instr)vector_back(&emit->code->instr); CHECK_BB(emit_exp(emit, decl->args)); if (emit_addr) { emit_regmove(emit, -t->size); -- vector_add(&emit->code->instr, (m_uint)instr); ++// emit_regmove(emit, SZ_INT -t->size); ++// const Instr instr = emit_add_instr(emit, Reg2RegAddr); ++ const Instr instr = emit_add_instr(emit, RegPushMem4); ++// emit_add_instr(emit, EOC); ++// instr->m_val = -SZ_INT; ++// vector_add(&emit->code->instr, (m_uint)instr); } return GW_OK; } @@@ -2004,6 -2004,6 +2010,7 @@@ DECL_EXP_FUNC(emit, m_bool, Emitter ANN2(1) /*static */ m_bool emit_exp(const Emitter emit, /* const */ Exp e) { Exp exp = e; do { ++ e->start = emit_code_size(emit); if (emit->info->debug && emit->status.line < e->pos.first.line) { const Instr instr = emit_add_instr(emit, DebugLine); instr->m_val = emit->status.line = e->pos.first.line; diff --cc src/parse/scan0.c index 2ffa7034,2ffa7034..13fc1d60 --- a/src/parse/scan0.c +++ b/src/parse/scan0.c @@@ -519,10 -519,10 +519,24 @@@ ANN Ast spread_class(const Env env, con static OP_EMIT(opem_struct_assign) { const Exp_Binary *bin = data; const Type t = bin->lhs->type; ++ const Exp e = exp_self(bin); ++ if(unlikely(exp_getvar(e))) { ++ for(m_int i = vector_size(&emit->code->instr); --i > e->start && i;) { ++ const Instr instr = (Instr)vector_at(&emit->code->instr, i-1); ++ free_instr(emit->gwion, instr); ++ } ++ VLEN(&emit->code->instr) = e->start; ++ exp_setvar(bin->lhs, true); ++ CHECK_BB(emit_exp(emit, bin->lhs)); ++ CHECK_BB(emit_exp(emit, bin->rhs)); ++ emit_add_instr(emit, Assign); ++ return GW_OK; ++ } ++// need to add ref counting (release former) if(t->size == SZ_INT) emit_add_instr(emit, int_r_assign); else if(t->size == SZ_FLOAT) emit_add_instr(emit, float_r_assign); else { -- const Instr instr = emit_add_instr(emit, Reg2RegOther); ++ const Instr instr = (Instr)emit_add_instr(emit, Reg2RegOther); instr->m_val = -(t->size + SZ_INT); instr->m_val2 = t->size; emit_regmove(emit, -SZ_INT); @@@ -531,8 -531,8 +545,15 @@@ return GW_OK; } ++ANN static OP_CHECK(opck_struct_assign) { ++ CHECK_NN(opck_rassign(env, data)); ++ Exp_Binary *bin = data; ++ exp_setnomut(exp_self(bin), true); ++ return bin->lhs->type; ++} ++ ANN static void scan0_struct_assign(const Env env, const Type t) { -- struct Op_Func opfunc = {.ck = opck_rassign, .em = opem_struct_assign }; ++ struct Op_Func opfunc = {.ck = opck_struct_assign, .em = opem_struct_assign }; struct Op_Import opi = { .op = insert_symbol(":=>"), .lhs = t, .rhs = t, .ret = t, .func = &opfunc}; add_op(env->gwion, &opi);