2015-11-08 12:39:13 +01:00
|
|
|
require_relative 'helper'
|
|
|
|
|
|
|
|
|
2017-01-19 08:02:29 +01:00
|
|
|
module Risc
|
2016-12-10 21:48:55 +01:00
|
|
|
class TestFieldStatement < MiniTest::Test
|
2015-11-08 12:39:13 +01:00
|
|
|
include Statements
|
|
|
|
|
2016-12-21 17:51:22 +01:00
|
|
|
def test_field_named_list
|
2016-12-30 13:10:49 +01:00
|
|
|
Parfait.object_space.get_main.add_local( :m , :Message)
|
2016-12-17 12:12:49 +01:00
|
|
|
@input = s(:statements, s(:return, s(:field_access,
|
2017-01-16 08:34:47 +01:00
|
|
|
s(:receiver, s(:local, :m)), s(:field, s(:ivar, :name)))))
|
2017-01-04 20:38:38 +01:00
|
|
|
@expect = [Label, SlotToReg, SlotToReg, SlotToReg, RegToSlot, LoadConstant ,
|
|
|
|
SlotToReg, RegToSlot, Label, FunctionReturn]
|
|
|
|
assert_nil msg = check_nil , msg
|
2015-11-08 12:39:13 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_field_arg
|
2016-12-30 13:10:49 +01:00
|
|
|
Parfait.object_space.get_main.add_local( :m , :Message)
|
2016-12-16 18:05:49 +01:00
|
|
|
clean_compile :Space, :get_name, { :main => :Message},
|
2016-12-13 17:48:42 +01:00
|
|
|
s(:statements, s(:return, s(:field_access,
|
2017-01-16 08:34:47 +01:00
|
|
|
s(:receiver, s(:arg, :main)), s(:field, s(:ivar, :name)))))
|
|
|
|
@input =s(:statements, s(:return, s(:call, :get_name, s(:arguments, s(:local, :m)))))
|
2016-12-10 21:48:55 +01:00
|
|
|
|
2017-01-04 20:38:38 +01:00
|
|
|
@expect = [Label, SlotToReg, SlotToReg, RegToSlot, LoadConstant, RegToSlot ,
|
|
|
|
LoadConstant, SlotToReg, RegToSlot, SlotToReg, SlotToReg, SlotToReg ,
|
2017-01-19 08:02:29 +01:00
|
|
|
RegToSlot, LoadConstant, RegToSlot, RiscTransfer, FunctionCall, Label ,
|
|
|
|
RiscTransfer, SlotToReg, SlotToReg, RegToSlot, LoadConstant, SlotToReg ,
|
2017-01-04 20:38:38 +01:00
|
|
|
RegToSlot, Label, FunctionReturn]
|
|
|
|
assert_nil msg = check_nil , msg
|
2015-11-08 12:39:13 +01:00
|
|
|
end
|
2015-11-08 12:55:38 +01:00
|
|
|
|
|
|
|
def test_message_field
|
2016-12-30 13:10:49 +01:00
|
|
|
Parfait.object_space.get_main.add_local(:name , :Word)
|
2017-01-16 08:34:47 +01:00
|
|
|
@input = s(:statements, s(:l_assignment, s(:local, :name), s(:field_access, s(:receiver, s(:known, :message)), s(:field, s(:ivar, :name)))), s(:return, s(:local, :name)))
|
2016-12-10 21:48:55 +01:00
|
|
|
|
2017-01-19 08:02:29 +01:00
|
|
|
@expect = [Label, RiscTransfer, SlotToReg, SlotToReg, RegToSlot, SlotToReg ,
|
2017-01-04 20:38:38 +01:00
|
|
|
SlotToReg, RegToSlot, LoadConstant, SlotToReg, RegToSlot, Label ,
|
|
|
|
FunctionReturn]
|
|
|
|
assert_nil msg = check_nil , msg
|
2015-11-08 12:55:38 +01:00
|
|
|
end
|
2015-11-08 12:39:13 +01:00
|
|
|
end
|
|
|
|
end
|