Fixed almost all but Interpreter
150 only failing, seems only 1 bug though and one in linker
This commit is contained in:
parent
9474932320
commit
aaf169ad8d
@ -22,6 +22,7 @@ module Mom
|
||||
attr_reader :method_source
|
||||
|
||||
def initialize(method_source)
|
||||
raise "no nil" unless method_source
|
||||
@method_source = method_source
|
||||
end
|
||||
|
||||
|
@ -65,7 +65,7 @@ module Mom
|
||||
# temporary, need to raise really.
|
||||
factory! << Parfait.object_space.get_factory_for(:Integer)
|
||||
integer_tmp! << factory[:reserve]
|
||||
Risc::Builtin::Object.emit_syscall( builder , :exit ) #uses integer_tmp
|
||||
Mom::Builtin.emit_syscall( builder , :exit ) #uses integer_tmp
|
||||
|
||||
add_code ok_label
|
||||
cache_entry[:cached_method] << callable_method
|
||||
|
@ -9,7 +9,7 @@ module Risc
|
||||
# space << Parfait.object_space # load constant
|
||||
# message[:receiver] << space #make current message's (r0) receiver the space
|
||||
# See http://ruby-x.org/rubyx/builder.html for details
|
||||
#
|
||||
#
|
||||
class Builder
|
||||
|
||||
attr_reader :built , :compiler
|
||||
|
@ -186,7 +186,7 @@ module Risc
|
||||
# populate the position caches (forward and revese) with the given position
|
||||
# forward caches object -> position
|
||||
# reverse caches position.at > position
|
||||
# Labels do not participatein reverse cache
|
||||
# Labels do not participate in reverse cache
|
||||
def self.set_cache( position , to)
|
||||
postest = Position.positions[position.object] unless to < 0
|
||||
raise "Mismatch #{position}" if postest and postest != position
|
||||
|
@ -1,5 +1,14 @@
|
||||
module RubyX
|
||||
# The RubyXCompiler provides the main interface to create binaries
|
||||
# The RubyXCompiler provides the main interface to create binaries, and also
|
||||
# give helper functions to create any intermediate layer.
|
||||
# Layers are:
|
||||
# - ruby , always needed as input, string
|
||||
# - vool - intermediate language layer
|
||||
# - mom - intermediate machine layer
|
||||
# - risc - "last" intermediate machine layer
|
||||
# - target - arm or interpreter binary code
|
||||
# - binary - "linked" code, everything need to create an elf binary
|
||||
#
|
||||
#
|
||||
# There are methods to go from ruby to any of the layers in the system
|
||||
# (mainly for testing). ruby_to_binary creates actual binary code
|
||||
@ -38,42 +47,59 @@ module RubyX
|
||||
to_binary(platform)
|
||||
end
|
||||
|
||||
# Process previously stored vool source to binary.
|
||||
# Binary code is generated byu calling to_risc, then positioning and calling
|
||||
# create_binary on the linker. The linker may then be used to creat a binary file.
|
||||
# The biary the method name refers to is binary code in memory, or in BinaryCode
|
||||
# objects to be precise.
|
||||
def to_binary(platform)
|
||||
linker = to_risc
|
||||
linker.position_all
|
||||
linker.create_binary(platform)
|
||||
linker
|
||||
# ruby_to_target creates Target instructions (but does not link)
|
||||
#
|
||||
# After creating vool, we call to_target
|
||||
# Return a Linker
|
||||
def ruby_to_target(ruby)
|
||||
ruby_to_vool(ruby)
|
||||
to_target()
|
||||
end
|
||||
|
||||
# ruby_to_risc creates Risc instructions (as the name implies), but also
|
||||
# translates those to the platform given
|
||||
# ruby_to_risc creates Risc instructions
|
||||
#
|
||||
# After creating vool, we call to_risc
|
||||
# Return a RiscCollection
|
||||
def ruby_to_risc(ruby)
|
||||
ruby_to_vool(ruby)
|
||||
to_risc()
|
||||
end
|
||||
|
||||
# Process previously stored vool source. First to mom, then to risc.
|
||||
def to_risc()
|
||||
mom = to_mom
|
||||
mom.to_risc()
|
||||
end
|
||||
|
||||
# ruby_to_mom does exactly that, it transform the incoming ruby source (string)
|
||||
# to mom
|
||||
# The vool is stored using ruby_to_vool, and if there was previous source,
|
||||
# this will also be momed
|
||||
# Transform the incoming ruby source (string) to mom
|
||||
#
|
||||
# The vool is stored using ruby_to_vool,the to_mom is called
|
||||
# Return Mom Statement
|
||||
def ruby_to_mom(ruby)
|
||||
ruby_to_vool(ruby)
|
||||
to_mom
|
||||
end
|
||||
|
||||
# Process previously stored vool source to binary.
|
||||
# Binary code is generated by calling to_risc, then positioning and calling
|
||||
# create_binary on the linker. The linker may then be used to creat a binary file.
|
||||
# The biary the method name refers to is binary code in memory, or in BinaryCode
|
||||
# objects to be precise.
|
||||
def to_binary(platform)
|
||||
linker = to_target(platform)
|
||||
linker.position_all
|
||||
linker.create_binary
|
||||
linker
|
||||
end
|
||||
|
||||
# transform stored vool to target code
|
||||
# return a linker
|
||||
def to_target(platform)
|
||||
collection = to_risc
|
||||
collection.translate(platform)
|
||||
end
|
||||
|
||||
# Process previously stored vool source to risc.
|
||||
# return a Risc::RiscCollection , a collection of MethodCompilers
|
||||
def to_risc()
|
||||
mom = to_mom
|
||||
mom.to_risc()
|
||||
end
|
||||
|
||||
# return mom for the previously stored vool source.
|
||||
def to_mom
|
||||
@vool.to_mom(nil)
|
||||
|
@ -4,17 +4,17 @@ module Mom
|
||||
class TestSlotLoadBasics < MiniTest::Test
|
||||
|
||||
def test_ins_ok
|
||||
assert SlotLoad.new( [:message, :caller] , [:receiver,:type] )
|
||||
assert SlotLoad.new("test", [:message, :caller] , [:receiver,:type] )
|
||||
end
|
||||
def test_ins_fail1
|
||||
assert_raises {SlotLoad.new( [:message, :caller] , nil )}
|
||||
assert_raises {SlotLoad.new( "test",[:message, :caller] , nil )}
|
||||
end
|
||||
def test_fail_on_right
|
||||
@load = SlotLoad.new( [:message, :caller] , [:receiver,:type] )
|
||||
@load = SlotLoad.new( "test",[:message, :caller] , [:receiver,:type] )
|
||||
assert_raises {@load.to_risc(Risc::FakeCompiler.new)}
|
||||
end
|
||||
def test_fail_on_left_long
|
||||
@load = SlotLoad.new( [:message, :caller , :type] , [:receiver,:type] )
|
||||
@load = SlotLoad.new("test", [:message, :caller , :type] , [:receiver,:type] )
|
||||
assert_raises {@load.to_risc(Risc::FakeCompiler.new)}
|
||||
end
|
||||
end
|
||||
|
@ -5,7 +5,7 @@ module Mom
|
||||
|
||||
def setup
|
||||
Parfait.boot!(Parfait.default_test_options)
|
||||
load = SlotLoad.new( [:message, :caller] , [:message,:type] )
|
||||
load = SlotLoad.new("test", [:message, :caller] , [:message,:type] )
|
||||
@compiler = Risc::FakeCompiler.new
|
||||
load.to_risc(@compiler)
|
||||
@instructions = @compiler.instructions
|
||||
|
@ -6,7 +6,7 @@ module Mom
|
||||
def setup
|
||||
Parfait.boot!(Parfait.default_test_options)
|
||||
@compiler = Risc::FakeCompiler.new
|
||||
load = SlotLoad.new( [:message, :caller, :type] , [:message, :caller , :type] )
|
||||
load = SlotLoad.new( "test",[:message, :caller, :type] , [:message, :caller , :type] )
|
||||
load.to_risc(@compiler)
|
||||
@instructions = @compiler.instructions
|
||||
end
|
||||
|
@ -2,7 +2,7 @@
|
||||
require_relative "helper"
|
||||
|
||||
module Vool
|
||||
class TestClassStatement < MiniTest::Test
|
||||
class TestClassStatementMom < MiniTest::Test
|
||||
include MomCompile
|
||||
|
||||
def setup
|
||||
|
@ -1,40 +0,0 @@
|
||||
require_relative "helper"
|
||||
|
||||
module Mom
|
||||
class TestMomCompiler < MiniTest::Test
|
||||
include MomCompile
|
||||
|
||||
def setup
|
||||
Parfait.boot!(Parfait.default_test_options)
|
||||
@comp = compile_mom( "class Test ; def main(); return 'Hi'; end; end;")
|
||||
end
|
||||
|
||||
def test_class
|
||||
assert_equal MomCompiler , @comp.class
|
||||
end
|
||||
def test_compilers
|
||||
assert_equal 23 , @comp.compilers.length
|
||||
end
|
||||
def test_boot_compilers
|
||||
assert_equal 22 , @comp.boot_compilers.length
|
||||
end
|
||||
def test_compilers_bare
|
||||
assert_equal 22 , MomCompiler.new.compilers.length
|
||||
end
|
||||
def test_returns_constants
|
||||
assert_equal Array , @comp.constants.class
|
||||
end
|
||||
def test_has_constant
|
||||
assert_equal "Hi" , @comp.constants[1].to_string
|
||||
end
|
||||
def test_has_translate
|
||||
assert @comp.translate(:interpreter)
|
||||
end
|
||||
def test_append_class
|
||||
assert_equal MomCompiler, (@comp.append @comp).class
|
||||
end
|
||||
def test_append_length
|
||||
assert_equal 2 , @comp.append(@comp).method_compilers.length
|
||||
end
|
||||
end
|
||||
end
|
@ -4,11 +4,11 @@ module Parfait
|
||||
class TestMethods < ParfaitTest
|
||||
def setup
|
||||
super
|
||||
Risc::Builtin.boot_functions
|
||||
Mom.boot!
|
||||
end
|
||||
def test_integer
|
||||
int = Parfait.object_space.get_class_by_name :Integer
|
||||
assert_equal 14, int.instance_type.method_names.get_length
|
||||
assert_equal 13, int.instance_type.method_names.get_length
|
||||
end
|
||||
def test_methods_booted
|
||||
word = @space.get_type_by_class_name(:Word)
|
||||
|
@ -1,9 +1,9 @@
|
||||
require_relative "helper"
|
||||
require_relative "../helper"
|
||||
|
||||
# TODO move these to interpreter dir
|
||||
module Mom
|
||||
module Risc
|
||||
module Builtin
|
||||
class IntCmp < BuiltinTest
|
||||
class IntCmp < Minitest::Test
|
||||
include Ticker
|
||||
def setup
|
||||
end
|
||||
|
@ -1,8 +1,8 @@
|
||||
require_relative "helper"
|
||||
require_relative "../helper"
|
||||
|
||||
module Mom
|
||||
module Risc
|
||||
module Builtin
|
||||
class IntMath < BuiltinTest
|
||||
class IntMath < Minitest::Test
|
||||
include Ticker
|
||||
def setup
|
||||
end
|
||||
|
@ -5,7 +5,7 @@ module Risc
|
||||
def setup
|
||||
Parfait.boot!(Parfait.default_test_options)
|
||||
Risc.boot!
|
||||
@linker = Mom::MomCompiler.new.translate(:interpreter)
|
||||
@linker = Mom::MomCollection.new.to_risc.translate(:interpreter)
|
||||
@binary = Parfait::BinaryCode.new(1)
|
||||
@method = Parfait.object_space.types.values.first.methods
|
||||
@label = Risc.label("hi","ho")
|
||||
|
@ -4,8 +4,9 @@ module Risc
|
||||
class TestMachinePositions < MiniTest::Test
|
||||
def setup_for(platform)
|
||||
Parfait.boot!(Parfait.default_test_options)
|
||||
Mom.boot!
|
||||
Risc.boot!
|
||||
@linker = Mom::MomCompiler.new.translate(platform)
|
||||
@linker = Mom::MomCollection.new.to_risc.translate(platform)
|
||||
@linker.position_all
|
||||
end
|
||||
def test_cpu_init
|
||||
|
@ -5,9 +5,10 @@ module Risc
|
||||
|
||||
def setup
|
||||
Parfait.boot!(Parfait.default_test_options)
|
||||
Mom.boot!
|
||||
Risc.boot!
|
||||
init = Parfait.object_space.get_init
|
||||
@builder = Risc::MethodCompiler.new( init ).builder(init)
|
||||
@builder = Risc::MethodCompiler.new( init ,Mom::Label.new( "source_name", "return_label")).builder(init)
|
||||
@label = Risc.label("source","name")
|
||||
@start = @builder.compiler.current
|
||||
end
|
||||
|
@ -5,9 +5,10 @@ module Risc
|
||||
|
||||
def setup
|
||||
Parfait.boot!(Parfait.default_test_options)
|
||||
Mom.boot!
|
||||
Risc.boot!
|
||||
@init = Parfait.object_space.get_init
|
||||
@compiler = Risc::MethodCompiler.new( @init )
|
||||
@compiler = Risc::MethodCompiler.new( @init , Mom::Label.new( "source_name", "return_label"))
|
||||
@builder = @compiler.builder(@init)
|
||||
end
|
||||
def test_inserts_built
|
||||
@ -42,7 +43,7 @@ module Risc
|
||||
end
|
||||
def test_allocate_len
|
||||
int = @builder.allocate_int
|
||||
assert_equal 41 , @builder.compiler.risc_instructions.length
|
||||
assert_equal 28 , @builder.compiler.risc_instructions.length
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -5,9 +5,10 @@ module Risc
|
||||
|
||||
def setup
|
||||
Parfait.boot!(Parfait.default_test_options)
|
||||
Mom.boot!
|
||||
Risc.boot!
|
||||
@init = Parfait.object_space.get_init
|
||||
@compiler = Risc::MethodCompiler.new( @init )
|
||||
@compiler = Risc::MethodCompiler.new( @init, Mom::Label.new( "source_name", "return_label") )
|
||||
@builder = @compiler.builder(@init)
|
||||
end
|
||||
def test_list
|
||||
|
@ -6,12 +6,12 @@ module Risc
|
||||
def setup
|
||||
Parfait.boot!(Parfait.default_test_options)
|
||||
Risc.boot!
|
||||
@linker = Mom::MomCompiler.new.translate(:arm)
|
||||
@linker = Mom::MomCollection.new.to_risc.translate(:arm)
|
||||
end
|
||||
|
||||
def test_simple_collect
|
||||
objects = Collector.collect_space(@linker)
|
||||
assert_equal 600 , objects.length , objects.length.to_s
|
||||
assert_equal 621 , objects.length , objects.length.to_s
|
||||
end
|
||||
|
||||
def test_collect_all_types
|
||||
@ -47,15 +47,15 @@ module Risc
|
||||
|
||||
def setup
|
||||
opt = Parfait.default_test_options
|
||||
opt[:factory] = 4000
|
||||
opt[:factory] = 400
|
||||
Parfait.boot!(opt)
|
||||
Risc.boot!
|
||||
@linker = Mom::MomCompiler.new.translate(:arm)
|
||||
@linker = Mom::MomCollection.new.to_risc.translate(:arm)
|
||||
end
|
||||
|
||||
def test_simple_collect
|
||||
objects = Collector.collect_space(@linker)
|
||||
assert_equal 20329, objects.length , objects.length.to_s
|
||||
assert_equal 2422, objects.length , objects.length.to_s
|
||||
end
|
||||
|
||||
def test_integer_positions
|
||||
|
@ -4,8 +4,9 @@ module Risc
|
||||
class TestInterpreterBasics < MiniTest::Test
|
||||
def setup
|
||||
Parfait.boot!(Parfait.default_test_options)
|
||||
Mom.boot!
|
||||
Risc.boot!
|
||||
@linker = Mom::MomCompiler.new.translate(:interpreter)
|
||||
@linker = Mom::MomCollection.new.to_risc.translate(:interpreter)
|
||||
end
|
||||
|
||||
def test_class
|
||||
@ -54,7 +55,7 @@ module Risc
|
||||
end
|
||||
def test_pc1
|
||||
@interpreter.tick
|
||||
assert_equal 23672 , @interpreter.pc
|
||||
assert_equal 22856 , @interpreter.pc
|
||||
end
|
||||
def test_tick2
|
||||
@interpreter.tick
|
||||
@ -68,7 +69,7 @@ module Risc
|
||||
def test_pc2
|
||||
@interpreter.tick
|
||||
@interpreter.tick
|
||||
assert_equal 23676 , @interpreter.pc
|
||||
assert_equal 22860 , @interpreter.pc
|
||||
end
|
||||
def test_tick_14_jump
|
||||
14.times {@interpreter.tick}
|
||||
|
@ -6,7 +6,7 @@ module Risc
|
||||
def setup
|
||||
Parfait.boot!(Parfait.default_test_options)
|
||||
Risc.boot!
|
||||
@linker = Mom::MomCompiler.new.translate(:arm)
|
||||
@linker = Mom::MomCollection.new.to_risc.translate(:arm)
|
||||
end
|
||||
def test_objects
|
||||
objects = @linker.object_positions
|
||||
@ -25,7 +25,7 @@ module Risc
|
||||
assert_equal 0 , Position.get(@linker.cpu_init).at
|
||||
end
|
||||
def test_cpu_at
|
||||
assert_equal "0x569c" , Position.get(@linker.cpu_init.first).to_s
|
||||
assert_equal "0x562c" , Position.get(@linker.cpu_init.first).to_s
|
||||
end
|
||||
def test_cpu_label
|
||||
assert_equal Position , Position.get(@linker.cpu_init.first).class
|
||||
|
@ -4,7 +4,7 @@ module Risc
|
||||
class TestMachinePos < MiniTest::Test
|
||||
def setup
|
||||
code = "class Space; def main(arg);a = 1;return a;end;end"
|
||||
@linker = RubyX::RubyXCompiler.new(RubyX.default_test_options).ruby_to_risc(code,:arm)
|
||||
@linker = RubyX::RubyXCompiler.new(RubyX.default_test_options).ruby_to_binary(code, :arm)
|
||||
@linker.position_all
|
||||
end
|
||||
def test_positions_set
|
||||
|
@ -6,7 +6,7 @@ module Risc
|
||||
def setup
|
||||
Parfait.boot!(Parfait.default_test_options)
|
||||
Risc.boot!
|
||||
@linker = Mom::MomCompiler.new.translate(:arm)
|
||||
@linker = Mom::MomCollection.new.to_risc.translate(:arm)
|
||||
end
|
||||
def test_init
|
||||
@text_writer = TextWriter.new(@linker)
|
||||
@ -21,7 +21,7 @@ module Risc
|
||||
def setup
|
||||
Parfait.boot!(Parfait.default_test_options)
|
||||
Risc.boot!
|
||||
@linker = Mom::MomCompiler.new.translate(:arm)
|
||||
@linker = Mom::MomCollection.new.to_risc.translate(:arm)
|
||||
@linker.position_all
|
||||
@linker.create_binary
|
||||
@text_writer = TextWriter.new(@linker)
|
||||
|
Loading…
Reference in New Issue
Block a user