diff --git a/lib/risc/fake_memory.rb b/lib/risc/fake_memory.rb index 4089f917..8730467a 100644 --- a/lib/risc/fake_memory.rb +++ b/lib/risc/fake_memory.rb @@ -18,17 +18,23 @@ module Risc end def set(index , value) range_check(index) + _set(index,value) + end + alias :[]= :set + def _set(index , value) @memory[index] = value value end - alias :[]= :set - def get(index) range_check(index) - @memory[index] + _get(index) end alias :[] :get + def _get(index) + @memory[index] + end + def size @memory.length end diff --git a/lib/risc/parfait_adapter.rb b/lib/risc/parfait_adapter.rb index f8df5c34..154b8b7c 100644 --- a/lib/risc/parfait_adapter.rb +++ b/lib/risc/parfait_adapter.rb @@ -1,13 +1,6 @@ require_relative "fake_memory" module Parfait - def self.variable_index(clazz_name , name) - clazz = clazz_name.split("::").last.to_sym - type = self.type_names[clazz] - i = type.keys.index(name) - raise "no #{name} for #{clazz}" unless i - i + 1 - end class Object def self.allocate @@ -35,26 +28,30 @@ module Parfait end end + def self.variable_index( name) + if(name == :type) + return Parfait::TYPE_INDEX + end + clazz = self.name.split("::").last.to_sym + type = Parfait.type_names[clazz] + i = type.keys.index(name) + raise "no #{name} for #{clazz}:#{type.keys}" unless i + i + 1 + end + def self.define_getter(name) + index = variable_index(name) define_method(name) do #puts "GETTING #{name} for #{self.class.name} in #{object_id.to_s(16)}" - if(name == :type) - return @memory[0] - end - index = Parfait.variable_index(self.class.name, name) - get_internal_word(index) + @memory._get(index) end end def self.define_setter(name) + index = variable_index(name) define_method("#{name}=".to_sym ) do |value| #puts "SETTING #{name}= for #{self.class.name} in #{object_id.to_s(16)}" - if(name == :type) - @memory[0] = value - return value - end - index = Parfait.variable_index(self.class.name, name) - set_internal_word(index , value) + @memory._set(index , value) end end end