Back: Bag-testing collections Up: Base classes Forward: Behavior-accessing class hierarchy   Top: GNU Smalltalk Library Reference Contents: Table of Contents Index: Class index About: About this document

1.9 Behavior

Defined in namespace Smalltalk
Superclass: Object
Category: Language-Implementation
I am the parent class of all "class" type methods. My instances know about the subclass/superclass relationships between classes, contain the description that instances are created from, and hold the method dictionary that's associated with each class. I provide methods for compiling methods, modifying the class inheritance hierarchy, examining the method dictionary, and iterating over the class hierarchy.

1.9.1 Behavior: accessing class hierarchy  (instance)
1.9.2 Behavior: accessing instances and variables  (instance)
1.9.3 Behavior: accessing the methodDictionary  (instance)
1.9.4 Behavior: built ins  (instance)
1.9.5 Behavior: builtin  (instance)
1.9.6 Behavior: compilation (alternative)  (instance)
1.9.7 Behavior: compiling methods  (instance)
1.9.8 Behavior: creating a class hierarchy  (instance)
1.9.9 Behavior: enumerating  (instance)
1.9.10 Behavior: evaluating  (instance)
1.9.11 Behavior: instance creation  (instance)
1.9.12 Behavior: instance variables  (instance)
1.9.13 Behavior: method dictionary  (instance)
1.9.14 Behavior: parsing class declarations  (instance)
1.9.15 Behavior: pluggable behavior (not yet implemented)  (instance)
1.9.16 Behavior: printing hierarchy  (instance)
1.9.17 Behavior: still unclassified  (instance)
1.9.18 Behavior: support for lightweight classes  (instance)
1.9.19 Behavior: testing functionality  (instance)
1.9.20 Behavior: testing the class hierarchy  (instance)
1.9.21 Behavior: testing the form of the instances  (instance)
1.9.22 Behavior: testing the method dictionary  (instance)


1.9.1 Behavior: accessing class hierarchy

allSubclasses
Answer the direct and indirect subclasses of the receiver in a Set

allSuperclasses
Answer all the receiver's superclasses in a collection

subclasses
Answer the direct subclasses of the receiver in a Set

superclass
Answer the receiver's superclass (if any, otherwise answer nil)

withAllSubclasses
Answer a Set containing the receiver together with its direct and indirect subclasses

withAllSuperclasses
Answer the receiver and all of its superclasses in a collection


1.9.2 Behavior: accessing instances and variables

allClassVarNames
Return all the class variables understood by the receiver

allInstVarNames
Answer the names of every instance variables the receiver contained in the receiver's instances

allInstances
Returns a set of all instances of the receiver

allSharedPools
Return the names of the shared pools defined by the class and any of its superclasses

classPool
Answer the class pool dictionary. Since Behavior does not support classes with class variables, we answer an empty one; adding variables to it results in an error.

classVarNames
Answer all the class variables for instances of the receiver

instVarNames
Answer an Array containing the instance variables defined by the receiver

instanceCount
Return a count of all the instances of the receiver

sharedPools
Return the names of the shared pools defined by the class

subclassInstVarNames
Answer the names of the instance variables the receiver inherited from its superclass


1.9.3 Behavior: accessing the methodDictionary

>> selector
Return the compiled method associated with selector, from the local method dictionary. Error if not found.

allSelectors
Answer a Set of all the selectors understood by the receiver

compiledMethodAt: selector
Return the compiled method associated with selector, from the local method dictionary. Error if not found.

compiledMethodAt: selector ifAbsent: aBlock
Return the compiled method associated with selector, from the local method dictionary. Evaluate aBlock if not found.

lookupSelector: aSelector
Return the compiled method associated with selector, from the local method dictionary or one of a superclass; return nil if not found.

parseTreeFor: selector
Answer the parse tree for the given selector, or nil if there was an error. Requires the Parser package to be loaded.

selectorAt: method
Return selector for the given CompiledMethod

selectors
Answer a Set of the receiver's selectors

sourceCodeAt: selector
Answer source code (if available) for the given selector.

sourceMethodAt: selector
This is too dependent on the original implementation


1.9.4 Behavior: built ins

basicNewInFixedSpace
Create a new instance of a class with no indexed instance variables. The instance is guaranteed not to move across garbage collections. Like #basicNew, this method should not be overridden.

basicNewInFixedSpace: numInstanceVariables
Create a new instance of a class with indexed instance variables. The instance has numInstanceVariables indexed instance variables. The instance is guaranteed not to move across garbage collections. Like #basicNew:, this method should not be overridden.

flushCache
Invalidate the method cache kept by the virtual machine. This message should not need to be called by user programs.

methodsFor: category ifTrue: condition
Compile the following code inside the receiver, with the given category, if condition is true; else ignore it

primCompile: code
Compile the code, a string or readable stream, with no category. Fail if the code does not obey Smalltalk syntax. Answer the generated CompiledMethod if it does.

Do not send this in user code; use #compile: or related methods instead.

primCompile: code ifError: aBlock
As with #primCompile:, but evaluate aBlock (passing the file name, line number and description of the error) if the code does not obey Smalltalk syntax.

Do not send this in user code; use #compile:ifError: or related methods instead.

someInstance
Private - Answer the first instance of the receiver in the object table


1.9.5 Behavior: builtin

basicNew
Create a new instance of a class with no indexed instance variables; this method must not be overridden.

basicNew: numInstanceVariables
Create a new instance of a class with indexed instance variables. The instance has numInstanceVariables indexed instance variables; this method must not be overridden.

new
Create a new instance of a class with no indexed instance variables

new: numInstanceVariables
Create a new instance of a class with indexed instance variables. The instance has numInstanceVariables indexed instance variables.


1.9.6 Behavior: compilation (alternative)

methods
Don't use this, it's only present to file in from Smalltalk/V

methodsFor
Don't use this, it's only present to file in from Dolphin Smalltalk

methodsFor: category ifFeatures: features
Start compiling methods in the receiver if this implementation of Smalltalk has the given features, else skip the section

methodsFor: category stamp: notUsed
Don't use this, it's only present to file in from Squeak

privateMethods
Don't use this, it's only present to file in from IBM Smalltalk

publicMethods
Don't use this, it's only present to file in from IBM Smalltalk


1.9.7 Behavior: compiling methods

methodsFor: aCategoryString
Calling this method prepares the parser to receive methods to be compiled and installed in the receiver's method dictionary. The methods are put in the category identified by the parameter.


1.9.8 Behavior: creating a class hierarchy

addSubclass: aClass
Add aClass asone of the receiver's subclasses.

removeSubclass: aClass
Remove aClass from the list of the receiver's subclasses

superclass: aClass
Set the receiver's superclass.


1.9.9 Behavior: enumerating

allInstancesDo: aBlock
Invokes aBlock for all instances of the receiver

allSubclassesDo: aBlock
Invokes aBlock for all subclasses, both direct and indirect.

allSubinstancesDo: aBlock
Invokes aBlock for all instances of each of the receiver's subclasses.

allSuperclassesDo: aBlock
Invokes aBlock for all superclasses, both direct and indirect.

selectSubclasses: aBlock
Return a Set of subclasses of the receiver satisfying aBlock.

selectSuperclasses: aBlock
Return a Set of superclasses of the receiver satisfying aBlock.

subclassesDo: aBlock
Invokes aBlock for all direct subclasses.

withAllSubclassesDo: aBlock
Invokes aBlock for the receiver and all subclasses, both direct and indirect.

withAllSuperclassesDo: aBlock
Invokes aBlock for the receiver and all superclasses, both direct and indirect.


1.9.10 Behavior: evaluating

evalString: aString to: anObject
Answer the stack top at the end of the evaluation of the code in aString. The code is executed as part of anObject

evalString: aString to: anObject ifError: aBlock
Answer the stack top at the end of the evaluation of the code in aString. If aString cannot be parsed, evaluate aBlock (see compile:ifError:). The code is executed as part of anObject

evaluate: code
Evaluate Smalltalk expression in 'code' and return result.

evaluate: code ifError: block
Evaluate 'code'. If a parsing error is detected, invoke 'block'

evaluate: code notifying: requestor
Evaluate Smalltalk expression in 'code'. If a parsing error is encountered, send #error: to requestor

evaluate: code to: anObject
Evaluate Smalltalk expression as part of anObject's method definition

evaluate: code to: anObject ifError: block
Evaluate Smalltalk expression as part of anObject's method definition. This method is used to support Inspector expression evaluation. If a parsing error is encountered, invoke error block, 'block'


1.9.11 Behavior: instance creation

newInFixedSpace
Create a new instance of a class without indexed instance variables. The instance is guaranteed not to move across garbage collections. If a subclass overrides #new, the changes will apply to this method too.

newInFixedSpace: numInstanceVariables
Create a new instance of a class with indexed instance variables. The instance has numInstanceVariables indexed instance variables. The instance is guaranteed not to move across garbage collections. If a subclass overrides #new:, the changes will apply to this method too.


1.9.12 Behavior: instance variables

addInstVarName: aString
Add the given instance variable to instance of the receiver

instanceVariableNames: instVarNames
Set the instance variables for the receiver to be those in instVarNames

removeInstVarName: aString
Remove the given instance variable from the receiver and recompile all of the receiver's subclasses


1.9.13 Behavior: method dictionary

addSelector: selector withMethod: compiledMethod
Add the given compiledMethod to the method dictionary, giving it the passed selector. Answer compiledMethod

compile: code
Compile method source. If there are parsing errors, answer nil. Else, return a CompiledMethod result of compilation

compile: code ifError: block
Compile method source. If there are parsing errors, invoke exception block, 'block' passing file name, line number and error. Return a CompiledMethod result of compilation

to

compile: code notifying: requestor
Compile method source. If there are parsing errors, send #error: to the requestor object, else return a CompiledMethod result of compilation

compileAll
Recompile all selectors in the receiver. Ignore errors.

compileAll: aNotifier
Recompile all selectors in the receiver. Notify aNotifier by sen- ding #error: messages if something goes wrong.

compileAllSubclasses
Recompile all selector of all subclasses. Notify aNotifier by sen- ding #error: messages if something goes wrong.

compileAllSubclasses: aNotifier
Recompile all selector of all subclasses. Notify aNotifier by sen- ding #error: messages if something goes wrong.

createGetMethod: what
Create a method accessing the variable `what'.

createGetMethod: what default: value
Create a method accessing the variable `what', with a default value of `value', using lazy initialization

createSetMethod: what
Create a method which sets the variable `what'.

decompile: selector
Decompile the bytecodes for the given selector.

defineAsyncCFunc: cFuncNameString withSelectorArgs: selectorAndArgs args: argsArray
Please lookup the part on the C interface in the manual. This method is deprecated, you should use the asyncCCall:args: attribute.

defineCFunc: cFuncNameString withSelectorArgs: selectorAndArgs returning: returnTypeSymbol args: argsArray
Please lookup the part on the C interface in the manual. This method is deprecated, you should use the cCall:returning:args: attribute.

edit: selector
Open Emacs to edit the method with the passed selector, then compile it

methodDictionary
Answer the receiver's method dictionary. Don't modify the method dictionary unless you exactly know what you're doing

methodDictionary: aDictionary
Set the receiver's method dictionary to aDictionary

recompile: selector
Recompile the given selector, answer nil if something goes wrong or the new CompiledMethod if everything's ok.

to

recompile: selector notifying: aNotifier
Recompile the given selector. If there are parsing errors, send #error: to the aNotifier object, else return a CompiledMethod result of compilation

removeSelector: selector
Remove the given selector from the method dictionary, answer the CompiledMethod attached to that selector

removeSelector: selector ifAbsent: aBlock
Remove the given selector from the method dictionary, answer the CompiledMethod attached to that selector. If the selector cannot be found, answer the result of evaluating aBlock.

selectorsAndMethodsDo: aBlock
Evaluate aBlock, passing for each evaluation a selector that's defined in the receiver and the corresponding method.


1.9.14 Behavior: parsing class declarations

parseInstanceVariableString: variableString
As with #parseVariableString:, but answer symbols that name the variables instead of strings.

parseVariableString: aString
Answer an array of instance variable names. aString should specify these in traditional file-in `instanceVariableNames' format. Signal an error if aString contains something other than valid Smalltalk variables.


1.9.15 Behavior: pluggable behavior (not yet implemented)

compilerClass
Answer the class that can be used to compile parse trees, or nil if there is none (as is the case now). Not used for methods if parserClass answers nil, and for doits if evaluatorClass answers nil.

debuggerClass
Answer which class is to be used to debug a chain of contexts which includes the receiver. nil means 'do not debug'; other classes are sent #debuggingPriority and the one with the highest priority is picked.

decompilerClass
Answer the class that can be used to decompile methods, or nil if there is none (as is the case now).

evaluatorClass
Answer the class that can be used to evaluate doits, or nil if there is none (as is the case now).

parserClass
Answer the class that can be used to parse methods, or nil if there is none (as is the case now).


1.9.16 Behavior: printing hierarchy

hierarchyIndent
Answer the indent to be used by #printHierarchy - 4 by default

printHierarchy
Print my entire subclass hierarchy on the terminal.

printSubclasses: level using: aBlock
I print my name, and then all my subclasses, each indented according to its position in the hierarchy. I pass aBlock a class name and a level


1.9.17 Behavior: still unclassified

parseNodeAt: selector
Available only when the Parser package is loaded--Answer an RBMethodNode that compiles to my method named by selector.

updateInstanceVars: variableArray shape: shape
Update instance variables and instance spec of the class and all its subclasses. variableArray lists the new variables, including inherited ones.


1.9.18 Behavior: support for lightweight classes

article
Answer an article (`a' or `an') which is ok for the receiver's name

asClass
Answer the first superclass that is a full-fledged Class object

environment
Answer the namespace that this class belongs to - the same as the superclass, since Behavior does not support namespaces yet.

name
Answer the class name; this prints to the name of the superclass enclosed in braces. This class name is used, for example, to print the receiver.

nameIn: aNamespace
Answer the class name when the class is referenced from aNamespace - a dummy one, since Behavior does not support names.

printOn: aStream in: aNamespace
Answer the class name when the class is referenced from aNamespace - a dummy one, since Behavior does not support names.

securityPolicy
Not commented.

securityPolicy: aSecurityPolicy
This method should not be called for instances of this class.


1.9.19 Behavior: testing functionality

isBehavior
Answer `true'.


1.9.20 Behavior: testing the class hierarchy

includesBehavior: aClass
Returns true if aClass is the receiver or a superclass of the receiver.

inheritsFrom: aClass
Returns true if aClass is a superclass of the receiver

kindOfSubclass
Return a string indicating the type of class the receiver is

shape
Answer the symbolic shape of my instances.

#ushort

shape: shape
Give the provided shape to the receiver's instances. The shape can be nil, or one of #byte #int8 #character #short #word #ushort #int #uint #int64 #uint64 #utf32 #float #double or #pointer. In addition, the special value #inherit means to use the shape of the superclass; note however that this is a static setting, and subclasses that used #inherit are not mutated when the superclass adopts a different shape.


1.9.21 Behavior: testing the form of the instances

instSize
Answer how many fixed instance variables are reserved to each of the receiver's instances

isBits
Answer whether my instances' variables are immediate, non-OOP values.

isFixed
Answer whether the receiver's instances have no indexed instance variables

isIdentity
Answer whether x = y implies x == y for instances of the receiver

isImmediate
Answer whether, if x is an instance of the receiver, x copy == x

isPointers
Answer whether the instance variables of the receiver's instances are objects

isVariable
Answer whether the receiver's instances have indexed instance variables


1.9.22 Behavior: testing the method dictionary

canUnderstand: selector
Returns true if the instances of the receiver understand the given selector

hasMethods
Return whether the receiver has any methods defined

includesSelector: selector
Returns true if the local method dictionary contains the given selector

scopeHas: name ifTrue: aBlock
If methods understood by the receiver's instances have access to a symbol named 'name', evaluate aBlock

whichClassIncludesSelector: selector
Answer which class in the receiver's hierarchy contains the implementation of selector used by instances of the class (nil if none does)

whichSelectorsAccess: instVarName
Answer a Set of selectors which access the given instance variable

whichSelectorsAssign: instVarName
Answer a Set of selectors which read the given instance variable

whichSelectorsRead: instVarName
Answer a Set of selectors which read the given instance variable

whichSelectorsReferTo: anObject
Returns a Set of selectors that refer to anObject

whichSelectorsReferToByteCode: aByteCode
Return the collection of selectors in the class which reference the byte code, aByteCode



Back: Behavior-testing the form of the instances Up: Behavior Forward: BindingDictionary   Top: GNU Smalltalk Library Reference Contents: Table of Contents Index: Class index About: About this document


This document was generated on May, 22 2008 using texi2html