Skip to content

Commit

Permalink
libfpvm: make op_not a regular operator and implement it in all cases
Browse files Browse the repository at this point in the history
We can substitute  !X  it with  X == 0. This catches cases where boolean
not is used algorithmically and not directly with if.
  • Loading branch information
wpwrak committed Jan 12, 2012
1 parent 8dbe0fd commit 3e056a9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion software/include/fpvm/ast.h
Expand Up @@ -47,7 +47,7 @@ enum ast_op {
op_min,
op_max,
op_int,
op_vops, /* virtual operations start here */
op_not,
};

/* maximum supported arity is 3 */
Expand Down
6 changes: 6 additions & 0 deletions software/libfpvm/fpvm.c
Expand Up @@ -522,6 +522,12 @@ static int compile(struct fpvm_fragment *fragment, int reg, struct ast_node *nod
return FPVM_INVALID_REG;
ADD_ISN(FPVM_OPCODE_TSIGN, opa, opb, reg);
break;
case op_not:
opb = REG_CONST(0);
if(opb == FPVM_INVALID_REG)
return FPVM_INVALID_REG;
ADD_ISN(FPVM_OPCODE_EQUAL, opa, opb, reg);
break;
default:
/* Normal case */
opcode = operator2opcode(node->op);
Expand Down

0 comments on commit 3e056a9

Please sign in to comment.