fix field access tests
This commit is contained in:
parent
17cb917104
commit
5a1a42cd48
@ -2,34 +2,50 @@ require_relative 'helper'
|
||||
|
||||
|
||||
module Register
|
||||
class TestFieldStatement #< MiniTest::Test
|
||||
class TestFieldStatement < MiniTest::Test
|
||||
include Statements
|
||||
|
||||
def test_field_frame
|
||||
@input = <<HERE
|
||||
class Space
|
||||
int main()
|
||||
Message m
|
||||
return m.name
|
||||
end
|
||||
end
|
||||
HERE
|
||||
@input = s(:statements,
|
||||
s(:field_def, :Message,
|
||||
s(:name, :m)),
|
||||
s(:return,
|
||||
s(:field_access,
|
||||
s(:receiver,
|
||||
s(:name, :m)),
|
||||
s(:field,
|
||||
s(:name, :name)))))
|
||||
|
||||
@expect = [Label, GetSlot, GetSlot, GetSlot, SetSlot, Label, FunctionReturn]
|
||||
check
|
||||
end
|
||||
|
||||
def test_field_arg
|
||||
@input = <<HERE
|
||||
class Space
|
||||
int get_name(Message main)
|
||||
return main.name
|
||||
end
|
||||
int main()
|
||||
Message m
|
||||
return get_name(m)
|
||||
end
|
||||
end
|
||||
HERE
|
||||
clean_compile s(:statements,
|
||||
s(:class, :Space,
|
||||
s(:derives, nil),
|
||||
s(:statements,
|
||||
s(:function, :Integer,
|
||||
s(:name, :get_name),
|
||||
s(:parameters,
|
||||
s(:parameter, :Message, :main)),
|
||||
s(:statements,
|
||||
s(:return,
|
||||
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 ,
|
||||
SetSlot, GetSlot, GetSlot, SetSlot, LoadConstant, SetSlot, RegisterTransfer ,
|
||||
FunctionCall, Label, RegisterTransfer, GetSlot, GetSlot, SetSlot, Label ,
|
||||
@ -38,28 +54,34 @@ HERE
|
||||
end
|
||||
|
||||
def test_self_field
|
||||
@input = <<HERE
|
||||
class Space
|
||||
int main()
|
||||
Type l = self.type
|
||||
return 1
|
||||
end
|
||||
end
|
||||
HERE
|
||||
@input = s(:statements,
|
||||
s(:field_def, :Type,
|
||||
s(:name, :l),
|
||||
s(:field_access,
|
||||
s(:receiver,
|
||||
s(:name, :self)),
|
||||
s(:field,
|
||||
s(:name, :type)))),
|
||||
s(:return,
|
||||
s(:int, 1)))
|
||||
|
||||
@expect = [Label, GetSlot, GetSlot, GetSlot, SetSlot, LoadConstant, SetSlot ,
|
||||
Label, FunctionReturn]
|
||||
check
|
||||
end
|
||||
|
||||
def test_message_field
|
||||
@input = <<HERE
|
||||
class Space
|
||||
int main()
|
||||
Word name = message.name
|
||||
return name
|
||||
end
|
||||
end
|
||||
HERE
|
||||
@input = s(:statements,
|
||||
s(:field_def, :Word,
|
||||
s(:name, :name),
|
||||
s(:field_access,
|
||||
s(:receiver,
|
||||
s(:name, :message)),
|
||||
s(:field,
|
||||
s(:name, :name)))),
|
||||
s(:return,
|
||||
s(:name, :name)))
|
||||
|
||||
@expect = [Label, RegisterTransfer, GetSlot, GetSlot, SetSlot, GetSlot, GetSlot ,
|
||||
SetSlot, Label, FunctionReturn]
|
||||
check
|
||||
|
Loading…
Reference in New Issue
Block a user