ProtoObject.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Fri, 04 Dec 2009 20:30:11 +0000
branchjv
changeset 17736 26cfea63471d
parent 17711 39faaaf888b4
child 17761 b0e5971141bc
permissions -rw-r--r--
Merged with trunk

"
 COPYRIGHT (c) 2004 by eXept Software AG
              All Rights Reserved

 This software is furnished under a license and may be used
 only in accordance with the terms of that license and with the
 inclusion of the above copyright notice.   This software may not
 be provided or otherwise made available to, or used by, any
 other person.  No title to or ownership of the software is
 hereby transferred.
"
"{ Package: 'stx:libbasic' }"

nil subclass:#ProtoObject
	instanceVariableNames:''
	classVariableNames:''
	poolDictionaries:''
	category:'Kernel-Objects'
!

!ProtoObject class methodsFor:'documentation'!

copyright
"
 COPYRIGHT (c) 2004 by eXept Software AG
              All Rights Reserved

 This software is furnished under a license and may be used
 only in accordance with the terms of that license and with the
 inclusion of the above copyright notice.   This software may not
 be provided or otherwise made available to, or used by, any
 other person.  No title to or ownership of the software is
 hereby transferred.
"
!

documentation
"
    a minimum object without much protocol;
    Provides the minimum required to prevent inspectors from crashing,
    and debuggers from blocking.
    (i.e. instead of inheriting from nil, better inherit from this).

    Named after a similar class found in Dolphin-Smalltalk.

    [author:]
        Claus Gittinger (not much authoring, though)
"
! !


!ProtoObject methodsFor:'error handling'!

doesNotUnderstand:aMessage
    "this message is sent by the runtime system (VM) when
     a message is not understood by some object (i.e. there
     is no method for that selector). The original message has
     been packed into aMessage (i.e. the receiver, selector and
     any arguments) and the original receiver is then sent the
     #doesNotUnderstand: message.
     Here, we raise another signal which usually enters the debugger.
     You can of course redefine #doesNotUnderstand: in your classes
     to implement message delegation, 
     or handle the MessageNotUnderstood exception gracefully."

    <context: #return>

    ^ MessageNotUnderstood raiseRequestWith:aMessage
! !

!ProtoObject methodsFor:'queries'!

class
    "return the receivers class"

%{  /* NOCONTEXT */

    RETURN ( __Class(self) );
%}

"
*** WARNING
***
*** this method has been automatically created,
*** since all nil-subclasses should respond to some minimum required
*** protocol.
***
*** Inspection and/or debugging of instances may not be possible,
*** if you remove/change this method. 
"
!

identityHash
    "return an Integer useful as a hash key for the receiver.
     This hash should return same values for the same object (i.e. use
     this to hash on identity of objects).

     We cannot use the Objects address (as other smalltalks do) since
     no object-table exists and the hashval must not change when objects
     are moved by the collector. Therefore we assign each object a unique
     Id in the object header itself as its hashed upon.
     (luckily we have 11 bits spare to do this - unluckily its only 11 bits).
     Time will show, if 11 bits are enough; if not, another entry in the
     object header will be needed, adding 4 bytes to every object. Alternatively,
     hashed-upon objects could add an instvar containing the hash value."

%{  /* NOCONTEXT */

    REGISTER unsigned INT hash;
    static unsigned nextHash = 0;

    if (__isNonNilObject(self)) {
        hash = __GET_HASH(self);
        if (hash == 0) {
            /* has no hash yet */

            if (++nextHash > __MAX_HASH__) {
                nextHash = 1;
            }
            hash = nextHash;
            __SET_HASH(self, hash);
        }

        /*
         * now, we got 11 bits for hashing;
         * make it as large as possible; since most hashers use the returned
         * key and take it modulo some prime number, this will allow for
         * better distribution (i.e. bigger empty spaces) in hashed collection.
         */
        hash = __MAKE_HASH__(hash);
        RETURN ( __mkSmallInteger(hash) );
    }
%}.
    ^ 0 "never reached, since redefined in UndefinedObject and SmallInteger"

    "Created: / 31-05-2007 / 23:18:40 / cg"
! !

!ProtoObject methodsFor:'testing'!

ifNil:aBlock
    ^ self
!

ifNotNil:aBlockOrValue
    ^ aBlockOrValue value
!

isBehavior
    "return true, if the receiver is describing another objects behavior.
     False is returned here - the method is only redefined in Behavior."

    ^ false
!

isBlock
    ^ false
!

isException
    ^ false
!

isExceptionHandler
    ^ false
!

isJavaObject
    ^ false
!

isLazyValue
    ^ false

    "Created: / 03-06-2007 / 14:02:12 / cg"
!

isLiteral
    ^ false

    "Created: / 04-06-2007 / 17:19:10 / cg"
! !

!ProtoObject class methodsFor:'documentation'!

version
    ^ '$Id: ProtoObject.st 10482 2009-12-04 20:30:11Z vranyj1 $'
!

version_CVS
    ^ '§Header: /cvs/stx/stx/libbasic/ProtoObject.st,v 1.13 2009/12/01 19:59:38 cg Exp §'
! !