Tue Oct 25 15:30:23 EDT 2011

TML Code in terms of Expr

This needs a cleanup of Expr.  I currently do not have a way to
represent a variable reference as a term of Expr.

Then I'm not getting the CPS version of makeVar.

Time to take a sneak peak[1].  It defines the following form:

let retN a =
  fun s k -> .<let z = .~a in .~(k s .<z>.)>.

The trick is that this manipulates the return value of the final CPS

With this change I'm having trouble trying to separate Expr and Term,
so let's merge them.

These work:

makeVar :: TypeOf (Code t) => (Code t) -> MCode (Code t)
makeVar term@(Code sterm) = SC c where  
  c (State n) k = 
    Let var sterm (k state' ref) where
      state' = State $ n+1
      ref = Code $ Ref $ var
      var = Var typ nam 0
      typ = typeOf term
      nam = regPrefix ++ (show $ n)

runMCode :: MCode rt -> (State -> rt -> Term) -> Term
runMCode (SC c) = c (State 0)

termExpr m = runMCode m k where
  k _ (Code (Ref v)) = Ret v  -- toplevel continuation

l = lit 123
l :: TML m r => r Tint

> termExpr $ add l l

Let (Var i "t0" 0)
     (Op i "add" [Lit i "123",
                  Lit i "123"])
 (Ret (Var i "t0" 0))

However, the termFun compiler seems to need some tinkering.  I don't
see immediately how it is different.  It seems most of it can be
reused though.  The result will be a FunDef node.

Maybe it should be a Lambda node.

[1] http://www.cs.rice.edu/~taha/publications/conference/pepm06.ps