diff --git a/lib/virtual/compiler/basic_expressions.rb b/lib/virtual/compiler/basic_expressions.rb index 2e9173a0..7a74699e 100644 --- a/lib/virtual/compiler/basic_expressions.rb +++ b/lib/virtual/compiler/basic_expressions.rb @@ -64,7 +64,7 @@ module Virtual raise "oh noo, nil from where #{expression.right.inspect}" unless r index = method.has_arg(expression.left.name.to_sym) if index - method.source.add_code Set.new(MessageSlot.new(index , r,type , r ) , Return.new) + method.source.add_code Set.new(ArgSlot.new(index , r.type , r ) , Return.new) else index = method.ensure_local(expression.left.name.to_sym) method.source.add_code Set.new(FrameSlot.new(index , r.type , r ) , Return.new) diff --git a/lib/virtual/compiler/name_expression.rb b/lib/virtual/compiler/name_expression.rb index abbd4446..cf68d2e2 100644 --- a/lib/virtual/compiler/name_expression.rb +++ b/lib/virtual/compiler/name_expression.rb @@ -10,11 +10,14 @@ module Virtual name = expression.name.to_sym if method.has_var(name) # either an argument, so it's stored in message + ret = Return.new if( index = method.has_arg(name)) - method.source.add_code Set.new( MessageSlot.new(expression.name) , Return.new) + method.source.add_code Set.new( ArgSlot.new(index ) , ret) else # or a local so it is in the frame - method.source.add_code FrameGet.new(expression.name , index) + index = method.ensure_local( name ) + method.source.add_code Set.new(FrameSlot.new(index ) , ret ) end + return ret else call = Ast::CallSiteExpression.new(expression.name , [] ) #receiver self is implicit Compiler.compile(call, method) diff --git a/lib/virtual/slots/message_slot.rb b/lib/virtual/slots/message_slot.rb index 0ff8c605..5bdc052c 100644 --- a/lib/virtual/slots/message_slot.rb +++ b/lib/virtual/slots/message_slot.rb @@ -37,4 +37,15 @@ module Virtual super( type , value ) end end + + # NewMessageName of the next message + class ArgSlot < MessageSlot + def initialize index , type = Unknown, value = nil + @index = index + super( type , value ) + end + attr_reader :index + end + + end diff --git a/test/fragments/test_all.rb b/test/fragments/test_all.rb index c8743bb1..7086be1a 100644 --- a/test/fragments/test_all.rb +++ b/test/fragments/test_all.rb @@ -1,7 +1,7 @@ require_relative "test_foo" require_relative "test_if" -#require_relative "test_functions" +require_relative "test_functions" #require_relative "test_hello" #require_relative "test_putint" #require_relative "test_recursive_fibo" diff --git a/test/fragments/test_if.rb b/test/fragments/test_if.rb index 3ac3d5a7..629e9034 100644 --- a/test/fragments/test_if.rb +++ b/test/fragments/test_if.rb @@ -24,7 +24,7 @@ HERE end - def ttest_if_function + def test_if_function @string_input = <