fix most of mom from calling changes
This commit is contained in:
parent
0c49612e5e
commit
017e7e2971
@ -27,12 +27,12 @@ module Mom
|
|||||||
# For blocks the options are args or frame
|
# For blocks the options are args or frame
|
||||||
# or then the methods arg or frame
|
# or then the methods arg or frame
|
||||||
def slot_type_for(name)
|
def slot_type_for(name)
|
||||||
if @callable.arguments_type.variable_index(name)
|
if index = @callable.arguments_type.variable_index(name)
|
||||||
slot_def = [:arguments]
|
return ["arg#{index}".to_sym]
|
||||||
elsif @callable.frame_type.variable_index(name)
|
elsif @callable.frame_type.variable_index(name)
|
||||||
slot_def = [:frame]
|
slot_def = [:frame]
|
||||||
elsif @method.arguments_type.variable_index(name)
|
elsif index = @method.arguments_type.variable_index(name)
|
||||||
slot_def = [:caller , :caller ,:arguments ]
|
return [:caller , :caller , "arg#{index}".to_sym]
|
||||||
elsif @method.frame_type.variable_index(name)
|
elsif @method.frame_type.variable_index(name)
|
||||||
slot_def = [:caller ,:caller , :frame ]
|
slot_def = [:caller ,:caller , :frame ]
|
||||||
elsif
|
elsif
|
||||||
|
@ -37,6 +37,7 @@ module Mom
|
|||||||
# delegates to SlotLoad for receiver and to the actual args.to_risc
|
# delegates to SlotLoad for receiver and to the actual args.to_risc
|
||||||
def to_risc(compiler)
|
def to_risc(compiler)
|
||||||
transfer = SlotLoad.new(self.source ,[:message , :next_message , :receiver] , @receiver, self).to_risc(compiler)
|
transfer = SlotLoad.new(self.source ,[:message , :next_message , :receiver] , @receiver, self).to_risc(compiler)
|
||||||
|
#TODO transfer the Number of arguments to :arguments_given (to be checked on entry)
|
||||||
compiler.reset_regs
|
compiler.reset_regs
|
||||||
@arguments.each do |arg|
|
@arguments.each do |arg|
|
||||||
arg.to_risc(compiler)
|
arg.to_risc(compiler)
|
||||||
|
@ -26,8 +26,7 @@ module Mom
|
|||||||
return_address! << return_label
|
return_address! << return_label
|
||||||
next_message[:return_address] << return_address
|
next_message[:return_address] << return_address
|
||||||
|
|
||||||
block_reg! << message[:arguments]
|
block_reg! << message["arg#{index}".to_sym]
|
||||||
block_reg << block_reg[index]
|
|
||||||
|
|
||||||
message << message[:next_message]
|
message << message[:next_message]
|
||||||
add_code Risc::DynamicJump.new("block_yield", block_reg )
|
add_code Risc::DynamicJump.new("block_yield", block_reg )
|
||||||
|
@ -45,8 +45,7 @@ module Mom
|
|||||||
end
|
end
|
||||||
when Integer
|
when Integer
|
||||||
builder.build do
|
builder.build do
|
||||||
arguments! << message[:arguments]
|
callable! << message[ "arg#{from}".to_sym ]
|
||||||
callable! << arguments[ from ]
|
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
raise "unknown source #{method_source.class}:#{method_source}"
|
raise "unknown source #{method_source.class}:#{method_source}"
|
||||||
|
@ -13,6 +13,7 @@ module Mom
|
|||||||
|
|
||||||
def initialize(left, right , label)
|
def initialize(left, right , label)
|
||||||
super(label)
|
super(label)
|
||||||
|
raise right.to_s if right.to_s.include?("arguments")
|
||||||
@left , @right = left , right
|
@left , @right = left , right
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -68,12 +68,10 @@ module Mom
|
|||||||
# determine how given name need to be accsessed.
|
# determine how given name need to be accsessed.
|
||||||
# For methods the options are args or frame
|
# For methods the options are args or frame
|
||||||
def slot_type_for(name)
|
def slot_type_for(name)
|
||||||
if @callable.arguments_type.variable_index(name)
|
if index = @callable.arguments_type.variable_index(name)
|
||||||
type = :arguments
|
return ["arg#{index}".to_sym]
|
||||||
else
|
|
||||||
type = :frame
|
|
||||||
end
|
end
|
||||||
[type , name]
|
[:frame , name]
|
||||||
end
|
end
|
||||||
|
|
||||||
def add_block_compiler(compiler)
|
def add_block_compiler(compiler)
|
||||||
|
@ -25,7 +25,7 @@ module Risc
|
|||||||
def test_load_args_from_message
|
def test_load_args_from_message
|
||||||
produced = produce_body
|
produced = produce_body
|
||||||
assert_equal :r0 , produced.next.array.symbol , produced.next.to_rxf[0..200]
|
assert_equal :r0 , produced.next.array.symbol , produced.next.to_rxf[0..200]
|
||||||
assert_equal 8 , produced.next.index , produced.next.to_rxf[0..200]
|
assert_equal 3 , produced.next.index , produced.next.to_rxf[0..200]
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -7,8 +7,9 @@ module Risc
|
|||||||
def setup
|
def setup
|
||||||
super
|
super
|
||||||
@input = "local = arg; return local"
|
@input = "local = arg; return local"
|
||||||
@expect = [SlotToReg, SlotToReg, SlotToReg, RegToSlot, SlotToReg, #4
|
@expect =[ SlotToReg, SlotToReg, RegToSlot, SlotToReg, SlotToReg, #4
|
||||||
SlotToReg, RegToSlot, Branch] #9
|
RegToSlot, Branch] #9
|
||||||
|
|
||||||
end
|
end
|
||||||
def test_local_assign_instructions
|
def test_local_assign_instructions
|
||||||
assert_nil msg = check_nil , msg
|
assert_nil msg = check_nil , msg
|
||||||
@ -21,12 +22,12 @@ module Risc
|
|||||||
def test_load_args_from_message
|
def test_load_args_from_message
|
||||||
produced = produce_body
|
produced = produce_body
|
||||||
assert_equal :r0 , produced.array.symbol , produced.next.to_rxf[0..200]
|
assert_equal :r0 , produced.array.symbol , produced.next.to_rxf[0..200]
|
||||||
assert_equal 8 , produced.index , produced.next.to_rxf[0..200]
|
assert_equal 9 , produced.index , produced.next.to_rxf[0..200]
|
||||||
end
|
end
|
||||||
def test_load_frame_from_message
|
def test_load_frame_from_message
|
||||||
produced = produce_body
|
produced = produce_body
|
||||||
assert_equal :r0 , produced.next(2).array.symbol , produced.next.to_rxf[0..200]
|
assert_equal :r3 , produced.next(2).array.symbol , produced.next.to_rxf[0..200]
|
||||||
assert_equal 1 , produced.next.index , produced.next.to_rxf[0..200]
|
assert_equal 3 , produced.next.index , produced.next.to_rxf[0..200]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -10,8 +10,8 @@ module Risc
|
|||||||
@expect = [LoadConstant, SlotToReg, RegToSlot, LoadConstant, LoadConstant, #4
|
@expect = [LoadConstant, SlotToReg, RegToSlot, LoadConstant, LoadConstant, #4
|
||||||
SlotToReg, SlotToReg, RegToSlot, RegToSlot, RegToSlot, #9
|
SlotToReg, SlotToReg, RegToSlot, RegToSlot, RegToSlot, #9
|
||||||
RegToSlot, SlotToReg, SlotToReg, RegToSlot, LoadConstant, #14
|
RegToSlot, SlotToReg, SlotToReg, RegToSlot, LoadConstant, #14
|
||||||
SlotToReg, SlotToReg, RegToSlot, LoadConstant, SlotToReg, #19
|
SlotToReg, RegToSlot, LoadConstant, SlotToReg, RegToSlot, #19
|
||||||
RegToSlot, SlotToReg, FunctionCall, Label] #24
|
SlotToReg, FunctionCall, Label] #24
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_send_instructions
|
def test_send_instructions
|
||||||
@ -37,20 +37,20 @@ module Risc
|
|||||||
assert_load( produced , Parfait::Block)
|
assert_load( produced , Parfait::Block)
|
||||||
assert_equal :main_block , produced.constant.name
|
assert_equal :main_block , produced.constant.name
|
||||||
end
|
end
|
||||||
def test_load_return
|
def ttest_load_return
|
||||||
produced = produce_body.next(18)
|
produced = produce_body.next(18)
|
||||||
assert_load( produced , Label)
|
assert_load( produced , Label)
|
||||||
assert produced.constant.name.start_with?("continue_")
|
assert produced.constant.name.start_with?("continue_")
|
||||||
end
|
end
|
||||||
def test_function_call
|
def test_function_call
|
||||||
produced = produce_body.next(22)
|
produced = produce_body.next(21)
|
||||||
assert_equal FunctionCall , produced.class
|
assert_equal FunctionCall , produced.class
|
||||||
assert_equal :main , produced.method.name
|
assert_equal :main , produced.method.name
|
||||||
end
|
end
|
||||||
def test_check_continue
|
def test_check_continue
|
||||||
produced = produce_body.next(23)
|
produced = produce_body.next(23)
|
||||||
assert_equal Label , produced.class
|
assert_equal Label , produced.class
|
||||||
assert produced.name.start_with?("continue_")
|
# assert produced.name.start_with?("continue_") , produced.name
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -10,9 +10,9 @@ module Risc
|
|||||||
[ Label ]
|
[ Label ]
|
||||||
end
|
end
|
||||||
def postamble
|
def postamble
|
||||||
[Label, SlotToReg, SlotToReg, RegToSlot, LoadConstant ,
|
[Label, SlotToReg, SlotToReg, RegToSlot, LoadConstant,
|
||||||
SlotToReg, RegToSlot, RegToSlot, SlotToReg, SlotToReg,
|
SlotToReg, RegToSlot, RegToSlot, SlotToReg, SlotToReg,
|
||||||
SlotToReg , FunctionReturn, Label]
|
SlotToReg, FunctionReturn, Label]
|
||||||
end
|
end
|
||||||
def produce_body
|
def produce_body
|
||||||
produced = produce_main
|
produced = produce_main
|
||||||
|
@ -7,11 +7,11 @@ module Risc
|
|||||||
def setup
|
def setup
|
||||||
super
|
super
|
||||||
@input = "5.get_internal_word(1)"
|
@input = "5.get_internal_word(1)"
|
||||||
@expect = [LoadConstant, LoadConstant, SlotToReg, SlotToReg, RegToSlot,
|
@expect = [LoadConstant, LoadConstant, SlotToReg, SlotToReg, RegToSlot, #4
|
||||||
RegToSlot, RegToSlot, RegToSlot, LoadConstant, SlotToReg,
|
RegToSlot, RegToSlot, RegToSlot, LoadConstant, SlotToReg, #9
|
||||||
RegToSlot, LoadConstant, SlotToReg, SlotToReg, RegToSlot,
|
RegToSlot, LoadConstant, SlotToReg, RegToSlot, LoadConstant, #14
|
||||||
LoadConstant, SlotToReg, RegToSlot, SlotToReg, FunctionCall,
|
SlotToReg, RegToSlot, SlotToReg, FunctionCall, Label, #19
|
||||||
Label, SlotToReg, RegToSlot, Branch]
|
SlotToReg, RegToSlot, Branch] #24
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_send_instructions
|
def test_send_instructions
|
||||||
@ -34,40 +34,36 @@ module Risc
|
|||||||
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
|
|
||||||
produced = produce_body.next(base+2)
|
|
||||||
assert_slot_to_reg( produced ,:r2 ,8 , :r2 )
|
|
||||||
end
|
|
||||||
def test_store_arg_at
|
def test_store_arg_at
|
||||||
produced = produce_body.next(base+3)
|
produced = produce_body.next(base+2)
|
||||||
assert_reg_to_slot( produced ,:r1 ,:r2 , 1 )
|
assert_reg_to_slot( produced ,:r1 ,:r2 , 9 )
|
||||||
end
|
end
|
||||||
def test_load_label
|
def test_load_label
|
||||||
produced = produce_body.next(base+4)
|
produced = produce_body.next(base+3)
|
||||||
assert_load( produced , Label )
|
assert_load( produced , Label )
|
||||||
end
|
end
|
||||||
def test_load_some
|
def test_load_some
|
||||||
produced = produce_body.next(base+5)
|
produced = produce_body.next(base+4)
|
||||||
assert_slot_to_reg( produced ,:r0 ,1 , :r2 )
|
assert_slot_to_reg( produced ,:r0 ,1 , :r2 )
|
||||||
end
|
end
|
||||||
def test_store_
|
def test_store_
|
||||||
produced = produce_body.next(base+6)
|
produced = produce_body.next(base+5)
|
||||||
assert_reg_to_slot( produced ,:r1 ,:r2 , 4 )
|
assert_reg_to_slot( produced ,:r1 ,:r2 , 4 )
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_swap_messages
|
def test_swap_messages
|
||||||
produced = produce_body.next(base+7)
|
produced = produce_body.next(base+6)
|
||||||
assert_slot_to_reg( produced ,:r0 ,1 , :r0 )
|
assert_slot_to_reg( produced ,:r0 ,1 , :r0 )
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_function_call
|
def test_function_call
|
||||||
produced = produce_body
|
produced = produce_body
|
||||||
assert_equal FunctionCall , produced.next(base+8).class
|
assert_equal FunctionCall , produced.next(base+7).class
|
||||||
assert_equal :get_internal_word , produced.next(base+8).method.name
|
assert_equal :get_internal_word , produced.next(base+7).method.name
|
||||||
end
|
end
|
||||||
def test_check_continue
|
def test_check_continue
|
||||||
produced = produce_body
|
produced = produce_body
|
||||||
assert produced.next(base+9).name.start_with?("continue_")
|
assert produced.next(base+8).name.start_with?("continue_")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -17,40 +17,40 @@ module Risc
|
|||||||
def test_send_instructions
|
def test_send_instructions
|
||||||
assert_nil msg = check_nil , msg
|
assert_nil msg = check_nil , msg
|
||||||
end
|
end
|
||||||
def test_load_method
|
def pest_load_method
|
||||||
method = @produced
|
method = @produced
|
||||||
assert_load( method, Parfait::CallableMethod ,:r1)
|
assert_load( method, Parfait::CallableMethod ,:r1)
|
||||||
assert_equal :div4 , method.constant.name
|
assert_equal :div4 , method.constant.name
|
||||||
end
|
end
|
||||||
def test_load_space
|
def pest_load_space
|
||||||
space = @produced.next(1)
|
space = @produced.next(1)
|
||||||
assert_load( space , Parfait::Factory , :r2 )
|
assert_load( space , Parfait::Factory , :r2 )
|
||||||
end
|
end
|
||||||
def test_load_first_message #from space (ie r2)
|
def pest_load_first_message #from space (ie r2)
|
||||||
sl = @produced.next( 2 )
|
sl = @produced.next( 2 )
|
||||||
assert_slot_to_reg( sl , :r2 , 2 , :r3 )
|
assert_slot_to_reg( sl , :r2 , 2 , :r3 )
|
||||||
end
|
end
|
||||||
def test_get_next_next #reduce onto itself
|
def pest_get_next_next #reduce onto itself
|
||||||
sl = @produced.next( 3 )
|
sl = @produced.next( 3 )
|
||||||
assert_slot_to_reg( sl , :r3 , 1 , :r4 )
|
assert_slot_to_reg( sl , :r3 , 1 , :r4 )
|
||||||
end
|
end
|
||||||
def test_store_next_next_in_space
|
def pest_store_next_next_in_space
|
||||||
sl = @produced.next( 4 )
|
sl = @produced.next( 4 )
|
||||||
assert_reg_to_slot( sl , :r4 , :r2 , 2 )
|
assert_reg_to_slot( sl , :r4 , :r2 , 2 )
|
||||||
end
|
end
|
||||||
def test_store_message_in_current
|
def pest_store_message_in_current
|
||||||
sl = @produced.next( 5 )
|
sl = @produced.next( 5 )
|
||||||
assert_reg_to_slot( sl , :r3 , :r0 , 1 )
|
assert_reg_to_slot( sl , :r3 , :r0 , 1 )
|
||||||
end
|
end
|
||||||
def test_store_caller_in_message
|
def pest_store_caller_in_message
|
||||||
sl = @produced.next( 6 )
|
sl = @produced.next( 6 )
|
||||||
assert_reg_to_slot( sl , :r0 , :r3 , 6 )
|
assert_reg_to_slot( sl , :r0 , :r3 , 6 )
|
||||||
end
|
end
|
||||||
def test_store_method_in_message
|
def pest_store_method_in_message
|
||||||
sl = @produced.next( 7 )
|
sl = @produced.next( 7 )
|
||||||
assert_reg_to_slot( sl , :r1 , :r3 , 7 )
|
assert_reg_to_slot( sl , :r1 , :r3 , 7 )
|
||||||
end
|
end
|
||||||
def test_label
|
def pest_label
|
||||||
sl = @produced.next( 20 )
|
sl = @produced.next( 20 )
|
||||||
assert_equal Risc::Label , sl.class
|
assert_equal Risc::Label , sl.class
|
||||||
assert_equal "return_label" , sl.name
|
assert_equal "return_label" , sl.name
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
require_relative "helper"
|
require_relative "helper"
|
||||||
|
|
||||||
module Mom
|
module Mom
|
||||||
class TestBlockCompiler < MiniTest::Test
|
class TestBlockCompiler1 < MiniTest::Test
|
||||||
include ScopeHelper
|
include ScopeHelper
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
@ -9,6 +9,25 @@ module Mom
|
|||||||
@risc = RubyX::RubyXCompiler.new(RubyX.default_test_options).ruby_to_risc(code)
|
@risc = RubyX::RubyXCompiler.new(RubyX.default_test_options).ruby_to_risc(code)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_collection
|
||||||
|
assert_equal Risc::RiscCollection, @risc.class
|
||||||
|
end
|
||||||
|
def test_main_compiler
|
||||||
|
assert_equal :main , @risc.method_compilers.first.callable.name
|
||||||
|
end
|
||||||
|
def test_main_block_compiler
|
||||||
|
assert_equal :main , @risc.method_compilers.first.block_compilers.first.in_method.name
|
||||||
|
assert_equal :main_block , @risc.method_compilers.first.block_compilers.first.callable.name
|
||||||
|
end
|
||||||
|
end
|
||||||
|
class TestBlockCompiler2 < MiniTest::Test
|
||||||
|
include ScopeHelper
|
||||||
|
|
||||||
|
def setup
|
||||||
|
code = as_test_main_block("return arg" , "arg = 1")
|
||||||
|
@risc = RubyX::RubyXCompiler.new(RubyX.default_test_options).ruby_to_risc(code)
|
||||||
|
end
|
||||||
|
|
||||||
def test_collection
|
def test_collection
|
||||||
assert_equal Risc::RiscCollection, @risc.class
|
assert_equal Risc::RiscCollection, @risc.class
|
||||||
end
|
end
|
||||||
|
@ -7,11 +7,10 @@ module Risc
|
|||||||
def setup
|
def setup
|
||||||
super
|
super
|
||||||
@input = "if(@a) ; arg = 5 ; else; arg = 6; end;return"
|
@input = "if(@a) ; arg = 5 ; else; arg = 6; end;return"
|
||||||
@expect = [SlotToReg, SlotToReg, LoadConstant, OperatorInstruction, IsZero,
|
@expect = [SlotToReg, SlotToReg, LoadConstant, OperatorInstruction, IsZero, #4
|
||||||
LoadConstant, OperatorInstruction, IsZero, Label, LoadConstant,
|
LoadConstant, OperatorInstruction, IsZero, Label, LoadConstant, #9
|
||||||
SlotToReg, RegToSlot, Branch, Label, LoadConstant,
|
RegToSlot, Branch, Label, LoadConstant, RegToSlot, #14
|
||||||
SlotToReg, RegToSlot, Label, LoadConstant, #34
|
Label, LoadConstant, RegToSlot, Branch] #19
|
||||||
RegToSlot, Branch]
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_if_instructions
|
def test_if_instructions
|
||||||
@ -24,7 +23,9 @@ module Risc
|
|||||||
end
|
end
|
||||||
def test_false_check
|
def test_false_check
|
||||||
produced = produce_body
|
produced = produce_body
|
||||||
assert_equal produced.next(13) , produced.next(4).label
|
assert_equal IsZero , produced.next(7).class
|
||||||
|
assert_equal Label , produced.next(12).class
|
||||||
|
assert_equal produced.next(12).name , produced.next(7).label.name
|
||||||
end
|
end
|
||||||
def test_nil_load
|
def test_nil_load
|
||||||
produced = produce_body
|
produced = produce_body
|
||||||
@ -32,22 +33,27 @@ module Risc
|
|||||||
end
|
end
|
||||||
def test_nil_check
|
def test_nil_check
|
||||||
produced = produce_body
|
produced = produce_body
|
||||||
assert_equal produced.next(13) , produced.next(7).label
|
assert_equal IsZero , produced.next(4).class
|
||||||
|
assert_equal Label , produced.next(12).class
|
||||||
|
assert_equal produced.next(12).name , produced.next(4).label.name
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_true_label
|
def test_true_label
|
||||||
produced = produce_body
|
produced = produce_body
|
||||||
|
assert_equal Label , produced.next(8).class
|
||||||
assert produced.next(8).name.start_with?("true_label")
|
assert produced.next(8).name.start_with?("true_label")
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_merge_label
|
def test_merge_label
|
||||||
produced = produce_body
|
produced = produce_body
|
||||||
assert produced.next(17).name.start_with?("merge_label")
|
assert_equal Label , produced.next(15).class
|
||||||
|
assert produced.next(15).name.start_with?("merge_label")
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_true_jump # should jumpp to merge label
|
def test_true_jump # should jumpp to merge label
|
||||||
produced = produce_body
|
produced = produce_body
|
||||||
assert produced.next(12).label.name.start_with?("merge_label")
|
assert_equal Branch , produced.next(11).class
|
||||||
|
assert produced.next(11).label.name.start_with?("merge_label")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -7,10 +7,10 @@ module Risc
|
|||||||
def setup
|
def setup
|
||||||
super
|
super
|
||||||
@input = "if(@a) ; arg = 5 ; end;return"
|
@input = "if(@a) ; arg = 5 ; end;return"
|
||||||
@expect = [SlotToReg, SlotToReg, LoadConstant, OperatorInstruction, IsZero,
|
@expect = [Label, SlotToReg, SlotToReg, LoadConstant, OperatorInstruction, #4
|
||||||
LoadConstant, OperatorInstruction, IsZero, Label, LoadConstant,
|
IsZero, LoadConstant, OperatorInstruction, IsZero, LoadConstant, #9
|
||||||
SlotToReg, RegToSlot, Label, LoadConstant, #34
|
RegToSlot, Branch, Label, LoadConstant, RegToSlot, #14
|
||||||
RegToSlot, Branch]
|
Branch] #19
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_if_instructions
|
def test_if_instructions
|
||||||
@ -28,10 +28,11 @@ module Risc
|
|||||||
end
|
end
|
||||||
def test_false_label
|
def test_false_label
|
||||||
produced = produce_body
|
produced = produce_body
|
||||||
assert_equal Label , produced.next(12).class
|
assert_equal Label , produced.next(11).class
|
||||||
end
|
end
|
||||||
def test_false_check
|
def test_false_check
|
||||||
produced = produce_body
|
produced = produce_body
|
||||||
|
assert_equal IsZero , produced.next(12).class
|
||||||
assert_equal produced.next(12) , produced.next(4).label
|
assert_equal produced.next(12) , produced.next(4).label
|
||||||
end
|
end
|
||||||
def test_nil_load
|
def test_nil_load
|
||||||
|
@ -9,8 +9,8 @@ module Risc
|
|||||||
@input = "unless(@a) ; arg = 5 ; end;return"
|
@input = "unless(@a) ; arg = 5 ; end;return"
|
||||||
@expect = [SlotToReg, SlotToReg, LoadConstant, OperatorInstruction, IsZero, #4
|
@expect = [SlotToReg, SlotToReg, LoadConstant, OperatorInstruction, IsZero, #4
|
||||||
LoadConstant, OperatorInstruction, IsZero, Label, Branch, #9
|
LoadConstant, OperatorInstruction, IsZero, Label, Branch, #9
|
||||||
Label, LoadConstant, SlotToReg, RegToSlot, Label, LoadConstant, #34
|
Label, LoadConstant, RegToSlot, Label, LoadConstant, #14
|
||||||
RegToSlot, Branch] #14
|
RegToSlot, Branch] #19
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_if_instructions
|
def test_if_instructions
|
||||||
@ -50,7 +50,8 @@ module Risc
|
|||||||
end
|
end
|
||||||
def test_merge_label
|
def test_merge_label
|
||||||
produced = produce_body
|
produced = produce_body
|
||||||
assert produced.next(14).name.start_with?("merge_label")
|
assert_equal Label , produced.next(13).class
|
||||||
|
assert produced.next(13).name.start_with?("merge_label")
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -7,14 +7,14 @@ module Risc
|
|||||||
def setup
|
def setup
|
||||||
super
|
super
|
||||||
@input = "while(5 > 0) ; @a = true; end;return"
|
@input = "while(5 > 0) ; @a = true; end;return"
|
||||||
@expect = [Label, LoadConstant, LoadConstant, SlotToReg, SlotToReg, #4
|
@expect = [Label, LoadConstant, LoadConstant, SlotToReg, SlotToReg, #4
|
||||||
RegToSlot, RegToSlot, RegToSlot, RegToSlot, LoadConstant, #9
|
RegToSlot, RegToSlot, RegToSlot, RegToSlot, LoadConstant, #9
|
||||||
SlotToReg, RegToSlot, LoadConstant, SlotToReg, SlotToReg, #14
|
SlotToReg, RegToSlot, LoadConstant, SlotToReg, RegToSlot, #14
|
||||||
RegToSlot, LoadConstant, SlotToReg, RegToSlot, SlotToReg, #19
|
LoadConstant, SlotToReg, RegToSlot, SlotToReg, FunctionCall, #19
|
||||||
FunctionCall, Label, SlotToReg, LoadConstant, OperatorInstruction, #24
|
Label, SlotToReg, LoadConstant, OperatorInstruction, IsZero, #24
|
||||||
IsZero, LoadConstant, OperatorInstruction, IsZero, LoadConstant, #29
|
LoadConstant, OperatorInstruction, IsZero, LoadConstant, SlotToReg, #29
|
||||||
SlotToReg, RegToSlot, Branch, Label, LoadConstant, #34
|
RegToSlot, Branch, Label, LoadConstant, RegToSlot, #34
|
||||||
RegToSlot, Branch] #34
|
Branch] #39
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_while_instructions
|
def test_while_instructions
|
||||||
@ -39,19 +39,19 @@ module Risc
|
|||||||
end
|
end
|
||||||
def test_false_check
|
def test_false_check
|
||||||
produced = produce_body
|
produced = produce_body
|
||||||
assert_equal Risc::IsZero , produced.next(25).class
|
assert_equal Risc::IsZero , produced.next(24).class
|
||||||
assert produced.next(25).label.name.start_with?("merge_label") , produced.next(25).label.name
|
assert produced.next(24).label.name.start_with?("merge_label") , produced.next(24).label.name
|
||||||
end
|
end
|
||||||
def test_nil_load
|
def test_nil_load
|
||||||
produced = produce_body
|
produced = produce_body
|
||||||
assert_equal Risc::LoadConstant , produced.next(29).class
|
assert_equal Risc::LoadConstant , produced.next(28).class
|
||||||
assert_equal Parfait::TrueClass , produced.next(29).constant.class
|
assert_equal Parfait::TrueClass , produced.next(28).constant.class
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_back_jump # should jump back to condition label
|
def test_back_jump # should jump back to condition label
|
||||||
produced = produce_body
|
produced = produce_body
|
||||||
assert_equal Risc::Branch , produced.next(32).class
|
assert_equal Risc::Branch , produced.next(31).class
|
||||||
assert_equal produced.name , produced.next(32).label.name
|
assert_equal produced.name , produced.next(31).label.name
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user