reinstate word creation and use for strings
so string constants become words, so we can fiddle with them
This commit is contained in:
parent
c8fa5238ee
commit
f746218765
@ -15,6 +15,15 @@ module Register
|
|||||||
end
|
end
|
||||||
list
|
list
|
||||||
end
|
end
|
||||||
|
# Functions to generate parfait objects
|
||||||
|
def self.new_word( string )
|
||||||
|
string = string.to_s if string.is_a? Symbol
|
||||||
|
word = Parfait::Word.new( string.length )
|
||||||
|
string.codepoints.each_with_index do |code , index |
|
||||||
|
word.set_char(index + 1 , code)
|
||||||
|
end
|
||||||
|
word
|
||||||
|
end
|
||||||
end
|
end
|
||||||
class Symbol
|
class Symbol
|
||||||
include Positioned
|
include Positioned
|
||||||
@ -61,8 +70,8 @@ end
|
|||||||
|
|
||||||
module Parfait
|
module Parfait
|
||||||
# Objects memory functions. Object memory is 1 based
|
# Objects memory functions. Object memory is 1 based
|
||||||
# but we implement it with ruby array (0 based) and use 0 as type-word
|
# but we implement it with ruby array (0 based) and don't use 0
|
||||||
# These are the same functions that Builtin implements at run-time
|
# These are the same functions that Builtin implements for run-time
|
||||||
class Object
|
class Object
|
||||||
include Padding
|
include Padding
|
||||||
include Positioned
|
include Positioned
|
||||||
@ -80,6 +89,7 @@ module Parfait
|
|||||||
# 1 -based index
|
# 1 -based index
|
||||||
def set_internal(index , value)
|
def set_internal(index , value)
|
||||||
raise "failed init for #{self.class}" unless @memory
|
raise "failed init for #{self.class}" unless @memory
|
||||||
|
raise "Word[#{index}] = " if((self.class == Parfait::Word) and value.nil? )
|
||||||
@memory[index] = value
|
@memory[index] = value
|
||||||
value
|
value
|
||||||
end
|
end
|
||||||
@ -122,7 +132,7 @@ module Parfait
|
|||||||
def to_string
|
def to_string
|
||||||
string = ""
|
string = ""
|
||||||
index = 1
|
index = 1
|
||||||
while( index <= self.length)
|
while( index <= self.char_length)
|
||||||
string[index - 1] = get_char(index).chr
|
string[index - 1] = get_char(index).chr
|
||||||
index = index + 1
|
index = index + 1
|
||||||
end
|
end
|
||||||
|
@ -36,7 +36,7 @@ module Soml
|
|||||||
end
|
end
|
||||||
|
|
||||||
def on_string expression
|
def on_string expression
|
||||||
value = expression.first.to_sym
|
value = Register.new_word expression.first.to_sym
|
||||||
reg = use_reg :Word
|
reg = use_reg :Word
|
||||||
Register.machine.constants << value
|
Register.machine.constants << value
|
||||||
add_code Register::LoadConstant.new( expression, value , reg )
|
add_code Register::LoadConstant.new( expression, value , reg )
|
||||||
|
@ -19,17 +19,6 @@ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'test'))
|
|||||||
|
|
||||||
require 'salama'
|
require 'salama'
|
||||||
|
|
||||||
module Register
|
|
||||||
# Functions to generate parfait objects
|
|
||||||
def self.new_word( string )
|
|
||||||
string = string.to_s if string.is_a? Symbol
|
|
||||||
word = Parfait::Word.new( string.length )
|
|
||||||
string.codepoints.each_with_index do |code , index |
|
|
||||||
word.set_char(index + 1 , code)
|
|
||||||
end
|
|
||||||
word
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
class Ignored
|
class Ignored
|
||||||
def == other
|
def == other
|
||||||
|
Loading…
Reference in New Issue
Block a user