diff --git a/lib/ast/function_expression.rb b/lib/ast/function_expression.rb index f4ab6d55..a99580c6 100644 --- a/lib/ast/function_expression.rb +++ b/lib/ast/function_expression.rb @@ -8,7 +8,8 @@ module Ast frame = frame.new_frame return_type = nil body.each do |ex| - return_type = ex.compile(frame , method ) + val = ex.compile(frame , method ) + return_type = val.type end method.return_type = return_type method diff --git a/lib/virtual/instruction.rb b/lib/virtual/instruction.rb index 3011094d..7edb5f65 100644 --- a/lib/virtual/instruction.rb +++ b/lib/virtual/instruction.rb @@ -18,6 +18,9 @@ module Virtual def initialize nex = nil @next = nex end + def type + Reference + end end # the first instruction we need is to stop. Off course in a real machine this would be a syscall, but that is just diff --git a/test/virtual/test_methods.rb b/test/virtual/test_methods.rb index 4a0b6d3f..832aab86 100644 --- a/test/virtual/test_methods.rb +++ b/test/virtual/test_methods.rb @@ -19,7 +19,7 @@ def String.length(x) @length end HERE - @output = [Virtual::Method.new(:length,[Ast::NameExpression.new(:x)],Boot::BootClass.new(:String,:Object))] + @output = [Virtual::Method.new(:length,[Ast::NameExpression.new(:x)],Boot::BootClass.new(:String,:Object),Virtual::Reference,Virtual::MethodEnter.new(Virtual::FrameSend.new(:_get_instance_variable , [ Virtual::StringConstant.new('length')])))] check end