Permalink
Browse files

fixes #13. adding == & != on bools

  • Loading branch information...
1 parent 1a3da9f commit d680a3355cd98c7bb1a43cfda9cae21bad799960 @baroquebobcat baroquebobcat committed Jan 15, 2012
Showing with 47 additions and 0 deletions.
  1. +33 −0 lib/mirah/jvm/types/boolean.rb
  2. +14 −0 test/jvm/test_jvm_compiler.rb
@@ -28,5 +28,38 @@ def box(builder)
builder.invokestatic box_type, "valueOf", [box_type, self]
end
+ def add_intrinsics
+ args = [math_type]
+ add_method('==', args, ComparisonIntrinsic.new(self, '==', :eq, args))
+ add_method('!=', args, ComparisonIntrinsic.new(self, '!=', :ne, args))
+ end
+
+ def math_type
+ Boolean
+ end
+
+ # same as NumberType's
+ def compile_boolean_operator(compiler, op, negated, call, label)
+ # Promote the target or the argument if necessary
+ convert_args(compiler,
+ [call.target, *call.parameters],
+ [math_type, math_type])
+ if negated
+ op = invert_op(op)
+ end
+ if label
+ jump_if(compiler.method, op, label)
+ else
+ compiler.method.op_to_bool do |label|
+ jump_if(compiler.method, op, label)
+ end
+ end
+ end
+
+ # Same as IntegerType's
+ # bools are ints for comparison purposes
+ def jump_if(builder, op, label)
+ builder.send "if_icmp#{op}", label
+ end
end
end
@@ -2262,4 +2262,18 @@ def test_missing_class_with_block_raises_inference_error
compile("Interface Implements_Go do; end")
end
end
+
+ def test_bool_equality
+ cls, = compile("puts true == false")
+ assert_output("false\n") do
+ cls.main(nil)
+ end
+ end
+
+ def test_bool_inequality
+ cls, = compile("puts true != false")
+ assert_output("true\n") do
+ cls.main(nil)
+ end
+ end
end

0 comments on commit d680a33

Please sign in to comment.