[pypy-commit] pypy translation-cleanup: Flowspacify LOAD_GLOBAL

rlamy noreply at buildbot.pypy.org
Thu Aug 30 18:38:38 CEST 2012


Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: translation-cleanup
Changeset: r57016:967a74f0f99a
Date: 2012-08-24 04:44 +0100
http://bitbucket.org/pypy/pypy/changeset/967a74f0f99a/

Log:	Flowspacify LOAD_GLOBAL

diff --git a/pypy/objspace/flow/flowcontext.py b/pypy/objspace/flow/flowcontext.py
--- a/pypy/objspace/flow/flowcontext.py
+++ b/pypy/objspace/flow/flowcontext.py
@@ -545,6 +545,10 @@
         self.lastblock = block
         self.pushvalue(w_result)
 
+    def LOAD_GLOBAL(self, nameindex, next_instr):
+        w_result = self.space.find_global(self.w_globals, self.getname_u(nameindex))
+        self.pushvalue(w_result)
+
     def BUILD_LIST_FROM_ARG(self, _, next_instr):
         # This opcode was added with pypy-1.8.  Here is a simpler
         # version, enough for annotation.
diff --git a/pypy/objspace/flow/objspace.py b/pypy/objspace/flow/objspace.py
--- a/pypy/objspace/flow/objspace.py
+++ b/pypy/objspace/flow/objspace.py
@@ -483,6 +483,16 @@
                 #pass
              raise operation.ImplicitOperationError(w_exc_cls, w_exc_value)
 
+    def find_global(self, w_globals, varname):
+        w_value = self.finditem_str(w_globals, varname)
+        if w_value is None:
+            # not in the globals, now look in the built-ins
+            w_value = self.builtin.getdictvalue(self, varname)
+            if w_value is None:
+                message = "global name '%s' is not defined" % varname
+                raise OperationError(self.w_NameError, self.wrap(message))
+        return w_value
+
     def w_KeyboardInterrupt(self):
         # the reason to do this is: if you interrupt the flowing of a function
         # with <Ctrl-C> the bytecode interpreter will raise an applevel


More information about the pypy-commit mailing list