diff --git a/lib/risc.rb b/lib/risc.rb index edc82221..505f9e84 100644 --- a/lib/risc.rb +++ b/lib/risc.rb @@ -17,6 +17,11 @@ end # of that subset that we need. # See risc/Readme module Risc + # module method to reset, and init + def self.boot! + Position.clear_positions + Builtin.boot_functions + end end require_relative "risc/padding" diff --git a/lib/risc/linker.rb b/lib/risc/linker.rb index 4ee1b5ef..3980d136 100644 --- a/lib/risc/linker.rb +++ b/lib/risc/linker.rb @@ -125,13 +125,5 @@ module Risc risc_init = Branch.new( "__initial_branch__" , init.callable.binary ) @platform.translator.translate(risc_init) end - end - - # module method to reset, and init - def self.boot! - Position.clear_positions - Builtin.boot_functions - end - end diff --git a/lib/rubyx/rubyx_compiler.rb b/lib/rubyx/rubyx_compiler.rb index 19c5934b..97adeae5 100644 --- a/lib/rubyx/rubyx_compiler.rb +++ b/lib/rubyx/rubyx_compiler.rb @@ -1,31 +1,29 @@ module RubyX class RubyXCompiler - attr_reader :source - def initialize(source) - @source = source + def initialize + Parfait.boot! + Risc.boot! end - def ruby_to_vool - ruby = Ruby::RubyCompiler.compile( source ) - vool = ruby.to_vool - vool + def ruby_to_vool(ruby_source) + ruby_tree = Ruby::RubyCompiler.compile( ruby_source ) + vool_tree = ruby_tree.to_vool + vool_tree end - def ruby_to_mom - vool = ruby_to_vool - vool.to_mom(nil) + def ruby_to_mom(ruby) + vool_tree = ruby_to_vool(ruby) + vool_tree.to_mom(nil) end - def ruby_to_risc(platform) - mom = ruby_to_mom + def ruby_to_risc(ruby, platform) + mom = ruby_to_mom(ruby) mom.translate(platform) end - def ruby_to_binary(platform) - Parfait.boot! - Risc.boot! - linker = ruby_to_risc(platform) + def ruby_to_binary(ruby , platform) + linker = ruby_to_risc(ruby, platform) linker.position_all linker.create_binary linker diff --git a/test/elf/helper.rb b/test/elf/helper.rb index 1fc9f765..e45a5555 100644 --- a/test/elf/helper.rb +++ b/test/elf/helper.rb @@ -8,8 +8,6 @@ module Elf DEBUG = false def setup - Parfait.boot! - Risc.boot! end def in_space(input) @@ -19,7 +17,7 @@ module Elf in_space("def main(arg);#{input};end") end def check(input, file) - linker = RubyX::RubyXCompiler.new(input).ruby_to_binary( :arm ) + linker = RubyX::RubyXCompiler.new.ruby_to_binary( input , :arm ) writer = Elf::ObjectWriter.new(linker) writer.save "test/#{file}.o" end diff --git a/test/elf/test_zero.rb b/test/elf/test_zero.rb index 7d2057d7..242883d7 100644 --- a/test/elf/test_zero.rb +++ b/test/elf/test_zero.rb @@ -6,7 +6,7 @@ module Elf def setup super - @linker = RubyX::RubyXCompiler.new(as_main("return 1")).ruby_to_risc(:arm) + @linker = RubyX::RubyXCompiler.new.ruby_to_risc(as_main("return 1"),:arm) @linker.position_all @linker.create_binary end diff --git a/test/mom/helper.rb b/test/mom/helper.rb index 22b41f42..b08d7ac3 100644 --- a/test/mom/helper.rb +++ b/test/mom/helper.rb @@ -4,8 +4,6 @@ module Risc module Statements def setup - Parfait.boot! - Risc::Builtin.boot_functions end def preamble @@ -31,7 +29,7 @@ module Risc end def produce_instructions assert @expect , "No output given" - linker = RubyX::RubyXCompiler.new(as_test_main).ruby_to_risc(:interpreter) + linker = RubyX::RubyXCompiler.new.ruby_to_risc(as_test_main,: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/risc/test_linker.rb b/test/risc/test_linker.rb index 53811945..0fa1834c 100644 --- a/test/risc/test_linker.rb +++ b/test/risc/test_linker.rb @@ -19,7 +19,7 @@ module Risc end class TestLinkerInit < MiniTest::Test def setup - @linker = RubyX::RubyXCompiler.new("class Space;def main;return 1;end;end").ruby_to_binary(:arm) + @linker = RubyX::RubyXCompiler.new.ruby_to_binary("class Space;def main;return 1;end;end",:arm) end def test_pos_cpu assert_equal 0 , Position.get(@linker.cpu_init).at diff --git a/test/risc/test_linker1.rb b/test/risc/test_linker1.rb index 18e4b5b4..4f34ea8d 100644 --- a/test/risc/test_linker1.rb +++ b/test/risc/test_linker1.rb @@ -3,9 +3,8 @@ require_relative "helper" module Risc class TestMachinePos < MiniTest::Test def setup - Parfait.boot! - Risc.boot! - @linker = RubyX::RubyXCompiler.new("class Space; def main(arg);a = 1;return a;end;end").ruby_to_risc(:arm) + code = "class Space; def main(arg);a = 1;return a;end;end" + @linker = RubyX::RubyXCompiler.new.ruby_to_risc(code,:arm) @linker.position_all end def test_positions_set diff --git a/test/risc/test_method_compiler.rb b/test/risc/test_method_compiler.rb index 69a8e628..e8e988c9 100644 --- a/test/risc/test_method_compiler.rb +++ b/test/risc/test_method_compiler.rb @@ -5,11 +5,10 @@ module Risc include ScopeHelper def setup - Parfait.boot! end def in_test_vool(str) - vool = RubyX::RubyXCompiler.new(in_Test(str)).ruby_to_vool + vool = RubyX::RubyXCompiler.new.ruby_to_vool(in_Test(str)) vool.to_mom(nil) vool end @@ -65,7 +64,7 @@ module Risc assert_equal 2 , method.frame_type.variable_index(:a) end def constant_setup(input) - mom = RubyX::RubyXCompiler.new(in_Test(input)).ruby_to_mom + mom = RubyX::RubyXCompiler.new.ruby_to_mom(in_Test(input)) assert_equal Mom::MomCompiler , mom.class compiler = mom.method_compilers.first assert_equal MethodCompiler , compiler.class diff --git a/test/rubyx/helper.rb b/test/rubyx/helper.rb index 6963ee27..ede5697b 100644 --- a/test/rubyx/helper.rb +++ b/test/rubyx/helper.rb @@ -3,20 +3,18 @@ require_relative "../helper" module RubyX module RubyXHelper def setup - Parfait.boot! - Risc.boot! end def ruby_to_risc(input , platform) mom = ruby_to_mom(input) mom.translate(platform) end def ruby_to_vool(input) - RubyXCompiler.new(input).ruby_to_vool + RubyXCompiler.new.ruby_to_vool(input) end def ruby_to_mom(input) - RubyXCompiler.new(input).ruby_to_mom + RubyXCompiler.new.ruby_to_mom(input) end - def compile_in_test input + def compile_in_test( input ) vool = ruby_to_vool in_Test(input) vool.to_mom(nil) itest = Parfait.object_space.get_class_by_name(:Test) diff --git a/test/rubyx/test_rubyx_compiler.rb b/test/rubyx/test_rubyx_compiler.rb index 33bce242..c2e1a432 100644 --- a/test/rubyx/test_rubyx_compiler.rb +++ b/test/rubyx/test_rubyx_compiler.rb @@ -15,13 +15,6 @@ module RubyX assert itest.instance_type.names.include?(:trivar) , itest.instance_type.names.inspect end - def test_doesnt_create_existing_clas - space_class = Parfait.object_space.get_class_by_name(:Space) - ruby_to_vool "class Space ; end" - clazz = Parfait.object_space.get_class_by_name(:Space) - assert_equal clazz , space_class - end - def test_class_body_is_scope clazz = ruby_to_vool in_Test("def meth; @ivar = 5 ;end") assert_equal Vool::Statements , clazz.body.class @@ -29,15 +22,17 @@ module RubyX end def test_space_is_unchanged_by_compile + compiler = RubyXCompiler.new space1 = Parfait.object_space.get_class_by_name(:Space) - ruby_to_vool "class Space ;end" + compiler.ruby_to_vool "class Space ;end" space2 = Parfait.object_space.get_class_by_name(:Space) assert_equal space1 , space2 end def test_space_type_is_unchanged_by_compile + compiler = RubyXCompiler.new space1 = Parfait.object_space.get_type_by_class_name(:Space) - ruby_to_vool "class Space ;end" + compiler.ruby_to_vool "class Space ;end" space2 = Parfait.object_space.get_type_by_class_name(:Space) assert_equal space1 , space2 end diff --git a/test/rubyx/test_rubyx_compiler1.rb b/test/rubyx/test_rubyx_compiler1.rb index c2f5d920..f449180f 100644 --- a/test/rubyx/test_rubyx_compiler1.rb +++ b/test/rubyx/test_rubyx_compiler1.rb @@ -25,8 +25,9 @@ module RubyX end def test_space_type_is_unchanged_by_compile + compiler = RubyXCompiler.new space1 = Parfait.object_space.get_type_by_class_name(:Space) - ruby_to_vool "class Space ;end" + compiler.ruby_to_vool "class Space ;end" space2 = Parfait.object_space.get_type_by_class_name(:Space) assert_equal space1 , space2 end diff --git a/test/support/compiling.rb b/test/support/compiling.rb index a6b2cf82..b1ee6ddf 100644 --- a/test/support/compiling.rb +++ b/test/support/compiling.rb @@ -22,7 +22,7 @@ module MomCompile include ScopeHelper def compile_method(input) - statements = RubyX::RubyXCompiler.new(input).ruby_to_vool + statements = RubyX::RubyXCompiler.new.ruby_to_vool(input) assert statements.is_a?(Vool::ClassStatement) ret = statements.to_mom(nil) assert_equal Parfait::Class , statements.clazz.class , statements @@ -50,8 +50,7 @@ module MomCompile block.body.to_mom(block_c) end def compile_mom(input) - Risc.boot! - RubyX::RubyXCompiler.new(input).ruby_to_mom + RubyX::RubyXCompiler.new.ruby_to_mom(input) end def check_array( should , is ) diff --git a/test/support/risc_interpreter.rb b/test/support/risc_interpreter.rb index 2ad1588c..042fa1b0 100644 --- a/test/support/risc_interpreter.rb +++ b/test/support/risc_interpreter.rb @@ -7,7 +7,7 @@ module Risc include ScopeHelper def setup - @linker = RubyX::RubyXCompiler.new(@string_input).ruby_to_binary( :interpreter) + @linker = RubyX::RubyXCompiler.new.ruby_to_binary(@string_input, :interpreter) @interpreter = Interpreter.new(@linker) @interpreter.start_program end