From 7b2523044458cc2e6a74b441bccd91e31c984b0f Mon Sep 17 00:00:00 2001 From: fennecdjay Date: Sat, 14 Sep 2019 14:33:54 +0200 Subject: [PATCH] :bug: More and more AFL stuff (the hard way) --- src/emit/emit.c | 18 ++++++++++-------- src/lib/func.c | 15 +++++++-------- src/lib/string.c | 2 +- src/lib/tuple.c | 1 + src/parse/check.c | 4 ++-- src/parse/cpy_ast.c | 3 ++- src/parse/operator.c | 11 +++++++++-- src/parse/scan1.c | 2 +- src/parse/scan2.c | 2 +- src/parse/scanx.c | 8 -------- 10 files changed, 34 insertions(+), 32 deletions(-) diff --git a/src/emit/emit.c b/src/emit/emit.c index 292d4f91..ca8dd7b6 100644 --- a/src/emit/emit.c +++ b/src/emit/emit.c @@ -591,7 +591,11 @@ ANN static m_bool prim_gack(const Emitter emit, const Exp_Primary* primary) { 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, @@ -988,10 +992,8 @@ ANN m_bool emit_exp_call1(const Emitter emit, const Func f) { 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; @@ -1095,7 +1097,7 @@ ANN m_bool emit_exp_spork(const Emitter emit, const Exp_Unary* unary) { 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); @@ -1189,7 +1191,7 @@ ANN static m_bool emit_stmt_code(const Emitter emit, const Stmt_Code stmt) { 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); @@ -1852,7 +1854,7 @@ ANN static m_bool emit_class_def(const Emitter emit, const Class_Def cdef) { 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); diff --git a/src/lib/func.c b/src/lib/func.c index dde379b3..b9f30fbb 100644 --- a/src/lib/func.c +++ b/src/lib/func.c @@ -49,8 +49,7 @@ static OP_EMIT(opem_func_assign) { 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; } @@ -200,12 +199,12 @@ static OP_CHECK(opck_fptr_at) { 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)) @@ -304,7 +303,7 @@ GWION_IMPORT(func) { 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)) diff --git a/src/lib/string.c b/src/lib/string.c index fbf31cf0..4cee1dd1 100644 --- a/src/lib/string.c +++ b/src/lib/string.c @@ -149,7 +149,7 @@ describe_string_plus(,SZ_INT, M_Object, release(lhs, shred), 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)) diff --git a/src/lib/tuple.c b/src/lib/tuple.c index 12505a68..e2a4c660 100644 --- a/src/lib/tuple.c +++ b/src/lib/tuple.c @@ -147,6 +147,7 @@ static OP_CHECK(opck_at_tuple) { } ++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); diff --git a/src/parse/check.c b/src/parse/check.c index f5ba6d97..53232bfa 100644 --- a/src/parse/check.c +++ b/src/parse/check.c @@ -761,7 +761,7 @@ ANN static Type check_lambda_call(const Env env, const Exp_Call *exp) { 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); @@ -1363,7 +1363,7 @@ ANN m_bool check_class_def(const Env env, const Class_Def cdef) { 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); diff --git a/src/parse/cpy_ast.c b/src/parse/cpy_ast.c index 3b16a26e..ef9c993d 100644 --- a/src/parse/cpy_ast.c +++ b/src/parse/cpy_ast.c @@ -172,7 +172,8 @@ ANN static void cpy_exp_postfix(MemPool p, Exp_Postfix *a, const Exp_Postfix *sr 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); } diff --git a/src/parse/operator.c b/src/parse/operator.c index 43cd9407..169df4d2 100644 --- a/src/parse/operator.c +++ b/src/parse/operator.c @@ -216,9 +216,16 @@ ANN static Nspc get_nspc(SymTable *st, const struct Op_Import* opi) { 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 { diff --git a/src/parse/scan1.c b/src/parse/scan1.c index 950dff75..4fa3d3c4 100644 --- a/src/parse/scan1.c +++ b/src/parse/scan1.c @@ -390,7 +390,7 @@ ANN m_bool scan1_class_def(const Env env, const Class_Def cdef) { 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); diff --git a/src/parse/scan2.c b/src/parse/scan2.c index 80e9f934..b64bc2bb 100644 --- a/src/parse/scan2.c +++ b/src/parse/scan2.c @@ -527,7 +527,7 @@ ANN m_bool scan2_class_def(const Env env, const Class_Def cdef) { 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; diff --git a/src/parse/scanx.c b/src/parse/scanx.c index f3bfd295..4f24d268 100644 --- a/src/parse/scanx.c +++ b/src/parse/scanx.c @@ -45,14 +45,6 @@ scanx_body(const Env e, const Class_Def c, const _exp_func f, void* d) { 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)) -- 2.43.0