Permalink
Browse files
Modernize OPy: misc.Set() -> set().
- Loading branch information...
Showing
with
7 additions
and
41 deletions.
-
+0
−35
opy/compiler2/misc.py
-
+2
−2
opy/compiler2/pyassem.py
-
+5
−4
opy/compiler2/pycodegen.py
|
|
@@ -8,41 +8,6 @@ def flatten(tup): |
|
|
elts.append(elt)
|
|
|
return elts
|
|
|
|
|
|
class Set:
|
|
|
def __init__(self):
|
|
|
self.elts = {}
|
|
|
def __len__(self):
|
|
|
return len(self.elts)
|
|
|
def __contains__(self, elt):
|
|
|
return elt in self.elts
|
|
|
def add(self, elt):
|
|
|
self.elts[elt] = elt
|
|
|
|
|
|
def elements(self):
|
|
|
# BUG FIX: bytecode is NON-DETERMINISTIC without this.
|
|
|
#
|
|
|
# This fixes ./smoke.sh opy-determinism-loop. It runs for 100
|
|
|
# iterations successfully with this fix. It always fails within 100
|
|
|
# without this fix.
|
|
|
|
|
|
# I thought that Python 2.7's dictionary order was arbitrary but
|
|
|
# deterministic. PYTHONHASHSEED=random is opt-in; the default should
|
|
|
# be PYTHONHASHSEED=0.
|
|
|
|
|
|
# TODO: What happens if we get rid of Set() and use the builtin set()?
|
|
|
|
|
|
#return self.elts.keys()
|
|
|
return sorted(self.elts.iterkeys())
|
|
|
|
|
|
def has_elt(self, elt):
|
|
|
return elt in self.elts
|
|
|
def remove(self, elt):
|
|
|
del self.elts[elt]
|
|
|
def copy(self):
|
|
|
c = Set()
|
|
|
c.elts.update(self.elts)
|
|
|
return c
|
|
|
|
|
|
class Stack:
|
|
|
def __init__(self):
|
|
|
self.stack = []
|
|
|
|
|
|
@@ -12,7 +12,7 @@ class FlowGraph: |
|
|
def __init__(self):
|
|
|
self.current = self.entry = Block()
|
|
|
self.exit = Block("exit")
|
|
|
self.blocks = misc.Set()
|
|
|
self.blocks = set()
|
|
|
self.blocks.add(self.entry)
|
|
|
self.blocks.add(self.exit)
|
|
|
|
|
|
@@ -82,7 +82,7 @@ def getBlocksInOrder(self): |
|
|
return order
|
|
|
|
|
|
def getBlocks(self):
|
|
|
return self.blocks.elements()
|
|
|
return self.blocks
|
|
|
|
|
|
def getRoot(self):
|
|
|
"""Return nodes appropriate for use with dominator"""
|
|
|
|
|
|
@@ -125,16 +125,17 @@ def compile(self, display=0, transformer=None): |
|
|
class LocalNameFinder:
|
|
|
"""Find local names in scope"""
|
|
|
def __init__(self, names=()):
|
|
|
self.names = misc.Set()
|
|
|
self.globals = misc.Set()
|
|
|
self.names = set()
|
|
|
self.globals = set()
|
|
|
for name in names:
|
|
|
self.names.add(name)
|
|
|
|
|
|
# XXX list comprehensions and for loops
|
|
|
|
|
|
def getLocals(self):
|
|
|
for elt in self.globals.elements():
|
|
|
if self.names.has_elt(elt):
|
|
|
# TODO: set difference
|
|
|
for elt in self.globals:
|
|
|
if elt in self.names:
|
|
|
self.names.remove(elt)
|
|
|
return self.names
|
|
|
|
|
|
|
0 comments on commit
173ea98