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
}
const m_uint offset = emit_code_offset(emit);
if (f != emit->env->func || !is_static)
- regseti(emit, offset /*+ f->def->stack_depth + */ /*+ sizeof(frame_t)*/);
+ regseti(emit, offset /*+ f->def->stack_depth + sizeof(frame_t)*/);
const Instr instr = emit_call(emit, f, is_static);
instr->m_val = f->def->base->ret_type->size;
instr->m_val2 = offset;
ANN static inline VM_Code _emit_func_def_code(const Emitter emit,
const Func func) {
if(!strcmp(s_name(func->def->base->xid), "new"))
- return finalyze(emit, CtorReturn);
-// emit_add_instr(emit, RegPushMem);
+ emit_add_instr(emit, RegPushMem);
return !fbflag(func->def->base, fbflag_internal) ? finalyze(emit, FuncReturn)
: emit_internal(emit, func);
}
const Func f = exp_self(member)->type->info->func;
if(!strcmp(s_name(f->def->base->xid), "new")) {
- const Instr instr = emit_add_instr(emit, RegPushImm);
- instr->m_val = (m_uint)f->code;
+ if(f != emit->env->func) {
+ const Instr instr = emit_add_instr(emit, f->code ? RegPushImm : SetFunc);
+ instr->m_val = (m_uint)f->code ?: (m_uint)f;
+ }
return;
}
if (f->def->base->tmpl)
const Exp_Unary *unary = (Exp_Unary *)data;
CHECK_BB(emit_instantiate_object(emit, exp_self(unary)->type,
unary->ctor.td->array, 0));
-// 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);
+ // 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);
+ if (!strcmp(s_name(env->func->def->base->xid), "new")) {
+ if(stmt->val)
+ ERR_B(stmt_self(stmt)->pos,
+ _("'return' statement inside constructor function should have no expression"))
+ return GW_OK;
+ }
DECL_OB(const Type, ret_type,
= stmt->val ? check_exp(env, stmt->val) : env->gwion->type[et_void]);
if (!env->func->def->base->ret_type) {
&&baseaddr, &®toreg, &®toregother, &®toregaddr, &®toregderef,
&&structmember, &&structmemberfloat, &&structmemberother,
&&structmemberaddr, &&memsetimm, &&memaddimm, &&repeatidx, &&repeat,
- &®pushme, &®pushmaybe, &&ctorreturn, &&funcreturn, &&_goto, &&allocint,
+ &®pushme, &®pushmaybe, &&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;