"
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' }"
"{ NameSpace: Smalltalk }"
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 class methodsFor:'helpers'!
shallowCopyOf:anObject
"return a copy of anObject with shared subobjects (a shallow copy)
i.e. the copy shares referenced instvars with its original."
%{ /* NOCONTEXT */
int ninsts, spc, sz;
OBJ theCopy;
OBJ cls = __qClass(anObject);
int flags = __intVal(__ClassInstPtr(cls)->c_flags);
/*
* bail out for special objects ..
*/
if (((flags & ~ARRAYMASK) == 0)
&& ((flags & ARRAYMASK) != WKPOINTERARRAY)) {
sz = __qSize(anObject);
__PROTECT__(anObject);
__qNew(theCopy, sz); /* OBJECT ALLOCATION */
__UNPROTECT__(anObject);
if (theCopy) {
cls = __qClass(anObject);
spc = __qSpace(theCopy);
theCopy->o_class = cls; __STORE_SPC(theCopy, cls, spc);
sz = sz - OHDR_SIZE;
if (sz) {
char *src, *dst;
src = (char *)(__InstPtr(anObject)->i_instvars);
dst = (char *)(__InstPtr(theCopy)->i_instvars);
#ifdef bcopy4
{
/* care for odd-number of longs */
int nW = sz >> 2;
if (sz & 3) {
nW++;
}
bcopy4(src, dst, nW);
}
#else
bcopy(src, dst, sz);
#endif
flags &= ARRAYMASK;
if (flags == POINTERARRAY) {
ninsts = __BYTES2OBJS__(sz);
} else {
ninsts = __intVal(__ClassInstPtr(cls)->c_ninstvars);
}
if (ninsts) {
do {
OBJ el;
el = __InstPtr(theCopy)->i_instvars[ninsts-1];
__STORE_SPC(theCopy, el, spc);
} while (--ninsts);
}
}
RETURN (theCopy);
}
}
%}.
"/ fallBack for special objects & memoryAllocation failure case
^ self error:'ProtoObject>>#shallowCopyOf: failed'
! !
!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:'inspecting'!
inspect
"this method is required to allow inspection of the object"
^ (Object compiledMethodAt:#inspect)
valueWithReceiver:self
arguments:nil
selector:#inspect
!
instVarAt:index
"this method is required to allow inspection of the object"
^ (Object compiledMethodAt:#instVarAt:)
valueWithReceiver:self
arguments:{index}
selector:#instVarAt:
! !
!ProtoObject methodsFor:'queries'!
class
"return the receiver's 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.
"
"Modified (comment): / 30-04-2016 / 15:51:12 / cg"
!
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 isBlock and:[aBlockOrValue argumentCount == 1]) ifTrue:[
^ aBlockOrValue value:self.
].
^ aBlockOrValue value
!
isBehavior
"return true, if the receiver is describing another object's behavior.
False is returned here - the method is only redefined in Behavior."
^ false
!
isBlock
^ false
!
isBridgeProxy
^ 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"
!
isNil
^ false.
!
isProtoObject
^ true
! !
!ProtoObject class methodsFor:'documentation'!
version
^ '$Header$'
!
version_CVS
^ '$Header$'
! !