fix register (sym/ref)

This commit is contained in:
Torsten Ruger 2015-07-24 17:21:13 +03:00
parent 959cb628fa
commit 1526656dfe

View File

@ -9,7 +9,10 @@ class Interpreter
attr_accessor :registers attr_accessor :registers
def initialize def initialize
@registers = Hash[(0...12).collect{|i| ["r#{i}" , "undefined"]}] @registers = {}
(0...12).each do |r|
set_register "r#{r}".to_sym , "undefined"
end
end end
def start bl def start bl
@ -34,7 +37,7 @@ class Interpreter
end end
def get_register( reg ) def get_register( reg )
reg = reg.symbol if reg.is_a? Register::RegisterReference reg = reg.symbol if reg.is_a? Register::RegisterReference
raise "Not a register #{reg}" unless Register::RegisterReference.look_like_reg(reg) raise "Not a register #{reg}" unless Register::RegisterReference.look_like_reg(reg)
@registers[reg] @registers[reg]
end end
@ -42,6 +45,7 @@ class Interpreter
def set_register reg , val def set_register reg , val
old = get_register( reg ) # also ensures format old = get_register( reg ) # also ensures format
return if old === val return if old === val
reg = reg.symbol if reg.is_a? Register::RegisterReference
@registers[reg] = val @registers[reg] = val
trigger(:register_changed, reg , old , val) trigger(:register_changed, reg , old , val)
end end