revert to symbols

Parfait::Words were nice, but endless problems with the fact that when
you write “String” you get a string.
Symbols take care of uniqueness at the same time
This commit is contained in:
Torsten Ruger
2015-05-31 18:34:18 +03:00
parent 5d870ef154
commit bee73801eb
18 changed files with 101 additions and 85 deletions

View File

@ -16,7 +16,7 @@ module FakeMem
end
end
def init_layout
vm_name = self.class.name.split("::").last
vm_name = self.class.name.split("::").last.to_sym
clazz = Virtual::Machine.instance.class_mappings[vm_name]
raise "Class not found #{vm_name}" unless clazz
raise "Layout not set #{vm_name}" unless clazz.object_layout
@ -52,6 +52,28 @@ module FakeMem
padded(words*4) # 4 == word length, a constant waiting for a home
end
end
module Virtual
def self.new_list array
list = Parfait::List.new_object
list.set_length array.length
index = 1
while index <= array.length do
list.set(index , array[index - 1])
index = index + 1
end
list
end
end
class Symbol
include Positioned
def init_layout; end
def has_layout?
true
end
def get_layout
Virtual::Machine.instance.class_mappings[:Word].object_layout
end
end
module Parfait
# Objects memory functions. Object memory is 1 based
@ -158,26 +180,3 @@ module Parfait
end
end
end
module Virtual
# Functions to generate parfait objects
def self.new_word( string )
string = string.to_s if string.is_a? Symbol
word = Parfait::Word.new_object( string.length )
string.codepoints.each_with_index do |code , index |
word.set_char(index + 1 , code)
end
word
end
def self.new_list array
list = Parfait::List.new_object
list.set_length array.length
index = 1
while index <= array.length do
list.set(index , array[index - 1])
index = index + 1
end
list
end
end