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 Register.machine.boot # force boot to reset main
end end
def clean_compile(statements)
compiler = Typed::Compiler.new
compiler.process( Typed.ast_to_code( statements ) )
end
def check def check
assert @expect , "No output given" assert @expect , "No output given"
compiler = Typed::Compiler.new Register.machine.space.get_main compiler = Typed::Compiler.new Register.machine.space.get_main

View File

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