From 486580aeb2e36509d24b5773d3f1947d59ee8197 Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Sun, 5 Oct 2014 01:12:44 +0300 Subject: [PATCH] fix bad scoping bug --- lib/arm/instruction.rb | 43 +++++++++++++++++++++++++----------------- 1 file changed, 26 insertions(+), 17 deletions(-) diff --git a/lib/arm/instruction.rb b/lib/arm/instruction.rb index 03148ce1..6a8719e0 100644 --- a/lib/arm/instruction.rb +++ b/lib/arm/instruction.rb @@ -15,25 +15,34 @@ module Arm def opcode @attributes[:opcode] end - end - - - # this is giving read access to the attributes hash via .attibute syntax - # so for an instruction pop you can write pop.opcode to get the :opcode attribute - - # TODDO: review (don't remember what the "set_" stuff was for) - def method_missing name , *args , &block - return super unless (args.length <= 1) or block_given? - set , attribute = name.to_s.split("set_") - if set == "" - @attributes[attribute.to_sym] = args[0] || 1 - return self - else - return super + def position + raise "position accessed but not set at #{length} for #{self.inspect}" if @position == nil + @position + end + def set_position pos + # resetting of position used to be error, but since relink and dynamic instruction size it is ok. in measures + if @position != nil and ((@position - pos).abs > 32) + raise "position set again #{pos}!=#{@position} for #{self}" + end + @position = pos end - return @attributes[name.to_sym] - end + # this is giving read access to the attributes hash via .attibute syntax + # so for an instruction pop you can write pop.opcode to get the :opcode attribute + + # TODDO: review (don't remember what the "set_" stuff was for) + def method_missing name , *args , &block + return super unless (args.length <= 1) or block_given? + set , attribute = name.to_s.split("set_") + if set == "" + @attributes[attribute.to_sym] = args[0] || 1 + return self + else + return super + end + return @attributes[name.to_sym] + end + end end require_relative "constants"