[svn] r6807: nemerle/trunk/ncc: generation/ILEmitter.n
generation/Typer3.n generation/Typer4.n misc/Pretty...
malekith
svnadmin at nemerle.org
Sun Oct 29 14:13:21 CET 2006
Log:
Add TExpr.MacroEnvelope.
Author: malekith
Date: Sun Oct 29 14:13:15 2006
New Revision: 6807
Modified:
nemerle/trunk/ncc/generation/ILEmitter.n
nemerle/trunk/ncc/generation/Typer3.n
nemerle/trunk/ncc/generation/Typer4.n
nemerle/trunk/ncc/misc/PrettyPrint.n
nemerle/trunk/ncc/typing/MacroRegistry.n
nemerle/trunk/ncc/typing/Macros.n
nemerle/trunk/ncc/typing/TypedTree.n
nemerle/trunk/ncc/typing/Typer.n
nemerle/trunk/ncc/typing/Typer2.n
Modified: nemerle/trunk/ncc/generation/ILEmitter.n
==============================================================================
--- nemerle/trunk/ncc/generation/ILEmitter.n (original)
+++ nemerle/trunk/ncc/generation/ILEmitter.n Sun Oct 29 14:13:15 2006
@@ -672,6 +672,10 @@
}
+ | MacroEnvelope (_, _, expr) =>
+ emit (expr)
+
+
/* insert label so TExpr.Goto can work */
| Label (id, expr) =>
if (_labels.Contains (id))
Modified: nemerle/trunk/ncc/generation/Typer3.n
==============================================================================
--- nemerle/trunk/ncc/generation/Typer3.n (original)
+++ nemerle/trunk/ncc/generation/Typer3.n Sun Oct 29 14:13:15 2006
@@ -1828,6 +1828,8 @@
TExpr.TypeOf (SubstType (t))
| HasType (e, t) =>
TExpr.HasType (SubstExpr (e), SubstType (t))
+ | MacroEnvelope (m, o, e) =>
+ TExpr.MacroEnvelope (m, o, SubstExpr (e))
| DefValIn (name, _, _) =>
name.SetType (SubstType (name.Type));
Modified: nemerle/trunk/ncc/generation/Typer4.n
==============================================================================
--- nemerle/trunk/ncc/generation/Typer4.n (original)
+++ nemerle/trunk/ncc/generation/Typer4.n Sun Oct 29 14:13:15 2006
@@ -290,6 +290,7 @@
else
Throws (e, allow_try, false)
+ | MacroEnvelope (_, _, e)
| Label (_, e) =>
Throws (e, allow_try, is_top)
Modified: nemerle/trunk/ncc/misc/PrettyPrint.n
==============================================================================
--- nemerle/trunk/ncc/misc/PrettyPrint.n (original)
+++ nemerle/trunk/ncc/misc/PrettyPrint.n Sun Oct 29 14:13:15 2006
@@ -57,7 +57,7 @@
def expr =
match (ctx) {
- | Some (c) => MacroRegistry.expand_macro (c, expr)
+ | Some (c) => MacroRegistry.expand_macro (c, expr) [0]
| _ => expr
};
@@ -1065,6 +1065,10 @@
append ($ "l$k:\n");
recurse_and_indent (body);
+ | TT.TExpr.MacroEnvelope (k, o, body) =>
+ append ($ "macro$k ($o):\n");
+ recurse_and_indent (body);
+
| TT.TExpr.Block (jump, body) =>
append ($ "block ($(jump.Name)) : ");
Modified: nemerle/trunk/ncc/typing/MacroRegistry.n
==============================================================================
--- nemerle/trunk/ncc/typing/MacroRegistry.n (original)
+++ nemerle/trunk/ncc/typing/MacroRegistry.n Sun Oct 29 14:13:15 2006
@@ -92,7 +92,7 @@
}
}
- internal static expand_macro (ctx : Typer, expr : PExpr) : PExpr {
+ internal static expand_macro (ctx : Typer, expr : PExpr) : PExpr * list [IMacro * PExpr] {
match (expr) {
| PExpr.Call (name, args) =>
match (Util.QidOfExpr (name)) {
@@ -106,10 +106,11 @@
} finally {
ctx.Manager.MacroColors.PopColor ();
}
- expand_macro (ctx, expanded);
- | None => expr
+ def (res, rest) = expand_macro (ctx, expanded);
+ (res, (x, expr) :: rest)
+ | None => (expr, [])
}
- | None => expr
+ | None => (expr, [])
}
| PExpr.MacroCall (name, namespc, parms) =>
@@ -122,12 +123,14 @@
} finally {
ctx.Manager.MacroColors.PopColor ();
}
- expand_macro (ctx, expanded)
+ def (res, rest) = expand_macro (ctx, expanded);
+ (res, (m, expr) :: rest)
+
| _ =>
Util.ice ("failed to resolve macro name `" + namespc.GetDisplayName () + "'")
}
- | _ => expr
+ | _ => (expr, [])
}
}
Modified: nemerle/trunk/ncc/typing/Macros.n
==============================================================================
--- nemerle/trunk/ncc/typing/Macros.n (original)
+++ nemerle/trunk/ncc/typing/Macros.n Sun Oct 29 14:13:15 2006
@@ -889,7 +889,7 @@
Util.locate (expr.loc, {
def expr =
match (ctx) {
- | Some (c) => MacroRegistry.expand_macro (c, expr)
+ | Some (c) => MacroRegistry.expand_macro (c, expr) [0]
| _ => expr
};
Modified: nemerle/trunk/ncc/typing/TypedTree.n
==============================================================================
--- nemerle/trunk/ncc/typing/TypedTree.n (original)
+++ nemerle/trunk/ncc/typing/TypedTree.n Sun Oct 29 14:13:15 2006
@@ -503,6 +503,7 @@
| ArrayIndexer { obj : TExpr; args : list [TExpr]; }
| TupleIndexer { obj : TExpr; pos : int; len : int; } // 0-based
| OpCode { name : string; }
+ | MacroEnvelope { original : Parsetree.PExpr; the_macro : IMacro; expanded : TExpr; }
// invalid after T2
| PropertyMember { obj : TExpr; prop : IProperty; }
@@ -657,6 +658,8 @@
ty = InternalType.Void
| HasType =>
ty = InternalType.Boolean
+ | MacroEnvelope (_, _, e) =>
+ ty = e.Type
| _ =>
Util.ice ($ "type is null for $loc, $this");
}
@@ -979,6 +982,12 @@
ArrayIndexer (walk (f, obj), walks (f, args))
+ | MacroEnvelope (id, orig, body) =>
+ def body = null_walk (f, body);
+ if (body == null) null
+ else
+ MacroEnvelope (id, orig, body)
+
| Label (id, body) =>
def body = null_walk (f, body);
if (body == null) null
Modified: nemerle/trunk/ncc/typing/Typer.n
==============================================================================
--- nemerle/trunk/ncc/typing/Typer.n (original)
+++ nemerle/trunk/ncc/typing/Typer.n Sun Oct 29 14:13:15 2006
@@ -1033,14 +1033,26 @@
e'
} else {
log (MACRO_EXPANSIONS, e.loc, $ "running expand with: $e");
- def e = MacroRegistry.expand_macro (this, e);
+ def (e, wraps) = MacroRegistry.expand_macro (this, e);
log (MACRO_EXPANSIONS, e.loc, $ "after expansion: $e");
def res = DoType (e, expected, is_toplevel_in_seq);
log (TYPING, e.loc,
$ "done typing: $e --> $res : $(if (res.ty != null) res.Type else null))");
- res
+
+ def wrap (e, wraps) {
+ match (wraps) {
+ | (orig, im) :: xs =>
+ wrap (TExpr.MacroEnvelope (e.Location, e.Type, im, orig, e), xs)
+ | [] => e
+ }
+ }
+
+ when (res.ty == null)
+ res.ty = expected;
+
+ wrap (res, wraps.Rev ())
}
} catch {
| _ is Recovery =>
@@ -3435,6 +3447,7 @@
| TExpr.TupleIndexer => "an tuple indexer reference"
| TExpr.TypeOf => "a typeof expression"
| TExpr.OpCode => "an operator reference"
+ | TExpr.MacroEnvelope (_, _, e) => DescribeExpression (e)
| TExpr.Error => "an erroneous expression"
| TExpr.Delayed (dt) =>
Modified: nemerle/trunk/ncc/typing/Typer2.n
==============================================================================
--- nemerle/trunk/ncc/typing/Typer2.n (original)
+++ nemerle/trunk/ncc/typing/Typer2.n Sun Oct 29 14:13:15 2006
@@ -1279,6 +1279,10 @@
TExpr.Label (lab, Walk (ctx, body))
+ | TExpr.MacroEnvelope (lab, orig, body) =>
+ TExpr.MacroEnvelope (lab, orig, Walk (ctx, body))
+
+
| TExpr.Block as b =>
Walk (ctx, ExpandBlock (b))
More information about the svn
mailing list