test compatibility layer
test from and to std/parfait objects for list and word for now moved some of that code to virtual, out of parfait
This commit is contained in:
parent
f7eb888c36
commit
cfc2c474b2
@ -84,6 +84,18 @@ module Parfait
|
||||
return if old_length >= len
|
||||
internal_object_grow(len + 1)
|
||||
end
|
||||
|
||||
def ==(other)
|
||||
# this should call parfait get_class, alas that is not implemented yet
|
||||
return false if other.class != self.class
|
||||
return false if other.get_length != self.get_length
|
||||
index = self.get_length
|
||||
while(index > 0)
|
||||
return false if other.get(index) != self.get(index)
|
||||
index = index - 1
|
||||
end
|
||||
return true
|
||||
end
|
||||
#many basic List functions can not be defined in ruby, such as
|
||||
# get/set/length/add/delete
|
||||
# so they must be defined as CompiledMethods in Builtin::Kernel
|
||||
|
@ -60,7 +60,7 @@ module Parfait
|
||||
|
||||
def create_class name , variable_names
|
||||
c = Class.new_object(name)
|
||||
c.set_instance_names Parfait.new_list(variable_names)
|
||||
c.set_instance_names Virtual.new_list(variable_names)
|
||||
@classes[name] = c
|
||||
end
|
||||
|
||||
|
@ -80,6 +80,19 @@ module Parfait
|
||||
def to_sof
|
||||
"Parfait::Word('#{to_s}')"
|
||||
end
|
||||
|
||||
def ==(other)
|
||||
# this should call parfait get_class, alas that is not implemented yet
|
||||
return false if other.class != self.class
|
||||
return false if other.length != self.length
|
||||
index = self.length
|
||||
while(index > 0)
|
||||
return false if other.get_char(index) != self.get_char(index)
|
||||
index = index - 1
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
def result= value
|
||||
raise "called"
|
||||
class_for(MoveInstruction).new(value , self , :opcode => :mov)
|
||||
|
@ -55,25 +55,6 @@ module Parfait
|
||||
class Parfait::List
|
||||
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
|
||||
def self.new_list array
|
||||
list = List.new_object
|
||||
list.set_length array.length
|
||||
index = 1
|
||||
while index < array.length do
|
||||
list.set(index , array[index - 1])
|
||||
end
|
||||
list
|
||||
end
|
||||
|
||||
Word.class_eval do
|
||||
def to_s
|
||||
string = ""
|
||||
@ -85,4 +66,37 @@ module Parfait
|
||||
string
|
||||
end
|
||||
end
|
||||
List.class_eval do
|
||||
def to_a
|
||||
array = []
|
||||
index = 1
|
||||
while( index <= self.get_length)
|
||||
array[index - 1] = get(index)
|
||||
index = index + 1
|
||||
end
|
||||
array
|
||||
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( 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
|
||||
|
@ -71,7 +71,7 @@ module Virtual
|
||||
|
||||
# attr_reader :string
|
||||
def self.compile_string expression , method
|
||||
value = Parfait.new_word(expression.string)
|
||||
value = Virtual.new_word(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(), Parfait.new_word(expession.name))
|
||||
method.add_code Set.new(NewName.new(), Virtual.new_word(expession.name))
|
||||
compiled_args = []
|
||||
expession.args.each_with_index do |arg , i|
|
||||
#compile in the running method, ie before passing control
|
||||
|
@ -143,7 +143,10 @@ module Virtual
|
||||
cl = @space.get_class_by_name( name )
|
||||
cl.set_super_class(object_class)
|
||||
end
|
||||
#boot_layouts
|
||||
boot_layouts!
|
||||
end
|
||||
def boot_layouts!
|
||||
|
||||
end
|
||||
def boot
|
||||
# read all the files needed for a minimal system at compile
|
||||
|
19
test/virtual/test_compat.rb
Normal file
19
test/virtual/test_compat.rb
Normal file
@ -0,0 +1,19 @@
|
||||
require_relative "../helper"
|
||||
|
||||
|
||||
class TestCompat < MiniTest::Test
|
||||
|
||||
def test_list_create_from_array
|
||||
array = [1,2,3]
|
||||
list = Virtual.new_list(array)
|
||||
assert_equal list , Virtual.new_list(array)
|
||||
assert_equal array , list.to_a
|
||||
end
|
||||
|
||||
def test_word_create_from_string
|
||||
string = "something"
|
||||
word = Virtual.new_word(string)
|
||||
assert_equal word , Virtual.new_word(string)
|
||||
assert_equal string , word.to_s
|
||||
end
|
||||
end
|
@ -50,8 +50,8 @@ class TestConversion < MiniTest::Test
|
||||
|
||||
def test_string
|
||||
string = "hello"
|
||||
word = Parfait.new_word string
|
||||
assert_equal word , Parfait.new_word(string)
|
||||
word = Virtual.new_word string
|
||||
assert_equal word , Virtual.new_word(string)
|
||||
assert_equal string , word.to_s
|
||||
end
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user