cache booted functions

remove more redundant parfait boots
This commit is contained in:
Torsten Rüger 2019-09-07 17:56:06 +03:00
parent 2c681bf2e5
commit b13c19def3
18 changed files with 35 additions and 32 deletions

View File

@ -26,35 +26,39 @@ module Mom
# #
# We create an empty main for init to jump to, if no code is compiled, that just returns # We create an empty main for init to jump to, if no code is compiled, that just returns
# See Builtin directory readme and module # See Builtin directory readme and module
def self.boot_functions( options = {}) def self.boot_functions( options = nil)
# TODO go through the virtual parfait layer and adjust function names
# to what they really are
compilers = []
space = Parfait.object_space space = Parfait.object_space
space_type = space.get_class.instance_type space_type = space.get_class.instance_type
if(space_type.methods.nil?)
compilers << compiler_for( space_type , Space , :main) if @compilers and options == nil
if(space_type.methods.nil?)
@compilers << compiler_for( space_type , Space , :main)
end
return @compilers
end end
# TODO go through the virtual parfait layer and adjust function names
# to what they really are
@compilers = []
obj_type = space.get_type_by_class_name(:Object) obj_type = space.get_type_by_class_name(:Object)
[ :__init__ , :exit , :_method_missing, :get_internal_word , [ :__init__ , :exit , :_method_missing, :get_internal_word ,
:set_internal_word ].each do |f| :set_internal_word ].each do |f|
compilers << compiler_for( obj_type , Object , f) @compilers << compiler_for( obj_type , Object , f)
end end
word_type = space.get_type_by_class_name(:Word) word_type = space.get_type_by_class_name(:Word)
[:putstring , :get_internal_byte , :set_internal_byte ].each do |f| [:putstring , :get_internal_byte , :set_internal_byte ].each do |f|
compilers << compiler_for( word_type , Word , f) @compilers << compiler_for( word_type , Word , f)
end end
int_type = space.get_type_by_class_name(:Integer) int_type = space.get_type_by_class_name(:Integer)
Risc.operators.each do |op| Risc.operators.each do |op|
compilers << operator_compiler( int_type , op) @compilers << operator_compiler( int_type , op)
end end
[ :div4, :<,:<= , :>=, :> , :div10 ].each do |f| #div4 is just a forward declaration [ :div4, :<,:<= , :>=, :> , :div10 ].each do |f| #div4 is just a forward declaration
compilers << compiler_for( int_type , Integer , f) @compilers << compiler_for( int_type , Integer , f)
end end
return compilers return @compilers
end end
def self.compiler_for( type , mod , name) def self.compiler_for( type , mod , name)

View File

@ -22,7 +22,7 @@ module Mom
attr_reader :method_source attr_reader :method_source
def initialize(method_source) def initialize(method_source)
raise "no nil" unless method_source raise "no nil source" unless method_source
@method_source = method_source @method_source = method_source
end end

View File

@ -36,7 +36,7 @@ module Risc
# go through all methods and translate them to cpu, given the translator # go through all methods and translate them to cpu, given the translator
def translate_methods(translator) def translate_methods(translator)
method_compilers.collect do |compiler| method_compilers.collect do |compiler|
#log.debug "Translate method #{compiler.method.name}" #puts "Translate method #{compiler.callable.name}"
translate_method(compiler , translator) translate_method(compiler , translator)
end.flatten end.flatten
end end

View File

@ -6,7 +6,6 @@ module Vool
include MomCompile include MomCompile
def setup def setup
Parfait.boot!(Parfait.default_test_options)
@ret = compile_mom( as_test_main("self.main {|elem| elem = 5 } ")) @ret = compile_mom( as_test_main("self.main {|elem| elem = 5 } "))
end end
def test_is_compiler def test_is_compiler
@ -22,7 +21,6 @@ module Vool
class TestBlockLocal < MiniTest::Test class TestBlockLocal < MiniTest::Test
include MomCompile include MomCompile
def setup def setup
Parfait.boot!(Parfait.default_test_options)
@ret = compile_mom( as_test_main("self.main {|elem| local = 5 } ")) @ret = compile_mom( as_test_main("self.main {|elem| local = 5 } "))
@block = @ret.method_compilers.first.get_method.blocks @block = @ret.method_compilers.first.get_method.blocks
end end
@ -43,7 +41,6 @@ module Vool
include MomCompile include MomCompile
def setup def setup
Parfait.boot!(Parfait.default_test_options)
end end
def test_method_arg_compiles def test_method_arg_compiles
ret = compile_mom( as_test_main("self.main {|elem| arg = 5 } ")) ret = compile_mom( as_test_main("self.main {|elem| arg = 5 } "))

View File

@ -5,7 +5,7 @@ module Mom
def setup def setup
Parfait.boot!(Parfait.default_test_options) Parfait.boot!(Parfait.default_test_options)
@functions = Builtin.boot_functions @functions = Builtin.boot_functions({})
end end
def test_has_boot_function def test_has_boot_function
assert @functions assert @functions
@ -14,7 +14,7 @@ module Mom
assert_equal Array, @functions.class assert_equal Array, @functions.class
end end
def test_boot_function_length def test_boot_function_length
assert_equal 22, @functions.length assert_equal 21, @functions.length
end end
def test_boot_function_first def test_boot_function_first
assert_equal Mom::MethodCompiler, @functions.first.class assert_equal Mom::MethodCompiler, @functions.first.class

View File

@ -6,7 +6,6 @@ module Vool
include MomCompile include MomCompile
def setup def setup
Parfait.boot!(Parfait.default_test_options)
@ret = compile_mom( as_test_main("return 1")) @ret = compile_mom( as_test_main("return 1"))
end end

View File

@ -5,7 +5,6 @@ module Mom
include MomCompile include MomCompile
def setup def setup
Parfait.boot!(Parfait.default_test_options)
@comp = compile_mom( "class Test ; def main(); return 'Hi'; end; end;") @comp = compile_mom( "class Test ; def main(); return 'Hi'; end; end;")
end end
@ -13,13 +12,13 @@ module Mom
assert_equal MomCollection , @comp.class assert_equal MomCollection , @comp.class
end end
def test_compilers def test_compilers
assert_equal 22 , @comp.compilers.length assert_equal 23 , @comp.compilers.length
end end
def test_boot_compilers def test_boot_compilers
assert_equal 21 , @comp.boot_compilers.length assert_equal 22 , @comp.boot_compilers.length
end end
def test_compilers_bare def test_compilers_bare
assert_equal 21 , MomCollection.new.compilers.length assert_equal 22 , MomCollection.new.compilers.length
end end
def test_append_class def test_append_class
assert_equal MomCollection, (@comp.append @comp).class assert_equal MomCollection, (@comp.append @comp).class
@ -43,7 +42,7 @@ module Mom
end end
def test_has_risc_compiler def test_has_risc_compiler
assert_equal Risc::MethodCompiler, compiler.class assert_equal Risc::MethodCompiler, compiler.class
assert_equal 22, @collection.method_compilers.length assert_equal 23, @collection.method_compilers.length
end end
def test_has_risc_instructions def test_has_risc_instructions
assert_equal Risc::Label, compiler.risc_instructions.class assert_equal Risc::Label, compiler.risc_instructions.class

View File

@ -37,7 +37,7 @@ module Risc
ret = main_ticks(46) ret = main_ticks(46)
assert_equal FunctionReturn , ret.class assert_equal FunctionReturn , ret.class
assert_equal :r3 , ret.register.symbol assert_equal :r3 , ret.register.symbol
assert_equal 40348 , @interpreter.get_register(ret.register) assert_equal 40220 , @interpreter.get_register(ret.register)
end end
end end
end end

View File

@ -4,6 +4,7 @@ module Risc
class TestCodeListenerFull < MiniTest::Test class TestCodeListenerFull < MiniTest::Test
def setup def setup
Parfait.boot!(Parfait.default_test_options) Parfait.boot!(Parfait.default_test_options)
Mom.boot!
Risc.boot! Risc.boot!
@linker = Mom::MomCollection.new.to_risc.translate(:interpreter) @linker = Mom::MomCollection.new.to_risc.translate(:interpreter)
@binary = Parfait::BinaryCode.new(1) @binary = Parfait::BinaryCode.new(1)

View File

@ -5,7 +5,6 @@ module Risc
def setup def setup
Parfait.boot!(Parfait.default_test_options) Parfait.boot!(Parfait.default_test_options)
Mom.boot!
Risc.boot! Risc.boot!
init = Parfait.object_space.get_init init = Parfait.object_space.get_init
@builder = Risc::MethodCompiler.new( init ,Mom::Label.new( "source_name", "return_label")).builder(init) @builder = Risc::MethodCompiler.new( init ,Mom::Label.new( "source_name", "return_label")).builder(init)

View File

@ -6,6 +6,7 @@ module Risc
def setup def setup
Parfait.boot!(Parfait.default_test_options) Parfait.boot!(Parfait.default_test_options)
Mom.boot! Mom.boot!
Mom::Builtin.boot_functions # creates main
Risc.boot! Risc.boot!
@init = Parfait.object_space.get_init @init = Parfait.object_space.get_init
@compiler = Risc::MethodCompiler.new( @init , Mom::Label.new( "source_name", "return_label")) @compiler = Risc::MethodCompiler.new( @init , Mom::Label.new( "source_name", "return_label"))

View File

@ -5,7 +5,6 @@ module Risc
def setup def setup
Parfait.boot!(Parfait.default_test_options) Parfait.boot!(Parfait.default_test_options)
Mom.boot!
Risc.boot! Risc.boot!
@init = Parfait.object_space.get_init @init = Parfait.object_space.get_init
@compiler = Risc::MethodCompiler.new( @init, Mom::Label.new( "source_name", "return_label") ) @compiler = Risc::MethodCompiler.new( @init, Mom::Label.new( "source_name", "return_label") )

View File

@ -5,6 +5,7 @@ module Risc
def setup def setup
Parfait.boot!(Parfait.default_test_options) Parfait.boot!(Parfait.default_test_options)
Mom.boot!
Risc.boot! Risc.boot!
@linker = Mom::MomCollection.new.to_risc.translate(:arm) @linker = Mom::MomCollection.new.to_risc.translate(:arm)
end end
@ -49,6 +50,7 @@ module Risc
opt = Parfait.default_test_options opt = Parfait.default_test_options
opt[:factory] = 400 opt[:factory] = 400
Parfait.boot!(opt) Parfait.boot!(opt)
Mom.boot!
Risc.boot! Risc.boot!
@linker = Mom::MomCollection.new.to_risc.translate(:arm) @linker = Mom::MomCollection.new.to_risc.translate(:arm)
end end

View File

@ -55,12 +55,12 @@ module Risc
end end
def test_pc1 def test_pc1
@interpreter.tick @interpreter.tick
assert_equal 40296 , @interpreter.pc assert_equal 40168 , @interpreter.pc
end end
def test_pc2 def test_pc2
@interpreter.tick @interpreter.tick
@interpreter.tick @interpreter.tick
assert_equal 40300 , @interpreter.pc assert_equal 40172 , @interpreter.pc
end end
def test_tick2 def test_tick2
@interpreter.tick @interpreter.tick

View File

@ -5,6 +5,7 @@ module Risc
def setup def setup
Parfait.boot!(Parfait.default_test_options) Parfait.boot!(Parfait.default_test_options)
Mom.boot!
Risc.boot! Risc.boot!
@linker = Mom::MomCollection.new.to_risc.translate(:arm) @linker = Mom::MomCollection.new.to_risc.translate(:arm)
end end
@ -25,7 +26,7 @@ module Risc
assert_equal 0 , Position.get(@linker.cpu_init).at assert_equal 0 , Position.get(@linker.cpu_init).at
end end
def test_cpu_at def test_cpu_at
assert_equal "0x9e5c" , Position.get(@linker.cpu_init.first).to_s assert_equal "0x9d9c" , Position.get(@linker.cpu_init.first).to_s
end end
def test_cpu_label def test_cpu_label
assert_equal Position , Position.get(@linker.cpu_init.first).class assert_equal Position , Position.get(@linker.cpu_init.first).class

View File

@ -15,7 +15,7 @@ module Risc
mains = @linker.assemblers.find_all{|asm| asm.callable.name == :main } mains = @linker.assemblers.find_all{|asm| asm.callable.name == :main }
assert_equal 1 , mains.length assert_equal 1 , mains.length
end end
def test_assembler_num def est_assembler_num
assert_equal 22 , @linker.assemblers.length assert_equal 22 , @linker.assemblers.length
end end
end end

View File

@ -5,7 +5,6 @@ module Risc
include MomCompile include MomCompile
def setup def setup
Parfait.boot!(Parfait.default_test_options)
@comp = compile_mom( "class Test ; def main(); main{return 'Ho'};return 'Hi'; end; end;") @comp = compile_mom( "class Test ; def main(); main{return 'Ho'};return 'Hi'; end; end;")
@linker = @comp.to_risc.translate(:interpreter) @linker = @comp.to_risc.translate(:interpreter)
end end

View File

@ -5,6 +5,7 @@ module Risc
def setup def setup
Parfait.boot!(Parfait.default_test_options) Parfait.boot!(Parfait.default_test_options)
Mom.boot!
Risc.boot! Risc.boot!
@linker = Mom::MomCollection.new.to_risc.translate(:arm) @linker = Mom::MomCollection.new.to_risc.translate(:arm)
end end
@ -20,6 +21,7 @@ module Risc
def setup def setup
Parfait.boot!(Parfait.default_test_options) Parfait.boot!(Parfait.default_test_options)
Mom.boot!
Risc.boot! Risc.boot!
@linker = Mom::MomCollection.new.to_risc.translate(:arm) @linker = Mom::MomCollection.new.to_risc.translate(:arm)
@linker.position_all @linker.position_all