moving string to parfait
using parfait::word also rename builtins string to word
This commit is contained in:
@ -36,7 +36,7 @@ module Elf
|
||||
assembler.objects.values.each do |slot|
|
||||
label = "#{slot.class.name}::#{slot.position.to_s(16)}"
|
||||
label += "=#{slot}" if slot.is_a?(Symbol) or slot.is_a?(String)
|
||||
label += "=#{slot.string}" if slot.is_a?(Virtual::StringConstant)
|
||||
label += "=#{slot.string}" if slot.is_a?(Parfait::Word)
|
||||
add_symbol label , slot.position
|
||||
end
|
||||
end
|
||||
|
@ -8,5 +8,28 @@ module Parfait
|
||||
# Words are constant, maybe like js strings, ruby symbols
|
||||
# Words are short, but may have spaces
|
||||
class Word < Object
|
||||
def initialize str
|
||||
@string = str
|
||||
end
|
||||
attr_reader :string
|
||||
|
||||
def result= value
|
||||
raise "called"
|
||||
class_for(MoveInstruction).new(value , self , :opcode => :mov)
|
||||
end
|
||||
def clazz
|
||||
Space.space.get_or_create_class(:Word)
|
||||
end
|
||||
def layout
|
||||
Virtual::Object.layout
|
||||
end
|
||||
def mem_length
|
||||
padded(1 + string.length)
|
||||
end
|
||||
def position
|
||||
return @position if @position
|
||||
return @string.position if @string.position
|
||||
super
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -144,7 +144,7 @@ module Register
|
||||
end
|
||||
|
||||
def assemble_String( str )
|
||||
str = str.string if str.is_a? Virtual::StringConstant
|
||||
str = str.string if str.is_a? Parfait::Word
|
||||
str = str.to_s if str.is_a? Symbol
|
||||
word = (str.length + 7) / 32 # all object are multiple of 8 words (7 for header)
|
||||
raise "String too long (implement split string!) #{word}" if word > 15
|
||||
|
@ -28,7 +28,7 @@ module Builtin
|
||||
def putint context
|
||||
putint_function = Virtual::CompiledMethod.new(:putint , [] , Virtual::Integer ,Virtual::Integer )
|
||||
return putint_function
|
||||
buffer = Virtual::StringConstant.new(" ") # create a buffer
|
||||
buffer = Parfait::Word.new(" ") # create a buffer
|
||||
context.object_space.add_object buffer # and save it (function local variable: a no no)
|
||||
int = putint_function.receiver
|
||||
moved_int = putint_function.new_local
|
||||
|
@ -76,6 +76,6 @@ module Builtin
|
||||
end
|
||||
end
|
||||
require_relative "integer"
|
||||
require_relative "string"
|
||||
require_relative "word"
|
||||
require_relative "array"
|
||||
require_relative "kernel"
|
||||
|
@ -1,5 +1,5 @@
|
||||
module Builtin
|
||||
class String
|
||||
class Word
|
||||
module ClassMethods
|
||||
def get context , index = Virtual::Integer
|
||||
get_function = Virtual::CompiledMethod.new(:get , [ Virtual::Integer] , Virtual::Integer , Virtual::Integer )
|
||||
@ -9,11 +9,11 @@ module Builtin
|
||||
set_function = Virtual::CompiledMethod.new(:set , [Virtual::Integer, Virtual::Integer] , Virtual::Integer ,Virtual::Integer )
|
||||
return set_function
|
||||
end
|
||||
def puts context
|
||||
def puts context
|
||||
puts_function = Virtual::CompiledMethod.new(:puts , [] )
|
||||
return puts_function
|
||||
end
|
||||
end
|
||||
extend ClassMethods
|
||||
extend ClassMethods
|
||||
end
|
||||
end
|
@ -71,7 +71,7 @@ module Virtual
|
||||
|
||||
# attr_reader :string
|
||||
def self.compile_string expression , method
|
||||
value = StringConstant.new(expression.string)
|
||||
value = Parfait::Word.new(expression.string)
|
||||
to = Return.new(Reference , value)
|
||||
Machine.instance.space.add_object value
|
||||
method.add_code Set.new( to , value )
|
||||
|
@ -8,7 +8,7 @@ module Virtual
|
||||
me = Compiler.compile( expession.receiver , method )
|
||||
method.add_code NewMessage.new
|
||||
method.add_code Set.new(NewSelf.new(me.type), me)
|
||||
method.add_code Set.new(NewName.new(), StringConstant.new(expession.name))
|
||||
method.add_code Set.new(NewName.new(), Parfait::Word.new(expession.name))
|
||||
compiled_args = []
|
||||
expession.args.each_with_index do |arg , i|
|
||||
#compile in the running method, ie before passing control
|
||||
|
@ -1,5 +1,5 @@
|
||||
module Virtual
|
||||
|
||||
|
||||
class Constant < ::Virtual::Object
|
||||
end
|
||||
class TrueConstant < Constant
|
||||
@ -10,7 +10,7 @@ module Virtual
|
||||
end
|
||||
|
||||
# another abstract "marker" class (so we can check for it)
|
||||
# derived classes are Boot/Meta Class and StringConstant
|
||||
# derived classes are Boot/Meta Class and StringConstant
|
||||
class ObjectConstant < Constant
|
||||
def type
|
||||
Virtual::Reference
|
||||
@ -32,36 +32,5 @@ module Virtual
|
||||
integer >= 0 and integer <= 255
|
||||
end
|
||||
end
|
||||
|
||||
# The name really says it all.
|
||||
# The only interesting thing is storage.
|
||||
# Currently string are stored "inline" , ie in the code segment.
|
||||
# Mainly because that works an i aint no elf expert.
|
||||
|
||||
class StringConstant < ObjectConstant
|
||||
def initialize str
|
||||
@string = str
|
||||
end
|
||||
attr_reader :string
|
||||
|
||||
def result= value
|
||||
raise "called"
|
||||
class_for(MoveInstruction).new(value , self , :opcode => :mov)
|
||||
end
|
||||
def clazz
|
||||
Space.space.get_or_create_class(:String)
|
||||
end
|
||||
def layout
|
||||
Virtual::Object.layout
|
||||
end
|
||||
def mem_length
|
||||
padded(1 + string.length)
|
||||
end
|
||||
def position
|
||||
return @position if @position
|
||||
return @string.position if @string.position
|
||||
super
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
@ -113,9 +113,9 @@ module Virtual
|
||||
[:putint,:fibo].each do |f|
|
||||
obj.add_instance_method Builtin::Integer.send(f , nil)
|
||||
end
|
||||
obj = @space.get_or_create_class :String
|
||||
obj = @space.get_or_create_class :Word
|
||||
[:get , :set , :puts].each do |f|
|
||||
obj.add_instance_method Builtin::String.send(f , nil)
|
||||
obj.add_instance_method Builtin::Word.send(f , nil)
|
||||
end
|
||||
obj = space.get_or_create_class :Array
|
||||
[:get , :set , :push].each do |f|
|
||||
|
@ -63,7 +63,7 @@ module Virtual
|
||||
|
||||
def layout_for(object)
|
||||
case object
|
||||
when Array , Symbol , String , Virtual::CompiledMethod , Virtual::Block , Virtual::StringConstant
|
||||
when Array , Symbol , String , Virtual::CompiledMethod , Virtual::Block , Parfait::Word
|
||||
@@ARRAY
|
||||
when Hash
|
||||
@@HASH.merge :keys => object.keys , :values => object.values
|
||||
|
Reference in New Issue
Block a user