remove MethodCall and thus all virtual instructions
This commit is contained in:
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
@ -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
|
||||
|
@ -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"
|
@ -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
|
@ -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
|
||||
|
Reference in New Issue
Block a user