2015-10-16 12:20:21 +02:00
|
|
|
require_relative 'helper'
|
2017-01-03 21:32:34 +01:00
|
|
|
require_relative "test_call_expression"
|
2015-10-16 12:20:21 +02:00
|
|
|
|
2017-01-19 08:02:29 +01:00
|
|
|
module Risc
|
2017-01-03 21:37:25 +01:00
|
|
|
class TestCallStatement < MiniTest::Test
|
|
|
|
include Statements
|
2015-10-16 12:20:21 +02:00
|
|
|
|
2017-01-03 21:37:25 +01:00
|
|
|
def test_call_constant_int
|
|
|
|
clean_compile :Integer, :puti, {}, s(:statements, s(:return, s(:int, 1)))
|
2017-01-16 08:34:47 +01:00
|
|
|
@input = s(:call, :puti , s(:arguments), s(:receiver, s(:int, 42)))
|
2017-01-03 21:37:25 +01:00
|
|
|
@expect = [Label, SlotToReg, LoadConstant, RegToSlot, LoadConstant, RegToSlot, LoadConstant ,
|
2017-01-19 08:02:29 +01:00
|
|
|
SlotToReg, RegToSlot, LoadConstant, RegToSlot, RiscTransfer, FunctionCall, Label ,
|
|
|
|
RiscTransfer, SlotToReg, SlotToReg, LoadConstant, SlotToReg, RegToSlot, Label ,
|
2017-01-04 20:38:38 +01:00
|
|
|
FunctionReturn]
|
|
|
|
assert_nil msg = check_nil , msg
|
2017-01-03 21:37:25 +01:00
|
|
|
end
|
2015-10-16 12:20:21 +02:00
|
|
|
|
|
|
|
|
2017-01-03 21:37:25 +01:00
|
|
|
def test_call_constant_string
|
|
|
|
clean_compile :Word, :putstr,{}, s(:statements, s(:return, s(:int, 1)))
|
2016-12-10 21:41:19 +01:00
|
|
|
|
2017-01-16 08:34:47 +01:00
|
|
|
@input =s(:call, :putstr, s(:arguments), s(:receiver, s(:string, "Hello")))
|
2017-01-04 20:38:38 +01:00
|
|
|
@expect = [Label, SlotToReg, LoadConstant, RegToSlot, LoadConstant, RegToSlot, LoadConstant ,
|
2017-01-19 08:02:29 +01:00
|
|
|
SlotToReg, RegToSlot, LoadConstant, RegToSlot, RiscTransfer, FunctionCall, Label ,
|
|
|
|
RiscTransfer, SlotToReg, SlotToReg, LoadConstant, SlotToReg, RegToSlot, Label ,
|
2017-01-04 20:38:38 +01:00
|
|
|
FunctionReturn]
|
|
|
|
assert_nil msg = check_nil , msg
|
2017-01-03 21:37:25 +01:00
|
|
|
end
|
2015-10-16 12:20:21 +02:00
|
|
|
|
2017-01-04 20:38:38 +01:00
|
|
|
def test_call_local_int
|
2017-01-03 21:37:25 +01:00
|
|
|
Parfait.object_space.get_main.add_local(:testi , :Integer)
|
|
|
|
clean_compile :Integer, :putint, {}, s(:statements, s(:return, s(:int, 1)))
|
2017-01-16 08:34:47 +01:00
|
|
|
@input = s(:statements, s(:l_assignment, s(:local, :testi), s(:int, 20)), s(:call, :putint, s(:arguments), s(:receiver, s(:local, :testi))))
|
2016-12-10 21:41:19 +01:00
|
|
|
|
2017-01-03 21:37:25 +01:00
|
|
|
@expect = [Label, LoadConstant, SlotToReg, RegToSlot, SlotToReg, SlotToReg, SlotToReg ,
|
2017-01-04 20:38:38 +01:00
|
|
|
RegToSlot, LoadConstant, RegToSlot, LoadConstant, SlotToReg, RegToSlot, LoadConstant ,
|
2017-01-19 08:02:29 +01:00
|
|
|
RegToSlot, RiscTransfer, FunctionCall, Label, RiscTransfer, SlotToReg, SlotToReg ,
|
2017-01-04 20:38:38 +01:00
|
|
|
LoadConstant, SlotToReg, RegToSlot, Label, FunctionReturn]
|
|
|
|
assert_nil msg = check_nil , msg
|
2017-01-03 21:37:25 +01:00
|
|
|
end
|
2015-10-16 12:20:21 +02:00
|
|
|
|
2017-01-03 21:37:25 +01:00
|
|
|
def test_call_local_class
|
|
|
|
Parfait.object_space.get_main.add_local(:test_l , :List)
|
|
|
|
clean_compile :List, :add, {}, s(:statements, s(:return, s(:int, 1)))
|
2016-12-10 21:41:19 +01:00
|
|
|
|
2017-01-16 08:34:47 +01:00
|
|
|
@input =s(:statements, s(:call, :add, s(:arguments), s(:receiver, s(:local, :test_l))))
|
2017-01-04 20:38:38 +01:00
|
|
|
@expect = [Label, SlotToReg, SlotToReg, SlotToReg, RegToSlot, LoadConstant, RegToSlot ,
|
2017-01-19 08:02:29 +01:00
|
|
|
LoadConstant, SlotToReg, RegToSlot, LoadConstant, RegToSlot, RiscTransfer, FunctionCall ,
|
|
|
|
Label, RiscTransfer, SlotToReg, SlotToReg, LoadConstant, SlotToReg, RegToSlot ,
|
2017-01-04 20:38:38 +01:00
|
|
|
Label, FunctionReturn]
|
|
|
|
assert_nil msg = check_nil , msg
|
2017-01-03 21:37:25 +01:00
|
|
|
end
|
2015-10-16 12:20:21 +02:00
|
|
|
|
2017-01-04 20:38:38 +01:00
|
|
|
def test_call_puts
|
2017-01-16 08:34:47 +01:00
|
|
|
clean_compile :Space, :putstr, {str: :Word}, s(:statements, s(:return, s(:arg, :str)))
|
|
|
|
@input =s(:call, :putstr , s(:arguments, s(:string, "Hello") ) )
|
2017-01-04 20:38:38 +01:00
|
|
|
@expect = [Label, SlotToReg, SlotToReg, RegToSlot, LoadConstant, RegToSlot ,
|
|
|
|
LoadConstant, SlotToReg, RegToSlot, LoadConstant, SlotToReg, RegToSlot ,
|
2017-01-19 08:02:29 +01:00
|
|
|
LoadConstant, RegToSlot, RiscTransfer, FunctionCall, Label, RiscTransfer ,
|
2017-01-04 20:38:38 +01:00
|
|
|
SlotToReg, SlotToReg, LoadConstant, SlotToReg, RegToSlot, Label ,
|
|
|
|
FunctionReturn]
|
|
|
|
was = check_return
|
|
|
|
set = was.next(8)
|
2017-01-03 21:37:25 +01:00
|
|
|
assert_equal RegToSlot , set.class
|
2017-01-04 20:38:38 +01:00
|
|
|
assert_equal 1, set.index , "Set to message must be offset, not #{set.index}"
|
2017-01-03 21:37:25 +01:00
|
|
|
end
|
2015-10-16 12:20:21 +02:00
|
|
|
end
|
|
|
|
end
|