fix field access tests

This commit is contained in:
Torsten Ruger 2016-12-10 22:48:55 +02:00
parent 17cb917104
commit 5a1a42cd48

View File

@ -2,34 +2,50 @@ require_relative 'helper'
module Register module Register
class TestFieldStatement #< MiniTest::Test class TestFieldStatement < MiniTest::Test
include Statements include Statements
def test_field_frame def test_field_frame
@input = <<HERE @input = s(:statements,
class Space s(:field_def, :Message,
int main() s(:name, :m)),
Message m s(:return,
return m.name s(:field_access,
end s(:receiver,
end s(:name, :m)),
HERE s(:field,
s(:name, :name)))))
@expect = [Label, GetSlot, GetSlot, GetSlot, SetSlot, Label, FunctionReturn] @expect = [Label, GetSlot, GetSlot, GetSlot, SetSlot, Label, FunctionReturn]
check check
end end
def test_field_arg def test_field_arg
@input = <<HERE clean_compile s(:statements,
class Space s(:class, :Space,
int get_name(Message main) s(:derives, nil),
return main.name s(:statements,
end s(:function, :Integer,
int main() s(:name, :get_name),
Message m s(:parameters,
return get_name(m) s(:parameter, :Message, :main)),
end s(:statements,
end s(:return,
HERE s(:field_access,
s(:receiver,
s(:name, :main)),
s(:field,
s(:name, :name)))))))))
@input = s(:statements,
s(:field_def, :Message,
s(:name, :m)),
s(:return,
s(:call,
s(:name, :get_name),
s(:arguments,
s(:name, :m)))))
@expect = [Label, GetSlot, GetSlot, SetSlot, LoadConstant, SetSlot, LoadConstant , @expect = [Label, GetSlot, GetSlot, SetSlot, LoadConstant, SetSlot, LoadConstant ,
SetSlot, GetSlot, GetSlot, SetSlot, LoadConstant, SetSlot, RegisterTransfer , SetSlot, GetSlot, GetSlot, SetSlot, LoadConstant, SetSlot, RegisterTransfer ,
FunctionCall, Label, RegisterTransfer, GetSlot, GetSlot, SetSlot, Label , FunctionCall, Label, RegisterTransfer, GetSlot, GetSlot, SetSlot, Label ,
@ -38,28 +54,34 @@ HERE
end end
def test_self_field def test_self_field
@input = <<HERE @input = s(:statements,
class Space s(:field_def, :Type,
int main() s(:name, :l),
Type l = self.type s(:field_access,
return 1 s(:receiver,
end s(:name, :self)),
end s(:field,
HERE s(:name, :type)))),
s(:return,
s(:int, 1)))
@expect = [Label, GetSlot, GetSlot, GetSlot, SetSlot, LoadConstant, SetSlot , @expect = [Label, GetSlot, GetSlot, GetSlot, SetSlot, LoadConstant, SetSlot ,
Label, FunctionReturn] Label, FunctionReturn]
check check
end end
def test_message_field def test_message_field
@input = <<HERE @input = s(:statements,
class Space s(:field_def, :Word,
int main() s(:name, :name),
Word name = message.name s(:field_access,
return name s(:receiver,
end s(:name, :message)),
end s(:field,
HERE s(:name, :name)))),
s(:return,
s(:name, :name)))
@expect = [Label, RegisterTransfer, GetSlot, GetSlot, SetSlot, GetSlot, GetSlot , @expect = [Label, RegisterTransfer, GetSlot, GetSlot, SetSlot, GetSlot, GetSlot ,
SetSlot, Label, FunctionReturn] SetSlot, Label, FunctionReturn]
check check