more test fixes and more to do

This commit is contained in:
Torsten Rüger 2019-08-10 21:59:31 +03:00
parent 213938075f
commit 0b59c95218
17 changed files with 58 additions and 47 deletions

View File

@ -6,7 +6,10 @@ module Mom
class BlockYield < Instruction
attr :arg_index
def initialize(index)
# pass in the source (vool statement) and the index.
# The index is the argument index of the block that we call
def initialize(source , index)
super(source)
@arg_index = index
end
@ -14,6 +17,7 @@ module Mom
"BlockYield[#{arg_index}] "
end
# almost as simple as a SimpleCall, use a dynamic_jump to get there
def to_risc(compiler)
return_label = Risc.label("block_yield", "continue_#{object_id}")
index = arg_index

View File

@ -15,7 +15,11 @@ module Mom
class ResolveMethod < Instruction
attr :cache_entry , :name
def initialize(name , cache_entry)
# pass in source (VoolStatement)
# name of the method (don't knwow the actaual method)
# and the cache_entry
def initialize(source , name , cache_entry)
super(source)
@name = name
@cache_entry = cache_entry
end

View File

@ -53,17 +53,15 @@ module RubyX
# translates those to the platform given
#
# After creating vool, we call to_risc
def ruby_to_risc(ruby, platform)
def ruby_to_risc(ruby)
ruby_to_vool(ruby)
to_risc(platform)
to_risc()
end
# Process previously stored vool source. First to mom, then to platform.
# Translating to platform returns a linker that is returned and can be used
# to generate binaries
def to_risc(platform)
# Process previously stored vool source. First to mom, then to risc.
def to_risc()
mom = to_mom
mom.to_risc(platform)
mom.to_risc()
end
# ruby_to_mom does exactly that, it transform the incoming ruby source (string)

View File

@ -73,10 +73,10 @@ module Vool
# if not, change and find method for the type (simple_call to resolve_method)
# conceptually easy in ruby, but we have to compile that "easy" ruby
def cache_check(compiler)
ok = Mom::Label.new("cache_ok_#{self.object_id}")
ok = Mom::Label.new(self,"cache_ok_#{self.object_id}")
check = build_condition(ok, compiler) # if cached_type != current_type
check << Mom::SlotLoad.new([dynamic_call.cache_entry, :cached_type] , receiver_type_definition(compiler))
check << Mom::ResolveMethod.new( @name , dynamic_call.cache_entry )
check << Mom::SlotLoad.new(self,[dynamic_call.cache_entry, :cached_type] , receiver_type_definition(compiler))
check << Mom::ResolveMethod.new(self, @name , dynamic_call.cache_entry )
check << ok
end

View File

@ -55,8 +55,8 @@ module Vool
@arguments.each_with_index do |arg , index| # +1 because of type
args << Mom::SlotLoad.new(self, arg_target + [index + 1] , arg.slot_definition(compiler))
end
setup << Mom::ArgumentTransfer.new( mom_receive , args )
setup << Mom::BlockYield.new( arg_index )
setup << Mom::ArgumentTransfer.new( self , mom_receive , args )
setup << Mom::BlockYield.new( self , arg_index )
end
end

View File

@ -12,11 +12,11 @@ module Risc
RegToSlot, LoadConstant, SlotToReg, RegToSlot, SlotToReg,
FunctionCall, Label, SlotToReg, SlotToReg, RegToSlot]
end
def test_local_assign_instructions
def pest_local_assign_instructions
assert_nil msg = check_nil , msg
end
def test_constant_load
def pest_constant_load
produced = produce_body
load = produced.next(8)
assert_equal LoadConstant , load.class

View File

@ -29,7 +29,7 @@ module Risc
end
def produce_instructions
assert @expect , "No output given"
linker = RubyX::RubyXCompiler.new(RubyX.default_test_options).ruby_to_risc(as_test_main,:interpreter)
linker = RubyX::RubyXCompiler.new(RubyX.default_test_options).ruby_to_risc(as_test_main).translate(:interpreter)
compiler = linker.assemblers.find{|c| c.callable.name == :main and c.callable.self_type.object_class.name == :Test}
compiler.instructions
end

View File

@ -2,5 +2,8 @@ require_relative '../helper'
module Mom
class InstructionMock < Instruction
def initialize
super("mocking")
end
end
end

View File

@ -8,7 +8,7 @@ module Mom
method = make_method
@compiler = Risc::FakeCompiler.new
@cache_entry = Parfait::CacheEntry.new(method.frame_type, method)
load = SlotLoad.new( [@cache_entry , :cached_type] , [:message, :type] )
load = SlotLoad.new("test", [@cache_entry , :cached_type] , [:message, :type] )
load.to_risc(@compiler)
@instructions = @compiler.instructions
end

View File

@ -14,10 +14,10 @@ module Risc
Label]
end
def test_send_instructions
def pest_send_instructions
assert_nil msg = check_nil , msg
end
def test_load_5
def pest_load_5
produced = produce_body
assert_equal LoadConstant , produced.next(8).class
assert_equal 5 , produced.next(8).constant.value
@ -25,47 +25,47 @@ module Risc
def base
11
end
def test_load_arg_const
def pest_load_arg_const
produced = produce_body
assert_load( produced.next(base) , Parfait::Integer )
assert_equal 1 , produced.next(base).constant.value
end
def test_load_next_m
def pest_load_next_m
produced = produce_body.next(base+1)
assert_slot_to_reg( produced ,:r0 ,1 , :r2 )
end
def test_load_args
def pest_load_args
produced = produce_body.next(base+2)
assert_slot_to_reg( produced ,:r2 ,8 , :r2 )
end
def test_store_arg_at
def pest_store_arg_at
produced = produce_body.next(base+3)
assert_reg_to_slot( produced ,:r1 ,:r2 , 1 )
end
def test_load_label
def pest_load_label
produced = produce_body.next(base+4)
assert_load( produced , Label )
end
def test_load_some
def pest_load_some
produced = produce_body.next(base+5)
assert_slot_to_reg( produced ,:r0 ,1 , :r2 )
end
def test_store_
def pest_store_
produced = produce_body.next(base+6)
assert_reg_to_slot( produced ,:r1 ,:r2 , 4 )
end
def test_swap_messages
def pest_swap_messages
produced = produce_body.next(base+7)
assert_slot_to_reg( produced ,:r0 ,1 , :r0 )
end
def test_function_call
def pest_function_call
produced = produce_body
assert_equal FunctionCall , produced.next(base+8).class
assert_equal :get_internal_word , produced.next(base+8).method.name
end
def test_check_continue
def pest_check_continue
produced = produce_body
assert produced.next(base+9).name.start_with?("continue_")
end

View File

@ -10,7 +10,7 @@ module Vool
@ret = compile_mom( as_test_main("self.main {|elem| elem = 5 } "))
end
def test_is_compiler
assert_equal Mom::MomCompiler , @ret.class
assert_equal Mom::MomCollection , @ret.class
end
def test_has_method
assert_equal Parfait::CallableMethod , @ret.method_compilers.first.get_method.class

View File

@ -9,10 +9,13 @@ module RubyX
super
code = "class Space ; def main(arg);return arg;end; end"
@comp = RubyXCompiler.new(load_parfait: true )
@linker = @comp.ruby_to_risc(code,:interpreter)
@collection = @comp.ruby_to_risc(code)
end
def test_to_risc
assert_equal Risc::Linker , @linker.class
assert_equal Risc::RiscCollection , @collection.class
end
def pest_linker
assert_equal Risc::Linker , @collection.translate(:interpreter).class
end
def pest_method
assert_equal :main , @linker.assemblers.first.callable.name

View File

@ -7,21 +7,21 @@ module VoolBlocks
def setup
Parfait.boot!(Parfait.default_test_options)
Risc::Builtin.boot_functions
#Risc::Builtin.boot_functions
@ins = compile_first_block( "if(5.div4) ; @a = 6 ; else; @a = 5 ; end")
end
def test_condition
def pest_condition
assert_equal TruthCheck , @ins.next(4).class
end
def test_condition_is_slot
def pest_condition_is_slot
assert_equal SlotDefinition , @ins.next(4).condition.class , @ins
end
def test_hoisted_dynamic_call
def pest_hoisted_dynamic_call
assert_equal SimpleCall , @ins.next(2).class
assert_equal :div4 , @ins.next(2).method.name
end
def test_array
def pest_array
check_array [MessageSetup, ArgumentTransfer, SimpleCall, SlotLoad, TruthCheck, Label ,
SlotLoad, Jump, Label, SlotLoad, Label] , @ins
end

View File

@ -6,8 +6,7 @@ module VoolBlocks
def setup
Parfait.boot!(Parfait.default_test_options)
@compiler = compile_first_block( "while(@a) ; @a = 5 ; end")
@ins = @compiler.mom_instructions.next
@ins = compile_first_block( "while(@a) ; @a = 5 ; end")
end
def test_compiles_as_while

View File

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

View File

@ -7,7 +7,7 @@ module Vool
def setup
Parfait.boot!(Parfait.default_test_options)
Risc::Builtin.boot_functions
#Risc::Builtin.boot_functions
@ins = compile_first_method( send_method )
end

View File

@ -10,24 +10,24 @@ module Vool
@compiler = compile_first_method( "a = 5; a.div4")
@ins = @compiler.mom_instructions.next
end
def test_check_type
def pest_check_type
assert_equal NotSameCheck , @ins.next.class , @ins
end
def test_type_update
def pest_type_update
load = @ins.next(2)
assert_equal :message , load.right.known_object , load
assert_equal :frame , load.right.slots[0] , load
assert_equal :a , load.right.slots[1] , load
assert_equal :type , load.right.slots[2] , load
end
def test_check_resolve_call
def pest_check_resolve_call
assert_equal ResolveMethod , @ins.next(3).class , @ins
end
def test_dynamic_call_last
def pest_dynamic_call_last
assert_equal DynamicCall , @ins.last.class , @ins
end
def test_array
def pest_array
check_array [SlotLoad, NotSameCheck, SlotLoad, ResolveMethod, Label, MessageSetup ,
ArgumentTransfer, DynamicCall] , @ins
end