diff --git a/lib/phisol/compiler/operator_value.rb b/lib/phisol/compiler/operator_value.rb index 1f7e047b..550167f1 100644 --- a/lib/phisol/compiler/operator_value.rb +++ b/lib/phisol/compiler/operator_value.rb @@ -2,15 +2,15 @@ module Phisol Compiler.class_eval do def on_operator_value statement - puts "operator #{statement.inspect}" + #puts "operator #{statement.inspect}" operator , left_e , right_e = *statement # left and right must be expressions. Expressions return a register when compiled left_reg = process(left_e) right_reg = process(right_e) raise "Not register #{left_reg}" unless left_reg.is_a?(Register::RegisterValue) raise "Not register #{right_reg}" unless right_reg.is_a?(Register::RegisterValue) - puts "left #{left_reg}" - puts "right #{right_reg}" + #puts "left #{left_reg}" + #puts "right #{right_reg}" @method.source.add_code Register::OperatorInstruction.new(statement,operator,left_reg,right_reg) return left_reg # though this has wrong value attached end diff --git a/test/compiler/statements/helper.rb b/test/compiler/statements/helper.rb new file mode 100644 index 00000000..58f8f7ed --- /dev/null +++ b/test/compiler/statements/helper.rb @@ -0,0 +1,23 @@ +require_relative '../../helper' + + +module Statements + + def check + machine = Virtual.machine.boot + machine.parse_and_compile @string_input + produced = Virtual.machine.space.get_main.source + assert @expect , "No output given" + assert_equal @expect.length , produced.blocks.length , "Block length" + produced.blocks.each_with_index do |b,i| + codes = @expect[i] + assert codes , "No codes for block #{i}" + assert_equal b.codes.length , codes.length , "Code length for block #{i+1}" + b.codes.each_with_index do |c , ii | + assert_equal codes[ii] , c.class , "Block #{i+1} , code #{ii+1}" + end + end + end + + +end diff --git a/test/compiler/statements/test_all.rb b/test/compiler/statements/test_all.rb index e69de29b..15eba1aa 100644 --- a/test/compiler/statements/test_all.rb +++ b/test/compiler/statements/test_all.rb @@ -0,0 +1 @@ +require_relative "test_if" diff --git a/test/compiler/statements/test_if.rb b/test/compiler/statements/test_if.rb new file mode 100644 index 00000000..4375d32d --- /dev/null +++ b/test/compiler/statements/test_if.rb @@ -0,0 +1,74 @@ +require_relative 'helper' + +class TestIfStatement < MiniTest::Test + include Statements + + def test_if_basic + @string_input = <