Squeak Class Documentation category index | class index  
 
ContextPart
  category: Kernel-Methods
  superclass: InstructionStream
  subclasses: BlockContext MethodContext

To the instruction parsing ability of InstructionStream I add the actual semantics for execution. The execution state is stored in the indexable fields of my subclasses. This includes temporary variables and a stack of values used in evaluating expressions. The actual semantics of execution can be found in my category "system simulation" and "instruction decode". These methods exactly parallel the operation of the Smalltalk machine itself.

The simulator is a group of my methods that do what the Smalltalk interpreter does: execute Smalltalk bytecodes. By adding code to the simulator, you may take statistics on the running of Smalltalk methods. For example,
Transcript show: (ContextPart runSimulated: [3 factorial]) printString.

instance methods
  accessing
  client
home
method
receiver
tempAt:
tempAt:put:

  controlling
  activateMethod:withArgs:receiver:class:
blockCopy:
hasSender:
pop
push:
quickSend:to:with:super:
return:to:
send:to:with:super:
terminate
terminateTo:
top

  debugger access
  depthBelow:
errorReportOn:
longStack
mclass
pc
release
releaseTo:
selector
sender
shortStack
singleRelease
sourceCode
stack
stackOfSize:
swapSender:
tempNames
tempsAndValues
tempsAndValuesLimitedTo:indent:

  instruction decoding
  doDup
doPop
jump:
jump:if:
methodReturnConstant:
methodReturnReceiver
methodReturnTop
popIntoLiteralVariable:
popIntoReceiverVariable:
popIntoTemporaryVariable:
pushActiveContext
pushConstant:
pushLiteralVariable:
pushReceiver
pushReceiverVariable:
pushTemporaryVariable:
send:super:numArgs:
storeIntoLiteralVariable:
storeIntoReceiverVariable:
storeIntoTemporaryVariable:

  objects from disk
  storeDataOn:

  printing
  printDetails:
printOn:

  private
  doPrimitive:method:receiver:args:
push:fromIndexable:
stackPtr
stackp:
tryNamedPrimitiveIn:for:withArgs:
tryPrimitiveFor:receiver:args:

  private-debugger
  cachesStack

  private-exceptions
  findNextHandlerContextStarting
findNextUnwindContextUpTo:
isHandlerContext
isUnwindContext
unwindTo:

  system simulation
  completeCallee:
quickStep
runSimulated:contextAtEachStep:
step
stepToSendOrReturn

class methods
  examples
  tallyInstructions:
tallyMethods:
trace:
trace:on:
trace:onFileNamed:

  instance creation
  basicNew:
initializedInstance
new
new:
newForMethod:

  private
  carefullyPrint:on:

  simulation
  initialize
primitiveFailToken
runSimulated:

instance methods
  accessing top  
 

client

Answer the client, that is, the object that sent the message that created this context.


 

home

Answer the context in which the receiver was defined.


 

method

Answer the method of this context.


 

receiver

Answer the receiver of the message that created this context.


 

tempAt:

Answer the value of the temporary variable whose index is the
argument, index.


 

tempAt:put:

Store the argument, value, as the temporary variable whose index is the
argument, index.


  controlling top  
 

activateMethod:withArgs:receiver:class:

Answer a ContextPart initialized with the arguments.


 

blockCopy:

Primitive. Distinguish a block of code from its enclosing method by
creating a new BlockContext for that block. The compiler inserts into all
methods that contain blocks the bytecodes to send the message
blockCopy:. Do not use blockCopy: in code that you write! Only the
compiler can decide to send the message blockCopy:. Fail if numArgs is
not a SmallInteger. Optional. No Lookup. See Object documentation
whatIsAPrimitive.


 

hasSender:

Answer whether the receiver is strictly above context on the stack.


 

pop

Answer the top of the receiver's stack and remove the top of the stack.


 

push:

Push val on the receiver's stack.


 

quickSend:to:with:super:

Send the given selector with arguments in an environment which closely resembles the non-simulating environment, with an interjected unwind-protected block to catch nonlocal returns.
Attention: don't get lost!


 

return:to:

Simulate the return of value to sendr.


 

send:to:with:super:

Simulate the action of sending a message with selector, selector, and
arguments, args, to receiver. The argument, superFlag, tells whether the
receiver of the message was specified with 'super' in the source method.


 

terminate

Make myself unresumable.


 

terminateTo:

Terminate all the Contexts between me and previousContext, if previousContext is on my Context stack. Make previousContext my sender.


 

top

Answer the top of the receiver's stack.


  debugger access top  
 

depthBelow:

Answer how many calls there are between this and aContext.


 

errorReportOn:

Write a detailed error report on the stack (above me) on a stream. For both the error file, and emailing a bug report. Suppress any errors while getting printStrings. Limit the length.


 

longStack

Answer a String showing the top 100 contexts on my sender chain.


 

mclass

Answer the class in which the receiver's method was found.


 

pc

Answer the index of the next bytecode to be executed.


 

release

Remove information from the receiver and all of the contexts on its
sender chain in order to break circularities.


 

releaseTo:

Remove information from the receiver and the contexts on its sender
chain up to caller in order to break circularities.


 

selector

Answer the selector of the method that created the receiver.


 

sender

Answer the context that sent the message that created the receiver.


 

shortStack

Answer a String showing the top ten contexts on my sender chain.


 

singleRelease

Remove information from the receiver in order to break circularities.


 

sourceCode


 

stack

Answer an Array of the contexts on the receiver's sender chain.


 

stackOfSize:

Answer an OrderedCollection of the top 'limit' contexts
on the receiver's sender chain.


 

swapSender:

Replace the receiver's sender with coroutine and answer the receiver's
previous sender. For use in coroutining.


 

tempNames

Answer an OrderedCollection of the names of the receiver's temporary
variables, which are strings.


 

tempsAndValues

Return a string of the temporary variabls and their current values


 

tempsAndValuesLimitedTo:indent:

Return a string of the temporary variabls and their current values


  instruction decoding top  
 

doDup

Simulate the action of a 'duplicate top of stack' bytecode.


 

doPop

Simulate the action of a 'remove top of stack' bytecode.


 

jump:

Simulate the action of a 'unconditional jump' bytecode whose offset is
the argument, distance.


 

jump:if:

Simulate the action of a 'conditional jump' bytecode whose offset is the
argument, distance, and whose condition is the argument, condition.


 

methodReturnConstant:

Simulate the action of a 'return constant' bytecode whose value is the
argument, value. This corresponds to a source expression like '^0'.


 

methodReturnReceiver

Simulate the action of a 'return receiver' bytecode. This corresponds to
the source expression '^self'.


 

methodReturnTop

Simulate the action of a 'return top of stack' bytecode. This corresponds
to source expressions like '^something'.


 

popIntoLiteralVariable:

Simulate the action of bytecode that removes the top of the stack and
stores it into a literal variable of my method.


 

popIntoReceiverVariable:

Simulate the action of bytecode that removes the top of the stack and
stores it into an instance variable of my receiver.


 

popIntoTemporaryVariable:

Simulate the action of bytecode that removes the top of the stack and
stores it into one of my temporary variables.


 

pushActiveContext

Simulate the action of bytecode that pushes the the active context on the
top of its own stack.


 

pushConstant:

Simulate the action of bytecode that pushes the constant, value, on the
top of the stack.


 

pushLiteralVariable:

Simulate the action of bytecode that pushes the contents of the literal
variable whose index is the argument, index, on the top of the stack.


 

pushReceiver

Simulate the action of bytecode that pushes the active context's receiver
on the top of the stack.


 

pushReceiverVariable:

Simulate the action of bytecode that pushes the contents of the receiver's
instance variable whose index is the argument, index, on the top of the
stack.


 

pushTemporaryVariable:

Simulate the action of bytecode that pushes the contents of the
temporary variable whose index is the argument, index, on the top of
the stack.


 

send:super:numArgs:

Simulate the action of bytecodes that send a message with selector,
selector. The argument, superFlag, tells whether the receiver of the
message was specified with 'super' in the source method. The arguments
of the message are found in the top numArgs locations on the stack and
the receiver just below them.


 

storeIntoLiteralVariable:

Simulate the action of bytecode that stores the top of the stack into a
literal variable of my method.


 

storeIntoReceiverVariable:

Simulate the action of bytecode that stores the top of the stack into an
instance variable of my receiver.


 

storeIntoTemporaryVariable:

Simulate the action of bytecode that stores the top of the stack into one
of my temporary variables.


  objects from disk top  
 

storeDataOn:

Contexts are not allowed go to out in DataStreams. They must be included inside an ImageSegment.


  printing top  
 

printDetails:

Put my class>>selector and arguments and temporaries on the stream. Protect against errors during printing.


 

printOn:

Append to the argument, aStream, a sequence of characters that
identifies the receiver.


  private top  
 

doPrimitive:method:receiver:args:

Simulate a primitive method whose index is primitiveIndex. The
simulated receiver and arguments are given as arguments to this message.


 

push:fromIndexable:

Push the elements of anIndexableCollection onto the receiver's stack.
Do not call directly. Called indirectly by {1. 2. 3} constructs.


 

stackPtr

For use only by the SystemTracer


 

stackp:

Storing into the stack pointer is a potentially dangerous thing.
This primitive stores nil into any cells that become accessible as a result,
and it performs the entire operation atomically.


 

tryNamedPrimitiveIn:for:withArgs:

Hack. Attempt to execute the named primitive from the given compiled method


 

tryPrimitiveFor:receiver:args:

If this method has a primitive index, then run the primitive and return its result.
Otherwise (and also if the primitive fails) return PrimitiveFailToken,
as an indication that the method should be activated and run as bytecodes.


  private-debugger top  
 

cachesStack


  private-exceptions top  
 

findNextHandlerContextStarting

Return the next handler marked context, returning nil if there is none. Search starts with self and proceeds up to nil.


 

findNextUnwindContextUpTo:

Return the next unwind marked above the receiver, returning nil if there is none. Search proceeds up to but not including aContext.


 

isHandlerContext


 

isUnwindContext


 

unwindTo:


  system simulation top  
 

completeCallee:

Simulate the execution of bytecodes until a return to the receiver.


 

quickStep

If the next instruction is a send, just perform it.
Otherwise, do a normal step.


 

runSimulated:contextAtEachStep:

Simulate the execution of the argument, aBlock, until it ends. aBlock
MUST NOT contain an '^'. Evaluate block2 with the current context
prior to each instruction executed. Answer the simulated value of aBlock.


 

step

Simulate the execution of the receiver's next bytecode. Answer the
context that would be the active context after this bytecode.


 

stepToSendOrReturn

Simulate the execution of bytecodes until either sending a message or
returning a value to the receiver (that is, until switching contexts).


class methods
  examples top  
 

tallyInstructions:

This method uses the simulator to count the number of occurrences of
each of the Smalltalk instructions executed during evaluation of aBlock.
Results appear in order of the byteCode set.


 

tallyMethods:

This method uses the simulator to count the number of calls on each method
invoked in evaluating aBlock. Results are given in order of decreasing counts.


 

trace:

ContextPart trace: [3 factorial]


 

trace:on:

ContextPart trace: [3 factorial]


 

trace:onFileNamed:

ContextPart trace: [3 factorial] onFileNamed: 'trace'


  instance creation top  
 

basicNew:

Primitive. Answer an instance of this class with the number
of indexable variables specified by the argument, sizeRequested.
Fail if this class is not indexable or if the argument is not a
positive Integer, or if there is not enough memory available.
Essential. See Object documentation whatIsAPrimitive.


 

initializedInstance

Answer an instance of the receiver which in some sense is initialized. In the case of Morphs, this will yield an instance that can be attached to the Hand after having received the same kind of basic initialization that would be obtained from an instance chosen from the 'new morph' menu. Return nil if the receiver is reluctant for some reason to return such a thing


 

new

Answer a new instance of the receiver (which is a class) with no indexable variables. Fail if the class is indexable.


 

new:

Answer an instance of this class with the number of indexable
variables specified by the argument, sizeRequested.


 

newForMethod:

This is the only method for creating new contexts, other than primitive cloning.
Any other attempts, such as inherited methods like shallowCopy, should be
avoided or must at least be rewritten to determine the proper size from the
method being activated. This is because asking a context its size (even basicSize!)
will not return the real object size but only the number of fields currently
accessible, as determined by stackp.


  private top  
 

carefullyPrint:on:


  simulation top  
 

initialize

A unique object to be returned when a primitive fails during simulation


 

primitiveFailToken


 

runSimulated:

Simulate the execution of the argument, current. Answer the result it
returns.