eRepeat,
eRegPushMe,
eRegPushMaybe,
++ eCtorReturn,
eFuncReturn,
eGoto,
eAllocWord,
#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
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");
Repeat~pc
RegPushMe
RegPushMaybe
++CtorReturn
FuncReturn
Goto~pc
AllocWord~u
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);
}
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))
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))
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))
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;
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;
}
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,
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;
}
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) {
&&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,
*(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;