arg assignment test (could be better)
This commit is contained in:
parent
dda2ff9049
commit
483a7c4467
27
test/mom/test_assign_arg_const.rb
Normal file
27
test/mom/test_assign_arg_const.rb
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
require_relative 'helper'
|
||||||
|
|
||||||
|
module Risc
|
||||||
|
class TestAssignArgConst < MiniTest::Test
|
||||||
|
include Statements
|
||||||
|
|
||||||
|
def setup
|
||||||
|
super
|
||||||
|
@input = "arg = 5"
|
||||||
|
@expect = [LoadConstant, RegToSlot]
|
||||||
|
end
|
||||||
|
def test_local_assign_instructions
|
||||||
|
assert_nil msg = check_nil , msg
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_constant_load
|
||||||
|
produced = produce_body
|
||||||
|
assert_equal 5 , produced.constant.known_object.value
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_slot_move
|
||||||
|
produced = produce_body
|
||||||
|
assert_equal produced.next.register , produced.register
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
22
test/mom/test_assign_local_arg.rb
Normal file
22
test/mom/test_assign_local_arg.rb
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
require_relative 'helper'
|
||||||
|
|
||||||
|
module Risc
|
||||||
|
class TestAssignLocalArg < MiniTest::Test
|
||||||
|
include Statements
|
||||||
|
|
||||||
|
def setup
|
||||||
|
super
|
||||||
|
@input = "local = arg"
|
||||||
|
@expect = [SlotToReg, SlotToReg, RegToSlot]
|
||||||
|
end
|
||||||
|
def test_local_assign_instructions
|
||||||
|
assert_nil msg = check_nil , msg
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_slot_move
|
||||||
|
produced = produce_body
|
||||||
|
assert_equal produced.next.next.register , produced.register
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
@ -1,89 +0,0 @@
|
|||||||
require_relative 'helper'
|
|
||||||
|
|
||||||
module Risc
|
|
||||||
class TestAssignStatement < MiniTest::Test
|
|
||||||
include Statements
|
|
||||||
|
|
||||||
def pest_assign_op
|
|
||||||
Parfait.object_space.get_main.add_local(:r , :Integer)
|
|
||||||
@input = "r = 10.mod4"
|
|
||||||
@expect = [Label, Label, Label, Label, Label]
|
|
||||||
assert_nil msg = check_nil , msg
|
|
||||||
end
|
|
||||||
|
|
||||||
def pest_assign_ivar
|
|
||||||
@input = "@r = 5"
|
|
||||||
@expect = [Label]
|
|
||||||
assert_nil msg = check_nil , msg
|
|
||||||
end
|
|
||||||
|
|
||||||
def pest_assign_call
|
|
||||||
Parfait.object_space.get_main.add_local(:r , :Object)
|
|
||||||
@input = s(:statements, s(:l_assignment, s(:local, :r), s(:call, :main, s(:arguments))))
|
|
||||||
@expect = [Label, SlotToReg, SlotToReg, RegToSlot, LoadConstant, RegToSlot ,
|
|
||||||
LoadConstant, SlotToReg, RegToSlot, LoadConstant, RegToSlot, RiscTransfer ,
|
|
||||||
FunctionCall, Label, RiscTransfer, SlotToReg, SlotToReg, SlotToReg ,
|
|
||||||
RegToSlot, LoadConstant, SlotToReg, RegToSlot, Label, FunctionReturn]
|
|
||||||
assert_nil msg = check_nil , msg
|
|
||||||
end
|
|
||||||
|
|
||||||
def pest_named_list_get
|
|
||||||
Parfait.object_space.get_main.add_local(:r , :Integer)
|
|
||||||
@input = s(:statements, s(:l_assignment, s(:local, :r), s(:int, 5)), s(:return, s(:local, :r)))
|
|
||||||
@expect = [Label, LoadConstant, SlotToReg, RegToSlot, SlotToReg, SlotToReg ,
|
|
||||||
RegToSlot, LoadConstant, SlotToReg, RegToSlot, Label, FunctionReturn]
|
|
||||||
was = check_return
|
|
||||||
get = was.next(5)
|
|
||||||
assert_equal SlotToReg , get.class
|
|
||||||
assert_equal 1 + 1, get.index , "Get to named_list index must be offset, not #{get.index}"
|
|
||||||
end
|
|
||||||
|
|
||||||
def pest_assign_local_int
|
|
||||||
Parfait.object_space.get_main.add_local(:r , :Integer)
|
|
||||||
@input = s(:statements, s(:l_assignment, s(:local, :r), s(:int, 5)) )
|
|
||||||
@expect = [Label, LoadConstant, SlotToReg, RegToSlot, LoadConstant, SlotToReg ,
|
|
||||||
RegToSlot, Label, FunctionReturn]
|
|
||||||
was = check_return
|
|
||||||
set = was.next(3)
|
|
||||||
assert_equal RegToSlot , set.class
|
|
||||||
assert_equal 1 + 1, set.index , "Set to named_list index must be offset, not #{set.index}"
|
|
||||||
end
|
|
||||||
|
|
||||||
def pest_misassign_local
|
|
||||||
Parfait.object_space.get_main.add_local(:r , :Integer)
|
|
||||||
@input = s(:statements, s(:l_assignment, s(:local, :r), s(:string, "5")) )
|
|
||||||
@expect = [Label, LoadConstant, SlotToReg, RegToSlot, Label, FunctionReturn]
|
|
||||||
assert_raises {check }
|
|
||||||
end
|
|
||||||
|
|
||||||
def pest_assign_arg
|
|
||||||
Parfait.object_space.get_main.add_argument(:blar , :Integer)
|
|
||||||
@input = s(:statements, s(:a_assignment, s(:arg, :blar), s(:int, 5)))
|
|
||||||
@expect = [Label, LoadConstant, SlotToReg, RegToSlot, LoadConstant, SlotToReg ,
|
|
||||||
RegToSlot, Label, FunctionReturn]
|
|
||||||
was = check_return
|
|
||||||
set = was.next(3)
|
|
||||||
assert_equal RegToSlot , set.class
|
|
||||||
assert_equal 1 + 1, set.index , "Set to args index must be offset, not #{set.index}"
|
|
||||||
end
|
|
||||||
|
|
||||||
def pest_misassign_arg
|
|
||||||
Parfait.object_space.get_main.add_argument(:blar , :Integer)
|
|
||||||
@input = s(:statements, s(:a_assignment, s(:arg, :blar), s(:string, "5")))
|
|
||||||
@expect = [Label, LoadConstant, SlotToReg, RegToSlot, Label, FunctionReturn]
|
|
||||||
assert_raises {check }
|
|
||||||
end
|
|
||||||
|
|
||||||
def pest_arg_get
|
|
||||||
# have to define bar externally, just because redefining main. Otherwise that would be automatic
|
|
||||||
Parfait.object_space.get_main.add_argument(:balr , :Integer)
|
|
||||||
@input = s(:statements, s(:return, s(:arg, :balr)))
|
|
||||||
@expect = [Label, SlotToReg, SlotToReg, RegToSlot, LoadConstant, SlotToReg ,
|
|
||||||
RegToSlot, Label, FunctionReturn]
|
|
||||||
was = check_return
|
|
||||||
get = was.next(2)
|
|
||||||
assert_equal SlotToReg , get.class
|
|
||||||
assert_equal 1 + 1, get.index , "Get to args index must be offset, not #{get.index}"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
Loading…
Reference in New Issue
Block a user