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

View File

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

View File

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

View File

@ -2,70 +2,70 @@ require_relative 'helper'
require_relative "test_call_expression" require_relative "test_call_expression"
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
clean_compile :Integer, :puti, {}, s(:statements, s(:return, s(:int, 1))) clean_compile :Integer, :puti, {}, s(:statements, s(:return, s(:int, 1)))
@input = s(:call, s(:name, :puti), s(:arguments), s(:receiver, s(:int, 42))) @input = s(:call, s(:name, :puti), s(:arguments), s(:receiver, s(:int, 42)))
@expect = [Label, SlotToReg, LoadConstant, RegToSlot, LoadConstant, RegToSlot, LoadConstant , @expect = [Label, SlotToReg, LoadConstant, RegToSlot, LoadConstant, RegToSlot, LoadConstant ,
SlotToReg, SlotToReg, RegToSlot, LoadConstant, RegToSlot, RegisterTransfer, FunctionCall , SlotToReg, SlotToReg, RegToSlot, LoadConstant, RegToSlot, RegisterTransfer, FunctionCall ,
Label, RegisterTransfer, SlotToReg, SlotToReg, Label, FunctionReturn] 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 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 end
int main()
puts("Hello")
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 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 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 HERE
@expect = [Label, SlotToReg, SlotToReg, RegToSlot, LoadConstant, RegToSlot, LoadConstant , @expect = [Label, SlotToReg, SlotToReg, RegToSlot, LoadConstant, RegToSlot, LoadConstant ,
RegToSlot, LoadConstant, RegToSlot, LoadConstant, RegToSlot, RegisterTransfer, FunctionCall , RegToSlot, LoadConstant, RegToSlot, LoadConstant, RegToSlot, RegisterTransfer, FunctionCall ,
Label, RegisterTransfer, SlotToReg, SlotToReg, Label, FunctionReturn] Label, RegisterTransfer, SlotToReg, SlotToReg, Label, FunctionReturn]
was = check was = check
set = was.next(7) set = was.next(7)
assert_equal RegToSlot , set.class assert_equal RegToSlot , set.class
assert_equal 9, set.index , "Set to message must be offset, not #{set.index}" assert_equal 9, set.index , "Set to message must be offset, not #{set.index}"
end
end end
end end
end

View File

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

View File

@ -1,35 +1,35 @@
require_relative 'helper' require_relative 'helper'
module Register module Register
class TestIfStatement < MiniTest::Test class TestIfStatement < MiniTest::Test
include Statements include Statements
def test_if_basicr 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))))) @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 , @expect = [Label, LoadConstant,LoadConstant, OperatorInstruction,IsPlus ,
LoadConstant,RegToSlot,Branch , Label , LoadConstant ,RegToSlot, LoadConstant,RegToSlot,Branch , Label , LoadConstant ,RegToSlot,
Label,Label,FunctionReturn] Label,Label,FunctionReturn]
check check
end end
def test_if_small_minus 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))) @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 , @expect = [Label, LoadConstant, LoadConstant, OperatorInstruction, IsMinus, Branch, Label ,
LoadConstant, RegToSlot, Label, Label, FunctionReturn] LoadConstant, RegToSlot, Label, Label, FunctionReturn]
check check
end end
def test_if_small_zero 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))) @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 , @expect = [Label, LoadConstant,LoadConstant,OperatorInstruction,IsZero ,
Branch , Label , LoadConstant ,RegToSlot, Branch , Label , LoadConstant ,RegToSlot,
Label,Label, FunctionReturn] Label,Label, FunctionReturn]
check check
end
end end
end end
end

View File

@ -1,44 +1,44 @@
require_relative 'helper' require_relative 'helper'
module Register module Register
class TestReturnStatement < MiniTest::Test class TestReturnStatement < MiniTest::Test
include Statements 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 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 end