start to move translate code
This commit is contained in:
parent
daf1b56062
commit
208b98d709
@ -6,5 +6,25 @@ module Mom
|
|||||||
@clazz = clazz
|
@clazz = clazz
|
||||||
@methods = methods
|
@methods = methods
|
||||||
end
|
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
|
||||||
end
|
end
|
||||||
|
@ -6,7 +6,7 @@ module Risc
|
|||||||
def compiler_for( clazz_name , method_name , arguments , locals = {})
|
def compiler_for( clazz_name , method_name , arguments , locals = {})
|
||||||
frame = Parfait::NamedList.type_for( locals )
|
frame = Parfait::NamedList.type_for( locals )
|
||||||
args = Parfait::NamedList.type_for( arguments )
|
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
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -17,7 +17,8 @@ module RubyX
|
|||||||
def self.ruby_to_binary(source , platform = :arm)
|
def self.ruby_to_binary(source , platform = :arm)
|
||||||
Parfait.boot!
|
Parfait.boot!
|
||||||
machine = Risc.machine.boot
|
machine = Risc.machine.boot
|
||||||
ruby_to_mom(source)
|
mom = ruby_to_mom(source)
|
||||||
|
#mom.translate(platform)
|
||||||
machine.translate(platform)
|
machine.translate(platform)
|
||||||
machine.position_all
|
machine.position_all
|
||||||
machine.create_binary
|
machine.create_binary
|
||||||
|
@ -6,6 +6,10 @@ module RubyX
|
|||||||
Parfait.boot!
|
Parfait.boot!
|
||||||
Risc.machine.boot
|
Risc.machine.boot
|
||||||
end
|
end
|
||||||
|
def ruby_to_risc(input , platform)
|
||||||
|
mom = ruby_to_mom(input)
|
||||||
|
mom.translate(platform)
|
||||||
|
end
|
||||||
def ruby_to_vool(input)
|
def ruby_to_vool(input)
|
||||||
RubyXCompiler.ruby_to_vool(input)
|
RubyXCompiler.ruby_to_vool(input)
|
||||||
end
|
end
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
require_relative "helper"
|
require_relative "helper"
|
||||||
|
|
||||||
module RubyX
|
module RubyX
|
||||||
class TestVoolCompiler < MiniTest::Test
|
class TestRubyXCompiler < MiniTest::Test
|
||||||
include ScopeHelper
|
include ScopeHelper
|
||||||
include RubyXHelper
|
include RubyXHelper
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
require_relative "helper"
|
require_relative "helper"
|
||||||
|
|
||||||
module RubyX
|
module RubyX
|
||||||
class TestVoolCompiler < MiniTest::Test
|
class TestRubyXCompilerMom < MiniTest::Test
|
||||||
include ScopeHelper
|
include ScopeHelper
|
||||||
include RubyXHelper
|
include RubyXHelper
|
||||||
|
|
||||||
|
15
test/rubyx/test_rubyx_compiler2.rb
Normal file
15
test/rubyx/test_rubyx_compiler2.rb
Normal file
@ -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
|
Loading…
x
Reference in New Issue
Block a user