return GW_OK;
}
-#define prim_unpack dummy_func
+ANN static m_bool prim_unpack(const Emitter emit NUSED, const Exp_Primary* primary) {
+// TODO err_msg
+ return primary->d.tuple.ok ? GW_OK : GW_ERROR;
+}
+
static const _exp_func prim_func[] = {
(_exp_func)prim_id, (_exp_func)prim_num, (_exp_func)prim_float, (_exp_func)prim_str,
(_exp_func)prim_array, (_exp_func)prim_gack, (_exp_func)prim_vec, (_exp_func)prim_vec,
m_bit exec = back->opcode;
m_uint val = back->m_val;
m_uint val2 = back->m_val2;
- back->opcode = eReg2Reg;
- back->m_val = SZ_INT;
- const Instr push = emit_add_instr(emit, RegPush);
- push->m_val = SZ_INT;
+ back->opcode = eRegPushMem;
+ back->m_val = back->m_val2 = 0;
const Instr instr = emit_add_instr(emit, (f_instr)(m_uint)exec);
instr->m_val = val;
instr->m_val2 = val2;
ANN static m_bool emit_exp_unary(const Emitter emit, const Exp_Unary* unary) {
struct Op_Import opi = { .op=unary->op, .data=(uintptr_t)unary };
if(unary->op != insert_symbol("spork") && unary->op != insert_symbol("fork") && unary->exp) {
- CHECK_BB(emit_exp(emit, unary->exp, 1))
+ CHECK_BB(emit_exp_pop_next(emit, unary->exp, 1))
opi.rhs = unary->exp->type;
}
return op_emit(emit, &opi);
ANN static m_bool optimize_taill_call(const Emitter emit, const Exp_Call* e) {
if(e->args) {
CHECK_BB(emit_exp(emit, e->args, 0))
- regpop(emit, SZ_INT);
+ regpop(emit, e->m_func->def->stack_depth);
emit_args(emit, e->m_func);
}
emit_add_instr(emit, Goto);
const Type type = cdef->base.type;
const Nspc nspc = type->nspc;
if(cdef->base.ext && cdef->base.ext->types)
- CHECK_BB(scanx_ext(emit->env, cdef, emit_parent, emit))
+ CHECK_BB(scanx_parent(cdef->base.type, emit_parent, emit))
SET_FLAG(type, emit);
nspc_allocdata(emit->gwion->mp, nspc);
emit_class_code(emit, type->name);
if(bin->rhs->type->e->d.func->def->base->tmpl)
fptr_instr(emit, bin->lhs->type->e->d.func, 2);
emit_add_instr(emit, int_r_assign);
- if((bin->lhs->type != t_lambda && isa(bin->lhs->type, t_fptr) < 0) &&
- GET_FLAG(bin->rhs->type->e->d.func, member)) {
+ if(isa(bin->lhs->type, t_fptr) < 0 && GET_FLAG(bin->rhs->type->e->d.func, member)) {
const Instr instr = emit_add_instr(emit, LambdaAssign);
instr->m_val = SZ_INT;
}
Exp_Binary* bin = (Exp_Binary*)data;
if(bin->rhs->type->e->d.func->def->base->tmpl &&
bin->rhs->type->e->d.func->def->base->tmpl->call) {
- struct FptrInfo info = { bin->lhs->type->e->d.func, bin->rhs->type->e->parent->e->d.func,
+ struct FptrInfo info = { bin->lhs->type->e->d.func, bin->rhs->type->e->parent->e->d.func,
bin->lhs, exp_self(bin)->pos };
- CHECK_BO(fptr_do(env, &info))
- bin->rhs->emit_var = 1;
- return bin->rhs->type;
-}
+ CHECK_BO(fptr_do(env, &info))
+ bin->rhs->emit_var = 1;
+ return bin->rhs->type;
+ }
struct FptrInfo info = { bin->lhs->type->e->d.func, bin->rhs->type->e->d.func,
bin->lhs, exp_self(bin)->pos };
CHECK_BO(fptr_do(env, &info))
GWI_BB(gwi_oper_ini(gwi, "@function", "@func_ptr", NULL))
GWI_BB(gwi_oper_add(gwi, opck_fptr_at))
GWI_BB(gwi_oper_emi(gwi, opem_func_assign))
- GWI_BB(gwi_oper_end(gwi, "@=>", NULL /*FuncAssign*/))
+ GWI_BB(gwi_oper_end(gwi, "@=>", NULL))
GWI_BB(gwi_oper_add(gwi, opck_fptr_cast))
GWI_BB(gwi_oper_emi(gwi, opem_fptr_cast))
GWI_BB(gwi_oper_end(gwi, "$", NULL))
describe_string_plus(Int_, SZ_INT, m_int,,
num_digit((m_uint)lhs), "%"INT_F, lhs)
describe_string_plus(Float_, SZ_FLOAT, m_float,,
- num_digit((m_uint)lhs) + 6, "%s%.4f", STRING(rhs), lhs)
+ num_digit((m_uint)lhs) + 6, "%.4f", lhs)
describe_string_plus(Complex_, SZ_COMPLEX, m_complex,,
num_digit((m_uint)creal(lhs)) + num_digit((m_uint)cimag(lhs)) + 18, "#(%.4f, %.4f)",
creal(lhs), cimag(lhs))
}
++i;
} while((e = e->next));
+ bin->rhs->d.exp_primary.d.tuple.ok = 1;
return bin->lhs->type;
}
return opck_at_object_tuple(env, data, mut);
if(arg || e)
ERR_O(exp_self(exp)->pos, _("argument number does not match for lambda"))
l->def = new_func_def(env->gwion->mp, new_func_base(env->gwion->mp, NULL, l->name, l->args),
- l->code, 0, loc_cpy(env->gwion->mp, exp_self(exp)->pos));
+ l->code, 0, loc_cpy(env->gwion->mp, loc_cpy(env->gwion->mp, exp_self(exp)->pos)));
CHECK_BO(traverse_func_def(env, l->def))
if(env->class_def)
SET_FLAG(l->def, member);
return traverse_cdef(env, cdef);
}
if(cdef->base.ext)
- CHECK_BB(env_ext(env, cdef, check_class_parent))
+ CHECK_BB(scanx_parent(cdef->base.type, check_class_parent, env))
else if(!type->e->parent)
type->e->parent = t_object;
inherit(type);
ANN static void cpy_exp_if(MemPool p, Exp_If *a, const Exp_If *src) {
a->cond = cpy_exp(p, src->cond);
- a->if_exp = cpy_exp(p, src->if_exp);
+ if(src->if_exp)
+ a->if_exp = cpy_exp(p, src->if_exp);
if(src->else_exp)
a->else_exp = cpy_exp(p, src->else_exp);
}
return ((Exp_Unary*)opi->data)->nspc;
}
+ANN static inline Nspc ensure_nspc(SymTable *st, const struct Op_Import* opi) {
+ DECL_OO(Nspc, nspc, = get_nspc(st, opi))
+ while(!nspc->info->op_map.ptr)
+ nspc = nspc->parent;
+ return nspc;
+}
+
ANN m_bool op_emit(const Emitter emit, const struct Op_Import* opi) {
- Nspc nspc = get_nspc(emit->gwion->st, opi);
- if(!nspc || !nspc->info->op_map.ptr)
+ Nspc nspc = ensure_nspc(emit->gwion->st, opi);
+ if(!nspc)
return GW_OK;
Type l = opi->lhs;
do {
return GW_OK;
SET_FLAG(cdef->base.type, scan1);
if(cdef->base.ext)
- CHECK_BB(env_ext(env, cdef, scan1_parent))
+ CHECK_BB(scanx_parent(cdef->base.type, scan1_parent, env))
if(cdef->body)
CHECK_BB(env_body(env, cdef, scan1_section))
SET_FLAG(cdef, scan1);
return GW_OK;
SET_FLAG(cdef->base.type, scan2);
if(cdef->base.ext)
- CHECK_BB(env_ext(env, cdef, scan2_class_parent))
+ CHECK_BB(scanx_parent(cdef->base.type, scan2_class_parent, env))
if(cdef->body)
CHECK_BB(env_body(env, cdef, scan2_section))
return GW_OK;
return ret;
}
-#undef scanx_ext
-ANN m_bool
-scanx_ext(const Env e, const Class_Def c, const _exp_func f, void* d) {
- DECL_BB(const m_int, scope, = _push(e, c))
- const m_bool ret = f(d, c);
- _pop(e, c, scope);
- return ret;
-}
#undef scanx_parent
__attribute__((returns_nonnull))