[svn] r7719: nemerle/trunk/ncc/typing: MacroRegistry.n Typer.n
divan
svnadmin at nemerle.org
Thu Jun 28 20:52:16 CEST 2007
Log:
Work on expanding macro in Typer.
Author: divan
Date: Thu Jun 28 20:52:13 2007
New Revision: 7719
Modified:
nemerle/trunk/ncc/typing/MacroRegistry.n
nemerle/trunk/ncc/typing/Typer.n
Modified: nemerle/trunk/ncc/typing/MacroRegistry.n
==============================================================================
--- nemerle/trunk/ncc/typing/MacroRegistry.n (original)
+++ nemerle/trunk/ncc/typing/MacroRegistry.n Thu Jun 28 20:52:13 2007
@@ -92,7 +92,7 @@
}
}
- internal static expand_macro (ctx : Typer, expr : PExpr) : PExpr * list [IMacro * PExpr] {
+ internal static expand_one_macro (ctx : Typer, expr : PExpr) : PExpr * option [IMacro * PExpr] {
match (expr) {
| PExpr.Call (name, args) =>
match (Util.QidOfExpr (name)) {
@@ -106,11 +106,10 @@
} finally {
ctx.Manager.MacroColors.PopColor ();
}
- def (res, rest) = expand_macro (ctx, expanded);
- (res, (x, expr) :: rest)
- | None => (expr, [])
+ (expanded, Some ((x, expr)))
+ | None => (expr, None ())
}
- | None => (expr, [])
+ | None => (expr, None ())
}
| PExpr.MacroCall (name, namespc, parms) =>
@@ -123,14 +122,22 @@
} finally {
ctx.Manager.MacroColors.PopColor ();
}
- def (res, rest) = expand_macro (ctx, expanded);
- (res, (m, expr) :: rest)
+ (expanded, Some ((m, expr)))
| _ =>
Util.ice ("failed to resolve macro name `" + namespc.GetDisplayName () + "'")
}
- | _ => (expr, [])
+ | _ => (expr, None ())
+ }
+ }
+
+ internal static expand_macro (ctx : Typer, expr : PExpr) : PExpr * list [IMacro * PExpr] {
+ match (expand_one_macro (ctx, expr)) {
+ | (e, Some (h)) =>
+ def (e, lst) = expand_macro (ctx, e);
+ (e, h :: lst)
+ | (e, None) => (e, [])
}
}
Modified: nemerle/trunk/ncc/typing/Typer.n
==============================================================================
--- nemerle/trunk/ncc/typing/Typer.n (original)
+++ nemerle/trunk/ncc/typing/Typer.n Thu Jun 28 20:52:13 2007
@@ -1074,30 +1074,29 @@
def orig_loc = e.Location;
log (MACRO_EXPANSIONS, e.loc, $ "running expand with: $e");
- def (e, wraps) = MacroRegistry.expand_macro (this, e);
+ match (MacroRegistry.expand_one_macro (this, e)) {
+ | (e, None) =>
log (MACRO_EXPANSIONS, e.loc, $ "after expansion: $e");
def res = DoType (e, expected, is_toplevel_in_seq);
-
- log (TYPING, e.loc,
+ log (TYPING, e'.loc,
$ "done typing: $e --> $res [$(res.GetHashCode())] : $(if (res.ty != null) res.Type else null))");
- def wrap (e, wraps) {
- match (wraps) {
- | (orig, im) :: xs =>
+ when (res.ty == null)
+ res.ty = expected;
+ res
+
+ | (e, Some ((orig, im))) =>
+ log (MACRO_EXPANSIONS, e.loc, $ "after expansion: $e");
+
+ def res = TypeExpr (e, expected, is_toplevel_in_seq);
+
// IT: In some cases, MacroEnvelope takes e.Location without keyword location.
// For example, for (mutable i;;) {} takes e.Location without 'for'.
// The following fixes that.
- def loc = if (orig_loc.IsGenerated) e.Location else orig_loc;
- wrap (TExpr.MacroEnvelope (loc, e.Type, im, orig, e), xs)
- | [] => e
- }
+ def loc = if (orig_loc.IsGenerated) res.Location else orig_loc;
+ TExpr.MacroEnvelope (loc, res.Type, im, orig, res)
}
-
- when (res.ty == null)
- res.ty = expected;
-
- wrap (res, wraps.Rev ())
}
} catch {
| _ is Recovery =>
More information about the svn
mailing list