Commits

Carl Friedrich Bolz committed bdf98ed Merge

merge

Comments (0)

Files changed (2)

prolog/interpreter/parsing.py

         ("NUMBER", parse_regex("(0|[1-9][0-9]*)")),
         ("FLOAT", parse_regex("(0|[1-9][0-9]*)(\.[0-9]+)")),
         ("IGNORE", parse_regex(
-            "[ \\n\\t]|(/\\*[^\\*]*(\\*[^/][^\\*]*)*\\*/)|(%[^\\n]*)")),
+            "[ \\n\\t\\r]|(/\\*[^\\*]*(\\*[^/][^\\*]*)*\\*/)|(%[^\\n]*)")),
         ("ATOM", parse_regex("([a-z]([a-zA-Z0-9]|_)*)|('[^']*')|\[\]|!|\+|\-|\{\}")),
         ("STRING", parse_regex('"[^"]*"')),
         ("(", parse_regex("\(")),
                 state = 1
             elif char == '\n':
                 state = 1
+            elif char == '\r':
+                state = 1
             elif char == ' ':
                 state = 1
             elif char == '(':
             except IndexError:
                 runner.state = 17
                 return i
-            if char == '=':
+            if char == '-':
                 state = 78
-            elif char == '-':
+            elif char == '=':
                 state = 79
             else:
                 break
 lexer = DummyLexer(recognize, DFA(98,
  {(0, '\t'): 1,
   (0, '\n'): 1,
+  (0, '\r'): 1,
   (0, ' '): 1,
   (0, '!'): 29,
   (0, '"'): 20,
   (15, '*'): 80,
   (15, '/'): 82,
   (15, '\\'): 81,
-  (17, '-'): 79,
-  (17, '='): 78,
+  (17, '-'): 78,
+  (17, '='): 79,
   (18, ']'): 29,
   (19, '}'): 29,
   (20, '\x00'): 20,
       94,
       95,
       97]),
- ['0, 0, 0, 0, start|, 0, start|, 0, 0, 0, 0, 0, start|, 0, 0, 0, 0, 0, start|, 0, 0, 0, 0, 0, start|, 0, start|, 0, 0, start|, 0, 0, 0, 0, 0, 0, 0, start|, 0, start|, start|, 0, 0, start|, 0, start|, start|, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0',
+ ['0, 0, 0, 0, start|, 0, start|, 0, 0, 0, 0, 0, start|, 0, 0, 0, 0, 0, start|, 0, 0, 0, 0, 0, start|, 0, start|, 0, start|, 0, 0, start|, 0, 0, 0, 0, 0, 0, 0, start|, 0, start|, start|, 0, 0, start|, 0, start|, start|, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0',
   'IGNORE',
   '(',
   'ATOM',
   'STRING',
   'ATOM',
   'ATOM',
-  'final*, start*, 2, final*, 0, start|, 0, 0, final*, start*, final*, 0, final*, start*, 0, final*, 0, final|, start|, 0, 1, final*, start*, final*, 0, final*, start*, 0, final*, 0, 1, final|, start|, 0, final*, start*, final*, 0, 1, final*, 0, start|, 0, final*, start*, final*, start*, 0, final*, 0, final*, final|, final*, 0, start|, 0, final*, start*, final*, start*, 0, final*, 0, final*, 1, final|, final*, 0, final|, start|, 0, 1, final*, start*, final*, start*, 0, final*, 0, final*, 0, 1, final|, start|, 0, final*, start*, final*, start*, 0, final*, 0',
+  '0, final*, start*, 2, final*, 0, start|, 0, final*, start*, final*, 0, final*, start*, 0, final*, 0, final|, start|, 0, 1, final*, start*, final*, 0, final*, start*, 0, final*, 0, 1, final|, start|, 0, final*, start*, final*, 0, final|, 1, final*, 0, start|, 0, final*, start*, final*, start*, 0, final*, 0, final*, 1, final|, final*, 0, start|, 0, final*, start*, final*, start*, 0, final*, 0, final*, final*, 0, final|, start|, 0, 1, final*, start*, final*, start*, 0, final*, 0, final*, 0, 1, final|, start|, 0, final*, start*, final*, start*, 0, final*, 0',
   'ATOM',
   'ATOM',
-  '0, final*, 1, 0, 1, 0, start|',
+  '0, start|, 0, final*, 1, 0, 1',
   'ATOM',
   'ATOM',
   'ATOM',

prolog/interpreter/test/test_arithmetic.py

 
 from pypy.rlib.rbigint import rbigint
 
+def is_64_bit():
+    return sys.maxint > 2147483647
+
 class TestArithmeticMethod(object):
     def test_add(self):
         f1 = Float(5.1)
         assert Number(5).arith_pow(Number(2)).num == 25
         assert Float(2.3).arith_pow(Float(3.1)).floatval == 13.223800591254721
         assert BigInt(rbigint.fromdecimalstr('1000000')).arith_pow(Number(4)).value.str() == '1000000000000000000000000'
-        assert BigInt(rbigint.fromdecimalstr('10')).arith_pow(BigInt(rbigint.fromdecimalstr('10'))).value.str() == '10000000000'
-        assert Number(10).arith_pow(BigInt(rbigint.fromdecimalstr('10'))).value.str() == '10000000000'
         assert Float(10.0).arith_pow(BigInt(rbigint.fromdecimalstr('10'))).floatval == 10000000000.0
         assert BigInt(rbigint.fromdecimalstr('10')).arith_pow(Float(10.0)).floatval == 10000000000.0
 
     def test_and(self):
         assert Number(8).arith_and(Number(2)).num == 0
         assert BigInt(rbigint.fromint(46546)).arith_and(Number(34)).num == 2
-        assert BigInt(rbigint.fromdecimalstr('34876573845637845')).arith_and(BigInt(rbigint.fromdecimalstr('845763478537534095'))).value.str() == '15973735027198597'
         assert Number(46546).arith_and(BigInt(rbigint.fromint(34))).num == 2
 
     def test_xor(self):
         assert Number(8).arith_xor(Number(2)).num == 10
         assert BigInt(rbigint.fromint(46546)).arith_xor(Number(34)).num == 46576
-        assert BigInt(rbigint.fromdecimalstr('34876573845637845')).arith_xor(BigInt(rbigint.fromdecimalstr('845763478537534095'))).value.str() == '848692582328774746'
         assert Number(46546).arith_xor(BigInt(rbigint.fromint(34))).num == 46576
 
     def test_mod(self):
         assert Number(8).arith_mod(Number(2)).num == 0
         assert BigInt(rbigint.fromint(46546)).arith_mod(Number(33)).num == 16
-        assert BigInt(rbigint.fromdecimalstr('348765738456378457436537854637845')).arith_mod(BigInt(rbigint.fromdecimalstr('845763478537534095'))).value.str() == '738607793931799615'
         assert Number(46546).arith_mod(BigInt(rbigint.fromint(33))).num == 16
 
         py.test.raises(ZeroDivisionError, 'BigInt(rbigint.fromdecimalstr("12342424234")).arith_mod(BigInt(rbigint.fromint(0)))')
         assert Float(7.4).arith_float_fractional_part().floatval == 7.4 - 7
         assert Float(7.4).arith_float_integer_part().num == 7.0
 
+    def test_data_types_32_bit(self):
+        if is_64_bit():
+            py.test.skip("only test on 32 bit")
+        assert BigInt(rbigint.fromdecimalstr('348765738456378457436537854637845')).arith_mod(BigInt(rbigint.fromdecimalstr('845763478537534095'))).value.str() == '738607793931799615'
+        assert BigInt(rbigint.fromdecimalstr('10')).arith_pow(BigInt(rbigint.fromdecimalstr('10'))).value.str() == '10000000000'
+        assert BigInt(rbigint.fromdecimalstr('34876573845637845')).arith_xor(BigInt(rbigint.fromdecimalstr('845763478537534095'))).value.str() == '848692582328774746'
+        assert BigInt(rbigint.fromdecimalstr('34876573845637845')).arith_and(BigInt(rbigint.fromdecimalstr('845763478537534095'))).value.str() == '15973735027198597'
 
 def test_simple():
     assert_true("X is 1 + 2, X = 3.")