From: Jérémie Astor Date: Thu, 15 Apr 2021 12:18:42 +0000 (+0200) Subject: :art: Improve repeat loop condition error message X-Git-Tag: nightly~745 X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=e6783cd940d9e028ecef1c5b5374022295c04161;p=gwion.git :art: Improve repeat loop condition error message --- diff --git a/src/lib/array.c b/src/lib/array.c index 06a3b578..ba787c6d 100644 --- a/src/lib/array.c +++ b/src/lib/array.c @@ -426,7 +426,7 @@ static OP_EMIT(opem_array_access) { return exp ? emit_array_access(emit, info) : GW_ERROR; } -static m_bit map_byte[BYTECODE_SZ*4];// = { eOP_MAX, test }; +static m_bit map_byte[BYTECODE_SZ*4]; static const struct VM_Code_ map_run_code = { .name = "map_run_code", .stack_depth = SZ_INT, @@ -434,7 +434,7 @@ static const struct VM_Code_ map_run_code = { }; #define MAP_CODE_OFFSET SZ_INT*10 -static INSTR(test) { +static INSTR(map_run_ini) { *(VM_Code*)(shred->reg) = (*(VM_Code*)MEM(SZ_INT)); *(VM_Code*)(shred->reg + SZ_INT) = 0; PUSH_REG(shred, SZ_INT); @@ -451,22 +451,22 @@ static INSTR(test) { m_vector_get(array, index, &*(m_bit**)(shred->mem + SZ_INT*5)); } -static INSTR(test2) { +static INSTR(map_run_end) { shred->mem -= MAP_CODE_OFFSET; const M_Object ret_obj = *(M_Object*)MEM(SZ_INT*2); const M_Vector array = ARRAY(ret_obj); POP_REG(shred, ARRAY_SIZE(array)); - POP_REG(shred, SZ_INT); const m_uint index = *(m_uint*)MEM(SZ_INT*5); const m_uint size = m_vector_size(array); - m_vector_set(array, index - 1, &*(m_bit**)(shred->reg + SZ_INT)); + m_vector_set(array, index - 1, &*(m_bit**)shred->reg); if(index == size) { shred->pc = *(m_uint*)MEM(SZ_INT*3); shred->code = *(VM_Code*)MEM(SZ_INT*4); - *(M_Object*)(shred->reg) = ret_obj; - shred->reg += SZ_INT; - } else + *(M_Object*)(shred->reg-SZ_INT) = ret_obj; + } else { shred->pc = 0; + POP_REG(shred, SZ_INT); + } shredule(shred->tick->shreduler, shred, 0); } @@ -546,12 +546,12 @@ static OP_CHECK(opck_array_implicit) { static void prepare_map_run(void) { *(unsigned*)map_byte = eOP_MAX; - *(f_instr*)(map_byte + SZ_INT*2) = test; + *(f_instr*)(map_byte + SZ_INT*2) = map_run_ini; *(unsigned*)(map_byte+ BYTECODE_SZ) = eSetCode; *(m_uint*)(map_byte + BYTECODE_SZ + SZ_INT*2) = 3; *(unsigned*)(map_byte+ BYTECODE_SZ*2) = eOverflow; *(unsigned*)(map_byte+ BYTECODE_SZ*3) = eOP_MAX; - *(f_instr*)(map_byte + BYTECODE_SZ*3 + SZ_INT*2) = test2; + *(f_instr*)(map_byte + BYTECODE_SZ*3 + SZ_INT*2) = map_run_end; } GWION_IMPORT(array) { diff --git a/src/parse/check.c b/src/parse/check.c index 48804f06..aa32acf7 100644 --- a/src/parse/check.c +++ b/src/parse/check.c @@ -1057,8 +1057,14 @@ ANN static m_bool do_stmt_each(const Env env, const Stmt_Each stmt) { ANN static inline m_bool cond_type(const Env env, const Exp e) { const Type t_int = env->gwion->type[et_int]; - if(check_implicit(env, e, t_int) < 0) - ERR_B(e->pos, _("invalid condition type")) + if(check_implicit(env, e, t_int) < 0) { + char explain[40 + strlen(e->type->name)]; + sprintf(explain, "expected `{/+}int{0}`, got `{/+}%s{0}`", e->type->name); + gwerr_basic(_("invalid repeat condition type"), explain, + _("use an integer or cast to int if possible"), env->name, e->pos, 0); + env->context->error = true; + return GW_ERROR; + } return GW_OK; }