put everything into register module (avoid clashes)

This commit is contained in:
Torsten Ruger 2017-01-03 22:37:25 +02:00
parent d94af2a724
commit a14a0de9d1
7 changed files with 318 additions and 314 deletions

View File

@ -1,63 +1,65 @@
require_relative '../helper'
module ExpressionHelper
module Register
module ExpressionHelper
def check
Register.machine.boot unless Register.machine.booted
compiler = Typed::MethodCompiler.new Parfait.object_space.get_main
code = Typed.ast_to_code @input
assert code.to_s , @input
produced = compiler.process( code )
assert @output , "No output given"
assert_equal produced.class , @output , "Wrong class"
produced
end
# test hack to in place change object type
def add_space_field(name,type)
class_type = Parfait.object_space.get_class_by_name(:Space).instance_type
class_type.send(:private_add_instance_variable, name , type)
end
end
module Statements
include AST::Sexp
include Compiling
def setup
Register.machine.boot # force boot to reset main
end
def check
assert @expect , "No output given"
compiler = Typed::MethodCompiler.new
code = Typed.ast_to_code( @input )
assert code.to_s , @input
produced = compiler.process( code )
produced = Parfait.object_space.get_main.instructions
compare_instructions produced , @expect
produced
end
def compare_instructions instruction , expect
index = 0
start = instruction
begin
should = expect[index]
assert should , "No instruction at #{index}"
assert_equal instruction.class , should , "Expected at #{index+1}\n#{should(start)}"
index += 1
instruction = instruction.next
end while( instruction )
end
def should start
str = start.to_ac.to_s
str.gsub!("Register::","")
ret = ""
str.split(",").each_slice(7).each do |line|
ret += " " + line.join(",") + " ,\n"
def check
Register.machine.boot unless Register.machine.booted
compiler = Typed::MethodCompiler.new Parfait.object_space.get_main
code = Typed.ast_to_code @input
assert code.to_s , @input
produced = compiler.process( code )
assert @output , "No output given"
assert_equal produced.class , @output , "Wrong class"
produced
end
# test hack to in place change object type
def add_space_field(name,type)
class_type = Parfait.object_space.get_class_by_name(:Space).instance_type
class_type.send(:private_add_instance_variable, name , type)
end
end
module Statements
include AST::Sexp
include Compiling
def setup
Register.machine.boot # force boot to reset main
end
def check
assert @expect , "No output given"
compiler = Typed::MethodCompiler.new
code = Typed.ast_to_code( @input )
assert code.to_s , @input
produced = compiler.process( code )
produced = Parfait.object_space.get_main.instructions
compare_instructions produced , @expect
produced
end
def compare_instructions instruction , expect
index = 0
start = instruction
begin
should = expect[index]
assert should , "No instruction at #{index}"
assert_equal instruction.class , should , "Expected at #{index+1}\n#{should(start)}"
index += 1
instruction = instruction.next
end while( instruction )
end
def should start
str = start.to_ac.to_s
str.gsub!("Register::","")
ret = ""
str.split(",").each_slice(7).each do |line|
ret += " " + line.join(",") + " ,\n"
end
ret
end
ret
end
end

View File

@ -1,100 +1,100 @@
require_relative 'helper'
module Register
class TestAssignStatement < MiniTest::Test
include Statements
class TestAssignStatement < MiniTest::Test
include Statements
def test_assign_op
Parfait.object_space.get_main.add_local(:r , :Integer)
def test_assign_op
Parfait.object_space.get_main.add_local(:r , :Integer)
@input = s(:statements, s(:assignment, s(:name, :r), s(:operator_value, :+, s(:int, 10), s(:int, 1))))
@input = s(:statements, s(:assignment, s(:name, :r), s(:operator_value, :+, s(:int, 10), s(:int, 1))))
@expect = [Label, LoadConstant, LoadConstant, OperatorInstruction, SlotToReg, RegToSlot, Label ,
FunctionReturn]
check
end
def test_assign_local
Parfait.object_space.get_main.add_local(:r , :Integer)
@input =s(:statements, s(:assignment, s(:name, :r), s(:int, 5)))
@expect = [Label, LoadConstant, SlotToReg, RegToSlot, Label, FunctionReturn]
check
end
def test_assign_local_assign
Parfait.object_space.get_main.add_local(:r , :Integer)
@input = s(:statements, s(:assignment, s(:name, :r), s(:int, 5)))
@expect = [Label, LoadConstant, SlotToReg, RegToSlot, Label, FunctionReturn]
check
end
def test_assign_call
Parfait.object_space.get_main.add_local(:r , :Integer)
@input = s(:statements, s(:assignment, s(:name, :r), s(:call, s(:name, :main), s(:arguments))))
@expect = [Label, SlotToReg, SlotToReg, RegToSlot, LoadConstant, RegToSlot, LoadConstant ,
SlotToReg, SlotToReg, RegToSlot, LoadConstant, RegToSlot, RegisterTransfer, FunctionCall ,
Label, RegisterTransfer, SlotToReg, SlotToReg, SlotToReg, RegToSlot, Label ,
@expect = [Label, LoadConstant, LoadConstant, OperatorInstruction, SlotToReg, RegToSlot, Label ,
FunctionReturn]
check
end
def test_assign_local
Parfait.object_space.get_main.add_local(:r , :Integer)
@input =s(:statements, s(:assignment, s(:name, :r), s(:int, 5)))
@expect = [Label, LoadConstant, SlotToReg, RegToSlot, Label, FunctionReturn]
check
end
def test_assign_local_assign
Parfait.object_space.get_main.add_local(:r , :Integer)
@input = s(:statements, s(:assignment, s(:name, :r), s(:int, 5)))
@expect = [Label, LoadConstant, SlotToReg, RegToSlot, Label, FunctionReturn]
check
end
end
def test_named_list_get
Parfait.object_space.get_main.add_local(:r , :Integer)
@input = s(:statements, s(:assignment, s(:name, :r), s(:int, 5)), s(:return, s(:name, :r)))
@expect = [Label, LoadConstant, SlotToReg, RegToSlot, SlotToReg, SlotToReg, RegToSlot ,
Label, FunctionReturn]
was = check
get = was.next(5)
assert_equal SlotToReg , get.class
assert_equal 1 + 1, get.index , "Get to named_list index must be offset, not #{get.index}"
end
def test_assign_call
Parfait.object_space.get_main.add_local(:r , :Integer)
@input = s(:statements, s(:assignment, s(:name, :r), s(:call, s(:name, :main), s(:arguments))))
@expect = [Label, SlotToReg, SlotToReg, RegToSlot, LoadConstant, RegToSlot, LoadConstant ,
SlotToReg, SlotToReg, RegToSlot, LoadConstant, RegToSlot, RegisterTransfer, FunctionCall ,
Label, RegisterTransfer, SlotToReg, SlotToReg, SlotToReg, RegToSlot, Label ,
FunctionReturn]
check
end
def test_assign_local_int
Parfait.object_space.get_main.add_local(:r , :Integer)
@input = s(:statements, s(:assignment, s(:name, :r), s(:int, 5)) )
@expect = [Label, LoadConstant, SlotToReg, RegToSlot, Label, FunctionReturn]
was = check
set = was.next(3)
assert_equal RegToSlot , set.class
assert_equal 1 + 1, set.index , "Set to named_list index must be offset, not #{set.index}"
end
def test_named_list_get
Parfait.object_space.get_main.add_local(:r , :Integer)
@input = s(:statements, s(:assignment, s(:name, :r), s(:int, 5)), s(:return, s(:name, :r)))
@expect = [Label, LoadConstant, SlotToReg, RegToSlot, SlotToReg, SlotToReg, RegToSlot ,
Label, FunctionReturn]
was = check
get = was.next(5)
assert_equal SlotToReg , get.class
assert_equal 1 + 1, get.index , "Get to named_list index must be offset, not #{get.index}"
end
def test_misassign_local
Parfait.object_space.get_main.add_local(:r , :Integer)
@input = s(:statements, s(:assignment, s(:name, :r), s(:string, "5")) )
@expect = [Label, LoadConstant, SlotToReg, RegToSlot, Label, FunctionReturn]
assert_raises {check }
end
def test_assign_local_int
Parfait.object_space.get_main.add_local(:r , :Integer)
@input = s(:statements, s(:assignment, s(:name, :r), s(:int, 5)) )
@expect = [Label, LoadConstant, SlotToReg, RegToSlot, Label, FunctionReturn]
was = check
set = was.next(3)
assert_equal RegToSlot , set.class
assert_equal 1 + 1, set.index , "Set to named_list index must be offset, not #{set.index}"
end
def test_assign_arg
Parfait.object_space.get_main.add_argument(:blar , :Integer)
@input = s(:statements, s(:assignment, s(:name, :blar), s(:int, 5)))
@expect = [Label, LoadConstant, SlotToReg, RegToSlot, Label, FunctionReturn]
was = check
set = was.next(3)
assert_equal RegToSlot , set.class
assert_equal 1 + 1, set.index , "Set to args index must be offset, not #{set.index}"
end
def test_misassign_local
Parfait.object_space.get_main.add_local(:r , :Integer)
@input = s(:statements, s(:assignment, s(:name, :r), s(:string, "5")) )
@expect = [Label, LoadConstant, SlotToReg, RegToSlot, Label, FunctionReturn]
assert_raises {check }
end
def test_misassign_arg
Parfait.object_space.get_main.add_argument(:blar , :Integer)
@input = s(:statements, s(:assignment, s(:name, :blar), s(:string, "5")))
@expect = [Label, LoadConstant, SlotToReg, RegToSlot, Label, FunctionReturn]
assert_raises {check }
end
def test_assign_arg
Parfait.object_space.get_main.add_argument(:blar , :Integer)
@input = s(:statements, s(:assignment, s(:name, :blar), s(:int, 5)))
@expect = [Label, LoadConstant, SlotToReg, RegToSlot, Label, FunctionReturn]
was = check
set = was.next(3)
assert_equal RegToSlot , set.class
assert_equal 1 + 1, set.index , "Set to args index must be offset, not #{set.index}"
end
def test_arg_get
# have to define bar externally, just because redefining main. Otherwise that would be automatic
Parfait.object_space.get_main.add_argument(:balr , :Integer)
@input = s(:statements, s(:return, s(:name, :balr)))
@expect = [Label, SlotToReg, SlotToReg, RegToSlot, Label, FunctionReturn]
was = check
get = was.next(2)
assert_equal SlotToReg , get.class
assert_equal 1 + 1, get.index , "Get to args index must be offset, not #{get.index}"
def test_misassign_arg
Parfait.object_space.get_main.add_argument(:blar , :Integer)
@input = s(:statements, s(:assignment, s(:name, :blar), s(:string, "5")))
@expect = [Label, LoadConstant, SlotToReg, RegToSlot, Label, FunctionReturn]
assert_raises {check }
end
def test_arg_get
# have to define bar externally, just because redefining main. Otherwise that would be automatic
Parfait.object_space.get_main.add_argument(:balr , :Integer)
@input = s(:statements, s(:return, s(:name, :balr)))
@expect = [Label, SlotToReg, SlotToReg, RegToSlot, Label, FunctionReturn]
was = check
get = was.next(2)
assert_equal SlotToReg , get.class
assert_equal 1 + 1, get.index , "Get to args index must be offset, not #{get.index}"
end
end
end
end

View File

@ -1,39 +1,41 @@
require_relative "helper"
module Register
class TestBasic < MiniTest::Test
include ExpressionHelper
include AST::Sexp
class TestBasic < MiniTest::Test
include ExpressionHelper
include AST::Sexp
def setup
Register.machine.boot
@output = Register::RegisterValue
end
def setup
Register.machine.boot
@output = Register::RegisterValue
end
def test_number
@input = s(:int , 42)
assert_equal 42 , check.value
end
def test_number
@input = s(:int , 42)
assert_equal 42 , check.value
end
def test_true
@input = s(:true)
check
end
def test_false
@input = s(:false)
check
end
def test_nil
@input = s(:nil)
check
end
def test_self
@input = s(:name, :self)
check
end
def test_string
@input = s(:string , "hello")
check
end
def test_true
@input = s(:true)
check
end
def test_false
@input = s(:false)
check
end
def test_nil
@input = s(:nil)
check
end
def test_self
@input = s(:name, :self)
check
end
def test_string
@input = s(:string , "hello")
check
end
end
end

View File

@ -2,70 +2,70 @@ require_relative 'helper'
require_relative "test_call_expression"
module Register
class TestCallStatement < MiniTest::Test
include Statements
class TestCallStatement < MiniTest::Test
include Statements
def test_call_constant_int
clean_compile :Integer, :puti, {}, s(:statements, s(:return, s(:int, 1)))
@input = s(:call, s(:name, :puti), s(:arguments), s(:receiver, s(:int, 42)))
@expect = [Label, SlotToReg, LoadConstant, RegToSlot, LoadConstant, RegToSlot, LoadConstant ,
SlotToReg, SlotToReg, RegToSlot, LoadConstant, RegToSlot, RegisterTransfer, FunctionCall ,
Label, RegisterTransfer, SlotToReg, SlotToReg, Label, FunctionReturn]
def test_call_constant_int
clean_compile :Integer, :puti, {}, s(:statements, s(:return, s(:int, 1)))
@input = s(:call, s(:name, :puti), s(:arguments), s(:receiver, s(:int, 42)))
@expect = [Label, SlotToReg, LoadConstant, RegToSlot, LoadConstant, RegToSlot, LoadConstant ,
SlotToReg, SlotToReg, RegToSlot, LoadConstant, RegToSlot, RegisterTransfer, FunctionCall ,
Label, RegisterTransfer, SlotToReg, SlotToReg, Label, FunctionReturn]
check
end
def test_call_constant_string
clean_compile :Word, :putstr,{}, s(:statements, s(:return, s(:int, 1)))
@input =s(:call, s(:name, :putstr), s(:arguments), s(:receiver, s(:string, "Hello")))
@expect = [Label, SlotToReg, LoadConstant, RegToSlot, LoadConstant, RegToSlot, LoadConstant ,
SlotToReg, SlotToReg, RegToSlot, LoadConstant, RegToSlot, RegisterTransfer, FunctionCall ,
Label, RegisterTransfer, SlotToReg, SlotToReg, Label, FunctionReturn]
check
end
def _test_call_local_int
Parfait.object_space.get_main.add_local(:testi , :Integer)
clean_compile :Integer, :putint, {}, s(:statements, s(:return, s(:int, 1)))
@input = s(:statements, s(:assignment, s(:name, :testi), s(:int, 20)), s(:call, s(:name, :putint), s(:arguments), s(:receiver, s(:name, :testi))))
@expect = [Label, LoadConstant, SlotToReg, RegToSlot, SlotToReg, SlotToReg, SlotToReg ,
RegToSlot, LoadConstant, RegToSlot, LoadConstant, RegToSlot, LoadConstant, RegToSlot ,
RegisterTransfer, FunctionCall, Label, RegisterTransfer, SlotToReg, SlotToReg, Label ,
FunctionReturn]
check
end
def test_call_local_class
Parfait.object_space.get_main.add_local(:test_l , :List)
clean_compile :List, :add, {}, s(:statements, s(:return, s(:int, 1)))
@input =s(:statements, s(:call, s(:name, :add), s(:arguments), s(:receiver, s(:name, :test_l))))
@expect = [Label, SlotToReg, SlotToReg, SlotToReg, RegToSlot, LoadConstant, RegToSlot ,
LoadConstant, SlotToReg, SlotToReg, RegToSlot, LoadConstant, RegToSlot, RegisterTransfer ,
FunctionCall, Label, RegisterTransfer, SlotToReg, SlotToReg, Label, FunctionReturn]
check
end
def _test_call_puts
@input = <<HERE
class Space
int puts(Word str)
return str
end
def test_call_constant_string
clean_compile :Word, :putstr,{}, s(:statements, s(:return, s(:int, 1)))
@input =s(:call, s(:name, :putstr), s(:arguments), s(:receiver, s(:string, "Hello")))
@expect = [Label, SlotToReg, LoadConstant, RegToSlot, LoadConstant, RegToSlot, LoadConstant ,
SlotToReg, SlotToReg, RegToSlot, LoadConstant, RegToSlot, RegisterTransfer, FunctionCall ,
Label, RegisterTransfer, SlotToReg, SlotToReg, Label, FunctionReturn]
check
int main()
puts("Hello")
end
def _test_call_local_int
Parfait.object_space.get_main.add_local(:testi , :Integer)
clean_compile :Integer, :putint, {}, s(:statements, s(:return, s(:int, 1)))
@input = s(:statements, s(:assignment, s(:name, :testi), s(:int, 20)), s(:call, s(:name, :putint), s(:arguments), s(:receiver, s(:name, :testi))))
@expect = [Label, LoadConstant, SlotToReg, RegToSlot, SlotToReg, SlotToReg, SlotToReg ,
RegToSlot, LoadConstant, RegToSlot, LoadConstant, RegToSlot, LoadConstant, RegToSlot ,
RegisterTransfer, FunctionCall, Label, RegisterTransfer, SlotToReg, SlotToReg, Label ,
FunctionReturn]
check
end
def test_call_local_class
Parfait.object_space.get_main.add_local(:test_l , :List)
clean_compile :List, :add, {}, s(:statements, s(:return, s(:int, 1)))
@input =s(:statements, s(:call, s(:name, :add), s(:arguments), s(:receiver, s(:name, :test_l))))
@expect = [Label, SlotToReg, SlotToReg, SlotToReg, RegToSlot, LoadConstant, RegToSlot ,
LoadConstant, SlotToReg, SlotToReg, RegToSlot, LoadConstant, RegToSlot, RegisterTransfer ,
FunctionCall, Label, RegisterTransfer, SlotToReg, SlotToReg, Label, FunctionReturn]
check
end
def _test_call_puts
@input = <<HERE
class Space
int puts(Word str)
return str
end
int main()
puts("Hello")
end
end
HERE
@expect = [Label, SlotToReg, SlotToReg, RegToSlot, LoadConstant, RegToSlot, LoadConstant ,
RegToSlot, LoadConstant, RegToSlot, LoadConstant, RegToSlot, RegisterTransfer, FunctionCall ,
Label, RegisterTransfer, SlotToReg, SlotToReg, Label, FunctionReturn]
was = check
set = was.next(7)
assert_equal RegToSlot , set.class
assert_equal 9, set.index , "Set to message must be offset, not #{set.index}"
@expect = [Label, SlotToReg, SlotToReg, RegToSlot, LoadConstant, RegToSlot, LoadConstant ,
RegToSlot, LoadConstant, RegToSlot, LoadConstant, RegToSlot, RegisterTransfer, FunctionCall ,
Label, RegisterTransfer, SlotToReg, SlotToReg, Label, FunctionReturn]
was = check
set = was.next(7)
assert_equal RegToSlot , set.class
assert_equal 9, set.index , "Set to message must be offset, not #{set.index}"
end
end
end
end

View File

@ -1,31 +1,31 @@
require_relative 'helper'
module Register
class TestClassStatements < MiniTest::Test
include Statements
class TestClassStatements < MiniTest::Test
include Statements
def class_def
clean_compile :Bar, :buh, {}, s(:statements, s(:return, s(:int, 1)))
end
def class_def
clean_compile :Bar, :buh, {}, s(:statements, s(:return, s(:int, 1)))
end
def test_class_call
#FIXME class call
# class_def
# @input = s(:statements, s(:return, s(:call, s(:name, :buh), s(:arguments), s(:receiver, s(:class_name, :Bar)))))
#
# @expect = [Label, SlotToReg, LoadConstant, RegToSlot, LoadConstant, RegToSlot, LoadConstant ,
# RegToSlot, LoadConstant, RegToSlot, RegisterTransfer, FunctionCall, Label, RegisterTransfer ,
# SlotToReg, SlotToReg, RegToSlot, Label, FunctionReturn]
# check
end
def test_class_call
#FIXME class call
# class_def
# @input = s(:statements, s(:return, s(:call, s(:name, :buh), s(:arguments), s(:receiver, s(:class_name, :Bar)))))
#
# @expect = [Label, SlotToReg, LoadConstant, RegToSlot, LoadConstant, RegToSlot, LoadConstant ,
# RegToSlot, LoadConstant, RegToSlot, RegisterTransfer, FunctionCall, Label, RegisterTransfer ,
# SlotToReg, SlotToReg, RegToSlot, Label, FunctionReturn]
# check
end
def test_class_field
# clean_compile :Space, s(:class_field, :Integer, :boo2)
#FIXME class_field handling unclear at the moment
# @input =s(:statements, s(:return, s(:field_access, s(:receiver, s(:name, :self)),
# s(:field,s(:name, :boo2)))))
# @expect = [Label, SlotToReg,SlotToReg,RegToSlot,Label,FunctionReturn]
# check
def test_class_field
# clean_compile :Space, s(:class_field, :Integer, :boo2)
#FIXME class_field handling unclear at the moment
# @input =s(:statements, s(:return, s(:field_access, s(:receiver, s(:name, :self)),
# s(:field,s(:name, :boo2)))))
# @expect = [Label, SlotToReg,SlotToReg,RegToSlot,Label,FunctionReturn]
# check
end
end
end
end

View File

@ -1,35 +1,35 @@
require_relative 'helper'
module Register
class TestIfStatement < MiniTest::Test
include Statements
class TestIfStatement < MiniTest::Test
include Statements
def test_if_basicr
@input = s(:statements, s(:if_statement, :plus, s(:condition, s(:operator_value, :-, s(:int, 10), s(:int, 12))), s(:true_statements, s(:return, s(:int, 3))), s(:false_statements, s(:return, s(:int, 4)))))
def test_if_basicr
@input = s(:statements, s(:if_statement, :plus, s(:condition, s(:operator_value, :-, s(:int, 10), s(:int, 12))), s(:true_statements, s(:return, s(:int, 3))), s(:false_statements, s(:return, s(:int, 4)))))
@expect = [Label, LoadConstant,LoadConstant, OperatorInstruction,IsPlus ,
LoadConstant,RegToSlot,Branch , Label , LoadConstant ,RegToSlot,
Label,Label,FunctionReturn]
check
end
@expect = [Label, LoadConstant,LoadConstant, OperatorInstruction,IsPlus ,
LoadConstant,RegToSlot,Branch , Label , LoadConstant ,RegToSlot,
Label,Label,FunctionReturn]
check
end
def test_if_small_minus
@input = s(:statements, s(:if_statement, :minus, s(:condition, s(:operator_value, :-, s(:int, 10), s(:int, 12))), s(:true_statements, s(:return, s(:int, 3))), s(:false_statements, nil)))
def test_if_small_minus
@input = s(:statements, s(:if_statement, :minus, s(:condition, s(:operator_value, :-, s(:int, 10), s(:int, 12))), s(:true_statements, s(:return, s(:int, 3))), s(:false_statements, nil)))
@expect = [Label, LoadConstant, LoadConstant, OperatorInstruction, IsMinus, Branch, Label ,
LoadConstant, RegToSlot, Label, Label, FunctionReturn]
check
end
@expect = [Label, LoadConstant, LoadConstant, OperatorInstruction, IsMinus, Branch, Label ,
LoadConstant, RegToSlot, Label, Label, FunctionReturn]
check
end
def test_if_small_zero
@input = s(:statements, s(:if_statement, :zero, s(:condition, s(:operator_value, :-, s(:int, 10), s(:int, 12))), s(:true_statements, s(:return, s(:int, 3))), s(:false_statements, nil)))
def test_if_small_zero
@input = s(:statements, s(:if_statement, :zero, s(:condition, s(:operator_value, :-, s(:int, 10), s(:int, 12))), s(:true_statements, s(:return, s(:int, 3))), s(:false_statements, nil)))
@expect = [Label, LoadConstant,LoadConstant,OperatorInstruction,IsZero ,
Branch , Label , LoadConstant ,RegToSlot,
Label,Label, FunctionReturn]
check
@expect = [Label, LoadConstant,LoadConstant,OperatorInstruction,IsZero ,
Branch , Label , LoadConstant ,RegToSlot,
Label,Label, FunctionReturn]
check
end
end
end
end

View File

@ -1,44 +1,44 @@
require_relative 'helper'
module Register
class TestReturnStatement < MiniTest::Test
include Statements
class TestReturnStatement < MiniTest::Test
include Statements
def test_return_int
@input = s(:statements, s(:return, s(:int, 5)))
@expect = [Label, LoadConstant ,RegToSlot,Label,FunctionReturn]
check
end
def test_return_local
Parfait.object_space.get_main.add_local(:runner , :Integer)
@input = s(:statements, s(:return, s(:name, :runner)))
@expect = [Label, SlotToReg,SlotToReg ,RegToSlot,Label,FunctionReturn]
check
end
def test_return_local_assign
Parfait.object_space.get_main.add_local(:runner , :Integer)
@input = s(:statements, s(:assignment, s(:name, :runner), s(:int, 5)), s(:return, s(:name, :runner)))
@expect = [Label, LoadConstant,SlotToReg,RegToSlot,SlotToReg,SlotToReg ,RegToSlot,
Label,FunctionReturn]
check
end
def test_return_call
@input =s(:statements, s(:return, s(:call, s(:name, :main), s(:arguments))))
@expect = [Label, SlotToReg, SlotToReg, RegToSlot, LoadConstant, RegToSlot, LoadConstant ,
SlotToReg, SlotToReg, RegToSlot, LoadConstant, RegToSlot, RegisterTransfer, FunctionCall ,
Label, RegisterTransfer, SlotToReg, SlotToReg, RegToSlot, Label, FunctionReturn]
check
end
def pest_return_space_length # need to add runtime first
Parfait.object_space.get_main.add_local(:l , :Type)
@input = s(:statements, s(:assignment, s(:name, :l), s(:call, s(:name, :get_type), s(:arguments), s(:receiver, s(:name, :space)))), s(:return, s(:field_access, s(:receiver, s(:name, :self)), s(:field, s(:name, :runner)))))
@expect = [Label, SlotToReg,SlotToReg ,RegToSlot,Label,FunctionReturn]
check
end
def test_return_int
@input = s(:statements, s(:return, s(:int, 5)))
@expect = [Label, LoadConstant ,RegToSlot,Label,FunctionReturn]
check
end
def test_return_local
Parfait.object_space.get_main.add_local(:runner , :Integer)
@input = s(:statements, s(:return, s(:name, :runner)))
@expect = [Label, SlotToReg,SlotToReg ,RegToSlot,Label,FunctionReturn]
check
end
def test_return_local_assign
Parfait.object_space.get_main.add_local(:runner , :Integer)
@input = s(:statements, s(:assignment, s(:name, :runner), s(:int, 5)), s(:return, s(:name, :runner)))
@expect = [Label, LoadConstant,SlotToReg,RegToSlot,SlotToReg,SlotToReg ,RegToSlot,
Label,FunctionReturn]
check
end
def test_return_call
@input =s(:statements, s(:return, s(:call, s(:name, :main), s(:arguments))))
@expect = [Label, SlotToReg, SlotToReg, RegToSlot, LoadConstant, RegToSlot, LoadConstant ,
SlotToReg, SlotToReg, RegToSlot, LoadConstant, RegToSlot, RegisterTransfer, FunctionCall ,
Label, RegisterTransfer, SlotToReg, SlotToReg, RegToSlot, Label, FunctionReturn]
check
end
def pest_return_space_length # need to add runtime first
Parfait.object_space.get_main.add_local(:l , :Type)
@input = s(:statements, s(:assignment, s(:name, :l), s(:call, s(:name, :get_type), s(:arguments), s(:receiver, s(:name, :space)))), s(:return, s(:field_access, s(:receiver, s(:name, :self)), s(:field, s(:name, :runner)))))
@expect = [Label, SlotToReg,SlotToReg ,RegToSlot,Label,FunctionReturn]
check
end
end
end