2015-10-16 12:20:21 +02:00
|
|
|
require_relative 'helper'
|
|
|
|
|
|
|
|
module Register
|
|
|
|
class TestCallStatement < MiniTest::Test
|
|
|
|
include Statements
|
|
|
|
|
|
|
|
def test_call_constant_int
|
|
|
|
@string_input = <<HERE
|
2015-10-16 16:17:39 +02:00
|
|
|
class Integer
|
|
|
|
int putint()
|
|
|
|
return 1
|
|
|
|
end
|
|
|
|
end
|
2015-10-16 12:20:21 +02:00
|
|
|
class Object
|
|
|
|
int main()
|
|
|
|
42.putint()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
HERE
|
2015-11-03 10:25:02 +01:00
|
|
|
@expect = [Label, GetSlot, LoadConstant, SetSlot, LoadConstant, SetSlot, LoadConstant ,
|
2015-11-07 21:20:21 +01:00
|
|
|
SetSlot, LoadConstant, SetSlot, RegisterTransfer, FunctionCall, Label, RegisterTransfer ,
|
|
|
|
GetSlot, GetSlot, Label, FunctionReturn]
|
2015-10-16 12:20:21 +02:00
|
|
|
check
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def test_call_constant_string
|
|
|
|
@string_input = <<HERE
|
2015-10-16 16:58:07 +02:00
|
|
|
class Word
|
|
|
|
int putstring()
|
|
|
|
return 1
|
|
|
|
end
|
|
|
|
end
|
2015-10-16 12:20:21 +02:00
|
|
|
class Object
|
|
|
|
int main()
|
|
|
|
"Hello".putstring()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
HERE
|
2015-11-03 10:25:02 +01:00
|
|
|
@expect = [Label, GetSlot, LoadConstant, SetSlot, LoadConstant, SetSlot, LoadConstant ,
|
2015-11-07 21:20:21 +01:00
|
|
|
SetSlot, LoadConstant, SetSlot, RegisterTransfer, FunctionCall, Label, RegisterTransfer ,
|
|
|
|
GetSlot, GetSlot, Label, FunctionReturn]
|
2015-10-16 12:20:21 +02:00
|
|
|
check
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_call_local_int
|
|
|
|
@string_input = <<HERE
|
2015-10-16 16:13:08 +02:00
|
|
|
class Integer
|
2015-10-16 16:17:39 +02:00
|
|
|
int putint()
|
2015-10-16 16:13:08 +02:00
|
|
|
return 1
|
|
|
|
end
|
|
|
|
end
|
2015-10-16 12:20:21 +02:00
|
|
|
class Object
|
|
|
|
int main()
|
|
|
|
int testi = 20
|
|
|
|
testi.putint()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
HERE
|
2015-11-03 10:25:02 +01:00
|
|
|
@expect = [Label, LoadConstant, GetSlot, SetSlot, GetSlot, GetSlot, GetSlot ,
|
|
|
|
SetSlot, LoadConstant, SetSlot, LoadConstant, SetSlot, LoadConstant, SetSlot ,
|
2015-11-07 21:20:21 +01:00
|
|
|
RegisterTransfer, FunctionCall, Label, RegisterTransfer, GetSlot, GetSlot, Label ,
|
2015-11-03 10:25:02 +01:00
|
|
|
FunctionReturn]
|
2015-10-16 12:20:21 +02:00
|
|
|
check
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_call_local_class
|
|
|
|
@string_input = <<HERE
|
|
|
|
class List < Object
|
|
|
|
int add()
|
|
|
|
return 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
class Object
|
|
|
|
int main()
|
|
|
|
List test_l
|
|
|
|
test_l.add()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
HERE
|
2015-11-03 10:25:02 +01:00
|
|
|
@expect = [Label, GetSlot, GetSlot, GetSlot, SetSlot, LoadConstant, SetSlot ,
|
|
|
|
LoadConstant, SetSlot, LoadConstant, SetSlot, RegisterTransfer, FunctionCall, Label ,
|
2015-11-07 21:20:21 +01:00
|
|
|
RegisterTransfer, GetSlot, GetSlot, Label, FunctionReturn]
|
2015-10-16 12:20:21 +02:00
|
|
|
check
|
|
|
|
end
|
|
|
|
|
2015-10-18 16:20:19 +02:00
|
|
|
def test_call_puts
|
2015-10-16 12:20:21 +02:00
|
|
|
@string_input = <<HERE
|
|
|
|
class Object
|
|
|
|
int puts(Word str)
|
|
|
|
return str
|
|
|
|
end
|
|
|
|
int main()
|
|
|
|
puts("Hello")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
HERE
|
2015-11-03 10:25:02 +01:00
|
|
|
@expect = [Label, GetSlot, GetSlot, SetSlot, LoadConstant, SetSlot, LoadConstant ,
|
|
|
|
SetSlot, LoadConstant, SetSlot, LoadConstant, SetSlot, RegisterTransfer, FunctionCall ,
|
2015-11-07 21:20:21 +01:00
|
|
|
Label, RegisterTransfer, GetSlot, GetSlot, Label, FunctionReturn]
|
2015-10-22 10:32:37 +02:00
|
|
|
was = check
|
2015-11-02 19:12:01 +01:00
|
|
|
set = was.next(7)
|
2015-10-22 10:32:37 +02:00
|
|
|
assert_equal SetSlot , set.class
|
2015-10-27 15:21:11 +01:00
|
|
|
assert_equal 9, set.index , "Set to message must be offset, not #{set.index}"
|
2015-10-16 12:20:21 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|