[svn] r6217: nemerle/trunk/ncc: parsing/MainParser.n testsuite/positive/imperative.n typing/Typer.n

nazgul svnadmin at nemerle.org
Wed May 3 13:12:50 CEST 2006


Log:
Allow mutable local variables without initializer

Author: nazgul
Date: Wed May  3 13:12:48 2006
New Revision: 6217

Modified:
   nemerle/trunk/ncc/parsing/MainParser.n
   nemerle/trunk/ncc/testsuite/positive/imperative.n
   nemerle/trunk/ncc/typing/Typer.n

Modified: nemerle/trunk/ncc/parsing/MainParser.n
==============================================================================
--- nemerle/trunk/ncc/parsing/MainParser.n	(original)
+++ nemerle/trunk/ncc/parsing/MainParser.n	Wed May  3 13:12:48 2006
@@ -1872,13 +1872,14 @@
 
             def loop () {
               def id = parse_expr (TokenStoppers.All);
-              match (get_token ()) {
+              ids ::= id;
+              match (peek_token ()) {
                 | Token.Operator ("=") =>
+                  shift ();
                   def val = parse_expr (stop);
-                  ids ::= id;
                   vals ::= val;
                 
-                | x => Message.Error (x.Location, "expected assignment operator =");
+                | _ => vals ::= null;
               }
               when (peek_token () is Token.Comma) {
                 shift ();
@@ -1888,7 +1889,7 @@
             loop ();
 
             match ((ids, vals)) {
-              | ([id], [val]) => PExpr.DefMutable (loc + val.loc, id, val)
+              | ([id], [val]) => PExpr.DefMutable (if (val != null) loc + val.loc else loc, id, val)
               | _ => PExpr.DefMutable (loc, PExpr.Tuple (loc, ids.Reverse ()),
                                        PExpr.Tuple (loc, vals.Reverse ()))
             }

Modified: nemerle/trunk/ncc/testsuite/positive/imperative.n
==============================================================================
--- nemerle/trunk/ncc/testsuite/positive/imperative.n	(original)
+++ nemerle/trunk/ncc/testsuite/positive/imperative.n	Wed May  3 13:12:48 2006
@@ -126,10 +126,23 @@
 assert (R.LL.xsum4 ([1,2,3,4,101,200]) == 12);
 assert (R.LL.xsum4 ([1,2,3,4,1010,200]) == 1010);
 
+mutable x;
+mutable z, y = 3, i : double;
+mutable w : string;
+
+x = 3;
+z = "ss";
+i = 1.2;
+i = 1.0;
+w = "aa";
+Nemerle.IO.print ("x=$x, z=$z, i=$i, y=$y, w=$w\n");
+
+
 /*
 BEGIN-OUTPUT
 a
 to_void False
 False
+x=3, z=ss, i=1, y=3, w=aa
 END-OUTPUT
 */

Modified: nemerle/trunk/ncc/typing/Typer.n
==============================================================================
--- nemerle/trunk/ncc/typing/Typer.n	(original)
+++ nemerle/trunk/ncc/typing/Typer.n	Wed May  3 13:12:48 2006
@@ -1070,6 +1070,9 @@
           ReportFatal (messenger, 
                        "ref and out parameters are only allowed in function calls")
 
+        | PT.PExpr.DefMutable (x, null) => 
+          DoType (PT.PExpr.DefMutable (x, <[ $(TExpr.DefaultValue (FreshTyVar ()) : typed) ]>), expected, is_toplevel_in_seq)
+                       
         | PT.PExpr.DefMutable (PT.PExpr.Ref (name), val)          
         | PT.PExpr.Define (PT.PExpr.Ref (name), val) =>
           def is_mutable = expression is PT.PExpr.DefMutable;
@@ -1092,19 +1095,26 @@
               unless (is_toplevel_in_seq)
                 PushLocals ();
 
+              def first_v = if (first_v == null) <[ $(TExpr.DefaultValue (FreshTyVar ()) : typed) ]> else first_v;
               def top = TypeLocalDefinition (true, first_n, first_v);
               
-              _ = List.FoldLeft2 (names, vals, top, fun (n, v, acc) {
+              def create_single (n, mutable v, acc) {
+                when (v == null) 
+                  v = <[ $(TExpr.DefaultValue (FreshTyVar ()) : typed) ]>;
                 match (n) {
                   | PT.PExpr.Ref (name) =>
                     def def_val_in = TypeLocalDefinition (true, name, v);
                     acc.body = def_val_in;
                     def_val_in
 
+                  | PT.PExpr.TypeEnforcement (nm, ty) =>
+                    create_single (nm, PT.PExpr.TypeEnforcement (v, ty), acc)
+                    
                   | _ =>
                     Message.FatalError (n.Location, "expected simple variable name in mutable definition")
                 }
-              });
+              }
+              _ = List.FoldLeft2 (names, vals, top, create_single);
               top
                 
             } finally {



More information about the svn mailing list