fix return statement to actually return
fix a million tests
This commit is contained in:
parent
79cf59c4e2
commit
142c36a374
@ -1,9 +1,10 @@
|
||||
module Soml
|
||||
Compiler.class_eval do
|
||||
|
||||
# return attr_reader :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
|
||||
|
@ -17,7 +17,7 @@ class Object
|
||||
end
|
||||
end
|
||||
HERE
|
||||
@length = 16
|
||||
@length = 17
|
||||
check
|
||||
end
|
||||
end
|
||||
|
@ -16,7 +16,7 @@ class Object
|
||||
end
|
||||
end
|
||||
HERE
|
||||
@length = 38
|
||||
@length = 39
|
||||
check
|
||||
end
|
||||
|
||||
|
@ -28,7 +28,7 @@ class Object
|
||||
end
|
||||
end
|
||||
HERE
|
||||
@length = 191
|
||||
@length = 196
|
||||
check
|
||||
|
||||
end
|
||||
|
@ -16,7 +16,7 @@ class Object
|
||||
end
|
||||
end
|
||||
HERE
|
||||
@length = 26
|
||||
@length = 27
|
||||
check
|
||||
end
|
||||
|
||||
|
@ -16,7 +16,7 @@ class Object
|
||||
end
|
||||
end
|
||||
HERE
|
||||
@length = 32
|
||||
@length = 33
|
||||
check
|
||||
end
|
||||
end
|
||||
|
@ -27,7 +27,7 @@ class Object
|
||||
end
|
||||
end
|
||||
HERE
|
||||
@length = 77
|
||||
@length = 78
|
||||
check
|
||||
end
|
||||
end
|
||||
|
@ -69,7 +69,7 @@ class Object
|
||||
end
|
||||
end
|
||||
HERE
|
||||
@expect = [Label, SaveReturn,LoadConstant,GetSlot,SetSlot,GetSlot,GetSlot ,
|
||||
@expect = [Label, SaveReturn,LoadConstant,GetSlot,SetSlot,GetSlot,GetSlot ,SetSlot,
|
||||
Label,RegisterTransfer,GetSlot,FunctionReturn]
|
||||
was = check
|
||||
get = was.next(6)
|
||||
@ -118,7 +118,7 @@ class Object
|
||||
end
|
||||
end
|
||||
HERE
|
||||
@expect = [Label, SaveReturn,GetSlot , Label , RegisterTransfer,GetSlot,FunctionReturn]
|
||||
@expect = [Label, SaveReturn,GetSlot , SetSlot,Label , RegisterTransfer,GetSlot,FunctionReturn]
|
||||
was = check
|
||||
get = was.next(2)
|
||||
assert_equal GetSlot , get.class
|
||||
|
@ -4,7 +4,7 @@ module Register
|
||||
class TestClassStatements < MiniTest::Test
|
||||
include Statements
|
||||
|
||||
def test_class_def
|
||||
def test_class_defs
|
||||
@string_input = <<HERE
|
||||
class Bar
|
||||
int self.buh()
|
||||
@ -17,7 +17,7 @@ class Object
|
||||
end
|
||||
end
|
||||
HERE
|
||||
@expect = [Label, SaveReturn,LoadConstant,Label,RegisterTransfer,GetSlot,FunctionReturn]
|
||||
@expect = [Label, SaveReturn,LoadConstant,SetSlot,Label,RegisterTransfer,GetSlot,FunctionReturn]
|
||||
check
|
||||
end
|
||||
|
||||
@ -35,7 +35,7 @@ class Object
|
||||
end
|
||||
HERE
|
||||
@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
|
||||
end
|
||||
|
||||
@ -48,7 +48,7 @@ class Object
|
||||
end
|
||||
end
|
||||
HERE
|
||||
@expect = [Label, SaveReturn,LoadConstant,Label,RegisterTransfer,GetSlot,FunctionReturn]
|
||||
@expect = [Label, SaveReturn,LoadConstant,SetSlot,Label,RegisterTransfer,GetSlot,FunctionReturn]
|
||||
assert_raises{check}
|
||||
end
|
||||
|
||||
@ -61,7 +61,7 @@ class Object
|
||||
end
|
||||
end
|
||||
HERE
|
||||
@expect = [Label, SaveReturn,GetSlot,GetSlot,Label,RegisterTransfer,GetSlot,FunctionReturn]
|
||||
@expect = [Label, SaveReturn,GetSlot,GetSlot,SetSlot,Label,RegisterTransfer,GetSlot,FunctionReturn]
|
||||
check
|
||||
end
|
||||
end
|
||||
|
@ -4,7 +4,7 @@ module Register
|
||||
class TestIfStatement < MiniTest::Test
|
||||
include Statements
|
||||
|
||||
def test_if_basic
|
||||
def test_if_basicr
|
||||
@string_input = <<HERE
|
||||
class Object
|
||||
int main()
|
||||
@ -17,7 +17,7 @@ class Object
|
||||
end
|
||||
HERE
|
||||
@expect = [Label, SaveReturn,LoadConstant,LoadConstant, OperatorInstruction,IsPlus ,
|
||||
LoadConstant,Branch , Label , LoadConstant ,
|
||||
LoadConstant,SetSlot,Branch , Label , LoadConstant ,SetSlot,
|
||||
Label,Label,RegisterTransfer,GetSlot,FunctionReturn]
|
||||
check
|
||||
end
|
||||
@ -34,7 +34,7 @@ class Object
|
||||
end
|
||||
HERE
|
||||
@expect = [Label, SaveReturn,LoadConstant,LoadConstant, OperatorInstruction,IsMinus ,
|
||||
Branch ,Label , LoadConstant ,
|
||||
Branch ,Label , LoadConstant ,SetSlot,
|
||||
Label,Label , RegisterTransfer,GetSlot,FunctionReturn]
|
||||
check
|
||||
end
|
||||
@ -51,7 +51,7 @@ class Object
|
||||
end
|
||||
HERE
|
||||
@expect = [Label, SaveReturn,LoadConstant,LoadConstant,OperatorInstruction,IsZero ,
|
||||
Branch , Label , LoadConstant ,
|
||||
Branch , Label , LoadConstant ,SetSlot,
|
||||
Label,Label, RegisterTransfer,GetSlot,FunctionReturn]
|
||||
check
|
||||
end
|
||||
|
@ -13,8 +13,12 @@ class Object
|
||||
end
|
||||
end
|
||||
HERE
|
||||
@expect = [Label, SaveReturn,LoadConstant ,Label,RegisterTransfer,GetSlot,FunctionReturn]
|
||||
check
|
||||
@expect = [Label, SaveReturn,LoadConstant ,SetSlot,Label,RegisterTransfer,GetSlot,FunctionReturn]
|
||||
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
|
||||
|
||||
def test_return_local
|
||||
@ -26,7 +30,7 @@ class Object
|
||||
end
|
||||
end
|
||||
HERE
|
||||
@expect = [Label, SaveReturn,GetSlot,GetSlot ,Label,RegisterTransfer,GetSlot,FunctionReturn]
|
||||
@expect = [Label, SaveReturn,GetSlot,GetSlot ,SetSlot,Label,RegisterTransfer,GetSlot,FunctionReturn]
|
||||
check
|
||||
end
|
||||
|
||||
@ -39,7 +43,7 @@ class Object
|
||||
end
|
||||
end
|
||||
HERE
|
||||
@expect = [Label, SaveReturn,LoadConstant,GetSlot,SetSlot,GetSlot,GetSlot ,
|
||||
@expect = [Label, SaveReturn,LoadConstant,GetSlot,SetSlot,GetSlot,GetSlot ,SetSlot,
|
||||
Label,RegisterTransfer,GetSlot,FunctionReturn]
|
||||
check
|
||||
end
|
||||
@ -53,7 +57,7 @@ class Object
|
||||
end
|
||||
end
|
||||
HERE
|
||||
@expect = [Label, SaveReturn,GetSlot,GetSlot ,Label,RegisterTransfer,GetSlot,FunctionReturn]
|
||||
@expect = [Label, SaveReturn,GetSlot,GetSlot ,SetSlot,Label,RegisterTransfer,GetSlot,FunctionReturn]
|
||||
check
|
||||
end
|
||||
|
||||
@ -66,7 +70,7 @@ class Object
|
||||
end
|
||||
HERE
|
||||
@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]
|
||||
check
|
||||
end
|
||||
|
@ -15,7 +15,7 @@ class Object
|
||||
end
|
||||
end
|
||||
HERE
|
||||
@expect = [Label, SaveReturn,Label,LoadConstant,IsPlus,LoadConstant,Branch,
|
||||
@expect = [Label, SaveReturn,Label,LoadConstant,IsPlus,LoadConstant,SetSlot,Branch,
|
||||
Label,Label,RegisterTransfer,GetSlot,FunctionReturn]
|
||||
check
|
||||
end
|
||||
@ -34,7 +34,7 @@ end
|
||||
HERE
|
||||
@expect = [Label, SaveReturn,LoadConstant,GetSlot,SetSlot,Label,GetSlot,GetSlot, IsPlus,GetSlot,
|
||||
GetSlot,LoadConstant,OperatorInstruction,GetSlot,SetSlot,Branch,
|
||||
Label,GetSlot,GetSlot,Label,RegisterTransfer,GetSlot,FunctionReturn]
|
||||
Label,GetSlot,GetSlot,SetSlot,Label,RegisterTransfer,GetSlot,FunctionReturn]
|
||||
check
|
||||
end
|
||||
|
||||
@ -54,7 +54,7 @@ HERE
|
||||
@expect = [Label, SaveReturn,LoadConstant,GetSlot,SetSlot,Label,
|
||||
GetSlot,GetSlot,LoadConstant,OperatorInstruction,IsPlus,
|
||||
GetSlot, GetSlot,LoadConstant,OperatorInstruction, GetSlot,
|
||||
SetSlot,GetSlot, GetSlot,Branch , Label ,
|
||||
SetSlot,GetSlot, GetSlot,SetSlot,Branch , Label ,
|
||||
Label , RegisterTransfer,GetSlot,FunctionReturn]
|
||||
check
|
||||
end
|
||||
|
@ -48,7 +48,7 @@ class AddTest < MiniTest::Test
|
||||
assert_equal Fixnum , right.class
|
||||
assert_equal 7 , right
|
||||
assert_equal 12 , left
|
||||
done_tr = ticks(2)
|
||||
done_tr = ticks(3)
|
||||
assert_equal Register::RegisterTransfer , done_tr.class
|
||||
result = @interpreter.get_register(done_op.left)
|
||||
assert_equal result , 12
|
||||
@ -58,16 +58,10 @@ class AddTest < MiniTest::Test
|
||||
#show_ticks # get output of what is
|
||||
["Branch","Label","LoadConstant","GetSlot","SetSlot",
|
||||
"RegisterTransfer","FunctionCall","Label","SaveReturn","LoadConstant",
|
||||
"LoadConstant","OperatorInstruction","Label","RegisterTransfer","GetSlot",
|
||||
"FunctionReturn","RegisterTransfer","Syscall","NilClass"].each_with_index do |name , index|
|
||||
"LoadConstant","OperatorInstruction","SetSlot","Label","RegisterTransfer",
|
||||
"GetSlot","FunctionReturn","RegisterTransfer","Syscall","NilClass"].each_with_index do |name , index|
|
||||
got = ticks(1)
|
||||
assert got.class.name.index(name) , "Wrong class for #{index+1}, expect #{name} , got #{got}"
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
# def test_exit
|
||||
# done = ticks(34)
|
||||
# assert_equal NilClass , done.class
|
||||
# end
|
||||
end
|
||||
|
@ -1,3 +1,4 @@
|
||||
require_relative "test_add"
|
||||
require_relative "test_if"
|
||||
require_relative "test_puts"
|
||||
require_relative "test_puti"
|
||||
require_relative "test_add"
|
||||
|
@ -32,17 +32,18 @@ HERE
|
||||
@interpreter.start Register.machine.init
|
||||
#show_ticks # get output of what is
|
||||
["Branch","Label","LoadConstant","GetSlot","SetSlot",
|
||||
"RegisterTransfer","FunctionCall","Label","SaveReturn","GetSlot",
|
||||
"GetSlot","SetSlot","LoadConstant","SetSlot","LoadConstant",
|
||||
"SetSlot","RegisterTransfer","FunctionCall","Label","SaveReturn",
|
||||
"GetSlot","LoadConstant","OperatorInstruction","IsZero","GetSlot",
|
||||
"LoadConstant","SetSlot","LoadConstant","SetSlot","RegisterTransfer",
|
||||
"FunctionCall","Label","SaveReturn","GetSlot","RegisterTransfer",
|
||||
"Syscall","RegisterTransfer","RegisterTransfer","SetSlot","Label",
|
||||
"RegisterTransfer","GetSlot","FunctionReturn","GetSlot","Branch",
|
||||
"Label","Label","RegisterTransfer","GetSlot","FunctionReturn",
|
||||
"GetSlot","Label","RegisterTransfer","GetSlot","FunctionReturn",
|
||||
"RegisterTransfer","Syscall","NilClass"].each_with_index do |name , index|
|
||||
"RegisterTransfer","FunctionCall","Label","SaveReturn","GetSlot",
|
||||
"GetSlot","SetSlot","LoadConstant","SetSlot","LoadConstant",
|
||||
"SetSlot","LoadConstant","SetSlot","RegisterTransfer","FunctionCall",
|
||||
"Label","SaveReturn","GetSlot","LoadConstant","OperatorInstruction",
|
||||
"IsZero","GetSlot","LoadConstant","SetSlot","LoadConstant",
|
||||
"SetSlot","LoadConstant","SetSlot","RegisterTransfer","FunctionCall",
|
||||
"Label","SaveReturn","GetSlot","RegisterTransfer","Syscall",
|
||||
"RegisterTransfer","RegisterTransfer","SetSlot","Label","RegisterTransfer",
|
||||
"GetSlot","FunctionReturn","GetSlot","Branch","Label",
|
||||
"Label","RegisterTransfer","GetSlot","FunctionReturn","GetSlot",
|
||||
"Label","RegisterTransfer","GetSlot","FunctionReturn","RegisterTransfer",
|
||||
"Syscall","NilClass"].each_with_index do |name , index|
|
||||
got = ticks(1)
|
||||
assert got.class.name.index(name) , "Wrong class for #{index+1}, expect #{name} , got #{got}"
|
||||
end
|
||||
|
@ -74,18 +74,19 @@ HERE
|
||||
"GetSlot","SetSlot","RegisterTransfer","FunctionCall","Label",
|
||||
"SaveReturn","GetSlot","LoadConstant","OperatorInstruction","IsZero",
|
||||
"Branch","Label","GetSlot","LoadConstant","OperatorInstruction",
|
||||
"IsZero","Label","LoadConstant","Label","GetSlot",
|
||||
"LoadConstant","OperatorInstruction","IsZero","Label","LoadConstant",
|
||||
"IsZero","Label","LoadConstant","SetSlot","Label",
|
||||
"GetSlot","LoadConstant","OperatorInstruction","IsZero","Label",
|
||||
"LoadConstant","SetSlot","Label","GetSlot","LoadConstant",
|
||||
"OperatorInstruction","IsZero","Label","LoadConstant","SetSlot",
|
||||
"Label","GetSlot","LoadConstant","OperatorInstruction","IsZero",
|
||||
"Label","LoadConstant","Label","GetSlot","LoadConstant",
|
||||
"OperatorInstruction","IsZero","Label","LoadConstant","Label",
|
||||
"Label","LoadConstant","SetSlot","Label","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",
|
||||
"GetSlot","SetSlot","GetSlot","GetSlot","GetSlot",
|
||||
"OperatorInstruction","SetSlot","Label","GetSlot","Label",
|
||||
"RegisterTransfer","GetSlot","FunctionReturn","GetSlot","Label",
|
||||
"RegisterTransfer","GetSlot","FunctionReturn","GetSlot","Label",
|
||||
"RegisterTransfer","GetSlot","FunctionReturn","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)
|
||||
assert got.class.name.index(name) , "Wrong class for #{index+1}, expect #{name} , got #{got}"
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user