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 clazz = Virtual.machine.space.get_class_by_name class_name
raise "No such class #{class_name}" unless clazz raise "No such class #{class_name}" unless clazz
method = clazz.create_instance_method( method_name , Virtual.new_list(args)) method = clazz.create_instance_method( method_name , Virtual.new_list(args))
method.info = CompiledMethodInfo.new method.info = CompiledMethodInfo.new(method)
method method
end 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 # 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 @return_type = return_type
@blocks = [enter] @blocks = [enter]
@current = enter @current = enter
new_block("return").add_code(MethodReturn.new) new_block("return").add_code(MethodReturn.new(method))
@constants = [] @constants = []
end end
attr_reader :blocks , :constants 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 # following classes are stubs. currently in brainstorming mode, so anything may change anytime
class MethodEnter < Instruction class MethodEnter < Instruction
def initialize method
@method = method
end
attr_reader :method
end end
end end

View File

@ -3,6 +3,12 @@ module Virtual
# also the return shuffles our objects beck before actually transferring control # also the return shuffles our objects beck before actually transferring control
class MethodReturn < Instruction class MethodReturn < Instruction
def initialize method
@method = method
end
attr_reader :method
end end
end end

View File

@ -8,7 +8,9 @@ module Virtual
# save return register and create a new frame # save return register and create a new frame
# lr is link register, ie where arm stores the return address when call is issued # 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 << 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 ) block.replace(code , new_codes )
end end
end end