Changeset 5326:c2604b2d5f08 in livinglogic.python.xist
 Timestamp:
 02/08/13 20:07:01 (6 years ago)
 Author:
 Walter Doerwald <walter@…>
 Branch:
 default
 Message:

Reintroduce constant folding.
 Location:
 src/ll
 Files:

Legend:
 Unmodified
 Added
 Removed

r5313

r5326


421  421  $node = $e.node; 
422  422  for i in range(count): 
423   $node = ul4c.Neg($node); 
 423  $node = ul4c.Neg.make($node); 
424  424  } 
425  425  ; 
… 
… 

439  439  '%' { cls = ul4c.Mod; } 
440  440  ) 
441   e2=expr8 { $node = cls($node, $e2.node) } 
 441  e2=expr8 { $node = cls.make($node, $e2.node) } 
442  442  )* 
443  443  ; 
… 
… 

453  453  '' { cls = ul4c.Sub; } 
454  454  ) 
455   e2=expr7 { $node = cls($node, $e2.node) } 
 455  e2=expr7 { $node = cls.make($node, $e2.node) } 
456  456  )* 
457  457  ; 
… 
… 

475  475  '>=' { cls = ul4c.GE; } 
476  476  ) 
477   e2=expr6 { $node = cls($node, $e2.node) } 
 477  e2=expr6 { $node = cls.make($node, $e2.node) } 
478  478  )* 
479  479  ; 
… 
… 

489  489  )? 
490  490  'in' 
491   e2=expr5 { $node = cls($node, $e2.node) } 
 491  e2=expr5 { $node = cls.make($node, $e2.node) } 
492  492  )? 
493  493  ; 
… 
… 

497  497  : 
498  498  'not' 
499   e=expr4 { $node = ul4c.Not($e.node) } 
 499  e=expr4 { $node = ul4c.Not.make($e.node) } 
500  500   
501  501  e=expr4 { $node = $e.node; } 

r5313

r5326


1   # $ANTLR 3.4 src/ll/UL4.g 20130206 18:06:39 
 1  # $ANTLR 3.4 src/ll/UL4.g 20130208 19:57:09 
2  2  
3  3  import sys 

r5313

r5326


1   # $ANTLR 3.4 src/ll/UL4.g 20130206 18:06:38 
 1  # $ANTLR 3.4 src/ll/UL4.g 20130208 19:57:08 
2  2  
3  3  import sys 
… 
… 

2443  2443  node = e 
2444  2444  for i in range(count): 
2445   node = ul4c.Neg(node) 
 2445  node = ul4c.Neg.make(node) 
2446  2446  
2447  2447  
… 
… 

2580  2580  if self._state.backtracking == 0: 
2581  2581  pass 
2582   node = cls(node, e2) 
 2582  node = cls.make(node, e2) 
2583  2583  
2584  2584  
… 
… 

2694  2694  if self._state.backtracking == 0: 
2695  2695  pass 
2696   node = cls(node, e2) 
 2696  node = cls.make(node, e2) 
2697  2697  
2698  2698  
… 
… 

2863  2863  if self._state.backtracking == 0: 
2864  2864  pass 
2865   node = cls(node, e2) 
 2865  node = cls.make(node, e2) 
2866  2866  
2867  2867  
… 
… 

2958  2958  if self._state.backtracking == 0: 
2959  2959  pass 
2960   node = cls(node, e2) 
 2960  node = cls.make(node, e2) 
2961  2961  
2962  2962  
… 
… 

3021  3021  if self._state.backtracking == 0: 
3022  3022  pass 
3023   node = ul4c.Not(e) 
 3023  node = ul4c.Not.make(e) 
3024  3024  
3025  3025  

r5322

r5326


1234  1234  self.obj = decoder.load() 
1235  1235  
 1236  def eval(self, keepws, vars): 
 1237  obj = (yield from self.obj.eval(keepws, vars)) 
 1238  return self.evalfold(obj) 
 1239  
 1240  @classmethod 
 1241  def make(cls, obj): 
 1242  if isinstance(obj, Const): 
 1243  result = cls.evalfold(obj.value) 
 1244  if not isinstance(result, Undefined): 
 1245  return Const(result) 
 1246  return cls(obj) 
 1247  
1236  1248  
1237  1249  @register("not") 
… 
… 

1247  1259  yield from self._formatop(self.obj) 
1248  1260  
1249   def eval(self, keepws, vars): 
1250   return not (yield from self.obj.eval(keepws, vars)) 
 1261  @classmethod 
 1262  def evalfold(cls, obj): 
 1263  return not obj 
1251  1264  
1252  1265  
… 
… 

1263  1276  yield from self._formatop(self.obj) 
1264  1277  
1265   def eval(self, keepws, vars): 
1266   return (yield from self.obj.eval(keepws, vars)) 
 1278  @classmethod 
 1279  def evalfold(cls, obj): 
 1280  return obj 
1267  1281  
1268  1282  
… 
… 

1379  1393  self.obj2 = decoder.load() 
1380  1394  
 1395  def eval(self, keepws, vars): 
 1396  obj1 = (yield from self.obj1.eval(keepws, vars)) 
 1397  obj2 = (yield from self.obj2.eval(keepws, vars)) 
 1398  return self.evalfold(obj1, obj2) 
 1399  
 1400  @classmethod 
 1401  def make(cls, obj1, obj2): 
 1402  if isinstance(obj1, Const) and isinstance(obj2, Const): 
 1403  result = cls.evalfold(obj1.value, obj2.value) 
 1404  if not isinstance(result, Undefined): 
 1405  return Const(result) 
 1406  return cls(obj1, obj2) 
 1407  
1381  1408  
1382  1409  @register("getitem") 
… 
… 

1402  1429  yield "]" 
1403  1430  
1404   def eval(self, keepws, vars): 
1405   obj1 = (yield from self.obj1.eval(keepws, vars)) 
1406   obj2 = (yield from self.obj2.eval(keepws, vars)) 
 1431  @classmethod 
 1432  def evalfold(cls, obj1, obj2): 
1407  1433  try: 
1408  1434  return obj1[obj2] 
… 
… 

1427  1453  yield from self._formatop(self.obj2) 
1428  1454  
1429   def eval(self, keepws, vars): 
1430   obj1 = (yield from self.obj1.eval(keepws, vars)) 
1431   obj2 = (yield from self.obj2.eval(keepws, vars)) 
 1455  @classmethod 
 1456  def evalfold(cls, obj1, obj2): 
1432  1457  return obj1 == obj2 
1433  1458  
… 
… 

1447  1472  yield from self._formatop(self.obj2) 
1448  1473  
1449   def eval(self, keepws, vars): 
1450   obj1 = (yield from self.obj1.eval(keepws, vars)) 
1451   obj2 = (yield from self.obj2.eval(keepws, vars)) 
 1474  @classmethod 
 1475  def evalfold(cls, obj1, obj2): 
1452  1476  return obj1 != obj2 
1453  1477  
… 
… 

1467  1491  yield from self._formatop(self.obj2) 
1468  1492  
1469   def eval(self, keepws, vars): 
1470   obj1 = (yield from self.obj1.eval(keepws, vars)) 
1471   obj2 = (yield from self.obj2.eval(keepws, vars)) 
 1493  @classmethod 
 1494  def evalfold(cls, obj1, obj2): 
1472  1495  return obj1 < obj2 
1473  1496  
… 
… 

1487  1510  yield from self._formatop(self.obj2) 
1488  1511  
1489   def eval(self, keepws, vars): 
1490   obj1 = (yield from self.obj1.eval(keepws, vars)) 
1491   obj2 = (yield from self.obj2.eval(keepws, vars)) 
 1512  @classmethod 
 1513  def evalfold(cls, obj1, obj2): 
1492  1514  return obj1 <= obj2 
1493  1515  
… 
… 

1507  1529  yield from self._formatop(self.obj2) 
1508  1530  
1509   def eval(self, keepws, vars): 
1510   obj1 = (yield from self.obj1.eval(keepws, vars)) 
1511   obj2 = (yield from self.obj2.eval(keepws, vars)) 
 1531  @classmethod 
 1532  def evalfold(cls, obj1, obj2): 
1512  1533  return obj1 > obj2 
1513  1534  
… 
… 

1527  1548  yield from self._formatop(self.obj2) 
1528  1549  
1529   def eval(self, keepws, vars): 
1530   obj1 = (yield from self.obj1.eval(keepws, vars)) 
1531   obj2 = (yield from self.obj2.eval(keepws, vars)) 
 1550  @classmethod 
 1551  def evalfold(cls, obj1, obj2): 
1532  1552  return obj1 >= obj2 
1533  1553  
… 
… 

1551  1571  yield from self._formatop(self.obj2) 
1552  1572  
1553   def eval(self, keepws, vars): 
1554   obj1 = (yield from self.obj1.eval(keepws, vars)) 
1555   obj2 = (yield from self.obj2.eval(keepws, vars)) 
 1573  @classmethod 
 1574  def evalfold(cls, obj1, obj2): 
1556  1575  return obj1 in obj2 
1557  1576  
… 
… 

1575  1594  yield from self._formatop(self.obj2) 
1576  1595  
1577   def eval(self, keepws, vars): 
1578   obj1 = (yield from self.obj1.eval(keepws, vars)) 
1579   obj2 = (yield from self.obj2.eval(keepws, vars)) 
 1596  @classmethod 
 1597  def evalfold(cls, obj1, obj2): 
1580  1598  return obj1 not in obj2 
1581  1599  
… 
… 

1594  1612  yield from self._formatop(self.obj2) 
1595  1613  
1596   def eval(self, keepws, vars): 
1597   obj1 = (yield from self.obj1.eval(keepws, vars)) 
1598   obj2 = (yield from self.obj2.eval(keepws, vars)) 
 1614  @classmethod 
 1615  def evalfold(cls, obj1, obj2): 
1599  1616  return obj1 + obj2 
1600  1617  
… 
… 

1614  1631  yield from self._formatop(self.obj2) 
1615  1632  
1616   def eval(self, keepws, vars): 
1617   obj1 = (yield from self.obj1.eval(keepws, vars)) 
1618   obj2 = (yield from self.obj2.eval(keepws, vars)) 
 1633  @classmethod 
 1634  def evalfold(cls, obj1, obj2): 
1619  1635  return obj1  obj2 
1620  1636  
… 
… 

1633  1649  yield from self._formatop(self.obj2) 
1634  1650  
1635   def eval(self, keepws, vars): 
1636   obj1 = (yield from self.obj1.eval(keepws, vars)) 
1637   obj2 = (yield from self.obj2.eval(keepws, vars)) 
 1651  @classmethod 
 1652  def evalfold(cls, obj1, obj2): 
1638  1653  return obj1 * obj2 
1639  1654  
… 
… 

1653  1668  yield from self._formatop(self.obj2) 
1654  1669  
1655   def eval(self, keepws, vars): 
1656   obj1 = (yield from self.obj1.eval(keepws, vars)) 
1657   obj2 = (yield from self.obj2.eval(keepws, vars)) 
 1670  @classmethod 
 1671  def evalfold(cls, obj1, obj2): 
1658  1672  return obj1 // obj2 
1659  1673  
… 
… 

1673  1687  yield from self._formatop(self.obj2) 
1674  1688  
1675   def eval(self, keepws, vars): 
1676   obj1 = (yield from self.obj1.eval(keepws, vars)) 
1677   obj2 = (yield from self.obj2.eval(keepws, vars)) 
 1689  @classmethod 
 1690  def evalfold(cls, obj1, obj2): 
1678  1691  return obj1 / obj2 
1679  1692  
… 
… 

1691  1704  yield " and " 
1692  1705  yield from self._formatop(self.obj2) 
 1706  
 1707  @classmethod 
 1708  def evalfold(cls, obj1, obj2): 
 1709  return obj1 and obj2 
1693  1710  
1694  1711  def eval(self, keepws, vars): 
… 
… 

1713  1730  yield from self._formatop(self.obj2) 
1714  1731  
 1732  @classmethod 
 1733  def evalfold(cls, obj1, obj2): 
 1734  return obj1 or obj2 
 1735  
1715  1736  def eval(self, keepws, vars): 
1716  1737  obj1 = (yield from self.obj1.eval(keepws, vars)) 
… 
… 

1734  1755  yield from self._formatop(self.obj2) 
1735  1756  
1736   def eval(self, keepws, vars): 
1737   obj1 = (yield from self.obj1.eval(keepws, vars)) 
1738   obj2 = (yield from self.obj2.eval(keepws, vars)) 
 1757  @classmethod 
 1758  def evalfold(cls, obj1, obj2): 
1739  1759  return obj1 % obj2 
1740  1760  