Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

libfpvm: added operators for logical AND and OR (untested, WIP)

  • Loading branch information...
commit 530ae74293cf9f74621ce323af159ac887469056 1 parent f2650b2
@wpwrak wpwrak authored
Showing with 27 additions and 0 deletions.
  1. +2 −0  software/include/fpvm/ast.h
  2. +25 −0 software/libfpvm/fpvm.c
View
2  software/include/fpvm/ast.h
@@ -48,6 +48,8 @@ enum ast_op {
op_max,
op_int,
op_bnot,
+ op_band,
+ op_bor,
};
/* maximum supported arity is 3 */
View
25 software/libfpvm/fpvm.c
@@ -395,6 +395,11 @@ static int compile(struct fpvm_fragment *fragment, int reg, struct ast_node *nod
opb = COMPILE(FPVM_INVALID_REG, node->contents.branches.c);
(void) COMPILE(FPVM_REG_IFB, node->contents.branches.a);
break;
+ case op_band:
+ case op_bor:
+ opa = opb = 0;
+ (void) COMPILE(FPVM_REG_IFB, node->contents.branches.a);
+ break;
case op_negate:
if(node->contents.branches.a->op == op_constant) {
/* Node is a negative constant */
@@ -528,6 +533,26 @@ static int compile(struct fpvm_fragment *fragment, int reg, struct ast_node *nod
return FPVM_INVALID_REG;
ADD_ISN(FPVM_OPCODE_EQUAL, opa, opb, reg);
break;
+ case op_band: {
+ int reg_zero = REG_CONST(0);
+ int reg_one = REG_CONST(1);
+ int reg_tmp = REG_ALLOC();
+
+ ADD_ISN(FPVM_OPCODE_IF, reg_one, reg_zero, reg_tmp);
+ (void) COMPILE(FPVM_REG_IFB, node->contents.branches.b);
+ ADD_ISN(FPVM_OPCODE_IF, reg_tmp, reg_zero, reg);
+ break;
+ }
+ case op_bor: {
+ int reg_zero = REG_CONST(0);
+ int reg_one = REG_CONST(1);
+ int reg_tmp = REG_ALLOC();
+
+ ADD_ISN(FPVM_OPCODE_IF, reg_one, reg_zero, reg_tmp);
+ (void) COMPILE(FPVM_REG_IFB, node->contents.branches.b);
+ ADD_ISN(FPVM_OPCODE_IF, reg_one, reg_tmp, reg);
+ break;
+ }
default:
/* Normal case */
opcode = operator2opcode(node->op);
Please sign in to comment.
Something went wrong with that request. Please try again.