emit_pop_scope(emit);
}
-ANN static Instr _flow(const Emitter emit, const Exp e, const m_bool b) {
- if(e->next) {
- free_exp(emit->gwion->mp, e->next);
- e->next = NULL;
- env_err(emit->env, e->pos, "expression after comma won't be executed");
- }
- CHECK_BO(emit_exp(emit, e, 0))
- const f_instr instr_i = b ? BranchEqInt : BranchNeqInt;
- const f_instr instr_f = b ? BranchEqFloat : BranchNeqFloat;
- return emit_flow(emit, e->type, instr_i, instr_f);
-}
-
-ANN static m_bool emit_stmt_flow(const Emitter emit, const Stmt_Flow stmt) {
- const m_uint index = emit_code_size(emit);
- Instr op = NULL;
- emit_push_stack(emit);
- if(!stmt->is_do)
- op = _flow(emit, stmt->cond, stmt_self(stmt)->stmt_type == ae_stmt_while);
- CHECK_BB(scoped_stmt(emit, stmt->body, 1))
- if(stmt->is_do) {
- CHECK_OB((op = _flow(emit, stmt->cond, stmt_self(stmt)->stmt_type != ae_stmt_while)))
- op->m_val = index;
- } else {
- const Instr goto_ = emit_add_instr(emit, Goto);
- goto_->m_val = index;
- op->m_val = emit_code_size(emit);
- }
- emit_pop_stack(emit, index);
- return GW_OK;
-}
-
ANN static m_uint get_decl_size(Var_Decl_List a) {
m_uint size = 0;
do if(GET_FLAG(a->self->value, used))
return size;
}
-ANN static void pop_exp(const Emitter emit, Exp e) {
+ANN static inline void pop_exp(const Emitter emit, Exp e) {
const m_uint size = pop_exp_size(emit, e);
if(size)
regpop(emit, size);
}
+ANN static inline m_bool emit_exp_pop_next(const Emitter emit, Exp e) {
+ CHECK_BB(emit_exp(emit, e, 0))
+ if(e->next)
+ pop_exp(emit, e->next);
+ return GW_OK;
+}
+
+ANN static Instr _flow(const Emitter emit, const Exp e, const m_bool b) {
+ CHECK_BO(emit_exp_pop_next(emit, e))
+ const f_instr instr_i = b ? BranchEqInt : BranchNeqInt;
+ const f_instr instr_f = b ? BranchEqFloat : BranchNeqFloat;
+ return emit_flow(emit, e->type, instr_i, instr_f);
+}
+
+ANN static m_bool emit_stmt_flow(const Emitter emit, const Stmt_Flow stmt) {
+ const m_uint index = emit_code_size(emit);
+ Instr op = NULL;
+ emit_push_stack(emit);
+ if(!stmt->is_do)
+ op = _flow(emit, stmt->cond, stmt_self(stmt)->stmt_type == ae_stmt_while);
+ CHECK_BB(scoped_stmt(emit, stmt->body, 1))
+ if(stmt->is_do) {
+ CHECK_OB((op = _flow(emit, stmt->cond, stmt_self(stmt)->stmt_type != ae_stmt_while)))
+ op->m_val = index;
+ } else {
+ const Instr goto_ = emit_add_instr(emit, Goto);
+ goto_->m_val = index;
+ op->m_val = emit_code_size(emit);
+ }
+ emit_pop_stack(emit, index);
+ return GW_OK;
+}
+
ANN static m_bool emit_stmt_for(const Emitter emit, const Stmt_For stmt) {
emit_push_stack(emit);
CHECK_BB(emit_stmt(emit, stmt->c1, 1))
const m_uint index = emit_code_size(emit);
- CHECK_BB(emit_stmt(emit, stmt->c2, 0))
+ if(stmt->c2->stmt_type == ae_stmt_exp)
+ emit_exp_pop_next(emit, stmt->c2->d.stmt_exp.val);
+ else
+ CHECK_BB(emit_stmt(emit, stmt->c2, 0))
const Instr op = emit_flow(emit, stmt->c2->d.stmt_exp.val->type,
BranchEqInt, BranchEqFloat);
CHECK_BB(scoped_stmt(emit, stmt->body, 1))
ANN static m_bool emit_stmt_loop(const Emitter emit, const Stmt_Loop stmt) {
emit_push_stack(emit);
- CHECK_BB(emit_exp(emit, stmt->cond, 0))
+ CHECK_BB(emit_exp_pop_next(emit, stmt->cond))
const m_uint index = emit_code_size(emit);
const Instr cpy = emit_add_instr(emit, Reg2RegAddr);
cpy->m_val2 = -SZ_INT;