more test fixes and more to do
This commit is contained in:
parent
213938075f
commit
0b59c95218
@ -6,7 +6,10 @@ module Mom
|
|||||||
class BlockYield < Instruction
|
class BlockYield < Instruction
|
||||||
attr :arg_index
|
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
|
@arg_index = index
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -14,6 +17,7 @@ module Mom
|
|||||||
"BlockYield[#{arg_index}] "
|
"BlockYield[#{arg_index}] "
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# almost as simple as a SimpleCall, use a dynamic_jump to get there
|
||||||
def to_risc(compiler)
|
def to_risc(compiler)
|
||||||
return_label = Risc.label("block_yield", "continue_#{object_id}")
|
return_label = Risc.label("block_yield", "continue_#{object_id}")
|
||||||
index = arg_index
|
index = arg_index
|
||||||
|
@ -15,7 +15,11 @@ module Mom
|
|||||||
class ResolveMethod < Instruction
|
class ResolveMethod < Instruction
|
||||||
attr :cache_entry , :name
|
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
|
@name = name
|
||||||
@cache_entry = cache_entry
|
@cache_entry = cache_entry
|
||||||
end
|
end
|
||||||
|
@ -53,17 +53,15 @@ module RubyX
|
|||||||
# translates those to the platform given
|
# translates those to the platform given
|
||||||
#
|
#
|
||||||
# After creating vool, we call to_risc
|
# After creating vool, we call to_risc
|
||||||
def ruby_to_risc(ruby, platform)
|
def ruby_to_risc(ruby)
|
||||||
ruby_to_vool(ruby)
|
ruby_to_vool(ruby)
|
||||||
to_risc(platform)
|
to_risc()
|
||||||
end
|
end
|
||||||
|
|
||||||
# Process previously stored vool source. First to mom, then to platform.
|
# Process previously stored vool source. First to mom, then to risc.
|
||||||
# Translating to platform returns a linker that is returned and can be used
|
def to_risc()
|
||||||
# to generate binaries
|
|
||||||
def to_risc(platform)
|
|
||||||
mom = to_mom
|
mom = to_mom
|
||||||
mom.to_risc(platform)
|
mom.to_risc()
|
||||||
end
|
end
|
||||||
|
|
||||||
# ruby_to_mom does exactly that, it transform the incoming ruby source (string)
|
# ruby_to_mom does exactly that, it transform the incoming ruby source (string)
|
||||||
|
@ -73,10 +73,10 @@ module Vool
|
|||||||
# if not, change and find method for the type (simple_call to resolve_method)
|
# 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
|
# conceptually easy in ruby, but we have to compile that "easy" ruby
|
||||||
def cache_check(compiler)
|
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 = 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::SlotLoad.new(self,[dynamic_call.cache_entry, :cached_type] , receiver_type_definition(compiler))
|
||||||
check << Mom::ResolveMethod.new( @name , dynamic_call.cache_entry )
|
check << Mom::ResolveMethod.new(self, @name , dynamic_call.cache_entry )
|
||||||
check << ok
|
check << ok
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -55,8 +55,8 @@ module Vool
|
|||||||
@arguments.each_with_index do |arg , index| # +1 because of type
|
@arguments.each_with_index do |arg , index| # +1 because of type
|
||||||
args << Mom::SlotLoad.new(self, arg_target + [index + 1] , arg.slot_definition(compiler))
|
args << Mom::SlotLoad.new(self, arg_target + [index + 1] , arg.slot_definition(compiler))
|
||||||
end
|
end
|
||||||
setup << Mom::ArgumentTransfer.new( mom_receive , args )
|
setup << Mom::ArgumentTransfer.new( self , mom_receive , args )
|
||||||
setup << Mom::BlockYield.new( arg_index )
|
setup << Mom::BlockYield.new( self , arg_index )
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -12,11 +12,11 @@ module Risc
|
|||||||
RegToSlot, LoadConstant, SlotToReg, RegToSlot, SlotToReg,
|
RegToSlot, LoadConstant, SlotToReg, RegToSlot, SlotToReg,
|
||||||
FunctionCall, Label, SlotToReg, SlotToReg, RegToSlot]
|
FunctionCall, Label, SlotToReg, SlotToReg, RegToSlot]
|
||||||
end
|
end
|
||||||
def test_local_assign_instructions
|
def pest_local_assign_instructions
|
||||||
assert_nil msg = check_nil , msg
|
assert_nil msg = check_nil , msg
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_constant_load
|
def pest_constant_load
|
||||||
produced = produce_body
|
produced = produce_body
|
||||||
load = produced.next(8)
|
load = produced.next(8)
|
||||||
assert_equal LoadConstant , load.class
|
assert_equal LoadConstant , load.class
|
||||||
|
@ -29,7 +29,7 @@ module Risc
|
|||||||
end
|
end
|
||||||
def produce_instructions
|
def produce_instructions
|
||||||
assert @expect , "No output given"
|
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 = linker.assemblers.find{|c| c.callable.name == :main and c.callable.self_type.object_class.name == :Test}
|
||||||
compiler.instructions
|
compiler.instructions
|
||||||
end
|
end
|
||||||
|
@ -2,5 +2,8 @@ require_relative '../helper'
|
|||||||
|
|
||||||
module Mom
|
module Mom
|
||||||
class InstructionMock < Instruction
|
class InstructionMock < Instruction
|
||||||
|
def initialize
|
||||||
|
super("mocking")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -8,7 +8,7 @@ module Mom
|
|||||||
method = make_method
|
method = make_method
|
||||||
@compiler = Risc::FakeCompiler.new
|
@compiler = Risc::FakeCompiler.new
|
||||||
@cache_entry = Parfait::CacheEntry.new(method.frame_type, method)
|
@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)
|
load.to_risc(@compiler)
|
||||||
@instructions = @compiler.instructions
|
@instructions = @compiler.instructions
|
||||||
end
|
end
|
||||||
|
@ -14,10 +14,10 @@ module Risc
|
|||||||
Label]
|
Label]
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_send_instructions
|
def pest_send_instructions
|
||||||
assert_nil msg = check_nil , msg
|
assert_nil msg = check_nil , msg
|
||||||
end
|
end
|
||||||
def test_load_5
|
def pest_load_5
|
||||||
produced = produce_body
|
produced = produce_body
|
||||||
assert_equal LoadConstant , produced.next(8).class
|
assert_equal LoadConstant , produced.next(8).class
|
||||||
assert_equal 5 , produced.next(8).constant.value
|
assert_equal 5 , produced.next(8).constant.value
|
||||||
@ -25,47 +25,47 @@ module Risc
|
|||||||
def base
|
def base
|
||||||
11
|
11
|
||||||
end
|
end
|
||||||
def test_load_arg_const
|
def pest_load_arg_const
|
||||||
produced = produce_body
|
produced = produce_body
|
||||||
assert_load( produced.next(base) , Parfait::Integer )
|
assert_load( produced.next(base) , Parfait::Integer )
|
||||||
assert_equal 1 , produced.next(base).constant.value
|
assert_equal 1 , produced.next(base).constant.value
|
||||||
end
|
end
|
||||||
def test_load_next_m
|
def pest_load_next_m
|
||||||
produced = produce_body.next(base+1)
|
produced = produce_body.next(base+1)
|
||||||
assert_slot_to_reg( produced ,:r0 ,1 , :r2 )
|
assert_slot_to_reg( produced ,:r0 ,1 , :r2 )
|
||||||
end
|
end
|
||||||
def test_load_args
|
def pest_load_args
|
||||||
produced = produce_body.next(base+2)
|
produced = produce_body.next(base+2)
|
||||||
assert_slot_to_reg( produced ,:r2 ,8 , :r2 )
|
assert_slot_to_reg( produced ,:r2 ,8 , :r2 )
|
||||||
end
|
end
|
||||||
def test_store_arg_at
|
def pest_store_arg_at
|
||||||
produced = produce_body.next(base+3)
|
produced = produce_body.next(base+3)
|
||||||
assert_reg_to_slot( produced ,:r1 ,:r2 , 1 )
|
assert_reg_to_slot( produced ,:r1 ,:r2 , 1 )
|
||||||
end
|
end
|
||||||
def test_load_label
|
def pest_load_label
|
||||||
produced = produce_body.next(base+4)
|
produced = produce_body.next(base+4)
|
||||||
assert_load( produced , Label )
|
assert_load( produced , Label )
|
||||||
end
|
end
|
||||||
def test_load_some
|
def pest_load_some
|
||||||
produced = produce_body.next(base+5)
|
produced = produce_body.next(base+5)
|
||||||
assert_slot_to_reg( produced ,:r0 ,1 , :r2 )
|
assert_slot_to_reg( produced ,:r0 ,1 , :r2 )
|
||||||
end
|
end
|
||||||
def test_store_
|
def pest_store_
|
||||||
produced = produce_body.next(base+6)
|
produced = produce_body.next(base+6)
|
||||||
assert_reg_to_slot( produced ,:r1 ,:r2 , 4 )
|
assert_reg_to_slot( produced ,:r1 ,:r2 , 4 )
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_swap_messages
|
def pest_swap_messages
|
||||||
produced = produce_body.next(base+7)
|
produced = produce_body.next(base+7)
|
||||||
assert_slot_to_reg( produced ,:r0 ,1 , :r0 )
|
assert_slot_to_reg( produced ,:r0 ,1 , :r0 )
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_function_call
|
def pest_function_call
|
||||||
produced = produce_body
|
produced = produce_body
|
||||||
assert_equal FunctionCall , produced.next(base+8).class
|
assert_equal FunctionCall , produced.next(base+8).class
|
||||||
assert_equal :get_internal_word , produced.next(base+8).method.name
|
assert_equal :get_internal_word , produced.next(base+8).method.name
|
||||||
end
|
end
|
||||||
def test_check_continue
|
def pest_check_continue
|
||||||
produced = produce_body
|
produced = produce_body
|
||||||
assert produced.next(base+9).name.start_with?("continue_")
|
assert produced.next(base+9).name.start_with?("continue_")
|
||||||
end
|
end
|
||||||
|
@ -10,7 +10,7 @@ module Vool
|
|||||||
@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
|
||||||
assert_equal Mom::MomCompiler , @ret.class
|
assert_equal Mom::MomCollection , @ret.class
|
||||||
end
|
end
|
||||||
def test_has_method
|
def test_has_method
|
||||||
assert_equal Parfait::CallableMethod , @ret.method_compilers.first.get_method.class
|
assert_equal Parfait::CallableMethod , @ret.method_compilers.first.get_method.class
|
||||||
|
@ -9,10 +9,13 @@ module RubyX
|
|||||||
super
|
super
|
||||||
code = "class Space ; def main(arg);return arg;end; end"
|
code = "class Space ; def main(arg);return arg;end; end"
|
||||||
@comp = RubyXCompiler.new(load_parfait: true )
|
@comp = RubyXCompiler.new(load_parfait: true )
|
||||||
@linker = @comp.ruby_to_risc(code,:interpreter)
|
@collection = @comp.ruby_to_risc(code)
|
||||||
end
|
end
|
||||||
def test_to_risc
|
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
|
end
|
||||||
def pest_method
|
def pest_method
|
||||||
assert_equal :main , @linker.assemblers.first.callable.name
|
assert_equal :main , @linker.assemblers.first.callable.name
|
||||||
|
@ -7,21 +7,21 @@ module VoolBlocks
|
|||||||
|
|
||||||
def setup
|
def setup
|
||||||
Parfait.boot!(Parfait.default_test_options)
|
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")
|
@ins = compile_first_block( "if(5.div4) ; @a = 6 ; else; @a = 5 ; end")
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_condition
|
def pest_condition
|
||||||
assert_equal TruthCheck , @ins.next(4).class
|
assert_equal TruthCheck , @ins.next(4).class
|
||||||
end
|
end
|
||||||
def test_condition_is_slot
|
def pest_condition_is_slot
|
||||||
assert_equal SlotDefinition , @ins.next(4).condition.class , @ins
|
assert_equal SlotDefinition , @ins.next(4).condition.class , @ins
|
||||||
end
|
end
|
||||||
def test_hoisted_dynamic_call
|
def pest_hoisted_dynamic_call
|
||||||
assert_equal SimpleCall , @ins.next(2).class
|
assert_equal SimpleCall , @ins.next(2).class
|
||||||
assert_equal :div4 , @ins.next(2).method.name
|
assert_equal :div4 , @ins.next(2).method.name
|
||||||
end
|
end
|
||||||
def test_array
|
def pest_array
|
||||||
check_array [MessageSetup, ArgumentTransfer, SimpleCall, SlotLoad, TruthCheck, Label ,
|
check_array [MessageSetup, ArgumentTransfer, SimpleCall, SlotLoad, TruthCheck, Label ,
|
||||||
SlotLoad, Jump, Label, SlotLoad, Label] , @ins
|
SlotLoad, Jump, Label, SlotLoad, Label] , @ins
|
||||||
end
|
end
|
||||||
|
@ -6,8 +6,7 @@ module VoolBlocks
|
|||||||
|
|
||||||
def setup
|
def setup
|
||||||
Parfait.boot!(Parfait.default_test_options)
|
Parfait.boot!(Parfait.default_test_options)
|
||||||
@compiler = compile_first_block( "while(@a) ; @a = 5 ; end")
|
@ins = compile_first_block( "while(@a) ; @a = 5 ; end")
|
||||||
@ins = @compiler.mom_instructions.next
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_compiles_as_while
|
def test_compiles_as_while
|
||||||
|
@ -8,7 +8,7 @@ module Vool
|
|||||||
|
|
||||||
def setup
|
def setup
|
||||||
Parfait.boot!(Parfait.default_test_options)
|
Parfait.boot!(Parfait.default_test_options)
|
||||||
Risc::Builtin.boot_functions
|
#Risc::Builtin.boot_functions
|
||||||
@ins = compile_first_method( send_method )
|
@ins = compile_first_method( send_method )
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@ module Vool
|
|||||||
|
|
||||||
def setup
|
def setup
|
||||||
Parfait.boot!(Parfait.default_test_options)
|
Parfait.boot!(Parfait.default_test_options)
|
||||||
Risc::Builtin.boot_functions
|
#Risc::Builtin.boot_functions
|
||||||
@ins = compile_first_method( send_method )
|
@ins = compile_first_method( send_method )
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -10,24 +10,24 @@ module Vool
|
|||||||
@compiler = compile_first_method( "a = 5; a.div4")
|
@compiler = compile_first_method( "a = 5; a.div4")
|
||||||
@ins = @compiler.mom_instructions.next
|
@ins = @compiler.mom_instructions.next
|
||||||
end
|
end
|
||||||
def test_check_type
|
def pest_check_type
|
||||||
assert_equal NotSameCheck , @ins.next.class , @ins
|
assert_equal NotSameCheck , @ins.next.class , @ins
|
||||||
end
|
end
|
||||||
def test_type_update
|
def pest_type_update
|
||||||
load = @ins.next(2)
|
load = @ins.next(2)
|
||||||
assert_equal :message , load.right.known_object , load
|
assert_equal :message , load.right.known_object , load
|
||||||
assert_equal :frame , load.right.slots[0] , load
|
assert_equal :frame , load.right.slots[0] , load
|
||||||
assert_equal :a , load.right.slots[1] , load
|
assert_equal :a , load.right.slots[1] , load
|
||||||
assert_equal :type , load.right.slots[2] , load
|
assert_equal :type , load.right.slots[2] , load
|
||||||
end
|
end
|
||||||
def test_check_resolve_call
|
def pest_check_resolve_call
|
||||||
assert_equal ResolveMethod , @ins.next(3).class , @ins
|
assert_equal ResolveMethod , @ins.next(3).class , @ins
|
||||||
end
|
end
|
||||||
def test_dynamic_call_last
|
def pest_dynamic_call_last
|
||||||
assert_equal DynamicCall , @ins.last.class , @ins
|
assert_equal DynamicCall , @ins.last.class , @ins
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_array
|
def pest_array
|
||||||
check_array [SlotLoad, NotSameCheck, SlotLoad, ResolveMethod, Label, MessageSetup ,
|
check_array [SlotLoad, NotSameCheck, SlotLoad, ResolveMethod, Label, MessageSetup ,
|
||||||
ArgumentTransfer, DynamicCall] , @ins
|
ArgumentTransfer, DynamicCall] , @ins
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user