emit_compound_addref(emit, exp->type, size, exp_getvar(exp));
}
-ANN2(1)
-static void emit_exp_addref(const Emitter emit, /* const */ Exp exp,
+/*ANN2(1)
+static void emit_exp_addref(const Emitter emit, Exp exp,
m_int size) {
do {
emit_exp_addref1(emit, exp, size);
size += exp_size(exp);
} while ((exp = exp->next));
-}
+}*/
ANN static inline m_bool emit_exp1(const Emitter emit, const Exp e) {
const Exp next = e->next;
ANN static m_bool emit_prim_array_exp(const Emitter emit, const Type t, Exp e) {
do {
CHECK_BB(emit_exp1(emit, e));
+ emit_exp_addref1(emit, e, -t->size);
emit_regmove(emit, - t->size + t->actual_size);
} while((e = e->next));
return GW_OK;
const Type base = array_base_simple(type);
if(!base->actual_size) CHECK_BB(emit_exp(emit, e));
else CHECK_BB(emit_prim_array_exp(emit, base, e));
- emit_exp_addref(emit, e, -exp_totalsize(e));
m_uint count = 0;
do ++count;
while ((e = e->next));
emit_regpushmem4(emit, offset, 0);
}
emit_add_instr(emit, NoOp);
+ CHECK_BB(emit_exp_call1(emit, call->func->type->info->func, is_static_call(emit->gwion, call->func))); // is a ctor, is_static is true
return GW_OK;
}
const Func f = t->info->func;
if(unlikely(is_new_struct(f, exp_self(call)->type)))
emit_new_struct(emit, call);
- else if (f != emit->env->func || (f && f->value_ref->from->owner_class))
- CHECK_BB(prepare_call(emit, call));
- else CHECK_BB(emit_func_args(emit, call));
- CHECK_BB(emit_exp_call1(emit, f, is_static_call(emit->gwion, call->func)));
+ else {
+ if (f != emit->env->func || (f && f->value_ref->from->owner_class))
+ CHECK_BB(prepare_call(emit, call));
+ else CHECK_BB(emit_func_args(emit, call));
+ CHECK_BB(emit_exp_call1(emit, f, is_static_call(emit->gwion, call->func)));
+ }
return GW_OK;
}
ANN static m_bool emit_exp_call(const Emitter emit, const Exp_Call *exp_call) {
- const Exp e = exp_self(exp_call);
- if (exp_getvar(e)) emit_regmove(emit, SZ_INT);
CHECK_BB(_emit_exp_call(emit, exp_call));
- const Type t = exp_self(exp_call)->type;
+ const Exp e = exp_self(exp_call);
if (exp_getvar(e)) {
emit_regmove(emit, -exp_self(exp_call)->type->size);
- if(isa(t, emit->gwion->type[et_object]) > 0)
- emit_local_exp(emit, e);
- const Instr instr = emit_add_instr(emit, Reg2RegAddr);
- instr->m_val = -SZ_INT;
- } else {
- if (!is_func(emit->gwion, exp_call->func->type) && // is_callable
- tflag(e->type, tflag_struct))
- emit_regmove(emit, -SZ_INT);
+ const Instr instr = emit_add_instr(emit, RegPushMem4);
+ instr->m_val = emit_local_exp(emit, e);
}
return GW_OK;
}
static clear_fn* s_clear[3] = { clear_sn, clear_so, clear_ss };
static clear_fn*const* clear[3] = { n_clear, o_clear, s_clear };
-ANN static void hmapinfo_init(HMapInfo *const info, const Type types[], const Type key, const Type val) {
+ANN static void hmapinfo_init(HMapInfo *const info, const Type key, const Type val) {
info->key = key;
info->val = val;
info->sz = key->size + val->size;
type_addref(t);
}
HMapInfo *const hinfo = (HMapInfo*)t->nspc->class_data;
- hmapinfo_init(hinfo, env->gwion->type, key, val);
+ hmapinfo_init(hinfo, key, val);
if(hinfo->keyk + hinfo->valk) {
t->nspc->dtor = new_vmcode(env->gwion->mp, NULL, NULL, "@dtor", SZ_INT, true, false);
t->nspc->dtor->native_func = (m_uint)dict_clear_dtor;
const bool emit_addr) {
const Instr instr = emit_structmember(emit, v->type->size, emit_addr);
instr->m_val = v->from->offset;
- instr->m_val2 = 3;
if (!emit_addr) emit_regmove(emit, v->type->size - SZ_INT);
}
const Exp_Dot *member = (Exp_Dot *)data;
const Type t_base = member_type(emit->gwion, member->base->type);
const Value value = find_value(t_base, member->xid);
- if(!tflag(t_base, tflag_emit) /*&& emit->env->class_def != t_base*/) {
- ensure_emit(emit, t_base);
- }
+// if(!tflag(t_base, tflag_emit) /*&& emit->env->class_def != t_base*/)
+// ensure_emit(emit, t_base);
if (is_class(emit->gwion, value->type)) {
emit_pushimm(emit, (m_uint)value->type);
return GW_OK;
const m_uint scope = env->scope->depth;
env->scope->depth = 0;
vector_init(&v);
- Vector w = (Vector)&env->curr->info->value->ptr;
+ const Vector w = (Vector)&env->curr->info->value->ptr;
m_uint i = vector_size(w);
while (i-- > 1) vector_add(&v, vector_at(w, i));
+ VLEN(w) = 1;
const m_bool ret = traverse_func_def(env, fdef);
for (m_uint i = vector_size(&v) + 1; --i;)
- vector_add((Vector)&env->curr->info->value->ptr, vector_at(&v, i - 1));
+ vector_add(w, vector_at(&v, i - 1));
vector_release(&v);
env->scope->depth = scope;
return ret;
e->exp_type = ae_exp_unary;
unary->unary_type = unary_td;
unary->op = insert_symbol("new");
- unary->ctor.td = new_type_decl(env->gwion->mp, insert_symbol("auto"), bin->rhs->d.exp_unary.ctor.td->pos);
+ unary->ctor.td = cpy_type_decl(env->gwion->mp, bin->rhs->d.exp_unary.ctor.td);
unary->ctor.exp = lhs;
free_exp(env->gwion->mp, rhs);
return check_exp(env, e);
return ret;
}
-ANN static bool class_def_has_body(const Env env, Ast ast) {
+ANN static bool class_def_has_body(Ast ast) {
for(m_uint i = 0; i < ast->len; i++) {
const Section *section = mp_vector_at(ast, Section, i);
if (section->section_type == ae_section_stmt) {
if (!tflag(t, tflag_struct)) inherit(t);
if (cdef->body) {
CHECK_BB(env_body(env, cdef, check_body));
- if (cflag(cdef, cflag_struct) || class_def_has_body(env, cdef->body))
+ if (cflag(cdef, cflag_struct) || class_def_has_body(cdef->body))
set_tflag(t, tflag_ctor);
}
if (!GET_FLAG(cdef, abstract)) CHECK_BB(check_abstract(env, cdef));