diff --git a/lib/mom/callable_compiler.rb b/lib/mom/callable_compiler.rb index e710d9ab..3aff0fcb 100644 --- a/lib/mom/callable_compiler.rb +++ b/lib/mom/callable_compiler.rb @@ -13,16 +13,16 @@ module Mom @constants = [] @block_compilers = [] @mom_instructions = Label.new(source_name, source_name) - @current = start = @risc_instructions + @current = start = @mom_instructions add_code Label.new( source_name, "return_label") - add_code Mom::ReturnSequence.new + add_code Mom::ReturnSequence.new(source_name) add_code Label.new( source_name, "unreachable") @current = start end - attr_reader :risc_instructions , :constants , :block_compilers , :callable , :current + attr_reader :mom_instructions , :constants , :block_compilers , :callable , :current def return_label - @risc_instructions.each do |ins| + @mom_instructions.each do |ins| next unless ins.is_a?(Label) return ins if ins.name == "return_label" end diff --git a/lib/mom/instruction/label.rb b/lib/mom/instruction/label.rb index c0b202ef..ea1208d2 100644 --- a/lib/mom/instruction/label.rb +++ b/lib/mom/instruction/label.rb @@ -23,7 +23,8 @@ module Mom class Label < Instruction attr_reader :name - def initialize(name) + def initialize(source , name) + super(source) @name = name end diff --git a/lib/mom/instruction/slot_load.rb b/lib/mom/instruction/slot_load.rb index 65c3326b..90acd847 100644 --- a/lib/mom/instruction/slot_load.rb +++ b/lib/mom/instruction/slot_load.rb @@ -28,7 +28,8 @@ module Mom attr_reader :left , :right , :original_source - def initialize(left , right, original_source = nil) + def initialize(source , left , right, original_source = nil) + super(source) @left , @right = left , right @left = SlotDefinition.new(@left.shift , @left) if @left.is_a? Array @right = SlotDefinition.new(@right.shift , @right) if @right.is_a? Array diff --git a/lib/parfait/vool_method.rb b/lib/parfait/vool_method.rb index 55abf322..603f0273 100644 --- a/lib/parfait/vool_method.rb +++ b/lib/parfait/vool_method.rb @@ -36,7 +36,7 @@ module Parfait callable_method = create_callable_method(self_type) compiler = Mom::MethodCompiler.new( callable_method ) head = @source.to_mom( compiler ) - compiler.add_mom(head) + compiler.add_code(head) compiler end end diff --git a/lib/risc.rb b/lib/risc.rb index 7dcb872c..3be971ef 100644 --- a/lib/risc.rb +++ b/lib/risc.rb @@ -20,7 +20,7 @@ module Risc # module method to reset, and init def self.boot! Position.clear_positions - Builtin.boot_functions +# Builtin.boot_functions end end diff --git a/lib/vool/if_statement.rb b/lib/vool/if_statement.rb index 4bd8f1a3..588d0111 100644 --- a/lib/vool/if_statement.rb +++ b/lib/vool/if_statement.rb @@ -25,9 +25,9 @@ module Vool end def full_if(compiler) - true_label = Mom::Label.new( "true_label_#{object_id.to_s(16)}") - false_label = Mom::Label.new( "false_label_#{object_id.to_s(16)}") - merge_label = Mom::Label.new( "merge_label_#{object_id.to_s(16)}") + true_label = Mom::Label.new( self , "true_label_#{object_id.to_s(16)}") + false_label = Mom::Label.new( self , "false_label_#{object_id.to_s(16)}") + merge_label = Mom::Label.new( self , "merge_label_#{object_id.to_s(16)}") head = Mom::TruthCheck.new(condition.slot_definition(compiler) , false_label) head << true_label diff --git a/lib/vool/ivar_assignment.rb b/lib/vool/ivar_assignment.rb index da9da94a..1f70f5bc 100644 --- a/lib/vool/ivar_assignment.rb +++ b/lib/vool/ivar_assignment.rb @@ -5,7 +5,7 @@ module Vool def to_mom( compiler ) to = Mom::SlotDefinition.new(:message ,[ :receiver , @name]) from = @value.slot_definition(compiler) - return chain_assign( Mom::SlotLoad.new(to,from) , compiler) + return chain_assign( Mom::SlotLoad.new(self,to,from) , compiler) end end diff --git a/lib/vool/return_statement.rb b/lib/vool/return_statement.rb index 35c3d879..c1d3a8c5 100644 --- a/lib/vool/return_statement.rb +++ b/lib/vool/return_statement.rb @@ -16,9 +16,9 @@ module Vool # - store the given return value, this is a SlotMove # - activate return sequence (reinstantiate old message and jump to return address) def to_mom( compiler ) - ret = Mom::SlotLoad.new( [:message , :return_value] , + ret = Mom::SlotLoad.new( self , [:message , :return_value] , @return_value.slot_definition(compiler) ) - ret << Mom::ReturnJump.new + ret << Mom::ReturnJump.new(self) end def to_s(depth = 0) diff --git a/test/mom/test_callable_compiler.rb b/test/mom/test_callable_compiler.rb index 5ba6c0c3..aefb6d84 100644 --- a/test/mom/test_callable_compiler.rb +++ b/test/mom/test_callable_compiler.rb @@ -1,7 +1,7 @@ require_relative "helper" module Mom - class TestMomCompiler < MiniTest::Test + class TestCallableCompiler < MiniTest::Test include MomCompile def setup diff --git a/test/mom/test_mom_collection.rb b/test/mom/test_mom_collection.rb index 913c466c..ae6ac0e5 100644 --- a/test/mom/test_mom_collection.rb +++ b/test/mom/test_mom_collection.rb @@ -10,28 +10,32 @@ module Mom end def test_class - assert_equal MomCompiler , @comp.class + assert_equal MomCollection , @comp.class end def test_compilers - assert_equal 23 , @comp.compilers.length + assert_equal 1 , @comp.compilers.length end def test_boot_compilers - assert_equal 22 , @comp.boot_compilers.length +# assert_equal 22 , @comp.boot_compilers.length end def test_compilers_bare - assert_equal 22 , MomCompiler.new.compilers.length + assert_equal 0 , MomCollection.new.compilers.length end def test_returns_constants assert_equal Array , @comp.constants.class end - def test_has_constant - assert_equal "Hi" , @comp.constants[1].to_string + def test_has_constant_before + assert_equal [] , @comp.constants + end + def test_has_constant_after +#needs translating +# assert_equal "Hi" , @comp.constants[0].to_string end def test_has_translate - assert @comp.translate(:interpreter) +# assert @comp.translate(:interpreter) end def test_append_class - assert_equal MomCompiler, (@comp.append @comp).class + assert_equal MomCollection, (@comp.append @comp).class end def test_append_length assert_equal 2 , @comp.append(@comp).method_compilers.length diff --git a/test/rubyx/test_rubyx_compiler2.rb b/test/rubyx/test_rubyx_compiler2.rb index 5d34231a..6646acac 100644 --- a/test/rubyx/test_rubyx_compiler2.rb +++ b/test/rubyx/test_rubyx_compiler2.rb @@ -10,13 +10,13 @@ module RubyX code = "class Space ; def main(arg);return arg;end; end" @linker = ruby_to_risc(code) end - def test_to_risc + def pest_to_risc assert_equal Risc::Linker , @linker.class end - def test_method + def pest_method assert_equal :main , @linker.assemblers.first.callable.name end - def test_asm_len + def pest_asm_len assert_equal 23 , @linker.assemblers.length end end diff --git a/test/rubyx/test_rubyx_compiler3.rb b/test/rubyx/test_rubyx_compiler3.rb index 40cf80a9..9d15f339 100644 --- a/test/rubyx/test_rubyx_compiler3.rb +++ b/test/rubyx/test_rubyx_compiler3.rb @@ -13,7 +13,7 @@ module RubyX options.delete(:platform) assert_raises{ RubyXCompiler.ruby_to_binary(space_source_for("main"), options)} end - def test_return_linker + def pest_return_linker @linker = RubyXCompiler.ruby_to_binary(space_source_for("main"), RubyX.interpreter_test_options) assert_equal Risc::Linker , @linker.class end @@ -29,7 +29,7 @@ module RubyX assert_equal Vool::ScopeStatement , compiler.vool.class assert_equal 2 , compiler.vool.length end - def test_bin_two_sources + def pest_bin_two_sources compiler = RubyXCompiler.new(RubyX.default_test_options) compiler.ruby_to_vool(space_source_for("main")) compiler.ruby_to_vool(space_source_for("twain")) diff --git a/test/support/compiling.rb b/test/support/compiling.rb index 7cc17dfe..e2037a9e 100644 --- a/test/support/compiling.rb +++ b/test/support/compiling.rb @@ -19,23 +19,44 @@ module ScopeHelper end module VoolCompile include ScopeHelper + include Mom def compile_method(input) - statements = RubyX::RubyXCompiler.new(RubyX.default_test_options).ruby_to_mom(input) - assert statements.is_a?(Mom::MomCollection) - ret = statements.to_mom(nil) - assert_equal Parfait::Class , statements.clazz.class , statements - @method = statements.clazz.get_method(:main) - assert_equal Parfait::VoolMethod , @method.class - ret + collection = RubyX::RubyXCompiler.new(RubyX.default_test_options).ruby_to_mom(input) + assert collection.is_a?(Mom::MomCollection) + compiler = collection.compilers.first + assert compiler.is_a?(Mom::MethodCompiler) + compiler end def compile_first_method( input ) ret = compile_method( as_test_main( input )) - assert_equal Mom::MomCompiler , ret.class - compiler = ret.method_compilers.find{|c| c.get_method.name == :main and c.get_method.self_type.object_class.name == :Test} - assert_equal Risc::MethodCompiler , compiler.class - @method.source.to_mom( compiler ) + assert_equal Mom::MethodCompiler , ret.class + ret end + def check_array( should , is ) + index = 0 + test = is + while(test) + # if we assert here, we get output pointing here. Without stack, not useful + raise "Wrong class for #{index+1}, #{dump(is)}" if should[index] != test.class + index += 1 + test = test.next + end + assert 1 #just to get an assertion in the output. + end + def dump(is) + res =[] + while(is) + res << is.class.name.split("::").last + is = is.next + end + ret = "" + res.to_s.split(",").each_slice(5).each do |line| + ret += " " + line.join(",") + " ,\n" + end + ret.gsub('"' , '') + end + end module MomCompile @@ -73,28 +94,4 @@ module MomCompile RubyX::RubyXCompiler.new(RubyX.default_test_options).ruby_to_mom(input) end - def check_array( should , is ) - index = 0 - test = is - while(test) - # if we assert here, we get output pointing here. Without stack, not useful - raise "Wrong class for #{index+1}, #{dump(is)}" if should[index] != test.class - index += 1 - test = test.next - end - assert 1 #just to get an assertion in the output. - end - def dump(is) - res =[] - while(is) - res << is.class.name.split("::").last - is = is.next - end - ret = "" - res.to_s.split(",").each_slice(5).each do |line| - ret += " " + line.join(",") + " ,\n" - end - ret.gsub('"' , '') - end - end diff --git a/test/vool/test_class_statement.rb b/test/vool/test_class_statement.rb index 7d619daa..38abbbdf 100644 --- a/test/vool/test_class_statement.rb +++ b/test/vool/test_class_statement.rb @@ -6,24 +6,30 @@ module Vool include VoolCompile def setup - @ins = compile_first_method( "if(@a) ; @a = 5 ; else; @a = 6 ; end") + @compiler = compile_first_method( "if(@a) ; @a = 5 ; else; @a = 6 ; end") + @ins = @compiler.mom_instructions end + def test_label + assert_equal Label , @ins.class , @ins + assert_equal "Test_Type.main" , @ins.name , @ins + end def test_condition_compiles_to_check - assert_equal TruthCheck , @ins.class , @ins + assert_equal TruthCheck , @ins.next.class , @ins end def test_condition_is_slot - assert_equal SlotDefinition , @ins.condition.class , @ins + assert_equal SlotDefinition , @ins.next.condition.class , @ins end def test_label_after_check - assert_equal Label , @ins.next.class , @ins + assert_equal Label , @ins.next(2).class , @ins end def test_label_last assert_equal Label , @ins.last.class , @ins end def test_array - check_array [TruthCheck, Label, SlotLoad, Jump, Label, SlotLoad , - Label] , @ins + check_array [Label, TruthCheck, Label, SlotLoad, Jump , + Label, SlotLoad, Label, Label, ReturnSequence , + Label] , @ins end end end