remove MethodCall and thus all virtual instructions

This commit is contained in:
Torsten Ruger 2015-10-18 19:27:46 +03:00
parent 15b570f5cf
commit d767caf479
20 changed files with 24 additions and 72 deletions

View File

@ -38,7 +38,7 @@ module Phisol
method = clazz.get_instance_method(name)
#puts Virtual.machine.space.get_class_by_name(:Integer).method_names.to_a
raise "Method not implemented #{me.type}.#{name}" unless method
@method.source.add_code Virtual::MethodCall.new( method )
Register.issue_call( @method , method )
ret = use_reg( method.source.return_type )
# the effect of the method is that the NewMessage Return slot will be filled, return it
# but move it into a register too

View File

@ -42,7 +42,6 @@ module Phisol
kids.to_a.each do |ex|
ret = process(ex)
raise ret.inspect if ret.is_a? Virtual::Instruction
end
@method = nil
# function definition is a statement, does not return any value

View File

@ -21,7 +21,7 @@ module Register
# And store the space as the new self (so the call can move it back as self)
function.source.add_code Register.set_slot( function, space_reg , :new_message , :receiver)
# now we are set up to issue a call to the main
function.source.add_code Virtual::MethodCall.new(Virtual.machine.space.get_main)
Register.issue_call( function , Virtual.machine.space.get_main)
emit_syscall( function , :exit )
return function
end

View File

@ -13,6 +13,12 @@ module Register
def to_s
"FunctionCall: #{method.name}"
end
end
def self.issue_call caller , callee
# move the current new_message to message
caller.source.add_code RegisterTransfer.new(caller, Register.new_message_reg , Register.message_reg )
# do the register call
caller.source.add_code FunctionCall.new( caller , callee )
end
end

View File

@ -1,24 +0,0 @@
module Register
# Defines the method call, ie
# - move the new_message to message
# - unroll self and
# - register call
# all in all, quite the reverse of a return
class CallImplementation
def run block
block.codes.dup.each do |code|
next unless code.is_a? Virtual::MethodCall
new_codes = []
# move the current new_message to message
new_codes << RegisterTransfer.new(code, Register.new_message_reg , Register.message_reg )
# do the register call
new_codes << FunctionCall.new( code , code.method )
block.replace(code , new_codes )
end
end
end
Virtual.machine.add_pass "Register::CallImplementation"
end

View File

@ -1,7 +1,6 @@
require_relative "instruction"
require_relative "register_value"
require_relative "assembler"
require_relative "passes/call_implementation"
# So the memory model of the machine allows for indexed access into an "object" .
# A fixed number of objects exist (ie garbage collection is reclaming, not destroying and

View File

@ -1,16 +0,0 @@
module Virtual
# Instruction is an abstract for all the code of the object-machine.
# Derived classes make up the actual functionality of the machine.
# All functions on the machine are captured as instances of instructions
#
# It is actually the point of the virtual machine layer to express oo functionality in the set of
# instructions, thus defining a minimal set of instructions needed to implement oo.
class Instruction
end
end
require_relative "instructions/method_call"

View File

@ -1,12 +0,0 @@
module Virtual
# MethodCall involves shuffling some registers about and doing a machine call
class MethodCall < Instruction
def initialize method
@method = method
end
attr_reader :method
end
end

View File

@ -81,7 +81,7 @@ module Virtual
# add an instruction after the current (insertion point)
# the added instruction will become the new insertion point
def add_code instruction
unless (instruction.is_a?(Instruction) or instruction.is_a?(Register::Instruction))
unless instruction.is_a?(Register::Instruction)
raise instruction.to_s
end
@current.add_code(instruction) #insert after current

View File

@ -17,7 +17,7 @@ class Object
end
HERE
@expect = [ [SaveReturn,Register::GetSlot,Virtual::Set,Virtual::Set,
Virtual::Set,Virtual::Set,Virtual::MethodCall] ,[RegisterTransfer,GetSlot,FunctionReturn] ]
Virtual::Set,Virtual::Set,RegisterTransfer,FunctionCall] ,[RegisterTransfer,GetSlot,FunctionReturn] ]
check
end

View File

@ -35,7 +35,7 @@ class Object
end
end
HERE
@expect = [[SaveReturn,Register::GetSlot,Virtual::Set,Virtual::Set,Virtual::MethodCall] ,
@expect = [[SaveReturn,Register::GetSlot,Virtual::Set,Virtual::Set,RegisterTransfer,FunctionCall] ,
[RegisterTransfer,GetSlot,FunctionReturn]]
check

View File

@ -12,7 +12,7 @@ class Object
end
HERE
@expect = [[SaveReturn,Virtual::Set,Register::GetSlot,Virtual::Set,
Virtual::Set,Virtual::MethodCall] ,[RegisterTransfer,GetSlot,FunctionReturn]]
Virtual::Set,RegisterTransfer,FunctionCall] ,[RegisterTransfer,GetSlot,FunctionReturn]]
check
end
end

View File

@ -52,7 +52,7 @@ class Object
end
HERE
@expect = [ [SaveReturn,Register::GetSlot,Virtual::Set,Virtual::Set,
Virtual::Set,Virtual::Set,Virtual::MethodCall] ,[RegisterTransfer,GetSlot,FunctionReturn] ]
Virtual::Set,Virtual::Set,RegisterTransfer,FunctionCall] ,[RegisterTransfer,GetSlot,FunctionReturn] ]
check
end
end

View File

@ -17,7 +17,7 @@ class Object
end
HERE
@expect = [ [SaveReturn,Virtual::Set,Register::GetSlot,Virtual::Set,
Virtual::Set,Virtual::MethodCall] ,[RegisterTransfer,GetSlot,FunctionReturn] ]
Virtual::Set,RegisterTransfer,FunctionCall] ,[RegisterTransfer,GetSlot,FunctionReturn] ]
check
end
end

View File

@ -28,7 +28,7 @@ class Object
end
HERE
@expect = [[SaveReturn,Register::GetSlot,Virtual::Set,Virtual::Set,
Virtual::Set,Virtual::Set,Virtual::MethodCall] , [RegisterTransfer,GetSlot,FunctionReturn]]
Virtual::Set,Virtual::Set,RegisterTransfer,FunctionCall] , [RegisterTransfer,GetSlot,FunctionReturn]]
check
end
end

View File

@ -25,7 +25,7 @@ class Object
end
HERE
@expect = [ [SaveReturn,Register::GetSlot,Virtual::Set,Virtual::Set,
Virtual::Set,Virtual::Set,Virtual::MethodCall] ,[RegisterTransfer,GetSlot,FunctionReturn] ]
Virtual::Set,Virtual::Set,RegisterTransfer,FunctionCall] ,[RegisterTransfer,GetSlot,FunctionReturn] ]
check
end

View File

@ -80,7 +80,7 @@ class Object
end
HERE
@expect = [[SaveReturn,GetSlot,GetSlot,SetSlot, LoadConstant,SetSlot,
Virtual::MethodCall,GetSlot,GetSlot,SetSlot] , [RegisterTransfer,GetSlot,FunctionReturn]]
RegisterTransfer,FunctionCall,GetSlot,GetSlot,SetSlot] , [RegisterTransfer,GetSlot,FunctionReturn]]
check
end
end

View File

@ -18,7 +18,7 @@ class Object
end
HERE
@expect = [[SaveReturn,GetSlot,LoadConstant,
SetSlot,LoadConstant,SetSlot,Virtual::MethodCall,GetSlot] ,
SetSlot,LoadConstant,SetSlot,RegisterTransfer,FunctionCall,GetSlot] ,
[RegisterTransfer,GetSlot,FunctionReturn]]
check
end
@ -38,7 +38,7 @@ class Object
end
HERE
@expect = [[SaveReturn,GetSlot,LoadConstant,
SetSlot,LoadConstant,SetSlot,Virtual::MethodCall,GetSlot] ,
SetSlot,LoadConstant,SetSlot,RegisterTransfer,FunctionCall,GetSlot] ,
[RegisterTransfer,GetSlot,FunctionReturn]]
check
end
@ -58,7 +58,7 @@ class Object
end
HERE
@expect = [ [SaveReturn,LoadConstant,GetSlot,SetSlot,GetSlot,
GetSlot,GetSlot,SetSlot,LoadConstant,SetSlot,Virtual::MethodCall,
GetSlot,GetSlot,SetSlot,LoadConstant,SetSlot,RegisterTransfer,FunctionCall,
GetSlot] ,[RegisterTransfer,GetSlot,FunctionReturn] ]
check
end
@ -78,7 +78,7 @@ class Object
end
HERE
@expect = [ [SaveReturn,GetSlot,GetSlot,GetSlot,SetSlot,
LoadConstant,SetSlot,Virtual::MethodCall,
LoadConstant,SetSlot,RegisterTransfer,FunctionCall,
GetSlot] ,[RegisterTransfer,GetSlot,FunctionReturn] ]
check
end
@ -95,7 +95,7 @@ end
end
HERE
@expect = [ [SaveReturn , GetSlot,GetSlot,SetSlot,LoadConstant,SetSlot,LoadConstant,
SetSlot,Virtual::MethodCall,GetSlot],
SetSlot,RegisterTransfer,FunctionCall,GetSlot],
[RegisterTransfer,GetSlot,FunctionReturn]]
check
end

View File

@ -55,7 +55,7 @@ class Object
end
HERE
@expect = [ [SaveReturn,GetSlot,SetSlot,LoadConstant,
SetSlot,LoadConstant,SetSlot,Virtual::MethodCall,
SetSlot,LoadConstant,SetSlot,RegisterTransfer,FunctionCall,
GetSlot] ,[RegisterTransfer,GetSlot,FunctionReturn] ]
check
end

View File

@ -66,7 +66,7 @@ class Object
end
HERE
@expect = [[SaveReturn,GetSlot,GetSlot,SetSlot, LoadConstant,
SetSlot,Virtual::MethodCall,GetSlot] , [RegisterTransfer,GetSlot,FunctionReturn]]
SetSlot,RegisterTransfer,FunctionCall,GetSlot] , [RegisterTransfer,GetSlot,FunctionReturn]]
check
end
end