2015-07-14 13:35:18 +00:00
|
|
|
#class Apex(nil)
|
2015-07-01 15:01:39 +00:00
|
|
|
{
|
|
|
|
#dcl(#class) sysdic.
|
|
|
|
|
|
|
|
#method(#class) yourself
|
|
|
|
{
|
|
|
|
^self.
|
|
|
|
}
|
|
|
|
|
|
|
|
#method yourself
|
|
|
|
{
|
|
|
|
^self.
|
|
|
|
}
|
|
|
|
|
|
|
|
#method(#class) dump
|
|
|
|
{
|
2015-10-03 15:29:03 +00:00
|
|
|
<primitive: #dump>
|
2015-07-01 15:01:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#method dump
|
|
|
|
{
|
2015-10-03 15:29:03 +00:00
|
|
|
<primitive: #dump>
|
2015-07-01 15:01:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#method(#class) new
|
|
|
|
{
|
2015-10-03 15:29:03 +00:00
|
|
|
## <primitive: 1>
|
|
|
|
<primitive: #new>
|
2015-07-01 15:01:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#method(#class) new: anInteger
|
|
|
|
{
|
2015-10-03 15:29:03 +00:00
|
|
|
## <primitive: 2>
|
|
|
|
<primitive: #new:>
|
2015-07-01 15:01:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#method basicSize
|
|
|
|
{
|
2015-10-03 15:29:03 +00:00
|
|
|
## <primitive: 3>
|
|
|
|
<primitive: #basicSize>
|
2015-07-01 15:01:39 +00:00
|
|
|
^0
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#method basicAt: anInteger
|
|
|
|
{
|
2015-10-03 15:29:03 +00:00
|
|
|
## <primitive: 4>
|
|
|
|
<primitive: #basicAt:>
|
2015-07-01 15:01:39 +00:00
|
|
|
## self error: 'out of range'.
|
|
|
|
}
|
|
|
|
|
|
|
|
#method basicAt: anInteger put: anObject
|
|
|
|
{
|
2015-10-03 15:29:03 +00:00
|
|
|
## <primitive: 5>
|
|
|
|
<primitive: #basicAt:put:>
|
2015-07-01 15:01:39 +00:00
|
|
|
## self error: 'out of range'.
|
|
|
|
}
|
|
|
|
|
|
|
|
#method badReturnError
|
|
|
|
{
|
|
|
|
## TODO: implement this
|
|
|
|
}
|
|
|
|
|
|
|
|
#method mustBeBoolean
|
|
|
|
{
|
|
|
|
## TODO: implement this
|
|
|
|
}
|
|
|
|
|
|
|
|
#method doesNotUnderstand: aMessageSymbol
|
|
|
|
{
|
|
|
|
## TODO: implement this
|
|
|
|
}
|
|
|
|
|
|
|
|
#method error: anErrorString
|
|
|
|
{
|
|
|
|
anErrorString dump.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-14 13:35:18 +00:00
|
|
|
#class Object(Apex)
|
2015-07-01 15:01:39 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-07-14 13:35:18 +00:00
|
|
|
#class UndefinedObject(Apex)
|
2015-07-01 15:01:39 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-07-14 13:35:18 +00:00
|
|
|
#class(#pointer) Class(Apex)
|
2015-07-01 15:01:39 +00:00
|
|
|
{
|
2015-07-26 14:38:34 +00:00
|
|
|
#dcl spec selfspec superclass subclasses name instvars classvars classinstvars pooldics instmthdic classmthdic.
|
2015-07-01 15:01:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#class Magnitude(Object)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
#class Association(Magnitude)
|
|
|
|
{
|
|
|
|
#dcl key value.
|
|
|
|
}
|
|
|
|
|
|
|
|
#class Character(Magnitude)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
#class Number(Magnitude)
|
|
|
|
{
|
|
|
|
#method add: aNumber
|
|
|
|
{
|
|
|
|
<primitive: 7>
|
|
|
|
}
|
|
|
|
|
|
|
|
#method + aNumber
|
|
|
|
{
|
|
|
|
<primitive: 7>
|
|
|
|
}
|
|
|
|
|
|
|
|
#method - aNumber
|
|
|
|
{
|
|
|
|
<primitive: 8>
|
|
|
|
}
|
|
|
|
|
|
|
|
#method * aNumber
|
|
|
|
{
|
|
|
|
<primitive: 8>
|
|
|
|
}
|
|
|
|
|
|
|
|
#method = aNumber
|
|
|
|
{
|
|
|
|
<primitive: 10>
|
|
|
|
}
|
|
|
|
|
|
|
|
#method < aNumber
|
|
|
|
{
|
|
|
|
<primitive: 11>
|
|
|
|
}
|
|
|
|
|
|
|
|
#method > aNumber
|
|
|
|
{
|
|
|
|
<primitive: 12>
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#class SmallInteger(Number)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
#class Boolean(Object)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#class True(Boolean)
|
|
|
|
{
|
|
|
|
#method ifTrue: trueBlock ifFalse: falseBlock
|
|
|
|
{
|
|
|
|
^trueBlock value.
|
|
|
|
}
|
|
|
|
|
|
|
|
#method ifTrue: trueBlock
|
|
|
|
{
|
|
|
|
^trueBlock value.
|
|
|
|
}
|
|
|
|
|
|
|
|
#method ifFalse: falseBlock
|
|
|
|
{
|
|
|
|
^nil.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#class False(Boolean)
|
|
|
|
{
|
|
|
|
#method ifTrue: trueBlock ifFalse: falseBlock
|
|
|
|
{
|
|
|
|
^falseBlock value.
|
|
|
|
}
|
|
|
|
|
|
|
|
#method ifTrue: trueBlock
|
|
|
|
{
|
|
|
|
^nil.
|
|
|
|
}
|
|
|
|
|
|
|
|
#method ifFalse: falseBlock
|
|
|
|
{
|
|
|
|
^falseBlock value.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#class Collection(Object)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
#class(#byte) ByteArray(Collection)
|
|
|
|
{
|
|
|
|
#method at: anInteger
|
|
|
|
{
|
|
|
|
^self basicAt: anInteger.
|
|
|
|
}
|
|
|
|
|
|
|
|
#method at: anInteger put: aValue
|
|
|
|
{
|
|
|
|
^self basicAt: anInteger put: aValue.
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#class(#pointer) Array(Collection)
|
|
|
|
{
|
|
|
|
#method at: anInteger
|
|
|
|
{
|
|
|
|
^self basicAt: anInteger.
|
|
|
|
}
|
|
|
|
|
|
|
|
#method at: anInteger put: aValue
|
|
|
|
{
|
|
|
|
^self basicAt: anInteger put: aValue.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#class(#character) String(Array)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
#class(#character) Symbol(Array)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#class Set(Collection)
|
|
|
|
{
|
|
|
|
#dcl tally bucket.
|
|
|
|
}
|
|
|
|
|
|
|
|
#class SymbolSet(Set)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
#class Dictionary(Set)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
#class SystemDictionary(Dictionary)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-07-12 17:14:21 +00:00
|
|
|
#class Namespace(Set)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-07-14 13:35:18 +00:00
|
|
|
#class PoolDictionary(Set)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-07-01 15:01:39 +00:00
|
|
|
#class MethodDictionary(Dictionary)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-07-14 13:35:18 +00:00
|
|
|
#class(#pointer) Context(Apex)
|
2015-07-01 15:01:39 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
#class(#pointer) MethodContext(Context)
|
|
|
|
{
|
|
|
|
#dcl sender ip sp ntmprs method receiver home origin.
|
|
|
|
|
|
|
|
#method pc
|
|
|
|
{
|
|
|
|
^ip
|
|
|
|
}
|
|
|
|
|
|
|
|
#method pc: anInteger
|
|
|
|
{
|
|
|
|
ip := anInteger.
|
|
|
|
"sp := sp - 1." "whould this always work??? "
|
|
|
|
}
|
|
|
|
|
|
|
|
#method sp
|
|
|
|
{
|
|
|
|
^sp.
|
|
|
|
|
|
|
|
}
|
|
|
|
#method sp: anInteger
|
|
|
|
{
|
|
|
|
sp := anInteger.
|
|
|
|
}
|
|
|
|
|
|
|
|
#method pc: aPC sp: aSP
|
|
|
|
{
|
|
|
|
ip := aPC.
|
|
|
|
sp := aSP.
|
|
|
|
##sp := sp - 1.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#class(#pointer) BlockContext(Context)
|
|
|
|
{
|
|
|
|
#dcl caller ip sp ntmprs nargs source home origin.
|
|
|
|
|
|
|
|
#method value
|
|
|
|
{
|
|
|
|
<primitive: 6>
|
|
|
|
}
|
|
|
|
|
|
|
|
#method value: a
|
|
|
|
{
|
|
|
|
<primitive: 6>
|
|
|
|
}
|
|
|
|
|
|
|
|
#method value: a value: b
|
|
|
|
{
|
|
|
|
<primitive: 6>
|
|
|
|
}
|
|
|
|
|
|
|
|
#method value: a value: b value: c
|
|
|
|
{
|
|
|
|
<primitive: 6>
|
|
|
|
}
|
|
|
|
|
|
|
|
#method whileTrue: aBlock
|
|
|
|
{
|
|
|
|
## http://stackoverflow.com/questions/2500483/is-there-a-way-in-a-message-only-language-to-define-a-whiletrue-message-without
|
|
|
|
|
|
|
|
## ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
## ^(self value) ifTrue: [aBlock value. self whileTrue: aBlock].
|
|
|
|
|
|
|
|
## ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
## less block context before whileTrue: is recursively sent.
|
|
|
|
## whileTrue: is sent in a method context.
|
|
|
|
## (self value) ifFalse: [^nil].
|
|
|
|
## aBlock value.
|
|
|
|
## self whileTrue: aBlock.
|
|
|
|
|
|
|
|
## ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
## ----------------------------------------------------------------------------
|
|
|
|
| pc sp xsp |
|
|
|
|
|
|
|
|
sp := thisContext sp.
|
|
|
|
sp := sp - 1. "decrement sp by 1 becuase thisContext pushed above affects the sp method"
|
|
|
|
pc := thisContext pc.
|
|
|
|
self value ifFalse: [ ^nil "^self" ].
|
|
|
|
aBlock value.
|
|
|
|
##thisContext pc: pc - 3 sp: sp.
|
|
|
|
##thisContext pc: pc + 2 sp: sp.
|
|
|
|
thisContext pc: pc + 1 sp: sp.
|
|
|
|
## this +2 or - 3 above is dependent on the byte code instruction size used for 'store'
|
|
|
|
## +2 to skip STORE_INTO_TEMP(pc) and POP_STACKTOP.
|
|
|
|
## TODO: make it independent of the byte code size
|
|
|
|
|
|
|
|
## ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
## #<label>:
|
|
|
|
## thisContext pc: #<label> sp: sp.
|
|
|
|
##
|
|
|
|
## | pc |
|
|
|
|
## pc := thisContext pc.
|
|
|
|
## ^self value ifTrue: [aBlock value. thisContext pc: pc]
|
|
|
|
|
|
|
|
## ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
## self value ifTrue: [ aBlock value. thisContext restart. ].
|
|
|
|
}
|
|
|
|
|
|
|
|
#method pc
|
|
|
|
{
|
|
|
|
^ip
|
|
|
|
}
|
|
|
|
|
|
|
|
#method pc: anInteger
|
|
|
|
{
|
|
|
|
ip := anInteger.
|
|
|
|
}
|
|
|
|
|
|
|
|
#method sp
|
|
|
|
{
|
|
|
|
^sp
|
|
|
|
}
|
|
|
|
|
|
|
|
#method sp: anInteger
|
|
|
|
{
|
|
|
|
sp := anInteger.
|
|
|
|
}
|
|
|
|
|
|
|
|
#method restart
|
|
|
|
{
|
|
|
|
ip := source pc.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#class(#pointer) CompiledMethod(Object)
|
|
|
|
{
|
|
|
|
#dcl owner preamble ntmprs nargs code source.
|
|
|
|
}
|
|
|
|
|
2015-10-03 15:29:03 +00:00
|
|
|
|
|
|
|
#class FFI(Object)
|
|
|
|
{
|
|
|
|
#dcl name handle funcs.
|
|
|
|
|
|
|
|
#method(#class) new: aString
|
|
|
|
{
|
|
|
|
^self new open: aString.
|
|
|
|
}
|
|
|
|
|
|
|
|
#method open: aString
|
|
|
|
{
|
|
|
|
self.funcs := Dictionary new.
|
|
|
|
self.name := aString.
|
|
|
|
self.handle := self privateOpen: self.name.
|
|
|
|
}
|
|
|
|
|
|
|
|
#method close
|
|
|
|
{
|
|
|
|
self privateClose: self.handle.
|
|
|
|
self.handle := nil.
|
|
|
|
}
|
|
|
|
|
|
|
|
#method call: aFunctionName withArgs: anArgArray
|
|
|
|
{
|
|
|
|
| f |
|
|
|
|
|
|
|
|
f := self.funcs at: aFunctionName.
|
|
|
|
f isNil ifTrue: [
|
|
|
|
f := self privateGetSymbol: aFunctionName in: self.handle.
|
|
|
|
f isNil ifTrue: [ self error: 'No such function' ].
|
|
|
|
self.funcs at: aFunctionName put: f.
|
|
|
|
].
|
|
|
|
|
|
|
|
^self privateCall: f withArgs: anArgArray.
|
|
|
|
}
|
|
|
|
|
|
|
|
#method privateOpen: aString
|
|
|
|
{
|
|
|
|
<primitive: #ffiOpen>
|
|
|
|
## throw an exception here.
|
|
|
|
}
|
|
|
|
|
|
|
|
#method privateClose: aHandle
|
|
|
|
{
|
|
|
|
<primitive: #ffiClose>
|
|
|
|
}
|
|
|
|
|
|
|
|
#method privateCall: aFFISym withArgs: anArgArray
|
|
|
|
{
|
|
|
|
<primitive: #ffiCall>
|
|
|
|
}
|
|
|
|
|
|
|
|
#method privateGetSymbol: aString in: aHandle
|
|
|
|
{
|
|
|
|
<primitive: #ffiGetSym>
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|