diff --git a/lib/phisol/compiler/basic_values.rb b/lib/phisol/compiler/basic_values.rb index 0d7ca605..23f05ba3 100644 --- a/lib/phisol/compiler/basic_values.rb +++ b/lib/phisol/compiler/basic_values.rb @@ -13,37 +13,35 @@ module Phisol def on_int statement int = statement.first -# reg = - to = Virtual::Return.new(Phisol::Integer , int) - @method.source.add_code Virtual::Set.new( int , to ) - to + reg = use_reg :int + @method.source.add_code Register::LoadConstant.new( statement, int , reg ) + return reg end def on_true statement - to = Virtual::Return.new(Phisol::Reference , true ) - @method.source.add_code Virtual::Set.new( true , to ) - to + reg = use_reg :ref + @method.source.add_code Register::LoadConstant.new( statement, true , reg ) + return reg end def on_false statement - to = Virtual::Return.new(Phisol::Reference , false) - @method.source.add_code Virtual::Set.new( false , to ) - to + reg = use_reg :ref + @method.source.add_code Register::LoadConstant.new( statement, false , reg ) + return reg end def on_nil statement - to = Virtual::Return.new(Phisol::Reference , nil) - @method.source.add_code Virtual::Set.new( nil , to ) - to + reg = use_reg :ref + @method.source.add_code Register::LoadConstant.new( statement, nil , reg ) + return reg end def on_string statement - # Clearly a TODO here to implement strings rather than reusing symbols value = statement.first.to_sym - to = Virtual::Return.new(Phisol::Reference , value) + reg = use_reg :ref @method.source.constants << value - @method.source.add_code Virtual::Set.new( value , to ) - to + @method.source.add_code Register::LoadConstant.new( statement, value , reg ) + return reg end end end diff --git a/lib/phisol/compiler/field_access.rb b/lib/phisol/compiler/field_access.rb index 9a36fd49..7d132b64 100644 --- a/lib/phisol/compiler/field_access.rb +++ b/lib/phisol/compiler/field_access.rb @@ -11,8 +11,10 @@ module Phisol when :self index = @clazz.object_layout.variable_index(field_name) raise "field access, but no such field:#{field_name} for class #{@clazz.name}" unless index - value = Virtual::Return.new(:int) - @method.source.add_code Virtual::Set.new( Virtual::SelfsSlot.new(index, :int ) , value ) + value = use_reg(:int) #TODO, need types in layout + move = Register.get_slot(statement, :self , index , value ) + @method.source.add_code move + return value when :message #message Slot raise "message not yet" diff --git a/test/compiler/compiler_helper.rb b/test/compiler/compiler_helper.rb index 9b59f258..b553f480 100644 --- a/test/compiler/compiler_helper.rb +++ b/test/compiler/compiler_helper.rb @@ -5,11 +5,13 @@ module CompilerHelper Phisol::Compiler.class_eval do def set_main + @clazz = Virtual.machine.space.get_class_by_name :Object @method = Virtual.machine.space.get_main end end def check - machine = Virtual.machine.boot + machine = Virtual.machine + machine.boot unless machine.booted parser = Parser::Salama.new parser = parser.send @root syntax = parser.parse_with_debug(@string_input) @@ -18,13 +20,8 @@ module CompilerHelper compiler = Phisol::Compiler.new compiler.set_main produced = compiler.process( parts ) - produced = [produced] unless produced.is_a? Array assert @output , "No output given" - assert_equal produced.length, @output.length , "Block length" - produced.each_with_index do |b,i| - codes = @output[i] - assert_equal codes , b.class , "Class #{i} " - end + assert_equal produced.class, @output , "Wrong class" end end diff --git a/test/compiler/test_all.rb b/test/compiler/test_all.rb index 864de38b..d0b1bfcc 100644 --- a/test/compiler/test_all.rb +++ b/test/compiler/test_all.rb @@ -1,4 +1,3 @@ require_relative "test_basic" -require_relative "test_hello" require_relative "test_compiler" require_relative "test_field_access" diff --git a/test/compiler/test_basic.rb b/test/compiler/test_basic.rb index 7f871ae2..5c221d81 100644 --- a/test/compiler/test_basic.rb +++ b/test/compiler/test_basic.rb @@ -6,7 +6,7 @@ class TestBasic < MiniTest::Test def setup @root = :basic_type - @output = [Virtual::Return] + @output = Register::RegisterValue end def test_number @@ -15,7 +15,7 @@ class TestBasic < MiniTest::Test end def test_true - @string_input = 'true ' + @string_input = 'true' check end def test_false @@ -30,12 +30,13 @@ class TestBasic < MiniTest::Test def test_var @string_input = 'int foo ' @root = :field_def + @output = AST::Node check end def test_self @string_input = 'self ' - @output = [Virtual::Self] + @output = Virtual::Self check end diff --git a/test/compiler/test_field_access.rb b/test/compiler/test_field_access.rb index 3108670f..d5ba9e6b 100644 --- a/test/compiler/test_field_access.rb +++ b/test/compiler/test_field_access.rb @@ -1,24 +1,30 @@ require_relative "compiler_helper" -require_relative "code_checker" module Virtual - class TestFoo < MiniTest::Test - include CodeChecker + class TestFields < MiniTest::Test + include CompilerHelper - def test_foo3 - @string_input = <