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/object"
|
||||||
require "parfait/module"
|
require "parfait/module"
|
||||||
require "parfait/class"
|
require "parfait/class"
|
||||||
require "parfait/hash"
|
require "parfait/dictionary"
|
||||||
require "parfait/array"
|
require "parfait/list"
|
||||||
require "parfait/string"
|
require "parfait/string"
|
||||||
require "parfait/message"
|
require "parfait/message"
|
||||||
require "parfait/frame"
|
require "parfait/frame"
|
||||||
@ -43,7 +43,7 @@ class Parfait::Object
|
|||||||
end
|
end
|
||||||
class Parfait::Class
|
class Parfait::Class
|
||||||
end
|
end
|
||||||
class Parfait::Array
|
class Parfait::List
|
||||||
def length
|
def length
|
||||||
internal_object_length
|
internal_object_length
|
||||||
end
|
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.
|
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,
|
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
|
#### 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
|
module Parfait
|
||||||
class Hash < Object
|
class Dictionary < Object
|
||||||
def initialize
|
def initialize
|
||||||
@keys = Array.new_object()
|
@keys = List.new_object()
|
||||||
@values = Array.new_object()
|
@values = List.new_object()
|
||||||
end
|
end
|
||||||
def values()
|
def values()
|
||||||
@values
|
@values
|
@ -14,8 +14,8 @@
|
|||||||
|
|
||||||
# In other words, the Layout is a list of names that describe
|
# In other words, the Layout is a list of names that describe
|
||||||
# the values stored in an actual object.
|
# the values stored in an actual object.
|
||||||
# The object is an array of values of length n and
|
# The object is an List of values of length n and
|
||||||
# the Layout is an array of names of length n
|
# the Layout is an List of names of length n
|
||||||
# Together they turn the object into a hash like structure
|
# Together they turn the object into a hash like structure
|
||||||
|
|
||||||
module Parfait
|
module Parfait
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
|
|
||||||
|
|
||||||
module Parfait
|
module Parfait
|
||||||
class Array < Object
|
class List < Object
|
||||||
|
|
||||||
# push means add to the end
|
# push means add to the end
|
||||||
# this automatically grows the array
|
# this automatically grows the List
|
||||||
def push value
|
def push value
|
||||||
self.set( length , value)
|
self.set( length , value)
|
||||||
end
|
end
|
||||||
@ -40,7 +40,7 @@ module Parfait
|
|||||||
index += 1
|
index += 1
|
||||||
end
|
end
|
||||||
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
|
# get/set/length/add/delete
|
||||||
# so they must be defined as CompiledMethods in Builtin::Kernel
|
# 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
|
# 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
|
# 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
|
# 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
|
# in an oo system all data is represented as objects
|
||||||
@ -24,7 +24,7 @@ module Parfait
|
|||||||
|
|
||||||
def initialize
|
def initialize
|
||||||
super()
|
super()
|
||||||
@classes = Parfait::Hash.new_object
|
@classes = Parfait::Dictionary.new_object
|
||||||
#global objects (data)
|
#global objects (data)
|
||||||
@objects = []
|
@objects = []
|
||||||
@symbols = []
|
@symbols = []
|
||||||
|
@ -106,7 +106,7 @@ end
|
|||||||
Virtual::Object.new.padded_words(2)
|
Virtual::Object.new.padded_words(2)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
Parfait::Hash.class_eval do
|
Parfait::Dictionary.class_eval do
|
||||||
include Positioned
|
include Positioned
|
||||||
HASH = { :names => [:keys,:values] , :types => [Virtual::Reference,Virtual::Reference]}
|
HASH = { :names => [:keys,:values] , :types => [Virtual::Reference,Virtual::Reference]}
|
||||||
def layout
|
def layout
|
||||||
@ -116,7 +116,7 @@ Parfait::Hash.class_eval do
|
|||||||
Virtual::Object.new.padded_words(2)
|
Virtual::Object.new.padded_words(2)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
::Parfait::Array.class_eval do
|
::Parfait::List.class_eval do
|
||||||
include Positioned
|
include Positioned
|
||||||
def layout
|
def layout
|
||||||
Virtual::Object.layout
|
Virtual::Object.layout
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
require_relative "test_array"
|
require_relative "test_list"
|
||||||
require_relative "test_hash"
|
require_relative "test_dictionary"
|
||||||
|
@ -3,7 +3,7 @@ require_relative "../helper"
|
|||||||
class TestDictionary < MiniTest::Test
|
class TestDictionary < MiniTest::Test
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
@lookup = ::Parfait::Hash.new
|
@lookup = ::Parfait::Dictionary.new
|
||||||
end
|
end
|
||||||
def test_list_create
|
def test_list_create
|
||||||
assert @lookup.empty?
|
assert @lookup.empty?
|
@ -3,7 +3,7 @@ require_relative "../helper"
|
|||||||
class TestList < MiniTest::Test
|
class TestList < MiniTest::Test
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
@list = ::Parfait::Array.new_object
|
@list = ::Parfait::List.new_object
|
||||||
end
|
end
|
||||||
def test_list_create
|
def test_list_create
|
||||||
assert @list.empty?
|
assert @list.empty?
|
Loading…
Reference in New Issue
Block a user