From: Jérémie Astor Date: Thu, 5 Aug 2021 12:00:47 +0000 (+0200) Subject: :art: Update and spork bugfix X-Git-Tag: nightly~489 X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=fa546710a1ead0405cd7276f3a4f7ba0fb6e719b;p=gwion.git :art: Update and spork bugfix --- diff --git a/ast b/ast index a4e4f7f5..ba2a75d2 160000 --- a/ast +++ b/ast @@ -1 +1 @@ -Subproject commit a4e4f7f5955fff6ebb05e90949a54c556dee964e +Subproject commit ba2a75d2445c1d107569c52fd69364e0142d80fb diff --git a/plug b/plug index 1c980306..ac29ebb0 160000 --- a/plug +++ b/plug @@ -1 +1 @@ -Subproject commit 1c980306a4146aa80dc3f3d21137aed3a68dac9b +Subproject commit ac29ebb012d01fda0eb1c84dc204941fc6a55d4f diff --git a/src/emit/emit.c b/src/emit/emit.c index bfd6fb87..cddf0dbd 100644 --- a/src/emit/emit.c +++ b/src/emit/emit.c @@ -1431,6 +1431,17 @@ ANN static Instr emit_call(const Emitter emit, const Func f, return emit_add_instr(emit, Overflow); } +ANN static m_bool emit_ensure_func(const Emitter emit, const Func f) { + const struct ValueFrom_ *from = f->value_ref->from; + if(from->owner_class) + CHECK_BB(ensure_emit(emit, from->owner_class)); + if(f->code) return GW_OK; + const m_uint scope = emit_push(emit, from->owner_class, from->owner); + const m_bool ret = emit_func_def(emit, f->def); + emit_pop(emit, scope); + return ret; +} + ANN m_bool emit_exp_call1(const Emitter emit, const Func f, const bool is_static) { const m_uint this_offset = emit->this_offset; @@ -1450,8 +1461,7 @@ ANN m_bool emit_exp_call1(const Emitter emit, const Func f, } } else if (emit->env->func != f && !f->value_ref->from->owner_class && !f->code && !is_fptr(emit->gwion, f->value_ref->type)) { - // ensure env? - CHECK_BB(emit_func_def(emit, f->def)); + CHECK_BB(emit_ensure_func(emit, f)); if (fbflag(f->def->base, fbflag_op)) { const Instr back = (Instr)vector_back(&emit->code->instr); assert(back->execute == SetFunc); @@ -1503,6 +1513,7 @@ ANN m_bool emit_exp_call1(const Emitter emit, const Func f, !is_fptr(emit->gwion, f->value_ref->type)) { // not yet emitted static func if (f->value_ref->from->owner_class) { + assert(GET_FLAG(f->value_ref, static)); const Instr instr = vector_size(&emit->code->instr) ? (Instr)vector_back(&emit->code->instr) : emit_add_instr(emit, SetFunc); @@ -1601,10 +1612,13 @@ ANN static m_bool spork_prepare_code(const Emitter emit, ANN static m_bool spork_prepare_func(const Emitter emit, const struct Sporker *sp) { + const Type t = actual_type(emit->gwion, sp->exp->d.exp_call.func->type); + const Func f = t->info->func; + if(!f->code && f != emit->env->func) + CHECK_BB(emit_ensure_func(emit, f)); push_spork_code(emit, sp->is_spork ? SPORK_FUNC_PREFIX : FORK_CODE_PREFIX, sp->exp->pos); - const Type t = actual_type(emit->gwion, sp->exp->d.exp_call.func->type); - return emit_exp_call1(emit, t->info->func, false); + return emit_exp_call1(emit, f, false); } ANN static VM_Code spork_prepare(const Emitter emit, const struct Sporker *sp) { diff --git a/src/vm/vm.c b/src/vm/vm.c index 01b24041..b8574203 100644 --- a/src/vm/vm.c +++ b/src/vm/vm.c @@ -933,10 +933,12 @@ vm_run(const VM *vm) { // lgtm [cpp/use-of-goto] forkini: reg -= SZ_INT; child = init_fork_shred(shred, (VM_Code)VAL, *(Type *)reg, VAL2), - DISPATCH() sporkfunc : - // LOOP_OPTIM - PRAGMA_PUSH() for (m_uint i = 0; i < VAL; i += SZ_INT) * - (m_uint *)(child->reg + i) = *(m_uint *)(reg + i + IVAL2); + DISPATCH() + sporkfunc: + PRAGMA_PUSH() + // LOOP_OPTIM + for (m_uint i = 0; i < VAL; i += SZ_INT) + *(m_uint *)(child->reg + i) = *(m_uint *)(reg + i + IVAL2); child->reg += VAL; DISPATCH() PRAGMA_POP() diff --git a/tests/pp/macro.gw b/tests/pp/macro.gw new file mode 100644 index 00000000..5c3d4604 --- /dev/null +++ b/tests/pp/macro.gw @@ -0,0 +1,7 @@ +#! [contains] 1 + +#define TEST_MULITLINE_MACRO(i) \ +more stuff.\ +and more + +<<< 1 >>>;