[pypy-dev] missing things for making PyPy "production" ready (for some value of production)
Antonio Cuni
anto.cuni at gmail.com
Wed Nov 14 19:20:54 CET 2007
Douglas McNeil wrote:
> This is probably the most low-hanging fruit there could be for a (fully
> float-aware) JIT. The functions tends to be embarrassingly simple, and
> seldom leave the int/float/list domain. Most numerical code is borderline
> RPython as-is.
if everything you need is to execute some function that plays with
numbers even at the costs of losing some python semantics (e.g.,
automatic int to long promotion), maybe RPython can do the job.
Create the following file as pypy/translator/goal/targetfibo.py
def target(*args):
return fibo, [int]
def fibo(N):
"calculates the Nth fibonacci number"
a, b = 1, 1
for i in range(N-1):
a, b = b, a+b
return a
Then, translate it:
$ cd /path/to/pypy/translator/goal:
$ ./translate.py --batch targetfibo.py
$ /tmp/usession-${USER}/testing_1
Here you can find the file testing_1.so that can be imported in CPython
as a module; the module contains the function fibo you defined above:
>>> import testing_1
>>> map(testing_1.fibo, range(1, 10))
[1, 1, 2, 3, 5, 8, 13, 21, 34]
=====================
== BIG FAT WARNING ==
=====================
I don't think we want to officially support this feature, and might
suddenly stop working at any time. Moreover, there are a lot of drawbacks:
- it can crash your python interpreter: e.g., if I try to divide by 0
inside the rpython function without a try/except block, my python prints
"Floating point exception", then crashes. Segfaults could happily
happens, too;
- only few input/output types are supported; it should work with int,
float and str; list and dictionaries are not supported (you can use them
inside your function, but they can't cross the borders);
Anyway, if all you need is to work with numbers and no much more, this
might fit your needs.
Just to make it clear, I'm not talking about the extcompiler: this is
another piece of code which in theory does not suffer from the problems
above and offers much more, but its status is not clear at the moment
and will probably be rewritten soon or later.
ciao Anto
More information about the Pypy-dev
mailing list