Call by name in Algol-60

RogerHA <>
7 Mar 1998 22:42:50 -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)
Jensen's device (1998-03-22)
Re: Call by name in Algol-60 (John Lindsay) (1998-03-24)
[4 later articles]
| List of all articles for this month |

From: RogerHA <>
Newsgroups: comp.compilers
Date: 7 Mar 1998 22:42:50 -0500
Organization: Compilers Central
Keywords: algol60

Hello All,

Call by name is one of those things which is straightforward to
understand if you start off in the right direction, but rapidly leads
to confusion if you start with a wrong turn. Andrejs assumes that the
thunks are done in the called procedure code, but this is not right,
you have to do it at the place where the procedure is called. This is
the environment where everything is known about how to evaluate the
parameter and calculate its adderss (if allowed) to do an assignment.

I recently answered a similar query in alt.folklore.computers, below
is a section of it.


Actually, the compiler does not have to remember much, if
anything. What you do is compile the code to evaluate the parameter,
and separate code to assign to it, at the point of the procedure
call. This code is not executed at the call, you just jump over
it. What you pass to the called procedure is the addresses of the two
routines, and a pointer to the stack frame. So, when the parameter is
to be fetched or assigned to, all you have to do is temporarily re-set
the variable stack pointer (to somewhere lower down) and call a
subroutine. If the parameter is passed on as a parameter to yet
another procedure, or recursively, all you do is pass on the three
pointers. Type conversion may have to be taken care of, one way way of
doing this is to put the required/actual type on the stack as a
parameter of the evaluation/assignment subroutine. Jensen's device
invloved having two parameters by name. The actual parameters were an
array element whose index is the other parameter. e.g. the formal
parameters might have been REAL a; INTEGER i; and the actual
parameters A[B], B.
So, if the actual parameter is K+1, the routine to fetch the value
does it, and the routine to do an assignment causes a run-time
error. All this is possible in a one-pass compiler, even without
forward declarations. What you do is have code which sorts out the
parameters at the point where a procedure starts executing. At this
point the type of all the formal parameters is known. Any parameters
which are by value get de-referenced at that point, and then behave as
local variables. Within the body of the procedure, any reference to
one of the parameters by name causes the thunk whose address is on the
stack to be called.

You can download an Algol-60 compiler from my pages at It actually uses call by reference
instead of call by name. It was for a seriously tiny machine (8K words
of 12 bits, a PDP8 with paper tape I/O, but the download runs on
MSDOS) and call by reference is normally sufficient. But the principle
of implementation is the same. When a procedure is called, it puts
onto the stack the address if that is possible, otherwise the value,
and then a tag saying whats there, including the type. At the head of
the called procedure any parameter which is by value but for which an
address has been supplied is de-referenced on the spot. Any parameter
called by name for which a value (not an address) has been supplied
causes a run-time error. Type conversions are done here too.

This download includes the compiler, written in Algol-60 (a subset). I
last did anything to it in 1986, and although I have recovered all the
compiler sources and some example programs, the machine readable
documentation is lost. I have written a short help file which I hope
is enough for people to do something with it. I have all the documents
in printed form. If sufficient interest is shown, or someone is kind
enough to scan the documents so I can edit them, I will get that on to
the web site too.

Best wishes and happy Algolling!

Roger Abbott
RHA (Minisystems) Ltd,

Post a followup to this message

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