[pypy-svn] r25969 - in pypy/dist/pypy: rpython/lltypesystem translator/c/test
tismer at codespeak.net
tismer at codespeak.net
Wed Apr 19 07:24:19 CEST 2006
Author: tismer
Date: Wed Apr 19 07:24:16 2006
New Revision: 25969
Modified:
pypy/dist/pypy/rpython/lltypesystem/rslice.py
pypy/dist/pypy/translator/c/test/test_wrapping.py
Log:
some builtin support and some slicing. a bit tedious, should avoid spending too much time
Modified: pypy/dist/pypy/rpython/lltypesystem/rslice.py
==============================================================================
--- pypy/dist/pypy/rpython/lltypesystem/rslice.py (original)
+++ pypy/dist/pypy/rpython/lltypesystem/rslice.py Wed Apr 19 07:24:16 2006
@@ -1,6 +1,9 @@
from pypy.rpython.rslice import AbstractSliceRepr
from pypy.rpython.lltypesystem.lltype import \
- GcStruct, Signed, Ptr, Void, malloc
+ GcStruct, Signed, Ptr, Void, malloc, PyObject, nullptr
+from pypy.annotation.pairtype import pairtype
+from pypy.rpython.robject import PyObjRepr, pyobj_repr
+from pypy.rpython.rmodel import inputconst, PyObjPtr, IntegerRepr
# ____________________________________________________________
#
@@ -36,3 +39,27 @@
s.stop = stop
return s
+# ____________________________________________________________
+#
+# limited support for casting into PyObject
+
+# stuff like this should go into one file maybe
+
+class __extend__(pairtype(SliceRepr, PyObjRepr)):
+ def convert_from_to((r_from, r_to), v, llops):
+ null = inputconst(Ptr(PyObject), nullptr(PyObject))
+ def pyint(v):
+ return llops.gencapicall('PyInt_FromLong', [v], resulttype=r_to)
+ v_step = v_start = v_stop = null
+ if r_from.lowleveltype is Signed:
+ v_start = pyint(v)
+ elif r_from.lowleveltype is Void:
+ v_stop = inputconst(r_to, -1)
+ else:
+ v_start = pyint(llops.genop('getfield', [v, inputconst(Void, 'start')],
+ resulttype=Signed))
+ v_stop = pyint(llops.genop('getfield', [v, inputconst(Void, 'stop')],
+ resulttype=Signed))
+ return llops.gencapicall('PySlice_New',
+ [v_start, v_stop, v_step],
+ resulttype = pyobj_repr)
Modified: pypy/dist/pypy/translator/c/test/test_wrapping.py
==============================================================================
--- pypy/dist/pypy/translator/c/test/test_wrapping.py (original)
+++ pypy/dist/pypy/translator/c/test/test_wrapping.py Wed Apr 19 07:24:16 2006
@@ -5,6 +5,7 @@
from pypy.annotation import model as annmodel
from pypy.rpython.lltypesystem import lltype
from pypy.rpython import robject, rclass
+from pypy.translator.tool.cbuild import enable_fast_compilation
import sys
@@ -214,20 +215,53 @@
# _______________________________________________
# creating our own setup function for the module
+# this class *can* be used for faster access.
+# the compiler anyway chews quite a bit on it...
+class BuiltinHelper(object):
+ # the following would be much easier if we had
+ # loop unrolling right inside the flowing process
+ src = []
+ src.append('def __init__(self):')
+ src.append(' import __builtin__ as b')
+ import __builtin__
+ for name in dir(__builtin__):
+ obj = getattr(__builtin__, name)
+ if callable(obj) and hasattr(obj, '__name__'):
+ src.append(' self.%s = b.%s' % (name, obj.__name__))
+ src = '\n'.join(src)
+ #print src
+ exec src
+ del __builtin__, name, obj, src
+
def setup_new_module(mod, modname):
# note the name clash with py.test on setup_module
import types
m = types.ModuleType(modname)
allobjs = mod.__dict__.values()
funcs = eval('[]') # or import list from __builtin__
- from twisted.internet import reactor
- print dir(reactor)
+ # one alternative
+ #bltn = BuiltinHelper()
+ # less code:
+ import __builtin__ as bltn
+ print bltn.list('hallo')
+ #from twisted.internet import reactor
+ #print dir(reactor)
#whow this works
isinstance = eval('isinstance')
+ # above is possible, this is probably a better compromise:
+ isinstance = bltn.isinstance
for obj in allobjs:
if isinstance(obj, types.FunctionType):
funcs.append( (obj.func_name, obj) )
print 'funcs=', funcs
+ print funcs[3:]
+ #funcs += [2, 3, 5]
+ # not yet
+ stuff = bltn.range(10)
+ print stuff[3:]
+ print stuff[:3]
+ print stuff[3:7]
+ print stuff[:-1]
funcs.sort()
return m
More information about the Pypy-commit
mailing list