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

@ -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 pest_sys
sys = main_ticks(18)
assert_equal Syscall , sys.class
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
end
end