Block temps was: Porting from other dialects

Mike Klein mike at twinsun.com
Tue Aug 18 22:05:39 UTC 1998


The issue is not nilling out the block temporary.
The issue is having one slot per block-activation so
that blocks may be value'd re-entrantly.  Otherwise the following wont
work right:

	| output supposedlyReentrantBlock guard |
	output := WriteStream on: String new. "I'm used to String new
writeStream..."
	guard := SharedQueue new.   "Used for process synchronization"
	supposedlyReentrantBlock := [ :array  |  
		1 to: array size do: [:index | output print: (array at:
index); space. Processor yield. ].
		guard nextPut: nil.   "  signal the guard  "
	].
	[supposedlyReentrantBlock value: #(1 2 3) ] fork.
	[supposedlyReentrantBlock value: #(-1 -2 -3) ] fork.
	guard next; next.  "  wait for two guard signalings  "
	^output contents 

In VisualWorks it evaluates to:  '1 -1 2 -2 3 -3 '
In Squeak it evaluates to:  '1 -1 -2 -3 '

This show that even block parameters have the problem.
As Glenn pointed out earlier, parameters are conceptually the same
as temporaries.  AFAIK the only real difference is that the compiler
enforces that parameters cannot be assigned (except by sending a message).
I.E. parameters are 'read only'

The problem is that both processes are using a shared activation record.
Closures would be nice.


On Tue, 18 Aug 1998, Andreas Raab wrote:

> Folks,
> 
> Even though I may spoil a students exercise let me give a comment on the
> following:
> 
> > Although fudging the compiler to accept block temps and fake them into method
> > temps is not too complicated, the problem I never really worked through was
> > handling them in the DEcompiler.
> 
> It's actually trivial to add block temps to Squeak by patching Parser
> statements:innerBlock: with the following (first and last lines show the
> context where to apply the patch).
> 
>   currentComment _ nil. 
>   returns _ false.
> 
>   "<---- begin block temps patch ---->"
>   hereType == #verticalBar ifTrue:[
>       self temporaries do:[:temp|
>         stmts addLast: (AssignmentNode new
>           variable: temp
>           value: (encoder encodeVariable: 'nil')
>           from: encoder)]]. 
>   "<---- end block temps patch ---->"
> 
>   more _ hereType ~~ #rightBracket.
>   [more] whileTrue: 
> 
> 
> The hidden assignment garantuees that the temp is reset on each activation
> of the block. The only problem is that you cannot have the same temp name
> in multiple blocks as in:
> 
>   [true] whileTrue:[ |tmp| ].
>   [true] whileTrue:[ |tmp| ].
> 
> But for porting issues that's not really a problem.
> 
>   Andreas
> --
> Linear algebra is your friend - Trigonometry is your enemy.
> +===== Andreas Raab ============= (raab at isg.cs.uni-magdeburg.de) =====+
> I Department of Simulation and Graphics      Phone: +49 391 671 8065  I
> I University of Magdeburg, Germany           Fax:   +49 391 671 1164  I
> +=============< http://isgwww.cs.uni-magdeburg.de/~raab >=============+
> 
> 





More information about the Squeak-dev mailing list