const m_uint size = v->type->size;
if(isa(v->type, t_class) < 0) {
if(isa(v->type, t_union) < 0) {
-printf("%s %lu %p·\n", v->name, v->offset, v->owner->info->class_data);
const Instr instr = emit_kind(emit, size, emit_var, dotstatic);
instr->m_val = (m_uint)(v->owner->info->class_data + v->offset);
instr->m_val2 = size;
pop->m_val = depth;
const Instr spork = emit_add_instr(emit, SporkFunc);
spork->m_val = depth + SZ_INT;
+ spork->m_val2 = -SZ_INT;
}
static inline void stack_alloc(const Emitter emit) {
ANN m_bool emit_exp_spork(const Emitter emit, const Exp_Unary* unary) {
const m_bool is_spork = unary->op == op_spork;
- if(unary->code) {
+ const Func f = !unary->code ? unary->exp->d.exp_call.m_func : NULL;
+ if(!f) {
emit_add_instr(emit, RegPushImm);
push_spork_code(emit, is_spork ? SPORK_CODE_PREFIX : FORK_CODE_PREFIX, unary->code->pos);
if(!SAFE_FLAG(emit->env->func, member))
const Instr ini = emit_add_instr(emit, unary->op == op_spork ? SporkIni : ForkIni);
ini->m_val = (m_uint)code;
ini->m_val2 = is_spork;
- if(unary->code) {
+ if(!f) {
if(!is_spork) {
const Instr push = emit_add_instr(emit, RegPush);
push->m_val = SZ_INT;
const Instr spork = emit_add_instr(emit, is_spork ? SporkExp : ForkEnd);
spork->m_val = emit->code->stack_depth;
} else {
- const Func f = unary->exp->d.exp_call.m_func;
- emit_exp_spork_finish(emit, f->def->stack_depth);
+ if(GET_FLAG(f, member) && isa(actual_type(f->value_ref->type), t_fptr) > 0) {
+ const m_uint depth = f->def->stack_depth;
+ const Instr pop = emit_add_instr(emit, RegPop);
+ pop->m_val = depth;
+ emit_add_instr(emit, RegPushMem);
+ const Instr arg = emit_add_instr(emit, SporkFunc);
+ arg->m_val = depth - SZ_INT;
+ const Instr cpy = emit_add_instr(emit, SporkFunc);
+ cpy->m_val = SZ_INT;
+ cpy->m_val2 = -SZ_INT;
+ const Instr cpy1 = emit_add_instr(emit, SporkFunc);
+ cpy1->m_val = SZ_INT;
+ cpy1->m_val2 = SZ_INT;
+ const Instr code = emit_add_instr(emit, DotMember);
+ code->m_val = f->value_ref->offset;
+ } else
+ emit_exp_spork_finish(emit, f->def->stack_depth);
const Instr end = emit_add_instr(emit, is_spork ? SporkEnd : ForkEnd);
end->m_val2 = f->def->base->ret_type->size;
}
SET_FLAG(stmt->l->self->d.exp_decl.list->self->value, enum);
}
if(stmt->xid){
-// if(!emit->env->class_def) {
const Instr instr = emit_add_instr(emit, RegPop);
instr->m_val = !GET_FLAG(stmt, static) ? SZ_INT : SZ_INT*2;
-/*
- } else if(!GET_FLAG(stmt, static)) {
- const Instr instr = emit_add_instr(emit, RegPop);
- instr->m_val = SZ_INT;
- printf("stmt->o %lu\n", stmt->o);
- }
-*/
}
emit_union_offset(stmt->l, stmt->o);
if(stmt->xid || stmt->type_xid || global)
emit_push_scope(emit);
emit->env->func = func;
CHECK_BB(emit_func_def_body(emit, func_def))
-// if(GET_FLAG(func_def, variadic) && !emit->env->func->variadic)
if(GET_FLAG(func_def, variadic)) {
if(!emit->env->func->variadic)
ERR_B(func_def->pos, "invalid variadic use")
if(!GET_FLAG(func, empty))
ERR_B(func_def->pos, "invalid variadic use")
-//printf("opcode %p %p %p\n", emit->env->func->variadic->execute, VarargTop, VarargEnd);
-
-/*
- if(emit->env->func->variadic->execute == VarargIni ||
- emit->env->func->variadic->execute == VarargTop
-) {
-//assert(emit->env->func->variadic->execute == VarargTop);
-//free_code(emit->gwion->p, emit->code);
-// emit_func_def_code(emit, func);
-// REM_REF(func->code, emit->gwion);
-// emit->env->func = former;
-// emit_pop_code(emit);
- ERR_B(func_def->pos, "invalid variadic use")
- }
-*/
}
emit_func_def_return(emit);
emit_func_def_code(emit, func);
while((body = body->next));
}
emit_class_finish(emit, nspc);
+ SET_FLAG(class_def->base.type->nspc->pre_ctor, ctor);
emit_class_pop(emit);
SET_FLAG(type, emit);
return GW_OK;
}
if(isa(type, env->class_def) < 0 && !GET_FLAG(func, global))
ERR_B(var->pos, "can't use non global fptr of other class.")
- if(GET_FLAG(func, member)) {
- if(GET_FLAG(v, static))
+ if(GET_FLAG(func, member) && GET_FLAG(v, static))
ERR_B(var->pos, "can't use static variables for member function.")
- if(!GET_FLAG(v, member))
- ERR_B(var->pos, "can't use member variables for static function.")
- }
return GW_OK;
}
ERR_O(member->base->pos,
"type '%s' does not have members - invalid use in dot expression of %s",
the_base->name, str)
- if(!strcmp(str, "this") && base_static)
+ if(member->xid == insert_symbol("this") && base_static)
ERR_O(exp_self(member)->pos,
"keyword 'this' must be associated with object instance...")
const Value value = find_value(the_base, member->xid);