modification of ContextPart?

Andreas Raab andreas.raab at gmx.de
Sat Nov 12 21:00:47 UTC 2005


Klaus D. Witzel wrote:
> after increasing nTemps of a CompiledMethod by 1, you wouldn't be able 
> to  see that you have already done so (in case you 
> change+run+change+run  incrementally, I mean) and soon run out of temp 
> space :(

Oh, yes, you absolutely can, because you'd always use "number of temps 
described by source code + 1" instead of "number of temps in existing 
method + 1" (where the former is constant).

However, there is an even simpler solution which is why not just 
allocate an extra temp that is never used? E.g., in 
Parser>>method:context:encoder: all it takes is to do something like:

   "Parse method header"
   sap := self pattern: doit inContext: ctxt.
   "sap={selector, arguments, precedence}"
   (sap at: 2) do: [:argNode | argNode isArg: true].
   "Parse temps"
   temps := self temporariesIn: (sap at: 1).

and change this to

   "Parse method header"
   sap := self pattern: doit inContext: ctxt.
   "sap={selector, arguments, precedence}"
   (sap at: 2) do: [:argNode | argNode isArg: true].
   "--> Add invisible temp <--"
   (encoder bindTemp: 'invisiTemp') nowHasDef nowHasRef.
   "Parse temps"
   temps := self temporariesIn: (sap at: 1).


(the call to nowHasDef nowHasRef is just to shut up the parser). Once 
you've recompiled the entire system (Smalltalk allClassesDo:[:cls| cls 
compileAll]) you can access this variable as:

MethodContext>>invisiTemp
   "Answer the receiver's invisiTemp"
   ^self tempAt: self method numArgs+1

MethodContext>>invisiTemp: anObject
   "Set the receiver's invisiTemp"
   ^self tempAt: self method numArgs+1 put: anObject

Cheers,
   - Andreas



More information about the Squeak-dev mailing list