From 1af66567fbb3198f83fa1bb4677ac6c91958049c Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Fri, 3 Oct 2014 11:07:18 +0300 Subject: [PATCH] fixed the SetImplementation with new register instructions --- lib/register/instruction.rb | 5 +++-- lib/register/instructions/get_slot.rb | 16 ++++++++++++++++ lib/register/instructions/load_constant.rb | 14 ++++++++++++++ lib/register/instructions/set_slot.rb | 16 ++++++++++++++++ lib/register/passes/set_implementation.rb | 8 ++++---- 5 files changed, 53 insertions(+), 6 deletions(-) create mode 100644 lib/register/instructions/get_slot.rb create mode 100644 lib/register/instructions/load_constant.rb create mode 100644 lib/register/instructions/set_slot.rb diff --git a/lib/register/instruction.rb b/lib/register/instruction.rb index 2ba2803b..4d8e913a 100644 --- a/lib/register/instruction.rb +++ b/lib/register/instruction.rb @@ -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" diff --git a/lib/register/instructions/get_slot.rb b/lib/register/instructions/get_slot.rb new file mode 100644 index 00000000..e90433f1 --- /dev/null +++ b/lib/register/instructions/get_slot.rb @@ -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 diff --git a/lib/register/instructions/load_constant.rb b/lib/register/instructions/load_constant.rb new file mode 100644 index 00000000..205f3b78 --- /dev/null +++ b/lib/register/instructions/load_constant.rb @@ -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 diff --git a/lib/register/instructions/set_slot.rb b/lib/register/instructions/set_slot.rb new file mode 100644 index 00000000..85c430fc --- /dev/null +++ b/lib/register/instructions/set_slot.rb @@ -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 diff --git a/lib/register/passes/set_implementation.rb b/lib/register/passes/set_implementation.rb index 79a486b3..196026ab 100644 --- a/lib/register/passes/set_implementation.rb +++ b/lib/register/passes/set_implementation.rb @@ -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