[svn] r6505: nemerle/trunk: macros/Util.n ncc/testsuite/positive/list-compr.n

nazgul svnadmin at nemerle.org
Thu Aug 10 22:53:19 CEST 2006


Log:
Fix list comprehensions for various corner cases - a hard brainstorm together with Snaury

Author: nazgul
Date: Thu Aug 10 22:53:14 2006
New Revision: 6505

Modified:
   nemerle/trunk/macros/Util.n
   nemerle/trunk/ncc/testsuite/positive/list-compr.n

Modified: nemerle/trunk/macros/Util.n
==============================================================================
--- nemerle/trunk/macros/Util.n	(original)
+++ nemerle/trunk/macros/Util.n	Thu Aug 10 22:53:14 2006
@@ -288,11 +288,21 @@
         | <[ $pat in [$first, $second .. $last] ]> =>
           Some (<[
              mutable i = $first;
-             def delta = $second - i;
+             mutable delta = $second - i;
              def last = $last;
-             while (if (delta < 0) i >= last else i <= last) {
+             mutable cond = if (delta < 0) i >= last else i <= last;             
+             def pre_last = unchecked (last - delta);
+             
+             when (delta < 0 && pre_last < last || delta > 0 && pre_last > last) // we overflowed
+               delta = -delta;
+               
+             while (cond) {
                def $pat = i;
-               i += delta;
+               if (delta < 0) 
+                 cond = i >= pre_last;
+               else 
+                 cond = i <= pre_last;
+               unchecked (i += delta);
                $acc;
              }
           ]>)
@@ -302,9 +312,11 @@
           Some (<[
              mutable i = $first;
              def last = $last;
-             while (i <= last) {
+             mutable cond = i <= last;
+             while (cond) {
                def $pat = i;
-               i++;               
+               cond = i < last;
+               unchecked (i++);               
                $acc;
              }
           ]>)

Modified: nemerle/trunk/ncc/testsuite/positive/list-compr.n
==============================================================================
--- nemerle/trunk/ncc/testsuite/positive/list-compr.n	(original)
+++ nemerle/trunk/ncc/testsuite/positive/list-compr.n	Thu Aug 10 22:53:14 2006
@@ -44,6 +44,18 @@
   System.Console.WriteLine(i);
   when (i == 14) Nemerle.Imperative.Break ();
 }
+System.Console.WriteLine ("--");
+foreach (i in $[int.MaxValue .. int.MaxValue])
+  System.Console.WriteLine (i);
+System.Console.WriteLine ("--");  
+foreach (i in $[int.MaxValue-2,int.MaxValue-1  .. int.MaxValue])
+  System.Console.WriteLine (i);  
+System.Console.WriteLine ("--");    
+foreach (i in $[int.MaxValue-3,int.MaxValue-1  .. int.MaxValue])
+  System.Console.WriteLine (i);   
+System.Console.WriteLine ("--");
+foreach (i in $[int.MinValue,int.MinValue+1  .. int.MinValue])
+  System.Console.WriteLine (i);   
 
 /*
 BEGIN-OUTPUT
@@ -93,5 +105,16 @@
 8
 10
 14
+--
+2147483647
+--
+2147483645
+2147483646
+2147483647
+--
+2147483644
+2147483646
+--
+-2147483648
 END-OUTPUT
 */



More information about the svn mailing list