[<<][meta][>>][..]
Sat Nov 19 12:28:57 EST 2011

PrettyC.hs

got: Ret, Let, App, Lit, Ref (Var), Op

todo: LetRec, If


For LetRec we need the following form:

{
  _ fun_0;
  _ fun_1;
  ...
fun:
  {
    ...
  }

  {
    ...
  }

}

Argument variables are declared inside a new scope without initial
assignment.  Function body is a new scope, and the body of the scope
for which the "fun" identifier is valid is also a new scope.  Probably
needs some nesting of the "fun" names to avoid clashes.

Problem: argument variable naming: at call site we don't know names,
and at definition site we can't change names.  So an extra indirection
is necessary to bind numbered names to given names.  This also solves
the name clash problem.


Got this coming out as compilation of

(letrec ((fun1
          (lambda (a b)
            (fun1 b a))))
  (fun1 1 2))


void fun()
{
    {
        float fun1_0;
        float fun1_1;
        {
            fun1_0 = 1;
            fun1_1 = 2;
            goto fun1;
        }
    fun1:
        {
            float a = fun1_0;
            float b = fun1_1;
            fun1_0 = b;
            fun1_1 = a;
            goto fun1;
        }
    }
}


Extended to mutial recursion:

(letrec ((fun1 (lambda (a b) (fun2 b a)))
         (fun2 (lambda (a b) (fun1 b a))))
  (fun1 1 2))


void fun()
{
    {
        float fun1_0;
        float fun1_1;
        float fun2_0;
        float fun2_1;
        {
            fun1_0 = 1;
            fun1_1 = 2;
            goto fun1;
        }
    fun1:
        {
            float a = fun1_0;
            float b = fun1_1;
            fun2_0 = b;
            fun2_1 = a;
            goto fun2;
        }
    fun2:
        {
            float a = fun2_0;
            float b = fun2_1;
            fun1_0 = b;
            fun1_1 = a;
            goto fun1;
        }
    }
}




[Reply][About]
[<<][meta][>>][..]