renamed array and hash to list and dictionary
Since these are not the ruby classes, we don’t need the old names. They are misleading. An Array is a military term, we mean list And a Hash is an implementation of a Dictionary, or LookupTable
This commit is contained in:
parent
a94ce51c58
commit
dd41758dea
@ -2,8 +2,8 @@ require "parfait/value"
|
||||
require "parfait/object"
|
||||
require "parfait/module"
|
||||
require "parfait/class"
|
||||
require "parfait/hash"
|
||||
require "parfait/array"
|
||||
require "parfait/dictionary"
|
||||
require "parfait/list"
|
||||
require "parfait/string"
|
||||
require "parfait/message"
|
||||
require "parfait/frame"
|
||||
@ -43,7 +43,7 @@ class Parfait::Object
|
||||
end
|
||||
class Parfait::Class
|
||||
end
|
||||
class Parfait::Array
|
||||
class Parfait::List
|
||||
def length
|
||||
internal_object_length
|
||||
end
|
||||
|
@ -19,7 +19,7 @@ And thus parfait can be used at run-time.
|
||||
It's too simple: just slips off the mind like a fish into water.
|
||||
|
||||
Parfait has a brother, the Builtin module. Builtin contains everything that can not be coded in ruby,
|
||||
but we still need (things like array access).
|
||||
but we still need (things like List access).
|
||||
|
||||
#### Example: Message send
|
||||
|
||||
|
@ -1,10 +1,10 @@
|
||||
# almost simplest hash imaginable. make good use of arrays
|
||||
# almost simplest hash imaginable. make good use of Lists
|
||||
|
||||
module Parfait
|
||||
class Hash < Object
|
||||
class Dictionary < Object
|
||||
def initialize
|
||||
@keys = Array.new_object()
|
||||
@values = Array.new_object()
|
||||
@keys = List.new_object()
|
||||
@values = List.new_object()
|
||||
end
|
||||
def values()
|
||||
@values
|
@ -14,8 +14,8 @@
|
||||
|
||||
# In other words, the Layout is a list of names that describe
|
||||
# the values stored in an actual object.
|
||||
# The object is an array of values of length n and
|
||||
# the Layout is an array of names of length n
|
||||
# The object is an List of values of length n and
|
||||
# the Layout is an List of names of length n
|
||||
# Together they turn the object into a hash like structure
|
||||
|
||||
module Parfait
|
||||
|
@ -1,10 +1,10 @@
|
||||
|
||||
|
||||
module Parfait
|
||||
class Array < Object
|
||||
class List < Object
|
||||
|
||||
# push means add to the end
|
||||
# this automatically grows the array
|
||||
# this automatically grows the List
|
||||
def push value
|
||||
self.set( length , value)
|
||||
end
|
||||
@ -40,7 +40,7 @@ module Parfait
|
||||
index += 1
|
||||
end
|
||||
end
|
||||
#many basic array functions can not be defined in ruby, such as
|
||||
#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
|
||||
|
@ -15,7 +15,7 @@ module Parfait
|
||||
# it is a collection of objects, some of which are data, some classes, some functions
|
||||
|
||||
# The main entry is a function called (of all things) "main", This _must be supplied by the compling
|
||||
# There is a start and exit block that call main, which receives an array of strings
|
||||
# There is a start and exit block that call main, which receives an List of strings
|
||||
|
||||
# While data ususally would live in a .data section, we may also "inline" it into the code
|
||||
# in an oo system all data is represented as objects
|
||||
@ -24,7 +24,7 @@ module Parfait
|
||||
|
||||
def initialize
|
||||
super()
|
||||
@classes = Parfait::Hash.new_object
|
||||
@classes = Parfait::Dictionary.new_object
|
||||
#global objects (data)
|
||||
@objects = []
|
||||
@symbols = []
|
||||
|
@ -106,7 +106,7 @@ end
|
||||
Virtual::Object.new.padded_words(2)
|
||||
end
|
||||
end
|
||||
Parfait::Hash.class_eval do
|
||||
Parfait::Dictionary.class_eval do
|
||||
include Positioned
|
||||
HASH = { :names => [:keys,:values] , :types => [Virtual::Reference,Virtual::Reference]}
|
||||
def layout
|
||||
@ -116,7 +116,7 @@ Parfait::Hash.class_eval do
|
||||
Virtual::Object.new.padded_words(2)
|
||||
end
|
||||
end
|
||||
::Parfait::Array.class_eval do
|
||||
::Parfait::List.class_eval do
|
||||
include Positioned
|
||||
def layout
|
||||
Virtual::Object.layout
|
||||
|
@ -1,2 +1,2 @@
|
||||
require_relative "test_array"
|
||||
require_relative "test_hash"
|
||||
require_relative "test_list"
|
||||
require_relative "test_dictionary"
|
||||
|
@ -3,7 +3,7 @@ require_relative "../helper"
|
||||
class TestDictionary < MiniTest::Test
|
||||
|
||||
def setup
|
||||
@lookup = ::Parfait::Hash.new
|
||||
@lookup = ::Parfait::Dictionary.new
|
||||
end
|
||||
def test_list_create
|
||||
assert @lookup.empty?
|
@ -3,7 +3,7 @@ require_relative "../helper"
|
||||
class TestList < MiniTest::Test
|
||||
|
||||
def setup
|
||||
@list = ::Parfait::Array.new_object
|
||||
@list = ::Parfait::List.new_object
|
||||
end
|
||||
def test_list_create
|
||||
assert @list.empty?
|
Loading…
Reference in New Issue
Block a user