giving the method to return and save

so they can make decisions
like wether to create a frame or not
This commit is contained in:
Torsten Ruger 2015-06-28 22:03:21 +03:00
parent 02615db508
commit a16abeb3e6
4 changed files with 19 additions and 5 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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