Scope rules for CPS and other questions...

Daniel Wang danwang@cs.princeton.edu
01 Dec 1999 20:01:35 -0500


Suresh Jagannathan <suresh@research.nj.nec.com> writes:

> The paper simplifies things a little bit from the current implementation,
> but I don't think there's any significant deviation.  CPS local functions
> have limited scope (namely the enclosing top-level function), but because
> they are continuations they don't escape fro the function in which they
> are defined.  There's no explicit lambda lifting phase.  MLton handles
> tail-calls properly.  I suspect since CPS functions get turned into labels
> and are called via jumps, the overhead of using "pure" CPS won't be very
> great, although I would be curious to see the results.

thanks, but I'm still not clear. Are CPS local functions able to 
"capture" variables from the enclosing scope? Or are local functions just
like top-level functions?

e.g.

 fun f (x) =
  let
    fun g(y)  = (x,y)
  in g(1) 
  end	

should I interpert the above equivalent to

 fun f (x) = g(x,1)
 and g (x,y)  = (x,y)
 
or the *bogus* declaration

 fun f(x) = g(x)
 and g(y) = (x,y) 

Also how are the jumps implemented in the C code produced by gcc?
There seems to be some magic involved otherwise you'd end up with one very
big C procedure that held the entire program, which would make gcc run dog
slow. (Not that I care about gcc's compile time or anything..) I just want to
know if I'll be able to compile big programs if I CPS convert everything in
a resonable time.