Debian Codegraph @

rpython/rtyper/extfuncregistry.py

raw symbols SCIP
1 # this registry uses the new interface for external functions
2
3 from rpython.rtyper.extfunc import register_external
4
5 # Register replacement functions for builtin functions
6 from rpython.rlib import rposix, rposix_stat, rposix_environ
7 from rpython.rlib import rtime
8
9 # ___________________________
10 # math functions
11
12 import math
13 from rpython.rtyper.lltypesystem.module import ll_math
14 from rpython.rlib import rfloat
15
16 # the following functions all take one float, return one float
17 # and are part of math.h
18 for name in ll_math.unary_math_functions:
19 llimpl = getattr(ll_math, 'll_math_%s' % name, None)
20 try:
21 f = getattr(math, name)
22 except AttributeError:
23 f = getattr(rfloat, name)
24 register_external(f, [float], float,
25 export_name="ll_math.ll_math_%s" % name,
26 sandboxsafe=True, llimpl=llimpl)
27
28 _register = [ # (module, [(method name, arg types, return type), ...], ...)
29 (rfloat, [
30 ('isfinite', [float], bool),
31 ]),
32 (math, [
33 ('copysign', [float, float], float),
34 ('isinf', [float], bool),
35 ('isnan', [float], bool),
36 ('floor', [float], float),
37 ('sqrt', [float], float),
38 ('log', [float], float),
39 ('log10', [float], float),
40 ('log1p', [float], float),
41 ('sin', [float], float),
42 ('cos', [float], float),
43 ('atan2', [float, float], float),
44 ('hypot', [float, float], float),
45 ('frexp', [float], (float, int)),
46 ('ldexp', [float, int], float),
47 ('modf', [float], (float, float)),
48 ('fmod', [float, float], float),
49 ('pow', [float, float], float),
50 ]),
51 ]
52 for module, methods in _register:
53 for name, arg_types, return_type in methods:
54 method_name = 'll_math_%s' % name
55 register_external(getattr(module, name), arg_types, return_type,
56 export_name='ll_math.%s' % method_name,
57 sandboxsafe=True,
58 llimpl=getattr(ll_math, method_name))