groundwork for interpreter platform
especially positioning makes the previous interpreter approach to fragile (too far off the real thing) Interpreter should be it’s own platform (still use the risc instructions), get a translator and use positions
This commit is contained in:
parent
dc8afce444
commit
07ed16d765
@ -25,23 +25,18 @@ module Risc
|
|||||||
attr_reader :booted , :translated
|
attr_reader :booted , :translated
|
||||||
attr_reader :platform
|
attr_reader :platform
|
||||||
|
|
||||||
# translate to arm, ie instantiate an arm translator and pass it to translate
|
# Translate code to whatever cpu is specified.
|
||||||
|
# Currently only :arm and :interpret
|
||||||
#
|
#
|
||||||
# currently we have no machanism to translate to other cpu's (nor such translators)
|
# Translating means translating the initial jump
|
||||||
# but the mechanism is ready
|
|
||||||
def translate_arm
|
|
||||||
@platform = Platform.for("Arm")
|
|
||||||
@translated = true
|
|
||||||
translate(@platform.translator)
|
|
||||||
end
|
|
||||||
|
|
||||||
# translate code to whatever cpu the translator translates to
|
|
||||||
# this means translating the initial jump
|
|
||||||
# and then translating all methods
|
# and then translating all methods
|
||||||
def translate( translator )
|
def translate( platform )
|
||||||
|
platform = platform.to_s.capitalize
|
||||||
|
@platform = Platform.for(platform)
|
||||||
|
@translated = true
|
||||||
methods = Parfait.object_space.get_all_methods
|
methods = Parfait.object_space.get_all_methods
|
||||||
translate_methods( methods , translator )
|
translate_methods( methods , @platform.translator )
|
||||||
@cpu_init = risc_init.to_cpu(translator)
|
@cpu_init = risc_init.to_cpu(@platform.translator)
|
||||||
end
|
end
|
||||||
|
|
||||||
# go through all methods and translate them to cpu, given the translator
|
# go through all methods and translate them to cpu, given the translator
|
||||||
@ -66,6 +61,7 @@ module Risc
|
|||||||
raise "Must be Parfait #{const}" unless const.is_a?(Parfait::Object)
|
raise "Must be Parfait #{const}" unless const.is_a?(Parfait::Object)
|
||||||
@constants << const
|
@constants << const
|
||||||
end
|
end
|
||||||
|
|
||||||
# To create binaries, objects (and labels) need to have a position
|
# To create binaries, objects (and labels) need to have a position
|
||||||
# (so objects can be loaded and branches know where to jump)
|
# (so objects can be loaded and branches know where to jump)
|
||||||
#
|
#
|
||||||
@ -76,7 +72,7 @@ module Risc
|
|||||||
# As code length amy change during assembly, this way at least the objects stay
|
# As code length amy change during assembly, this way at least the objects stay
|
||||||
# in place and we don't have to deal with chaning loading code
|
# in place and we don't have to deal with chaning loading code
|
||||||
def position_all
|
def position_all
|
||||||
translate_arm unless @translated
|
raise "Not translated " unless @translated
|
||||||
#need the initial jump at 0 and then functions
|
#need the initial jump at 0 and then functions
|
||||||
Position.set(cpu_init , 0 , cpu_init)
|
Position.set(cpu_init , 0 , cpu_init)
|
||||||
@code_start = position_objects( @platform.padding )
|
@code_start = position_objects( @platform.padding )
|
||||||
|
@ -13,9 +13,10 @@ module Vool
|
|||||||
statements = self.ruby_to_vool(source)
|
statements = self.ruby_to_vool(source)
|
||||||
statements.to_mom(nil)
|
statements.to_mom(nil)
|
||||||
end
|
end
|
||||||
def self.ruby_to_binary(source)
|
def self.ruby_to_binary(source , platform = :arm)
|
||||||
machine = Risc.machine.boot
|
machine = Risc.machine.boot
|
||||||
self.ruby_to_vool(source)
|
self.ruby_to_vool(source)
|
||||||
|
machine.translate(platform)
|
||||||
machine.position_all
|
machine.position_all
|
||||||
machine.create_binary
|
machine.create_binary
|
||||||
end
|
end
|
||||||
|
@ -21,6 +21,7 @@ module Risc
|
|||||||
class TestMachinePositions < MiniTest::Test
|
class TestMachinePositions < MiniTest::Test
|
||||||
def setup
|
def setup
|
||||||
@machine = Risc.machine.boot
|
@machine = Risc.machine.boot
|
||||||
|
@machine.translate(:arm)
|
||||||
@machine.position_all
|
@machine.position_all
|
||||||
end
|
end
|
||||||
def test_has_positions
|
def test_has_positions
|
||||||
@ -32,6 +33,7 @@ module Risc
|
|||||||
class TestMachineInit < MiniTest::Test
|
class TestMachineInit < MiniTest::Test
|
||||||
def setup
|
def setup
|
||||||
@machine = Risc.machine.boot
|
@machine = Risc.machine.boot
|
||||||
|
@machine.translate(:arm)
|
||||||
@machine.position_all
|
@machine.position_all
|
||||||
@machine.create_binary
|
@machine.create_binary
|
||||||
end
|
end
|
||||||
|
@ -18,6 +18,7 @@ module Risc
|
|||||||
|
|
||||||
def setup
|
def setup
|
||||||
@machine = Risc.machine.boot
|
@machine = Risc.machine.boot
|
||||||
|
@machine.translate(:arm)
|
||||||
@machine.position_all
|
@machine.position_all
|
||||||
@text_writer = TextWriter.new(@machine)
|
@text_writer = TextWriter.new(@machine)
|
||||||
end
|
end
|
||||||
|
@ -17,10 +17,11 @@ module Risc
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_translate_space
|
def test_translate_space
|
||||||
assert @machine.translate_arm
|
assert @machine.translate(:arm)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_no_loops_in_chain
|
def test_no_loops_in_chain
|
||||||
|
@machine.translate(:arm)
|
||||||
@machine.position_all
|
@machine.position_all
|
||||||
init = Parfait.object_space.get_init
|
init = Parfait.object_space.get_init
|
||||||
all = []
|
all = []
|
||||||
@ -30,6 +31,7 @@ module Risc
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
def test_no_risc #by assembling, risc doesnt have assemble method
|
def test_no_risc #by assembling, risc doesnt have assemble method
|
||||||
|
@machine.translate(:arm)
|
||||||
@machine.position_all
|
@machine.position_all
|
||||||
@machine.objects.each do |id , method|
|
@machine.objects.each do |id , method|
|
||||||
next unless method.is_a? Parfait::TypedMethod
|
next unless method.is_a? Parfait::TypedMethod
|
||||||
|
Loading…
Reference in New Issue
Block a user