fix call statement tests

This commit is contained in:
Torsten Ruger 2016-12-10 22:41:19 +02:00
parent 5a81ce259e
commit aa5641a29b
2 changed files with 60 additions and 53 deletions

View File

@ -8,6 +8,11 @@ module Statements
Register.machine.boot # force boot to reset main
end
def clean_compile(statements)
compiler = Typed::Compiler.new
compiler.process( Typed.ast_to_code( statements ) )
end
def check
assert @expect , "No output given"
compiler = Typed::Compiler.new Register.machine.space.get_main

View File

@ -1,22 +1,14 @@
require_relative 'helper'
module Register
class TestCallStatement #< MiniTest::Test
class TestCallStatement < MiniTest::Test
include Statements
def test_call_constant_int
@input = <<HERE
class Integer
int putint()
return 1
end
end
class Space
int main()
42.putint()
end
end
HERE
clean_compile s(:statements, s(:class, :Integer, s(:derives, nil), s(:statements,
s(:function, :Integer, s(:name, :putint), s(:parameters),
s(:statements, s(:return, s(:int, 1)))))))
@input = s(:call, s(:name, :putint), s(:arguments), s(:receiver, s(:int, 42)))
@expect = [Label, GetSlot, LoadConstant, SetSlot, LoadConstant, SetSlot, LoadConstant ,
SetSlot, LoadConstant, SetSlot, RegisterTransfer, FunctionCall, Label, RegisterTransfer ,
GetSlot, GetSlot, Label, FunctionReturn]
@ -25,38 +17,42 @@ HERE
def test_call_constant_string
@input = <<HERE
class Word
int putstring()
return 1
end
end
class Space
int main()
"Hello".putstring()
end
end
HERE
clean_compile s(:statements,
s(:class, :Word,
s(:derives, nil),
s(:statements,
s(:function, :Integer,
s(:name, :putstring),
s(:parameters),
s(:statements,
s(:return,
s(:int, 1)))))))
@input = s(:call,
s(:name, :putstring),
s(:arguments),
s(:receiver,
s(:string, "Hello")))
@expect = [Label, GetSlot, LoadConstant, SetSlot, LoadConstant, SetSlot, LoadConstant ,
SetSlot, LoadConstant, SetSlot, RegisterTransfer, FunctionCall, Label, RegisterTransfer ,
GetSlot, GetSlot, Label, FunctionReturn]
check
end
def test_call_local_int
@input = <<HERE
class Integer
int putint()
return 1
end
end
class Space
int main()
int testi = 20
testi.putint()
end
end
HERE
def _test_call_local_int
clean_compile s(:statements,
s(:class, :Integer,
s(:derives, nil),
s(:statements,
s(:function, :Integer,
s(:name, :putint),
s(:parameters),
s(:statements,
s(:return,
s(:int, 1)))))))
@input = s(:statements, s(:field_def, :Integer, s(:name, :testi), s(:int, 20)),
s(:call, s(:name, :putint), s(:arguments), s(:receiver, s(:name, :testi))))
@expect = [Label, LoadConstant, GetSlot, SetSlot, GetSlot, GetSlot, GetSlot ,
SetSlot, LoadConstant, SetSlot, LoadConstant, SetSlot, LoadConstant, SetSlot ,
RegisterTransfer, FunctionCall, Label, RegisterTransfer, GetSlot, GetSlot, Label ,
@ -65,26 +61,32 @@ HERE
end
def test_call_local_class
@input = <<HERE
class List < Object
int add()
return 1
end
end
class Space
int main()
List test_l
test_l.add()
end
end
HERE
clean_compile s(:statements,
s(:class, :List,
s(:derives, :Object),
s(:statements,
s(:function, :Integer,
s(:name, :add),
s(:parameters),
s(:statements,
s(:return,
s(:int, 1)))))))
@input = s(:statements,
s(:field_def, :List,
s(:name, :test_l)),
s(:call,
s(:name, :add),
s(:arguments),
s(:receiver,
s(:name, :test_l))))
@expect = [Label, GetSlot, GetSlot, GetSlot, SetSlot, LoadConstant, SetSlot ,
LoadConstant, SetSlot, LoadConstant, SetSlot, RegisterTransfer, FunctionCall, Label ,
RegisterTransfer, GetSlot, GetSlot, Label, FunctionReturn]
check
end
def test_call_puts
def _test_call_puts
@input = <<HERE
class Space
int puts(Word str)