#class Apex(nil) { #dcl(#class) sysdic. ## ------------------------------------------------------- ## ------------------------------------------------------- #method(#class) dump { } #method dump { } ## ------------------------------------------------------- ## ------------------------------------------------------- #method(#class) yourself { ^self. } #method yourself { ^self. } ## ------------------------------------------------------- ## ------------------------------------------------------- #method(#class) basicNew { self primitiveFailed. } #method(#class) basicNew: anInteger { self primitiveFailed. } #method(#class) ngcNew { self primitiveFailed. } #method(#class) ngcNew: anInteger { self primitiveFailed. } #method(#class) new { | x | x := self basicNew. x initialize. "TODO: assess if it's good to call 'initialize' from new." ^x. } #method(#class) new: anInteger { | x | ## TODO: check if the class is a fixed class. ## if so, raise an exception. x := self basicNew: anInteger. x initialize. "TODO: assess if it's good to call 'initialize' from new." ^x. } #method initialize { "a subclass may override this method." ^self. } #method ngcDispose { self primitiveFailed. } ## ------------------------------------------------------- ## ------------------------------------------------------- #method shallowCopy { self primitiveFailed. } ## ------------------------------------------------------- ## ------------------------------------------------------- #method class { } #method(#class) class { ^Class } ## ------------------------------------------------------- ## ------------------------------------------------------- #method basicSize { self primitiveFailed. } #method(#class) basicSize { self primitiveFailed. } #method basicAt: anInteger { ## TODO: chagne it to 'self outOfRangeError' or something. self error: 'out of range'. } #method basicAt: anInteger put: anObject { self error: 'out of range'. } #method(#class) basicAt: anInteger { self error: 'out of range'. } #method(#class) basicAt: anInteger put: anObject { self error: 'out of range'. } ## ------------------------------------------------------- ## ------------------------------------------------------- #method == anObject { "check if the receiver is identical to anObject. this doesn't compare the contents" } #method ~~ anObject { ^(self == anObject) not. } #method(#class) == anObject { "check if the receiver is identical to anObject. this doesn't compare the contents" } #method(#class) ~~ anObject { ^(self == anObject) not. } ## TODO: add = and ~= for equality check. ## ------------------------------------------------------- ## COMMON QUERIES ## ------------------------------------------------------- #method isNil { "^self == nil." ^false } #method notNil { "^(self == nil) not" "^self ~= nil." ^true. } #method(#class) isNil { "^self == nil." ^false } #method(#class) notNil { "^(self == nil) not" "^self ~= nil." ^true. } #method isError { ^false } #method(#class) isError { ^false } ## ------------------------------------------------------- ## ------------------------------------------------------- #method(#class) inheritsFrom: aClass { | c | c := self superclass. [c notNil] whileTrue: [ [ c == aClass ] ifTrue: [^true]. c := c superclass. ]. ^false } #method(#class) isMemberOf: aClass { ## a class object is an instance of Class ## but Class inherits from Apex. On the other hand, ## most of ordinary classes are under Object again under Apex. ## special consideration is required here. ^aClass == Class } #method(#class) isKindOf: aClass { ^(self isMemberOf: aClass) or: [self inheritsFrom: aClass]. } #method isMemberOf: aClass { ^self class == aClass } #method isKindOf: aClass { ^(self isMemberOf: aClass) or: [self class inheritsFrom: aClass]. } ## ------------------------------------------------------- ## ------------------------------------------------------- " #method(#class) respondsTo: selectorSymbol { TODO: find selectorSymbol in the class method dictionary... } #method respondsTo: selectorSymbol { TODO: find selectorSymbol in the method dictionary... } " ## ------------------------------------------------------- ## ------------------------------------------------------- ## method(#class) primitiveFailed ## { ## this method will be added after Exception class has been defined. ## } #method primitiveFailed { self class primitiveFailed. } #method doesNotUnderstand: messageSymbol { self class doesNotUnderstand: messageSymbol } #method(#class) error: msgText { ## TODO: implement this ## Error signal: msgText. msgText dump. } #method error: aString { self class error: aString. } #method cannotInstantiate { self class cannotInstantiate } } #class Object(Apex) { } #class UndefinedObject(Apex) { #method isNil { ^true } #method notNil { ^false. } #method handleException: exception { ('### EXCEPTION NOT HANDLED #### ' & exception class name & ' - ' & exception messageText) dump. ## TODO: debug the current process???? " ## TODO: ensure to execute ensure blocks as well.... ####Processor activeProcess terminate. } } (* -------------------- #pooldic Error { #NONE := error(0). #GENERIC := error(1). # } ------------------- *) #class Error(Apex) { (* ---------------------------- TODO: support constant declaration... #const { #NONE := error(0). #GENERIC := error(1). } -------------------------------- *) #method isError { ^true } #method asInteger { } #method asString { } }