2015-05-12 08:54:36 +02:00
|
|
|
require "parfait/value"
|
|
|
|
require "parfait/object"
|
|
|
|
require "parfait/module"
|
|
|
|
require "parfait/class"
|
2015-05-12 18:10:45 +02:00
|
|
|
require "parfait/dictionary"
|
|
|
|
require "parfait/list"
|
2015-05-16 13:01:48 +02:00
|
|
|
require "parfait/layout"
|
2015-05-13 15:06:38 +02:00
|
|
|
require "parfait/word"
|
2015-05-12 08:54:36 +02:00
|
|
|
require "parfait/message"
|
|
|
|
require "parfait/frame"
|
2015-05-12 14:36:44 +02:00
|
|
|
require "parfait/space"
|
2015-05-12 13:58:29 +02:00
|
|
|
|
|
|
|
# Below we define functions (in different classes) that are not part of the run-time
|
|
|
|
# They are used for the boot process, ie when this codes executes in the vm that builds salama
|
|
|
|
|
|
|
|
# To stay sane, we use the same classes that we use later, but "adapt" them to work in ruby
|
|
|
|
# This affects mainly memory layout
|
|
|
|
|
|
|
|
module FakeMem
|
|
|
|
def initialize
|
2015-05-17 13:55:10 +02:00
|
|
|
@memory = [0,nil]
|
2015-05-12 13:58:29 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-05-15 15:45:36 +02:00
|
|
|
module Parfait
|
2015-05-17 13:38:25 +02:00
|
|
|
# Objects memory functions. Object memory is 1 based
|
|
|
|
# but we implement it with ruby array (0 based) and use 0 as type-word
|
|
|
|
# These are the same functions that Builtin implements at run-time
|
2015-05-15 15:45:36 +02:00
|
|
|
class Object
|
|
|
|
include FakeMem
|
|
|
|
def self.new_object *args
|
2015-05-16 11:54:11 +02:00
|
|
|
# Space.space.get_class_by_name(:Word)
|
2015-05-16 19:16:49 +02:00
|
|
|
#puts "I am #{self}"
|
2015-05-15 15:45:36 +02:00
|
|
|
object = self.new(*args)
|
|
|
|
object
|
|
|
|
end
|
2015-05-17 13:38:25 +02:00
|
|
|
# these internal functions are _really_ internal
|
|
|
|
# they respresent the smallest code needed to build larger functionality
|
|
|
|
# but should _never_ be used outside parfait. in fact that should be impossible
|
|
|
|
def internal_object_get_typeword
|
|
|
|
@memory[0]
|
|
|
|
end
|
|
|
|
def internal_object_set_typeword w
|
|
|
|
@memory[0] = w
|
|
|
|
end
|
2015-05-15 15:45:36 +02:00
|
|
|
def internal_object_length
|
2015-05-17 13:38:25 +02:00
|
|
|
@memory.length - 1 # take of type-word
|
2015-05-15 15:45:36 +02:00
|
|
|
end
|
2015-05-17 13:38:25 +02:00
|
|
|
# 1 -based index
|
2015-05-15 15:45:36 +02:00
|
|
|
def internal_object_get(index)
|
|
|
|
@memory[index]
|
|
|
|
end
|
2015-05-17 13:38:25 +02:00
|
|
|
# 1 -based index
|
2015-05-15 15:45:36 +02:00
|
|
|
def internal_object_set(index , value)
|
|
|
|
@memory[index] = value
|
|
|
|
end
|
2015-05-17 13:38:25 +02:00
|
|
|
def internal_object_grow(length)
|
|
|
|
old_length = internal_object_length()
|
|
|
|
while( old_length < length )
|
|
|
|
internal_object_set( old_length + 1, nil)
|
2015-05-17 13:44:48 +02:00
|
|
|
old_length = old_length + 1
|
2015-05-17 13:38:25 +02:00
|
|
|
end
|
2015-05-15 15:45:36 +02:00
|
|
|
end
|
2015-05-12 17:52:01 +02:00
|
|
|
end
|
2015-05-15 15:45:36 +02:00
|
|
|
class Parfait::Class
|
2015-05-12 17:52:01 +02:00
|
|
|
end
|
2015-05-15 15:45:36 +02:00
|
|
|
class Parfait::List
|
2015-05-12 13:58:29 +02:00
|
|
|
end
|
2015-05-14 19:39:12 +02:00
|
|
|
|
2015-05-15 15:45:36 +02:00
|
|
|
# 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 |
|
2015-05-18 09:10:31 +02:00
|
|
|
word.set_char(index + 1 , code)
|
2015-05-14 19:39:12 +02:00
|
|
|
end
|
|
|
|
word
|
|
|
|
end
|
2015-05-16 13:01:48 +02:00
|
|
|
def self.new_list array
|
|
|
|
list = List.new_object
|
|
|
|
list.set_length array.length
|
2015-05-18 09:10:31 +02:00
|
|
|
index = 1
|
2015-05-16 13:01:48 +02:00
|
|
|
while index < array.length do
|
2015-05-18 09:10:31 +02:00
|
|
|
list.set(index , array[index - 1])
|
2015-05-16 13:01:48 +02:00
|
|
|
end
|
|
|
|
list
|
|
|
|
end
|
|
|
|
|
2015-05-15 19:31:43 +02:00
|
|
|
Word.class_eval do
|
|
|
|
def to_s
|
|
|
|
string = ""
|
2015-05-18 09:10:31 +02:00
|
|
|
index = 1
|
|
|
|
while( index <= self.length)
|
|
|
|
string[index - 1] = get_char(index).chr
|
2015-05-15 19:31:43 +02:00
|
|
|
index = index + 1
|
|
|
|
end
|
|
|
|
string
|
|
|
|
end
|
|
|
|
end
|
2015-05-14 19:39:12 +02:00
|
|
|
end
|