2015-10-15 12:08:53 +02:00
|
|
|
require_relative 'helper'
|
|
|
|
|
|
|
|
module Register
|
|
|
|
class TestAssignStatement < MiniTest::Test
|
|
|
|
include Statements
|
|
|
|
|
|
|
|
def setup
|
|
|
|
Virtual.machine.boot
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_assign_arg
|
|
|
|
Virtual.machine.space.get_main.arguments.push Parfait::Variable.new(:Integer , :bar)
|
|
|
|
@string_input = <<HERE
|
|
|
|
class Object
|
|
|
|
int main(int bar)
|
|
|
|
bar = 5
|
|
|
|
end
|
|
|
|
end
|
|
|
|
HERE
|
2015-10-18 16:39:35 +02:00
|
|
|
@expect = [[SaveReturn,LoadConstant,SetSlot] , [RegisterTransfer,GetSlot,FunctionReturn]]
|
2015-10-15 12:08:53 +02:00
|
|
|
check
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_assign_int
|
|
|
|
@string_input = <<HERE
|
|
|
|
class Object
|
|
|
|
int main()
|
|
|
|
int r = 5
|
|
|
|
end
|
|
|
|
end
|
|
|
|
HERE
|
2015-10-18 16:39:35 +02:00
|
|
|
@expect = [[SaveReturn,LoadConstant,GetSlot,SetSlot] , [RegisterTransfer,GetSlot,FunctionReturn]]
|
2015-10-15 12:08:53 +02:00
|
|
|
check
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_assign_op
|
|
|
|
@string_input = <<HERE
|
|
|
|
class Object
|
|
|
|
int main()
|
|
|
|
int n = 10 + 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
HERE
|
2015-10-18 16:39:35 +02:00
|
|
|
@expect = [[SaveReturn,LoadConstant,LoadConstant,
|
2015-10-18 16:32:32 +02:00
|
|
|
OperatorInstruction,GetSlot,SetSlot],[RegisterTransfer,GetSlot,FunctionReturn]]
|
2015-10-15 12:08:53 +02:00
|
|
|
check
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_assign_local
|
|
|
|
@string_input = <<HERE
|
|
|
|
class Object
|
|
|
|
int main()
|
|
|
|
int runner
|
|
|
|
runner = 5
|
|
|
|
end
|
|
|
|
end
|
|
|
|
HERE
|
2015-10-18 16:39:35 +02:00
|
|
|
@expect = [[SaveReturn,LoadConstant,GetSlot,SetSlot] , [RegisterTransfer,GetSlot,FunctionReturn]]
|
2015-10-15 12:08:53 +02:00
|
|
|
check
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_assign_local_assign
|
|
|
|
@string_input = <<HERE
|
|
|
|
class Object
|
|
|
|
int main()
|
|
|
|
int runner = 5
|
|
|
|
end
|
|
|
|
end
|
|
|
|
HERE
|
2015-10-18 16:39:35 +02:00
|
|
|
@expect = [[SaveReturn,LoadConstant, GetSlot,SetSlot] , [RegisterTransfer,GetSlot,FunctionReturn]]
|
2015-10-15 12:08:53 +02:00
|
|
|
check
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_assign_call
|
|
|
|
@string_input = <<HERE
|
|
|
|
class Object
|
|
|
|
int main()
|
|
|
|
int r = main()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
HERE
|
2015-10-18 16:39:35 +02:00
|
|
|
@expect = [[SaveReturn,GetSlot,GetSlot,SetSlot, LoadConstant,SetSlot,
|
2015-10-18 16:32:32 +02:00
|
|
|
Virtual::MethodCall,GetSlot,GetSlot,SetSlot] , [RegisterTransfer,GetSlot,FunctionReturn]]
|
2015-10-15 12:08:53 +02:00
|
|
|
check
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|