[pypy-svn] r9589 - in pypy/dist/pypy: objspace/flow translator

arigo at codespeak.net arigo at codespeak.net
Wed Mar 2 19:00:30 CET 2005


Author: arigo
Date: Wed Mar  2 19:00:30 2005
New Revision: 9589

Modified:
   pypy/dist/pypy/objspace/flow/framestate.py
   pypy/dist/pypy/objspace/flow/model.py
   pypy/dist/pypy/objspace/flow/objspace.py
   pypy/dist/pypy/translator/annrpython.py
   pypy/dist/pypy/translator/gencl.py
   pypy/dist/pypy/translator/genpyrex.py
Log:
Cleaned up the UndefinedConstant subclass of Constant.  Replaced it with 
Constant(undefined_value).  This is a follow-up on the removal of UNDEFINED in 
the interpreter.


Modified: pypy/dist/pypy/objspace/flow/framestate.py
==============================================================================
--- pypy/dist/pypy/objspace/flow/framestate.py	(original)
+++ pypy/dist/pypy/objspace/flow/framestate.py	Wed Mar  2 19:00:30 2005
@@ -10,7 +10,7 @@
             data = []
             for w in state.getfastscope():
                 if w is None:
-                    data.append(UNDEFINED)
+                    data.append(Constant(undefined_value))
                 else:
                     data.append(w)
             data.extend(state.valuestack.items)
@@ -43,7 +43,7 @@
             recursively_unflatten(frame.space, data)
             fastscope = []
             for w in data[:fastlocals]:
-                if w is UNDEFINED:
+                if isinstance(w, Constant) and w.value is undefined_value:
                     fastscope.append(None)
                 else:
                     fastscope.append(w)

Modified: pypy/dist/pypy/objspace/flow/model.py
==============================================================================
--- pypy/dist/pypy/objspace/flow/model.py	(original)
+++ pypy/dist/pypy/objspace/flow/model.py	Wed Mar  2 19:00:30 2005
@@ -201,15 +201,6 @@
             flags = ''
         return '(%s%s)' % (r, flags)
 
-class UndefinedConstant(Constant):
-    def __init__(self):
-        Constant.__init__(self,object())
-    
-    def __repr__(self):
-        return '(*undefined*)'
-    
-UNDEFINED = UndefinedConstant()
-
 class SpaceOperation:
     def __init__(self, opname, args, result):
         self.opname = opname      # operation name
@@ -232,14 +223,14 @@
     def __repr__(self):
         return "%r = %s(%s)" % (self.result, self.opname, ", ".join(map(repr, self.args)))
 
-class Atom:
-    "NOT_RPYTHON"
+class Atom(object):
     def __init__(self, name):
         self.name = name
     def __repr__(self):
         return self.name
 last_exception = Atom('last_exception')
 last_exc_value = Atom('last_exc_value')
+undefined_value= Atom('*undefined*')
 # if Block().exitswitch == Constant(last_exception), it means that we are
 # interested in catching the exception that the *last operation* of the
 # block could raise.  The exitcases of the links are None for no exception

Modified: pypy/dist/pypy/objspace/flow/objspace.py
==============================================================================
--- pypy/dist/pypy/objspace/flow/objspace.py	(original)
+++ pypy/dist/pypy/objspace/flow/objspace.py	Wed Mar  2 19:00:30 2005
@@ -108,7 +108,7 @@
         return self.do_operation('newslice', w_start, w_stop, w_step)
 
     def wrap(self, obj):
-        if isinstance(obj, (Variable, Constant)) and obj is not UNDEFINED:
+        if isinstance(obj, (Variable, Constant)):
             raise TypeError("already wrapped: " + repr(obj))
         # method-wrapper have ill-defined comparison and introspection
         # to appear in a flow graph

Modified: pypy/dist/pypy/translator/annrpython.py
==============================================================================
--- pypy/dist/pypy/translator/annrpython.py	(original)
+++ pypy/dist/pypy/translator/annrpython.py	Wed Mar  2 19:00:30 2005
@@ -6,7 +6,7 @@
 from pypy.annotation.model import pair
 from pypy.annotation.factory import ListFactory, DictFactory, BlockedInference
 from pypy.annotation.bookkeeper import Bookkeeper
-from pypy.objspace.flow.model import Variable, Constant, UndefinedConstant
+from pypy.objspace.flow.model import Variable, Constant, undefined_value
 from pypy.objspace.flow.model import SpaceOperation, FunctionGraph
 from pypy.objspace.flow.model import last_exception, last_exc_value
 
@@ -165,9 +165,9 @@
                     return None
                 else:
                     raise
-        elif isinstance(arg, UndefinedConstant):  # undefined local variables
-            return annmodel.SomeImpossibleValue()
         elif isinstance(arg, Constant):
+            if arg.value is undefined_value:   # undefined local variables
+                return annmodel.SomeImpossibleValue()
             assert not arg.value is last_exception and not arg.value is last_exc_value
             return self.bookkeeper.immutablevalue(arg.value)
         else:

Modified: pypy/dist/pypy/translator/gencl.py
==============================================================================
--- pypy/dist/pypy/translator/gencl.py	(original)
+++ pypy/dist/pypy/translator/gencl.py	Wed Mar  2 19:00:30 2005
@@ -298,7 +298,7 @@
         target = link.target.inputargs
         print "(psetq", # parallel assignment
         for s, t in zip(source, target):
-            if s != t and not isinstance(s, UndefinedConstant):
+            if s != t and s != Constant(undefined_value):
                 print self.str(t), self.str(s),
         print ")"
         self.emit_jump(link.target)

Modified: pypy/dist/pypy/translator/genpyrex.py
==============================================================================
--- pypy/dist/pypy/translator/genpyrex.py	(original)
+++ pypy/dist/pypy/translator/genpyrex.py	Wed Mar  2 19:00:30 2005
@@ -4,7 +4,7 @@
 """
 from pypy.interpreter.baseobjspace import ObjSpace
 from pypy.interpreter.argument import Arguments
-from pypy.objspace.flow.model import Variable, Constant, UndefinedConstant
+from pypy.objspace.flow.model import Variable, Constant, undefined_value
 from pypy.objspace.flow.model import mkentrymap, last_exception
 from pypy.translator.annrpython import RPythonAnnotator
 from pypy.annotation.model import SomePBC
@@ -403,10 +403,10 @@
         sourceargs = link.args
         targetargs = block.inputargs
         assert len(sourceargs) == len(targetargs)
-        # get rid of identity-assignments and assignments of UndefinedConstant
+        # get rid of identity-assignments and assignments of undefined_value
         sargs, targs = [], []
         for s,t in zip(sourceargs, targetargs):
-            if s != t and not isinstance(s, UndefinedConstant):
+            if s != t and s != Constant(undefined_value):
                 sargs.append(s)
                 targs.append(t)
         if sargs:



More information about the Pypy-commit mailing list