Move booting to RubyXCompiler init
Also pass the source into the compile method. This way compiler can be reused for subsequent compile. Does remove some double boots, but no major time save
This commit is contained in:
parent
d73e1526cd
commit
8a81d41d5e
@ -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"
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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 )
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user