diff --git a/lib/mom/instruction/block_yield.rb b/lib/mom/instruction/block_yield.rb index 873ab552..d0e7de30 100644 --- a/lib/mom/instruction/block_yield.rb +++ b/lib/mom/instruction/block_yield.rb @@ -6,7 +6,10 @@ module Mom class BlockYield < Instruction attr :arg_index - def initialize(index) + # pass in the source (vool statement) and the index. + # The index is the argument index of the block that we call + def initialize(source , index) + super(source) @arg_index = index end @@ -14,6 +17,7 @@ module Mom "BlockYield[#{arg_index}] " end + # almost as simple as a SimpleCall, use a dynamic_jump to get there def to_risc(compiler) return_label = Risc.label("block_yield", "continue_#{object_id}") index = arg_index diff --git a/lib/mom/instruction/resolve_method.rb b/lib/mom/instruction/resolve_method.rb index 63a1caeb..f10bbd1c 100644 --- a/lib/mom/instruction/resolve_method.rb +++ b/lib/mom/instruction/resolve_method.rb @@ -15,7 +15,11 @@ module Mom class ResolveMethod < Instruction attr :cache_entry , :name - def initialize(name , cache_entry) + # pass in source (VoolStatement) + # name of the method (don't knwow the actaual method) + # and the cache_entry + def initialize(source , name , cache_entry) + super(source) @name = name @cache_entry = cache_entry end diff --git a/lib/rubyx/rubyx_compiler.rb b/lib/rubyx/rubyx_compiler.rb index d0a93128..b0c84371 100644 --- a/lib/rubyx/rubyx_compiler.rb +++ b/lib/rubyx/rubyx_compiler.rb @@ -53,17 +53,15 @@ module RubyX # translates those to the platform given # # After creating vool, we call to_risc - def ruby_to_risc(ruby, platform) + def ruby_to_risc(ruby) ruby_to_vool(ruby) - to_risc(platform) + to_risc() end - # Process previously stored vool source. First to mom, then to platform. - # Translating to platform returns a linker that is returned and can be used - # to generate binaries - def to_risc(platform) + # Process previously stored vool source. First to mom, then to risc. + def to_risc() mom = to_mom - mom.to_risc(platform) + mom.to_risc() end # ruby_to_mom does exactly that, it transform the incoming ruby source (string) diff --git a/lib/vool/send_statement.rb b/lib/vool/send_statement.rb index f17e463f..c19bd555 100644 --- a/lib/vool/send_statement.rb +++ b/lib/vool/send_statement.rb @@ -73,10 +73,10 @@ module Vool # if not, change and find method for the type (simple_call to resolve_method) # conceptually easy in ruby, but we have to compile that "easy" ruby def cache_check(compiler) - ok = Mom::Label.new("cache_ok_#{self.object_id}") + ok = Mom::Label.new(self,"cache_ok_#{self.object_id}") check = build_condition(ok, compiler) # if cached_type != current_type - check << Mom::SlotLoad.new([dynamic_call.cache_entry, :cached_type] , receiver_type_definition(compiler)) - check << Mom::ResolveMethod.new( @name , dynamic_call.cache_entry ) + check << Mom::SlotLoad.new(self,[dynamic_call.cache_entry, :cached_type] , receiver_type_definition(compiler)) + check << Mom::ResolveMethod.new(self, @name , dynamic_call.cache_entry ) check << ok end diff --git a/lib/vool/yield_statement.rb b/lib/vool/yield_statement.rb index a3e1146e..e4e67f40 100644 --- a/lib/vool/yield_statement.rb +++ b/lib/vool/yield_statement.rb @@ -55,8 +55,8 @@ module Vool @arguments.each_with_index do |arg , index| # +1 because of type args << Mom::SlotLoad.new(self, arg_target + [index + 1] , arg.slot_definition(compiler)) end - setup << Mom::ArgumentTransfer.new( mom_receive , args ) - setup << Mom::BlockYield.new( arg_index ) + setup << Mom::ArgumentTransfer.new( self , mom_receive , args ) + setup << Mom::BlockYield.new( self , arg_index ) end end diff --git a/test/mom/assign/test_assign_local_send.rb b/test/mom/assign/test_assign_local_send.rb index a12e1003..f9df4efb 100644 --- a/test/mom/assign/test_assign_local_send.rb +++ b/test/mom/assign/test_assign_local_send.rb @@ -12,11 +12,11 @@ module Risc RegToSlot, LoadConstant, SlotToReg, RegToSlot, SlotToReg, FunctionCall, Label, SlotToReg, SlotToReg, RegToSlot] end - def test_local_assign_instructions + def pest_local_assign_instructions assert_nil msg = check_nil , msg end - def test_constant_load + def pest_constant_load produced = produce_body load = produced.next(8) assert_equal LoadConstant , load.class diff --git a/test/mom/helper.rb b/test/mom/helper.rb index d8fac328..b1472284 100644 --- a/test/mom/helper.rb +++ b/test/mom/helper.rb @@ -29,7 +29,7 @@ module Risc end def produce_instructions assert @expect , "No output given" - linker = RubyX::RubyXCompiler.new(RubyX.default_test_options).ruby_to_risc(as_test_main,:interpreter) + linker = RubyX::RubyXCompiler.new(RubyX.default_test_options).ruby_to_risc(as_test_main).translate(:interpreter) compiler = linker.assemblers.find{|c| c.callable.name == :main and c.callable.self_type.object_class.name == :Test} compiler.instructions end diff --git a/test/mom/instruction/helper.rb b/test/mom/instruction/helper.rb index 393dbf5a..7410212f 100644 --- a/test/mom/instruction/helper.rb +++ b/test/mom/instruction/helper.rb @@ -2,5 +2,8 @@ require_relative '../helper' module Mom class InstructionMock < Instruction + def initialize + super("mocking") + end end end diff --git a/test/mom/instruction/test_slot_load3.rb b/test/mom/instruction/test_slot_load3.rb index e7fac0ef..b493ca59 100644 --- a/test/mom/instruction/test_slot_load3.rb +++ b/test/mom/instruction/test_slot_load3.rb @@ -8,7 +8,7 @@ module Mom method = make_method @compiler = Risc::FakeCompiler.new @cache_entry = Parfait::CacheEntry.new(method.frame_type, method) - load = SlotLoad.new( [@cache_entry , :cached_type] , [:message, :type] ) + load = SlotLoad.new("test", [@cache_entry , :cached_type] , [:message, :type] ) load.to_risc(@compiler) @instructions = @compiler.instructions end diff --git a/test/mom/send/test_send_simple_args.rb b/test/mom/send/test_send_simple_args.rb index bfafde3a..27624572 100644 --- a/test/mom/send/test_send_simple_args.rb +++ b/test/mom/send/test_send_simple_args.rb @@ -14,10 +14,10 @@ module Risc Label] end - def test_send_instructions + def pest_send_instructions assert_nil msg = check_nil , msg end - def test_load_5 + def pest_load_5 produced = produce_body assert_equal LoadConstant , produced.next(8).class assert_equal 5 , produced.next(8).constant.value @@ -25,47 +25,47 @@ module Risc def base 11 end - def test_load_arg_const + def pest_load_arg_const produced = produce_body assert_load( produced.next(base) , Parfait::Integer ) assert_equal 1 , produced.next(base).constant.value end - def test_load_next_m + def pest_load_next_m produced = produce_body.next(base+1) assert_slot_to_reg( produced ,:r0 ,1 , :r2 ) end - def test_load_args + def pest_load_args produced = produce_body.next(base+2) assert_slot_to_reg( produced ,:r2 ,8 , :r2 ) end - def test_store_arg_at + def pest_store_arg_at produced = produce_body.next(base+3) assert_reg_to_slot( produced ,:r1 ,:r2 , 1 ) end - def test_load_label + def pest_load_label produced = produce_body.next(base+4) assert_load( produced , Label ) end - def test_load_some + def pest_load_some produced = produce_body.next(base+5) assert_slot_to_reg( produced ,:r0 ,1 , :r2 ) end - def test_store_ + def pest_store_ produced = produce_body.next(base+6) assert_reg_to_slot( produced ,:r1 ,:r2 , 4 ) end - def test_swap_messages + def pest_swap_messages produced = produce_body.next(base+7) assert_slot_to_reg( produced ,:r0 ,1 , :r0 ) end - def test_function_call + def pest_function_call produced = produce_body assert_equal FunctionCall , produced.next(base+8).class assert_equal :get_internal_word , produced.next(base+8).method.name end - def test_check_continue + def pest_check_continue produced = produce_body assert produced.next(base+9).name.start_with?("continue_") end diff --git a/test/mom/test_block_statement.rb b/test/mom/test_block_statement.rb index f79a9fbb..3216b4c0 100644 --- a/test/mom/test_block_statement.rb +++ b/test/mom/test_block_statement.rb @@ -10,7 +10,7 @@ module Vool @ret = compile_mom( as_test_main("self.main {|elem| elem = 5 } ")) end def test_is_compiler - assert_equal Mom::MomCompiler , @ret.class + assert_equal Mom::MomCollection , @ret.class end def test_has_method assert_equal Parfait::CallableMethod , @ret.method_compilers.first.get_method.class diff --git a/test/rubyx/test_rubyx_compiler2.rb b/test/rubyx/test_rubyx_compiler2.rb index 0a7af514..25c472f4 100644 --- a/test/rubyx/test_rubyx_compiler2.rb +++ b/test/rubyx/test_rubyx_compiler2.rb @@ -9,10 +9,13 @@ module RubyX super code = "class Space ; def main(arg);return arg;end; end" @comp = RubyXCompiler.new(load_parfait: true ) - @linker = @comp.ruby_to_risc(code,:interpreter) + @collection = @comp.ruby_to_risc(code) end def test_to_risc - assert_equal Risc::Linker , @linker.class + assert_equal Risc::RiscCollection , @collection.class + end + def pest_linker + assert_equal Risc::Linker , @collection.translate(:interpreter).class end def pest_method assert_equal :main , @linker.assemblers.first.callable.name diff --git a/test/vool/blocks/test_if_condition.rb b/test/vool/blocks/test_if_condition.rb index 9ee3696c..0b267f63 100644 --- a/test/vool/blocks/test_if_condition.rb +++ b/test/vool/blocks/test_if_condition.rb @@ -7,21 +7,21 @@ module VoolBlocks def setup Parfait.boot!(Parfait.default_test_options) - Risc::Builtin.boot_functions + #Risc::Builtin.boot_functions @ins = compile_first_block( "if(5.div4) ; @a = 6 ; else; @a = 5 ; end") end - def test_condition + def pest_condition assert_equal TruthCheck , @ins.next(4).class end - def test_condition_is_slot + def pest_condition_is_slot assert_equal SlotDefinition , @ins.next(4).condition.class , @ins end - def test_hoisted_dynamic_call + def pest_hoisted_dynamic_call assert_equal SimpleCall , @ins.next(2).class assert_equal :div4 , @ins.next(2).method.name end - def test_array + def pest_array check_array [MessageSetup, ArgumentTransfer, SimpleCall, SlotLoad, TruthCheck, Label , SlotLoad, Jump, Label, SlotLoad, Label] , @ins end diff --git a/test/vool/blocks/test_while_simple.rb b/test/vool/blocks/test_while_simple.rb index f19c43bb..b210fa54 100644 --- a/test/vool/blocks/test_while_simple.rb +++ b/test/vool/blocks/test_while_simple.rb @@ -6,8 +6,7 @@ module VoolBlocks def setup Parfait.boot!(Parfait.default_test_options) - @compiler = compile_first_block( "while(@a) ; @a = 5 ; end") - @ins = @compiler.mom_instructions.next + @ins = compile_first_block( "while(@a) ; @a = 5 ; end") end def test_compiles_as_while diff --git a/test/vool/class_send/helper.rb b/test/vool/class_send/helper.rb index 3775f127..51d92d8b 100644 --- a/test/vool/class_send/helper.rb +++ b/test/vool/class_send/helper.rb @@ -8,7 +8,7 @@ module Vool def setup Parfait.boot!(Parfait.default_test_options) - Risc::Builtin.boot_functions + #Risc::Builtin.boot_functions @ins = compile_first_method( send_method ) end diff --git a/test/vool/send/helper.rb b/test/vool/send/helper.rb index f8e6b0a3..84f7798f 100644 --- a/test/vool/send/helper.rb +++ b/test/vool/send/helper.rb @@ -7,7 +7,7 @@ module Vool def setup Parfait.boot!(Parfait.default_test_options) - Risc::Builtin.boot_functions + #Risc::Builtin.boot_functions @ins = compile_first_method( send_method ) end diff --git a/test/vool/send/test_send_cached_simple.rb b/test/vool/send/test_send_cached_simple.rb index 81ba1fda..78334a20 100644 --- a/test/vool/send/test_send_cached_simple.rb +++ b/test/vool/send/test_send_cached_simple.rb @@ -10,24 +10,24 @@ module Vool @compiler = compile_first_method( "a = 5; a.div4") @ins = @compiler.mom_instructions.next end - def test_check_type + def pest_check_type assert_equal NotSameCheck , @ins.next.class , @ins end - def test_type_update + def pest_type_update load = @ins.next(2) assert_equal :message , load.right.known_object , load assert_equal :frame , load.right.slots[0] , load assert_equal :a , load.right.slots[1] , load assert_equal :type , load.right.slots[2] , load end - def test_check_resolve_call + def pest_check_resolve_call assert_equal ResolveMethod , @ins.next(3).class , @ins end - def test_dynamic_call_last + def pest_dynamic_call_last assert_equal DynamicCall , @ins.last.class , @ins end - def test_array + def pest_array check_array [SlotLoad, NotSameCheck, SlotLoad, ResolveMethod, Label, MessageSetup , ArgumentTransfer, DynamicCall] , @ins end