Re: Call by name in Algol-60

RogerHA <>
18 Mar 1998 22:48:21 -0500

          From comp.compilers

Related articles
Call by name in Algol-60 (RogerHA) (1998-03-07)
Re: Call by name in Algol-60 (1998-03-15)
Re: Call by name in Algol-60 (RogerHA) (1998-03-18)
Re: Call by name in Algol-60 (John Lindsay) (1998-03-18)
Re: Call by name in Algol-60 (1998-03-20)
Re: Call by name in Algol-60 (John Lindsay) (1998-03-24)
| List of all articles for this month |

From: RogerHA <>
Newsgroups: comp.compilers
Date: 18 Mar 1998 22:48:21 -0500
Organization: Compilers Central
References: 98-03-074 98-03-124
Keywords: algol60

<< Well, I still don't understand why such a very complex solution (with
two separate thunks for each actual parameter) is necessary. Why much
simpler one, where a thunk always returns an address (of a temporary
location in memory in the case of expression) will not work properly ?
If we go for your solution, then I wonder how it should be

1. A compiler scans each actual parameter two times and generates the same
      code twice, the only difference being at the end of the code (fetching or

2. The part of the code identical for both thunks is simply copied from the
      first thunk to form the second one (except the difference mentioned in
      the p. 1).

If, in the case of an actual parameter being an expression, the second
thunk is there only to cause a run-time exception, wouldn't it be
better to check this already in the compiling time ?

Colud you please explain me all this ?

[I believe it's not possible to verify statically whether or not a
call-by-name routine assigns to a variable. Imagine a situation where
it depends on the input, and you know that for external reasons the input
will always make it do something valid. Also consider that useful algol60
systems needed to support separate compilation and libraries. -John]

I was trying to explain the basis of the solution, to show the
principles involved. Of course there are ways in which the details can
be changed.

I think what you are asking is two sepearate questions (a) why not
return an address and (b) why have two thunks when one will do, if all
you do is return an address.

You can do it by returning an address, but this is not enough by
itself, as the moderator said. It is not possible for the compiler to
know whether or not the address can be used meaningfully. You must
have some way of checking this at run time. I suggested separate
thunks, but other ways are possible. You could use the same thunk but
with a parameter, to indicate whether a fetch from or assignment to
the calculated address is about to be done. The address could be
marked or known from its value whether it is a temporary variable or
one declared by the programmer. If the response to my posting on
another thread is anything to go by, you will get some more
suggestions, there is nothing new in any of this.

Which way you choose will depend upon the machine you are compiling
for and how you have chosen to compile other statements. One obvious
way of implementing expressions is using a stack. The two thunks can
operate directly on the stack, one removes an item, the other adds
one. The address is implicit. I find this way aesthetically pleasing,
which I suppose is why I explained call by name in that way.

Hope this helps.

Roger Abbott
RHA (Minisystems) Ltd

Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.