diff --git a/lib/virtual/compiled_method_info.rb b/lib/virtual/compiled_method_info.rb index 0065eca8..98e3b92d 100644 --- a/lib/virtual/compiled_method_info.rb +++ b/lib/virtual/compiled_method_info.rb @@ -40,16 +40,17 @@ module Virtual clazz = Virtual.machine.space.get_class_by_name class_name raise "No such class #{class_name}" unless clazz method = clazz.create_instance_method( method_name , Virtual.new_list(args)) - method.info = CompiledMethodInfo.new + method.info = CompiledMethodInfo.new(method) method end - def initialize return_type = Virtual::Unknown + # just passing the method object in for Instructions to make decisions (later) + def initialize method , return_type = Virtual::Unknown # first block we have to create with .new , as new_block assumes a current - enter = Block.new( "enter" , self ).add_code(MethodEnter.new()) + enter = Block.new( "enter" , self ).add_code(MethodEnter.new( method )) @return_type = return_type @blocks = [enter] @current = enter - new_block("return").add_code(MethodReturn.new) + new_block("return").add_code(MethodReturn.new(method)) @constants = [] end attr_reader :blocks , :constants diff --git a/lib/virtual/instructions/method_enter.rb b/lib/virtual/instructions/method_enter.rb index 89ecef12..5c853da4 100644 --- a/lib/virtual/instructions/method_enter.rb +++ b/lib/virtual/instructions/method_enter.rb @@ -2,6 +2,11 @@ module Virtual # following classes are stubs. currently in brainstorming mode, so anything may change anytime class MethodEnter < Instruction + def initialize method + @method = method + end + + attr_reader :method end end diff --git a/lib/virtual/instructions/method_return.rb b/lib/virtual/instructions/method_return.rb index 16622bd6..5ce6f58f 100644 --- a/lib/virtual/instructions/method_return.rb +++ b/lib/virtual/instructions/method_return.rb @@ -3,6 +3,12 @@ module Virtual # also the return shuffles our objects beck before actually transferring control class MethodReturn < Instruction + def initialize method + @method = method + end + + attr_reader :method + end end diff --git a/lib/virtual/passes/enter_implementation.rb b/lib/virtual/passes/enter_implementation.rb index 72e51c8a..2420d9ae 100644 --- a/lib/virtual/passes/enter_implementation.rb +++ b/lib/virtual/passes/enter_implementation.rb @@ -8,7 +8,9 @@ module Virtual # save return register and create a new frame # lr is link register, ie where arm stores the return address when call is issued new_codes << Register::SaveReturn.new( Register::RegisterReference.message_reg , Virtual::RETURN_INDEX ) - new_codes << Virtual::NewFrame.new + unless code.method.locals.empty? and code.method.tmps.empty? + new_codes << Virtual::NewFrame.new + end block.replace(code , new_codes ) end end