[nem-en] access to type and function call resolution information in a macro

Kamil Skalski kamil.skalski at gmail.com
Tue Jun 6 22:35:22 CEST 2006


You can perform typing of expression from inside macro, though it
makes it a little bit more verbose and less stable with respect to
type inference:

    /** Delay execution of the current macro. You need to provide a function
        that will resolve it at a later time, when more info is needed. It shall
        take one boolean parameter, when it is true, you should fail with a
        descriptive error message stating that more typing information
is needed.
        If it is false, you should just return None ().

        For example:

        macro foo (x) {
          def x' = Macros.ImplicitCTX ().TypeExpr (x);

          Macros.ImplicitCTX ().DelayMacro (fun (fail_loudly) {
            match (x'.Type.Hint) {
              | Some (t) =>
                // do something with the type
                Some (...)
              | None =>
                when (fail_loudly)
                  Message.Error (x.loc, $ "cannot deduce type of $x");
                None ()
            }
          })
        }

        This function will first try to call your resolution function
and only if
        it fails, it will get queued for later.
    */
    public DelayMacro (resolve : bool -> option [PT.PExpr],
                       mutable expected : TyVar = null) : PT.PExpr

2006/6/6, Kannan Goundan <cakoose at yahoo.com>:
> I'm wrote a macro that takes:
>
>    FancyAssert(a < 10)
>
> And produces something like:
>
>    unless (a < 10)
>       throw Exception("Failed: (a < 10), a = " + a.ToString());
>
> Right now, it works with a 'PExpr' tree, but I currently have some
> issues that could be resolved if type information and function call
> resolution information were available.  Any ideas?
>
> - Kannan
>
> __________________________________________________
> Do You Yahoo!?
> Tired of spam?  Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com
>
> _______________________________________________
> https://nemerle.org/mailman/listinfo/devel-en
>


-- 
Kamil Skalski
http://nazgul.omega.pl



More information about the devel-en mailing list