2017-01-06 09:53:40 +00:00
|
|
|
|
|
|
|
class Collection(Object)
|
2015-10-08 14:26:04 +00:00
|
|
|
{
|
|
|
|
}
|
2016-05-13 15:10:34 +00:00
|
|
|
|
|
|
|
## -------------------------------------------------------------------------------
|
2017-01-06 09:53:40 +00:00
|
|
|
class(#pointer) Array(Collection)
|
2016-05-13 15:10:34 +00:00
|
|
|
{
|
2017-01-06 09:53:40 +00:00
|
|
|
method size
|
2016-05-13 15:10:34 +00:00
|
|
|
{
|
2017-01-06 09:53:40 +00:00
|
|
|
^self basicSize
|
2016-05-13 15:10:34 +00:00
|
|
|
}
|
|
|
|
|
2017-01-06 09:53:40 +00:00
|
|
|
method at: anInteger
|
2016-05-13 15:10:34 +00:00
|
|
|
{
|
|
|
|
^self basicAt: anInteger.
|
|
|
|
}
|
|
|
|
|
2017-01-06 09:53:40 +00:00
|
|
|
method at: anInteger put: aValue
|
2016-05-13 15:10:34 +00:00
|
|
|
{
|
|
|
|
^self basicAt: anInteger put: aValue.
|
|
|
|
}
|
|
|
|
|
2017-01-06 09:53:40 +00:00
|
|
|
method first
|
2016-05-13 15:10:34 +00:00
|
|
|
{
|
|
|
|
^self at: 0.
|
|
|
|
}
|
|
|
|
|
2017-01-06 09:53:40 +00:00
|
|
|
method last
|
2016-05-13 15:10:34 +00:00
|
|
|
{
|
2017-01-06 09:53:40 +00:00
|
|
|
^self at: (self basicSize - 1).
|
2016-05-13 15:10:34 +00:00
|
|
|
}
|
|
|
|
|
2017-01-06 09:53:40 +00:00
|
|
|
method do: aBlock
|
2016-05-13 15:10:34 +00:00
|
|
|
{
|
2017-01-06 09:53:40 +00:00
|
|
|
0 priorTo: (self basicSize) do: [:i | aBlock value: (self at: i)].
|
2016-05-13 15:10:34 +00:00
|
|
|
}
|
|
|
|
|
2017-01-06 09:53:40 +00:00
|
|
|
method copy: anArray
|
2016-05-13 15:10:34 +00:00
|
|
|
{
|
2017-01-06 09:53:40 +00:00
|
|
|
0 priorTo: (anArray basicSize) do: [:i | self at: i put: (anArray at: i) ].
|
2016-05-13 15:10:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
## -------------------------------------------------------------------------------
|
|
|
|
|
2017-01-06 09:53:40 +00:00
|
|
|
class(#character) String(Array)
|
2016-05-13 15:10:34 +00:00
|
|
|
{
|
2017-01-06 09:53:40 +00:00
|
|
|
method & string
|
2016-05-13 15:10:34 +00:00
|
|
|
{
|
2017-01-05 10:16:04 +00:00
|
|
|
(* TOOD: make this a primitive for performance. *)
|
|
|
|
|
|
|
|
(* concatenate two strings. *)
|
|
|
|
| newsize newstr cursize appsize |
|
2016-06-22 03:23:14 +00:00
|
|
|
|
2017-01-05 10:16:04 +00:00
|
|
|
cursize := self basicSize.
|
|
|
|
appsize := string basicSize.
|
|
|
|
newsize := cursize + appsize.
|
|
|
|
(*newstr := self class basicNew: newsize.*)
|
|
|
|
newstr := String basicNew: newsize.
|
2016-06-22 03:23:14 +00:00
|
|
|
|
2017-01-05 10:16:04 +00:00
|
|
|
0 priorTo: cursize do: [:i | newstr at: i put: (self at: i) ].
|
|
|
|
0 priorTo: appsize do: [:i | newstr at: (i + cursize) put: (string at: i) ].
|
2016-06-22 03:23:14 +00:00
|
|
|
|
2016-05-13 15:10:34 +00:00
|
|
|
^newstr
|
|
|
|
}
|
2017-01-05 10:16:04 +00:00
|
|
|
|
2017-01-06 09:53:40 +00:00
|
|
|
method asString
|
2017-01-05 10:16:04 +00:00
|
|
|
{
|
|
|
|
^self
|
|
|
|
}
|
2016-05-13 15:10:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
## -------------------------------------------------------------------------------
|
|
|
|
|
2017-01-06 09:53:40 +00:00
|
|
|
class(#character) Symbol(String)
|
2016-05-13 15:10:34 +00:00
|
|
|
{
|
2017-01-06 09:53:40 +00:00
|
|
|
method asString
|
2017-01-05 10:16:04 +00:00
|
|
|
{
|
|
|
|
(* TODO: make this a primitive for performance *)
|
|
|
|
|
|
|
|
(* convert a symbol to a string *)
|
|
|
|
| size str |
|
|
|
|
size := self basicSize.
|
|
|
|
str := String basicNew: size.
|
|
|
|
|
|
|
|
0 priorTo: size do: [:i | str at: i put: (self at: i) ].
|
|
|
|
^str.
|
|
|
|
}
|
2016-05-13 15:10:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
## -------------------------------------------------------------------------------
|
|
|
|
|
2017-01-06 09:53:40 +00:00
|
|
|
class(#byte) ByteArray(Collection)
|
2016-05-13 15:10:34 +00:00
|
|
|
{
|
2017-01-06 09:53:40 +00:00
|
|
|
method at: anInteger
|
2016-05-13 15:10:34 +00:00
|
|
|
{
|
|
|
|
^self basicAt: anInteger.
|
|
|
|
}
|
|
|
|
|
2017-01-06 09:53:40 +00:00
|
|
|
method at: anInteger put: aValue
|
2016-05-13 15:10:34 +00:00
|
|
|
{
|
|
|
|
^self basicAt: anInteger put: aValue.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
## -------------------------------------------------------------------------------
|
|
|
|
|
2017-01-06 09:53:40 +00:00
|
|
|
class Set(Collection)
|
2016-05-13 15:10:34 +00:00
|
|
|
{
|
2017-01-06 09:53:40 +00:00
|
|
|
dcl tally bucket.
|
2017-01-05 10:16:04 +00:00
|
|
|
|
2017-01-06 09:53:40 +00:00
|
|
|
method initialize
|
2017-01-05 10:16:04 +00:00
|
|
|
{
|
|
|
|
self.tally := 0.
|
|
|
|
self.bucket := Array new: 100.
|
|
|
|
}
|
|
|
|
|
2017-01-06 09:53:40 +00:00
|
|
|
method size
|
2017-01-05 10:16:04 +00:00
|
|
|
{
|
|
|
|
^self.tally
|
|
|
|
}
|
|
|
|
|
2017-01-06 09:53:40 +00:00
|
|
|
method at: key
|
2017-01-05 10:16:04 +00:00
|
|
|
{
|
|
|
|
| ass |
|
|
|
|
ass := self __find: key or_upsert: false with: nil.
|
|
|
|
(ass notNil) ifTrue: [^ass value].
|
|
|
|
^ErrorCode.NOENT
|
|
|
|
}
|
|
|
|
|
2017-01-06 09:53:40 +00:00
|
|
|
method at: key ifAbsent: error_block
|
2017-01-05 10:16:04 +00:00
|
|
|
{
|
|
|
|
| ass |
|
|
|
|
ass := self __find: key or_upsert: false with: nil.
|
|
|
|
(ass notNil) ifTrue: [^ass value].
|
|
|
|
^error_block value.
|
|
|
|
}
|
|
|
|
|
2017-01-06 09:53:40 +00:00
|
|
|
method at: key put: value
|
2017-01-05 10:16:04 +00:00
|
|
|
{
|
|
|
|
self __find: key or_upsert: true with: value.
|
|
|
|
^value
|
|
|
|
}
|
|
|
|
|
2017-01-06 09:53:40 +00:00
|
|
|
method __find: key or_upsert: upsert with: value
|
2017-01-05 10:16:04 +00:00
|
|
|
{
|
|
|
|
| hv ass bs index ntally |
|
|
|
|
|
|
|
|
bs := self.bucket size.
|
|
|
|
hv := key hash.
|
|
|
|
index := hv rem: bs.
|
|
|
|
|
|
|
|
[(ass := self.bucket at: index) notNil]
|
|
|
|
whileTrue: [
|
2017-01-06 09:53:40 +00:00
|
|
|
[key == ass key] ifTrue: [ (* TODO: change it to equality??? *)
|
2017-01-05 10:16:04 +00:00
|
|
|
(* found *)
|
|
|
|
upsert ifTrue: [ass value: value].
|
|
|
|
^ass
|
|
|
|
].
|
|
|
|
index := (index + 1) rem: bs.
|
|
|
|
].
|
|
|
|
|
|
|
|
upsert ifFalse: [^nil].
|
|
|
|
|
|
|
|
ntally := self.tally + 1.
|
|
|
|
(ntally >= bs) ifTrue: [
|
|
|
|
(* expand the bucket *)
|
|
|
|
|
|
|
|
].
|
|
|
|
|
|
|
|
ass := Association key: key value: value.
|
|
|
|
self.tally := ntally.
|
|
|
|
self.bucket at: index put: ass.
|
|
|
|
|
|
|
|
^ass
|
|
|
|
}
|
|
|
|
|
2017-01-06 09:53:40 +00:00
|
|
|
method do: block
|
2017-01-05 10:16:04 +00:00
|
|
|
{
|
|
|
|
| bs |
|
|
|
|
|
|
|
|
bs := self.bucket size.
|
|
|
|
0 priorTo: bs by: 1 do: [:i |
|
|
|
|
| ass |
|
|
|
|
(ass := self.bucket at: i) notNil ifTrue: [block value: ass value]
|
|
|
|
].
|
|
|
|
}
|
|
|
|
|
2017-01-06 09:53:40 +00:00
|
|
|
method keysAndValuesDo: block
|
2017-01-05 10:16:04 +00:00
|
|
|
{
|
|
|
|
| bs |
|
|
|
|
|
|
|
|
bs := self.bucket size.
|
|
|
|
0 priorTo: bs by: 1 do: [:i |
|
|
|
|
| ass |
|
|
|
|
(ass := self.bucket at: i) notNil ifTrue: [block value: ass key value: ass value]
|
|
|
|
].
|
|
|
|
}
|
2016-05-13 15:10:34 +00:00
|
|
|
}
|
|
|
|
|
2017-01-06 09:53:40 +00:00
|
|
|
class SymbolSet(Set)
|
2016-05-13 15:10:34 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-01-06 09:53:40 +00:00
|
|
|
class Dictionary(Set)
|
2016-05-13 15:10:34 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-01-06 09:53:40 +00:00
|
|
|
pooldic Log
|
2016-05-13 15:10:34 +00:00
|
|
|
{
|
2016-06-30 13:44:37 +00:00
|
|
|
## -----------------------------------------------------------
|
2016-07-01 16:31:47 +00:00
|
|
|
## defines log levels
|
2016-06-30 13:44:37 +00:00
|
|
|
## these items must follow defintions in stix.h
|
|
|
|
## -----------------------------------------------------------
|
2016-07-01 16:31:47 +00:00
|
|
|
|
2016-06-30 13:44:37 +00:00
|
|
|
#DEBUG := 1.
|
|
|
|
#INFO := 2.
|
|
|
|
#WARN := 4.
|
|
|
|
#ERROR := 8.
|
|
|
|
#FATAL := 16.
|
2016-05-13 15:10:34 +00:00
|
|
|
}
|
|
|
|
|
2017-01-06 09:53:40 +00:00
|
|
|
class SystemDictionary(Dictionary)
|
2016-06-30 13:44:37 +00:00
|
|
|
{
|
|
|
|
## the following methods may not look suitable to be placed
|
|
|
|
## inside a system dictionary. but they are here for quick and dirty
|
|
|
|
## output production from the stix code.
|
|
|
|
## System logNl: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'.
|
|
|
|
##
|
|
|
|
|
2017-01-06 09:53:40 +00:00
|
|
|
dcl(#pooldic) Log.
|
2016-06-30 13:44:37 +00:00
|
|
|
|
2017-01-06 09:53:40 +00:00
|
|
|
method atLevel: level log: message
|
2016-07-01 16:31:47 +00:00
|
|
|
{
|
|
|
|
<primitive: #_log>
|
|
|
|
## do nothing upon logging failure
|
|
|
|
}
|
|
|
|
|
2017-01-06 09:53:40 +00:00
|
|
|
method atLevel: level log: message and: message2
|
2016-07-01 16:31:47 +00:00
|
|
|
{
|
|
|
|
<primitive: #_log>
|
|
|
|
## do nothing upon logging failure
|
|
|
|
}
|
|
|
|
|
2017-01-06 09:53:40 +00:00
|
|
|
method atLevel: level log: message and: message2 and: message3
|
2016-06-30 13:44:37 +00:00
|
|
|
{
|
|
|
|
<primitive: #_log>
|
|
|
|
## do nothing upon logging failure
|
|
|
|
}
|
|
|
|
|
2017-01-06 09:53:40 +00:00
|
|
|
method atLevel: level logNl: message
|
2016-06-30 13:44:37 +00:00
|
|
|
{
|
2016-07-01 16:31:47 +00:00
|
|
|
## the #_log primitive accepts an array.
|
|
|
|
## so the following lines should work also.
|
|
|
|
## | x |
|
|
|
|
## x := Array new: 2.
|
|
|
|
## x at: 0 put: message.
|
|
|
|
## x at: 1 put: S'\n'.
|
|
|
|
## ^self atLevel: level log: x.
|
|
|
|
|
|
|
|
^self atLevel: level log: message and: S'\n'.
|
|
|
|
}
|
|
|
|
|
2017-01-06 09:53:40 +00:00
|
|
|
method atLevel: level logNl: message and: message2
|
2016-07-01 16:31:47 +00:00
|
|
|
{
|
|
|
|
^self atLevel: level log: message and: message2 and: S'\n'.
|
2016-06-30 13:44:37 +00:00
|
|
|
}
|
|
|
|
|
2017-01-06 09:53:40 +00:00
|
|
|
method log: message
|
2016-06-30 13:44:37 +00:00
|
|
|
{
|
2016-07-01 16:31:47 +00:00
|
|
|
^self atLevel: Log.INFO log: message.
|
2016-06-30 13:44:37 +00:00
|
|
|
}
|
|
|
|
|
2017-01-06 09:53:40 +00:00
|
|
|
method log: message and: message2
|
2016-07-04 15:36:10 +00:00
|
|
|
{
|
|
|
|
^self atLevel: Log.INFO log: message and: message2.
|
|
|
|
}
|
|
|
|
|
2017-01-06 09:53:40 +00:00
|
|
|
method logNl: message
|
2016-06-30 13:44:37 +00:00
|
|
|
{
|
2016-07-01 16:31:47 +00:00
|
|
|
^self atLevel: Log.INFO logNl: message.
|
2016-06-30 13:44:37 +00:00
|
|
|
}
|
2016-07-04 15:36:10 +00:00
|
|
|
|
2017-01-06 09:53:40 +00:00
|
|
|
method logNl: message and: message2
|
2016-07-04 15:36:10 +00:00
|
|
|
{
|
|
|
|
^self atLevel: Log.INFO logNl: message and: message2.
|
|
|
|
}
|
2017-01-06 09:53:40 +00:00
|
|
|
|
|
|
|
method at: key
|
|
|
|
{
|
|
|
|
(key class = Symbol) ifTrue: [InvalidArgumentException signal: 'argument is not a symbol'].
|
|
|
|
^super at: key.
|
|
|
|
}
|
2016-06-30 13:44:37 +00:00
|
|
|
}
|
2016-05-13 15:10:34 +00:00
|
|
|
|
2017-01-06 09:53:40 +00:00
|
|
|
class Namespace(Set)
|
2016-05-13 15:10:34 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-01-06 09:53:40 +00:00
|
|
|
class PoolDictionary(Set)
|
2016-05-13 15:10:34 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-01-06 09:53:40 +00:00
|
|
|
class MethodDictionary(Dictionary)
|
2016-05-13 15:10:34 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-01-06 09:53:40 +00:00
|
|
|
extend Apex
|
2016-07-01 16:31:47 +00:00
|
|
|
{
|
|
|
|
## -------------------------------------------------------
|
|
|
|
## Association has been defined now. let's add association
|
|
|
|
## creating methods
|
|
|
|
## -------------------------------------------------------
|
|
|
|
|
2017-01-06 09:53:40 +00:00
|
|
|
method(#class) -> object
|
2016-07-01 16:31:47 +00:00
|
|
|
{
|
|
|
|
^Association new key: self value: object
|
|
|
|
}
|
|
|
|
|
2017-01-06 09:53:40 +00:00
|
|
|
method -> object
|
2016-07-01 16:31:47 +00:00
|
|
|
{
|
|
|
|
^Association new key: self value: object
|
|
|
|
}
|
|
|
|
}
|