moo/stix/kernel/Stix.st

399 lines
5.6 KiB
Smalltalk
Raw Normal View History

#include 'Apex.st'.
#include 'Class.st'.
#include 'Boolean.st'.
2016-05-07 01:37:44 +00:00
#########################################################################################
#class Magnitude(Object)
{
}
#class Association(Magnitude)
{
#dcl key value.
#method key: key value: value
{
self.key := key.
self.value := value.
}
#method key
{
^self.key
}
#method value
{
^self.value
}
}
#class Character(Magnitude)
{
## #method basicSize
## {
## ^0
## }
}
#class Number(Magnitude)
{
#method + aNumber
{
2015-10-15 14:40:08 +00:00
<primitive: #_integer_add>
self primitiveFailed.
}
#method - aNumber
{
2015-10-15 14:40:08 +00:00
<primitive: #_integer_sub>
self primitiveFailed.
}
#method * aNumber
{
2015-10-15 14:40:08 +00:00
<primitive: #_integer_mul>
self primitiveFailed.
}
2015-11-22 13:32:06 +00:00
#method quo: aNumber
{
<primitive: #_integer_quo>
self primitiveFailed.
}
#method rem: aNumber
{
<primitive: #_integer_rem>
self primitiveFailed.
}
#method // aNumber
{
<primitive: #_integer_quo2>
self primitiveFailed.
}
#method \\ aNumber
{
<primitive: #_integer_rem2>
self primitiveFailed.
}
#method = aNumber
{
2015-10-15 14:40:08 +00:00
<primitive: #_integer_eq>
self primitiveFailed.
}
#method ~= aNumber
{
<primitive: #_integer_ne>
self primitiveFailed.
}
#method < aNumber
{
2015-10-15 14:40:08 +00:00
<primitive: #_integer_lt>
self primitiveFailed.
}
#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-12-25 05:09:17 +00:00
#method negated
{
<primitive: #_integer_negated>
^0 - self.
}
#method bitAt: index
{
2015-12-26 01:37:33 +00:00
<primitive: #_integer_bitat>
^(self bitShift: index negated) bitAnd: 1.
2015-12-25 05:09:17 +00:00
}
#method bitAnd: aNumber
{
<primitive: #_integer_bitand>
self primitiveFailed.
}
#method bitOr: aNumber
{
<primitive: #_integer_bitor>
self primitiveFailed.
}
#method bitXor: aNumber
{
<primitive: #_integer_bitxor>
self primitiveFailed.
}
#method bitInvert
{
2015-12-17 16:37:26 +00:00
<primitive: #_integer_bitinv>
2015-12-13 16:08:05 +00:00
^-1 - self.
}
#method bitShift: aNumber
{
<primitive: #_integer_bitshift>
self primitiveFailed.
}
#method asString
2015-12-13 16:08:05 +00:00
{
^self printStringRadix: 10
2015-12-13 16:08:05 +00:00
}
#method printStringRadix: aNumber
{
<primitive: #_integer_inttostr>
self primitiveFailed.
}
2015-10-15 14:40:08 +00:00
#method to: end by: step do: aBlock
{
| i |
i := self.
(step > 0)
ifTrue: [
[ i <= end ] whileTrue: [
aBlock value: i.
i := i + step.
].
]
ifFalse: [
[ i >= end ] whileTrue: [
aBlock value: i.
i := i - step.
].
].
}
#method to: end do: aBlock
{
^self to: end by: 1 do: aBlock.
}
#method priorTo: end by: step do: aBlock
{
| i |
i := self.
(step > 0)
ifTrue: [
[ i < end ] whileTrue: [
aBlock value: i.
i := i + step.
].
]
ifFalse: [
[ i > end ] whileTrue: [
aBlock value: i.
i := i - step.
].
].
}
#method priorTo: end do: aBlock
{
^self priorTo: end by: 1 do: aBlock.
}
#method abs
{
self < 0 ifTrue: [^self negated].
^self.
}
#method sign
{
self < 0 ifTrue: [^-1].
self > 0 ifTrue: [^1].
^0.
}
}
#class Integer(Number)
{
#method timesRepeat: aBlock
{
1 to: self by: 1 do: [ :count | aBlock value ].
}
}
#class SmallInteger(Integer)
{
## #method basicSize
## {
## ^0
## }
#method asError
{
<primitive: #_smooi_as_error>
}
#method asCharacter
{
<primitive: #_smooi_as_character>
}
}
#class(#liword) LargeInteger(Integer)
2015-10-29 15:24:46 +00:00
{
}
#class(#liword) LargePositiveInteger(LargeInteger)
2015-10-29 15:24:46 +00:00
{
#method abs
{
^self.
}
#method sign
{
^1.
}
2015-10-29 15:24:46 +00:00
}
#class(#liword) LargeNegativeInteger(LargeInteger)
2015-10-29 15:24:46 +00:00
{
#method abs
{
^self negated.
}
#method sign
{
^-1.
}
2015-10-29 15:24:46 +00:00
}
#########################################################################################
2015-10-29 15:24:46 +00:00
2016-05-18 14:53:20 +00:00
#include 'Collect.st'.
#class(#pointer) CompiledMethod(Object)
{
2016-05-27 15:01:54 +00:00
## #dcl owner name preamble preamble_data_1 preamble_data_2 ntmprs nargs code source.
#dcl owner name preamble preamble_data_1 preamble_data_2 ntmprs nargs source.
#method preamble
{
^self.preamble
}
#method preambleCode
{
^self.preamble bitAnd: 16rFF.
}
#method owner
{
^self.owner
}
#method name
{
^self.name
}
}
2015-10-15 14:40:08 +00:00
#include 'Context.st'.
#include 'Except.st'.
2015-10-15 14:40:08 +00:00
#include 'Process.st'.
#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
self.handle := self privateOpen: self.name.
"[ self.handle := self privateOpen: self.name ]
on: Exception do: [
]
on: XException do: [
]."
^self.
}
#method close
{
self privateClose: self.handle.
self.handle := nil.
}
#method call: aFunctionName withSig: aString withArgs: anArray
{
| 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.
## ].
f := self privateGetSymbol: aFunctionName in: self.handle.
f isNil ifTrue: [ self error: 'No such function' ].
^self privateCall: f withSig: aString withArgs: anArray
}
#method privateOpen: aString
{
2015-10-15 14:40:08 +00:00
<primitive: #_ffi_open>
^nil. ## TODO: Error signal: 'can not open'
}
#method privateClose: aHandle
{
2015-10-15 14:40:08 +00:00
<primitive: #_ffi_close>
}
#method privateCall: aSymbol withSig: aString withArgs: anArray
{
2015-10-15 14:40:08 +00:00
<primitive: #_ffi_call>
}
#method privateGetSymbol: aString in: aHandle
{
2015-10-15 14:40:08 +00:00
<primitive: #_ffi_getsym>
^nil.
}
}
2016-05-07 01:37:44 +00:00
#########################################################################################
#include 'Stdio.st'.
#include 'Console.st'.