fixing risc collection tests
This commit is contained in:
parent
9a2716280c
commit
9474932320
@ -21,12 +21,12 @@ module Mom
|
|||||||
# classes have booted, now create a minimal set of functions
|
# classes have booted, now create a minimal set of functions
|
||||||
# minimal means only that which can not be coded in ruby
|
# minimal means only that which can not be coded in ruby
|
||||||
# Methods are grabbed from respective modules by sending the method name.
|
# Methods are grabbed from respective modules by sending the method name.
|
||||||
# This should return the implementation of the method (ie a method object),
|
# This should return the implementation of the method (ie a method compiler),
|
||||||
# not actually try to implement it(as that's impossible in ruby)
|
# not actually try to implement it(as that's impossible in ruby)
|
||||||
#
|
#
|
||||||
# When no main has been compiled, we will add an empty main (for testing)
|
# We create an empty main for init to jump to, if no code is compiled, that just returns
|
||||||
#
|
# See Builtin directory readme and module
|
||||||
def self.boot_functions(add_main = false)
|
def self.boot_functions()
|
||||||
# TODO go through the virtual parfait layer and adjust function names
|
# TODO go through the virtual parfait layer and adjust function names
|
||||||
# to what they really are
|
# to what they really are
|
||||||
compilers = []
|
compilers = []
|
||||||
@ -37,8 +37,8 @@ module Mom
|
|||||||
end
|
end
|
||||||
|
|
||||||
obj_type = space.get_type_by_class_name(:Object)
|
obj_type = space.get_type_by_class_name(:Object)
|
||||||
[ :get_internal_word , :set_internal_word , :_method_missing,
|
[ :__init__ , :exit , :_method_missing, :get_internal_word ,
|
||||||
:exit , :__init__ ].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
|
||||||
|
|
||||||
|
@ -17,13 +17,13 @@ module Mom
|
|||||||
# lazily instantiate the compilers for boot functions
|
# lazily instantiate the compilers for boot functions
|
||||||
# (in the hope of only booting the functions once)
|
# (in the hope of only booting the functions once)
|
||||||
def boot_compilers
|
def boot_compilers
|
||||||
@boot_compilers ||= Risc::Builtin.boot_functions
|
@boot_compilers ||= Mom::Builtin.boot_functions
|
||||||
end
|
end
|
||||||
|
|
||||||
# Return all compilers, namely the MethodCompilers passed in, plus the
|
# Return all compilers, namely the MethodCompilers passed in, plus the
|
||||||
# boot_function's compilers (boot_compilers)
|
# boot_function's compilers (boot_compilers)
|
||||||
def compilers
|
def compilers
|
||||||
@method_compilers #+ boot_compilers
|
@method_compilers + boot_compilers
|
||||||
end
|
end
|
||||||
|
|
||||||
# collects constants from all compilers into one array
|
# collects constants from all compilers into one array
|
||||||
@ -37,8 +37,8 @@ module Mom
|
|||||||
self
|
self
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_risc( )
|
def to_risc( )
|
||||||
riscs = method_compilers.collect do | mom_c |
|
riscs = compilers.collect do | mom_c |
|
||||||
mom_c.to_risc
|
mom_c.to_risc
|
||||||
end
|
end
|
||||||
# to_risc all compilers
|
# to_risc all compilers
|
||||||
|
@ -10,21 +10,9 @@ module Risc
|
|||||||
@method_compilers = compilers
|
@method_compilers = compilers
|
||||||
end
|
end
|
||||||
|
|
||||||
# lazily instantiate the compilers for boot functions
|
|
||||||
# (in the hope of only booting the functions once)
|
|
||||||
def boot_compilers
|
|
||||||
@boot_compilers ||= Risc::Builtin.boot_functions
|
|
||||||
end
|
|
||||||
|
|
||||||
# Return all compilers, namely the MethodCompilers passed in, plus the
|
|
||||||
# boot_function's compilers (boot_compilers)
|
|
||||||
def compilers
|
|
||||||
@method_compilers #+ boot_compilers
|
|
||||||
end
|
|
||||||
|
|
||||||
# collects constants from all compilers into one array
|
# collects constants from all compilers into one array
|
||||||
def constants
|
def constants
|
||||||
compilers.inject([]){|sum ,comp| sum + comp.constants }
|
method_compilers.inject([]){|sum ,comp| sum + comp.constants }
|
||||||
end
|
end
|
||||||
|
|
||||||
# Append another MomCompilers method_compilers to this one.
|
# Append another MomCompilers method_compilers to this one.
|
||||||
@ -47,7 +35,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)
|
||||||
compilers.collect do |compiler|
|
method_compilers.collect do |compiler|
|
||||||
#log.debug "Translate method #{compiler.method.name}"
|
#log.debug "Translate method #{compiler.method.name}"
|
||||||
translate_method(compiler , translator)
|
translate_method(compiler , translator)
|
||||||
end.flatten
|
end.flatten
|
||||||
|
@ -44,9 +44,9 @@ module RubyX
|
|||||||
# The biary the method name refers to is binary code in memory, or in BinaryCode
|
# The biary the method name refers to is binary code in memory, or in BinaryCode
|
||||||
# objects to be precise.
|
# objects to be precise.
|
||||||
def to_binary(platform)
|
def to_binary(platform)
|
||||||
linker = to_risc(platform)
|
linker = to_risc
|
||||||
linker.position_all
|
linker.position_all
|
||||||
linker.create_binary
|
linker.create_binary(platform)
|
||||||
linker
|
linker
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -13,13 +13,13 @@ module Mom
|
|||||||
assert_equal MomCollection , @comp.class
|
assert_equal MomCollection , @comp.class
|
||||||
end
|
end
|
||||||
def test_compilers
|
def test_compilers
|
||||||
assert_equal 1 , @comp.compilers.length
|
assert_equal 22 , @comp.compilers.length
|
||||||
end
|
end
|
||||||
def test_boot_compilers
|
def test_boot_compilers
|
||||||
# assert_equal 22 , @comp.boot_compilers.length
|
assert_equal 21 , @comp.boot_compilers.length
|
||||||
end
|
end
|
||||||
def test_compilers_bare
|
def test_compilers_bare
|
||||||
assert_equal 0 , MomCollection.new.compilers.length
|
assert_equal 21 , MomCollection.new.compilers.length
|
||||||
end
|
end
|
||||||
def test_returns_constants
|
def test_returns_constants
|
||||||
assert_equal Array , @comp.constants.class
|
assert_equal Array , @comp.constants.class
|
||||||
@ -50,7 +50,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 1, @collection.method_compilers.length
|
assert_equal 22, @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
|
||||||
|
59
test/risc/test_risc_collection.rb
Normal file
59
test/risc/test_risc_collection.rb
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
require_relative "helper"
|
||||||
|
|
||||||
|
module Risc
|
||||||
|
class TestMomCompilerTranslate < MiniTest::Test
|
||||||
|
include MomCompile
|
||||||
|
|
||||||
|
def setup
|
||||||
|
Parfait.boot!(Parfait.default_test_options)
|
||||||
|
@comp = compile_mom( "class Test ; def main(); main{return 'Ho'};return 'Hi'; end; end;")
|
||||||
|
@linker = @comp.to_risc.translate(:interpreter)
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_translate_class
|
||||||
|
assert_equal Linker , @linker.class
|
||||||
|
end
|
||||||
|
def test_linker_has_constants
|
||||||
|
assert_equal Array , @linker.constants.class
|
||||||
|
end
|
||||||
|
def test_linker_constants_not_empty
|
||||||
|
assert !@linker.constants.empty?
|
||||||
|
end
|
||||||
|
def test_linker_constants_contains_hi
|
||||||
|
assert @linker.constants.include?("Hi")
|
||||||
|
end
|
||||||
|
def test_linker_constants_contains_ho
|
||||||
|
assert @linker.constants.include?("Ho")
|
||||||
|
end
|
||||||
|
def test_translate_platform
|
||||||
|
assert_kind_of Platform , @linker.platform
|
||||||
|
end
|
||||||
|
def test_translate_assemblers
|
||||||
|
assert_equal Assembler , @linker.assemblers.first.class
|
||||||
|
end
|
||||||
|
def test_assembler_code
|
||||||
|
assert_equal Label , @linker.assemblers.first.instructions.class
|
||||||
|
end
|
||||||
|
def test_assembler_assembled
|
||||||
|
assert_equal LoadConstant , @linker.assemblers.first.instructions.next.class
|
||||||
|
end
|
||||||
|
def test_no_loops_in_chain
|
||||||
|
@linker.assemblers.each do |asm|
|
||||||
|
all = []
|
||||||
|
asm.instructions.each do |ins|
|
||||||
|
assert !all.include?(ins) , "Double in #{asm.callable.name}:#{ins}"
|
||||||
|
all << ins
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
def test_no_risc
|
||||||
|
@linker.position_all
|
||||||
|
@linker.create_binary
|
||||||
|
@linker.assemblers.each do |asm|
|
||||||
|
asm.instructions.each do |ins|
|
||||||
|
ins.assemble(Util::DevNull.new)
|
||||||
|
end # risc instruction don't have an assemble
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user