fix return statement to actually return

fix a million tests
This commit is contained in:
Torsten Ruger 2015-10-27 21:04:46 +02:00
parent 79cf59c4e2
commit 142c36a374
16 changed files with 61 additions and 59 deletions

View File

@ -1,9 +1,10 @@
module Soml module Soml
Compiler.class_eval do Compiler.class_eval do
# return attr_reader :statement
def on_return statement def on_return statement
return process(statement.to_a.first ) reg = process(statement.first )
add_code Register.set_slot( statement, reg , :message , :return_value)
nil # statements don't return
end end
end end
end end

View File

@ -17,7 +17,7 @@ class Object
end end
end end
HERE HERE
@length = 16 @length = 17
check check
end end
end end

View File

@ -16,7 +16,7 @@ class Object
end end
end end
HERE HERE
@length = 38 @length = 39
check check
end end

View File

@ -28,7 +28,7 @@ class Object
end end
end end
HERE HERE
@length = 191 @length = 196
check check
end end

View File

@ -16,7 +16,7 @@ class Object
end end
end end
HERE HERE
@length = 26 @length = 27
check check
end end

View File

@ -16,7 +16,7 @@ class Object
end end
end end
HERE HERE
@length = 32 @length = 33
check check
end end
end end

View File

@ -27,7 +27,7 @@ class Object
end end
end end
HERE HERE
@length = 77 @length = 78
check check
end end
end end

View File

@ -69,7 +69,7 @@ class Object
end end
end end
HERE HERE
@expect = [Label, SaveReturn,LoadConstant,GetSlot,SetSlot,GetSlot,GetSlot , @expect = [Label, SaveReturn,LoadConstant,GetSlot,SetSlot,GetSlot,GetSlot ,SetSlot,
Label,RegisterTransfer,GetSlot,FunctionReturn] Label,RegisterTransfer,GetSlot,FunctionReturn]
was = check was = check
get = was.next(6) get = was.next(6)
@ -118,7 +118,7 @@ class Object
end end
end end
HERE HERE
@expect = [Label, SaveReturn,GetSlot , Label , RegisterTransfer,GetSlot,FunctionReturn] @expect = [Label, SaveReturn,GetSlot , SetSlot,Label , RegisterTransfer,GetSlot,FunctionReturn]
was = check was = check
get = was.next(2) get = was.next(2)
assert_equal GetSlot , get.class assert_equal GetSlot , get.class

View File

@ -4,7 +4,7 @@ module Register
class TestClassStatements < MiniTest::Test class TestClassStatements < MiniTest::Test
include Statements include Statements
def test_class_def def test_class_defs
@string_input = <<HERE @string_input = <<HERE
class Bar class Bar
int self.buh() int self.buh()
@ -17,7 +17,7 @@ class Object
end end
end end
HERE HERE
@expect = [Label, SaveReturn,LoadConstant,Label,RegisterTransfer,GetSlot,FunctionReturn] @expect = [Label, SaveReturn,LoadConstant,SetSlot,Label,RegisterTransfer,GetSlot,FunctionReturn]
check check
end end
@ -35,7 +35,7 @@ class Object
end end
HERE HERE
@expect = [Label, SaveReturn,GetSlot,LoadConstant,SetSlot,LoadConstant,SetSlot,LoadConstant,SetSlot, @expect = [Label, SaveReturn,GetSlot,LoadConstant,SetSlot,LoadConstant,SetSlot,LoadConstant,SetSlot,
RegisterTransfer,FunctionCall,GetSlot,Label,RegisterTransfer,GetSlot,FunctionReturn] RegisterTransfer,FunctionCall,GetSlot,SetSlot,Label,RegisterTransfer,GetSlot,FunctionReturn]
check check
end end
@ -48,7 +48,7 @@ class Object
end end
end end
HERE HERE
@expect = [Label, SaveReturn,LoadConstant,Label,RegisterTransfer,GetSlot,FunctionReturn] @expect = [Label, SaveReturn,LoadConstant,SetSlot,Label,RegisterTransfer,GetSlot,FunctionReturn]
assert_raises{check} assert_raises{check}
end end
@ -61,7 +61,7 @@ class Object
end end
end end
HERE HERE
@expect = [Label, SaveReturn,GetSlot,GetSlot,Label,RegisterTransfer,GetSlot,FunctionReturn] @expect = [Label, SaveReturn,GetSlot,GetSlot,SetSlot,Label,RegisterTransfer,GetSlot,FunctionReturn]
check check
end end
end end

View File

@ -4,7 +4,7 @@ module Register
class TestIfStatement < MiniTest::Test class TestIfStatement < MiniTest::Test
include Statements include Statements
def test_if_basic def test_if_basicr
@string_input = <<HERE @string_input = <<HERE
class Object class Object
int main() int main()
@ -17,7 +17,7 @@ class Object
end end
HERE HERE
@expect = [Label, SaveReturn,LoadConstant,LoadConstant, OperatorInstruction,IsPlus , @expect = [Label, SaveReturn,LoadConstant,LoadConstant, OperatorInstruction,IsPlus ,
LoadConstant,Branch , Label , LoadConstant , LoadConstant,SetSlot,Branch , Label , LoadConstant ,SetSlot,
Label,Label,RegisterTransfer,GetSlot,FunctionReturn] Label,Label,RegisterTransfer,GetSlot,FunctionReturn]
check check
end end
@ -34,7 +34,7 @@ class Object
end end
HERE HERE
@expect = [Label, SaveReturn,LoadConstant,LoadConstant, OperatorInstruction,IsMinus , @expect = [Label, SaveReturn,LoadConstant,LoadConstant, OperatorInstruction,IsMinus ,
Branch ,Label , LoadConstant , Branch ,Label , LoadConstant ,SetSlot,
Label,Label , RegisterTransfer,GetSlot,FunctionReturn] Label,Label , RegisterTransfer,GetSlot,FunctionReturn]
check check
end end
@ -51,7 +51,7 @@ class Object
end end
HERE HERE
@expect = [Label, SaveReturn,LoadConstant,LoadConstant,OperatorInstruction,IsZero , @expect = [Label, SaveReturn,LoadConstant,LoadConstant,OperatorInstruction,IsZero ,
Branch , Label , LoadConstant , Branch , Label , LoadConstant ,SetSlot,
Label,Label, RegisterTransfer,GetSlot,FunctionReturn] Label,Label, RegisterTransfer,GetSlot,FunctionReturn]
check check
end end

View File

@ -13,8 +13,12 @@ class Object
end end
end end
HERE HERE
@expect = [Label, SaveReturn,LoadConstant ,Label,RegisterTransfer,GetSlot,FunctionReturn] @expect = [Label, SaveReturn,LoadConstant ,SetSlot,Label,RegisterTransfer,GetSlot,FunctionReturn]
check was = check
set = was.next(3)
assert_equal SetSlot , set.class
should = Register.machine.space.first_message.get_layout.variable_index(:return_value)
assert_equal should, set.index , "Set to message must got to return_value(#{should}), not #{set.index}"
end end
def test_return_local def test_return_local
@ -26,7 +30,7 @@ class Object
end end
end end
HERE HERE
@expect = [Label, SaveReturn,GetSlot,GetSlot ,Label,RegisterTransfer,GetSlot,FunctionReturn] @expect = [Label, SaveReturn,GetSlot,GetSlot ,SetSlot,Label,RegisterTransfer,GetSlot,FunctionReturn]
check check
end end
@ -39,7 +43,7 @@ class Object
end end
end end
HERE HERE
@expect = [Label, SaveReturn,LoadConstant,GetSlot,SetSlot,GetSlot,GetSlot , @expect = [Label, SaveReturn,LoadConstant,GetSlot,SetSlot,GetSlot,GetSlot ,SetSlot,
Label,RegisterTransfer,GetSlot,FunctionReturn] Label,RegisterTransfer,GetSlot,FunctionReturn]
check check
end end
@ -53,7 +57,7 @@ class Object
end end
end end
HERE HERE
@expect = [Label, SaveReturn,GetSlot,GetSlot ,Label,RegisterTransfer,GetSlot,FunctionReturn] @expect = [Label, SaveReturn,GetSlot,GetSlot ,SetSlot,Label,RegisterTransfer,GetSlot,FunctionReturn]
check check
end end
@ -66,7 +70,7 @@ class Object
end end
HERE HERE
@expect = [Label, SaveReturn,GetSlot,GetSlot,SetSlot, LoadConstant, @expect = [Label, SaveReturn,GetSlot,GetSlot,SetSlot, LoadConstant,
SetSlot,LoadConstant,SetSlot,RegisterTransfer,FunctionCall,GetSlot ,Label, SetSlot,LoadConstant,SetSlot,RegisterTransfer,FunctionCall,GetSlot ,SetSlot,Label,
RegisterTransfer,GetSlot,FunctionReturn] RegisterTransfer,GetSlot,FunctionReturn]
check check
end end

View File

@ -15,7 +15,7 @@ class Object
end end
end end
HERE HERE
@expect = [Label, SaveReturn,Label,LoadConstant,IsPlus,LoadConstant,Branch, @expect = [Label, SaveReturn,Label,LoadConstant,IsPlus,LoadConstant,SetSlot,Branch,
Label,Label,RegisterTransfer,GetSlot,FunctionReturn] Label,Label,RegisterTransfer,GetSlot,FunctionReturn]
check check
end end
@ -34,7 +34,7 @@ end
HERE HERE
@expect = [Label, SaveReturn,LoadConstant,GetSlot,SetSlot,Label,GetSlot,GetSlot, IsPlus,GetSlot, @expect = [Label, SaveReturn,LoadConstant,GetSlot,SetSlot,Label,GetSlot,GetSlot, IsPlus,GetSlot,
GetSlot,LoadConstant,OperatorInstruction,GetSlot,SetSlot,Branch, GetSlot,LoadConstant,OperatorInstruction,GetSlot,SetSlot,Branch,
Label,GetSlot,GetSlot,Label,RegisterTransfer,GetSlot,FunctionReturn] Label,GetSlot,GetSlot,SetSlot,Label,RegisterTransfer,GetSlot,FunctionReturn]
check check
end end
@ -54,7 +54,7 @@ HERE
@expect = [Label, SaveReturn,LoadConstant,GetSlot,SetSlot,Label, @expect = [Label, SaveReturn,LoadConstant,GetSlot,SetSlot,Label,
GetSlot,GetSlot,LoadConstant,OperatorInstruction,IsPlus, GetSlot,GetSlot,LoadConstant,OperatorInstruction,IsPlus,
GetSlot, GetSlot,LoadConstant,OperatorInstruction, GetSlot, GetSlot, GetSlot,LoadConstant,OperatorInstruction, GetSlot,
SetSlot,GetSlot, GetSlot,Branch , Label , SetSlot,GetSlot, GetSlot,SetSlot,Branch , Label ,
Label , RegisterTransfer,GetSlot,FunctionReturn] Label , RegisterTransfer,GetSlot,FunctionReturn]
check check
end end

View File

@ -48,7 +48,7 @@ class AddTest < MiniTest::Test
assert_equal Fixnum , right.class assert_equal Fixnum , right.class
assert_equal 7 , right assert_equal 7 , right
assert_equal 12 , left assert_equal 12 , left
done_tr = ticks(2) done_tr = ticks(3)
assert_equal Register::RegisterTransfer , done_tr.class assert_equal Register::RegisterTransfer , done_tr.class
result = @interpreter.get_register(done_op.left) result = @interpreter.get_register(done_op.left)
assert_equal result , 12 assert_equal result , 12
@ -58,16 +58,10 @@ class AddTest < MiniTest::Test
#show_ticks # get output of what is #show_ticks # get output of what is
["Branch","Label","LoadConstant","GetSlot","SetSlot", ["Branch","Label","LoadConstant","GetSlot","SetSlot",
"RegisterTransfer","FunctionCall","Label","SaveReturn","LoadConstant", "RegisterTransfer","FunctionCall","Label","SaveReturn","LoadConstant",
"LoadConstant","OperatorInstruction","Label","RegisterTransfer","GetSlot", "LoadConstant","OperatorInstruction","SetSlot","Label","RegisterTransfer",
"FunctionReturn","RegisterTransfer","Syscall","NilClass"].each_with_index do |name , index| "GetSlot","FunctionReturn","RegisterTransfer","Syscall","NilClass"].each_with_index do |name , index|
got = ticks(1) got = ticks(1)
assert got.class.name.index(name) , "Wrong class for #{index+1}, expect #{name} , got #{got}" assert got.class.name.index(name) , "Wrong class for #{index+1}, expect #{name} , got #{got}"
end end
end end
# def test_exit
# done = ticks(34)
# assert_equal NilClass , done.class
# end
end end

View File

@ -1,3 +1,4 @@
require_relative "test_add"
require_relative "test_if"
require_relative "test_puts" require_relative "test_puts"
require_relative "test_puti" require_relative "test_puti"
require_relative "test_add"

View File

@ -34,15 +34,16 @@ HERE
["Branch","Label","LoadConstant","GetSlot","SetSlot", ["Branch","Label","LoadConstant","GetSlot","SetSlot",
"RegisterTransfer","FunctionCall","Label","SaveReturn","GetSlot", "RegisterTransfer","FunctionCall","Label","SaveReturn","GetSlot",
"GetSlot","SetSlot","LoadConstant","SetSlot","LoadConstant", "GetSlot","SetSlot","LoadConstant","SetSlot","LoadConstant",
"SetSlot","RegisterTransfer","FunctionCall","Label","SaveReturn", "SetSlot","LoadConstant","SetSlot","RegisterTransfer","FunctionCall",
"GetSlot","LoadConstant","OperatorInstruction","IsZero","GetSlot", "Label","SaveReturn","GetSlot","LoadConstant","OperatorInstruction",
"LoadConstant","SetSlot","LoadConstant","SetSlot","RegisterTransfer", "IsZero","GetSlot","LoadConstant","SetSlot","LoadConstant",
"FunctionCall","Label","SaveReturn","GetSlot","RegisterTransfer", "SetSlot","LoadConstant","SetSlot","RegisterTransfer","FunctionCall",
"Syscall","RegisterTransfer","RegisterTransfer","SetSlot","Label", "Label","SaveReturn","GetSlot","RegisterTransfer","Syscall",
"RegisterTransfer","GetSlot","FunctionReturn","GetSlot","Branch", "RegisterTransfer","RegisterTransfer","SetSlot","Label","RegisterTransfer",
"Label","Label","RegisterTransfer","GetSlot","FunctionReturn", "GetSlot","FunctionReturn","GetSlot","Branch","Label",
"GetSlot","Label","RegisterTransfer","GetSlot","FunctionReturn", "Label","RegisterTransfer","GetSlot","FunctionReturn","GetSlot",
"RegisterTransfer","Syscall","NilClass"].each_with_index do |name , index| "Label","RegisterTransfer","GetSlot","FunctionReturn","RegisterTransfer",
"Syscall","NilClass"].each_with_index do |name , index|
got = ticks(1) got = ticks(1)
assert got.class.name.index(name) , "Wrong class for #{index+1}, expect #{name} , got #{got}" assert got.class.name.index(name) , "Wrong class for #{index+1}, expect #{name} , got #{got}"
end end

View File

@ -74,18 +74,19 @@ HERE
"GetSlot","SetSlot","RegisterTransfer","FunctionCall","Label", "GetSlot","SetSlot","RegisterTransfer","FunctionCall","Label",
"SaveReturn","GetSlot","LoadConstant","OperatorInstruction","IsZero", "SaveReturn","GetSlot","LoadConstant","OperatorInstruction","IsZero",
"Branch","Label","GetSlot","LoadConstant","OperatorInstruction", "Branch","Label","GetSlot","LoadConstant","OperatorInstruction",
"IsZero","Label","LoadConstant","Label","GetSlot", "IsZero","Label","LoadConstant","SetSlot","Label",
"LoadConstant","OperatorInstruction","IsZero","Label","LoadConstant", "GetSlot","LoadConstant","OperatorInstruction","IsZero","Label",
"LoadConstant","SetSlot","Label","GetSlot","LoadConstant",
"OperatorInstruction","IsZero","Label","LoadConstant","SetSlot",
"Label","GetSlot","LoadConstant","OperatorInstruction","IsZero", "Label","GetSlot","LoadConstant","OperatorInstruction","IsZero",
"Label","LoadConstant","Label","GetSlot","LoadConstant", "Label","LoadConstant","SetSlot","Label","Label",
"OperatorInstruction","IsZero","Label","LoadConstant","Label", "RegisterTransfer","GetSlot","FunctionReturn","GetSlot","GetSlot",
"SetSlot","GetSlot","GetSlot","GetSlot","OperatorInstruction",
"SetSlot","Label","GetSlot","SetSlot","Label",
"RegisterTransfer","GetSlot","FunctionReturn","GetSlot","SetSlot",
"Label","RegisterTransfer","GetSlot","FunctionReturn","GetSlot", "Label","RegisterTransfer","GetSlot","FunctionReturn","GetSlot",
"GetSlot","SetSlot","GetSlot","GetSlot","GetSlot", "Label","RegisterTransfer","GetSlot","FunctionReturn","RegisterTransfer",
"OperatorInstruction","SetSlot","Label","GetSlot","Label", "Syscall","NilClass"].each_with_index do |name , index|
"RegisterTransfer","GetSlot","FunctionReturn","GetSlot","Label",
"RegisterTransfer","GetSlot","FunctionReturn","GetSlot","Label",
"RegisterTransfer","GetSlot","FunctionReturn","RegisterTransfer","Syscall",
"NilClass"].each_with_index do |name , index|
got = ticks(1) got = ticks(1)
assert got.class.name.index(name) , "Wrong class for #{index+1}, expect #{name} , got #{got}" assert got.class.name.index(name) , "Wrong class for #{index+1}, expect #{name} , got #{got}"
end end