remove MethodEnter Instructions
only resolved to SaveReturn anyway also Halt instruction wasn’t used, gone passes changed to start at register
This commit is contained in:
parent
8bf1337043
commit
fa4949fc80
@ -11,7 +11,6 @@ require "virtual/method_source"
|
||||
# the passes _are_ order dependant
|
||||
require "virtual/passes/minimizer"
|
||||
require "virtual/passes/collector"
|
||||
require "virtual/passes/enter_implementation"
|
||||
|
||||
|
||||
class Fixnum
|
||||
|
@ -13,6 +13,4 @@ module Virtual
|
||||
|
||||
end
|
||||
|
||||
require_relative "instructions/halt"
|
||||
require_relative "instructions/method_call"
|
||||
require_relative "instructions/method_enter"
|
||||
|
@ -1,12 +0,0 @@
|
||||
module Virtual
|
||||
|
||||
|
||||
# the first instruction we need is to stop. Off course in a real machine this would be a syscall,
|
||||
# but that is just an implementation (in a programm it would be a function).
|
||||
# But in a virtual machine, not only do we need this instruction,
|
||||
# it is indeed the first instruction as just this instruction is the smallest possible programm
|
||||
# for the machine.
|
||||
# As such it is the next instruction for any first instruction that we generate.
|
||||
class Halt < Instruction
|
||||
end
|
||||
end
|
@ -1,12 +0,0 @@
|
||||
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
|
@ -36,8 +36,7 @@ module Virtual
|
||||
|
||||
class Machine
|
||||
|
||||
FIRST_PASS = "Virtual::EnterImplementation"
|
||||
LAST_PASS = "Virtual::SetOptimisation"
|
||||
FIRST_PASS = "Register::CallImplementation"
|
||||
|
||||
def initialize
|
||||
@parser = Parser::Salama.new
|
||||
|
@ -56,7 +56,8 @@ module Virtual
|
||||
|
||||
def init method , return_type = nil
|
||||
# first block we have to create with .new , as new_block assumes a current
|
||||
enter = Block.new( "enter" , method ).add_code(MethodEnter.new( method ))
|
||||
enter = Block.new( "enter" , method )
|
||||
enter.add_code Register.save_return(self, :message , :return_address)
|
||||
set_return_type( return_type )
|
||||
@blocks = [enter]
|
||||
@current = enter
|
||||
|
@ -1,15 +0,0 @@
|
||||
module Virtual
|
||||
|
||||
class EnterImplementation
|
||||
def run block
|
||||
block.codes.dup.each do |code|
|
||||
next unless code.is_a? Virtual::MethodEnter
|
||||
new_codes = []
|
||||
# save return register to the message at instance return_address
|
||||
new_codes << Register.save_return(code, :message , :return_address)
|
||||
block.replace(code , new_codes )
|
||||
end
|
||||
end
|
||||
end
|
||||
Virtual.machine.add_pass "Virtual::EnterImplementation"
|
||||
end
|
@ -11,7 +11,7 @@ class Bar
|
||||
end
|
||||
end
|
||||
HERE
|
||||
@expect = [ [Virtual::MethodEnter] ,[RegisterTransfer,GetSlot,FunctionReturn]]
|
||||
@expect = [ [SaveReturn] ,[RegisterTransfer,GetSlot,FunctionReturn]]
|
||||
check
|
||||
end
|
||||
|
||||
|
@ -16,7 +16,7 @@ class Object
|
||||
end
|
||||
end
|
||||
HERE
|
||||
@expect = [ [Virtual::MethodEnter,Register::GetSlot,Virtual::Set,Virtual::Set,
|
||||
@expect = [ [SaveReturn,Register::GetSlot,Virtual::Set,Virtual::Set,
|
||||
Virtual::Set,Virtual::Set,Virtual::MethodCall] ,[RegisterTransfer,GetSlot,FunctionReturn] ]
|
||||
check
|
||||
end
|
||||
|
@ -35,7 +35,7 @@ class Object
|
||||
end
|
||||
end
|
||||
HERE
|
||||
@expect = [[Virtual::MethodEnter,Register::GetSlot,Virtual::Set,Virtual::Set,Virtual::MethodCall] ,
|
||||
@expect = [[SaveReturn,Register::GetSlot,Virtual::Set,Virtual::Set,Virtual::MethodCall] ,
|
||||
[RegisterTransfer,GetSlot,FunctionReturn]]
|
||||
check
|
||||
|
||||
|
@ -11,7 +11,7 @@ class Object
|
||||
end
|
||||
end
|
||||
HERE
|
||||
@expect = [[Virtual::MethodEnter,Virtual::Set,Register::GetSlot,Virtual::Set,
|
||||
@expect = [[SaveReturn,Virtual::Set,Register::GetSlot,Virtual::Set,
|
||||
Virtual::Set,Virtual::MethodCall] ,[RegisterTransfer,GetSlot,FunctionReturn]]
|
||||
check
|
||||
end
|
||||
|
@ -16,7 +16,7 @@ class Object
|
||||
end
|
||||
end
|
||||
HERE
|
||||
@expect = [[Virtual::MethodEnter,Virtual::Set,Virtual::Set,Register::GetSlot,
|
||||
@expect = [[SaveReturn,Virtual::Set,Virtual::Set,Register::GetSlot,
|
||||
Register::GetSlot,Register::OperatorInstruction,Register::IsZeroBranch] ,
|
||||
[Virtual::Set,Register::AlwaysBranch] ,[Virtual::Set] ,[] ,[RegisterTransfer,GetSlot,FunctionReturn] ]
|
||||
check
|
||||
@ -30,7 +30,7 @@ class Object
|
||||
end
|
||||
end
|
||||
HERE
|
||||
@expect = [[Virtual::MethodEnter,Virtual::Set] , [RegisterTransfer,GetSlot,FunctionReturn]]
|
||||
@expect = [[SaveReturn,Virtual::Set] , [RegisterTransfer,GetSlot,FunctionReturn]]
|
||||
check
|
||||
end
|
||||
|
||||
@ -51,7 +51,7 @@ class Object
|
||||
end
|
||||
end
|
||||
HERE
|
||||
@expect = [ [Virtual::MethodEnter,Register::GetSlot,Virtual::Set,Virtual::Set,
|
||||
@expect = [ [SaveReturn,Register::GetSlot,Virtual::Set,Virtual::Set,
|
||||
Virtual::Set,Virtual::Set,Virtual::MethodCall] ,[RegisterTransfer,GetSlot,FunctionReturn] ]
|
||||
check
|
||||
end
|
||||
|
@ -16,7 +16,7 @@ class Object
|
||||
end
|
||||
end
|
||||
HERE
|
||||
@expect = [ [Virtual::MethodEnter,Virtual::Set,Register::GetSlot,Virtual::Set,
|
||||
@expect = [ [SaveReturn,Virtual::Set,Register::GetSlot,Virtual::Set,
|
||||
Virtual::Set,Virtual::MethodCall] ,[RegisterTransfer,GetSlot,FunctionReturn] ]
|
||||
check
|
||||
end
|
||||
|
@ -27,7 +27,7 @@ class Object
|
||||
end
|
||||
end
|
||||
HERE
|
||||
@expect = [[Virtual::MethodEnter,Register::GetSlot,Virtual::Set,Virtual::Set,
|
||||
@expect = [[SaveReturn,Register::GetSlot,Virtual::Set,Virtual::Set,
|
||||
Virtual::Set,Virtual::Set,Virtual::MethodCall] , [RegisterTransfer,GetSlot,FunctionReturn]]
|
||||
check
|
||||
end
|
||||
|
@ -24,7 +24,7 @@ class Object
|
||||
end
|
||||
end
|
||||
HERE
|
||||
@expect = [ [Virtual::MethodEnter,Register::GetSlot,Virtual::Set,Virtual::Set,
|
||||
@expect = [ [SaveReturn,Register::GetSlot,Virtual::Set,Virtual::Set,
|
||||
Virtual::Set,Virtual::Set,Virtual::MethodCall] ,[RegisterTransfer,GetSlot,FunctionReturn] ]
|
||||
check
|
||||
end
|
||||
|
@ -17,7 +17,7 @@ class Object
|
||||
end
|
||||
end
|
||||
HERE
|
||||
@expect = [[Virtual::MethodEnter,LoadConstant,SetSlot] , [RegisterTransfer,GetSlot,FunctionReturn]]
|
||||
@expect = [[SaveReturn,LoadConstant,SetSlot] , [RegisterTransfer,GetSlot,FunctionReturn]]
|
||||
check
|
||||
end
|
||||
|
||||
@ -29,7 +29,7 @@ class Object
|
||||
end
|
||||
end
|
||||
HERE
|
||||
@expect = [[Virtual::MethodEnter,LoadConstant,GetSlot,SetSlot] , [RegisterTransfer,GetSlot,FunctionReturn]]
|
||||
@expect = [[SaveReturn,LoadConstant,GetSlot,SetSlot] , [RegisterTransfer,GetSlot,FunctionReturn]]
|
||||
check
|
||||
end
|
||||
|
||||
@ -41,7 +41,7 @@ int main()
|
||||
end
|
||||
end
|
||||
HERE
|
||||
@expect = [[Virtual::MethodEnter,LoadConstant,LoadConstant,
|
||||
@expect = [[SaveReturn,LoadConstant,LoadConstant,
|
||||
OperatorInstruction,GetSlot,SetSlot],[RegisterTransfer,GetSlot,FunctionReturn]]
|
||||
check
|
||||
end
|
||||
@ -55,7 +55,7 @@ class Object
|
||||
end
|
||||
end
|
||||
HERE
|
||||
@expect = [[Virtual::MethodEnter,LoadConstant,GetSlot,SetSlot] , [RegisterTransfer,GetSlot,FunctionReturn]]
|
||||
@expect = [[SaveReturn,LoadConstant,GetSlot,SetSlot] , [RegisterTransfer,GetSlot,FunctionReturn]]
|
||||
check
|
||||
end
|
||||
|
||||
@ -67,7 +67,7 @@ class Object
|
||||
end
|
||||
end
|
||||
HERE
|
||||
@expect = [[Virtual::MethodEnter,LoadConstant, GetSlot,SetSlot] , [RegisterTransfer,GetSlot,FunctionReturn]]
|
||||
@expect = [[SaveReturn,LoadConstant, GetSlot,SetSlot] , [RegisterTransfer,GetSlot,FunctionReturn]]
|
||||
check
|
||||
end
|
||||
|
||||
@ -79,7 +79,7 @@ class Object
|
||||
end
|
||||
end
|
||||
HERE
|
||||
@expect = [[Virtual::MethodEnter,GetSlot,GetSlot,SetSlot, LoadConstant,SetSlot,
|
||||
@expect = [[SaveReturn,GetSlot,GetSlot,SetSlot, LoadConstant,SetSlot,
|
||||
Virtual::MethodCall,GetSlot,GetSlot,SetSlot] , [RegisterTransfer,GetSlot,FunctionReturn]]
|
||||
check
|
||||
end
|
||||
|
@ -17,7 +17,7 @@ class Object
|
||||
end
|
||||
end
|
||||
HERE
|
||||
@expect = [[Virtual::MethodEnter,GetSlot,LoadConstant,
|
||||
@expect = [[SaveReturn,GetSlot,LoadConstant,
|
||||
SetSlot,LoadConstant,SetSlot,Virtual::MethodCall,GetSlot] ,
|
||||
[RegisterTransfer,GetSlot,FunctionReturn]]
|
||||
check
|
||||
@ -37,7 +37,7 @@ class Object
|
||||
end
|
||||
end
|
||||
HERE
|
||||
@expect = [[Virtual::MethodEnter,GetSlot,LoadConstant,
|
||||
@expect = [[SaveReturn,GetSlot,LoadConstant,
|
||||
SetSlot,LoadConstant,SetSlot,Virtual::MethodCall,GetSlot] ,
|
||||
[RegisterTransfer,GetSlot,FunctionReturn]]
|
||||
check
|
||||
@ -57,7 +57,7 @@ class Object
|
||||
end
|
||||
end
|
||||
HERE
|
||||
@expect = [ [Virtual::MethodEnter,LoadConstant,GetSlot,SetSlot,GetSlot,
|
||||
@expect = [ [SaveReturn,LoadConstant,GetSlot,SetSlot,GetSlot,
|
||||
GetSlot,GetSlot,SetSlot,LoadConstant,SetSlot,Virtual::MethodCall,
|
||||
GetSlot] ,[RegisterTransfer,GetSlot,FunctionReturn] ]
|
||||
check
|
||||
@ -77,7 +77,7 @@ class Object
|
||||
end
|
||||
end
|
||||
HERE
|
||||
@expect = [ [Virtual::MethodEnter,GetSlot,GetSlot,GetSlot,SetSlot,
|
||||
@expect = [ [SaveReturn,GetSlot,GetSlot,GetSlot,SetSlot,
|
||||
LoadConstant,SetSlot,Virtual::MethodCall,
|
||||
GetSlot] ,[RegisterTransfer,GetSlot,FunctionReturn] ]
|
||||
check
|
||||
@ -94,7 +94,7 @@ int main()
|
||||
end
|
||||
end
|
||||
HERE
|
||||
@expect = [ [Virtual::MethodEnter , GetSlot,GetSlot,SetSlot,LoadConstant,SetSlot,LoadConstant,
|
||||
@expect = [ [SaveReturn , GetSlot,GetSlot,SetSlot,LoadConstant,SetSlot,LoadConstant,
|
||||
SetSlot,Virtual::MethodCall,GetSlot],
|
||||
[RegisterTransfer,GetSlot,FunctionReturn]]
|
||||
check
|
||||
|
@ -16,7 +16,7 @@ class Object
|
||||
end
|
||||
end
|
||||
HERE
|
||||
@expect = [[Virtual::MethodEnter,LoadConstant,LoadConstant,
|
||||
@expect = [[SaveReturn,LoadConstant,LoadConstant,
|
||||
OperatorInstruction,IsZeroBranch] ,
|
||||
[LoadConstant,AlwaysBranch] ,[LoadConstant] ,[] ,
|
||||
[RegisterTransfer,GetSlot,FunctionReturn]]
|
||||
@ -34,7 +34,7 @@ class Object
|
||||
end
|
||||
end
|
||||
HERE
|
||||
@expect = [[Virtual::MethodEnter,LoadConstant,LoadConstant,
|
||||
@expect = [[SaveReturn,LoadConstant,LoadConstant,
|
||||
OperatorInstruction,IsZeroBranch] ,
|
||||
[AlwaysBranch] ,[LoadConstant] ,[] ,
|
||||
[RegisterTransfer,GetSlot,FunctionReturn]]
|
||||
@ -54,7 +54,7 @@ class Object
|
||||
end
|
||||
end
|
||||
HERE
|
||||
@expect = [ [Virtual::MethodEnter,GetSlot,SetSlot,LoadConstant,
|
||||
@expect = [ [SaveReturn,GetSlot,SetSlot,LoadConstant,
|
||||
SetSlot,LoadConstant,SetSlot,Virtual::MethodCall,
|
||||
GetSlot] ,[RegisterTransfer,GetSlot,FunctionReturn] ]
|
||||
check
|
||||
|
@ -13,7 +13,7 @@ class Object
|
||||
end
|
||||
end
|
||||
HERE
|
||||
@expect = [[Virtual::MethodEnter,LoadConstant] , [RegisterTransfer,GetSlot,FunctionReturn]]
|
||||
@expect = [[SaveReturn,LoadConstant] , [RegisterTransfer,GetSlot,FunctionReturn]]
|
||||
check
|
||||
end
|
||||
|
||||
@ -26,7 +26,7 @@ class Object
|
||||
end
|
||||
end
|
||||
HERE
|
||||
@expect = [[Virtual::MethodEnter,GetSlot,GetSlot] , [RegisterTransfer,GetSlot,FunctionReturn]]
|
||||
@expect = [[SaveReturn,GetSlot,GetSlot] , [RegisterTransfer,GetSlot,FunctionReturn]]
|
||||
check
|
||||
end
|
||||
|
||||
@ -39,7 +39,7 @@ class Object
|
||||
end
|
||||
end
|
||||
HERE
|
||||
@expect = [[Virtual::MethodEnter,LoadConstant,GetSlot,SetSlot,GetSlot,GetSlot] ,
|
||||
@expect = [[SaveReturn,LoadConstant,GetSlot,SetSlot,GetSlot,GetSlot] ,
|
||||
[RegisterTransfer,GetSlot,FunctionReturn]]
|
||||
check
|
||||
end
|
||||
@ -53,7 +53,7 @@ class Object
|
||||
end
|
||||
end
|
||||
HERE
|
||||
@expect = [[Virtual::MethodEnter,GetSlot,GetSlot] , [RegisterTransfer,GetSlot,FunctionReturn]]
|
||||
@expect = [[SaveReturn,GetSlot,GetSlot] , [RegisterTransfer,GetSlot,FunctionReturn]]
|
||||
check
|
||||
end
|
||||
|
||||
@ -65,7 +65,7 @@ class Object
|
||||
end
|
||||
end
|
||||
HERE
|
||||
@expect = [[Virtual::MethodEnter,GetSlot,GetSlot,SetSlot, LoadConstant,
|
||||
@expect = [[SaveReturn,GetSlot,GetSlot,SetSlot, LoadConstant,
|
||||
SetSlot,Virtual::MethodCall,GetSlot] , [RegisterTransfer,GetSlot,FunctionReturn]]
|
||||
check
|
||||
end
|
||||
|
@ -15,7 +15,7 @@ class Object
|
||||
end
|
||||
end
|
||||
HERE
|
||||
@expect = [[Virtual::MethodEnter],[LoadConstant,IsZeroBranch,LoadConstant,AlwaysBranch],
|
||||
@expect = [[SaveReturn],[LoadConstant,IsZeroBranch,LoadConstant,AlwaysBranch],
|
||||
[],[RegisterTransfer,GetSlot,FunctionReturn]]
|
||||
check
|
||||
end
|
||||
@ -31,7 +31,7 @@ class Object
|
||||
end
|
||||
end
|
||||
HERE
|
||||
@expect = [[Virtual::MethodEnter,LoadConstant,GetSlot,SetSlot],[GetSlot,GetSlot,LoadConstant,OperatorInstruction,
|
||||
@expect = [[SaveReturn,LoadConstant,GetSlot,SetSlot],[GetSlot,GetSlot,LoadConstant,OperatorInstruction,
|
||||
IsZeroBranch,GetSlot,GetSlot,LoadConstant,OperatorInstruction,GetSlot,SetSlot,AlwaysBranch],
|
||||
[],[RegisterTransfer,GetSlot,FunctionReturn]]
|
||||
check
|
||||
@ -50,7 +50,7 @@ class Object
|
||||
end
|
||||
end
|
||||
HERE
|
||||
@expect = [[Virtual::MethodEnter,LoadConstant,GetSlot,SetSlot],
|
||||
@expect = [[SaveReturn,LoadConstant,GetSlot,SetSlot],
|
||||
[GetSlot,GetSlot,LoadConstant,OperatorInstruction,IsZeroBranch,GetSlot,
|
||||
GetSlot,LoadConstant,OperatorInstruction,GetSlot,SetSlot,GetSlot,
|
||||
GetSlot,AlwaysBranch] ,
|
||||
|
Loading…
Reference in New Issue
Block a user