2015-10-08 14:26:04 +00:00
|
|
|
#include 'Apex.st'.
|
|
|
|
#include 'Object.st'.
|
|
|
|
#include 'UndefinedObject.st'.
|
|
|
|
#include 'Class.st'.
|
|
|
|
#include 'Boolean.st'.
|
2015-07-01 15:01:39 +00:00
|
|
|
|
|
|
|
|
2015-10-08 14:26:04 +00:00
|
|
|
#class Error(Object)
|
|
|
|
{
|
|
|
|
#method(#class) signal: aString
|
2015-07-01 15:01:39 +00:00
|
|
|
{
|
2015-10-08 14:26:04 +00:00
|
|
|
"accept an arbitary object instead of a string.
|
|
|
|
the object can be sent displayString for string conversion"
|
2015-07-01 15:01:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#class Magnitude(Object)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
#class Association(Magnitude)
|
|
|
|
{
|
|
|
|
#dcl key value.
|
|
|
|
}
|
|
|
|
|
|
|
|
#class Character(Magnitude)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
#class Number(Magnitude)
|
|
|
|
{
|
|
|
|
#method + aNumber
|
|
|
|
{
|
2015-10-15 14:40:08 +00:00
|
|
|
<primitive: #_integer_add>
|
|
|
|
self primitiveFailed.
|
2015-07-01 15:01:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#method - aNumber
|
|
|
|
{
|
2015-10-15 14:40:08 +00:00
|
|
|
<primitive: #_integer_sub>
|
|
|
|
self primitiveFailed.
|
2015-07-01 15:01:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#method * aNumber
|
|
|
|
{
|
2015-10-15 14:40:08 +00:00
|
|
|
<primitive: #_integer_mul>
|
|
|
|
self primitiveFailed.
|
2015-07-01 15:01:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#method = aNumber
|
|
|
|
{
|
2015-10-15 14:40:08 +00:00
|
|
|
<primitive: #_integer_eq>
|
|
|
|
self primitiveFailed.
|
|
|
|
}
|
|
|
|
|
|
|
|
#method ~= aNumber
|
|
|
|
{
|
|
|
|
<primitive: #_integer_ne>
|
|
|
|
self primitiveFailed.
|
2015-07-01 15:01:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#method < aNumber
|
|
|
|
{
|
2015-10-15 14:40:08 +00:00
|
|
|
<primitive: #_integer_lt>
|
|
|
|
self primitiveFailed.
|
2015-07-01 15:01:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#method > aNumber
|
|
|
|
{
|
2015-10-15 14:40:08 +00:00
|
|
|
<primitive: #_integer_gt>
|
|
|
|
self primitiveFailed.
|
|
|
|
}
|
|
|
|
|
|
|
|
#method <= aNumber
|
|
|
|
{
|
|
|
|
<primitive: #_integer_le>
|
|
|
|
self primitiveFailed.
|
|
|
|
}
|
|
|
|
|
|
|
|
#method >= aNumber
|
|
|
|
{
|
|
|
|
<primitive: #_integer_ge>
|
|
|
|
self primitiveFailed.
|
2015-07-01 15:01:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-10-15 14:40:08 +00:00
|
|
|
|
2015-10-08 14:26:04 +00:00
|
|
|
#method to: end by: step do: aBlock
|
2015-07-01 15:01:39 +00:00
|
|
|
{
|
2015-10-08 14:26:04 +00:00
|
|
|
| i |
|
2015-07-01 15:01:39 +00:00
|
|
|
|
2015-10-08 14:26:04 +00:00
|
|
|
i := self.
|
|
|
|
(step > 0)
|
|
|
|
ifTrue: [
|
|
|
|
[ i <= end ] whileTrue: [
|
|
|
|
aBlock value: i.
|
|
|
|
i := i + step.
|
|
|
|
]
|
|
|
|
]
|
|
|
|
ifFalse: [
|
|
|
|
[ i >= end ] whileTrue: [
|
|
|
|
aBlock value: i.
|
|
|
|
i := i - step.
|
|
|
|
]
|
|
|
|
].
|
2015-07-01 15:01:39 +00:00
|
|
|
}
|
|
|
|
|
2015-10-08 14:26:04 +00:00
|
|
|
#method to: end do: aBlock
|
2015-07-01 15:01:39 +00:00
|
|
|
{
|
2015-10-08 14:26:04 +00:00
|
|
|
^self to: end by: 1 do: aBlock.
|
2015-07-01 15:01:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-08 14:26:04 +00:00
|
|
|
#class SmallInteger(Number)
|
2015-07-14 13:35:18 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-10-08 14:26:04 +00:00
|
|
|
#include 'Collection.st'.
|
|
|
|
#include 'Collection-ByteArray.st'.
|
|
|
|
#include 'Collection-Array.st'.
|
|
|
|
#include 'Collection-Set.st'.
|
2015-07-01 15:01:39 +00:00
|
|
|
|
|
|
|
#class(#pointer) CompiledMethod(Object)
|
|
|
|
{
|
2015-10-08 14:26:04 +00:00
|
|
|
#dcl owner preamble preamble_data_1 preamble_data_2 ntmprs nargs code source.
|
2015-07-01 15:01:39 +00:00
|
|
|
}
|
|
|
|
|
2015-10-15 14:40:08 +00:00
|
|
|
#include 'Context.st'.
|
|
|
|
#include 'Process.st'.
|
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.
|
2015-10-14 13:25:36 +00:00
|
|
|
|
2015-10-03 15:29:03 +00:00
|
|
|
self.handle := self privateOpen: self.name.
|
2015-10-08 14:26:04 +00:00
|
|
|
|
|
|
|
"[ self.handle := self privateOpen: self.name ]
|
|
|
|
on: Error do: [
|
|
|
|
]
|
|
|
|
on: XError do: [
|
|
|
|
]."
|
|
|
|
|
|
|
|
^self.
|
2015-10-03 15:29:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#method close
|
|
|
|
{
|
|
|
|
self privateClose: self.handle.
|
|
|
|
self.handle := nil.
|
|
|
|
}
|
|
|
|
|
2015-10-04 16:21:31 +00:00
|
|
|
#method call: aFunctionName withSig: aString withArgs: anArray
|
2015-10-03 15:29:03 +00:00
|
|
|
{
|
|
|
|
| f |
|
|
|
|
|
2015-10-04 16:21:31 +00:00
|
|
|
## 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.
|
|
|
|
## ].
|
|
|
|
f := self privateGetSymbol: aFunctionName in: self.handle.
|
2015-10-08 14:26:04 +00:00
|
|
|
f isNil ifTrue: [ self error: 'No such function' ].
|
2015-10-03 15:29:03 +00:00
|
|
|
|
2015-10-04 16:21:31 +00:00
|
|
|
^self privateCall: f withSig: aString withArgs: anArray
|
2015-10-03 15:29:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#method privateOpen: aString
|
|
|
|
{
|
2015-10-15 14:40:08 +00:00
|
|
|
<primitive: #_ffi_open>
|
2015-10-08 14:26:04 +00:00
|
|
|
^nil. ## TODO: Error signal: 'can not open'
|
2015-10-03 15:29:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#method privateClose: aHandle
|
|
|
|
{
|
2015-10-15 14:40:08 +00:00
|
|
|
<primitive: #_ffi_close>
|
2015-10-03 15:29:03 +00:00
|
|
|
}
|
|
|
|
|
2015-10-04 16:21:31 +00:00
|
|
|
#method privateCall: aSymbol withSig: aString withArgs: anArray
|
2015-10-03 15:29:03 +00:00
|
|
|
{
|
2015-10-15 14:40:08 +00:00
|
|
|
<primitive: #_ffi_call>
|
2015-10-03 15:29:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#method privateGetSymbol: aString in: aHandle
|
|
|
|
{
|
2015-10-15 14:40:08 +00:00
|
|
|
<primitive: #_ffi_getsym>
|
2015-10-08 14:26:04 +00:00
|
|
|
^nil.
|
2015-10-03 15:29:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|