#include 'Apex.st'. #include 'Class.st'. #include 'Boolean.st'. ######################################################################################### #class Error(Object) { #method(#class) signal: aString { "accept an arbitary object instead of a string. the object can be sent displayString for string conversion" } } #class Magnitude(Object) { } #class Association(Magnitude) { #dcl key value. } #class Character(Magnitude) { ## #method basicSize ## { ## ^0 ## } } #class Number(Magnitude) { #method + aNumber { self primitiveFailed. } #method - aNumber { self primitiveFailed. } #method * aNumber { self primitiveFailed. } #method quo: aNumber { self primitiveFailed. } #method rem: aNumber { self primitiveFailed. } #method // aNumber { self primitiveFailed. } #method \\ aNumber { self primitiveFailed. } #method = aNumber { self primitiveFailed. } #method ~= aNumber { self primitiveFailed. } #method < aNumber { self primitiveFailed. } #method > aNumber { self primitiveFailed. } #method <= aNumber { self primitiveFailed. } #method >= aNumber { self primitiveFailed. } #method negated { ^0 - self. } #method bitAt: index { "## index is 1-based" ^(self bitShift: (index - 1) negated) bitAnd: 1. } #method bitAnd: aNumber { self primitiveFailed. } #method bitOr: aNumber { self primitiveFailed. } #method bitXor: aNumber { self primitiveFailed. } #method bitInvert { ^-1 - self. } #method bitShift: aNumber { self primitiveFailed. } #method asString { ^self printStringRadix: 10 } #method printStringRadix: aNumber { self primitiveFailed. } #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 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 ## } } #class(#liword) LargeInteger(Integer) { } #class(#liword) LargePositiveInteger(LargeInteger) { #method abs { ^self. } #method sign { ^1. } } #class(#liword) LargeNegativeInteger(LargeInteger) { #method abs { ^self negated. } #method sign { ^-1. } } #include 'Collect.st'. #class(#pointer) CompiledMethod(Object) { ## #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 } } #include 'Context.st'. #include 'Except.st'. #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. self.handle := self privateOpen: self.name. "[ self.handle := self privateOpen: self.name ] on: Error do: [ ] on: XError 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 { ^nil. ## TODO: Error signal: 'can not open' } #method privateClose: aHandle { } #method privateCall: aSymbol withSig: aString withArgs: anArray { } #method privateGetSymbol: aString in: aHandle { ^nil. } } ######################################################################################### ## #include 'Console.st'