[pypy-svn] r48865 - in pypy/branch/kill-remaining-suggested-primitives: . pypy pypy/annotation pypy/annotation/test pypy/interpreter pypy/objspace/flow pypy/objspace/flow/test pypy/rlib pypy/rlib/test pypy/rpython pypy/rpython/lltypesystem pypy/rpython/module pypy/rpython/ootypesystem/test pypy/rpython/test pypy/tool pypy/tool/test pypy/translator pypy/translator/c pypy/translator/goal pypy/translator/jvm pypy/translator/stackless pypy/translator/stackless/test pypy/translator/tool

xoraxax at codespeak.net xoraxax at codespeak.net
Tue Nov 20 19:31:21 CET 2007


Author: xoraxax
Date: Tue Nov 20 19:31:20 2007
New Revision: 48865

Added:
   pypy/branch/kill-remaining-suggested-primitives/
      - copied from r48795, pypy/dist/
   pypy/branch/kill-remaining-suggested-primitives/pypy/
      - copied from r48813, pypy/dist/pypy/
   pypy/branch/kill-remaining-suggested-primitives/pypy/rpython/lltypesystem/ll2ctypes.py
      - copied unchanged from r48844, pypy/dist/pypy/rpython/lltypesystem/ll2ctypes.py
   pypy/branch/kill-remaining-suggested-primitives/pypy/rpython/lltypesystem/rffi.py
      - copied unchanged from r48844, pypy/dist/pypy/rpython/lltypesystem/rffi.py
   pypy/branch/kill-remaining-suggested-primitives/pypy/rpython/rcontrollerentry.py
      - copied unchanged from r48849, pypy/dist/pypy/rpython/rcontrollerentry.py
   pypy/branch/kill-remaining-suggested-primitives/pypy/rpython/test/test_controllerentry.py
      - copied unchanged from r48849, pypy/dist/pypy/rpython/test/test_controllerentry.py
   pypy/branch/kill-remaining-suggested-primitives/pypy/rpython/test/test_stack.py
   pypy/branch/kill-remaining-suggested-primitives/pypy/tool/descriptor.py
   pypy/branch/kill-remaining-suggested-primitives/pypy/tool/test/test_descriptor.py
      - copied, changed from r48813, pypy/dist/pypy/tool/test/test_instancemethod.py
   pypy/branch/kill-remaining-suggested-primitives/pypy/translator/jvm/genjvm.py
      - copied unchanged from r48840, pypy/dist/pypy/translator/jvm/genjvm.py
Removed:
   pypy/branch/kill-remaining-suggested-primitives/pypy/rpython/module/ll_stack.py
   pypy/branch/kill-remaining-suggested-primitives/pypy/rpython/module/ll_stackless.py
   pypy/branch/kill-remaining-suggested-primitives/pypy/tool/instancemethod.py
   pypy/branch/kill-remaining-suggested-primitives/pypy/tool/test/test_instancemethod.py
Modified:
   pypy/branch/kill-remaining-suggested-primitives/pypy/annotation/builtin.py
   pypy/branch/kill-remaining-suggested-primitives/pypy/annotation/model.py
   pypy/branch/kill-remaining-suggested-primitives/pypy/annotation/test/test_annrpython.py
   pypy/branch/kill-remaining-suggested-primitives/pypy/interpreter/eval.py
   pypy/branch/kill-remaining-suggested-primitives/pypy/objspace/flow/__init__.py
   pypy/branch/kill-remaining-suggested-primitives/pypy/objspace/flow/model.py
   pypy/branch/kill-remaining-suggested-primitives/pypy/objspace/flow/test/test_framestate.py
   pypy/branch/kill-remaining-suggested-primitives/pypy/objspace/flow/test/test_objspace.py
   pypy/branch/kill-remaining-suggested-primitives/pypy/rlib/rstack.py
   pypy/branch/kill-remaining-suggested-primitives/pypy/rlib/test/test_nonconst.py
   pypy/branch/kill-remaining-suggested-primitives/pypy/rpython/controllerentry.py
   pypy/branch/kill-remaining-suggested-primitives/pypy/rpython/extfunctable.py
   pypy/branch/kill-remaining-suggested-primitives/pypy/rpython/llinterp.py
   pypy/branch/kill-remaining-suggested-primitives/pypy/rpython/lltypesystem/lloperation.py
   pypy/branch/kill-remaining-suggested-primitives/pypy/rpython/ootypesystem/test/test_bltann.py
   pypy/branch/kill-remaining-suggested-primitives/pypy/rpython/ootypesystem/test/test_ooann.py
   pypy/branch/kill-remaining-suggested-primitives/pypy/rpython/ootypesystem/test/test_oortype.py
   pypy/branch/kill-remaining-suggested-primitives/pypy/rpython/rbuiltin.py
   pypy/branch/kill-remaining-suggested-primitives/pypy/rpython/test/test_llann.py
   pypy/branch/kill-remaining-suggested-primitives/pypy/tool/udir.py
   pypy/branch/kill-remaining-suggested-primitives/pypy/translator/c/extfunc.py
   pypy/branch/kill-remaining-suggested-primitives/pypy/translator/exceptiontransform.py
   pypy/branch/kill-remaining-suggested-primitives/pypy/translator/geninterplevel.py
   pypy/branch/kill-remaining-suggested-primitives/pypy/translator/goal/targetlbench.py
   pypy/branch/kill-remaining-suggested-primitives/pypy/translator/stackless/frame.py
   pypy/branch/kill-remaining-suggested-primitives/pypy/translator/stackless/test/test_yield_current_frame_to_caller.py
   pypy/branch/kill-remaining-suggested-primitives/pypy/translator/stackless/transform.py
   pypy/branch/kill-remaining-suggested-primitives/pypy/translator/tool/make_dot.py
   pypy/branch/kill-remaining-suggested-primitives/pypy/translator/transform.py
   pypy/branch/kill-remaining-suggested-primitives/pypy/translator/translator.py
Log:
(armin, alexander): Removed the remaining suggested primitives, fiddled with controller logic and 
made it working in the end again. Checking it to run tests easily on remote machines ...



Modified: pypy/branch/kill-remaining-suggested-primitives/pypy/annotation/builtin.py
==============================================================================
--- pypy/dist/pypy/annotation/builtin.py	(original)
+++ pypy/branch/kill-remaining-suggested-primitives/pypy/annotation/builtin.py	Tue Nov 20 19:31:20 2007
@@ -18,7 +18,6 @@
 from pypy.objspace.flow.model import Constant
 import pypy.rlib.rarithmetic
 import pypy.rlib.objectmodel
-import pypy.rlib.rstack
 
 # convenience only!
 def immutablevalue(x):
@@ -339,9 +338,6 @@
 def llmemory_cast_int_to_adr(s):
     return SomeAddress()
 
-def rstack_yield_current_frame_to_caller():
-    return SomeExternalObject(pypy.rlib.rstack.frame_stack_top)
-    
 
 ##def rarith_ovfcheck(s_obj):
 ##    if isinstance(s_obj, SomeInteger) and s_obj.unsigned:
@@ -384,8 +380,6 @@
 BUILTIN_ANALYZERS[pypy.rpython.lltypesystem.llmemory.cast_adr_to_ptr] = llmemory_cast_adr_to_ptr
 BUILTIN_ANALYZERS[pypy.rpython.lltypesystem.llmemory.cast_adr_to_int] = llmemory_cast_adr_to_int
 BUILTIN_ANALYZERS[pypy.rpython.lltypesystem.llmemory.cast_int_to_adr] = llmemory_cast_int_to_adr
-BUILTIN_ANALYZERS[pypy.rlib.rstack.yield_current_frame_to_caller] = (
-    rstack_yield_current_frame_to_caller)
 
 BUILTIN_ANALYZERS[getattr(OSError.__init__, 'im_func', OSError.__init__)] = (
     OSError_init)

Modified: pypy/branch/kill-remaining-suggested-primitives/pypy/annotation/model.py
==============================================================================
--- pypy/dist/pypy/annotation/model.py	(original)
+++ pypy/branch/kill-remaining-suggested-primitives/pypy/annotation/model.py	Tue Nov 20 19:31:20 2007
@@ -29,7 +29,8 @@
 
 
 from types import BuiltinFunctionType, MethodType, FunctionType
-import pypy.tool.instancemethod
+import pypy
+from pypy.tool import descriptor
 from pypy.tool.pairtype import pair, extendabletype
 from pypy.tool.tls import tlsobject
 from pypy.rlib.rarithmetic import r_uint, r_longlong, r_ulonglong, base_int
@@ -441,7 +442,7 @@
 
     def __init__(self, analyser, s_self=None, methodname=None):
         if isinstance(analyser, MethodType):
-            analyser = pypy.tool.instancemethod.InstanceMethod(
+            analyser = descriptor.InstanceMethod(
                 analyser.im_func,
                 analyser.im_self,
                 analyser.im_class)

Modified: pypy/branch/kill-remaining-suggested-primitives/pypy/annotation/test/test_annrpython.py
==============================================================================
--- pypy/dist/pypy/annotation/test/test_annrpython.py	(original)
+++ pypy/branch/kill-remaining-suggested-primitives/pypy/annotation/test/test_annrpython.py	Tue Nov 20 19:31:20 2007
@@ -16,7 +16,7 @@
 from pypy.rlib.rarithmetic import r_uint, base_int, r_longlong, r_ulonglong
 from pypy.rlib.rarithmetic import r_singlefloat
 from pypy.rlib import objectmodel
-from pypy.objspace.flow import FlowObjSpace
+from pypy.objspace.flow.objspace import FlowObjSpace
 
 from pypy.translator.test import snippet
 

Modified: pypy/branch/kill-remaining-suggested-primitives/pypy/interpreter/eval.py
==============================================================================
--- pypy/dist/pypy/interpreter/eval.py	(original)
+++ pypy/branch/kill-remaining-suggested-primitives/pypy/interpreter/eval.py	Tue Nov 20 19:31:20 2007
@@ -4,7 +4,6 @@
 """
 from pypy.interpreter.error import OperationError
 from pypy.interpreter.baseobjspace import Wrappable
-from pypy.rlib import rstack # for resume points
 
 
 class Code(Wrappable):

Modified: pypy/branch/kill-remaining-suggested-primitives/pypy/objspace/flow/__init__.py
==============================================================================
--- pypy/dist/pypy/objspace/flow/__init__.py	(original)
+++ pypy/branch/kill-remaining-suggested-primitives/pypy/objspace/flow/__init__.py	Tue Nov 20 19:31:20 2007
@@ -1,2 +0,0 @@
-from pypy.objspace.flow.objspace import FlowObjSpace
-Space = FlowObjSpace

Modified: pypy/branch/kill-remaining-suggested-primitives/pypy/objspace/flow/model.py
==============================================================================
--- pypy/dist/pypy/objspace/flow/model.py	(original)
+++ pypy/branch/kill-remaining-suggested-primitives/pypy/objspace/flow/model.py	Tue Nov 20 19:31:20 2007
@@ -6,6 +6,7 @@
 from __future__ import generators
 import py
 from pypy.tool.uid import uid, Hashable
+from pypy.tool.descriptor import roproperty
 from pypy.tool.sourcetools import PY_IDENTIFIER, nice_repr_for_func
 
 """
@@ -30,15 +31,6 @@
 
 __metaclass__ = type
 
-class roproperty(object):
-    def __init__(self, getter):
-        self.getter = getter
-    def __get__(self, obj, cls=None):
-        if obj is None:
-            return self
-        else:
-            return self.getter(obj)
-
 
 class FunctionGraph(object):
     __slots__ = ['startblock', 'returnblock', 'exceptblock', '__dict__']

Modified: pypy/branch/kill-remaining-suggested-primitives/pypy/objspace/flow/test/test_framestate.py
==============================================================================
--- pypy/dist/pypy/objspace/flow/test/test_framestate.py	(original)
+++ pypy/branch/kill-remaining-suggested-primitives/pypy/objspace/flow/test/test_framestate.py	Tue Nov 20 19:31:20 2007
@@ -4,7 +4,7 @@
 from pypy.objspace.flow.model import *
 from pypy.objspace.flow.framestate import *
 from pypy.interpreter.pycode import PyCode
-from pypy.objspace.flow import FlowObjSpace
+from pypy.objspace.flow.objspace import FlowObjSpace
 
 class TestFrameState:
     def setup_class(cls):

Modified: pypy/branch/kill-remaining-suggested-primitives/pypy/objspace/flow/test/test_objspace.py
==============================================================================
--- pypy/dist/pypy/objspace/flow/test/test_objspace.py	(original)
+++ pypy/branch/kill-remaining-suggested-primitives/pypy/objspace/flow/test/test_objspace.py	Tue Nov 20 19:31:20 2007
@@ -4,7 +4,7 @@
 from pypy.objspace.flow.model import flatten
 from pypy.interpreter.argument import Arguments
 from pypy.translator.simplify import simplify_graph
-from pypy.objspace.flow import FlowObjSpace 
+from pypy.objspace.flow.objspace import FlowObjSpace 
 from pypy.objspace.flow import objspace
 from pypy import conftest
 

Modified: pypy/branch/kill-remaining-suggested-primitives/pypy/rlib/rstack.py
==============================================================================
--- pypy/dist/pypy/rlib/rstack.py	(original)
+++ pypy/branch/kill-remaining-suggested-primitives/pypy/rlib/rstack.py	Tue Nov 20 19:31:20 2007
@@ -5,17 +5,35 @@
 
 import inspect
 
+from pypy.rlib.objectmodel import we_are_translated
+from pypy.rpython.extregistry import ExtRegistryEntry
+from pypy.rpython.lltypesystem import rffi, lltype
+from pypy.rpython.controllerentry import Controller, SomeControlledInstance
+
+
 def stack_unwind():
+    if we_are_translated():
+        from pypy.rpython.lltypesystem.lloperation import llop
+        return llop.stack_unwind(lltype.Void)
     raise RuntimeError("cannot unwind stack in non-translated versions")
 
+
 def stack_capture():
+    if we_are_translated():
+        from pypy.rpython.lltypesystem.lloperation import llop
+        ptr = llop.stack_capture(OPAQUE_STATE_HEADER_PTR)
+        return frame_stack_top_controller.box(ptr)
     raise RuntimeError("cannot unwind stack in non-translated versions")
 
+
 def stack_frames_depth():
-    return len(inspect.stack())
+    if we_are_translated():
+        from pypy.rpython.lltypesystem.lloperation import llop
+        return llop.stack_frames_depth(lltype.Signed)
+    else:
+        return len(inspect.stack())
 
-def stack_too_big():
-    return False
+stack_too_big = rffi.llexternal('LL_stack_too_big', [], rffi.INT, _callable=lambda: 0)
 
 def stack_check():
     if stack_too_big():
@@ -29,16 +47,62 @@
 def yield_current_frame_to_caller():
     raise NotImplementedError("only works in translated versions")
 
+
 class frame_stack_top(object):
     def switch(self):
         raise NotImplementedError("only works in translated versions")
 
 
-from pypy.rpython.extregistry import ExtRegistryEntry
+class BoundSwitchOfFrameStackTop(object): pass
+class BoundSwitchOfFrameStackTopController(Controller):
+    knowntype = BoundSwitchOfFrameStackTop
+    def call(self, real_object):
+        from pypy.rpython.lltypesystem.lloperation import llop
+        ptr = llop.stack_switch(OPAQUE_STATE_HEADER_PTR, real_object)
+        return frame_stack_top_controller.box(ptr)
+
+
+class FrameStackTopController(Controller):
+    knowntype = frame_stack_top
+    can_be_None = True
+
+    def is_true(self, real_object):
+        return bool(real_object)
+
+    def get_switch(self, real_object):
+        return bound_switch_of_frame_stack_top_controller.box(real_object)
+
+    def convert(self, obj):
+        assert obj is None
+        return lltype.nullptr(OPAQUE_STATE_HEADER_PTR.TO)
+
+frame_stack_top_controller = FrameStackTopController()
+bound_switch_of_frame_stack_top_controller = BoundSwitchOfFrameStackTopController()
+OPAQUE_STATE_HEADER = lltype.GcOpaqueType("OPAQUE_STATE_HEADER")
+OPAQUE_STATE_HEADER._exttypeinfo = "Really bad hack - dont remove"
+OPAQUE_STATE_HEADER_PTR = lltype.Ptr(OPAQUE_STATE_HEADER)
+
+
+
+class FrameStackTopReturningFnEntry(ExtRegistryEntry):
+    def compute_result_annotation(self):
+        from pypy.annotation import model as annmodel
+        return SomeControlledInstance(annmodel.lltype_to_annotation(OPAQUE_STATE_HEADER_PTR), frame_stack_top_controller)
+
+
+class YieldCurrentFrameToCallerFnEntry(FrameStackTopReturningFnEntry):
+    _about_ = yield_current_frame_to_caller
+
+    def specialize_call(self, hop):
+        var = hop.genop("yield_current_frame_to_caller", [], hop.r_result.lowleveltype)
+        return var
+
 
 def resume_point(label, *args, **kwds):
     pass
 
+
+
 class ResumePointFnEntry(ExtRegistryEntry):
     _about_ = resume_point
 
@@ -83,17 +147,14 @@
     r_arg = hop.rtyper.bindingrepr(v_arg)
     return hop.inputarg(r_arg, arg=index)
 
-class ResumeStateCreateFnEntry(ExtRegistryEntry):
+class ResumeStateCreateFnEntry(FrameStackTopReturningFnEntry):
     _about_ = resume_state_create
 
     def compute_result_annotation(self, s_prevstate, s_label, *args_s):
-        from pypy.annotation import model as annmodel
-        return annmodel.SomeExternalObject(frame_stack_top)
+        return FrameStackTopReturningFnEntry.compute_result_annotation(self)
 
     def specialize_call(self, hop):
         from pypy.rpython.lltypesystem import lltype
-        from pypy.rpython.rmodel import SimplePointerRepr
-        from pypy.translator.stackless.frame import STATE_HEADER
 
         assert hop.args_s[1].is_constant()
         c_label = hop.inputconst(lltype.Void, hop.args_s[1].const)
@@ -142,4 +203,3 @@
         return hop.genop('resume_state_invoke', [v_state, v_returning, v_raising],
                          hop.r_result)
         
-        

Modified: pypy/branch/kill-remaining-suggested-primitives/pypy/rlib/test/test_nonconst.py
==============================================================================
--- pypy/dist/pypy/rlib/test/test_nonconst.py	(original)
+++ pypy/branch/kill-remaining-suggested-primitives/pypy/rlib/test/test_nonconst.py	Tue Nov 20 19:31:20 2007
@@ -4,7 +4,7 @@
 
 from pypy.rlib.nonconst import NonConstant
 
-from pypy.objspace.flow import FlowObjSpace
+from pypy.objspace.flow.objspace import FlowObjSpace
 from pypy.annotation.annrpython import RPythonAnnotator
 from pypy.conftest import option
 from pypy.annotation.model import SomeInstance

Modified: pypy/branch/kill-remaining-suggested-primitives/pypy/rpython/controllerentry.py
==============================================================================
--- pypy/dist/pypy/rpython/controllerentry.py	(original)
+++ pypy/branch/kill-remaining-suggested-primitives/pypy/rpython/controllerentry.py	Tue Nov 20 19:31:20 2007
@@ -1,5 +1,6 @@
 from pypy.annotation import model as annmodel
 from pypy.tool.pairtype import pairtype
+from pypy.annotation.binaryop import _make_none_union, SomePBC # SomePBC needed by _make_none_union
 from pypy.annotation.bookkeeper import getbookkeeper
 from pypy.rpython.extregistry import ExtRegistryEntry
 from pypy.rpython.annlowlevel import cachedtype
@@ -48,6 +49,7 @@
 
 class Controller(object):
     __metaclass__ = cachedtype
+    can_be_None = False
 
     def _freeze_(self):
         return True
@@ -210,6 +212,9 @@
         self.controller = controller
         self.knowntype = controller.knowntype
 
+    def can_be_none(self):
+        return self.controller.can_be_None
+
     def rtyper_makerepr(self, rtyper):
         from pypy.rpython.rcontrollerentry import ControlledInstanceRepr
         return ControlledInstanceRepr(rtyper, self.s_real_obj, self.controller)
@@ -218,6 +223,7 @@
         real_key = rtyper.makekey(self.s_real_obj)
         return self.__class__, real_key, self.controller
 
+_make_none_union("SomeControlledInstance", "obj.s_real_obj, obj.controller", globals())
 
 class __extend__(SomeControlledInstance):
 

Modified: pypy/branch/kill-remaining-suggested-primitives/pypy/rpython/extfunctable.py
==============================================================================
--- pypy/dist/pypy/rpython/extfunctable.py	(original)
+++ pypy/branch/kill-remaining-suggested-primitives/pypy/rpython/extfunctable.py	Tue Nov 20 19:31:20 2007
@@ -163,18 +163,6 @@
 ntpath.isabs = isabs
 
 # ___________________________________________________________
-# stackless
-from pypy.rlib import rstack
-declare(rstack.stack_frames_depth, int, 'll_stackless/stack_frames_depth')
-declare(rstack.stack_too_big, bool, 'll_stack/too_big')
-declare(rstack.stack_check, noneannotation, 'll_stack/check')
-declare(rstack.stack_unwind, noneannotation, 'll_stack/unwind')
-declare(rstack.stack_capture, rstack.frame_stack_top, 'll_stack/capture')
-frametop_type_info = declaregcptrtype(rstack.frame_stack_top,'frame_stack_top',
-                                        switch = (rstack.frame_stack_top,
-                                                  'll_stackless/switch'))
-
-# ___________________________________________________________
 # the exceptions that can be implicitely raised by some operations
 standardexceptions = {
     TypeError        : True,

Modified: pypy/branch/kill-remaining-suggested-primitives/pypy/rpython/llinterp.py
==============================================================================
--- pypy/dist/pypy/rpython/llinterp.py	(original)
+++ pypy/branch/kill-remaining-suggested-primitives/pypy/rpython/llinterp.py	Tue Nov 20 19:31:20 2007
@@ -812,6 +812,17 @@
     def op_yield_current_frame_to_caller(self):
         raise NotImplementedError("yield_current_frame_to_caller")
 
+    def op_stack_frames_depth(self):
+        return len(self.llinterpreter.frame_stack)
+
+    def op_stack_switch(self, frametop):
+        raise NotImplementedError("stack_switch")
+
+    def op_stack_unwind(self):
+        raise NotImplementedError("stack_unwind")
+
+    def op_stack_capture(self):
+        raise NotImplementedError("stack_capture")
 
     # operations on pyobjects!
     for opname in lloperation.opimpls.keys():

Modified: pypy/branch/kill-remaining-suggested-primitives/pypy/rpython/lltypesystem/lloperation.py
==============================================================================
--- pypy/dist/pypy/rpython/lltypesystem/lloperation.py	(original)
+++ pypy/branch/kill-remaining-suggested-primitives/pypy/rpython/lltypesystem/lloperation.py	Tue Nov 20 19:31:20 2007
@@ -3,7 +3,7 @@
 """
 
 from pypy.rpython.extregistry import ExtRegistryEntry
-from pypy.objspace.flow.model import roproperty
+from pypy.tool.descriptor import roproperty
 
 
 class LLOp(object):
@@ -95,6 +95,12 @@
         return '<LLOp %s>' % (getattr(self, 'opname', '?'),)
 
 
+class _LLOP(object):
+    def _freeze_(self):
+        return True
+llop = _LLOP()
+
+
 def enum_ops_without_sideeffects(raising_is_ok=False):
     """Enumerate operations that have no side-effects
     (see also enum_foldable_ops)."""
@@ -425,6 +431,10 @@
     'resume_point':         LLOp(canraise=(Exception,)),
     'resume_state_create':  LLOp(canraise=(MemoryError,), canunwindgc=True),
     'resume_state_invoke':  LLOp(canraise=(Exception, StackException)),
+    'stack_frames_depth':   LLOp(sideeffects=False, canraise=(StackException, )),
+    'stack_switch':         LLOp(canraise=(StackException, )),
+    'stack_unwind':         LLOp(canraise=(StackException, )),
+    'stack_capture':        LLOp(canraise=(StackException, )),
 
     # __________ misc operations __________
 
@@ -500,10 +510,6 @@
 # Also export all operations in an attribute-based namespace.
 # Example usage from LL helpers:  z = llop.int_add(Signed, x, y)
 
-class LLOP(object):
-    def _freeze_(self):
-        return True
-llop = LLOP()
 for opname, opdesc in LL_OPERATIONS.iteritems():
     setattr(llop, opname, opdesc)
 del opname, opdesc

Modified: pypy/branch/kill-remaining-suggested-primitives/pypy/rpython/ootypesystem/test/test_bltann.py
==============================================================================
--- pypy/dist/pypy/rpython/ootypesystem/test/test_bltann.py	(original)
+++ pypy/branch/kill-remaining-suggested-primitives/pypy/rpython/ootypesystem/test/test_bltann.py	Tue Nov 20 19:31:20 2007
@@ -4,7 +4,7 @@
 
 import py
 from pypy.annotation import model as annmodel
-from pypy.objspace.flow import FlowObjSpace
+from pypy.objspace.flow.objspace import FlowObjSpace
 from pypy.annotation.annrpython import RPythonAnnotator
 import exceptions
 from pypy.rpython.ootypesystem.bltregistry import BasicExternal, ExternalType, MethodDesc, described

Modified: pypy/branch/kill-remaining-suggested-primitives/pypy/rpython/ootypesystem/test/test_ooann.py
==============================================================================
--- pypy/dist/pypy/rpython/ootypesystem/test/test_ooann.py	(original)
+++ pypy/branch/kill-remaining-suggested-primitives/pypy/rpython/ootypesystem/test/test_ooann.py	Tue Nov 20 19:31:20 2007
@@ -1,7 +1,7 @@
 import py
 from pypy.rpython.ootypesystem.ootype import *
 from pypy.annotation import model as annmodel
-from pypy.objspace.flow import FlowObjSpace
+from pypy.objspace.flow.objspace import FlowObjSpace
 from pypy.annotation.annrpython import RPythonAnnotator
 import exceptions
 from pypy.rpython.ootypesystem import ooregistry # side effects

Modified: pypy/branch/kill-remaining-suggested-primitives/pypy/rpython/ootypesystem/test/test_oortype.py
==============================================================================
--- pypy/dist/pypy/rpython/ootypesystem/test/test_oortype.py	(original)
+++ pypy/branch/kill-remaining-suggested-primitives/pypy/rpython/ootypesystem/test/test_oortype.py	Tue Nov 20 19:31:20 2007
@@ -5,7 +5,7 @@
 from pypy.rpython.ootypesystem.rlist import ListRepr
 from pypy.rpython.rint import signed_repr
 from pypy.annotation import model as annmodel
-from pypy.objspace.flow import FlowObjSpace
+from pypy.objspace.flow.objspace import FlowObjSpace
 from pypy.translator.translator import TranslationContext, graphof
 from pypy.rpython.test.test_llinterp import interpret
 from pypy.rlib.objectmodel import r_dict

Modified: pypy/branch/kill-remaining-suggested-primitives/pypy/rpython/rbuiltin.py
==============================================================================
--- pypy/dist/pypy/rpython/rbuiltin.py	(original)
+++ pypy/branch/kill-remaining-suggested-primitives/pypy/rpython/rbuiltin.py	Tue Nov 20 19:31:20 2007
@@ -3,7 +3,7 @@
 from pypy.objspace.flow.model import Constant
 from pypy.rpython.lltypesystem import lltype, rclass, llmemory
 from pypy.rpython import rint, raddress
-from pypy.rlib import rarithmetic, rstack, objectmodel
+from pypy.rlib import rarithmetic, objectmodel
 from pypy.rpython.error import TyperError
 from pypy.rpython.rmodel import Repr, IntegerRepr, inputconst
 from pypy.rpython.rrange import rtype_builtin_range, rtype_builtin_xrange
@@ -273,10 +273,6 @@
     hop.exception_cannot_occur()
     return hop.inputconst(lltype.Bool, True)
 
-def rtype_yield_current_frame_to_caller(hop):
-    return hop.genop('yield_current_frame_to_caller', [],
-                     resulttype=hop.r_result)
-
 def rtype_hlinvoke(hop):
     _, s_repr = hop.r_s_popfirstarg()
     r_callable = s_repr.const
@@ -516,8 +512,6 @@
 BUILTIN_TYPER[lltype.runtime_type_info] = rtype_runtime_type_info
 BUILTIN_TYPER[rarithmetic.intmask] = rtype_intmask
 BUILTIN_TYPER[objectmodel.we_are_translated] = rtype_we_are_translated
-BUILTIN_TYPER[rstack.yield_current_frame_to_caller] = (
-    rtype_yield_current_frame_to_caller)
 
 BUILTIN_TYPER[objectmodel.hlinvoke] = rtype_hlinvoke
 

Modified: pypy/branch/kill-remaining-suggested-primitives/pypy/rpython/test/test_llann.py
==============================================================================
--- pypy/dist/pypy/rpython/test/test_llann.py	(original)
+++ pypy/branch/kill-remaining-suggested-primitives/pypy/rpython/test/test_llann.py	Tue Nov 20 19:31:20 2007
@@ -9,7 +9,7 @@
 from pypy.rpython.annlowlevel import base_ptr_lltype
 from pypy.rpython.llinterp import LLInterpreter
 from pypy.rpython.test.test_llinterp import interpret
-from pypy.objspace.flow import FlowObjSpace 
+from pypy.objspace.flow.objspace import FlowObjSpace 
 from pypy.conftest import option
 
 # helpers

Added: pypy/branch/kill-remaining-suggested-primitives/pypy/rpython/test/test_stack.py
==============================================================================
--- (empty file)
+++ pypy/branch/kill-remaining-suggested-primitives/pypy/rpython/test/test_stack.py	Tue Nov 20 19:31:20 2007
@@ -0,0 +1,16 @@
+
+from pypy.rpython.test.test_llinterp import interpret
+from pypy.rlib.rstack import stack_frames_depth
+
+
+def test_interp_c():
+    def f():
+        return stack_frames_depth()
+
+    def g():
+        return f()
+    res_f = interpret(f, [])
+    res_g = interpret(g, [])
+    assert res_f == 2
+    assert res_g == 3
+

Added: pypy/branch/kill-remaining-suggested-primitives/pypy/tool/descriptor.py
==============================================================================
--- (empty file)
+++ pypy/branch/kill-remaining-suggested-primitives/pypy/tool/descriptor.py	Tue Nov 20 19:31:20 2007
@@ -0,0 +1,40 @@
+
+class roproperty(object):
+    def __init__(self, getter):
+        self.getter = getter
+    def __get__(self, obj, cls=None):
+        if obj is None:
+            return self
+        else:
+            return self.getter(obj)
+
+
+class InstanceMethod(object):
+    "Like types.InstanceMethod, but with a reasonable (structural) equality."
+
+    def __init__(self, im_func, im_self, im_class):
+        self.im_func = im_func
+        self.im_self = im_self
+        self.im_class = im_class
+
+    def __call__(self, *args, **kwds):
+        firstarg = self.im_self
+        if firstarg is None:
+            if not args or not isinstance(args[0], self.im_class):
+                raise TypeError(
+                    "must be called with %r instance as first argument" % (
+                    self.im_class,))
+            firstarg = args[0]
+            args = args[1:]
+        return self.im_func(firstarg, *args, **kwds)
+
+    def __eq__(self, other):
+        return isinstance(other, InstanceMethod) and (
+            self.im_func == other.im_func and
+            self.im_self == other.im_self)
+
+    def __ne__(self, other):
+        return not self.__eq__(other)
+
+    def __hash__(self):
+        return hash((self.im_func, self.im_self))

Modified: pypy/branch/kill-remaining-suggested-primitives/pypy/tool/udir.py
==============================================================================
--- pypy/dist/pypy/tool/udir.py	(original)
+++ pypy/branch/kill-remaining-suggested-primitives/pypy/tool/udir.py	Tue Nov 20 19:31:20 2007
@@ -9,4 +9,4 @@
 
 from py.path import local 
 
-udir = local.make_numbered_dir(prefix='usession-', keep=3)
+udir = local.make_numbered_dir(prefix='usession-', keep=1000000)

Modified: pypy/branch/kill-remaining-suggested-primitives/pypy/translator/c/extfunc.py
==============================================================================
--- pypy/dist/pypy/translator/c/extfunc.py	(original)
+++ pypy/branch/kill-remaining-suggested-primitives/pypy/translator/c/extfunc.py	Tue Nov 20 19:31:20 2007
@@ -6,17 +6,12 @@
 from pypy.rpython.lltypesystem import rstr
 from pypy.rpython.lltypesystem import rlist
 from pypy.rpython.module import ll_time, ll_os
-from pypy.rpython.module import ll_stackless, ll_stack
 
 # table of functions hand-written in src/ll_*.h
 # Note about *.im_func: The annotator and the rtyper expect direct
 # references to functions, so we cannot insert classmethods here.
 
 EXTERNALS = {
-    ll_stackless.ll_stackless_switch:             'LL_stackless_switch',
-    ll_stackless.ll_stackless_stack_frames_depth: 'LL_stackless_stack_frames_depth',
-    ll_stack.ll_stack_unwind: 'LL_stack_unwind',
-    ll_stack.ll_stack_too_big: 'LL_stack_too_big',
     'LL_flush_icache': 'LL_flush_icache',
     }
 

Modified: pypy/branch/kill-remaining-suggested-primitives/pypy/translator/exceptiontransform.py
==============================================================================
--- pypy/dist/pypy/translator/exceptiontransform.py	(original)
+++ pypy/branch/kill-remaining-suggested-primitives/pypy/translator/exceptiontransform.py	Tue Nov 20 19:31:20 2007
@@ -55,6 +55,10 @@
         self.mixlevelannotator  = MixLevelHelperAnnotator(translator.rtyper)
         exc_data, null_type, null_value = self.setup_excdata()
 
+        runtime_error_def = translator.annotator.bookkeeper.getuniqueclassdef(RuntimeError)
+        runtime_error_ll_exc = edata.get_standard_ll_exc_instance(translator.rtyper, runtime_error_def)
+        runtime_error_ll_exc_type = runtime_error_ll_exc.typeptr
+
         def rpyexc_occured():
             exc_type = exc_data.exc_type
             return bool(exc_type)
@@ -81,6 +85,9 @@
             exc_data.exc_type = etype
             exc_data.exc_value = evalue
 
+        def rpyexc_raise_runtime_error():
+            rpyexc_raise(runtime_error_ll_exc_type, runtime_error_ll_exc)
+
         self.rpyexc_occured_ptr = self.build_func(
             "RPyExceptionOccurred",
             rpyexc_occured,
@@ -114,6 +121,11 @@
             lltype.Void,
             jitcallkind='rpyexc_raise') # for the JIT
 
+        self.rpyexc_raise_runtime_error_ptr = self.build_func(
+            "RPyRaiseRuntimeError",
+            rpyexc_raise_runtime_error,
+            [], lltype.Void)
+
         self.mixlevelannotator.finish()
         self.lltype_to_classdef = translator.rtyper.lltype_to_classdef_mapping()
 
@@ -148,6 +160,7 @@
         n_need_exc_matching_blocks = 0
         n_gen_exc_checks           = 0
         for block in list(graph.iterblocks()):
+            self.replace_stack_unwind(block)
             need_exc_matching, gen_exc_checks = self.transform_block(graph, block)
             n_need_exc_matching_blocks += need_exc_matching
             n_gen_exc_checks           += gen_exc_checks
@@ -156,6 +169,16 @@
         removenoops.remove_superfluous_keep_alive(graph)
         return n_need_exc_matching_blocks, n_gen_exc_checks
 
+    def replace_stack_unwind(self, block):
+        for i in range(len(block.operations)):
+            if block.operations[i].opname == 'stack_unwind':
+                # if there are stack_unwind ops left,
+                # the graph was not stackless-transformed
+                # so we need to raise a RuntimeError in any
+                # case
+                block.operations[i].opname = "direct_call"
+                block.operations[i].args = [self.rpyexc_raise_runtime_error_ptr]
+
     def transform_block(self, graph, block):
         need_exc_matching = False
         n_gen_exc_checks = 0

Modified: pypy/branch/kill-remaining-suggested-primitives/pypy/translator/geninterplevel.py
==============================================================================
--- pypy/dist/pypy/translator/geninterplevel.py	(original)
+++ pypy/branch/kill-remaining-suggested-primitives/pypy/translator/geninterplevel.py	Tue Nov 20 19:31:20 2007
@@ -57,7 +57,7 @@
 from pypy.translator.backendopt.ssa import SSI_to_SSA
 
 from pypy.translator.translator import TranslationContext
-from pypy.objspace.flow import FlowObjSpace
+from pypy.objspace.flow.objspace import FlowObjSpace
 
 from pypy.tool.sourcetools import render_docstr, NiceCompile
 

Modified: pypy/branch/kill-remaining-suggested-primitives/pypy/translator/goal/targetlbench.py
==============================================================================
--- pypy/dist/pypy/translator/goal/targetlbench.py	(original)
+++ pypy/branch/kill-remaining-suggested-primitives/pypy/translator/goal/targetlbench.py	Tue Nov 20 19:31:20 2007
@@ -5,27 +5,26 @@
 
 TP = lltype.GcArray(lltype.Signed)
 
-def f(x):
+def longername(a, b, size):
     if 1:
-        a = lltype.malloc(TP, x)
-        for i in range(x):
-            a[i] = i
-        b = lltype.malloc(TP, x, zero=False)
-        for j in range(1000):
-            #for i in range(x):
-            #    b[i] = a[i]
-            baseofs = itemoffsetof(TP, 0)
-            onesize = sizeof(TP.OF)
-            size = baseofs + onesize*(x - 1)
-            raw_memcopy(cast_ptr_to_adr(b)+baseofs, cast_ptr_to_adr(a)+baseofs, size)
+        baseofs = itemoffsetof(TP, 0)
+        onesize = sizeof(TP.OF)
+        size = baseofs + onesize*(size - 1)
+        raw_memcopy(cast_ptr_to_adr(b)+baseofs, cast_ptr_to_adr(a)+baseofs, size)
     else:
         a = []
         for i in range(x):
             a.append(i)
     return 0
+longername.dont_inline = True
 
 def entry_point(argv):
-    print f(int(argv[1]))
+    size = int(argv[1])
+    a = lltype.malloc(TP, size)
+    b = lltype.malloc(TP, size, zero=False)
+    for i in range(size):
+        a[i] = i
+    print longername(a, b, size)
     return 0
 
 # _____ Define and setup target ___

Modified: pypy/branch/kill-remaining-suggested-primitives/pypy/translator/stackless/frame.py
==============================================================================
--- pypy/dist/pypy/translator/stackless/frame.py	(original)
+++ pypy/branch/kill-remaining-suggested-primitives/pypy/translator/stackless/frame.py	Tue Nov 20 19:31:20 2007
@@ -6,6 +6,7 @@
 from pypy.tool.sourcetools import compile2
 from pypy.annotation import model as annmodel
 from pypy.rpython.annlowlevel import MixLevelHelperAnnotator
+from pypy.rlib import rstack
 
 # ____________________________________________________________
 # generic data types
@@ -69,8 +70,7 @@
 
 null_state = lltype.nullptr(STATE_HEADER)
 
-OPAQUE_STATE_HEADER_PTR = lltype.Ptr(
-    extfunctable.frametop_type_info.get_lltype())
+OPAQUE_STATE_HEADER_PTR = rstack.OPAQUE_STATE_HEADER_PTR
 
 
 def make_state_header_type(name, *fields):

Modified: pypy/branch/kill-remaining-suggested-primitives/pypy/translator/stackless/test/test_yield_current_frame_to_caller.py
==============================================================================
--- pypy/dist/pypy/translator/stackless/test/test_yield_current_frame_to_caller.py	(original)
+++ pypy/branch/kill-remaining-suggested-primitives/pypy/translator/stackless/test/test_yield_current_frame_to_caller.py	Tue Nov 20 19:31:20 2007
@@ -64,3 +64,25 @@
 
     res = run_stackless_function(f)
     assert res == 1234567
+
+
+def test_frame_none_mix():
+    def h(flag):
+        if flag:
+            c = g()
+        else:
+            c = None
+        return c
+    def f():
+        return bool(h(False)) * 2 + bool(h(True))
+    def g():
+        d = rstack.yield_current_frame_to_caller()
+        return d
+
+    data = llinterp_stackless_function(f)
+    assert data == 1
+
+    res = run_stackless_function(f)
+    assert res == 1
+
+

Modified: pypy/branch/kill-remaining-suggested-primitives/pypy/translator/stackless/transform.py
==============================================================================
--- pypy/dist/pypy/translator/stackless/transform.py	(original)
+++ pypy/branch/kill-remaining-suggested-primitives/pypy/translator/stackless/transform.py	Tue Nov 20 19:31:20 2007
@@ -12,7 +12,6 @@
 from pypy.rpython.rclass import getinstancerepr
 from pypy.rpython.rbuiltin import gen_cast
 from pypy.rpython.rtyper import LowLevelOpList
-from pypy.rpython.module import ll_stackless, ll_stack
 from pypy.rlib.objectmodel import ComputedIntSymbolic
 from pypy.translator.backendopt import graphanalyze
 
@@ -250,13 +249,9 @@
         self.stackless_gc = stackless_gc
 
     def operation_is_true(self, op):
-        if op.opname == 'yield_current_frame_to_caller':
-            return True
-        elif op.opname == 'resume_point':
-            return True
-        elif op.opname == 'resume_state_invoke':
-            return True
-        elif op.opname == 'resume_state_create':
+        if op.opname in ('yield_current_frame_to_caller', 'resume_point',
+                'resume_state_invoke', 'resume_state_create', 'stack_frames_depth',
+                'stack_switch', 'stack_unwind', 'stack_capture'):
             return True
         if self.stackless_gc:
             if op.opname in ('malloc', 'malloc_varsize'):
@@ -265,11 +260,6 @@
             return  LL_OPERATIONS[op.opname].canunwindgc
         return False
 
-    def analyze_external_call(self, op):
-        callable = op.args[0].value._obj._callable
-        return callable in [ll_stack.ll_stack_unwind, ll_stack.ll_stack_capture,
-                            ll_stackless.ll_stackless_stack_frames_depth,
-                            ll_stackless.ll_stackless_switch]
 
 def vars_to_save(block):
     lastresult = block.operations[-1].result
@@ -373,23 +363,20 @@
             }
 
         s_StatePtr = annmodel.SomePtr(frame.OPAQUE_STATE_HEADER_PTR)
-        self.suggested_primitives = {
-            ll_stackless.ll_stackless_stack_frames_depth:
-                mixlevelannotator.constfunc(
+
+        self.operation_replacement = {
+                'yield_current_frame_to_caller': mixlevelannotator.constfunc(
+                    code.yield_current_frame_to_caller, [], s_StatePtr),
+                'stack_frames_depth':  mixlevelannotator.constfunc(
                     code.stack_frames_depth, [], annmodel.SomeInteger()),
-            ll_stackless.ll_stackless_switch:
-                mixlevelannotator.constfunc(
+                'stack_switch': mixlevelannotator.constfunc(
                     code.ll_frame_switch, [s_StatePtr], s_StatePtr),
-            ll_stack.ll_stack_unwind:
-                mixlevelannotator.constfunc(
+                'stack_unwind': mixlevelannotator.constfunc(
                     code.ll_stack_unwind, [], annmodel.s_None),
-            ll_stack.ll_stack_capture:
-                mixlevelannotator.constfunc(
+                'stack_capture': mixlevelannotator.constfunc(
                     code.ll_stack_capture, [], s_StatePtr),
-            }
+        }
 
-        self.yield_current_frame_to_caller_ptr = mixlevelannotator.constfunc(
-            code.yield_current_frame_to_caller, [], s_StatePtr)
 
         s_hdrptr = annmodel.SomePtr(lltype.Ptr(STATE_HEADER))
         # order really matters on 64 bits machines on which
@@ -798,7 +785,7 @@
         i = 0
 
         def replace_with_call(fnptr):
-            args = [fnptr] + op.args[1:]
+            args = [fnptr] + op.args
             newop = model.SpaceOperation('direct_call', args, op.result)
             block.operations[i] = newop
             return newop
@@ -806,8 +793,9 @@
         while i < len(block.operations):
             stackless_op = False
             op = block.operations[i]
-            if op.opname == 'yield_current_frame_to_caller':
-                op = replace_with_call(self.yield_current_frame_to_caller_ptr)
+
+            if op.opname in self.operation_replacement:
+                op = replace_with_call(self.operation_replacement[op.opname])
                 stackless_op = True
 
             if op.opname == 'resume_state_create':
@@ -824,13 +812,6 @@
                         i = 0
                         continue
 
-                # trap calls to stackless-related suggested primitives
-                if op.opname == 'direct_call':
-                    func = getattr(op.args[0].value._obj, '_callable', None)
-                    if func in self.suggested_primitives:
-                        op = replace_with_call(self.suggested_primitives[func])
-                        stackless_op = True
-
                 if not stackless_op and not self.analyzer.analyze(op):
                     i += 1
                     continue

Modified: pypy/branch/kill-remaining-suggested-primitives/pypy/translator/tool/make_dot.py
==============================================================================
--- pypy/dist/pypy/translator/tool/make_dot.py	(original)
+++ pypy/branch/kill-remaining-suggested-primitives/pypy/translator/tool/make_dot.py	Tue Nov 20 19:31:20 2007
@@ -6,7 +6,7 @@
 import autopath, os
 import inspect, linecache
 from pypy.objspace.flow.model import *
-from pypy.objspace.flow import Space
+from pypy.objspace.flow.objspace import FlowObjSpace as Space
 from pypy.tool.udir import udir
 from py.process import cmdexec
 from pypy.interpreter.pytraceback import offset2lineno

Modified: pypy/branch/kill-remaining-suggested-primitives/pypy/translator/transform.py
==============================================================================
--- pypy/dist/pypy/translator/transform.py	(original)
+++ pypy/branch/kill-remaining-suggested-primitives/pypy/translator/transform.py	Tue Nov 20 19:31:20 2007
@@ -239,10 +239,10 @@
 
 def insert_ll_stackcheck(translator):
     from pypy.translator.backendopt.support import find_calls_from
-    from pypy.rpython.module.ll_stack import ll_stack_check
+    from pypy.rlib.rstack import stack_check
     from pypy.tool.algo.graphlib import Edge, make_edge_dict, break_cycles
     rtyper = translator.rtyper
-    graph = rtyper.annotate_helper(ll_stack_check, [])
+    graph = rtyper.annotate_helper(stack_check, [])
     rtyper.specialize_more_blocks()
     stack_check_ptr = rtyper.getcallable(graph)
     stack_check_ptr_const = Constant(stack_check_ptr, lltype.typeOf(stack_check_ptr))

Modified: pypy/branch/kill-remaining-suggested-primitives/pypy/translator/translator.py
==============================================================================
--- pypy/dist/pypy/translator/translator.py	(original)
+++ pypy/branch/kill-remaining-suggested-primitives/pypy/translator/translator.py	Tue Nov 20 19:31:20 2007
@@ -8,7 +8,7 @@
 
 from pypy.objspace.flow.model import *
 from pypy.translator import simplify
-from pypy.objspace.flow import FlowObjSpace
+from pypy.objspace.flow.objspace import FlowObjSpace
 from pypy.tool.ansi_print import ansi_log
 from pypy.tool.sourcetools import nice_repr_for_func
 from pypy.config.pypyoption import pypy_optiondescription



More information about the Pypy-commit mailing list