optimize compiler test jumps
This commit is contained in:
parent
c9986cc25a
commit
ed6137a7d7
@ -528,10 +528,18 @@ void compiler::emit_stmt_while(const ast::stmt_while::ptr& stmt, const block::pt
|
||||
bool const_cond = is_constant_condition(stmt->test);
|
||||
|
||||
if (!const_cond)
|
||||
{
|
||||
if (stmt->test == ast::kind::expr_not)
|
||||
{
|
||||
emit_expr(stmt->test.as_not->rvalue, blk);
|
||||
emit_opcode(opcode::OP_JumpOnTrue, break_loc);
|
||||
}
|
||||
else
|
||||
{
|
||||
emit_expr(stmt->test, blk);
|
||||
emit_opcode(opcode::OP_JumpOnFalse, break_loc);
|
||||
}
|
||||
}
|
||||
|
||||
emit_stmt(stmt->stmt, stmt->blk, false);
|
||||
|
||||
@ -586,10 +594,18 @@ void compiler::emit_stmt_dowhile(const ast::stmt_dowhile::ptr& stmt, const block
|
||||
bool const_cond = is_constant_condition(stmt->test);
|
||||
|
||||
if (!const_cond)
|
||||
{
|
||||
if (stmt->test == ast::kind::expr_not)
|
||||
{
|
||||
emit_expr(stmt->test.as_not->rvalue, blk);
|
||||
emit_opcode(opcode::OP_JumpOnTrue, break_loc);
|
||||
}
|
||||
else
|
||||
{
|
||||
emit_expr(stmt->test, blk);
|
||||
emit_opcode(opcode::OP_JumpOnFalse, break_loc);
|
||||
}
|
||||
}
|
||||
|
||||
emit_opcode(opcode::OP_jumpback, begin_loc);
|
||||
|
||||
@ -641,10 +657,18 @@ void compiler::emit_stmt_for(const ast::stmt_for::ptr& stmt, const block::ptr& b
|
||||
bool const_cond = is_constant_condition(stmt->test);
|
||||
|
||||
if (!const_cond)
|
||||
{
|
||||
if (stmt->test == ast::kind::expr_not)
|
||||
{
|
||||
emit_expr(stmt->test.as_not->rvalue, blk);
|
||||
emit_opcode(opcode::OP_JumpOnTrue, break_loc);
|
||||
}
|
||||
else
|
||||
{
|
||||
emit_expr(stmt->test, blk);
|
||||
emit_opcode(opcode::OP_JumpOnFalse, break_loc);
|
||||
}
|
||||
}
|
||||
|
||||
can_break_ = true;
|
||||
can_continue_ = true;
|
||||
|
@ -528,10 +528,18 @@ void compiler::emit_stmt_while(const ast::stmt_while::ptr& stmt, const block::pt
|
||||
bool const_cond = is_constant_condition(stmt->test);
|
||||
|
||||
if (!const_cond)
|
||||
{
|
||||
if (stmt->test == ast::kind::expr_not)
|
||||
{
|
||||
emit_expr(stmt->test.as_not->rvalue, blk);
|
||||
emit_opcode(opcode::OP_JumpOnTrue, break_loc);
|
||||
}
|
||||
else
|
||||
{
|
||||
emit_expr(stmt->test, blk);
|
||||
emit_opcode(opcode::OP_JumpOnFalse, break_loc);
|
||||
}
|
||||
}
|
||||
|
||||
emit_stmt(stmt->stmt, stmt->blk, false);
|
||||
|
||||
@ -586,10 +594,18 @@ void compiler::emit_stmt_dowhile(const ast::stmt_dowhile::ptr& stmt, const block
|
||||
bool const_cond = is_constant_condition(stmt->test);
|
||||
|
||||
if (!const_cond)
|
||||
{
|
||||
if (stmt->test == ast::kind::expr_not)
|
||||
{
|
||||
emit_expr(stmt->test.as_not->rvalue, blk);
|
||||
emit_opcode(opcode::OP_JumpOnTrue, break_loc);
|
||||
}
|
||||
else
|
||||
{
|
||||
emit_expr(stmt->test, blk);
|
||||
emit_opcode(opcode::OP_JumpOnFalse, break_loc);
|
||||
}
|
||||
}
|
||||
|
||||
emit_opcode(opcode::OP_jumpback, begin_loc);
|
||||
|
||||
@ -641,10 +657,18 @@ void compiler::emit_stmt_for(const ast::stmt_for::ptr& stmt, const block::ptr& b
|
||||
bool const_cond = is_constant_condition(stmt->test);
|
||||
|
||||
if (!const_cond)
|
||||
{
|
||||
if (stmt->test == ast::kind::expr_not)
|
||||
{
|
||||
emit_expr(stmt->test.as_not->rvalue, blk);
|
||||
emit_opcode(opcode::OP_JumpOnTrue, break_loc);
|
||||
}
|
||||
else
|
||||
{
|
||||
emit_expr(stmt->test, blk);
|
||||
emit_opcode(opcode::OP_JumpOnFalse, break_loc);
|
||||
}
|
||||
}
|
||||
|
||||
can_break_ = true;
|
||||
can_continue_ = true;
|
||||
|
@ -520,10 +520,18 @@ void compiler::emit_stmt_while(const ast::stmt_while::ptr& stmt, const block::pt
|
||||
bool const_cond = is_constant_condition(stmt->test);
|
||||
|
||||
if (!const_cond)
|
||||
{
|
||||
if (stmt->test == ast::kind::expr_not)
|
||||
{
|
||||
emit_expr(stmt->test.as_not->rvalue, blk);
|
||||
emit_opcode(opcode::OP_JumpOnTrue, break_loc);
|
||||
}
|
||||
else
|
||||
{
|
||||
emit_expr(stmt->test, blk);
|
||||
emit_opcode(opcode::OP_JumpOnFalse, break_loc);
|
||||
}
|
||||
}
|
||||
|
||||
emit_stmt(stmt->stmt, stmt->blk, false);
|
||||
|
||||
@ -578,10 +586,18 @@ void compiler::emit_stmt_dowhile(const ast::stmt_dowhile::ptr& stmt, const block
|
||||
bool const_cond = is_constant_condition(stmt->test);
|
||||
|
||||
if (!const_cond)
|
||||
{
|
||||
if (stmt->test == ast::kind::expr_not)
|
||||
{
|
||||
emit_expr(stmt->test.as_not->rvalue, blk);
|
||||
emit_opcode(opcode::OP_JumpOnTrue, break_loc);
|
||||
}
|
||||
else
|
||||
{
|
||||
emit_expr(stmt->test, blk);
|
||||
emit_opcode(opcode::OP_JumpOnFalse, break_loc);
|
||||
}
|
||||
}
|
||||
|
||||
emit_opcode(opcode::OP_jumpback, begin_loc);
|
||||
|
||||
@ -633,10 +649,18 @@ void compiler::emit_stmt_for(const ast::stmt_for::ptr& stmt, const block::ptr& b
|
||||
bool const_cond = is_constant_condition(stmt->test);
|
||||
|
||||
if (!const_cond)
|
||||
{
|
||||
if (stmt->test == ast::kind::expr_not)
|
||||
{
|
||||
emit_expr(stmt->test.as_not->rvalue, blk);
|
||||
emit_opcode(opcode::OP_JumpOnTrue, break_loc);
|
||||
}
|
||||
else
|
||||
{
|
||||
emit_expr(stmt->test, blk);
|
||||
emit_opcode(opcode::OP_JumpOnFalse, break_loc);
|
||||
}
|
||||
}
|
||||
|
||||
can_break_ = true;
|
||||
can_continue_ = true;
|
||||
|
@ -520,10 +520,18 @@ void compiler::emit_stmt_while(const ast::stmt_while::ptr& stmt, const block::pt
|
||||
bool const_cond = is_constant_condition(stmt->test);
|
||||
|
||||
if (!const_cond)
|
||||
{
|
||||
if (stmt->test == ast::kind::expr_not)
|
||||
{
|
||||
emit_expr(stmt->test.as_not->rvalue, blk);
|
||||
emit_opcode(opcode::OP_JumpOnTrue, break_loc);
|
||||
}
|
||||
else
|
||||
{
|
||||
emit_expr(stmt->test, blk);
|
||||
emit_opcode(opcode::OP_JumpOnFalse, break_loc);
|
||||
}
|
||||
}
|
||||
|
||||
emit_stmt(stmt->stmt, stmt->blk, false);
|
||||
|
||||
@ -578,10 +586,18 @@ void compiler::emit_stmt_dowhile(const ast::stmt_dowhile::ptr& stmt, const block
|
||||
bool const_cond = is_constant_condition(stmt->test);
|
||||
|
||||
if (!const_cond)
|
||||
{
|
||||
if (stmt->test == ast::kind::expr_not)
|
||||
{
|
||||
emit_expr(stmt->test.as_not->rvalue, blk);
|
||||
emit_opcode(opcode::OP_JumpOnTrue, break_loc);
|
||||
}
|
||||
else
|
||||
{
|
||||
emit_expr(stmt->test, blk);
|
||||
emit_opcode(opcode::OP_JumpOnFalse, break_loc);
|
||||
}
|
||||
}
|
||||
|
||||
emit_opcode(opcode::OP_jumpback, begin_loc);
|
||||
|
||||
@ -633,10 +649,18 @@ void compiler::emit_stmt_for(const ast::stmt_for::ptr& stmt, const block::ptr& b
|
||||
bool const_cond = is_constant_condition(stmt->test);
|
||||
|
||||
if (!const_cond)
|
||||
{
|
||||
if (stmt->test == ast::kind::expr_not)
|
||||
{
|
||||
emit_expr(stmt->test.as_not->rvalue, blk);
|
||||
emit_opcode(opcode::OP_JumpOnTrue, break_loc);
|
||||
}
|
||||
else
|
||||
{
|
||||
emit_expr(stmt->test, blk);
|
||||
emit_opcode(opcode::OP_JumpOnFalse, break_loc);
|
||||
}
|
||||
}
|
||||
|
||||
can_break_ = true;
|
||||
can_continue_ = true;
|
||||
|
@ -520,10 +520,18 @@ void compiler::emit_stmt_while(const ast::stmt_while::ptr& stmt, const block::pt
|
||||
bool const_cond = is_constant_condition(stmt->test);
|
||||
|
||||
if (!const_cond)
|
||||
{
|
||||
if (stmt->test == ast::kind::expr_not)
|
||||
{
|
||||
emit_expr(stmt->test.as_not->rvalue, blk);
|
||||
emit_opcode(opcode::OP_JumpOnTrue, break_loc);
|
||||
}
|
||||
else
|
||||
{
|
||||
emit_expr(stmt->test, blk);
|
||||
emit_opcode(opcode::OP_JumpOnFalse, break_loc);
|
||||
}
|
||||
}
|
||||
|
||||
emit_stmt(stmt->stmt, stmt->blk, false);
|
||||
|
||||
@ -578,10 +586,18 @@ void compiler::emit_stmt_dowhile(const ast::stmt_dowhile::ptr& stmt, const block
|
||||
bool const_cond = is_constant_condition(stmt->test);
|
||||
|
||||
if (!const_cond)
|
||||
{
|
||||
if (stmt->test == ast::kind::expr_not)
|
||||
{
|
||||
emit_expr(stmt->test.as_not->rvalue, blk);
|
||||
emit_opcode(opcode::OP_JumpOnTrue, break_loc);
|
||||
}
|
||||
else
|
||||
{
|
||||
emit_expr(stmt->test, blk);
|
||||
emit_opcode(opcode::OP_JumpOnFalse, break_loc);
|
||||
}
|
||||
}
|
||||
|
||||
emit_opcode(opcode::OP_jumpback, begin_loc);
|
||||
|
||||
@ -633,10 +649,18 @@ void compiler::emit_stmt_for(const ast::stmt_for::ptr& stmt, const block::ptr& b
|
||||
bool const_cond = is_constant_condition(stmt->test);
|
||||
|
||||
if (!const_cond)
|
||||
{
|
||||
if (stmt->test == ast::kind::expr_not)
|
||||
{
|
||||
emit_expr(stmt->test.as_not->rvalue, blk);
|
||||
emit_opcode(opcode::OP_JumpOnTrue, break_loc);
|
||||
}
|
||||
else
|
||||
{
|
||||
emit_expr(stmt->test, blk);
|
||||
emit_opcode(opcode::OP_JumpOnFalse, break_loc);
|
||||
}
|
||||
}
|
||||
|
||||
can_break_ = true;
|
||||
can_continue_ = true;
|
||||
|
@ -528,10 +528,18 @@ void compiler::emit_stmt_while(const ast::stmt_while::ptr& stmt, const block::pt
|
||||
bool const_cond = is_constant_condition(stmt->test);
|
||||
|
||||
if (!const_cond)
|
||||
{
|
||||
if (stmt->test == ast::kind::expr_not)
|
||||
{
|
||||
emit_expr(stmt->test.as_not->rvalue, blk);
|
||||
emit_opcode(opcode::OP_JumpOnTrue, break_loc);
|
||||
}
|
||||
else
|
||||
{
|
||||
emit_expr(stmt->test, blk);
|
||||
emit_opcode(opcode::OP_JumpOnFalse, break_loc);
|
||||
}
|
||||
}
|
||||
|
||||
emit_stmt(stmt->stmt, stmt->blk, false);
|
||||
|
||||
@ -586,10 +594,18 @@ void compiler::emit_stmt_dowhile(const ast::stmt_dowhile::ptr& stmt, const block
|
||||
bool const_cond = is_constant_condition(stmt->test);
|
||||
|
||||
if (!const_cond)
|
||||
{
|
||||
if (stmt->test == ast::kind::expr_not)
|
||||
{
|
||||
emit_expr(stmt->test.as_not->rvalue, blk);
|
||||
emit_opcode(opcode::OP_JumpOnTrue, break_loc);
|
||||
}
|
||||
else
|
||||
{
|
||||
emit_expr(stmt->test, blk);
|
||||
emit_opcode(opcode::OP_JumpOnFalse, break_loc);
|
||||
}
|
||||
}
|
||||
|
||||
emit_opcode(opcode::OP_jumpback, begin_loc);
|
||||
|
||||
@ -641,10 +657,18 @@ void compiler::emit_stmt_for(const ast::stmt_for::ptr& stmt, const block::ptr& b
|
||||
bool const_cond = is_constant_condition(stmt->test);
|
||||
|
||||
if (!const_cond)
|
||||
{
|
||||
if (stmt->test == ast::kind::expr_not)
|
||||
{
|
||||
emit_expr(stmt->test.as_not->rvalue, blk);
|
||||
emit_opcode(opcode::OP_JumpOnTrue, break_loc);
|
||||
}
|
||||
else
|
||||
{
|
||||
emit_expr(stmt->test, blk);
|
||||
emit_opcode(opcode::OP_JumpOnFalse, break_loc);
|
||||
}
|
||||
}
|
||||
|
||||
can_break_ = true;
|
||||
can_continue_ = true;
|
||||
|
@ -528,10 +528,18 @@ void compiler::emit_stmt_while(const ast::stmt_while::ptr& stmt, const block::pt
|
||||
bool const_cond = is_constant_condition(stmt->test);
|
||||
|
||||
if (!const_cond)
|
||||
{
|
||||
if (stmt->test == ast::kind::expr_not)
|
||||
{
|
||||
emit_expr(stmt->test.as_not->rvalue, blk);
|
||||
emit_opcode(opcode::OP_JumpOnTrue, break_loc);
|
||||
}
|
||||
else
|
||||
{
|
||||
emit_expr(stmt->test, blk);
|
||||
emit_opcode(opcode::OP_JumpOnFalse, break_loc);
|
||||
}
|
||||
}
|
||||
|
||||
emit_stmt(stmt->stmt, stmt->blk, false);
|
||||
|
||||
@ -586,10 +594,18 @@ void compiler::emit_stmt_dowhile(const ast::stmt_dowhile::ptr& stmt, const block
|
||||
bool const_cond = is_constant_condition(stmt->test);
|
||||
|
||||
if (!const_cond)
|
||||
{
|
||||
if (stmt->test == ast::kind::expr_not)
|
||||
{
|
||||
emit_expr(stmt->test.as_not->rvalue, blk);
|
||||
emit_opcode(opcode::OP_JumpOnTrue, break_loc);
|
||||
}
|
||||
else
|
||||
{
|
||||
emit_expr(stmt->test, blk);
|
||||
emit_opcode(opcode::OP_JumpOnFalse, break_loc);
|
||||
}
|
||||
}
|
||||
|
||||
emit_opcode(opcode::OP_jumpback, begin_loc);
|
||||
|
||||
@ -641,10 +657,18 @@ void compiler::emit_stmt_for(const ast::stmt_for::ptr& stmt, const block::ptr& b
|
||||
bool const_cond = is_constant_condition(stmt->test);
|
||||
|
||||
if (!const_cond)
|
||||
{
|
||||
if (stmt->test == ast::kind::expr_not)
|
||||
{
|
||||
emit_expr(stmt->test.as_not->rvalue, blk);
|
||||
emit_opcode(opcode::OP_JumpOnTrue, break_loc);
|
||||
}
|
||||
else
|
||||
{
|
||||
emit_expr(stmt->test, blk);
|
||||
emit_opcode(opcode::OP_JumpOnFalse, break_loc);
|
||||
}
|
||||
}
|
||||
|
||||
can_break_ = true;
|
||||
can_continue_ = true;
|
||||
|
@ -528,10 +528,18 @@ void compiler::emit_stmt_while(const ast::stmt_while::ptr& stmt, const block::pt
|
||||
bool const_cond = is_constant_condition(stmt->test);
|
||||
|
||||
if (!const_cond)
|
||||
{
|
||||
if (stmt->test == ast::kind::expr_not)
|
||||
{
|
||||
emit_expr(stmt->test.as_not->rvalue, blk);
|
||||
emit_opcode(opcode::OP_JumpOnTrue, break_loc);
|
||||
}
|
||||
else
|
||||
{
|
||||
emit_expr(stmt->test, blk);
|
||||
emit_opcode(opcode::OP_JumpOnFalse, break_loc);
|
||||
}
|
||||
}
|
||||
|
||||
emit_stmt(stmt->stmt, stmt->blk, false);
|
||||
|
||||
@ -586,10 +594,18 @@ void compiler::emit_stmt_dowhile(const ast::stmt_dowhile::ptr& stmt, const block
|
||||
bool const_cond = is_constant_condition(stmt->test);
|
||||
|
||||
if (!const_cond)
|
||||
{
|
||||
if (stmt->test == ast::kind::expr_not)
|
||||
{
|
||||
emit_expr(stmt->test.as_not->rvalue, blk);
|
||||
emit_opcode(opcode::OP_JumpOnTrue, break_loc);
|
||||
}
|
||||
else
|
||||
{
|
||||
emit_expr(stmt->test, blk);
|
||||
emit_opcode(opcode::OP_JumpOnFalse, break_loc);
|
||||
}
|
||||
}
|
||||
|
||||
emit_opcode(opcode::OP_jumpback, begin_loc);
|
||||
|
||||
@ -641,10 +657,18 @@ void compiler::emit_stmt_for(const ast::stmt_for::ptr& stmt, const block::ptr& b
|
||||
bool const_cond = is_constant_condition(stmt->test);
|
||||
|
||||
if (!const_cond)
|
||||
{
|
||||
if (stmt->test == ast::kind::expr_not)
|
||||
{
|
||||
emit_expr(stmt->test.as_not->rvalue, blk);
|
||||
emit_opcode(opcode::OP_JumpOnTrue, break_loc);
|
||||
}
|
||||
else
|
||||
{
|
||||
emit_expr(stmt->test, blk);
|
||||
emit_opcode(opcode::OP_JumpOnFalse, break_loc);
|
||||
}
|
||||
}
|
||||
|
||||
can_break_ = true;
|
||||
can_continue_ = true;
|
||||
|
@ -528,10 +528,18 @@ void compiler::emit_stmt_while(const ast::stmt_while::ptr& stmt, const block::pt
|
||||
bool const_cond = is_constant_condition(stmt->test);
|
||||
|
||||
if (!const_cond)
|
||||
{
|
||||
if (stmt->test == ast::kind::expr_not)
|
||||
{
|
||||
emit_expr(stmt->test.as_not->rvalue, blk);
|
||||
emit_opcode(opcode::OP_JumpOnTrue, break_loc);
|
||||
}
|
||||
else
|
||||
{
|
||||
emit_expr(stmt->test, blk);
|
||||
emit_opcode(opcode::OP_JumpOnFalse, break_loc);
|
||||
}
|
||||
}
|
||||
|
||||
emit_stmt(stmt->stmt, stmt->blk, false);
|
||||
|
||||
@ -586,10 +594,18 @@ void compiler::emit_stmt_dowhile(const ast::stmt_dowhile::ptr& stmt, const block
|
||||
bool const_cond = is_constant_condition(stmt->test);
|
||||
|
||||
if (!const_cond)
|
||||
{
|
||||
if (stmt->test == ast::kind::expr_not)
|
||||
{
|
||||
emit_expr(stmt->test.as_not->rvalue, blk);
|
||||
emit_opcode(opcode::OP_JumpOnTrue, break_loc);
|
||||
}
|
||||
else
|
||||
{
|
||||
emit_expr(stmt->test, blk);
|
||||
emit_opcode(opcode::OP_JumpOnFalse, break_loc);
|
||||
}
|
||||
}
|
||||
|
||||
emit_opcode(opcode::OP_jumpback, begin_loc);
|
||||
|
||||
@ -641,10 +657,18 @@ void compiler::emit_stmt_for(const ast::stmt_for::ptr& stmt, const block::ptr& b
|
||||
bool const_cond = is_constant_condition(stmt->test);
|
||||
|
||||
if (!const_cond)
|
||||
{
|
||||
if (stmt->test == ast::kind::expr_not)
|
||||
{
|
||||
emit_expr(stmt->test.as_not->rvalue, blk);
|
||||
emit_opcode(opcode::OP_JumpOnTrue, break_loc);
|
||||
}
|
||||
else
|
||||
{
|
||||
emit_expr(stmt->test, blk);
|
||||
emit_opcode(opcode::OP_JumpOnFalse, break_loc);
|
||||
}
|
||||
}
|
||||
|
||||
can_break_ = true;
|
||||
can_continue_ = true;
|
||||
|
Loading…
Reference in New Issue
Block a user