From: Jérémie Astor Date: Wed, 21 Jul 2021 16:55:26 +0000 (+0200) Subject: On dev: EffectIgnore+CtorStuff X-Git-Tag: nightly~528 X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=6ac82d07025a0f056dd548a0dc4fb1e63ce424fe;p=gwion.git On dev: EffectIgnore+CtorStuff --- 6ac82d07025a0f056dd548a0dc4fb1e63ce424fe diff --cc include/opcode.h index 3b2c28ed,3b2c28ed..281fc9cd --- a/include/opcode.h +++ b/include/opcode.h @@@ -30,6 -30,6 +30,7 @@@ enum eRepeat, eRegPushMe, eRegPushMaybe, ++ eCtorReturn, eFuncReturn, eGoto, eAllocWord, @@@ -248,6 -248,6 +249,7 @@@ #define Repeat (f_instr)eRepeat #define RegPushMe (f_instr)eRegPushMe #define RegPushMaybe (f_instr)eRegPushMaybe ++#define CtorReturn (f_instr)eCtorReturn #define FuncReturn (f_instr)eFuncReturn #define Goto (f_instr)eGoto #define AllocWord (f_instr)eAllocWord @@@ -601,6 -601,6 +603,10 @@@ ANN static inline void dump_opcodes(con gw_out("{Y}┃{0}{-}% 4lu{0}: RegPushMaybe", j); gw_out("\n"); break; ++ case eCtorReturn: ++ gw_out("{Y}┃{0}{-}% 4lu{0}: CtorReturn ", j); ++ gw_out("\n"); ++ break; case eFuncReturn: gw_out("{Y}┃{0}{-}% 4lu{0}: FuncReturn ", j); gw_out("\n"); diff --cc opcode.txt index 2bd04b75,2bd04b75..b173ce4c --- a/opcode.txt +++ b/opcode.txt @@@ -27,6 -27,6 +27,7 @@@ RepeatIdx~pc~ Repeat~pc RegPushMe RegPushMaybe ++CtorReturn FuncReturn Goto~pc AllocWord~u diff --cc src/emit/emit.c index f1ee3c5e,f1ee3c5e..e0a3f600 --- a/src/emit/emit.c +++ b/src/emit/emit.c @@@ -2560,7 -2560,7 +2560,8 @@@ ANN static VM_Code emit_internal(const ANN static inline VM_Code _emit_func_def_code(const Emitter emit, const Func func) { if(!strcmp(s_name(func->def->base->xid), "new")) -- emit_add_instr(emit, RegPushMem); ++ return finalyze(emit, CtorReturn); ++// emit_add_instr(emit, RegPushMem); return !fbflag(func->def->base, fbflag_internal) ? finalyze(emit, FuncReturn) : emit_internal(emit, func); } diff --cc src/lib/engine.c index a984cf3a,a984cf3a..3f6d8c2a --- a/src/lib/engine.c +++ b/src/lib/engine.c @@@ -78,7 -78,7 +78,7 @@@ static INSTR(PredicateCheck) ANN static m_bool import_core_libs(const Gwi gwi) { gwidoc(gwi, "one type to rule them all."); -- const Type t_class = gwi_mk_type(gwi, "@Class", SZ_INT, NULL); ++ const Type t_class = gwi_mk_type(gwi, "Class", SZ_INT, NULL); set_tflag(t_class, tflag_infer); GWI_BB(gwi_set_global_type(gwi, t_class, et_class)) GWI_BB(gwi_gack(gwi, t_class, gack_class)) @@@ -194,7 -194,7 +194,7 @@@ GWI_BB(import_ref(gwi)) gwidoc(gwi, "Operators class types."); -- GWI_BB(gwi_oper_ini(gwi, "@Class", "@Class", "int")) ++ GWI_BB(gwi_oper_ini(gwi, "Class", "Class", "int")) GWI_BB(gwi_oper_end(gwi, "==", int_eq)) GWI_BB(gwi_oper_end(gwi, "!=", int_neq)) GWI_BB(gwi_oper_end(gwi, ">=", instr_class_ge)) @@@ -214,13 -214,13 +214,13 @@@ GWI_BB(gwi_oper_end(gwi, "@dot", NULL)) gwidoc(gwi, "allow static access."); -- GWI_BB(gwi_oper_ini(gwi, "@Class", (m_str)OP_ANY_TYPE, NULL)) ++ GWI_BB(gwi_oper_ini(gwi, "Class", (m_str)OP_ANY_TYPE, NULL)) GWI_BB(gwi_oper_add(gwi, opck_object_dot)) GWI_BB(gwi_oper_emi(gwi, opem_object_dot)) GWI_BB(gwi_oper_end(gwi, "@dot", NULL)) gwidoc(gwi, "Allow binary call to constructors."); -- GWI_BB(gwi_oper_ini(gwi, (m_str)OP_ANY_TYPE, "@Class", NULL)) ++ GWI_BB(gwi_oper_ini(gwi, (m_str)OP_ANY_TYPE, "Class", NULL)) GWI_BB(gwi_oper_add(gwi, opck_class_call)) GWI_BB(gwi_oper_end(gwi, "=>", NULL)) diff --cc src/lib/opfunc.c index ac3c17f9,ac3c17f9..0d3cfd7b --- a/src/lib/opfunc.c +++ b/src/lib/opfunc.c @@@ -101,8 -101,8 +101,9 @@@ OP_CHECK(opck_new) DECL_ON(const Type, t, = known_type(env, unary->ctor.td)); if(unary->ctor.exp) { const Exp self = exp_self(unary); -- const Exp args = unary->ctor.exp; -- const Exp base = new_exp_unary2(env->gwion->mp, unary->op, unary->ctor.td, NULL, self->pos); ++ const Exp args = cpy_exp(env->gwion->mp, unary->ctor.exp); ++ const Exp base = new_exp_unary2(env->gwion->mp, unary->op, unary->ctor.td, unary->ctor.exp, self->pos); ++base->type = t; const Exp func = new_exp_dot(env->gwion->mp, base, insert_symbol("new"), self->pos); self->d.exp_call.func = func; self->d.exp_call.args = args; @@@ -127,6 -127,6 +128,9 @@@ OP_EMIT(opem_new) const Exp_Unary *unary = (Exp_Unary *)data; CHECK_BB(emit_instantiate_object(emit, exp_self(unary)->type, unary->ctor.td->array, 0)); -- emit_gc(emit, -SZ_INT); ++// we don't need gc for arrays? ++// also when in rewrote exp ++// if(!(unary->ctor.td->array || unary->ctor.exp)) ++// emit_gc(emit, -SZ_INT); return GW_OK; } diff --cc src/parse/check.c index 9b95ebd7,9b95ebd7..877a2608 --- a/src/parse/check.c +++ b/src/parse/check.c @@@ -1220,6 -1220,6 +1220,9 @@@ ANN static m_bool check_stmt_return(con if (!env->func) ERR_B(stmt_self(stmt)->pos, _("'return' statement found outside function definition")) ++ if (!strcmp(s_name(env->func->def->base->xid), "new")) ++ ERR_B(stmt_self(stmt)->pos, ++ _("'return' statement found inside constructor function")) if (env->scope->depth == 1) // so ops no dot set scope->depth ? set_fflag(env->func, fflag_return); DECL_OB(const Type, ret_type, @@@ -1834,6 -1834,6 +1837,8 @@@ ANN static inline void check_unhandled( for (m_uint j = 0; j < m_vector_size(w); j++) { struct ScopeEffect eff; m_vector_get(w, j, &eff); ++ if(s_name(eff.sym)[0] == '!') ++ continue; gwerr_secondary("Unhandled effect", env->name, eff.pos); env->context->error = false; } diff --cc src/plug.c index 97303a1a,97303a1a..9b394e5d --- a/src/plug.c +++ b/src/plug.c @@@ -115,6 -115,6 +115,9 @@@ ANN void set_module(const struct Gwion return; } } ++ const Plug plug = new_plug(gwion->mp, name); ++ plug->self = ptr; ++ map_set(map, (m_uint)name, (m_uint)plug); } ANN void plug_run(const struct Gwion_ *gwion, const Map mod) { diff --cc src/vm/vm.c index 05b218ed,05b218ed..f1db7ba3 --- a/src/vm/vm.c +++ b/src/vm/vm.c @@@ -412,7 -412,7 +412,7 @@@ vm_run(const VM *vm) { // lgtm [cpp/use &&baseaddr, &®toreg, &®toregother, &®toregaddr, &®toregderef, &&structmember, &&structmemberfloat, &&structmemberother, &&structmemberaddr, &&memsetimm, &&memaddimm, &&repeatidx, &&repeat, -- &®pushme, &®pushmaybe, &&funcreturn, &&_goto, &&allocint, ++ &®pushme, &®pushmaybe, &&ctorreturn, &&funcreturn, &&_goto, &&allocint, &&allocfloat, &&allocother, &&intplus, &&intminus, &&intmul, &&intdiv, &&intmod, &&intplusimm, &&intminusimm, &&intmulimm, &&intdivimm, &&intmodimm, @@@ -584,6 -584,6 +584,9 @@@ *(m_uint *)reg = gw_rand((uint32_t *)vm->rand) > (UINT32_MAX / 2); reg += SZ_INT; DISPATCH(); ++ctorreturn: ++*(M_Object*)(reg) = *(M_Object*)mem; ++reg += SZ_INT; funcreturn : { register frame_t frame = *(frame_t *)(mem - sizeof(frame_t)); bytecode = (code = frame.code)->bytecode;