hoist parfait boot out of the machine boot

This commit is contained in:
Torsten Ruger 2018-06-30 00:39:23 +03:00
parent 8d7a2fe4d6
commit 46d8f5002f
35 changed files with 62 additions and 33 deletions

View File

@ -13,6 +13,7 @@ group :test do
gem "simplecov" gem "simplecov"
gem "minitest-color" gem "minitest-color"
gem 'minitest-fail-fast' gem 'minitest-fail-fast'
#gem "minitest-reporters"
gem "net-ssh" gem "net-ssh"
end end

View File

@ -23,7 +23,6 @@ module Risc
end end
attr_reader :constants , :cpu_init attr_reader :constants , :cpu_init
attr_reader :translated
attr_reader :platform attr_reader :platform
# Translate code to whatever cpu is specified. # Translate code to whatever cpu is specified.
@ -34,7 +33,6 @@ module Risc
def translate( platform ) def translate( platform )
platform = platform.to_s.capitalize platform = platform.to_s.capitalize
@platform = Platform.for(platform) @platform = Platform.for(platform)
@translated = true
translate_methods( @platform.translator ) translate_methods( @platform.translator )
@cpu_init = risc_init.to_cpu(@platform.translator) @cpu_init = risc_init.to_cpu(@platform.translator)
end end
@ -85,7 +83,6 @@ module Risc
# As code length may change during assembly, this way at least the objects stay # As code length may change during assembly, this way at least the objects stay
# in place and we don't have to deal with changing loading code # in place and we don't have to deal with changing loading code
def position_all def position_all
raise "Not translated " unless @translated
#need the initial jump at 0 and then functions #need the initial jump at 0 and then functions
Position.new(cpu_init).set(0) Position.new(cpu_init).set(0)
code_start = position_objects( @platform.padding ) code_start = position_objects( @platform.padding )
@ -165,8 +162,6 @@ module Risc
def boot def boot
initialize initialize
Position.clear_positions Position.clear_positions
@translated = false
Parfait.boot!
Builtin.boot_functions Builtin.boot_functions
self self
end end

View File

@ -15,6 +15,7 @@ module RubyX
end end
def self.ruby_to_binary(source , platform = :arm) def self.ruby_to_binary(source , platform = :arm)
Parfait.boot!
machine = Risc.machine.boot machine = Risc.machine.boot
ruby_to_mom(source) ruby_to_mom(source)
machine.translate(platform) machine.translate(platform)

View File

@ -4,6 +4,7 @@ module Arm
class TestTranslator < MiniTest::Test class TestTranslator < MiniTest::Test
def setup def setup
Parfait.boot!
Risc.machine.boot Risc.machine.boot
@jump = Risc::DynamicJump.new("" , :r1) @jump = Risc::DynamicJump.new("" , :r1)
@codes = Translator.new.translate @jump @codes = Translator.new.translate @jump

View File

@ -8,6 +8,7 @@ module Elf
DEBUG = false DEBUG = false
def setup def setup
Parfait.boot!
Risc.machine.boot Risc.machine.boot
end end

View File

@ -3,6 +3,7 @@ require_relative "../helper"
class TestZeroCode < MiniTest::Test class TestZeroCode < MiniTest::Test
def setup def setup
Parfait.boot!
@machine = Risc.machine.boot @machine = Risc.machine.boot
@space = Parfait.object_space @space = Parfait.object_space
@space.each_type do | type | @space.each_type do | type |

View File

@ -15,6 +15,8 @@ end
require "minitest/color" require "minitest/color"
require "minitest/autorun" require "minitest/autorun"
#require "minitest/fail_fast" #require "minitest/fail_fast"
#require "minitest/reporters"
#Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib')) $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'test')) $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'test'))

View File

@ -4,7 +4,8 @@ module Risc
module Statements module Statements
def setup def setup
Risc.machine.boot # force boot to reset main Parfait.boot!
Risc::Builtin.boot_functions
end end
def preamble def preamble

View File

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

View File

@ -4,7 +4,7 @@ module Parfait
class ParfaitTest < MiniTest::Test class ParfaitTest < MiniTest::Test
def setup def setup
@machine = Risc.machine.boot Parfait.boot!
@space = Parfait.object_space @space = Parfait.object_space
end end
end end

View File

@ -15,20 +15,10 @@ module Parfait
assert @space.false_object , "No lies" assert @space.false_object , "No lies"
assert @space.nil_object , "No nothing" assert @space.nil_object , "No nothing"
end end
def test_methods_booted
word = @space.get_class_by_name(:Word).instance_type
assert_equal 3 , word.method_names.get_length
assert word.get_method(:putstring) , "no putstring"
end
def test_global_space def test_global_space
assert_equal Parfait::Space , Parfait.object_space.class assert_equal Parfait::Space , Parfait.object_space.class
end end
def test_integer
int = Parfait.object_space.get_class_by_name :Integer
assert_equal 14, int.instance_type.method_names.get_length
end
def test_get_integer_instance def test_get_integer_instance
int = @space.get_integer int = @space.get_integer
@ -158,6 +148,21 @@ module Parfait
assert_equal 0 , cl.instance_type.methods_length , "name #{cl.name}" assert_equal 0 , cl.instance_type.methods_length , "name #{cl.name}"
end end
end end
end end
class TestMethods < ParfaitTest
def setup
super
Risc::Builtin.boot_functions
end
def test_integer
int = Parfait.object_space.get_class_by_name :Integer
assert_equal 14, int.instance_type.method_names.get_length
end
def test_methods_booted
word = @space.get_class_by_name(:Word).instance_type
assert_equal 3 , word.method_names.get_length
assert word.get_method(:putstring) , "no putstring"
end
end
end end

View File

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

View File

@ -3,6 +3,7 @@ require_relative "helper"
module Risc module Risc
class TestPositionTranslated < MiniTest::Test class TestPositionTranslated < MiniTest::Test
def setup def setup
Parfait.boot!
machine = Risc.machine.boot machine = Risc.machine.boot
machine.translate(:interpreter) machine.translate(:interpreter)
@binary = Parfait::BinaryCode.new(1) @binary = Parfait::BinaryCode.new(1)

View File

@ -3,6 +3,7 @@ require_relative "helper"
module Risc module Risc
class TestMachinePositions < MiniTest::Test class TestMachinePositions < MiniTest::Test
def setup_for(platform) def setup_for(platform)
Parfait.boot!
@machine = Risc.machine.boot @machine = Risc.machine.boot
@machine.translate(platform) @machine.translate(platform)
@machine.position_all @machine.position_all

View File

@ -4,6 +4,7 @@ module Risc
class TestCodeBuilder < MiniTest::Test class TestCodeBuilder < MiniTest::Test
def setup def setup
Parfait.boot!
Risc.machine.boot Risc.machine.boot
init = Parfait.object_space.get_init init = Parfait.object_space.get_init
@builder = Risc::RiscCompiler.new( init ).code_builder(init) @builder = Risc::RiscCompiler.new( init ).code_builder(init)
@ -100,6 +101,7 @@ module Risc
class TestCompilerBuilder < MiniTest::Test class TestCompilerBuilder < MiniTest::Test
def setup def setup
Parfait.boot!
Risc.machine.boot Risc.machine.boot
@init = Parfait.object_space.get_init @init = Parfait.object_space.get_init
@builder = Risc::RiscCompiler.new( @init ).compiler_builder(@init) @builder = Risc::RiscCompiler.new( @init ).compiler_builder(@init)

View File

@ -4,6 +4,7 @@ module Risc
class TestCollector < MiniTest::Test class TestCollector < MiniTest::Test
def setup def setup
Parfait.boot!
@machine = Risc.machine.boot @machine = Risc.machine.boot
end end

View File

@ -18,6 +18,7 @@ module Risc
end end
class TestInterpreterStarts < MiniTest::Test class TestInterpreterStarts < MiniTest::Test
def setup def setup
Parfait.boot!
@machine = Risc.machine.boot @machine = Risc.machine.boot
@machine.translate(:interpreter) @machine.translate(:interpreter)
@machine.position_all @machine.position_all
@ -37,6 +38,7 @@ module Risc
end end
class TestInterpreterTicks < MiniTest::Test class TestInterpreterTicks < MiniTest::Test
def setup def setup
Parfait.boot!
@machine = Risc.machine.boot @machine = Risc.machine.boot
@machine.translate(:interpreter) @machine.translate(:interpreter)
@machine.position_all @machine.position_all

View File

@ -21,6 +21,7 @@ module Risc
class TestIdentityTranslator < MiniTest::Test class TestIdentityTranslator < MiniTest::Test
def setup def setup
Parfait.boot!
@machine = Risc.machine.boot @machine = Risc.machine.boot
@translator = IdentityTranslator.new @translator = IdentityTranslator.new
end end

View File

@ -4,6 +4,7 @@ module Risc
class TestMachineObjects < MiniTest::Test class TestMachineObjects < MiniTest::Test
def setup def setup
Parfait.boot!
@machine = Risc.machine.boot @machine = Risc.machine.boot
end end
def test_objects def test_objects
@ -36,6 +37,7 @@ module Risc
end end
class TestMachinePos < MiniTest::Test class TestMachinePos < MiniTest::Test
def setup def setup
Parfait.boot!
@machine = Risc.machine.boot @machine = Risc.machine.boot
@machine.translate(:arm) @machine.translate(:arm)
@machine.position_all @machine.position_all
@ -48,6 +50,7 @@ module Risc
end end
class TestMachineInit < MiniTest::Test class TestMachineInit < MiniTest::Test
def setup def setup
Parfait.boot!
@machine = Risc.machine.boot @machine = Risc.machine.boot
@machine.translate(:arm) @machine.translate(:arm)
@machine.position_all @machine.position_all

View File

@ -5,7 +5,7 @@ module Risc
include ScopeHelper include ScopeHelper
def setup def setup
Risc.machine.boot Parfait.boot!
end end
def create_method def create_method

View File

@ -17,6 +17,7 @@ module Risc
class TestTextWriterPositions < MiniTest::Test class TestTextWriterPositions < MiniTest::Test
def setup def setup
Parfait.boot!
@machine = Risc.machine.boot @machine = Risc.machine.boot
@machine.translate(:arm) @machine.translate(:arm)
@machine.position_all @machine.position_all

View File

@ -4,6 +4,7 @@ module Risc
class TestTranslator < MiniTest::Test class TestTranslator < MiniTest::Test
def setup def setup
Parfait.boot!
@machine = Risc.machine.boot @machine = Risc.machine.boot
@translator = Arm::Translator.new @translator = Arm::Translator.new
end end

View File

@ -3,6 +3,7 @@ require_relative "../helper"
module RubyX module RubyX
module RubyXHelper module RubyXHelper
def setup def setup
Parfait.boot!
Risc.machine.boot Risc.machine.boot
end end
def ruby_to_vool(input) def ruby_to_vool(input)

View File

@ -14,7 +14,7 @@ module RubyX
def test_creates_class_deriviation def test_creates_class_deriviation
mom = ruby_to_mom "class Testing ; end" mom = ruby_to_mom "class Testing ; end"
assert mom , "No classes created" #assert mom , "No classes created"
end end
def test_creates_class_with_deriviation def test_creates_class_with_deriviation

View File

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

View File

@ -6,7 +6,8 @@ module Vool
include MomCompile include MomCompile
def setup def setup
Risc.machine.boot Parfait.boot!
Risc::Builtin.boot_functions
@ins = compile_first_method( send_method ) @ins = compile_first_method( send_method )
end end

View File

@ -5,7 +5,8 @@ module Vool
include MomCompile include MomCompile
def setup def setup
Risc.machine.boot Parfait.boot!
Risc::Builtin.boot_functions
@ins = compile_first_method( "local = 5") @ins = compile_first_method( "local = 5")
end end
@ -36,7 +37,7 @@ module Vool
class TestAssignMomInstanceToLocal < MiniTest::Test class TestAssignMomInstanceToLocal < MiniTest::Test
include MomCompile include MomCompile
def setup def setup
Risc.machine.boot Parfait.boot!
@ins = compile_first_method( "@a = 5 ; local = @a") @ins = compile_first_method( "@a = 5 ; local = @a")
end end
def test_class_compiles def test_class_compiles
@ -49,7 +50,7 @@ module Vool
include MomCompile include MomCompile
def setup def setup
Risc.machine.boot Parfait.boot!
@ins = compile_first_method( "arg = 5") @ins = compile_first_method( "arg = 5")
end end
@ -73,7 +74,7 @@ module Vool
class TestAssignMomToInstance < MiniTest::Test class TestAssignMomToInstance < MiniTest::Test
include MomCompile include MomCompile
def setup def setup
Risc.machine.boot Parfait.boot!
end end
def test_assigns_const def test_assigns_const
@ins = compile_first_method( "@a = 5") @ins = compile_first_method( "@a = 5")

View File

@ -7,7 +7,8 @@ module Vool
include Mom include Mom
def setup def setup
Risc.machine.boot Parfait.boot!
Risc::Builtin.boot_functions
@ins = compile_first_method( "if(5.div4) ; @a = 6 ; else; @a = 5 ; end") @ins = compile_first_method( "if(5.div4) ; @a = 6 ; else; @a = 5 ; end")
end end

View File

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

View File

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

View File

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

View File

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

View File

@ -6,7 +6,7 @@ module Vool
include Mom include Mom
def setup def setup
Risc.machine.boot Parfait.boot!
@inst = compile_first_method( "return 5") @inst = compile_first_method( "return 5")
end end

View File

@ -7,7 +7,8 @@ module Vool
include Mom include Mom
def setup def setup
Risc.machine.boot Parfait.boot!
Risc::Builtin.boot_functions
@ins = compile_first_method( "while(5.div4) ; 5.div4 ; end") @ins = compile_first_method( "while(5.div4) ; 5.div4 ; end")
end end

View File

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