fixed the SetImplementation with new register instructions
This commit is contained in:
parent
38a286942e
commit
1af66567fb
@ -30,5 +30,6 @@ module Register
|
||||
|
||||
end
|
||||
|
||||
require "instructions/variable_set"
|
||||
#require "instructions/object_set"
|
||||
require_relative "instructions/set_slot"
|
||||
require_relative "instructions/get_slot"
|
||||
require_relative "instructions/load_constant"
|
||||
|
16
lib/register/instructions/get_slot.rb
Normal file
16
lib/register/instructions/get_slot.rb
Normal file
@ -0,0 +1,16 @@
|
||||
module Register
|
||||
# offset memory get access
|
||||
# so the value to be set must be given as the first register
|
||||
# the second argument holds the base address
|
||||
# and the third a possible (small) offset into the "object"
|
||||
#
|
||||
# if for example the value is pointed to by a register, a VariableGet (load) is needed first
|
||||
class GetSlot < Instruction
|
||||
def initialize value , reference , index = 0
|
||||
@value = value
|
||||
@reference = reference
|
||||
@index = index
|
||||
end
|
||||
attr_accessor :value , :reference , :index
|
||||
end
|
||||
end
|
14
lib/register/instructions/load_constant.rb
Normal file
14
lib/register/instructions/load_constant.rb
Normal file
@ -0,0 +1,14 @@
|
||||
module Register
|
||||
# load a constant into a register
|
||||
#
|
||||
# first arguemnt is the register the constant is loaded into
|
||||
# second is the actual constant
|
||||
|
||||
class LoadConstant < Instruction
|
||||
def initialize value , constant
|
||||
@value = value
|
||||
@constant = constant
|
||||
end
|
||||
attr_accessor :value , :constant
|
||||
end
|
||||
end
|
16
lib/register/instructions/set_slot.rb
Normal file
16
lib/register/instructions/set_slot.rb
Normal file
@ -0,0 +1,16 @@
|
||||
module Register
|
||||
# offset memory set access
|
||||
# so the value must be given as the first register
|
||||
# the second argument holds the base address
|
||||
# and the third a possible (small) offset into the "object"
|
||||
#
|
||||
# if for example the value is pointed to by a register, a VariableGet (load) is needed first
|
||||
class SetSlot < Instruction
|
||||
def initialize value , reference , index = 0
|
||||
@value = value
|
||||
@reference = reference
|
||||
@index = index
|
||||
end
|
||||
attr_accessor :value , :reference , :index
|
||||
end
|
||||
end
|
@ -21,7 +21,7 @@ end
|
||||
|
||||
module Register
|
||||
# This implements setting of the various slot variables the vm defines.
|
||||
# Basic mem moves, but have to shuffle the type nibbles
|
||||
# Basic mem moves, but have to shuffle the type nibbles (TODO!)
|
||||
|
||||
class SetImplementation
|
||||
def run block
|
||||
@ -33,11 +33,11 @@ module Register
|
||||
tmp = RegisterReference.new(Virtual::Message::TMP_REG)
|
||||
# for constants we have to "move" the constants value
|
||||
if( code.from.is_a? Virtual::Constant)
|
||||
move1 = RegisterMachine.instance.mov( tmp , code.from )
|
||||
move1 = LoadConstant.new( tmp , code.from )
|
||||
else # while otherwise we "load"
|
||||
move1 = RegisterMachine.instance.ldr( tmp , code.from.reg , code.from.index )
|
||||
move1 = GetSlot.new( tmp , code.from.reg , code.from.index )
|
||||
end
|
||||
move2 = RegisterMachine.instance.str( tmp , to , code.to.index )
|
||||
move2 = SetSlot.new( tmp , to , code.to.index )
|
||||
block.replace(code , [move1,move2] )
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user