diff --git a/lib/soml/compiler/call_site.rb b/lib/soml/compiler/call_site.rb index 0a434958..873dd523 100644 --- a/lib/soml/compiler/call_site.rb +++ b/lib/soml/compiler/call_site.rb @@ -28,7 +28,12 @@ module Soml name_tmp = use_reg(:Word) add_code Register::LoadConstant.new(statement, name , name_tmp) add_code Register.set_slot( statement , name_tmp , :new_message , :name) - # next arguments. reset tmp regs for each and load result into new_message + # next arguments. first length then args + len_tmp = use_reg(:Integer , arguments.to_a.length ) + add_code Register::LoadConstant.new(statement, arguments.to_a.length , len_tmp) + add_code Register.set_slot( statement , len_tmp , :new_message , :indexed_length) + + # reset tmp regs for each and load result into new_message arguments.to_a.each_with_index do |arg , i| reset_regs # processing should return the register with the value diff --git a/test/compiler/fragments/test_foo.rb b/test/compiler/fragments/test_foo.rb index 89bcd3b1..b361d35d 100644 --- a/test/compiler/fragments/test_foo.rb +++ b/test/compiler/fragments/test_foo.rb @@ -16,7 +16,7 @@ class Object end end HERE - @length = 36 + @length = 38 check end diff --git a/test/compiler/fragments/test_functions.rb b/test/compiler/fragments/test_functions.rb index 4c91b8dc..428dc121 100644 --- a/test/compiler/fragments/test_functions.rb +++ b/test/compiler/fragments/test_functions.rb @@ -28,7 +28,7 @@ class Object end end HERE - @length = 179 + @length = 191 check end diff --git a/test/compiler/fragments/test_hello.rb b/test/compiler/fragments/test_hello.rb index 3e4c2a46..de24c801 100644 --- a/test/compiler/fragments/test_hello.rb +++ b/test/compiler/fragments/test_hello.rb @@ -11,7 +11,7 @@ class Object end end HERE - @length = 35 + @length = 37 @stdout = "Hello Raisa, I am salama" check end diff --git a/test/compiler/fragments/test_if.rb b/test/compiler/fragments/test_if.rb index 1a4950bf..da6cfb11 100644 --- a/test/compiler/fragments/test_if.rb +++ b/test/compiler/fragments/test_if.rb @@ -31,7 +31,7 @@ class Object end end HERE - @length = 45 + @length = 47 @stdout = "10" check end @@ -53,7 +53,7 @@ class Object end end HERE - @length = 57 + @length = 61 @stdout = "else" check end diff --git a/test/compiler/fragments/test_putint.rb b/test/compiler/fragments/test_putint.rb index 73b60281..50664148 100644 --- a/test/compiler/fragments/test_putint.rb +++ b/test/compiler/fragments/test_putint.rb @@ -16,7 +16,7 @@ class Object end end HERE - @length = 30 + @length = 32 check end end diff --git a/test/compiler/fragments/test_recursive_fibo.rb b/test/compiler/fragments/test_recursive_fibo.rb index 9ad6a11b..158129fb 100644 --- a/test/compiler/fragments/test_recursive_fibo.rb +++ b/test/compiler/fragments/test_recursive_fibo.rb @@ -27,7 +27,7 @@ class Object end end HERE - @length = 71 + @length = 77 check end end diff --git a/test/compiler/statements/test_assign.rb b/test/compiler/statements/test_assign.rb index 8fd8f90d..972d1f23 100644 --- a/test/compiler/statements/test_assign.rb +++ b/test/compiler/statements/test_assign.rb @@ -55,7 +55,7 @@ class Object end HERE @expect = [Label, SaveReturn,GetSlot,GetSlot,SetSlot, LoadConstant,SetSlot, - RegisterTransfer,FunctionCall,GetSlot,GetSlot,SetSlot , + LoadConstant,SetSlot,RegisterTransfer,FunctionCall,GetSlot,GetSlot,SetSlot , Label,RegisterTransfer,GetSlot,FunctionReturn] check end diff --git a/test/compiler/statements/test_call.rb b/test/compiler/statements/test_call.rb index 1daf9cae..a770a654 100644 --- a/test/compiler/statements/test_call.rb +++ b/test/compiler/statements/test_call.rb @@ -18,7 +18,7 @@ class Object end HERE @expect = [Label, SaveReturn,GetSlot,LoadConstant, - SetSlot,LoadConstant,SetSlot,RegisterTransfer,FunctionCall,GetSlot , + SetSlot,LoadConstant,SetSlot,LoadConstant,SetSlot,RegisterTransfer,FunctionCall,GetSlot , Label,RegisterTransfer,GetSlot,FunctionReturn] check end @@ -38,7 +38,7 @@ class Object end HERE @expect = [Label, SaveReturn,GetSlot,LoadConstant, - SetSlot,LoadConstant,SetSlot,RegisterTransfer,FunctionCall,GetSlot , + SetSlot,LoadConstant,SetSlot,LoadConstant,SetSlot,RegisterTransfer,FunctionCall,GetSlot , Label,RegisterTransfer,GetSlot,FunctionReturn] check end @@ -58,7 +58,7 @@ class Object end HERE @expect = [ Label, SaveReturn,LoadConstant,GetSlot,SetSlot,GetSlot, - GetSlot,GetSlot,SetSlot,LoadConstant,SetSlot,RegisterTransfer,FunctionCall, + GetSlot,GetSlot,SetSlot,LoadConstant,SetSlot,LoadConstant,SetSlot,RegisterTransfer,FunctionCall, GetSlot ,Label,RegisterTransfer,GetSlot,FunctionReturn] check end @@ -78,7 +78,7 @@ class Object end HERE @expect = [ Label, SaveReturn,GetSlot,GetSlot,GetSlot,SetSlot, - LoadConstant,SetSlot,RegisterTransfer,FunctionCall, + LoadConstant,SetSlot,LoadConstant,SetSlot,RegisterTransfer,FunctionCall, GetSlot ,Label,RegisterTransfer,GetSlot,FunctionReturn] check end @@ -95,12 +95,12 @@ end end HERE @expect = [ Label, SaveReturn , GetSlot,GetSlot,SetSlot,LoadConstant,SetSlot,LoadConstant, - SetSlot,RegisterTransfer,FunctionCall,GetSlot, + SetSlot,LoadConstant,SetSlot,RegisterTransfer,FunctionCall,GetSlot, Label,RegisterTransfer,GetSlot,FunctionReturn] was = check set = was.next(8) assert_equal SetSlot , set.class - assert_equal 10, 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 diff --git a/test/compiler/statements/test_class.rb b/test/compiler/statements/test_class.rb index e8aab309..07da0bec 100644 --- a/test/compiler/statements/test_class.rb +++ b/test/compiler/statements/test_class.rb @@ -34,7 +34,7 @@ class Object end end HERE - @expect = [Label, SaveReturn,GetSlot,LoadConstant,SetSlot,LoadConstant,SetSlot, + @expect = [Label, SaveReturn,GetSlot,LoadConstant,SetSlot,LoadConstant,SetSlot,LoadConstant,SetSlot, RegisterTransfer,FunctionCall,GetSlot,Label,RegisterTransfer,GetSlot,FunctionReturn] check end diff --git a/test/compiler/statements/test_return.rb b/test/compiler/statements/test_return.rb index 09bd77dc..5989f703 100644 --- a/test/compiler/statements/test_return.rb +++ b/test/compiler/statements/test_return.rb @@ -66,7 +66,8 @@ class Object end HERE @expect = [Label, SaveReturn,GetSlot,GetSlot,SetSlot, LoadConstant, - SetSlot,RegisterTransfer,FunctionCall,GetSlot ,Label,RegisterTransfer,GetSlot,FunctionReturn] + SetSlot,LoadConstant,SetSlot,RegisterTransfer,FunctionCall,GetSlot ,Label, + RegisterTransfer,GetSlot,FunctionReturn] check end end diff --git a/test/interpreter/test_puti.rb b/test/interpreter/test_puti.rb index 7815e98c..c30e7664 100644 --- a/test/interpreter/test_puti.rb +++ b/test/interpreter/test_puti.rb @@ -61,29 +61,31 @@ HERE #show_ticks # get output of what is ["Branch","Label","LoadConstant","GetSlot","SetSlot", "RegisterTransfer","FunctionCall","Label","SaveReturn","GetSlot", - "LoadConstant","SetSlot","LoadConstant","SetSlot","RegisterTransfer", - "FunctionCall","Label","SaveReturn","LoadConstant","GetSlot", - "SetSlot","GetSlot","GetSlot","SetSlot","LoadConstant", - "SetSlot","GetSlot","GetSlot","SetSlot","RegisterTransfer", - "FunctionCall","Label","SaveReturn","GetSlot","LoadConstant", - "OperatorInstruction","GetSlot","SetSlot","GetSlot","GetSlot", - "GetSlot","OperatorInstruction","GetSlot","SetSlot","GetSlot", - "GetSlot","IsNotzero","Label","GetSlot","GetSlot", - "SetSlot","LoadConstant","SetSlot","GetSlot","GetSlot", + "LoadConstant","SetSlot","LoadConstant","SetSlot","LoadConstant", "SetSlot","RegisterTransfer","FunctionCall","Label","SaveReturn", - "GetSlot","LoadConstant","OperatorInstruction","IsZero","Branch", + "LoadConstant","GetSlot","SetSlot","GetSlot","GetSlot", + "SetSlot","LoadConstant","SetSlot","LoadConstant","SetSlot", + "GetSlot","GetSlot","SetSlot","RegisterTransfer","FunctionCall", + "Label","SaveReturn","GetSlot","LoadConstant","OperatorInstruction", + "GetSlot","SetSlot","GetSlot","GetSlot","GetSlot", + "OperatorInstruction","GetSlot","SetSlot","GetSlot","GetSlot", + "IsNotzero","Label","GetSlot","GetSlot","SetSlot", + "LoadConstant","SetSlot","LoadConstant","SetSlot","GetSlot", + "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", "Label","GetSlot","LoadConstant","OperatorInstruction","IsZero", "Label","LoadConstant","Label","GetSlot","LoadConstant", "OperatorInstruction","IsZero","Label","LoadConstant","Label", - "GetSlot","LoadConstant","OperatorInstruction","IsZero","Label", - "LoadConstant","Label","GetSlot","LoadConstant","OperatorInstruction", - "IsZero","Label","LoadConstant","Label","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","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| got = ticks(1) assert got.class.name.index(name) , "Wrong class for #{index+1}, expect #{name} , got #{got}" end diff --git a/test/interpreter/test_puts.rb b/test/interpreter/test_puts.rb index 210b8ac2..e01d8b4f 100644 --- a/test/interpreter/test_puts.rb +++ b/test/interpreter/test_puts.rb @@ -59,12 +59,12 @@ class TestPuts < MiniTest::Test #show_ticks # get output of what is [ "Branch","Label","LoadConstant","GetSlot","SetSlot", "RegisterTransfer","FunctionCall","Label","SaveReturn","GetSlot", - "LoadConstant","SetSlot","LoadConstant","SetSlot","RegisterTransfer", - "FunctionCall","Label","SaveReturn","GetSlot","RegisterTransfer", - "Syscall","RegisterTransfer","RegisterTransfer","SetSlot","Label", - "RegisterTransfer","GetSlot","FunctionReturn","GetSlot","Label", - "RegisterTransfer","GetSlot","FunctionReturn","RegisterTransfer","Syscall", - "NilClass"].each_with_index do |name , index| + "LoadConstant","SetSlot","LoadConstant","SetSlot","LoadConstant", + "SetSlot","RegisterTransfer","FunctionCall","Label","SaveReturn", + "GetSlot","RegisterTransfer","Syscall","RegisterTransfer","RegisterTransfer", + "SetSlot","Label","RegisterTransfer","GetSlot","FunctionReturn", + "GetSlot","Label","RegisterTransfer","GetSlot","FunctionReturn", + "RegisterTransfer","Syscall","NilClass"].each_with_index do |name , index| got = ticks(1) #puts "TICK #{index}" assert got.class.name.index(name) , "Wrong class for #{index+1}, expect #{name} , got #{got}" @@ -72,20 +72,20 @@ class TestPuts < MiniTest::Test end def test_putstring - done = ticks(21) + done = ticks(23) assert_equal Register::Syscall , done.class assert_equal "Hello again" , @interpreter.stdout end def test_return - done = ticks(28) + done = ticks(30) assert_equal Register::FunctionReturn , done.class assert Register::Label , @interpreter.instruction.class assert @interpreter.instruction.is_a?(Register::Instruction) , "not instruction #{@interpreter.instruction}" end def test_exit - done = ticks(36) + done = ticks(38) assert_equal NilClass , done.class assert_equal "Hello again" , @interpreter.stdout end