Assignment #1 and &

Posted to ccs.courses.com3355
1 April 1996
Those of you who are using C or C++ have an extra complication to deal
with in assignment #1.  The type checker inserts a & operator in front
of every mention of a variable.  In fib.q, for example,

    write_int (fib (read_int()))

becomes

    (&write_int) ((&fib_1) ((&read_int) ()));

in fib.qt.  Strictly speaking, the variables write_int, fib_1, and
read_int aren't in call position any more.  In your program for
assignment #1, you will need to treat them as though they were.
This is legitimate because the & is a no-op on values of any proc
type.

In fact, however, our code generators treat the & operator as a
no-op for values of all types, since the type checker inserts an
explicit @ operator wherever dereferencing is needed.  Thus a
simpler solution is to change one of the action procedures to
prevent the & operator from appearing in the abstract syntax tree
at all.

I think you can do this by making your own copy of action.c, and
changing the code for mk_unary to be the following.  I haven't
tested this, however.

ast mk_unary() {
  ast expr = top_ast(0);
  operation op = top_op();
  pop_ast();
  pop_op();
  if (op == vAddress)
    push_ast(expr);
  else push_ast(make_ast_unop(op, expr));
  return top_ast();
}

William D Clinger