[pypy-commit] pypy result-in-resops: shift stuff around so test_oparser passes. good start

fijal noreply at buildbot.pypy.org
Sun Aug 26 11:52:11 CEST 2012


Author: Maciej Fijalkowski <fijall at gmail.com>
Branch: result-in-resops
Changeset: r56863:19c017fb9ebb
Date: 2012-08-26 11:51 +0200
http://bitbucket.org/pypy/pypy/changeset/19c017fb9ebb/

Log:	shift stuff around so test_oparser passes. good start

diff --git a/pypy/jit/metainterp/history.py b/pypy/jit/metainterp/history.py
--- a/pypy/jit/metainterp/history.py
+++ b/pypy/jit/metainterp/history.py
@@ -1,6 +1,6 @@
 
 from pypy.rpython.extregistry import ExtRegistryEntry
-from pypy.rpython.lltypesystem import lltype, llmemory, rffi
+from pypy.rpython.lltypesystem import lltype, llmemory
 from pypy.rpython.ootypesystem import ootype
 from pypy.rlib.objectmodel import we_are_translated, Symbolic
 from pypy.rlib.objectmodel import compute_unique_id
@@ -9,7 +9,7 @@
 from pypy.conftest import option
 
 from pypy.jit.metainterp.resoperation import rop, AbstractValue, INT, REF,\
-     FLOAT
+     FLOAT, repr_pointer, repr_object, ConstPtr
 
 from pypy.jit.codewriter import heaptracker, longlong
 import weakref
@@ -18,65 +18,6 @@
 
 FAILARGS_LIMIT = 1000
 
-def getkind(TYPE, supports_floats=True,
-                  supports_longlong=True,
-                  supports_singlefloats=True):
-    if TYPE is lltype.Void:
-        return "void"
-    elif isinstance(TYPE, lltype.Primitive):
-        if TYPE is lltype.Float and supports_floats:
-            return 'float'
-        if TYPE is lltype.SingleFloat and supports_singlefloats:
-            return 'int'     # singlefloats are stored in an int
-        if TYPE in (lltype.Float, lltype.SingleFloat):
-            raise NotImplementedError("type %s not supported" % TYPE)
-        # XXX fix this for oo...
-        if (TYPE != llmemory.Address and
-            rffi.sizeof(TYPE) > rffi.sizeof(lltype.Signed)):
-            if supports_longlong:
-                assert rffi.sizeof(TYPE) == 8
-                return 'float'
-            raise NotImplementedError("type %s is too large" % TYPE)
-        return "int"
-    elif isinstance(TYPE, lltype.Ptr):
-        if TYPE.TO._gckind == 'raw':
-            return "int"
-        else:
-            return "ref"
-    elif isinstance(TYPE, ootype.OOType):
-        return "ref"
-    else:
-        raise NotImplementedError("type %s not supported" % TYPE)
-getkind._annspecialcase_ = 'specialize:memo'
-
-def repr_pointer(box):
-    from pypy.rpython.lltypesystem import rstr
-    try:
-        T = box.value._obj.container._normalizedcontainer(check=False)._TYPE
-        if T is rstr.STR:
-            return repr(box._get_str())
-        return '*%s' % (T._name,)
-    except AttributeError:
-        return box.value
-
-def repr_object(box):
-    try:
-        TYPE = box.value.obj._TYPE
-        if TYPE is ootype.String:
-            return '(%r)' % box.value.obj._str
-        if TYPE is ootype.Class or isinstance(TYPE, ootype.StaticMethod):
-            return '(%r)' % box.value.obj
-        if isinstance(box.value.obj, ootype._view):
-            return repr(box.value.obj._inst._TYPE)
-        else:
-            return repr(TYPE)
-    except AttributeError:
-        return box.value
-
-def repr_rpython(box, typechars):
-    return '%s/%s%d' % (box._get_hash_(), typechars,
-                        compute_unique_id(box))
-
 
 class AbstractDescr(AbstractValue):
     __slots__ = ()
@@ -114,227 +55,6 @@
         return self.jitcodes[oocls]
 
 
-class Const(AbstractValue):
-    __slots__ = ()
-
-    @staticmethod
-    def _new(x):
-        "NOT_RPYTHON"
-        T = lltype.typeOf(x)
-        kind = getkind(T)
-        if kind == "int":
-            if isinstance(T, lltype.Ptr):
-                intval = heaptracker.adr2int(llmemory.cast_ptr_to_adr(x))
-            else:
-                intval = lltype.cast_primitive(lltype.Signed, x)
-            return ConstInt(intval)
-        elif kind == "ref":
-            return cpu.ts.new_ConstRef(x)
-        elif kind == "float":
-            return ConstFloat(longlong.getfloatstorage(x))
-        else:
-            raise NotImplementedError(kind)
-
-    def constbox(self):
-        return self
-
-    def same_box(self, other):
-        return self.same_constant(other)
-
-    def same_constant(self, other):
-        raise NotImplementedError
-
-    def __repr__(self):
-        return 'Const(%s)' % self._getrepr_()
-
-    def is_constant(self):
-        return True
-
-
-class ConstInt(Const):
-    type = INT
-    value = 0
-    _attrs_ = ('value',)
-
-    def __init__(self, value):
-        if not we_are_translated():
-            if is_valid_int(value):
-                value = int(value)    # bool -> int
-            else:
-                assert isinstance(value, Symbolic)
-        self.value = value
-
-    def clonebox(self):
-        return BoxInt(self.value)
-
-    nonconstbox = clonebox
-
-    def getint(self):
-        return self.value
-
-    def getaddr(self):
-        return heaptracker.int2adr(self.value)
-
-    def _get_hash_(self):
-        return make_hashable_int(self.value)
-
-    def same_constant(self, other):
-        if isinstance(other, ConstInt):
-            return self.value == other.value
-        return False
-
-    def nonnull(self):
-        return self.value != 0
-
-    def _getrepr_(self):
-        return self.value
-
-    def repr_rpython(self):
-        return repr_rpython(self, 'ci')
-
-CONST_FALSE = ConstInt(0)
-CONST_TRUE  = ConstInt(1)
-
-class ConstFloat(Const):
-    type = FLOAT
-    value = longlong.ZEROF
-    _attrs_ = ('value',)
-
-    def __init__(self, valuestorage):
-        assert lltype.typeOf(valuestorage) is longlong.FLOATSTORAGE
-        self.value = valuestorage
-
-    def clonebox(self):
-        return BoxFloat(self.value)
-
-    nonconstbox = clonebox
-
-    def getfloatstorage(self):
-        return self.value
-
-    def _get_hash_(self):
-        return longlong.gethash(self.value)
-
-    def same_constant(self, other):
-        if isinstance(other, ConstFloat):
-            return self.value == other.value
-        return False
-
-    def nonnull(self):
-        return self.value != longlong.ZEROF
-
-    def _getrepr_(self):
-        return self.getfloat()
-
-    def repr_rpython(self):
-        return repr_rpython(self, 'cf')
-
-CONST_FZERO = ConstFloat(longlong.ZEROF)
-
-class ConstPtr(Const):
-    type = REF
-    value = lltype.nullptr(llmemory.GCREF.TO)
-    _attrs_ = ('value',)
-
-    def __init__(self, value):
-        assert lltype.typeOf(value) == llmemory.GCREF
-        self.value = value
-
-    def clonebox(self):
-        return BoxPtr(self.value)
-
-    nonconstbox = clonebox
-
-    def getref_base(self):
-        return self.value
-
-    def getref(self, PTR):
-        return lltype.cast_opaque_ptr(PTR, self.getref_base())
-    getref._annspecialcase_ = 'specialize:arg(1)'
-
-    def _get_hash_(self):
-        if self.value:
-            return lltype.identityhash(self.value)
-        else:
-            return 0
-
-    def getaddr(self):
-        return llmemory.cast_ptr_to_adr(self.value)
-
-    def same_constant(self, other):
-        if isinstance(other, ConstPtr):
-            return self.value == other.value
-        return False
-
-    def nonnull(self):
-        return bool(self.value)
-
-    _getrepr_ = repr_pointer
-
-    def repr_rpython(self):
-        return repr_rpython(self, 'cp')
-
-    def _get_str(self):    # for debugging only
-        from pypy.rpython.annlowlevel import hlstr
-        from pypy.rpython.lltypesystem import rstr
-        try:
-            return hlstr(lltype.cast_opaque_ptr(lltype.Ptr(rstr.STR),
-                                                self.value))
-        except lltype.UninitializedMemoryAccess:
-            return '<uninitialized string>'
-
-CONST_NULL = ConstPtr(ConstPtr.value)
-
-class ConstObj(Const):
-    type = REF
-    value = ootype.NULL
-    _attrs_ = ('value',)
-
-    def __init__(self, value):
-        assert ootype.typeOf(value) is ootype.Object
-        self.value = value
-
-    def clonebox(self):
-        return BoxObj(self.value)
-
-    nonconstbox = clonebox
-
-    def getref_base(self):
-       return self.value
-
-    def getref(self, OBJ):
-        return ootype.cast_from_object(OBJ, self.getref_base())
-    getref._annspecialcase_ = 'specialize:arg(1)'
-
-    def _get_hash_(self):
-        if self.value:
-            return ootype.identityhash(self.value)
-        else:
-            return 0
-
-##    def getaddr(self):
-##        # so far this is used only when calling
-##        # CodeWriter.IndirectCallset.bytecode_for_address.  We don't need a
-##        # real addr, but just a key for the dictionary
-##        return self.value
-
-    def same_constant(self, other):
-        if isinstance(other, ConstObj):
-            return self.value == other.value
-        return False
-
-    def nonnull(self):
-        return bool(self.value)
-
-    _getrepr_ = repr_object
-
-    def repr_rpython(self):
-        return repr_rpython(self, 'co')
-
-    def _get_str(self):    # for debugging only
-        from pypy.rpython.annlowlevel import hlstr
-        return hlstr(ootype.cast_from_object(ootype.String, self.value))
-
 class Box(AbstractValue):
     __slots__ = ()
     _extended_display = True
@@ -547,17 +267,6 @@
 # ____________________________________________________________
 
 
-def make_hashable_int(i):
-    from pypy.rpython.lltypesystem.ll2ctypes import NotCtypesAllocatedStructure
-    if not we_are_translated() and isinstance(i, llmemory.AddressAsInt):
-        # Warning: such a hash changes at the time of translation
-        adr = heaptracker.int2adr(i)
-        try:
-            return llmemory.cast_adr_to_int(adr, "emulated")
-        except NotCtypesAllocatedStructure:
-            return 12345 # use an arbitrary number for the hash
-    return i
-
 def get_const_ptr_for_string(s):
     from pypy.rpython.annlowlevel import llstr
     if not we_are_translated():
diff --git a/pypy/jit/metainterp/jitprof.py b/pypy/jit/metainterp/jitprof.py
--- a/pypy/jit/metainterp/jitprof.py
+++ b/pypy/jit/metainterp/jitprof.py
@@ -112,7 +112,7 @@
     def count_ops(self, opnum, kind=Counters.OPS):
         from pypy.jit.metainterp.resoperation import rop
         self.counters[kind] += 1
-        if opnum == rop.CALL and kind == Counters.RECORDED_OPS:# or opnum == rop.OOSEND:
+        if rop._CALL_FIRST <= opnum <= rop._CALL_LAST and kind == Counters.RECORDED_OPS:# or opnum == rop.OOSEND:
             self.calls += 1
 
     def print_stats(self):
diff --git a/pypy/jit/metainterp/optimizeopt/test/test_multilabel.py b/pypy/jit/metainterp/optimizeopt/test/test_multilabel.py
--- a/pypy/jit/metainterp/optimizeopt/test/test_multilabel.py
+++ b/pypy/jit/metainterp/optimizeopt/test/test_multilabel.py
@@ -1,9 +1,8 @@
 from __future__ import with_statement
 from pypy.jit.metainterp.optimizeopt.test.test_util import (
-    LLtypeMixin, BaseTest, Storage, _sortboxes, FakeDescrWithSnapshot,
-    FakeMetaInterpStaticData)
-from pypy.jit.metainterp.history import TreeLoop, JitCellToken, TargetToken
-from pypy.jit.metainterp.resoperation import rop, opname, ResOperation
+    LLtypeMixin, BaseTest, FakeDescrWithSnapshot, FakeMetaInterpStaticData)
+from pypy.jit.metainterp.history import TreeLoop
+from pypy.jit.metainterp.resoperation import rop
 from pypy.jit.metainterp.optimize import InvalidLoop
 from py.test import raises
 from pypy.jit.metainterp.optimizeopt.optimizer import Optimization
diff --git a/pypy/jit/metainterp/optimizeopt/test/test_optimizebasic.py b/pypy/jit/metainterp/optimizeopt/test/test_optimizebasic.py
--- a/pypy/jit/metainterp/optimizeopt/test/test_optimizebasic.py
+++ b/pypy/jit/metainterp/optimizeopt/test/test_optimizebasic.py
@@ -7,9 +7,9 @@
 import pypy.jit.metainterp.optimizeopt.optimizer as optimizeopt
 import pypy.jit.metainterp.optimizeopt.virtualize as virtualize
 from pypy.jit.metainterp.optimize import InvalidLoop
-from pypy.jit.metainterp.history import AbstractDescr, ConstInt, BoxInt, get_const_ptr_for_string
-from pypy.jit.metainterp import executor, compile, resume, history
-from pypy.jit.metainterp.resoperation import rop, opname, ResOperation
+from pypy.jit.metainterp.history import ConstInt, BoxInt, get_const_ptr_for_string
+from pypy.jit.metainterp import executor, compile, resume
+from pypy.jit.metainterp.resoperation import rop, opname
 from pypy.rlib.rarithmetic import LONG_BIT
 
 def test_store_final_boxes_in_guard():
diff --git a/pypy/jit/metainterp/optimizeopt/test/test_optimizeopt.py b/pypy/jit/metainterp/optimizeopt/test/test_optimizeopt.py
--- a/pypy/jit/metainterp/optimizeopt/test/test_optimizeopt.py
+++ b/pypy/jit/metainterp/optimizeopt/test/test_optimizeopt.py
@@ -1,21 +1,16 @@
 import py
 from pypy.rlib.objectmodel import instantiate
 from pypy.jit.metainterp.optimizeopt.test.test_util import (
-    LLtypeMixin, BaseTest, Storage, _sortboxes, convert_old_style_to_targets)
+    LLtypeMixin, BaseTest, convert_old_style_to_targets)
 import pypy.jit.metainterp.optimizeopt.optimizer as optimizeopt
 import pypy.jit.metainterp.optimizeopt.virtualize as virtualize
-from pypy.jit.metainterp.optimizeopt import ALL_OPTS_DICT, build_opt_chain
+from pypy.jit.metainterp.optimizeopt import build_opt_chain
 from pypy.jit.metainterp.optimize import InvalidLoop
-from pypy.jit.metainterp.history import AbstractDescr, ConstInt, BoxInt
-from pypy.jit.metainterp.history import TreeLoop, JitCellToken, TargetToken
-from pypy.jit.metainterp.jitprof import EmptyProfiler
-from pypy.jit.metainterp import executor, compile, resume, history
-from pypy.jit.metainterp.resoperation import rop, opname, ResOperation
-from pypy.jit.tool.oparser import pure_parse
-from pypy.jit.metainterp.optimizeopt.util import args_dict
+from pypy.jit.metainterp.history import AbstractDescr, ConstInt, TreeLoop
+from pypy.jit.metainterp import compile, resume
+from pypy.jit.metainterp.resoperation import rop, opname
 from pypy.jit.metainterp.optimizeopt.test.test_optimizebasic import FakeMetaInterpStaticData
 from pypy.config.pypyoption import get_pypy_config
-from pypy.jit.metainterp.optimizeopt.unroll import Inliner
 
 def test_build_opt_chain():
     def check(chain, expected_names):
diff --git a/pypy/jit/metainterp/resoperation.py b/pypy/jit/metainterp/resoperation.py
--- a/pypy/jit/metainterp/resoperation.py
+++ b/pypy/jit/metainterp/resoperation.py
@@ -1,8 +1,11 @@
 from pypy.rlib.objectmodel import we_are_translated, specialize
-from pypy.rpython.lltypesystem.llmemory import GCREF
-from pypy.rpython.lltypesystem.lltype import typeOf
+from pypy.rpython.lltypesystem import lltype, llmemory, rffi
+from pypy.rpython.ootypesystem import ootype
 from pypy.jit.codewriter import longlong
-from pypy.rlib.objectmodel import compute_identity_hash, newlist_hint
+from pypy.rlib.objectmodel import compute_identity_hash, newlist_hint,\
+     compute_unique_id, Symbolic
+from pypy.jit.codewriter import heaptracker
+from pypy.rlib.rarithmetic import is_valid_int
 
 INT   = 'i'
 REF   = 'r'
@@ -178,6 +181,301 @@
     def set_extra(self, key, value):
         raise KeyError
 
+def getkind(TYPE, supports_floats=True,
+                  supports_longlong=True,
+                  supports_singlefloats=True):
+    if TYPE is lltype.Void:
+        return "void"
+    elif isinstance(TYPE, lltype.Primitive):
+        if TYPE is lltype.Float and supports_floats:
+            return 'float'
+        if TYPE is lltype.SingleFloat and supports_singlefloats:
+            return 'int'     # singlefloats are stored in an int
+        if TYPE in (lltype.Float, lltype.SingleFloat):
+            raise NotImplementedError("type %s not supported" % TYPE)
+        # XXX fix this for oo...
+        if (TYPE != llmemory.Address and
+            rffi.sizeof(TYPE) > rffi.sizeof(lltype.Signed)):
+            if supports_longlong:
+                assert rffi.sizeof(TYPE) == 8
+                return 'float'
+            raise NotImplementedError("type %s is too large" % TYPE)
+        return "int"
+    elif isinstance(TYPE, lltype.Ptr):
+        if TYPE.TO._gckind == 'raw':
+            return "int"
+        else:
+            return "ref"
+    elif isinstance(TYPE, ootype.OOType):
+        return "ref"
+    else:
+        raise NotImplementedError("type %s not supported" % TYPE)
+getkind._annspecialcase_ = 'specialize:memo'
+
+class Const(AbstractValue):
+    __slots__ = ()
+
+    @staticmethod
+    def _new(x):
+        "NOT_RPYTHON"
+        T = lltype.typeOf(x)
+        kind = getkind(T)
+        if kind == "int":
+            if isinstance(T, lltype.Ptr):
+                intval = heaptracker.adr2int(llmemory.cast_ptr_to_adr(x))
+            else:
+                intval = lltype.cast_primitive(lltype.Signed, x)
+            return ConstInt(intval)
+        elif kind == "ref":
+            return cpu.ts.new_ConstRef(x)
+        elif kind == "float":
+            return ConstFloat(longlong.getfloatstorage(x))
+        else:
+            raise NotImplementedError(kind)
+
+    def constbox(self):
+        return self
+
+    def same_box(self, other):
+        return self.same_constant(other)
+
+    def same_constant(self, other):
+        raise NotImplementedError
+
+    def __repr__(self):
+        return 'Const(%s)' % self._getrepr_()
+
+    def is_constant(self):
+        return True
+
+def repr_rpython(box, typechars):
+    return '%s/%s%d' % (box._get_hash_(), typechars,
+                        compute_unique_id(box))
+
+
+def repr_pointer(box):
+    from pypy.rpython.lltypesystem import rstr
+    try:
+        T = box.value._obj.container._normalizedcontainer(check=False)._TYPE
+        if T is rstr.STR:
+            return repr(box._get_str())
+        return '*%s' % (T._name,)
+    except AttributeError:
+        return box.value
+
+def repr_object(box):
+    try:
+        TYPE = box.value.obj._TYPE
+        if TYPE is ootype.String:
+            return '(%r)' % box.value.obj._str
+        if TYPE is ootype.Class or isinstance(TYPE, ootype.StaticMethod):
+            return '(%r)' % box.value.obj
+        if isinstance(box.value.obj, ootype._view):
+            return repr(box.value.obj._inst._TYPE)
+        else:
+            return repr(TYPE)
+    except AttributeError:
+        return box.value
+
+def make_hashable_int(i):
+    from pypy.rpython.lltypesystem.ll2ctypes import NotCtypesAllocatedStructure
+    if not we_are_translated() and isinstance(i, llmemory.AddressAsInt):
+        # Warning: such a hash changes at the time of translation
+        adr = heaptracker.int2adr(i)
+        try:
+            return llmemory.cast_adr_to_int(adr, "emulated")
+        except NotCtypesAllocatedStructure:
+            return 12345 # use an arbitrary number for the hash
+    return i
+
+class ConstInt(Const):
+    type = INT
+    value = 0
+    _attrs_ = ('value',)
+
+    def __init__(self, value):
+        if not we_are_translated():
+            if is_valid_int(value):
+                value = int(value)    # bool -> int
+            else:
+                assert isinstance(value, Symbolic)
+        self.value = value
+
+    def clonebox(self):
+        from pypy.jit.metainterp.history import BoxInt
+        return BoxInt(self.value)
+
+    nonconstbox = clonebox
+
+    def getint(self):
+        return self.value
+
+    def getaddr(self):
+        return heaptracker.int2adr(self.value)
+
+    def _get_hash_(self):
+        return make_hashable_int(self.value)
+
+    def same_constant(self, other):
+        if isinstance(other, ConstInt):
+            return self.value == other.value
+        return False
+
+    def nonnull(self):
+        return self.value != 0
+
+    def _getrepr_(self):
+        return self.value
+
+    def repr_rpython(self):
+        return repr_rpython(self, 'ci')
+
+CONST_FALSE = ConstInt(0)
+CONST_TRUE  = ConstInt(1)
+
+class ConstFloat(Const):
+    type = FLOAT
+    value = longlong.ZEROF
+    _attrs_ = ('value',)
+
+    def __init__(self, valuestorage):
+        assert lltype.typeOf(valuestorage) is longlong.FLOATSTORAGE
+        self.value = valuestorage
+
+    def clonebox(self):
+        from pypy.jit.metainterp.history import BoxFloat
+        return BoxFloat(self.value)
+
+    nonconstbox = clonebox
+
+    def getfloatstorage(self):
+        return self.value
+
+    def _get_hash_(self):
+        return longlong.gethash(self.value)
+
+    def same_constant(self, other):
+        if isinstance(other, ConstFloat):
+            return self.value == other.value
+        return False
+
+    def nonnull(self):
+        return self.value != longlong.ZEROF
+
+    def _getrepr_(self):
+        return self.getfloat()
+
+    def repr_rpython(self):
+        return repr_rpython(self, 'cf')
+
+CONST_FZERO = ConstFloat(longlong.ZEROF)
+
+class ConstPtr(Const):
+    type = REF
+    value = lltype.nullptr(llmemory.GCREF.TO)
+    _attrs_ = ('value',)
+
+    def __init__(self, value):
+        assert lltype.typeOf(value) == llmemory.GCREF
+        self.value = value
+
+    def clonebox(self):
+        from pypy.jit.metainterp.history import BoxPtr
+        return BoxPtr(self.value)
+
+    nonconstbox = clonebox
+
+    def getref_base(self):
+        return self.value
+
+    def getref(self, PTR):
+        return lltype.cast_opaque_ptr(PTR, self.getref_base())
+    getref._annspecialcase_ = 'specialize:arg(1)'
+
+    def _get_hash_(self):
+        if self.value:
+            return lltype.identityhash(self.value)
+        else:
+            return 0
+
+    def getaddr(self):
+        return llmemory.cast_ptr_to_adr(self.value)
+
+    def same_constant(self, other):
+        if isinstance(other, ConstPtr):
+            return self.value == other.value
+        return False
+
+    def nonnull(self):
+        return bool(self.value)
+
+    _getrepr_ = repr_pointer
+
+    def repr_rpython(self):
+        return repr_rpython(self, 'cp')
+
+    def _get_str(self):    # for debugging only
+        from pypy.rpython.annlowlevel import hlstr
+        from pypy.rpython.lltypesystem import rstr
+        try:
+            return hlstr(lltype.cast_opaque_ptr(lltype.Ptr(rstr.STR),
+                                                self.value))
+        except lltype.UninitializedMemoryAccess:
+            return '<uninitialized string>'
+
+CONST_NULL = ConstPtr(ConstPtr.value)
+
+class ConstObj(Const):
+    type = REF
+    value = ootype.NULL
+    _attrs_ = ('value',)
+
+    def __init__(self, value):
+        assert ootype.typeOf(value) is ootype.Object
+        self.value = value
+
+    def clonebox(self):
+        from pypy.jit.metainterp.history import BoxObj
+        return BoxObj(self.value)
+
+    nonconstbox = clonebox
+
+    def getref_base(self):
+       return self.value
+
+    def getref(self, OBJ):
+        return ootype.cast_from_object(OBJ, self.getref_base())
+    getref._annspecialcase_ = 'specialize:arg(1)'
+
+    def _get_hash_(self):
+        if self.value:
+            return ootype.identityhash(self.value)
+        else:
+            return 0
+
+##    def getaddr(self):
+##        # so far this is used only when calling
+##        # CodeWriter.IndirectCallset.bytecode_for_address.  We don't need a
+##        # real addr, but just a key for the dictionary
+##        return self.value
+
+    def same_constant(self, other):
+        if isinstance(other, ConstObj):
+            return self.value == other.value
+        return False
+
+    def nonnull(self):
+        return bool(self.value)
+
+    _getrepr_ = repr_object
+
+    def repr_rpython(self):
+        return repr_rpython(self, 'co')
+
+    def _get_str(self):    # for debugging only
+        from pypy.rpython.annlowlevel import hlstr
+        return hlstr(ootype.cast_from_object(ootype.String, self.value))
+
 class AbstractResOp(AbstractValue):
     """The central ResOperation class, representing one operation."""
 
@@ -186,6 +484,12 @@
     pc = 0
     opnum = 0
 
+    DOCUMENTED_KEYS = {
+        'failargs': 'arguments for guard ops that are alive. '
+                    'valid from optimizations (store_final_args) until '
+                    'the backend',
+    }
+
     extras = None
     # ResOps are immutable, however someone can store a temporary
     # extra mutable stuff here, in the extras field. Other fields (including
@@ -200,6 +504,8 @@
 
     @specialize.arg(1)
     def set_extra(self, key, value):
+        if key not in self.DOCUMENTED_KEYS:
+            raise Exception("Please document '%s' extra parameter and it's lifetime" % key)
         setattr(self, key, value)
 
     @classmethod
@@ -373,7 +679,6 @@
 
     @staticmethod
     def wrap_constant(intval):
-        from pypy.jit.metainterp.history import ConstInt
         return ConstInt(intval)
 
 class ResOpFloat(object):
@@ -394,7 +699,6 @@
 
     @staticmethod
     def wrap_constant(floatval):
-        from pypy.jit.metainterp.history import ConstFloat
         return ConstFloat(floatval)
 
 class ResOpPointer(object):
@@ -402,7 +706,7 @@
     type = REF
     
     def __init__(self, pval):
-        assert typeOf(pval) == GCREF
+        assert lltype.typeOf(pval) == llmemory.GCREF
         self.pval = pval
 
     def getref_base(self):
@@ -415,7 +719,6 @@
 
     @staticmethod
     def wrap_constant(pval):
-        from pypy.jit.metainterp.history import ConstPtr
         return ConstPtr(pval)
 
 # ===================
diff --git a/pypy/jit/metainterp/test/test_resoperation.py b/pypy/jit/metainterp/test/test_resoperation.py
--- a/pypy/jit/metainterp/test/test_resoperation.py
+++ b/pypy/jit/metainterp/test/test_resoperation.py
@@ -184,5 +184,5 @@
 
 def test_get_set_extra():
     op = rop.create_resop_2(rop.rop.INT_ADD, 3, FakeBox("a"), FakeBox("b"))
-    op.set_extra("x", 2)
-    assert op.get_extra("x") == 2
+    op.set_extra("failargs", 2)
+    assert op.get_extra("failargs") == 2
diff --git a/pypy/jit/metainterp/typesystem.py b/pypy/jit/metainterp/typesystem.py
--- a/pypy/jit/metainterp/typesystem.py
+++ b/pypy/jit/metainterp/typesystem.py
@@ -3,7 +3,7 @@
 from pypy.rpython.annlowlevel import cast_base_ptr_to_instance, llstr, oostr
 from pypy.rpython.annlowlevel import cast_instance_to_base_ptr
 from pypy.rpython.annlowlevel import cast_instance_to_base_obj
-from pypy.jit.metainterp import history
+from pypy.jit.metainterp import history, resoperation
 from pypy.jit.codewriter import heaptracker
 from pypy.rlib.objectmodel import r_dict, specialize
 
@@ -44,15 +44,15 @@
     cast_instance_to_base_ref = staticmethod(cast_instance_to_base_ptr)
     BASETYPE = llmemory.GCREF
     BoxRef = history.BoxPtr
-    ConstRef = history.ConstPtr
+    ConstRef = resoperation.ConstPtr
     loops_done_with_this_frame_ref = None # patched by compile.py
-    NULLREF = history.ConstPtr.value
-    CONST_NULL = history.ConstPtr(NULLREF)
+    NULLREF = resoperation.ConstPtr.value
+    CONST_NULL = resoperation.ConstPtr(NULLREF)
     CVAL_NULLREF = None # patched by optimizeopt.py
 
     def new_ConstRef(self, x):
         ptrval = lltype.cast_opaque_ptr(llmemory.GCREF, x)
-        return history.ConstPtr(ptrval)
+        return resoperation.ConstPtr(ptrval)
 
     def get_typeptr(self, obj):
         return obj.typeptr
@@ -75,7 +75,7 @@
     def cls_of_box(self, box):
         obj = box.getref(lltype.Ptr(rclass.OBJECT))
         cls = llmemory.cast_ptr_to_adr(obj.typeptr)
-        return history.ConstInt(heaptracker.adr2int(cls))
+        return resoperation.ConstInt(heaptracker.adr2int(cls))
 
     def instanceOf(self, instbox, clsbox):
         adr = clsbox.getaddr()
@@ -84,7 +84,7 @@
         return rclass.ll_isinstance(real_instance, bounding_class)
 
     def get_exception_box(self, etype):
-        return history.ConstInt(etype)
+        return resoperation.ConstInt(etype)
 
     def get_exc_value_box(self, evalue):
         return history.BoxPtr(evalue)
@@ -111,7 +111,7 @@
 
     def conststr(self, str):
         ll = llstr(str)
-        return history.ConstPtr(lltype.cast_opaque_ptr(llmemory.GCREF, ll))
+        return resoperation.ConstPtr(lltype.cast_opaque_ptr(llmemory.GCREF, ll))
 
     # A dict whose keys are refs (like the .value of BoxPtr).
     # It is an r_dict on lltype.  Two copies, to avoid conflicts with
@@ -153,15 +153,15 @@
     cast_instance_to_base_ref = staticmethod(cast_instance_to_base_obj)
     BASETYPE = ootype.Object
     BoxRef = history.BoxObj
-    ConstRef = history.ConstObj
+    ConstRef = resoperation.ConstObj
     loops_done_with_this_frame_ref = None # patched by compile.py
-    NULLREF = history.ConstObj.value
-    CONST_NULL = history.ConstObj(NULLREF)
+    NULLREF = resoperation.ConstObj.value
+    CONST_NULL = resoperation.ConstObj(NULLREF)
     CVAL_NULLREF = None # patched by optimizeopt.py
     
     def new_ConstRef(self, x):
         obj = ootype.cast_to_object(x)
-        return history.ConstObj(obj)
+        return resoperation.ConstObj(obj)
 
     def get_typeptr(self, obj):
         return ootype.classof(obj)
@@ -183,7 +183,7 @@
     def cls_of_box(self, cpu, box):
         obj = box.getref(ootype.ROOT)
         oocls = ootype.classof(obj)
-        return history.ConstObj(ootype.cast_to_object(oocls))
+        return resoperation.ConstObj(ootype.cast_to_object(oocls))
 
     def subclassOf(self, cpu, clsbox1, clsbox2):
         cls1 = clsbox1.getref(ootype.Class)
@@ -191,7 +191,7 @@
         return ootype.subclassof(cls1, cls2)
 
     def get_exception_box(self, etype):
-        return history.ConstObj(etype)
+        return resoperation.ConstObj(etype)
 
     def get_exc_value_box(self, evalue):
         return history.BoxObj(evalue)
@@ -218,7 +218,7 @@
 
     def conststr(self, str):
         oo = oostr(str)
-        return history.ConstObj(ootype.cast_to_object(oo))
+        return resoperation.ConstObj(ootype.cast_to_object(oo))
 
     # A dict whose keys are refs (like the .value of BoxObj).
     # It is a normal dict on ootype.  Two copies, to avoid conflicts
diff --git a/pypy/jit/tool/oparser.py b/pypy/jit/tool/oparser.py
--- a/pypy/jit/tool/oparser.py
+++ b/pypy/jit/tool/oparser.py
@@ -285,14 +285,14 @@
         opres = self.create_op(opnum, self._example_for(opnum), args, descr)
         self.vars[res] = opres
         if fail_args is not None:
-            res.setfailargs(fail_args)
+            res.set_extra("failargs", fail_args)
         return opres
 
     def parse_op_no_result(self, line):
         opnum, args, descr, fail_args = self.parse_op(line)
         res = self.create_op(opnum, self._example_for(opnum), args, descr)
         if fail_args is not None:
-            res.setfailargs(fail_args)
+            res.set_extra("failargs", fail_args)
         return res
 
     def parse_next_op(self, line):
diff --git a/pypy/jit/tool/oparser_model.py b/pypy/jit/tool/oparser_model.py
--- a/pypy/jit/tool/oparser_model.py
+++ b/pypy/jit/tool/oparser_model.py
@@ -5,7 +5,7 @@
     class LoopModel(object):
         from pypy.jit.metainterp.history import TreeLoop, JitCellToken
         from pypy.jit.metainterp.history import Box, BoxInt, BoxFloat
-        from pypy.jit.metainterp.history import ConstInt, ConstObj, ConstPtr, ConstFloat
+        from pypy.jit.metainterp.resoperation import ConstInt, ConstObj, ConstPtr, ConstFloat
         from pypy.jit.metainterp.history import BasicFailDescr, TargetToken
         from pypy.jit.metainterp.typesystem import llhelper
 
diff --git a/pypy/jit/tool/test/test_oparser.py b/pypy/jit/tool/test/test_oparser.py
--- a/pypy/jit/tool/test/test_oparser.py
+++ b/pypy/jit/tool/test/test_oparser.py
@@ -40,7 +40,7 @@
         loop = self.parse(x, None, locals())
         assert len(loop.operations) == 1
         assert loop.operations[0].getdescr()
-        assert loop.operations[0].getfailargs() == []
+        assert loop.operations[0].get_extra("failargs") == []
 
     def test_descr(self):
         class Xyz(AbstractDescr):
@@ -204,7 +204,7 @@
         guard_true(i0, descr=<Guard0>)
         '''
         loop = self.parse(x, nonstrict=True)
-        assert loop.operations[0].getfailargs() == []
+        assert loop.operations[0].get_extra("failargs") == []
 
     def test_no_inputargs(self):
         x = '''


More information about the pypy-commit mailing list