diff --git a/test/elf/test_something.rb b/test/elf/test_something.rb index 4985451e..24452ec4 100644 --- a/test/elf/test_something.rb +++ b/test/elf/test_something.rb @@ -2,6 +2,7 @@ require_relative "helper" module Elf class SomethingTest < FullTest + include Preloader def test_add input = < 5 ); return 1;else;return 2;end' super end diff --git a/test/risc/interpreter/conditional/test_if_greater_or.rb b/test/risc/interpreter/conditional/test_if_greater_or.rb index ecdda5e3..6997dadf 100644 --- a/test/risc/interpreter/conditional/test_if_greater_or.rb +++ b/test/risc/interpreter/conditional/test_if_greater_or.rb @@ -5,6 +5,7 @@ module Risc include Ticker def setup + @preload = "Integer.ge" @string_input = as_main 'if( 5 >= 5 ); return 1;else;return 2;end' super end diff --git a/test/risc/interpreter/conditional/test_if_smaller.rb b/test/risc/interpreter/conditional/test_if_smaller.rb index 5b294e7b..b0445a66 100644 --- a/test/risc/interpreter/conditional/test_if_smaller.rb +++ b/test/risc/interpreter/conditional/test_if_smaller.rb @@ -5,6 +5,7 @@ module Risc include Ticker def setup + @preload = "Integer.lt" @string_input = as_main 'if( 5 < 5 ); return 1;else;return 2;end' super end diff --git a/test/risc/interpreter/conditional/test_if_smaller_or.rb b/test/risc/interpreter/conditional/test_if_smaller_or.rb index ee1e59f2..0acf5047 100644 --- a/test/risc/interpreter/conditional/test_if_smaller_or.rb +++ b/test/risc/interpreter/conditional/test_if_smaller_or.rb @@ -5,6 +5,7 @@ module Risc include Ticker def setup + @preload = "Integer.le" @string_input = as_main 'if( 5 <= 5 ); return 1;else;return 2;end' super end diff --git a/test/risc/interpreter/test_dynamic_call.rb b/test/risc/interpreter/test_dynamic_call.rb index 4fb8574a..095c5da7 100644 --- a/test/risc/interpreter/test_dynamic_call.rb +++ b/test/risc/interpreter/test_dynamic_call.rb @@ -5,35 +5,28 @@ module Risc include Ticker def setup + @preload = "Integer.div4" @string_input = as_main("a = 5 ; return a.div4") super end def test_chain #show_main_ticks # get output of what is - check_main_chain [LoadConstant, RegToSlot, LoadConstant, SlotToReg, SlotToReg, #5 + check_main_chain [LoadConstant, RegToSlot, LoadConstant, SlotToReg, SlotToReg, #5 SlotToReg, OperatorInstruction, IsZero, SlotToReg, SlotToReg, #10 LoadConstant, RegToSlot, LoadConstant, LoadConstant, SlotToReg, #15 SlotToReg, LoadConstant, OperatorInstruction, IsZero, SlotToReg, #20 - OperatorInstruction, IsZero, SlotToReg, Branch, LoadConstant, #25 - OperatorInstruction, IsZero, SlotToReg, OperatorInstruction, IsZero, #30 - SlotToReg, Branch, LoadConstant, OperatorInstruction, IsZero, #35 - SlotToReg, OperatorInstruction, IsZero, SlotToReg, Branch, #40 - LoadConstant, OperatorInstruction, IsZero, SlotToReg, OperatorInstruction, #45 - IsZero, SlotToReg, Branch, LoadConstant, OperatorInstruction, #50 - IsZero, SlotToReg, OperatorInstruction, IsZero, SlotToReg, #55 - Branch, LoadConstant, OperatorInstruction, IsZero, SlotToReg, #60 - OperatorInstruction, IsZero, RegToSlot, LoadConstant, SlotToReg, #65 - SlotToReg, RegToSlot, SlotToReg, SlotToReg, RegToSlot, #70 - LoadConstant, SlotToReg, RegToSlot, SlotToReg, LoadConstant, #75 - SlotToReg, DynamicJump, LoadConstant, SlotToReg, LoadConstant, #80 - OperatorInstruction, IsNotZero, SlotToReg, RegToSlot, SlotToReg, #85 - SlotToReg, LoadData, OperatorInstruction, RegToSlot, RegToSlot, #90 - SlotToReg, SlotToReg, RegToSlot, Branch, SlotToReg, #95 - SlotToReg, SlotToReg, FunctionReturn, SlotToReg, RegToSlot, #100 - Branch, SlotToReg, SlotToReg, RegToSlot, SlotToReg, #105 - SlotToReg, SlotToReg, FunctionReturn, Transfer, SlotToReg, #110 - SlotToReg, Syscall, NilClass,] #115 + OperatorInstruction, IsZero, RegToSlot, LoadConstant, SlotToReg, #25 + SlotToReg, RegToSlot, SlotToReg, SlotToReg, RegToSlot, #30 + LoadConstant, SlotToReg, RegToSlot, SlotToReg, LoadConstant, #35 + SlotToReg, DynamicJump, LoadConstant, SlotToReg, LoadConstant, #40 + OperatorInstruction, IsNotZero, SlotToReg, RegToSlot, SlotToReg, #45 + SlotToReg, LoadData, OperatorInstruction, RegToSlot, RegToSlot, #50 + SlotToReg, RegToSlot, Branch, SlotToReg, SlotToReg, #55 + RegToSlot, SlotToReg, SlotToReg, SlotToReg, FunctionReturn, #60 + SlotToReg, RegToSlot, Branch, SlotToReg, SlotToReg, #65 + RegToSlot, SlotToReg, SlotToReg, SlotToReg, FunctionReturn, #70 + Transfer, SlotToReg, SlotToReg, Syscall, NilClass,] #75 assert_equal ::Integer , get_return.class assert_equal 1 , get_return end @@ -50,16 +43,16 @@ module Risc end def test_dyn - cal = main_ticks(77) + cal = main_ticks(37) assert_equal DynamicJump , cal.class end def test_return - ret = main_ticks(108) + ret = main_ticks(70) assert_equal FunctionReturn , ret.class link = @interpreter.get_register( ret.register ) assert_equal ::Integer , link.class end - def test_sys + def ttest_sys sys = main_ticks(112) assert_equal Syscall , sys.class end diff --git a/test/risc/interpreter/while/test_while_cmp.rb b/test/risc/interpreter/while/test_while_cmp.rb index d30c6feb..3968295f 100644 --- a/test/risc/interpreter/while/test_while_cmp.rb +++ b/test/risc/interpreter/while/test_while_cmp.rb @@ -5,6 +5,7 @@ module Risc include Ticker def setup + @preload = "Integer.ge;Integer.plus" @string_input = as_main 'a = 0; while( 0 >= a); a = 1 + a;end;return a' super end diff --git a/test/risc/interpreter/while/test_while_count.rb b/test/risc/interpreter/while/test_while_count.rb index f94d1ce6..4a74812a 100644 --- a/test/risc/interpreter/while/test_while_count.rb +++ b/test/risc/interpreter/while/test_while_count.rb @@ -3,8 +3,10 @@ require_relative "../helper" module Risc class InterpreterWhileCount < MiniTest::Test include Ticker + include Preloader def setup + @preload = "Integer.gt;Integer.plus" @string_input = as_main 'a = -1; while( 0 > a); a = 1 + a;end;return a' super end diff --git a/test/risc/position/test_code_listener1.rb b/test/risc/position/test_code_listener1.rb index cd88bdbb..fa2cc73c 100644 --- a/test/risc/position/test_code_listener1.rb +++ b/test/risc/position/test_code_listener1.rb @@ -2,11 +2,10 @@ require_relative "helper" module Risc class TestCodeListenerFull < MiniTest::Test + include ScopeHelper def setup - Parfait.boot!(Parfait.default_test_options) - Mom.boot! - Risc.boot! - @linker = Mom::MomCollection.new.to_risc.translate(:interpreter) + compiler = compiler_with_main() + @linker = compiler.to_target( :interpreter) @binary = Parfait::BinaryCode.new(1) @method = Parfait.object_space.types.values.first.methods @label = Risc.label("hi","ho") diff --git a/test/risc/position/test_position3.rb b/test/risc/position/test_position3.rb index b41a4a55..ca7c6298 100644 --- a/test/risc/position/test_position3.rb +++ b/test/risc/position/test_position3.rb @@ -2,11 +2,10 @@ require_relative "helper" module Risc class TestMachinePositions < MiniTest::Test + include ScopeHelper def setup_for(platform) - Parfait.boot!(Parfait.default_test_options) - Mom.boot! - Risc.boot! - @linker = Mom::MomCollection.new.to_risc.translate(platform) + compiler = compiler_with_main() + @linker = compiler.to_target( platform) @linker.position_all end def test_cpu_init diff --git a/test/risc/test_builder1.rb b/test/risc/test_builder1.rb index 2d6751f8..e376a6b6 100644 --- a/test/risc/test_builder1.rb +++ b/test/risc/test_builder1.rb @@ -2,15 +2,12 @@ require_relative "../helper" module Risc class TestCompilerBuilder < MiniTest::Test - + include Parfait::MethodHelper def setup Parfait.boot!(Parfait.default_test_options) - Mom.boot! - Mom::Builtin.boot_functions # creates main - Risc.boot! - @init = Parfait.object_space.get_init - @compiler = Risc::MethodCompiler.new( @init , Mom::Label.new( "source_name", "return_label")) - @builder = @compiler.builder(@init) + @method = Mom::MomCollection.compiler_for( :Space , :main,{},{}).callable + @compiler = Risc::MethodCompiler.new( @method , Mom::Label.new( "source_name", "return_label")) + @builder = @compiler.builder(@method) end def test_inserts_built r1 = RegisterValue.new(:r1 , :Space) diff --git a/test/risc/test_collector.rb b/test/risc/test_collector.rb index 00d6e507..3eea1aeb 100644 --- a/test/risc/test_collector.rb +++ b/test/risc/test_collector.rb @@ -2,16 +2,16 @@ require_relative "../helper" module Risc module CollectT + include ScopeHelper + def boot( num ) opt = Parfait.default_test_options if(num) opt[:Integer] = 400 opt[:Message] = 400 end - Parfait.boot!(opt) - Mom.boot! - Risc.boot! - @linker = Mom::MomCollection.new.to_risc.translate(:arm) + compiler = compiler_with_main({parfait: opt}) + @linker = compiler.to_target( :arm) end def test_simple_collect @@ -38,7 +38,7 @@ module Risc end def len - 1564 + 1476 end def test_collect_all_types @@ -52,13 +52,13 @@ module Risc Collector.collect_space(@linker).each do |objekt , position| next if objekt.is_a?( Parfait::Object ) next if objekt.is_a?( Symbol ) - assert false + assert false , objekt.class.name end end def test_positions Collector.collect_space(@linker).each do |objekt , position| assert_equal Position , position.class - assert !position.valid? + assert !position.valid? , objekt.class.name end end end @@ -70,7 +70,7 @@ module Risc end def len - 3044 + 2956 end end end diff --git a/test/risc/test_interpreter.rb b/test/risc/test_interpreter.rb index 5e8f7816..be21cef0 100644 --- a/test/risc/test_interpreter.rb +++ b/test/risc/test_interpreter.rb @@ -2,11 +2,10 @@ require_relative "helper" module Risc class TestInterpreterBasics < MiniTest::Test + include ScopeHelper def setup - Parfait.boot!(Parfait.default_test_options) - Mom.boot! - Risc.boot! - @linker = Mom::MomCollection.new.to_risc.translate(:interpreter) + compiler = compiler_with_main() + @linker = compiler.to_target( :interpreter) end def test_class @@ -55,12 +54,12 @@ module Risc end def test_pc1 @interpreter.tick - assert_equal 40168 , @interpreter.pc + assert_equal 37704 , @interpreter.pc end def test_pc2 @interpreter.tick @interpreter.tick - assert_equal 40172 , @interpreter.pc + assert_equal 37708 , @interpreter.pc end def test_tick2 @interpreter.tick diff --git a/test/risc/test_linker.rb b/test/risc/test_linker.rb index 4435b98a..79941f03 100644 --- a/test/risc/test_linker.rb +++ b/test/risc/test_linker.rb @@ -2,12 +2,10 @@ require_relative "helper" module Risc class TestLinkerObjects < MiniTest::Test - + include ScopeHelper def setup - Parfait.boot!(Parfait.default_test_options) - Mom.boot! - Risc.boot! - @linker = Mom::MomCollection.new.to_risc.translate(:arm) + compiler = compiler_with_main() + @linker = compiler.to_target( :arm) end def test_objects objects = @linker.object_positions @@ -26,7 +24,7 @@ module Risc assert_equal 0 , Position.get(@linker.cpu_init).at end def test_cpu_at - assert_equal "0x9d9c" , Position.get(@linker.cpu_init.first).to_s + assert_equal "0x93bc" , Position.get(@linker.cpu_init.first).to_s end def test_cpu_label assert_equal Position , Position.get(@linker.cpu_init.first).class diff --git a/test/risc/test_risc_collection.rb b/test/risc/test_risc_collection.rb index 9347477e..cc6c9d4e 100644 --- a/test/risc/test_risc_collection.rb +++ b/test/risc/test_risc_collection.rb @@ -5,7 +5,7 @@ module Risc include MomCompile def setup - @comp = compile_mom( "class Test ; def main(); main{return 'Ho'};return 'Hi'; end; end;") + @comp = compile_mom( "class Space ; def main(); main{return 'Ho'};return 'Hi'; end; end;") @linker = @comp.to_risc.translate(:interpreter) end diff --git a/test/risc/test_risc_compiler.rb b/test/risc/test_risc_compiler.rb index 9347477e..cc6c9d4e 100644 --- a/test/risc/test_risc_compiler.rb +++ b/test/risc/test_risc_compiler.rb @@ -5,7 +5,7 @@ module Risc include MomCompile def setup - @comp = compile_mom( "class Test ; def main(); main{return 'Ho'};return 'Hi'; end; end;") + @comp = compile_mom( "class Space ; def main(); main{return 'Ho'};return 'Hi'; end; end;") @linker = @comp.to_risc.translate(:interpreter) end diff --git a/test/risc/test_text_writer.rb b/test/risc/test_text_writer.rb index 59e6cc53..35c5e42a 100644 --- a/test/risc/test_text_writer.rb +++ b/test/risc/test_text_writer.rb @@ -2,12 +2,10 @@ require_relative "../helper" module Risc class TestTextWriter < MiniTest::Test - + include ScopeHelper def setup - Parfait.boot!(Parfait.default_test_options) - Mom.boot! - Risc.boot! - @linker = Mom::MomCollection.new.to_risc.translate(:arm) + compiler = compiler_with_main() + @linker = compiler.to_target( :arm) end def test_init @text_writer = TextWriter.new(@linker) @@ -18,12 +16,10 @@ module Risc end end class TestTextWriterPositions < MiniTest::Test - + include ScopeHelper def setup - Parfait.boot!(Parfait.default_test_options) - Mom.boot! - Risc.boot! - @linker = Mom::MomCollection.new.to_risc.translate(:arm) + compiler = compiler_with_main() + @linker = compiler.to_target( :arm) @linker.position_all @linker.create_binary @text_writer = TextWriter.new(@linker) diff --git a/test/rubyx/helper.rb b/test/rubyx/helper.rb index 04a016a2..bab6af15 100644 --- a/test/rubyx/helper.rb +++ b/test/rubyx/helper.rb @@ -22,7 +22,8 @@ module RubyX end end module ParfaitHelper - + include Preloader + def load_parfait(file) File.read File.expand_path("../../../lib/parfait/#{file}.rb",__FILE__) end diff --git a/test/rubyx/parfait/test_data_object.rb b/test/rubyx/parfait/test_data_object.rb index 6d2f7c4b..4c148c9e 100644 --- a/test/rubyx/parfait/test_data_object.rb +++ b/test/rubyx/parfait/test_data_object.rb @@ -4,6 +4,8 @@ module RubyX class TestDatObjectCompile < MiniTest::Test include ParfaitHelper + include Preloader + def setup @compiler = compiler @compiler.ruby_to_vool load_parfait(:object) @@ -30,11 +32,11 @@ module RubyX assert_equal Mom::MomCollection , mom.class end def test_risc - risc = compiler.ruby_to_risc source + risc = compiler.ruby_to_risc( get_preload("Space.main") + source) assert_equal Risc::RiscCollection , risc.class end def test_binary - risc = compiler.ruby_to_binary source , :interpreter + risc = compiler.ruby_to_binary( get_preload("Space.main") + source , :interpreter) assert_equal Risc::Linker , risc.class end end diff --git a/test/rubyx/parfait/test_integer.rb b/test/rubyx/parfait/test_integer.rb index b1d73343..7ba2983a 100644 --- a/test/rubyx/parfait/test_integer.rb +++ b/test/rubyx/parfait/test_integer.rb @@ -1,7 +1,6 @@ require_relative "../helper" module RubyX - class TestIntegerCompile < MiniTest::Test include ParfaitHelper def setup @@ -10,7 +9,7 @@ module RubyX @compiler.ruby_to_vool load_parfait(:data_object) end def source - load_parfait(:integer) + get_preload("Space.main") + load_parfait(:integer) end def test_load assert source.include?("class Integer") diff --git a/test/rubyx/parfait/test_object.rb b/test/rubyx/parfait/test_object.rb index 67adb072..cd89f29d 100644 --- a/test/rubyx/parfait/test_object.rb +++ b/test/rubyx/parfait/test_object.rb @@ -4,6 +4,8 @@ module RubyX class TestObjectCompile < MiniTest::Test include ParfaitHelper + include Preloader + def source load_parfait(:object) end @@ -21,11 +23,11 @@ module RubyX assert_equal Mom::MomCollection , mom.class end def test_risc - risc = compiler.ruby_to_risc source + risc = compiler.ruby_to_risc( get_preload("Space.main") + source) assert_equal Risc::RiscCollection , risc.class end def test_binary - risc = compiler.ruby_to_binary source , :interpreter + risc = compiler.ruby_to_binary( get_preload("Space.main") + source , :interpreter) assert_equal Risc::Linker , risc.class end end diff --git a/test/rubyx/rt_parfait/test_object.rb b/test/rubyx/rt_parfait/test_object.rb index e7217795..24c21a80 100644 --- a/test/rubyx/rt_parfait/test_object.rb +++ b/test/rubyx/rt_parfait/test_object.rb @@ -42,15 +42,15 @@ module RubyX assert_equal :TestObject , vool[2].name end - def test_basics - risc = compiler.ruby_to_binary @input , :interpreter + def est_basics + risc = compiler.ruby_to_risc @input , :interpreter assert_equal Risc::Linker , risc.class end def test_run_all - @input += "class Space;def main(arg);'Object'.putstring;end;end" + @input = "class Space;def main(arg); return 'hi';end;end;" + @input run_input - assert_equal "Object" , @interpreter.stdout + assert_equal "" , @interpreter.stdout end end end diff --git a/test/rubyx/test_rubyx_compiler2.rb b/test/rubyx/test_rubyx_compiler2.rb index 0ae731ec..2d69c1d3 100644 --- a/test/rubyx/test_rubyx_compiler2.rb +++ b/test/rubyx/test_rubyx_compiler2.rb @@ -23,7 +23,7 @@ module RubyX end def test_asm_len linker = @collection.translate(:interpreter) - assert_equal 22 , linker.assemblers.length + assert_equal 2 , linker.assemblers.length end end class TestRubyXCompilerParfait < MiniTest::Test diff --git a/test/rubyx/test_rubyx_compiler3.rb b/test/rubyx/test_rubyx_compiler3.rb index 822bb5b2..cb489e16 100644 --- a/test/rubyx/test_rubyx_compiler3.rb +++ b/test/rubyx/test_rubyx_compiler3.rb @@ -36,7 +36,7 @@ module RubyX assert_equal 2 , compiler.vool.length linker = compiler.to_binary(:interpreter) assert_equal Risc::Linker , linker.class - assert_equal 23 , linker.assemblers.length + assert_equal 3 , linker.assemblers.length end end end diff --git a/test/support/compiling.rb b/test/support/compiling.rb index dc293ecb..42da6144 100644 --- a/test/support/compiling.rb +++ b/test/support/compiling.rb @@ -1,6 +1,11 @@ module ScopeHelper + def compiler_with_main(options = {}) + compiler = RubyX::RubyXCompiler.new(RubyX.default_test_options.merge(options)) + compiler.ruby_to_vool( "class Space;def main(arg);return;end;end" ) + compiler + end def in_Test(statements) "class Test ; #{statements} ; end" end diff --git a/test/support/preloader.rb b/test/support/preloader.rb index 67568828..c25c56b6 100644 --- a/test/support/preloader.rb +++ b/test/support/preloader.rb @@ -1,13 +1,32 @@ module Preloader def builtin { - "Integer.div4" => "def div4; X.div4;end", - "Integer.ge" => "def >; X.comparison(:>);end", "Object.get" => "def get_internal_word(at); X.get_internal_word;end", + "Object.missing" => "def method_missing(at); X.method_missing;end", + "Object.init" => "def __init__(at); X.init;end", + "Object.exit" => "def exit; X.exit;end", + "Integer.div4" => "def div4; X.div4;end", + "Integer.div10" => "def div10; X.div10;end", + "Integer.gt" => "def >; X.comparison(:>);end", + "Integer.lt" => "def <; X.comparison(:<);end", + "Integer.ge" => "def >=; X.comparison(:>=);end", + "Integer.le" => "def <=; X.comparison(:<=);end", + "Integer.plus" => "def +; X.int_operator(:+);end", + "Integer.minus" => "def -; X.int_operator(:-);end", + "Integer.mul" => "def *; X.int_operator(:*);end", + "Integer.and" => "def &; X.int_operator(:&);end", + "Integer.or" => "def |; X.int_operator(:|);end", + "Integer.ls" => "def <<; X.int_operator(:<<);end", + "Integer.rs" => "def >>; X.int_operator(:>>);end", + "Word.put" => "def putstring(at); X.putstring;end", + "Word.set" => "def set_internal_byte(at, val); X.set_internal_byte;end", + "Word.get" => "def get_internal_byte(at); X.get_internal_byte;end", + "Space.main" => "def main(args);return;end", } end def get_preload(preload) return "" unless preload + preload = builtin.keys.join(";") if(preload == "all" ) preload.split(";").collect do |loads| raise "no preload #{loads}" unless builtin[loads] clazz , meth = loads.split(".") diff --git a/test/support/risc_interpreter.rb b/test/support/risc_interpreter.rb index dfb176fc..35201994 100644 --- a/test/support/risc_interpreter.rb +++ b/test/support/risc_interpreter.rb @@ -6,10 +6,11 @@ module Risc module Ticker include ScopeHelper include Output + include Preloader def setup compiler = RubyX::RubyXCompiler.new(RubyX.interpreter_test_options) - @linker = compiler.ruby_to_binary(@string_input, :interpreter) + @linker = compiler.ruby_to_binary(preload + @string_input, :interpreter) @interpreter = Interpreter.new(@linker) @interpreter.start_program end @@ -103,17 +104,11 @@ module Risc # use the input as it, compile and run it # input muts contain a Space.main, but may contain more classes and methods def run_input(input) - @string_input = input + @string_input = preload + input do_setup run_all end - # wrap the input in Space (main is assumed to be part of it) - def run_space(input) - @string_input = in_Space(input) - do_setup - run_all - end def run_all while(@interpreter.instruction) @interpreter.tick