Permalink
Browse files

libfpvm: make op_not a regular operator and implement it in all cases

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...
1 parent 8dbe0fd commit 3e056a90753f03a569a75bffc2b419429af06f0c @wpwrak wpwrak committed Jan 12, 2012
Showing with 7 additions and 1 deletion.
  1. +1 −1 software/include/fpvm/ast.h
  2. +6 −0 software/libfpvm/fpvm.c
View
2 software/include/fpvm/ast.h
@@ -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 */
View
6 software/libfpvm/fpvm.c
@@ -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);

0 comments on commit 3e056a9

Please sign in to comment.