Commit 3a013576 authored by Kevin Modzelewski's avatar Kevin Modzelewski

Merge pull request #134 from undingen/mathmodule

Import math module
parents ec1b3848 6c3f703d
......@@ -24,21 +24,13 @@
#include <string.h>
#include <limits.h>
// These belong in pyconfig.h:
#define HAVE_STDARG_PROTOTYPES
#define HAVE_LONG_LONG 1
#define PY_LONG_LONG long long
#define SIZEOF_VOID_P 8
#define SIZEOF_SIZE_T 8
#define SIZEOF_INT 4
// These include orders come from CPython:
#include "patchlevel.h"
#include "pyconfig.h"
#include "pyport.h"
#include "pymath.h"
#include "pymem.h"
#include "object.h"
......@@ -74,6 +66,8 @@
/* Argument must be a char or an int in [-128, 127] or [0, 255]. */
#define Py_CHARMASK(c) ((unsigned char)((c) & 0xff))
#include "pyfpe.h"
#ifdef __cplusplus
extern "C" {
#endif
......
......@@ -61,7 +61,9 @@ PyAPI_FUNC(PyObject *) PyFloat_FromDouble(double);
/* Extract C double from Python float. The macro version trades safety for
speed. */
PyAPI_FUNC(double) PyFloat_AsDouble(PyObject *);
#define PyFloat_AS_DOUBLE(op) (((PyFloatObject *)(op))->ob_fval)
// Pyston changes: these aren't direct macros any more [they potentially could be though]
#define PyFloat_AS_DOUBLE(op) PyFloat_AsDouble(op)
//#define PyFloat_AS_DOUBLE(op) (((PyFloatObject *)(op))->ob_fval)
/* Write repr(v) into the char buffer argument, followed by null byte. The
buffer must be "big enough"; >= 100 is very safe.
......
// Copyright (c) 2014 Dropbox, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// TODO: In the future this file should get generated by the build process.
#ifndef Py_PYCONFIG_H
#define Py_PYCONFIG_H
#define HAVE_STDARG_PROTOTYPES
#define HAVE_LONG_LONG 1
#define PY_LONG_LONG long long
#define SIZEOF_VOID_P 8
#define SIZEOF_SIZE_T 8
#define SIZEOF_INT 4
#define HAVE_COPYSIGN 1
#define HAVE_ROUND 1
#define HAVE_HYPOT 1
#define HAVE_DECL_ISFINITE 1
#define HAVE_DECL_ISNAN 1
#define HAVE_ACOSH 1
#define HAVE_ASINH 1
#define HAVE_ATANH 1
#define HAVE_EXPM1 1
#endif /*Py_PYCONFIG_H*/
// Copyright (c) 2014 Dropbox, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef Py_PYFPE_H
#define Py_PYFPE_H
#ifdef __cplusplus
extern "C" {
#endif
#include <math.h>
#define PyFPE_START_PROTECT(err, leave)
#define PyFPE_END_PROTECT(v)
#ifdef __cplusplus
}
#endif
#endif /* !Py_PYFPE_H */
// This file is originally from CPython 2.7, with modifications for Pyston
#ifndef Py_PYMATH_H
#define Py_PYMATH_H
#include "pyconfig.h" /* include for defines */
/**************************************************************************
Symbols and macros to supply platform-independent interfaces to mathematical
functions and constants
**************************************************************************/
/* Python provides implementations for copysign, round and hypot in
* Python/pymath.c just in case your math library doesn't provide the
* functions.
*
*Note: PC/pyconfig.h defines copysign as _copysign
*/
#ifndef HAVE_COPYSIGN
extern double copysign(double, double);
#endif
#ifndef HAVE_ROUND
extern double round(double);
#endif
#ifndef HAVE_HYPOT
extern double hypot(double, double);
#endif
/* extra declarations */
#ifndef _MSC_VER
#ifndef __STDC__
extern double fmod (double, double);
extern double frexp (double, int *);
extern double ldexp (double, int);
extern double modf (double, double *);
extern double pow(double, double);
#endif /* __STDC__ */
#endif /* _MSC_VER */
#ifdef _OSF_SOURCE
/* OSF1 5.1 doesn't make these available with XOPEN_SOURCE_EXTENDED defined */
extern int finite(double);
extern double copysign(double, double);
#endif
/* High precision defintion of pi and e (Euler)
* The values are taken from libc6's math.h.
*/
#ifndef Py_MATH_PIl
#define Py_MATH_PIl 3.1415926535897932384626433832795029L
#endif
#ifndef Py_MATH_PI
#define Py_MATH_PI 3.14159265358979323846
#endif
#ifndef Py_MATH_El
#define Py_MATH_El 2.7182818284590452353602874713526625L
#endif
#ifndef Py_MATH_E
#define Py_MATH_E 2.7182818284590452354
#endif
/* On x86, Py_FORCE_DOUBLE forces a floating-point number out of an x87 FPU
register and into a 64-bit memory location, rounding from extended
precision to double precision in the process. On other platforms it does
nothing. */
/* we take double rounding as evidence of x87 usage */
#ifndef Py_FORCE_DOUBLE
# ifdef X87_DOUBLE_ROUNDING
PyAPI_FUNC(double) _Py_force_double(double);
# define Py_FORCE_DOUBLE(X) (_Py_force_double(X))
# else
# define Py_FORCE_DOUBLE(X) (X)
# endif
#endif
#ifdef HAVE_GCC_ASM_FOR_X87
PyAPI_FUNC(unsigned short) _Py_get_387controlword(void);
PyAPI_FUNC(void) _Py_set_387controlword(unsigned short);
#endif
/* Py_IS_NAN(X)
* Return 1 if float or double arg is a NaN, else 0.
* Caution:
* X is evaluated more than once.
* This may not work on all platforms. Each platform has *some*
* way to spell this, though -- override in pyconfig.h if you have
* a platform where it doesn't work.
* Note: PC/pyconfig.h defines Py_IS_NAN as _isnan
*/
#ifndef Py_IS_NAN
#if defined HAVE_DECL_ISNAN && HAVE_DECL_ISNAN == 1
#define Py_IS_NAN(X) isnan(X)
#else
#define Py_IS_NAN(X) ((X) != (X))
#endif
#endif
/* Py_IS_INFINITY(X)
* Return 1 if float or double arg is an infinity, else 0.
* Caution:
* X is evaluated more than once.
* This implementation may set the underflow flag if |X| is very small;
* it really can't be implemented correctly (& easily) before C99.
* Override in pyconfig.h if you have a better spelling on your platform.
* Py_FORCE_DOUBLE is used to avoid getting false negatives from a
* non-infinite value v sitting in an 80-bit x87 register such that
* v becomes infinite when spilled from the register to 64-bit memory.
* Note: PC/pyconfig.h defines Py_IS_INFINITY as _isinf
*/
#ifndef Py_IS_INFINITY
# if defined HAVE_DECL_ISINF && HAVE_DECL_ISINF == 1
# define Py_IS_INFINITY(X) isinf(X)
# else
# define Py_IS_INFINITY(X) ((X) && \
(Py_FORCE_DOUBLE(X)*0.5 == Py_FORCE_DOUBLE(X)))
# endif
#endif
/* Py_IS_FINITE(X)
* Return 1 if float or double arg is neither infinite nor NAN, else 0.
* Some compilers (e.g. VisualStudio) have intrisics for this, so a special
* macro for this particular test is useful
* Note: PC/pyconfig.h defines Py_IS_FINITE as _finite
*/
#ifndef Py_IS_FINITE
#if defined HAVE_DECL_ISFINITE && HAVE_DECL_ISFINITE == 1
#define Py_IS_FINITE(X) isfinite(X)
#elif defined HAVE_FINITE
#define Py_IS_FINITE(X) finite(X)
#else
#define Py_IS_FINITE(X) (!Py_IS_INFINITY(X) && !Py_IS_NAN(X))
#endif
#endif
/* HUGE_VAL is supposed to expand to a positive double infinity. Python
* uses Py_HUGE_VAL instead because some platforms are broken in this
* respect. We used to embed code in pyport.h to try to worm around that,
* but different platforms are broken in conflicting ways. If you're on
* a platform where HUGE_VAL is defined incorrectly, fiddle your Python
* config to #define Py_HUGE_VAL to something that works on your platform.
*/
#ifndef Py_HUGE_VAL
#define Py_HUGE_VAL HUGE_VAL
#endif
/* Py_NAN
* A value that evaluates to a NaN. On IEEE 754 platforms INF*0 or
* INF/INF works. Define Py_NO_NAN in pyconfig.h if your platform
* doesn't support NaNs.
*/
#if !defined(Py_NAN) && !defined(Py_NO_NAN)
#define Py_NAN (Py_HUGE_VAL * 0.)
#endif
/* Py_OVERFLOWED(X)
* Return 1 iff a libm function overflowed. Set errno to 0 before calling
* a libm function, and invoke this macro after, passing the function
* result.
* Caution:
* This isn't reliable. C99 no longer requires libm to set errno under
* any exceptional condition, but does require +- HUGE_VAL return
* values on overflow. A 754 box *probably* maps HUGE_VAL to a
* double infinity, and we're cool if that's so, unless the input
* was an infinity and an infinity is the expected result. A C89
* system sets errno to ERANGE, so we check for that too. We're
* out of luck if a C99 754 box doesn't map HUGE_VAL to +Inf, or
* if the returned result is a NaN, or if a C89 box returns HUGE_VAL
* in non-overflow cases.
* X is evaluated more than once.
* Some platforms have better way to spell this, so expect some #ifdef'ery.
*
* OpenBSD uses 'isinf()' because a compiler bug on that platform causes
* the longer macro version to be mis-compiled. This isn't optimal, and
* should be removed once a newer compiler is available on that platform.
* The system that had the failure was running OpenBSD 3.2 on Intel, with
* gcc 2.95.3.
*
* According to Tim's checkin, the FreeBSD systems use isinf() to work
* around a FPE bug on that platform.
*/
#if defined(__FreeBSD__) || defined(__OpenBSD__)
#define Py_OVERFLOWED(X) isinf(X)
#else
#define Py_OVERFLOWED(X) ((X) != 0.0 && (errno == ERANGE || \
(X) == Py_HUGE_VAL || \
(X) == -Py_HUGE_VAL))
#endif
#endif /* Py_PYMATH_H */
......@@ -268,7 +268,7 @@ SRCS := $(MAIN_SRCS) $(STDLIB_SRCS)
STDLIB_OBJS := stdlib.bc.o stdlib.stripped.bc.o
STDLIB_RELEASE_OBJS := stdlib.release.bc.o
STDMODULE_SRCS := errnomodule.c shamodule.c sha256module.c sha512module.c md5.c md5module.c _sre.c $(EXTRA_STDMODULE_SRCS)
STDMODULE_SRCS := errnomodule.c shamodule.c sha256module.c sha512module.c _math.c mathmodule.c md5.c md5module.c _sre.c $(EXTRA_STDMODULE_SRCS)
FROM_CPYTHON_SRCS := $(addprefix ../lib_python/2.7_Modules/,$(STDMODULE_SRCS)) $(wildcard capi/*.c)
# The stdlib objects have slightly longer dependency chains,
......
......@@ -79,6 +79,12 @@ static int vgetargs1(PyObject* _tuple, const char* fmt, va_list* ap, int flags)
*p = n;
break;
}
case 'd': { // double
double* p = (double*)va_arg(*ap, double*);
RELEASE_ASSERT(arg->cls == float_cls, "%s", getTypeName(arg)->c_str());
*p = static_cast<BoxedFloat*>(arg)->d;
break;
}
case 's': {
if (*fmt == '*') {
Py_buffer* p = (Py_buffer*)va_arg(*ap, Py_buffer*);
......
......@@ -55,7 +55,7 @@ extern "C" PyObject* Py_InitModule4(const char* name, PyMethodDef* methods, cons
if (VERBOSITY())
printf("Loading method %s\n", methods->ml_name);
assert((methods->ml_flags & (~(METH_VARARGS | METH_KEYWORDS | METH_NOARGS))) == 0);
assert((methods->ml_flags & (~(METH_VARARGS | METH_KEYWORDS | METH_NOARGS | METH_O))) == 0);
module->giveAttr(methods->ml_name,
new BoxedCApiFunction(methods->ml_flags, passthrough, methods->ml_name, methods->ml_meth));
......@@ -69,14 +69,25 @@ extern "C" PyObject* Py_InitModule4(const char* name, PyMethodDef* methods, cons
return module;
}
extern "C" int PyModule_AddIntConstant(PyObject* _m, const char* name, long value) {
extern "C" PyObject* PyModule_GetDict(PyObject* _m) {
BoxedModule* m = static_cast<BoxedModule*>(_m);
assert(m->cls == module_cls);
m->setattr(name, boxInt(value), NULL);
return makeAttrWrapper(m);
}
extern "C" int PyModule_AddObject(PyObject* _m, const char* name, PyObject* value) {
BoxedModule* m = static_cast<BoxedModule*>(_m);
assert(m->cls == module_cls);
m->setattr(name, value, NULL);
return 0;
}
extern "C" int PyModule_AddIntConstant(PyObject* _m, const char* name, long value) {
return PyModule_AddObject(_m, name, boxInt(value));
}
} // namespace pyston
......@@ -53,6 +53,10 @@ public:
assert(kwargs->d.size() == 0);
assert(varargs->elts.size() == 0);
rtn = (Box*)self->func(self->passthrough, NULL);
} else if (self->ml_flags == METH_O) {
assert(kwargs->d.size() == 0);
assert(varargs->elts.size() == 1);
rtn = (Box*)self->func(self->passthrough, varargs->elts[0]);
} else {
RELEASE_ASSERT(0, "0x%x", self->ml_flags);
}
......
......@@ -23,6 +23,10 @@ namespace pyston {
Box* True, *False;
extern "C" PyObject* PyBool_FromLong(long n) {
return boxBool(n != 0);
}
extern "C" Box* boolInvert(BoxedBool* v) {
return boxInt(~v->b);
}
......
......@@ -415,7 +415,7 @@ BoxedModule* builtins_module;
extern "C" {
BoxedClass* Exception, *AssertionError, *AttributeError, *GeneratorExit, *TypeError, *NameError, *KeyError, *IndexError,
*IOError, *OSError, *ZeroDivisionError, *ValueError, *UnboundLocalError, *RuntimeError, *ImportError,
*StopIteration, *Warning, *SyntaxError, *OverflowError, *DeprecationWarning;
*StopIteration, *Warning, *SyntaxError, *OverflowError, *DeprecationWarning, *MemoryError;
}
Box* exceptionNew1(BoxedClass* cls) {
......@@ -590,6 +590,7 @@ void setupBuiltins() {
/*PendingDeprecationWarning =*/makeBuiltinException(Warning, "PendingDeprecationWarning");
DeprecationWarning = makeBuiltinException(Warning, "DeprecationWarning");
/*BytesWarning =*/makeBuiltinException(Warning, "BytesWarning");
MemoryError = makeBuiltinException(Exception, "MemoryError");
repr_obj = new BoxedFunction(boxRTFunction((void*)repr, UNKNOWN, 1));
builtins_module->giveAttr("repr", repr_obj);
......
// Copyright (c) 2014 Dropbox, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#define _USE_MATH_DEFINES
#include <cmath>
#include "codegen/compvars.h"
#include "core/types.h"
#include "runtime/inline/boxing.h"
#include "runtime/types.h"
#include "runtime/util.h"
namespace pyston {
BoxedModule* math_module;
static double _extractFloat(Box* b) {
if (b->cls != int_cls && b->cls != float_cls) {
raiseExcHelper(TypeError, "a float is required");
}
if (b->cls == int_cls)
return static_cast<BoxedInt*>(b)->n;
else
return static_cast<BoxedFloat*>(b)->d;
}
Box* mathSqrtFloat(Box* b) {
assert(b->cls == float_cls);
double d = static_cast<BoxedFloat*>(b)->d;
if (d < 0) {
raiseExcHelper(ValueError, "math domain error");
}
return boxFloat(sqrt(d));
}
Box* mathSqrtInt(Box* b) {
assert(b->cls == int_cls);
double d = static_cast<BoxedInt*>(b)->n;
if (d < 0) {
raiseExcHelper(ValueError, "math domain error");
}
return boxFloat(sqrt(d));
}
Box* mathSqrt(Box* b) {
double d = _extractFloat(b);
if (d < 0) {
raiseExcHelper(ValueError, "math domain error");
}
return boxFloat(sqrt(d));
}
Box* mathTanFloat(Box* b) {
assert(b->cls == float_cls);
double d = static_cast<BoxedFloat*>(b)->d;
return boxFloat(tan(d));
}
Box* mathTanInt(Box* b) {
assert(b->cls == int_cls);
double d = static_cast<BoxedInt*>(b)->n;
return boxFloat(tan(d));
}
Box* mathTan(Box* b) {
double d = _extractFloat(b);
return boxFloat(tan(d));
}
static void _addFunc(const char* name, void* int_func, void* float_func, void* boxed_func) {
std::vector<ConcreteCompilerType*> v_i, v_f, v_u;
assert(BOXED_INT);
v_i.push_back(BOXED_INT);
v_f.push_back(BOXED_FLOAT);
v_u.push_back(UNKNOWN);
CLFunction* cl = createRTFunction(1, 0, false, false);
addRTFunction(cl, int_func, BOXED_FLOAT, v_i);
addRTFunction(cl, float_func, BOXED_FLOAT, v_f);
addRTFunction(cl, boxed_func, UNKNOWN, v_u);
math_module->giveAttr(name, new BoxedFunction(cl));
}
void setupMath() {
math_module = createModule("math", "__builtin__");
math_module->giveAttr("pi", boxFloat(M_PI));
_addFunc("sqrt", (void*)mathSqrtInt, (void*)mathSqrtFloat, (void*)mathSqrt);
_addFunc("tan", (void*)mathTanInt, (void*)mathTanFloat, (void*)mathTan);
}
}
......@@ -62,13 +62,6 @@ public:
}
};
extern "C" PyObject* PyModule_GetDict(PyObject* _m) {
BoxedModule* m = static_cast<BoxedModule*>(_m);
assert(m->cls == module_cls);
return makeAttrWrapper(m);
}
#define MAKE_CHECK(NAME, cls_name) \
extern "C" bool Py##NAME##_Check(PyObject* op) { return isSubclass(op->cls, cls_name); }
......@@ -110,10 +103,6 @@ extern "C" Py_ssize_t PyString_Size(PyObject* s) {
return static_cast<BoxedString*>(s)->s.size();
}
extern "C" PyObject* PyInt_FromLong(long n) {
return boxInt(n);
}
extern "C" int PyDict_SetItem(PyObject* mp, PyObject* _key, PyObject* _item) {
Box* b = static_cast<Box*>(mp);
Box* key = static_cast<Box*>(_key);
......@@ -137,7 +126,6 @@ extern "C" int PyDict_SetItemString(PyObject* mp, const char* key, PyObject* ite
return PyDict_SetItem(mp, boxStrConstant(key), item);
}
BoxedClass* capifunc_cls;
extern "C" void conservativeGCHandler(GCVisitor* v, Box* b) {
......@@ -228,6 +216,10 @@ extern "C" int PyType_Ready(PyTypeObject* cls) {
return 0;
}
extern "C" int PyType_IsSubtype(PyTypeObject*, PyTypeObject*) {
Py_FatalError("unimplemented");
}
// copied from CPython's getargs.c:
extern "C" int PyBuffer_FillInfo(Py_buffer* view, PyObject* obj, void* buf, Py_ssize_t len, int readonly, int flags) {
if (view == NULL)
......@@ -365,6 +357,10 @@ extern "C" Py_ssize_t PyObject_Size(PyObject* o) {
}
}
extern "C" PyObject* PyObject_GetIter(PyObject*) {
Py_FatalError("unimplemented");
}
extern "C" PyObject* PyObject_GetItem(PyObject* o, PyObject* key) {
try {
return getitem(o, key);
......@@ -396,6 +392,9 @@ extern "C" PyObject* PySequence_GetSlice(PyObject* o, Py_ssize_t i1, Py_ssize_t
}
}
extern "C" PyObject* PyIter_Next(PyObject*) {
Py_FatalError("unimplemented");
}
extern "C" int PyCallable_Check(PyObject* x) {
if (x == NULL)
......@@ -448,6 +447,10 @@ extern "C" int PyErr_WarnEx(PyObject* category, const char* text, Py_ssize_t sta
Py_FatalError("unimplemented");
}
extern "C" PyObject* PyErr_SetFromErrno(PyObject* type) {
Py_FatalError("unimplemented");
return NULL;
}
extern "C" PyObject* PyImport_Import(PyObject* module_name) {
RELEASE_ASSERT(module_name, "");
......@@ -465,6 +468,25 @@ extern "C" PyObject* PyCallIter_New(PyObject* callable, PyObject* sentinel) {
Py_FatalError("unimplemented");
}
extern "C" void* PyMem_Malloc(size_t sz) {
return gc_compat_malloc(sz);
}
extern "C" void* PyMem_Realloc(void* ptr, size_t sz) {
return gc_compat_realloc(ptr, sz);
}
extern "C" void PyMem_Free(void* ptr) {
gc_compat_free(ptr);
}
extern "C" PyObject* PyNumber_Divide(PyObject*, PyObject*) {
Py_FatalError("unimplemented");
}
extern "C" PyObject* PyNumber_Multiply(PyObject*, PyObject*) {
Py_FatalError("unimplemented");
}
BoxedModule* importTestExtension() {
const char* pathname = "../test/test_extension/test.so";
......
......@@ -24,6 +24,19 @@
namespace pyston {
extern "C" PyObject* PyFloat_FromDouble(double d) {
return boxFloat(d);
}
extern "C" double PyFloat_AsDouble(PyObject* o) {
if (o->cls == float_cls)
return static_cast<BoxedFloat*>(o)->d;
else if (o->cls == int_cls)
return static_cast<BoxedInt*>(o)->n;
Py_FatalError("unimplemented");
return 0.0;
}
template <typename T> static inline void raiseDivZeroExcIfZero(T var) {
if (var == 0) {
raiseExcHelper(ZeroDivisionError, "float divide by zero");
......
......@@ -50,6 +50,10 @@ extern "C" PyObject* PyInt_FromSsize_t(Py_ssize_t ival) {
return boxInt(ival);
}
extern "C" PyObject* PyInt_FromLong(long n) {
return boxInt(n);
}
BoxedInt* interned_ints[NUM_INTERNED_INTS];
// If we don't have fast overflow-checking builtins, provide some slow variants:
......
......@@ -62,12 +62,37 @@ extern "C" unsigned long PyLong_AsUnsignedLong(PyObject* vv) {
}
}
extern "C" long PyLong_AsLong(PyObject* vv) {
RELEASE_ASSERT(PyLong_Check(vv), "");
BoxedLong* l = static_cast<BoxedLong*>(vv);
RELEASE_ASSERT(mpz_fits_slong_p(l->n), "");
return mpz_get_si(l->n);
}
extern "C" long PyLong_AsLongAndOverflow(PyObject*, int*) {
Py_FatalError("unimplemented");
}
extern "C" double PyLong_AsDouble(PyObject* vv) {
RELEASE_ASSERT(PyLong_Check(vv), "");
BoxedLong* l = static_cast<BoxedLong*>(vv);
return mpz_get_d(l->n);
}
extern "C" PyObject* PyLong_FromDouble(double v) {
Py_FatalError("unimplemented");
}
extern "C" PyObject* PyLong_FromUnsignedLong(unsigned long ival) {
BoxedLong* rtn = new BoxedLong(long_cls);
mpz_init_set_ui(rtn->n, ival);
return rtn;
}
extern "C" double _PyLong_Frexp(PyLongObject* a, Py_ssize_t* e) {
Py_FatalError("unimplemented");
}
extern "C" Box* createLong(const std::string* s) {
BoxedLong* rtn = new BoxedLong(long_cls);
int r = mpz_init_set_str(rtn->n, s->c_str(), 10);
......
......@@ -38,6 +38,7 @@ extern "C" void init_sha256();
extern "C" void init_sha512();
extern "C" void init_md5();
extern "C" void init_sre();
extern "C" void initmath();
namespace pyston {
......@@ -784,7 +785,6 @@ void setupRuntime() {
setupSys();
setupBuiltins();
setupMath();
setupTime();
setupThread();
setupPosix();
......@@ -797,6 +797,7 @@ void setupRuntime() {
init_sha512();
init_md5();
init_sre();
initmath();
setupSysEnd();
......
......@@ -63,7 +63,6 @@ void setupGenerator();
void setupSys();
void setupBuiltins();
void setupMath();
void setupTime();
void setupThread();
void setupPosix();
......
# expected: fail
# - C API exceptions are not yet supported
import math
print max(range(5))
print min(range(5))
print math.sqrt(-1)
......@@ -13,3 +13,8 @@ print abs(-1.0)
print max(1, 2)
print min(1, 2)
print max(range(5))
print min(range(5))
for x in [float("inf"), math.pi]:
print x, math.isinf(x), math.fabs(x), math.ceil(x), math.log(x), math.log10(x)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment