[svn] r6488: nemerle/trunk: boot/Nemerle.Compiler.dll boot/Nemerle.MSBuild.Tasks.dll boot/Nemerle.Macros.d...

nazgul svnadmin at nemerle.org
Sun Aug 6 18:42:28 CEST 2006


Log:
Cleanup after try/catch changes.

Author: nazgul
Date: Sun Aug  6 18:36:19 2006
New Revision: 6488

Modified:
   nemerle/trunk/boot/Nemerle.Compiler.dll
   nemerle/trunk/boot/Nemerle.MSBuild.Tasks.dll
   nemerle/trunk/boot/Nemerle.Macros.dll
   nemerle/trunk/boot/Nemerle.dll
   nemerle/trunk/boot/ncc.exe
   nemerle/trunk/macros/Late.n
   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/parsing/ParseTree.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/boot/Nemerle.Compiler.dll
==============================================================================
Binary files. No diff available.

Modified: nemerle/trunk/boot/Nemerle.MSBuild.Tasks.dll
==============================================================================
Binary files. No diff available.

Modified: nemerle/trunk/boot/Nemerle.Macros.dll
==============================================================================
Binary files. No diff available.

Modified: nemerle/trunk/boot/Nemerle.dll
==============================================================================
Binary files. No diff available.

Modified: nemerle/trunk/boot/ncc.exe
==============================================================================
Binary files. No diff available.

Modified: nemerle/trunk/macros/Late.n
==============================================================================
--- nemerle/trunk/macros/Late.n	(original)
+++ nemerle/trunk/macros/Late.n	Sun Aug  6 18:36:19 2006
@@ -306,8 +306,6 @@
         | PExpr.Lambda(decl) => PExpr.Lambda(loc, recurse_fun(decl))
         | PExpr.Throw(expr) =>
           PExpr.Throw(loc, recurse(expr))
-        | PExpr.TryWith(body, ex, ty, handler) =>
-          PExpr.Try(loc, recurse(body), [TryCase.Catch(ex, ty, recurse(handler))])
         | PExpr.TryFinally(body, handler) =>
           PExpr.TryFinally(loc, recurse(body), recurse(handler))
         | PExpr.Try(body, cases) =>

Modified: nemerle/trunk/ncc/generation/ILEmitter.n
==============================================================================
--- nemerle/trunk/ncc/generation/ILEmitter.n	(original)
+++ nemerle/trunk/ncc/generation/ILEmitter.n	Sun Aug  6 18:36:19 2006
@@ -1169,46 +1169,6 @@
 
 
         /* emit the try/with construction */
-        | TryWith (try_expr, catch_val, catch_expr)
-        | TryFault (try_expr, catch_expr) with catch_val = null =>
-          def type_of_try_expr = expr.SystemType;
-
-          def ignore_try_with_result = is_void (try_expr.Type);
-          mutable try_result = null;
-
-          unless (ignore_try_with_result)
-            try_result = _ilg.DeclareLocal (type_of_try_expr);
-
-          _ = _ilg.BeginExceptionBlock ();
-
-          emit (try_expr);
-
-          unless (try_expr.Throws || ignore_try_with_result)
-            _ilg.Emit (OpCodes.Stloc, try_result);
-
-          if (catch_val == null) {
-            _ilg.BeginFaultBlock ();
-            emit (catch_expr);
-          } else {
-            _ilg.BeginCatchBlock (catch_val.Type.SystemType);
-
-            def catch_val_local_slot = declare_val_local_slot (catch_val);
-            _ilg.Emit (OpCodes.Stloc, catch_val_local_slot);
-
-            emit (catch_expr);
-            // close scope opened by declare_val_local_slot
-            when (_debug_doc != null) _ilg.EndScope ();
-
-            unless (catch_expr.Throws || ignore_try_with_result)
-              _ilg.Emit (OpCodes.Stloc, try_result);
-          }
-
-          _ilg.EndExceptionBlock ();
-
-          unless (ignore_try_with_result)
-            _ilg.Emit (OpCodes.Ldloc, try_result);
-
-
         | TryFinally (try_expr, finally_expr) =>
           def type_of_try_expr = try_expr.SystemType;
 
@@ -1252,6 +1212,10 @@
             _ilg.Emit (OpCodes.Stloc, try_result);
 
           def walk_case (case) {
+            | Try_case.Fault (catch_expr) =>
+              _ilg.BeginFaultBlock ();
+              emit (catch_expr);
+            
             | Try_case.Catch (catch_val, catch_expr) =>
               _ilg.BeginCatchBlock (catch_val.Type.SystemType);
 

Modified: nemerle/trunk/ncc/generation/Typer3.n
==============================================================================
--- nemerle/trunk/ncc/generation/Typer3.n	(original)
+++ nemerle/trunk/ncc/generation/Typer3.n	Sun Aug  6 18:36:19 2006
@@ -798,14 +798,10 @@
               body.Walk (rewrite),
               TExpr.Assign (InternalType.Void, fldref, TExpr.TrueLiteral)])
 
-        | TryWith (body, _, handler) =>
-          _ = body.Walk (look_for_invalid_yield);
-          _ = handler.Walk (look_for_invalid_yield);
-          expr
-
         | Try (body, cases) as expr =>
           _ = body.Walk (look_for_invalid_yield);
           def walk_case(case) {
+            | Try_case.Fault (handler)
             | Try_case.Catch (_, handler) =>
               _ = handler.Walk (look_for_invalid_yield);
             | Try_case.Filter (_, filter, handler) =>
@@ -829,7 +825,7 @@
                         TExpr.MethodRef (dispose_meth.GetMemType (),
                                          thisref, dispose_meth, [], true), 
                         [], false);
-          def expr = TExpr.TryFault (expr.Type, expr, dispose_call);
+          def expr = TExpr.Try (expr.Type, expr, [Try_case.Fault (dispose_call)]);
           fh.body = FunBody.Typed (expr);
           
           def this_N_state =
@@ -1725,19 +1721,6 @@
         // we cannot handle closurised values as placeholders for exceptions
         // so we use a fresh variable for exception and assign it using
         // regular DefValIn
-        | TExpr.TryWith (body, orig, handler) =>
-          if (orig.InClosure) {
-            def val =
-              LocalValue (current_local_fun, orig.Name,
-                          orig.Type,
-                          LocalValue.Kind.ExceptionValue (),
-                          is_mutable = false);
-            val.Register ();
-            val.UseFrom (current_local_fun);
-            def handler =
-              TExpr.DefValIn (handler.Type, orig, PlainRef (val), handler);
-            TExpr.Try (Walk (body), [Try_case.Catch (val, Walk (handler))])
-          } else null
         | TExpr.Try (body, cases) =>
           mutable change_happened = false;
           def need_walk (cases) {
@@ -1771,7 +1754,8 @@
                 TExpr.DefValIn (handler.Type, orig, PlainRef (val), handler);
               change_happened = true;
               Try_case.Filter (val, Walk (filter), Walk (handler))
-            | Try_case.Catch => case
+            | Try_case.Fault
+            | Try_case.Catch 
             | Try_case.Filter => case
           }
           if (need_walk (cases))
@@ -1842,8 +1826,7 @@
         | HasType (e, t) =>
           TExpr.HasType (SubstExpr (e), SubstType (t))
           
-        | DefValIn (name, _, _)
-        | TryWith (_, name, _) =>
+        | DefValIn (name, _, _) =>
           name.SetType (SubstType (name.Type));
           null
 
@@ -1865,7 +1848,6 @@
         | Assign
         | Throw
         | TryFinally
-        | TryFault
         | Literal
         | This
         | Base

Modified: nemerle/trunk/ncc/generation/Typer4.n
==============================================================================
--- nemerle/trunk/ncc/generation/Typer4.n	(original)
+++ nemerle/trunk/ncc/generation/Typer4.n	Sun Aug  6 18:36:19 2006
@@ -218,8 +218,7 @@
           log (STV, expr.loc, $ "done )");
         }
         match (expr) {
-          | DefValIn (name, _, _)
-          | TryWith (_, name, _) =>
+          | DefValIn (name, _, _) =>
             log (STV, expr.loc, $ "( name($(name)) : $(name.Type)");
             CheckSTV (name.Type);
             log (STV, expr.loc, $ "done )");
@@ -230,7 +229,7 @@
                 log (STV, expr.loc, $ "( name($(name)) : $(name.Type)");
                 CheckSTV (name.Type);
                 log (STV, expr.loc, $ "done )");
-              | _ => ()
+              | Try_case.Fault => ()
             }
             foreach (case in cases)
               walk_case (case);
@@ -388,8 +387,6 @@
             exprs.Iter (NoThrowPlease);
             false
 
-          | TryFault (body, handler)
-          | TryWith (body, _, handler)
           | TryFinally (body, handler) =>
             when (! allow_try)
               // use ice here?
@@ -407,6 +404,7 @@
                              "try-blocks cannot be used inside expressions, "
                              "this message shouldn't happen though");
             def walk_case (case) {
+              | Try_case.Fault (handler)
               | Try_case.Catch (_, handler) =>
                 _ = Throws (handler, true);
               | Try_case.Filter (_, filter, handler) =>
@@ -669,17 +667,13 @@
             }
             TExpr.Array (res.Rev (), dimensions)
 
-          | TryWith (body, exn, handler) =>
-            TExpr.Try (WalkTry (body), [Try_case.Catch (exn, WalkTry (handler))])
-            
           | TryFinally (body, handler) =>
             TExpr.TryFinally (WalkTry (body), Walk (handler))
 
-          | TryFault (body, handler) =>
-            TExpr.TryFault (WalkTry (body), Walk (handler))
-
           | Try (body, cases) =>
             def walk_case (case) {
+              | Try_case.Fault (handler) =>
+                Try_case.Fault (WalkTry (handler))
               | Try_case.Catch (exn, handler) =>
                 Try_case.Catch (exn, WalkTry (handler))
               | Try_case.Filter (exn, filter, handler) =>

Modified: nemerle/trunk/ncc/misc/PrettyPrint.n
==============================================================================
--- nemerle/trunk/ncc/misc/PrettyPrint.n	(original)
+++ nemerle/trunk/ncc/misc/PrettyPrint.n	Sun Aug  6 18:36:19 2006
@@ -206,16 +206,6 @@
         | <[ throw $exc ]> =>
           add ("throw "); SprintExpr (ctx, exc, indentation, acc);
 
-        | PExpr.TryWith (body, exn, exn_ty, handler) =>
-          add (sprintf ("try {\n%s  ", indentation));
-          SprintExpr (ctx, body, indentation + "  ", acc);
-          add (sprintf ("\n%s}\n%scatch {\n%s", indentation, indentation, indentation + "  "));
-          sprint_ss (exn); add (" : ");
-          SprintExpr (ctx, exn_ty, indentation, acc);
-          add (sprintf ("=>\n%s", indentation + "    "));
-          SprintExpr (ctx, handler, indentation + "    ", acc);
-          add (sprintf ("\n%s}", indentation));
-
         | PExpr.TryFinally (body, handler) =>
           add (sprintf ("try {\n%s  ", indentation));
           SprintExpr (ctx, body, indentation + "  ", acc);
@@ -1123,22 +1113,6 @@
           append ("throw ");
           recurse (exn)
 
-        | TT.TExpr.TryFault (body, handler) =>
-          append ("try {\n");
-          recurse_and_indent (body);
-          append ("\n" + indentation + "} fault {\n");
-          recurse_and_indent (handler);
-          append ("\n" + indentation + "}")
-        
-        | TT.TExpr.TryWith (body /* PExpr */, exn /* LocalValue */, handler /* PExpr */) =>
-          append ("try {\n");
-          recurse_and_indent (body);
-          append ("\n" + indentation + "} catch {\n  " + indentation + exn.Name + " : ");
-          print_type (exn.Type);
-          append (" =>\n");
-          recurse_and_indent (handler);
-          append ("\n" + indentation + "}")
-          
         | TT.TExpr.TryFinally (body /* PExpr */, handler /* PExpr */) =>
           append ("try {\n");
           recurse_and_indent (body);
@@ -1151,6 +1125,8 @@
           recurse_and_indent (body);
           append ("\n" + indentation + "} catch {");
           def print_case (case) {
+            | TT.Try_case.Fault (handler) =>
+              recurse_and_indent (handler);
             | TT.Try_case.Catch (exn, handler) =>
               append ("\n  " + indentation + "| " + exn.Name + " is ");
               print_type (exn.Type);

Modified: nemerle/trunk/ncc/parsing/ParseTree.n
==============================================================================
--- nemerle/trunk/ncc/parsing/ParseTree.n	(original)
+++ nemerle/trunk/ncc/parsing/ParseTree.n	Sun Aug  6 18:36:19 2006
@@ -274,8 +274,6 @@
     | Lambda          { decl : Function_decl; }
     | Throw           { exn : PExpr; }
     | Try             { body : PExpr; cases : list [TryCase]; }
-    | TryWith         { body : PExpr; exn : Splicable; exn_ty : PExpr; 
-                        handler : PExpr; }
     | TryFinally      { body : PExpr; handler : PExpr; }
     | Literal         { val : Nemerle.Compiler.Literal; }
     | This

Modified: nemerle/trunk/ncc/typing/Macros.n
==============================================================================
--- nemerle/trunk/ncc/typing/Macros.n	(original)
+++ nemerle/trunk/ncc/typing/Macros.n	Sun Aug  6 18:36:19 2006
@@ -614,20 +614,13 @@
       | <[ out $e ]> =>
         <[ PExpr.ParmOut ($(quoted_expr (e))) ]>
 
-      | PExpr.TryWith (body, exn, exn_ty, handler) =>
-        def qbody = quoted_expr (body);
-        <[ PExpr.Try ($qbody, [
-             TryCase.Catch ($(quoted_sstring (exn)),
-                            $(quoted_expr (exn_ty)),
-                            $(quoted_expr (handler)))]) ]>
-
-      | PExpr.TryFinally (body, handler) =>
+      | <[ try $body finally $handler ]> =>
         assert (body != null);
         assert (handler != null);
         <[ PExpr.TryFinally ($(quoted_expr (body)),
                              $(quoted_expr (handler))) ]>
 
-      | PExpr.Try (body, cases) =>
+      | <[ try $body catch { ..$cases } ]> =>
         def quoted_case (case) {
           | TryCase.Catch (exn, exn_ty, handler) =>
             <[ TryCase.Catch ($(quoted_sstring (exn)),
@@ -957,9 +950,6 @@
             else
               <[ throw $(traverse (exc)) ]>
 
-          | PExpr.TryWith (body, exn, exn_ty, handler) =>
-            PExpr.Try (traverse (body), [TryCase.Catch (exn, exn_ty, traverse (handler))])
-
           | PExpr.TryFinally (body, handler) =>
             PExpr.TryFinally (traverse (body), traverse (handler))
 
@@ -1093,11 +1083,7 @@
               | _ => e
             }
 
-          | PExpr.TryWith (body, Splicable.Name (exn), exn_ty, handler) 
-            when exn.Equals (from) =>
-            PExpr.Try (body, [TryCase.Catch (Splicable.Name (to), exn_ty, handler)])
-
-          | PExpr.Try (body, cases) =>
+          | <[ try $body catch { ..$cases } ]> =>
             mutable changed = false;
             def walk_case (case) {
               | TryCase.Catch (Splicable.Name (exn), exn_ty, handler)

Modified: nemerle/trunk/ncc/typing/TypedTree.n
==============================================================================
--- nemerle/trunk/ncc/typing/TypedTree.n	(original)
+++ nemerle/trunk/ncc/typing/TypedTree.n	Sun Aug  6 18:36:19 2006
@@ -428,6 +428,7 @@
   [Record]
   public variant Try_case
   {
+    | Fault { handler : TExpr; }
     | Catch { exn : LocalValue; handler : TExpr; }
     | Filter { exn : LocalValue; filter : TExpr; handler : TExpr; }
   }
@@ -493,8 +494,6 @@
     | Assign                { target : TExpr; source : TExpr; }
     | DefValIn              { name : LocalValue; val : TExpr; mutable body : TExpr; }
     | Throw                 { exn : TExpr; }
-    | TryFault              { body : TExpr; handler : TExpr; }
-    | TryWith               { body : TExpr; exn : LocalValue; handler : TExpr; }
     | TryFinally            { body : TExpr; handler : TExpr; }
     | Try                   { body : TExpr; mutable cases : list [Try_case]; }
     | Literal               { val : Nemerle.Compiler.Literal; }
@@ -938,19 +937,12 @@
           } else
             null
 
-        | TryWith (body, exn, handler) =>
-          Try (walk (f, body), [Try_case.Catch (exn, walk (f, handler))])
-          
-          
         | TryFinally (body, handler) =>
           TryFinally (walk (f, body), walk (f, handler))
           
-
-        | TryFault (body, handler) =>
-          TryFault (walk (f, body), walk (f, handler))
-
         | Try (body, cases) =>
           def walk_case(case) {
+            | Try_case.Fault (handler) => Try_case.Fault (walk (f, handler))
             | Try_case.Catch (exn, handler) => Try_case.Catch (exn, walk (f, handler))
             | Try_case.Filter (exn, filter, handler) => Try_case.Filter (exn, walk (f, filter), walk (f, handler))
           }

Modified: nemerle/trunk/ncc/typing/Typer.n
==============================================================================
--- nemerle/trunk/ncc/typing/Typer.n	(original)
+++ nemerle/trunk/ncc/typing/Typer.n	Sun Aug  6 18:36:19 2006
@@ -1236,34 +1236,6 @@
           TypeIndexer (obj, args, expected)
 
 
-        | (PT.PExpr.TryWith) as x =>
-          def body = TypeExpr (x.body);
-          if (ExpectSubtyping (expected, body.Type, "try body"))
-            match (x.exn) {
-              | PT.Splicable.Name (exn) =>
-                def decl = DefineLocal (exn, BindType (x.exn_ty),
-                                        LocalValue.Kind.ExceptionValue (), false);
-                PushLocals ();
-                def handler = 
-                  try {
-                    AddLocal (exn, decl);
-                    TypeExpr (x.handler);
-                  } finally {
-                    PopLocals ();
-                  }
-
-                _ = ExpectSubtyping (expected, handler.Type, "catch body");
-                TExpr.Try (ImplicitCast (body, expected), [
-                  Try_case.Catch (decl,
-                                  ImplicitCast (handler, expected))])
-
-              | _ =>
-                ReportFatal (messenger, 
-                             "$ operator used outside quotation <[ ... ]> context")
-            }
-          else TExpr.Error ()
-
-
         | PT.PExpr.TryFinally (e1, e2) =>
           def body = TypeExpr (e1, expected);
           def tv = FreshTyVar ();
@@ -1312,11 +1284,10 @@
                               PopLocals ();
                             }
 
-                          def bool_tv = BindType (<[ bool ]>);
-                          _ = ExpectSubtyping (bool_tv, filter.Type, "catch filter");
+                          _ = ExpectSubtyping (InternalType.Boolean, filter.Type, "catch filter");
                           _ = ExpectSubtyping (expected, handler.Type, "catch body");
                           type_trycases (cases,
-                                         Try_case.Filter (decl, ImplicitCast (filter, bool_tv),
+                                         Try_case.Filter (decl, ImplicitCast (filter, InternalType.Boolean),
                                                                 ImplicitCast (handler, expected)) :: acc)
                         | _ => None ()
                       }
@@ -3380,7 +3351,6 @@
         | TExpr.If => "a `if' expression"
         | TExpr.HasType => "a `is' expression"
         | TExpr.Throw => "a throw expression"
-        | TExpr.TryWith => "a try...with expression"
         | TExpr.TryFinally => "a try...finally expression"
         | TExpr.Try => "a try expression"
         | TExpr.Literal => "a literal value"
@@ -3402,7 +3372,6 @@
             | _ => "a yet-untyped expression"
           }
 
-        | TExpr.TryFault
         | TExpr.Switch
         | TExpr.DefaultValue
         | TExpr.Goto

Modified: nemerle/trunk/ncc/typing/Typer2.n
==============================================================================
--- nemerle/trunk/ncc/typing/Typer2.n	(original)
+++ nemerle/trunk/ncc/typing/Typer2.n	Sun Aug  6 18:36:19 2006
@@ -1151,18 +1151,6 @@
           else
             expr
 
-        | TExpr.TryWith (body, exn, handler) =>
-          unless (ctx %&& Context.AllowTry)
-            ReportError (messenger, 
-                         "try block is not allowed inside expressions");
-          
-          exn.Register ();
-          current_fun.uses_try_block = true;
-
-          TExpr.Try (Walk (Context.AllowGotoAndSuch, body),
-                     [Try_case.Catch (exn,
-                                      Walk (Context.AllowGotoAndSuch, handler))])
-
         | TExpr.TryFinally (body, handler) =>
           unless (ctx %&& Context.AllowTry)
             ReportError (messenger, 
@@ -1181,6 +1169,7 @@
             | Try_case.Catch (exn, _)
             | Try_case.Filter (exn, _, _) =>
               exn.Register ();
+            | Try_case.Fault => ()
           }
           foreach (case in cases)
             register_case (case);
@@ -1192,6 +1181,8 @@
             | Try_case.Filter (exn, filter, handler) =>
               Try_case.Filter (exn, Walk (Context.AllowGotoAndSuch, filter),
                                Walk (Context.AllowGotoAndSuch, handler))
+            | Try_case.Fault (handler) =>
+              Try_case.Fault (Walk (Context.AllowGotoAndSuch, handler))
           }
           TExpr.Try (Walk (Context.AllowGotoAndSuch, body), cases.Map (walk_case))
 
@@ -1300,8 +1291,6 @@
         
         | TExpr.DefaultValue => null
 
-       
-        | TExpr.TryFault
         | TExpr.Switch
         | TExpr.MultipleAssign
         | TExpr.MethodAddress => assert (false)



More information about the svn mailing list