move generator functions to the instructions they generate

This commit is contained in:
Torsten Ruger 2015-06-30 09:43:50 +03:00
parent bd77db656a
commit 60c8f8ef73
4 changed files with 34 additions and 31 deletions

View File

@ -28,4 +28,15 @@ module Register
end end
attr_accessor :register , :array , :index attr_accessor :register , :array , :index
end end
# Produce a GetSlot instruction.
# From and to are registers or symbols that can be transformed to a register by resolve_to_register
# index resolves with resolve_index.
def self.get_slot from , index , to
index = resolve_index( from , index)
from = resolve_to_register from
to = resolve_to_register to
GetSlot.new( from , index , to)
end
end end

View File

@ -13,4 +13,14 @@ module Register
end end
attr_reader :register , :index attr_reader :register , :index
end end
# Produce a SaveReturn instruction.
# From is a register or symbol that can be transformed to a register by resolve_to_register
# index resolves with resolve_index.
def self.save_return from , index
index = resolve_index( from , index)
from = resolve_to_register from
SaveReturn.new( from , index )
end
end end

View File

@ -27,4 +27,15 @@ module Register
end end
attr_accessor :register , :array , :index attr_accessor :register , :array , :index
end end
# Produce a SetSlot instruction.
# From and to are registers or symbols that can be transformed to a register by resolve_to_register
# index resolves with resolve_index.
def self.set_slot from , to , index
index = resolve_index( to , index)
from = resolve_to_register from
to = resolve_to_register to
SetSlot.new( from , to , index)
end
end end

View File

@ -86,35 +86,6 @@ module Register
RegisterReference.new :r4 RegisterReference.new :r4
end end
# Produce a GetSlot instruction (see there).
# From and to are registers or symbols that can be transformed to a register by resolve_to_register
# index resolves with resolve_index.
def self.get_slot from , index , to
index = resolve_index( from , index)
from = resolve_to_register from
to = resolve_to_register to
GetSlot.new( from , index , to)
end
# Produce a SetSlot instruction (see there).
# From and to are registers or symbols that can be transformed to a register by resolve_to_register
# index resolves with resolve_index.
def self.set_slot from , to , index
index = resolve_index( to , index)
from = resolve_to_register from
to = resolve_to_register to
SetSlot.new( from , to , index)
end
# Produce a SaveReturn instruction (see there).
# From is a register or symbol that can be transformed to a register by resolve_to_register
# index resolves with resolve_index.
def self.save_return from , index
index = resolve_index( from , index)
from = resolve_to_register from
SaveReturn.new( from , index )
end
# The first arg is a class name (possibly lowercase) and the second an instance variable name. # The first arg is a class name (possibly lowercase) and the second an instance variable name.
# By looking up the class and the layout for that class, we can resolve the instance # By looking up the class and the layout for that class, we can resolve the instance
# variable name to an index. # variable name to an index.