move the hash access stuff to arm, not sure if needed at all

This commit is contained in:
Torsten Ruger 2014-10-03 11:05:17 +03:00
parent 220d9f6213
commit 38a286942e
2 changed files with 29 additions and 11 deletions

View File

@ -16,6 +16,24 @@ module Arm
@attributes[:opcode] @attributes[:opcode]
end end
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
end
return @attributes[name.to_sym]
end
end end
require_relative "constants" require_relative "constants"

View File

@ -1,5 +1,12 @@
module Register module Register
# the register machine has at least 8 registers, named r0-r5 , :lr and :pc (for historical reasons)
# we can load and store their contents and
# access (get/set) memory at a constant offset from a register
# while the vm works with objects, the register machine has registers,
# but we keep the names for better understanding, r4/5 are temporary/scratch
# there is no direct memory access, only through registers
# constants can/must be loaded into registers before use
class Instruction class Instruction
# returns an array of registers (RegisterReferences) that this instruction uses. # returns an array of registers (RegisterReferences) that this instruction uses.
@ -18,17 +25,10 @@ module Register
def assigns def assigns
raise "abstract called for #{self.class}" raise "abstract called for #{self.class}"
end end
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
end end
require "instructions/variable_set"
#require "instructions/object_set"