[<<][meta][>>][..]
Tue Dec 13 10:54:57 EST 2011

Toplevel definitions

Should this be part of Loop class?  What should be the return type?
Nothing probably, it's a side effect.

  class TML m r => Loop s m r | r -> m, r -> s where
    ...
    -- Toplevel definition.  
    _def :: String -> t -> m (r ())

So what about the type?  What I need mostly is to map t to a primitive
type, so it needs a TypeOf instance.

What about this:

  class TML m r => Loop s m r | r -> m, r -> s where
    ...
    _def :: TypeOf (r t) => String -> m (r t) -> m (r ())

  instance Loop Term MCode' Code where
    ...
    _def name mterm = do
      ct@(Code term) <- mterm
      return $ Code $ Topdef (Var (typeOf ct) name) term

I didn't try yet, but one thing that's missing is obviously the
instance of TypeOf for functions, and a way to collect toplevel
definitions.  This should manipulate the continutation, inserting the
definitions in a Begin form.  This can reuse mVoid:

    _def name mterm = do
      ct@(Code term) <- mterm
      mVoid $ Code $ Topdef (Var (typeOf ct) name) term


Ok, that's it.  After adding a workaround in PrimC for the Begin
wrapper introduced by mVoid, this is what comes out:

  ctop t = code $ termTopdef t
  t10 = _def "fun" (compileLoopTop f)
  t11 = ctop $ term $ t10

  *Main> t11
  int fun(float a0, float * a1, float * a2, int a3)
  {
      {
          float fun4_0;
          int fun4_1;
          {
              fun4_0 = a0;
              fun4_1 = 0;
              goto fun4;
          }
      fun4:
          {
              const float a5 = fun4_0;
              const int a6 = fun4_1;
              const float r7 = *add(a1, a6);
              const float r8 = add(a5, r7);
              *add(a2, a6) = r8;
              const int r9 = lt(a6, a3);
              if (r9)
              {
                  const int r10 = add(a6, 1);
                  fun4_0 = r8;
                  fun4_1 = r10;
                  goto fun4;
              }
              else
              {
                  return 0;
              }
          }
      }
  }



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