From: fennecdjay Date: Tue, 14 May 2019 17:18:45 +0000 (+0200) Subject: :bug: Fix some shreduler and vararg related bugs X-Git-Tag: nightly~2488 X-Git-Url: http://10.11.0.4:5575/?a=commitdiff_plain;h=e131ecad3b4d5e43e50d186a2ee15e530e42bd29;p=gwion.git :bug: Fix some shreduler and vararg related bugs --- diff --git a/include/gwion_all.h b/include/gwion_all.h new file mode 100644 index 00000000..c84301b5 --- /dev/null +++ b/include/gwion_all.h @@ -0,0 +1,41 @@ +#ifndef __GWION_ALL +#include "gwion_util.h" +#include "gwion_ast.h" +#include "oo.h" +#include "arg.h" +#include "constant.h" +#include "nspc.h" +#include "env.h" +#include "vm.h" +#include "context.h" +#include "escape.h" +#include "func.h" +#include "driver.h" +#include "compile.h" +#include "gwiondata.h" +#include "gwion.h" +#include "instr.h" +#include "gack.h" +#include "emit.h" +#include "object.h" +#include "import.h" +#include "gwi.h" +#include "lang_private.h" +#include "memoize.h" +#include "array.h" +#include "opcode.h" +#include "operator.h" +#include "optim.h" +#include "parse.h" +#include "plug.h" +#include "shreduler_private.h" +#include "soundinfo.h" +#include "switch.h" +#include "template.h" +#include "traverse.h" +#include "type.h" +#include "ugen.h" +#include "value.h" +#include "vararg.h" +#include "engine.h" +#endif diff --git a/include/import.h b/include/import.h index b454618c..56a36330 100644 --- a/include/import.h +++ b/include/import.h @@ -69,6 +69,7 @@ ANN Type_Decl* str2decl(const Env, const m_str, m_uint* depth); OP_CHECK(opck_const_rhs); OP_CHECK(opck_unary_meta); OP_CHECK(opck_unary_meta2); +OP_CHECK(opck_unary_meta2_uniq); OP_CHECK(opck_unary); OP_CHECK(opck_post); OP_CHECK(opck_rassign); diff --git a/src/emit/emit.c b/src/emit/emit.c index e915e548..d6f656f7 100644 --- a/src/emit/emit.c +++ b/src/emit/emit.c @@ -1607,6 +1607,10 @@ ANN static inline m_bool emit_member(const Emitter emit, const Value v, const ui } ANN static m_bool emit_exp_dot(const Emitter emit, const Exp_Dot* member) { + if(member->xid == insert_symbol("vararg")) { // TODO prohibit this? + emit_add_instr(emit, RegPushImm); + return GW_OK; + } if(is_special(member->t_base) > 0) return emit_exp_dot_special(emit, member); const Value value = find_value(actual_type(member->t_base), member->xid); diff --git a/src/lib/func.c b/src/lib/func.c index 05f8773b..a757862c 100644 --- a/src/lib/func.c +++ b/src/lib/func.c @@ -76,7 +76,7 @@ ANN2(1,3,4) m_bool check_lambda(const Env env, const Type owner, ERR_B(exp_self(l)->pos, "argument number does not match for lambda") l->def = new_func_def(env->gwion->mp, new_func_base(env->gwion->mp, def->base->td, l->name, l->args), l->code, def->flag, loc_cpy(env->gwion->mp, def->pos)); - const m_bool ret = traverse_func_def(env, l->def); + CHECK_BB(traverse_func_def(env, l->def)) arg = l->args; while(arg) { arg->td = NULL; @@ -84,7 +84,7 @@ ANN2(1,3,4) m_bool check_lambda(const Env env, const Type owner, } if(owner) env_pop(env, scope); - return ret; + return GW_OK; } static OP_CHECK(opck_fptr_at) { @@ -212,6 +212,5 @@ GWION_IMPORT(func) { register_freearg(gwi, SporkIni, freearg_xork); register_freearg(gwi, ForkIni, freearg_xork); register_freearg(gwi, DotTmpl, freearg_dottmpl); - gwi_reserve(gwi, "__func__"); return GW_OK; } diff --git a/src/lib/opfunc.c b/src/lib/opfunc.c index 28934e67..18f6293f 100644 --- a/src/lib/opfunc.c +++ b/src/lib/opfunc.c @@ -60,6 +60,14 @@ OP_CHECK(opck_unary_meta2) { return t_int; } +OP_CHECK(opck_unary_meta2_uniq) { + const Exp_Unary* unary = (Exp_Unary*)data; + CHECK_OO(opck_unary_meta2(env, data)) + if(unary->exp->next) + ERR_N(stmt_self(unary)->pos, "fuck!!") + return t_int; +} + OP_CHECK(opck_unary) { const Exp_Unary* unary = (Exp_Unary*)data; if(unary->exp->meta != ae_meta_var) diff --git a/src/lib/prim.c b/src/lib/prim.c index 5b3119be..629c75e1 100644 --- a/src/lib/prim.c +++ b/src/lib/prim.c @@ -60,7 +60,7 @@ static GWION_IMPORT(int_unary) { CHECK_BB(gwi_oper_ini(gwi, NULL, "int", "int")) CHECK_BB(gwi_oper_add(gwi, opck_unary_meta)) CHECK_BB(gwi_oper_end(gwi, op_sub, int_negate)) - CHECK_BB(gwi_oper_add(gwi, opck_unary_meta2)) + CHECK_BB(gwi_oper_add(gwi, opck_unary_meta2_uniq)) CHECK_BB(gwi_oper_end(gwi, op_not, IntNot)) CHECK_OP(inc, unary, pre_inc) CHECK_OP(dec, unary, pre_dec) @@ -269,11 +269,11 @@ static GWION_IMPORT(float) { CHECK_BB(gwi_oper_ini(gwi, NULL, "float", "float")) CHECK_FF(sub, unary_meta, negate) CHECK_BB(gwi_oper_ini(gwi, NULL, "float", "int")) - CHECK_FF(not, unary_meta2, not) + CHECK_FF(not, unary_meta2_uniq, not) CHECK_BB(gwi_oper_ini(gwi, NULL, "time", "int")) - CHECK_FF(not, unary_meta, not) + CHECK_FF(not, unary_meta2_uniq, not) CHECK_BB(gwi_oper_ini(gwi, NULL, "dur", "int")) - CHECK_FF(not, unary_meta, not) + CHECK_FF(not, unary_meta2_uniq, not) CHECK_BB(gwi_oper_ini(gwi, "int", "dur", "dur")) CHECK_BB(gwi_oper_end(gwi, op_coloncolon, int_float_mul)) CHECK_BB(gwi_oper_ini(gwi, "float", "dur", "dur")) diff --git a/src/lib/string.c b/src/lib/string.c index c8f60843..d979ff12 100644 --- a/src/lib/string.c +++ b/src/lib/string.c @@ -245,5 +245,6 @@ GWION_IMPORT(string) { gwi_item_ini(gwi, "string", "__func__"); gwi_item_end(gwi, ae_flag_const, NULL); + gwi_reserve(gwi, "__func__"); return GW_OK; } diff --git a/src/parse/check.c b/src/parse/check.c index 6432437d..2e88c71a 100644 --- a/src/parse/check.c +++ b/src/parse/check.c @@ -299,12 +299,12 @@ ANN Type check_exp_array(const Env env, const Exp_Array* array) { CHECK_OO(t_base) Exp e = array->array->exp; CHECK_OO(check_exp(env, e)) - m_uint depth = 1; + m_uint depth = 0; do { if(isa(e->type, t_int) < 0) ERR_O(e->pos, "array index %i must be of type 'int', not '%s'", depth, e->type->name) - } while((e = e->next) && ++depth); + } while(++depth && (e = e->next)); if(depth != array->array->depth) ERR_O(exp_self(array)->pos, "invalid array acces expression.") diff --git a/src/parse/traverse.c b/src/parse/traverse.c index 25ed3f81..55c3ad3b 100644 --- a/src/parse/traverse.c +++ b/src/parse/traverse.c @@ -49,9 +49,12 @@ ANN m_bool traverse_decl(const Env env, const Exp_Decl* decl) { } ANN m_bool traverse_func_def(const Env env, const Func_Def def) { - CHECK_BB(scan1_func_def(env, def)) - CHECK_BB(scan2_func_def(env, def)) - return check_func_def(env, def); + const Func former = env->func; + if(scan1_func_def(env, def) > 0 && scan2_func_def(env, def) > 0 && + check_func_def(env, def) > 0) + return GW_OK; + env->func = former; + return GW_ERROR; } ANN m_bool traverse_stmt_union(const Env env, const Stmt_Union def) { diff --git a/src/vm/shreduler.c b/src/vm/shreduler.c index 2f8e4b9d..674aa4a8 100644 --- a/src/vm/shreduler.c +++ b/src/vm/shreduler.c @@ -44,13 +44,14 @@ ANN static void shreduler_parent(const VM_Shred out, const Vector v) { ANN static void unwind(const VM_Shred shred) { VM_Code code = shred->code; while(code) { + if(shred->mem <= (((m_bit*)(shred) + sizeof(struct VM_Shred_) + SIZEOF_REG))) + break; const m_bit exec = (m_bit)((Instr)vector_back(code->instr))->opcode; if(exec == eFuncReturn) { code = *(VM_Code*)(shred->mem - SZ_INT*3); if(!GET_FLAG(code, op)) REM_REF(code, shred->info->vm->gwion) shred->mem -= *(m_uint*)(shred->mem - SZ_INT*4) + SZ_INT*4; - if(shred->mem <= (((m_bit*)(shred) + sizeof(struct VM_Shred_) + SIZEOF_REG)))break; } else break; } shred->code = code; diff --git a/src/vm/vm.c b/src/vm/vm.c index 8723a8bd..8c42a61b 100644 --- a/src/vm/vm.c +++ b/src/vm/vm.c @@ -589,7 +589,8 @@ regtomem: overflow: if(overflow_((shred->mem = mem), shred)) { PRAGMA_PUSH() - shred->code = a.code; +// shred->code = a.code; + shred->mem = mem; PRAGMA_POP() Except(shred, "StackOverflow"); } @@ -720,7 +721,7 @@ exceptbase: except: if(!(a.obj = *(M_Object*)(reg-SZ_INT))) { if(array_base) _release(array_base, shred); - shred->code = code; +// shred->code = code; shred->mem = mem; exception(shred, "NullPtrException"); continue;