[pypy-commit] pypy ec-keepalive: Add objectmodel.fetch_translated_config()

arigo pypy.commits at gmail.com
Mon Jan 4 04:33:09 EST 2016


Author: Armin Rigo <arigo at tunes.org>
Branch: ec-keepalive
Changeset: r81538:8aa4fa415f00
Date: 2016-01-04 09:41 +0100
http://bitbucket.org/pypy/pypy/changeset/8aa4fa415f00/

Log:	Add objectmodel.fetch_translated_config()

diff --git a/rpython/rlib/objectmodel.py b/rpython/rlib/objectmodel.py
--- a/rpython/rlib/objectmodel.py
+++ b/rpython/rlib/objectmodel.py
@@ -335,6 +335,25 @@
     # XXX this can be made more efficient in the future
     return bytearray(str(i))
 
+def fetch_translated_config():
+    """Returns the config that is current when translating.
+    Returns None if not translated.
+    """
+    return None
+
+class Entry(ExtRegistryEntry):
+    _about_ = fetch_translated_config
+
+    def compute_result_annotation(self):
+        config = self.bookkeeper.annotator.translator.config
+        return self.bookkeeper.immutablevalue(config)
+
+    def specialize_call(self, hop):
+        from rpython.rtyper.lltypesystem import lltype
+        translator = hop.rtyper.annotator.translator
+        hop.exception_cannot_occur()
+        return hop.inputconst(lltype.Void, translator.config)
+
 # ____________________________________________________________
 
 class FREED_OBJECT(object):
diff --git a/rpython/rlib/test/test_objectmodel.py b/rpython/rlib/test/test_objectmodel.py
--- a/rpython/rlib/test/test_objectmodel.py
+++ b/rpython/rlib/test/test_objectmodel.py
@@ -6,7 +6,8 @@
     prepare_dict_update, reversed_dict, specialize, enforceargs, newlist_hint,
     resizelist_hint, is_annotation_constant, always_inline, NOT_CONSTANT,
     iterkeys_with_hash, iteritems_with_hash, contains_with_hash,
-    setitem_with_hash, getitem_with_hash, delitem_with_hash, import_from_mixin)
+    setitem_with_hash, getitem_with_hash, delitem_with_hash, import_from_mixin,
+    fetch_translated_config)
 from rpython.translator.translator import TranslationContext, graphof
 from rpython.rtyper.test.tool import BaseRtypingTest
 from rpython.rtyper.test.test_llinterp import interpret
@@ -439,6 +440,13 @@
         res = self.interpret(f, [42])
         assert res == 84
 
+    def test_fetch_translated_config(self):
+        assert fetch_translated_config() is None
+        def f():
+            return fetch_translated_config().translation.continuation
+        res = self.interpret(f, [])
+        assert res is False
+
 
 def test_specialize_decorator():
     def f():


More information about the pypy-commit mailing list