Commits

Alex Gaynor  committed 3452112

Some files that should be removed.

  • Participants
  • Parent commits 0425059
  • Branches kill-someobject

Comments (0)

Files changed (3)

File pypy/rpython/test/test_robject.py

-from pypy.rpython.lltypesystem.lltype import *
-from pypy.rpython.test.test_llinterp import interpret
-
-
-def test_simple():
-    def fn(obj):
-        return obj + 1
-    _1L = pyobjectptr(1L)
-    res = interpret(fn, [_1L], someobjects=True)
-    assert res._obj.value == 2L
-
-def test_obj_obj_dict():
-    def f(i, c):
-        d = {}
-        d[1] = 'a'
-        d['a'] = i
-        d['ab'] = c
-        d[i] = c
-        return len(d)
-    res = interpret(f, [2, 'c'], someobjects=True)
-    assert res == 4
-    res = interpret(f, [3, 'c'], someobjects=True)
-    assert res == 4
-
-def test_obj_list():
-    def f(i, c):
-        lis = [1, 2, 3, 4]
-        lis[i] = c
-        lis.append(i)
-        return len(lis)
-    res = interpret(f, [2, 'c'], someobjects=True)
-    assert res == 5
-    res = interpret(f, [3, 'c'], someobjects=True)
-    assert res == 5
-
-def test_obj_iter():
-    def f(flag):
-        if flag:
-            x = (1, 2)
-        else:
-            x = '34'
-        lst = [u for u in x]
-        return lst[flag]
-    res = interpret(f, [1], someobjects=True)
-    assert res._obj.value == 2
-    res = interpret(f, [0], someobjects=True)
-    assert res._obj.value == '3'
-
-def test_listofobj_iter():
-    def f(look):
-        lst = ['*', 2, 5]
-        for u in lst:
-            if u == look:
-                return True
-        return False
-    res = interpret(f, [1], someobjects=True)
-    assert res is False
-    res = interpret(f, [2], someobjects=True)
-    assert res is True

File pypy/translator/llsupport/test/test_wrapper.py

-import py
-from pypy import conftest
-from pypy.translator.translator import TranslationContext
-from pypy.translator.llsupport.wrapper import new_wrapper
-from pypy.rpython.rmodel import PyObjPtr
-from pypy.rpython.llinterp import LLInterpreter
-from pypy.rpython.lltypesystem import lltype
-
-
-class TestMakeWrapper:
-
-    def getgraph(self, func, argtypes=None):
-        from pypy.config.pypyoption import get_pypy_config
-        config = get_pypy_config(translating=True)
-        config.translation.gc = "ref"
-        config.translation.simplifying = True
-        t = TranslationContext(config=config)
-        if argtypes is None:
-            argtypes = []
-        a = t.buildannotator()
-        a.build_types(func, argtypes)
-        a.simplify()
-        t.buildrtyper().specialize()
-        wrapperptr = new_wrapper(func, t)
-        wrappergraph = wrapperptr._obj.graph
-        F = lltype.typeOf(wrapperptr).TO
-        assert F.ARGS == (PyObjPtr,) * len(wrappergraph.getargs())
-        assert F.RESULT == PyObjPtr
-
-        for inputarg in wrappergraph.getargs():
-            assert inputarg.concretetype == PyObjPtr
-        assert wrappergraph.getreturnvar().concretetype == PyObjPtr
-        return t.graphs[0], wrappergraph, t
-
-    def interpret(self, t, graph, *args):
-        interp = LLInterpreter(t.rtyper)
-        result = interp.eval_graph(graph, [lltype.pyobjectptr(arg)
-                                               for arg in args])
-        return result._obj.value
-
-    def test_simple(self):
-        def f(x):
-            return x * 3
-        graph, wrappergraph, t = self.getgraph(f, [int])
-        res = self.interpret(t, wrappergraph, 3)
-        assert res == 9
-
-    def test_manyargs(self):
-        def f(x, y, z):
-            return x * y + z
-        graph, wrappergraph, t = self.getgraph(f, [int, int, int])
-        res = self.interpret(t, wrappergraph, 3, 4, 5)
-        assert res == 3 * 4 + 5
-
-    def test_returnnone(self):
-        def f():
-            pass
-        graph, wrappergraph, t = self.getgraph(f)
-        res = self.interpret(t, wrappergraph)
-        assert res is None

File pypy/translator/llsupport/wrapper.py

-from pypy.objspace.flow.model import Variable
-from pypy.objspace.flow.model import Block, Link, FunctionGraph, checkgraph
-from pypy.rpython.lltypesystem.lltype import \
-     Ptr, PyObject, typeOf, Signed, FuncType, functionptr, nullptr, Void
-from pypy.rpython.rtyper import LowLevelOpList
-from pypy.rpython.rmodel import inputconst, PyObjPtr
-from pypy.rpython.robject import pyobj_repr
-
-from pypy.rpython.typesystem import getfunctionptr
-
-
-
-def new_wrapper(func, translator, newname=None):
-    # The basic idea is to produce a flow graph from scratch, using the
-    # help of the rtyper for the conversion of the arguments after they
-    # have been decoded.
-    
-    bk = translator.annotator.bookkeeper
-    graph = bk.getdesc(func).getuniquegraph()
-
-    f = getfunctionptr(graph)
-    FUNCTYPE = typeOf(f).TO
-
-    newops = LowLevelOpList(translator.rtyper)
-
-    varguments = []
-    for var in graph.startblock.inputargs:
-        v = Variable(var)
-        v.concretetype = PyObjPtr
-        varguments.append(v)
-
-    wrapper_inputargs = varguments[:]
-    # use the rtyper to produce the conversions
-    inputargs = f._obj.graph.getargs()
-    for i in range(len(varguments)):
-        if FUNCTYPE.ARGS[i] != PyObjPtr:
-            rtyper = translator.rtyper
-            r_arg = rtyper.bindingrepr(inputargs[i])
-            # give the rtyper a chance to know which function we are wrapping
-            rtyper.set_wrapper_context(func)
-            varguments[i] = newops.convertvar(varguments[i],
-                                              r_from = pyobj_repr,
-                                              r_to = r_arg)
-            rtyper.set_wrapper_context(None)
-
-    vlist = [inputconst(typeOf(f), f)] + varguments
-    vresult = newops.genop('direct_call', vlist, resulttype=FUNCTYPE.RESULT)
-
-    if FUNCTYPE.RESULT != PyObjPtr:
-        # convert "result" back to a PyObject
-        rtyper = translator.rtyper
-        assert rtyper is not None, (
-            "needs the rtyper to perform function result conversions")
-        r_result = rtyper.bindingrepr(f._obj.graph.getreturnvar())
-        vresult = newops.convertvar(vresult,
-                                    r_from = r_result,
-                                    r_to = pyobj_repr)
-
-    # "return result"
-    block = Block(wrapper_inputargs)
-    wgraph = FunctionGraph('pyfn_' + (newname or func.func_name), block)
-    translator.update_call_graph(wgraph, graph, object())
-    translator.graphs.append(wgraph)
-    block.operations[:] = newops
-    block.closeblock(Link([vresult], wgraph.returnblock))
-    wgraph.getreturnvar().concretetype = PyObjPtr
-    checkgraph(wgraph)
-
-    # the above convertvar()s may have created and annotated new helpers
-    # that need to be specialized now
-    translator.rtyper.specialize_more_blocks()
-
-    return functionptr(FuncType([PyObjPtr] * len(wrapper_inputargs),
-                                PyObjPtr),
-                       wgraph.name,
-                       graph = wgraph,
-                       exception_policy = "CPython")
-