[svn] r6045: nemerle/trunk/ncc: misc/PrettyPrint.n testsuite/negative/delayed-macro-colors.n typing/Typer....

malekith svnadmin at nemerle.org
Thu Dec 29 23:03:37 CET 2005


Log:
Restore colors on delayed macro execution.

Author: malekith
Date: Thu Dec 29 23:03:36 2005
New Revision: 6045

Added:
   nemerle/trunk/ncc/testsuite/negative/delayed-macro-colors.n
Modified:
   nemerle/trunk/ncc/misc/PrettyPrint.n
   nemerle/trunk/ncc/typing/Typer.n

Modified: nemerle/trunk/ncc/misc/PrettyPrint.n
==============================================================================
--- nemerle/trunk/ncc/misc/PrettyPrint.n	(original)
+++ nemerle/trunk/ncc/misc/PrettyPrint.n	Thu Dec 29 23:03:36 2005
@@ -39,6 +39,8 @@
 using Nemerle.Compiler.Parsetree;
 using TT = Nemerle.Compiler.Typedtree;
 
+//#define PRINT_COLOR
+
 namespace Nemerle.Compiler
 {
   public module PrettyPrint
@@ -97,7 +99,10 @@
       def sprint_ss (x) {
         if (x == null) add ("(NULL-MEM)") else
         match (x) {
-          | Splicable.Name (n) => add (n.Id)
+          | Splicable.Name (n) => add (n.Id);
+          #if PRINT_COLOR
+          add ("."); add (n.color.ToString ());
+          #endif
           | Splicable.Expression (e) =>
             add ("$(");
             SprintExpr (ctx, e, indentation, acc);
@@ -111,7 +116,9 @@
       match (expr) {
         | <[ $(n : name) ]> =>
           add (n.Id);
-          // add ("."); add (n.color.ToString ());
+          #if PRINT_COLOR
+          add ("."); add (n.color.ToString ());
+          #endif
 
         | <[ $obj . $mem ]> => 
           SprintExpr (ctx, obj, indentation, acc); add ("."); sprint_ss (mem)

Added: nemerle/trunk/ncc/testsuite/negative/delayed-macro-colors.n
==============================================================================
--- (empty file)
+++ nemerle/trunk/ncc/testsuite/negative/delayed-macro-colors.n	Thu Dec 29 23:03:36 2005
@@ -0,0 +1,4 @@
+def foo(lst) { lst.Map(Nemerle.Collections.List.IsEmpty) }
+foreach (_ in foo([]))
+  _ = x // E: unbound
+ 

Modified: nemerle/trunk/ncc/typing/Typer.n
==============================================================================
--- nemerle/trunk/ncc/typing/Typer.n	(original)
+++ nemerle/trunk/ncc/typing/Typer.n	Thu Dec 29 23:03:36 2005
@@ -463,19 +463,47 @@
       <[ $(DelayAction (expected, DelayedMacro (this, expected, resolve)) : typed) ]>
     }
 
-    [Record]
     class DelayedMacro : DelayedAction
     {
       typer : Typer;
       expected : TyVar;
       fn : bool -> option [PT.PExpr];
       
+      context : int * int * GlobalEnv;
+
+      public this (typer : Typer, expected : TyVar, fn : bool -> option [PT.PExpr])
+      {
+        this.typer = typer;
+        this.expected = expected;
+        this.fn = fn;
+
+        context = 
+          (MacroColorizer.Color, 
+           MacroColorizer.UseColor, 
+           MacroColorizer.UseContext);
+      }
+      
       public override Resolve (fail_loudly : bool) : option [TExpr]
       {
+        def backup = 
+          (MacroColorizer.Color, 
+           MacroColorizer.UseColor, 
+           MacroColorizer.UseContext);
+           
+        (MacroColorizer.Color, 
+         MacroColorizer.UseColor, 
+         MacroColorizer.UseContext) = context;
+
+        try {
         match (fn (fail_loudly)) {
           | Some (e) => Some (typer.TypeExpr (e, expected))
           | None => None ()
         }
+        } finally {
+          (MacroColorizer.Color, 
+           MacroColorizer.UseColor, 
+           MacroColorizer.UseContext) = backup;
+        }
       }
     }
 



More information about the svn mailing list