diff --git a/lib/mom/class_compiler.rb b/lib/mom/class_compiler.rb index 44516d0c..25e25c86 100644 --- a/lib/mom/class_compiler.rb +++ b/lib/mom/class_compiler.rb @@ -6,5 +6,25 @@ module Mom @clazz = clazz @methods = methods end + + # Translate code to whatever cpu is specified. + # Currently only :arm and :interpret + # + # Translating means translating the initial jump + # and then translating all methods + def translate( platform ) + platform = platform.to_s.capitalize + @platform = Risc::Platform.for(platform) + translate_methods( @platform.translator ) + #@cpu_init = risc_init.to_cpu(@platform.translator) + end + + # go through all methods and translate them to cpu, given the translator + def translate_methods(translator) + Parfait.object_space.get_all_methods.each do |method| + #log.debug "Translate method #{method.name}" + method.translate_cpu(translator) + end + end end end diff --git a/lib/risc/builtin/compile_helper.rb b/lib/risc/builtin/compile_helper.rb index b70c05e5..2cc4e3c4 100644 --- a/lib/risc/builtin/compile_helper.rb +++ b/lib/risc/builtin/compile_helper.rb @@ -6,7 +6,7 @@ module Risc def compiler_for( clazz_name , method_name , arguments , locals = {}) frame = Parfait::NamedList.type_for( locals ) args = Parfait::NamedList.type_for( arguments ) - Risc::RiscCompiler.compiler_for_class(clazz_name , method_name , args, frame ) + RiscCompiler.compiler_for_class(clazz_name , method_name , args, frame ) end end diff --git a/lib/rubyx/rubyx_compiler.rb b/lib/rubyx/rubyx_compiler.rb index ce6ccc9b..99f9a759 100644 --- a/lib/rubyx/rubyx_compiler.rb +++ b/lib/rubyx/rubyx_compiler.rb @@ -17,7 +17,8 @@ module RubyX def self.ruby_to_binary(source , platform = :arm) Parfait.boot! machine = Risc.machine.boot - ruby_to_mom(source) + mom = ruby_to_mom(source) + #mom.translate(platform) machine.translate(platform) machine.position_all machine.create_binary diff --git a/test/rubyx/helper.rb b/test/rubyx/helper.rb index 72689fa9..2605b0e0 100644 --- a/test/rubyx/helper.rb +++ b/test/rubyx/helper.rb @@ -6,6 +6,10 @@ module RubyX Parfait.boot! Risc.machine.boot end + def ruby_to_risc(input , platform) + mom = ruby_to_mom(input) + mom.translate(platform) + end def ruby_to_vool(input) RubyXCompiler.ruby_to_vool(input) end diff --git a/test/rubyx/test_rubyx_compiler.rb b/test/rubyx/test_rubyx_compiler.rb index 973dcddc..c2d6e85d 100644 --- a/test/rubyx/test_rubyx_compiler.rb +++ b/test/rubyx/test_rubyx_compiler.rb @@ -1,7 +1,7 @@ require_relative "helper" module RubyX - class TestVoolCompiler < MiniTest::Test + class TestRubyXCompiler < MiniTest::Test include ScopeHelper include RubyXHelper diff --git a/test/rubyx/test_rubyx_compiler1.rb b/test/rubyx/test_rubyx_compiler1.rb index 21fddbcb..ad5b1a5d 100644 --- a/test/rubyx/test_rubyx_compiler1.rb +++ b/test/rubyx/test_rubyx_compiler1.rb @@ -1,7 +1,7 @@ require_relative "helper" module RubyX - class TestVoolCompiler < MiniTest::Test + class TestRubyXCompilerMom < MiniTest::Test include ScopeHelper include RubyXHelper @@ -14,7 +14,7 @@ module RubyX def test_creates_class_deriviation mom = ruby_to_mom "class Testing ; end" - #assert mom , "No classes created" + #assert mom , "No classes created" end def test_creates_class_with_deriviation diff --git a/test/rubyx/test_rubyx_compiler2.rb b/test/rubyx/test_rubyx_compiler2.rb new file mode 100644 index 00000000..57dc6ff3 --- /dev/null +++ b/test/rubyx/test_rubyx_compiler2.rb @@ -0,0 +1,15 @@ +require_relative "helper" + +module RubyX + class TestRubyXCompilerRisc < MiniTest::Test + include ScopeHelper + include RubyXHelper + + def test_to_risc + code = "class Space ; def main(arg);return arg;end; end" + risc = ruby_to_risc(code, :interpreter) + assert_equal Array , risc.class + end + + end +end