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:
@ -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
|
||||
|
Reference in New Issue
Block a user