const Instr s1 = emit_add_instr(emit, MemSetImm);
s1->m_val = offset + SZ_INT;
stmt->v->from->offset = offset + SZ_INT*2;
+ if(stmt->idx)
+ stmt->vidx->from->offset = offset + SZ_INT;
if(n) {
const Instr instr = emit_add_instr(emit, AutoUnrollInit);
instr->m_val = offset-SZ_INT;
stmt->v = new_value(env->gwion->mp, ret, s_name(stmt->sym));
set_vflag(stmt->v, vflag_valid);
nspc_add_value(env->curr, stmt->sym, stmt->v);
+ if(stmt->idx) {
+ stmt->vidx = new_value(env->gwion->mp, env->gwion->type[et_int], s_name(stmt->idx));
+ set_vflag(stmt->vidx, vflag_valid);
+ nspc_add_value(env->curr, stmt->idx, stmt->vidx);
+ }
return check_conts(env, stmt_self(stmt), stmt->body);
}
RET_NSPC(_scan1_stmt_match(env, stmt))
}
+ANN static inline m_bool stmt_each_defined(const restrict Env env, const Stmt_Each stmt) {
+ if(nspc_lookup_value1(env->curr, stmt->sym))
+ ERR_B(stmt_self(stmt)->pos, _("foreach value '%s' is already defined"), s_name(stmt->sym))
+ if(stmt->idx && nspc_lookup_value1(env->curr, stmt->idx))
+ ERR_B(stmt_self(stmt)->pos, _("foreach index '%s' is already defined"), s_name(stmt->idx))
+ return GW_OK;
+}
+
#define describe_ret_nspc(name, type, prolog, exp) describe_stmt_func(scan1, name, type, prolog, exp)
describe_ret_nspc(flow, Stmt_Flow,, !(scan1_exp(env, stmt->cond) < 0 ||
scan1_stmt(env, stmt->body) < 0) ? 1 : -1)
scan1_stmt(env, stmt->c2) < 0 ||
(stmt->c3 && scan1_exp(env, stmt->c3) < 0) ||
scan1_stmt(env, stmt->body) < 0) ? 1 : -1)
-describe_ret_nspc(each, Stmt_Each,, !(scan1_exp(env, stmt->exp) < 0 ||
+describe_ret_nspc(each, Stmt_Each,, !(stmt_each_defined(env, stmt) < 0 || scan1_exp(env, stmt->exp) < 0 ||
scan1_stmt(env, stmt->body) < 0) ? 1 : -1)
describe_ret_nspc(loop, Stmt_Loop,, !(scan1_exp(env, stmt->cond) < 0 ||
scan1_stmt(env, stmt->body) < 0) ? 1 : -1)