fix scoping of blockcompiler

Was accessing caller scope, but must use caller's caller as the yield itself is a call.
This commit is contained in:
Torsten Ruger 2018-07-31 18:00:42 +03:00
parent 4fe0edd1e3
commit 04bcfea8ce
6 changed files with 80 additions and 36 deletions

View File

@ -39,9 +39,9 @@ module Risc
elsif @callable.frame_type.variable_index(name)
slot_def = [:frame]
elsif @method.arguments_type.variable_index(name)
slot_def = [:caller , :arguments ]
slot_def = [:caller , :caller ,:arguments ]
elsif @method.frame_type.variable_index(name)
slot_def = [:caller , :frame ]
slot_def = [:caller ,:caller , :frame ]
elsif
raise "no variable #{name} , need to resolve at runtime"
end

View File

@ -3,7 +3,6 @@ require_relative "../helper"
module Risc
class TestMessageSetupSimple < MiniTest::Test
include Statements
include Assertions
def setup
super

View File

@ -0,0 +1,63 @@
require_relative "../helper"
module Risc
class BloclAssignOuter < MiniTest::Test
include Ticker
def setup
@string_input = block_main("a = 15 ;yielder {a = 10 ; return 15} ; return a")
super
end
def test_chain
#show_main_ticks # get output of what is
check_main_chain [LoadConstant, SlotToReg, RegToSlot, LoadConstant, SlotToReg,
RegToSlot, LoadConstant, LoadConstant, SlotToReg, RegToSlot,
RegToSlot, SlotToReg, SlotToReg, Branch, RegToSlot,
SlotToReg, SlotToReg, RegToSlot, RegToSlot, SlotToReg,
RegToSlot, SlotToReg, SlotToReg, RegToSlot, SlotToReg,
SlotToReg, SlotToReg, Branch, SlotToReg, RegToSlot,
LoadConstant, SlotToReg, RegToSlot, SlotToReg, FunctionCall,
LoadConstant, SlotToReg, OperatorInstruction, IsZero, SlotToReg,
SlotToReg, LoadConstant, SlotToReg, RegToSlot, RegToSlot,
SlotToReg, SlotToReg, RegToSlot, Branch, SlotToReg,
SlotToReg, RegToSlot, RegToSlot, SlotToReg, RegToSlot,
SlotToReg, SlotToReg, RegToSlot, LoadConstant, SlotToReg,
RegToSlot, SlotToReg, Branch, SlotToReg, SlotToReg,
DynamicJump, LoadConstant, SlotToReg, SlotToReg, SlotToReg,
RegToSlot, LoadConstant, RegToSlot, SlotToReg, SlotToReg,
RegToSlot, SlotToReg, SlotToReg, SlotToReg, Branch,
FunctionReturn, SlotToReg, SlotToReg, RegToSlot, SlotToReg,
SlotToReg, RegToSlot, SlotToReg, SlotToReg, RegToSlot,
SlotToReg, Branch, SlotToReg, SlotToReg, FunctionReturn,
SlotToReg, SlotToReg, RegToSlot, SlotToReg, SlotToReg,
RegToSlot, Branch, SlotToReg, SlotToReg, SlotToReg,
FunctionReturn, Transfer, SlotToReg, SlotToReg, Branch,
Syscall, NilClass]
assert_equal 10 , get_return
end
def test_block_jump
load_ins = main_ticks(66)
assert_equal DynamicJump , load_ins.class
assert_equal Parfait::Block , @interpreter.get_register(load_ins.register).class
end
def test_block_load
load_ins = main_ticks(67)
assert_load load_ins , Parfait::Integer , :r1
assert_equal 10 , @interpreter.get_register(load_ins.register).value
end
def test_block_slot1
assert_slot_to_reg main_ticks(68) ,:r0 , 6 , :r2
end
def test_block_slot2
assert_slot_to_reg main_ticks(69) ,:r2 , 6 , :r2
end
def test_block_slot3
assert_slot_to_reg main_ticks(70) ,:r2 , 3 , :r2
end
def test_block_reg
assert_reg_to_slot main_ticks(71) ,:r1 , :r2 , 1
end
end
end

View File

@ -1,7 +1,7 @@
require_relative "../helper"
module Risc
class BlockAssignLocal < MiniTest::Test
class BlockReturn < MiniTest::Test
include Ticker
def setup
@ -36,36 +36,18 @@ module Risc
assert_equal 15 , get_return
end
def est_call_main
call_ins = ticks(main_at)
assert_equal FunctionCall , call_ins.class
assert :main , call_ins.method.name
end
def est_load_yield
load_ins = main_ticks(4)
def test_load_return
load_ins = main_ticks(56)
assert_equal LoadConstant , load_ins.class
assert_equal Parfait::CallableMethod , @interpreter.get_register(load_ins.register).class
assert_equal :yielder , @interpreter.get_register(load_ins.register).name
end
def est_load_space
load_ins = main_ticks(5)
assert_equal LoadConstant , load_ins.class
assert_equal Parfait::Space , @interpreter.get_register(load_ins.register).class
end
def est_op
op = main_ticks(35)
assert_equal OperatorInstruction , op.class
assert_equal :- , op.operator
end
def est_load_block
load_ins = main_ticks(39)
assert_equal LoadConstant , load_ins.class
assert_equal Parfait::Space , @interpreter.get_register(load_ins.register).class
assert_equal Parfait::ReturnAddress , @interpreter.get_register(load_ins.register).class
end
def test_load_block
load_ins = main_ticks(63)
assert_equal DynamicJump , load_ins.class
assert_equal Parfait::Block , @interpreter.get_register(load_ins.register).class
assert_equal :main_block , @interpreter.get_register(load_ins.register).name
end
def pest_sys
sys = main_ticks(18)
assert_equal Syscall , sys.class
end
end
end

View File

@ -1,19 +1,19 @@
module Risc
module Minitest
module Assertions
def assert_slot_to_reg( slot , array = nil, index = nil , register = nil)
assert_equal SlotToReg , slot.class
assert_equal Risc::SlotToReg , slot.class
assert_equal( array , slot.array.symbol , "wrong source register") if array
assert_equal( index , slot.index, "wrong source index") if index
assert_equal( register , slot.register.symbol, "wrong destination") if register
end
def assert_reg_to_slot( slot , register = nil, array = nil, index = nil )
assert_equal RegToSlot , slot.class
assert_equal Risc::RegToSlot , slot.class
assert_equal( register , slot.register.symbol, "wrong source register") if register
assert_equal( array , slot.array.symbol, "wrong destination register") if array
assert_equal( index , slot.index, "wrong destination index") if index
end
def assert_load(load , clazz = nil , register = nil)
assert_equal LoadConstant , load.class
assert_equal Risc::LoadConstant , load.class
assert_equal( clazz , load.constant.class) if clazz
assert_equal( register , load.register.symbol, "wrong destination register") if register
end

View File

@ -61,7 +61,7 @@ module VoolBlocks
assert @ins.left
end
def test_slots_left
assert_equal [:caller, :arguments, :arg] , @ins.left.slots
assert_equal [:caller,:caller, :arguments, :arg] , @ins.left.slots
end
end