def self.emit_binop(state, v)
if v.op == "&&"
- raise "logical and"
+ lvar = emit(state, v.left)
+ result = mktemp(state);
+ putln state, "Value #{result} = #{lvar};"
+ putln state, "if (IsTrue(#{result})) {"
+ state.indent += 1
+ rvar = emit(state, v.right)
+ putln state, "#{result} = #{rvar};"
+ state.indent -= 1
+ putln state, "} else {"
+ putln state, " #{result} = MakeBool(false);"
+ putln state, "}"
elsif v.op == "||"
- raise "logical or"
+ lvar = emit(state, v.left)
+ result = mktemp(state);
+ putln state, "Value #{result} = #{lvar};"
+ putln state, "if (IsFalse(#{result})) {"
+ state.indent += 1
+ rvar = emit(state, v.right)
+ putln state, "#{result} = #{rvar};"
+ state.indent -= 1
+ putln state, "}"
else
lvar = emit(state, v.left)
rvar = emit(state, v.right)
when ">"
putln state, "Value #{result} = OpGt(#{lvar}, #{rvar});"
when ">="
- putln state, "Value #{result} = OpGte(#{lvar}, #{rvar});"
+ putln state, "Value #{result} = OpGtEq(#{lvar}, #{rvar});"
when "=="
putln state, "Value #{result} = OpEq(#{lvar}, #{rvar});"
when "!="
putln state, "Value #{result} = OpNeq(#{lvar}, #{rvar});"
-
- # when "&&"
- # putln state, "Value #{result} = OpAnd(#{lvar}, #{rvar});"
- #
- # when "||"
- # putln state, "Value #{result} = OpOr(#{lvar}, #{rvar});"
-
else
raise "not implemented"
end
/* C Type Conversions
*************************************************/
+static inline int32_t ValueAsBool(Value val) {
+ assert(IsBool(val));
+ return (bool)val.as_uint64;
+}
+
static inline int32_t ValueAsInt(Value val) {
assert(IsInt(val));
return (int32_t)val.as_uint64;
exit(1);
}
}
+
+/* Binary Operators
+ *************************************************/
+
+static inline Value OpAdd(Value left, Value right) {
+ return MakeNil();
+}
+
+static inline Value OpSub(Value left, Value right) {
+ return MakeNil();
+}
+
+static inline Value OpMul(Value left, Value right) {
+ return MakeNil();
+}
+
+static inline Value OpDiv(Value left, Value right) {
+ return MakeNil();
+}
+
+static inline Value OpMod(Value left, Value right) {
+ return MakeNil();
+}
+
+static inline Value OpLt(Value left, Value right) {
+ return MakeNil();
+}
+
+static inline Value OpLtEq(Value left, Value right) {
+ return MakeNil();
+}
+
+static inline Value OpGt(Value left, Value right) {
+ return MakeNil();
+}
+
+static inline Value OpGtEq(Value left, Value right) {
+ return MakeNil();
+}
+
+static inline Value OpEq(Value left, Value right) {
+ return MakeNil();
+}
+
+static inline Value OpNeq(Value left, Value right) {
+ return MakeNil();
+}