clean up booting

many machine boot became obsolete
or just neede parfait to boot
actual linker functionality pending
This commit is contained in:
Torsten Ruger 2018-07-01 14:12:42 +03:00
parent e75aef933d
commit c947c27a14
32 changed files with 71 additions and 62 deletions

View File

@ -65,7 +65,7 @@ module Risc
# An integer is plucked from object_space abd added to the machine constant pool
# if none was given
def self.label( source , name , position = nil , nekst = nil)
position = Risc.machine.get_address unless position
position = Parfait.object_space.get_address unless position
Label.new( source , name , position, nekst )
end
end

View File

@ -19,15 +19,19 @@ module RubyX
vool.to_mom(nil)
end
def ruby_to_risc(platform)
mom = ruby_to_mom
mom.translate(platform)
end
def ruby_to_binary(platform = :arm)
Parfait.boot!
machine = Risc.machine.boot
mom = ruby_to_mom
puts "MOM #{mom.class}"
mom.translate(platform)
#machine.translate(platform)
machine.position_all
machine.create_binary
Risc.boot!
assemblers = ruby_to_mom(platform)
puts "Assemblers #{assemblers}"
linker = Linker.new
linker.position_all
linker.create_binary
end
end
end

View File

@ -25,7 +25,7 @@ module Arm
assert_nil code.branch_to
end
def test_method_call
Risc.machine.boot
Parfait.boot!
bin = Parfait::BinaryCode.new(1)
Risc::Position.new(bin).set(0x20)
code = @machine.call( bin ,{} )#this jumps to the next instruction

View File

@ -5,7 +5,6 @@ module Arm
def setup
Parfait.boot!
Risc.machine.boot
@jump = Risc::DynamicJump.new("" , :r1)
@codes = Translator.new.translate @jump
end

View File

@ -9,7 +9,7 @@ module Elf
def setup
Parfait.boot!
Risc.machine.boot
Risc.boot!
end
def in_space(input)

View File

@ -37,7 +37,7 @@ module Mains
end
def compile(input , file , scp)
Risc.machine.boot
Risc.boot!
puts "Compiling test/#{file}.o" if DEBUG
RubyX::RubyXCompiler.ruby_to_binary( "class Space;def main(arg);#{input};end;end" )
writer = Elf::ObjectWriter.new(Risc.machine)

View File

@ -29,7 +29,7 @@ module Risc
end
def produce_instructions
assert @expect , "No output given"
RubyX::RubyXCompiler.ruby_to_binary as_test_main , :interpreter
RubyX::RubyXCompiler.new(as_test_main).ruby_to_binary( :interpreter)
test = Parfait.object_space.get_class_by_name :Test
test.instance_type.get_method(:main).cpu_instructions
end

View File

@ -4,7 +4,7 @@ module Mom
class TestSlotDefinitionConstant < MiniTest::Test
def setup
Risc.machine.boot
Parfait.boot!
@compiler = CompilerMock.new
@definition = SlotDefinition.new(StringConstant.new("hi") , [])
@instruction = @definition.to_register(@compiler , InstructionMock.new)

View File

@ -3,7 +3,7 @@ require_relative "helper"
module Mom
class TestSlotDefinitionKnown1 < MiniTest::Test
def setup
Risc.machine.boot
Parfait.boot!
@compiler = CompilerMock.new
@definition = SlotDefinition.new(:message , :caller)
@instruction = @definition.to_register(@compiler , InstructionMock.new)

View File

@ -3,7 +3,7 @@ require_relative "helper"
module Mom
class TestSlotDefinitionKnown2 < MiniTest::Test
def setup
Risc.machine.boot
Parfait.boot!
@compiler = CompilerMock.new
@definition = SlotDefinition.new(:message , [:caller , :type])
@instruction = @definition.to_register(@compiler , InstructionMock.new)

View File

@ -4,7 +4,7 @@ module Mom
class TestSlotLoad1 < MiniTest::Test
def setup
Risc.machine.boot
Parfait.boot!
@load = SlotLoad.new( [:message, :caller] , [:message,:type] )
@compiler = CompilerMock.new
@instruction = @load.to_risc(@compiler)

View File

@ -5,7 +5,7 @@ module Mom
def setup
Parfait.boot!
Risc.machine.boot
Risc.boot!
@load = SlotLoad.new( [:message, :caller] , [:message, :caller , :type] )
@compiler = CompilerMock.new
@instruction = @load.to_risc(@compiler)

View File

@ -18,11 +18,27 @@ module Mom
def test_has_translate
assert @comp.translate(:interpreter)
end
end
class TestClassCompilerTranslate < MiniTest::Test
include MomCompile
def setup
Parfait.boot!
@comp = compile_mom( "class Test ; def main(); return 1; end; end;")
@trans = @comp.translate(:interpreter)
end
def test_translate_class
assert_equal Array , @comp.translate(:interpreter).class
assert_equal Array , @trans.class
end
def test_translate_assemblers
assert_equal Risc::Assembler , @comp.translate(:interpreter).first.class
assert_equal Risc::Assembler , @trans.first.class
end
def test_assembler_code
assert_equal Risc::Label , @trans.first.instructions.class
end
def test_assembler_assembled
assert_equal Risc::LoadConstant , @trans.first.instructions.next.class
end
end
end

View File

@ -97,6 +97,15 @@ module Parfait
def test_has_next_address
assert_equal Parfait::ReturnAddress , @space.next_address.next_integer.class
end
def test_address_count
addr = @space.get_address
count = 0
while(addr)
count += 1
addr = addr.next_integer
end
assert_equal 10, count
end
def test_messages
mess = @space.first_message

View File

@ -4,7 +4,7 @@ module Parfait
class TestEmptyWord < ParfaitTest
def setup
Risc.machine.boot
Parfait.boot!
@word = Parfait::Word.new(0)
end
def test_word_create

View File

@ -5,7 +5,6 @@ module Risc
class TestBranchListenerBooted < MiniTest::Test
def setup
Parfait.boot!
DummyPlatform.boot
@binary = Parfait::BinaryCode.new(1)
@bin_pos = CodeListener.init(@binary).set(0)
@label = Label.new("HI","ho" , FakeAddress.new(2))
@ -26,7 +25,7 @@ module Risc
assert @branch.precheck_called
end
end
class TestBranchListenerPositioned < MiniTest::Test
class TestBranchListenerPositioned #< MiniTest::Test
def setup
@machine = Risc.machine.boot
@machine.translate(:interpreter)

View File

@ -3,7 +3,7 @@ require_relative "helper"
module Risc
class TestCodeListener < MiniTest::Test
def setup
Risc.machine.boot
Parfait.boot!
@binary = Parfait::BinaryCode.new(1)
@method = Parfait.object_space.types.values.first.methods
@label = Risc.label("hi","ho")

View File

@ -3,7 +3,7 @@ require_relative "helper"
module Risc
class TestInstructionListener < MiniTest::Test
def setup
Risc.machine.boot
Parfait.boot!
@binary = Parfait::BinaryCode.new(1)
@bin_pos = Position.new(@binary).set(0)
@instruction = DummyInstruction.new(DummyInstruction.new)

View File

@ -4,7 +4,7 @@ module Risc
class TestLabelListener < MiniTest::Test
def setup
Risc.machine.boot
Parfait.boot!
@label = Label.new("Hi","Ho" , FakeAddress.new(5))
@label_pos = Position.new(@label ).set(4)
@code = Parfait::BinaryCode.new(1)

View File

@ -5,7 +5,7 @@ module Risc
def setup
Parfait.boot!
Risc.machine.boot
Risc.boot!
init = Parfait.object_space.get_init
@builder = Risc::MethodCompiler.new( init ).code_builder(init)
@label = Risc.label("source","name")
@ -102,7 +102,7 @@ module Risc
def setup
Parfait.boot!
Risc.machine.boot
Risc.boot!
@init = Parfait.object_space.get_init
@builder = Risc::MethodCompiler.new( @init ).compiler_builder(@init)
end

View File

@ -5,30 +5,31 @@ module Risc
def setup
Parfait.boot!
@machine = Risc.machine.boot
Risc.boot!
@linker = Linker.new
end
def test_simple_collect
objects = Risc::Collector.collect_space
objects = Collector.collect_space(@linker)
assert ((400 < objects.length) or (450 > objects.length)) , objects.length.to_s
end
def test_collect_all_types
Risc::Collector.collect_space.each do |objekt , position|
Collector.collect_space(@linker).each do |objekt , position|
next unless objekt.is_a?( Parfait::Type )
assert Parfait.object_space.get_type_for( objekt.hash ) , objekt.hash
end
end
def test_allowed_types
Risc::Collector.collect_space.each do |objekt , position|
Collector.collect_space(@linker).each do |objekt , position|
next if objekt.is_a?( Parfait::Object )
next if objekt.is_a?( Symbol )
assert false
end
end
def test_positions
Risc::Collector.collect_space.each do |objekt , position|
Collector.collect_space(@linker).each do |objekt , position|
assert_equal Position , position.class
assert !position.valid?
end

View File

@ -5,7 +5,7 @@ module Risc
def setup
Parfait.boot!
Risc.boot
Risc.boot!
@machine = Linker.new
end
def test_objects
@ -19,22 +19,6 @@ module Risc
def test_constant
assert @machine.add_constant( Parfait::Integer.new(5) )
end
def test_address_get
assert_equal Parfait::ReturnAddress , @machine.get_address.class
end
def test_address_is_constant
addr = @machine.get_address
assert @machine.constants.include?(addr)
end
def test_address_count
addr = @machine.get_address
count = 0
while(addr)
count += 1
addr = addr.next_integer
end
assert_equal 5, count
end
end
class TestMachinePos #< MiniTest::Test
def setup

View File

@ -11,7 +11,6 @@ module Risc
def setup
Parfait.boot!
Risc.machine.boot
@r0 = RegisterValue.new(:r0 , :Message)
@r1 = RegisterValue.new(:r1 , :Space)
end

View File

@ -4,11 +4,10 @@ module RubyX
module RubyXHelper
def setup
Parfait.boot!
Risc.machine.boot
Risc.boot!
end
def ruby_to_risc(input , platform)
mom = ruby_to_mom(input)
puts "MOM #{mom.class}"
mom.translate(platform)
end
def ruby_to_vool(input)

View File

@ -51,7 +51,7 @@ module Vool
include RubyTests
def setup
Risc.machine.boot
Parfait.boot!
end
def compile_ct( input )
lst = compile( input )

View File

@ -64,7 +64,7 @@ module Vool
include RubyTests
def setup
Risc.machine.boot
Parfait.boot!
end
def test_int_receiver

View File

@ -21,7 +21,7 @@ module Vool
assert_equal true , @lst.has_yield?
end
def test_method_args
Risc.machine.boot
Parfait.boot!
assert_equal 2 , @lst.make_arg_type.get_length
end
end

View File

@ -35,8 +35,8 @@ module MomCompile
compile_to_mom(method , res.clazz.instance_type)
end
def compile_to_mom(method , for_type)
typed_method = create_typed_method(for_type)
source.to_mom( typed_method )
typed_method = method.create_typed_method(for_type)
method.source.to_mom( typed_method )
end
def check_array( should , is )

View File

@ -8,7 +8,7 @@ module Risc
def setup
Parfait.boot!
Risc.machine.boot
Risc.boot!
RubyX::RubyXCompiler.ruby_to_binary( @string_input , :interpreter)
@interpreter = Interpreter.new
@interpreter.start_machine

View File

@ -7,7 +7,7 @@ module Vool
def setup
Parfait.boot!
Risc.machine.boot
Risc.boot!
@ins = compile_first_method( "a = main(1 + 2)" )
end

View File

@ -7,7 +7,6 @@ module Vool
def setup
Parfait.boot!
Risc.machine.boot
@ins = compile_first_method( "a = 5; a.div4")
end
def test_check_type

View File

@ -44,7 +44,7 @@ module Vool
def setup
Parfait.boot!
Risc.machine.boot
Risc.boot!
@ins = compile_first_method( "return 5.div4")
end