Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
Pyston
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
Pyston
Commits
6d156a18
Commit
6d156a18
authored
Apr 21, 2015
by
Travis Hance
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
get floatobject.c to compile, add float.hex and float.fromhex
parent
8a051d9b
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
74 additions
and
8 deletions
+74
-8
Makefile
Makefile
+1
-0
from_cpython/CMakeLists.txt
from_cpython/CMakeLists.txt
+1
-0
from_cpython/Include/floatobject.h
from_cpython/Include/floatobject.h
+0
-6
from_cpython/Include/pyport.h
from_cpython/Include/pyport.h
+34
-0
from_cpython/Objects/floatobject.c
from_cpython/Objects/floatobject.c
+22
-2
src/runtime/float.cpp
src/runtime/float.cpp
+11
-0
src/runtime/types.h
src/runtime/types.h
+2
-0
test/tests/float.py
test/tests/float.py
+3
-0
No files found.
Makefile
View file @
6d156a18
...
...
@@ -377,6 +377,7 @@ STDOBJECT_SRCS := \
capsule.c
\
stringobject.c
\
exceptions.c
\
floatobject.c
\
unicodeobject.c
\
unicodectype.c
\
bytearrayobject.c
\
...
...
from_cpython/CMakeLists.txt
View file @
6d156a18
...
...
@@ -79,6 +79,7 @@ file(GLOB_RECURSE STDOBJECT_SRCS Objects
capsule.c
cobject.c
exceptions.c
floatobject.c
iterobject.c
memoryobject.c
stringobject.c
...
...
from_cpython/Include/floatobject.h
View file @
6d156a18
...
...
@@ -12,16 +12,10 @@ PyFloatObject represents a (double precision) floating point number.
extern
"C"
{
#endif
// Pyston change: this is not the format we're using
// - actually I think it is but there's no reason to have multiple definitions.
#if 0
typedef
struct
{
PyObject_HEAD
double
ob_fval
;
}
PyFloatObject
;
#endif
struct
_PyFloatObject
;
typedef
struct
_PyFloatObject
PyFloatObject
;
// Pyston change: this is no longer a static object
PyAPI_DATA
(
PyTypeObject
*
)
float_cls
;
...
...
from_cpython/Include/pyport.h
View file @
6d156a18
...
...
@@ -424,3 +424,37 @@ typedef PY_LONG_LONG Py_intptr_t;
#endif
/* Py_PYPORT_H */
/* Py_ADJUST_ERANGE1(x)
* Py_ADJUST_ERANGE2(x, y)
* Set errno to 0 before calling a libm function, and invoke one of these
* macros after, passing the function result(s) (Py_ADJUST_ERANGE2 is useful
* for functions returning complex results). This makes two kinds of
* adjustments to errno: (A) If it looks like the platform libm set
* errno=ERANGE due to underflow, clear errno. (B) If it looks like the
* platform libm overflowed but didn't set errno, force errno to ERANGE. In
* effect, we're trying to force a useful implementation of C89 errno
* behavior.
* Caution:
* This isn't reliable. See Py_OVERFLOWED comments.
* X and Y may be evaluated more than once.
*/
#define Py_ADJUST_ERANGE1(X) \
do { \
if (errno == 0) { \
if ((X) == Py_HUGE_VAL || (X) == -Py_HUGE_VAL) \
errno = ERANGE; \
} \
else if (errno == ERANGE && (X) == 0.0) \
errno = 0; \
} while(0)
#define Py_ADJUST_ERANGE2(X, Y) \
do { \
if ((X) == Py_HUGE_VAL || (X) == -Py_HUGE_VAL || \
(Y) == Py_HUGE_VAL || (Y) == -Py_HUGE_VAL) { \
if (errno == 0) \
errno = ERANGE; \
} \
else if (errno == ERANGE) \
errno = 0; \
} while(0)
from_cpython/Objects/floatobject.c
View file @
6d156a18
...
...
@@ -138,6 +138,8 @@ PyFloat_GetInfo(void)
return
floatinfo
;
}
// pyston change: comment this out
#if 0
PyObject *
PyFloat_FromDouble(double fval)
{
...
...
@@ -153,6 +155,7 @@ PyFloat_FromDouble(double fval)
op->ob_fval = fval;
return (PyObject *) op;
}
#endif
/**************************************************************************
RED_FLAG 22-Sep-2000 tim
...
...
@@ -170,6 +173,8 @@ Since we can't change the interface of a public API function, pend is
still supported but now *officially* useless: if pend is not NULL,
*pend is set to NULL.
**************************************************************************/
// pyston change: comment this out
#if 0
PyObject *
PyFloat_FromString(PyObject *v, char **pend)
{
...
...
@@ -235,6 +240,7 @@ PyFloat_FromString(PyObject *v, char **pend)
#endif
return result;
}
#endif
static
void
float_dealloc
(
PyFloatObject
*
op
)
...
...
@@ -247,6 +253,8 @@ float_dealloc(PyFloatObject *op)
Py_TYPE
(
op
)
->
tp_free
((
PyObject
*
)
op
);
}
// pyston change: comment this out
#if 0
double
PyFloat_AsDouble(PyObject *op)
{
...
...
@@ -281,6 +289,7 @@ PyFloat_AsDouble(PyObject *op)
return val;
}
#endif
/* Methods */
...
...
@@ -1078,6 +1087,8 @@ float_long(PyObject *v)
#error "C doubles do not appear to be IEEE 754 binary64 format"
#endif
// pyston change: comment this out
#if 0
PyObject *
_Py_double_round(double x, int ndigits) {
...
...
@@ -1214,6 +1225,7 @@ _Py_double_round(double x, int ndigits) {
_Py_dg_freedtoa(buf);
return result;
}
#endif
#undef FIVE_POW_LIMIT
...
...
@@ -1359,7 +1371,8 @@ hex_from_char(char c) {
of the form 4k+1. */
#define TOHEX_NBITS DBL_MANT_DIG + 3 - (DBL_MANT_DIG+2)%4
static
PyObject
*
// pyston change: make this not static
PyObject
*
float_hex
(
PyObject
*
v
)
{
double
x
,
m
;
...
...
@@ -1437,7 +1450,8 @@ case_insensitive_match(const char *s, const char *t)
/* Convert a hexadecimal string to a float. */
static
PyObject
*
// pyston change: make this not static
PyObject
*
float_fromhex
(
PyObject
*
cls
,
PyObject
*
arg
)
{
PyObject
*
result_as_float
,
*
result
;
...
...
@@ -2105,6 +2119,8 @@ static PyNumberMethods float_as_number = {
0
,
/* nb_inplace_true_divide */
};
// pyston change: don't need this
#if 0
PyTypeObject PyFloat_Type = {
PyVarObject_HEAD_INIT(&PyType_Type, 0)
"float",
...
...
@@ -2295,7 +2311,10 @@ PyFloat_Fini(void)
}
}
}
#endif
// pyston change: comment this out
#if 0
/*----------------------------------------------------------------------------
* _PyFloat_{Pack,Unpack}{4,8}. See floatobject.h.
*/
...
...
@@ -2705,3 +2724,4 @@ _PyFloat_Unpack8(const unsigned char *p, int le)
return x;
}
}
#endif
src/runtime/float.cpp
View file @
6d156a18
...
...
@@ -17,6 +17,7 @@
#include <cstring>
#include <gmp.h>
#include "capi/types.h"
#include "core/types.h"
#include "runtime/inline/boxing.h"
#include "runtime/long.h"
...
...
@@ -24,6 +25,9 @@
#include "runtime/types.h"
#include "runtime/util.h"
extern
"C"
PyObject
*
float_hex
(
PyObject
*
v
)
noexcept
;
extern
"C"
PyObject
*
float_fromhex
(
PyObject
*
cls
,
PyObject
*
arg
)
noexcept
;
namespace
pyston
{
extern
"C"
PyObject
*
PyFloat_FromDouble
(
double
d
)
noexcept
{
...
...
@@ -1424,6 +1428,9 @@ exit:
return
result
;
}
static
PyMethodDef
float_methods
[]
=
{
{
"hex"
,
(
PyCFunction
)
float_hex
,
METH_NOARGS
,
NULL
},
{
"fromhex"
,
(
PyCFunction
)
float_fromhex
,
METH_O
|
METH_CLASS
,
NULL
}
};
void
setupFloat
()
{
_addFunc
(
"__add__"
,
BOXED_FLOAT
,
(
void
*
)
floatAddFloat
,
(
void
*
)
floatAddInt
,
(
void
*
)
floatAdd
);
float_cls
->
giveAttr
(
"__radd__"
,
float_cls
->
getattr
(
"__add__"
));
...
...
@@ -1472,6 +1479,10 @@ void setupFloat() {
new
BoxedClassmethod
(
new
BoxedBuiltinFunctionOrMethod
(
boxRTFunction
((
void
*
)
floatGetFormat
,
STR
,
2
),
"__getformat__"
,
floatGetFormatDoc
)));
for
(
auto
&
md
:
float_methods
)
{
float_cls
->
giveAttr
(
md
.
ml_name
,
new
BoxedMethodDescriptor
(
&
md
,
float_cls
));
}
float_cls
->
freeze
();
floatFormatInit
();
...
...
src/runtime/types.h
View file @
6d156a18
...
...
@@ -407,6 +407,8 @@ public:
DEFAULT_CLASS_SIMPLE
(
float_cls
);
};
static_assert
(
sizeof
(
BoxedFloat
)
==
sizeof
(
PyFloatObject
),
""
);
static_assert
(
offsetof
(
BoxedFloat
,
d
)
==
offsetof
(
PyFloatObject
,
ob_fval
),
""
);
class
BoxedComplex
:
public
Box
{
public:
...
...
test/tests/float.py
View file @
6d156a18
...
...
@@ -58,3 +58,6 @@ try:
float
.
__getformat__
(
'oooga booga boooga'
)
except
Exception
as
e
:
print
e
.
message
print
float
.
fromhex
(
"f0.04a"
)
print
(
5.0
).
hex
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment