implemented simple optimization in compiling an if expression

This commit is contained in:
hyunghwan.chung
2017-01-31 16:14:11 +00:00
parent 22013650bb
commit 07d8d0ea83
4 changed files with 86 additions and 42 deletions

View File

@ -3518,7 +3518,8 @@ int moo_execute (moo_t* moo)
case BCODE_JUMP_BACKWARD_IF_TRUE_X:
FETCH_PARAM_CODE_TO (moo, b1);
LOG_INST_1 (moo, "jump_backward_if_true %zu", b1);
if (MOO_STACK_GETTOP(moo) == moo->_true) moo->ip -= b1;
/*if (MOO_STACK_GETTOP(moo) == moo->_true) moo->ip -= b1;*/
if (MOO_STACK_GETTOP(moo) != moo->_false) moo->ip -= b1;
MOO_STACK_POP (moo);
break;
@ -3527,7 +3528,8 @@ int moo_execute (moo_t* moo)
case BCODE_JUMP_BACKWARD_IF_TRUE_2:
case BCODE_JUMP_BACKWARD_IF_TRUE_3:
LOG_INST_1 (moo, "jump_backward_if_true %zu", (moo_oow_t)(bcode & 0x3));
if (MOO_STACK_GETTOP(moo) == moo->_true) moo->ip -= (bcode & 0x3); /* low 2 bits */
/*if (MOO_STACK_GETTOP(moo) == moo->_true) moo->ip -= (bcode & 0x3);*/ /* low 2 bits */
if (MOO_STACK_GETTOP(moo) != moo->_false) moo->ip -= (bcode & 0x3);
MOO_STACK_POP (moo);
break;
@ -3560,7 +3562,8 @@ int moo_execute (moo_t* moo)
case BCODE_JUMP2_BACKWARD_IF_TRUE:
FETCH_PARAM_CODE_TO (moo, b1);
LOG_INST_1 (moo, "jump2_backward_if_true %zu", b1);
if (MOO_STACK_GETTOP(moo) == moo->_true) moo->ip -= MAX_CODE_JUMP + b1;
/* if (MOO_STACK_GETTOP(moo) == moo->_true) moo->ip -= MAX_CODE_JUMP + b1; */
if (MOO_STACK_GETTOP(moo) != moo->_false) moo->ip -= MAX_CODE_JUMP + b1;
MOO_STACK_POP (moo);
break;
/* -------------------------------------------------------- */