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
e98abcb2
Commit
e98abcb2
authored
Jan 11, 2016
by
Marius Wachtler
1
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1040 from Daetalus/complex_improvements_2
Add missing complex attributes
parents
2526c94e
fb612f83
Changes
5
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
377 additions
and
673 deletions
+377
-673
from_cpython/Include/complexobject.h
from_cpython/Include/complexobject.h
+0
-4
from_cpython/Objects/complexobject.c
from_cpython/Objects/complexobject.c
+32
-16
src/runtime/complex.cpp
src/runtime/complex.cpp
+295
-653
src/runtime/types.h
src/runtime/types.h
+4
-0
test/tests/complex.py
test/tests/complex.py
+46
-0
No files found.
from_cpython/Include/complexobject.h
View file @
e98abcb2
...
@@ -39,14 +39,10 @@ PyComplexObject represents a complex number with double-precision
...
@@ -39,14 +39,10 @@ PyComplexObject represents a complex number with double-precision
real and imaginary parts.
real and imaginary parts.
*/
*/
// Pyston change: this is not our object format
#if 0
typedef
struct
{
typedef
struct
{
PyObject_HEAD
PyObject_HEAD
Py_complex
cval
;
Py_complex
cval
;
}
PyComplexObject
;
}
PyComplexObject
;
#endif
typedef
struct
_PyComplexObject
PyComplexObject
;
// Pyston change: this is not a static object any more
// Pyston change: this is not a static object any more
// PyAPI_DATA(PyTypeObject) PyComplex_Type;
// PyAPI_DATA(PyTypeObject) PyComplex_Type;
...
...
from_cpython/Objects/complexobject.c
View file @
e98abcb2
...
@@ -215,8 +215,6 @@ c_abs(Py_complex z)
...
@@ -215,8 +215,6 @@ c_abs(Py_complex z)
return
result
;
return
result
;
}
}
// Pyston changes: comment this out
#if 0
static
PyObject
*
static
PyObject
*
complex_subtype_from_c_complex
(
PyTypeObject
*
type
,
Py_complex
cval
)
complex_subtype_from_c_complex
(
PyTypeObject
*
type
,
Py_complex
cval
)
{
{
...
@@ -356,14 +354,18 @@ PyComplex_AsCComplex(PyObject *op)
...
@@ -356,14 +354,18 @@ PyComplex_AsCComplex(PyObject *op)
}
}
}
}
// Pyston changes: comment this out
#if 0
static void
static void
complex_dealloc(PyObject *op)
complex_dealloc(PyObject *op)
{
{
op->ob_type->tp_free(op);
op->ob_type->tp_free(op);
}
}
#endif
static PyObject *
// Pyston change: make no static
PyObject
*
complex_format
(
PyComplexObject
*
v
,
int
precision
,
char
format_code
)
complex_format
(
PyComplexObject
*
v
,
int
precision
,
char
format_code
)
{
{
PyObject
*
result
=
NULL
;
PyObject
*
result
=
NULL
;
...
@@ -426,6 +428,8 @@ complex_format(PyComplexObject *v, int precision, char format_code)
...
@@ -426,6 +428,8 @@ complex_format(PyComplexObject *v, int precision, char format_code)
return
result
;
return
result
;
}
}
// Pyston changes: comment this out
#if 0
static int
static int
complex_print(PyComplexObject *v, FILE *fp, int flags)
complex_print(PyComplexObject *v, FILE *fp, int flags)
{
{
...
@@ -788,8 +792,10 @@ complex_coerce(PyObject **pv, PyObject **pw)
...
@@ -788,8 +792,10 @@ complex_coerce(PyObject **pv, PyObject **pw)
}
}
return 1; /* Can't do it */
return 1; /* Can't do it */
}
}
#endif
static PyObject *
// Pyston change: make no static
PyObject
*
complex_richcompare
(
PyObject
*
v
,
PyObject
*
w
,
int
op
)
complex_richcompare
(
PyObject
*
v
,
PyObject
*
w
,
int
op
)
{
{
PyObject
*
res
;
PyObject
*
res
;
...
@@ -858,6 +864,8 @@ complex_richcompare(PyObject *v, PyObject *w, int op)
...
@@ -858,6 +864,8 @@ complex_richcompare(PyObject *v, PyObject *w, int op)
return
Py_NotImplemented
;
return
Py_NotImplemented
;
}
}
// Pyston change: comment this out
#if 0
static PyObject *
static PyObject *
complex_int(PyObject *v)
complex_int(PyObject *v)
{
{
...
@@ -907,8 +915,10 @@ PyDoc_STRVAR(complex__format__doc,
...
@@ -907,8 +915,10 @@ PyDoc_STRVAR(complex__format__doc,
"complex.__format__() -> str\n"
"complex.__format__() -> str\n"
"\n"
"\n"
"Convert to a string according to format_spec.");
"Convert to a string according to format_spec.");
#endif
static PyObject *
// Pyston changes: make no static
PyObject
*
complex__format__
(
PyObject
*
self
,
PyObject
*
args
)
complex__format__
(
PyObject
*
self
,
PyObject
*
args
)
{
{
PyObject
*
format_spec
;
PyObject
*
format_spec
;
...
@@ -952,7 +962,6 @@ PyDoc_STRVAR(complex_is_finite_doc,
...
@@ -952,7 +962,6 @@ PyDoc_STRVAR(complex_is_finite_doc,
"complex.is_finite() -> bool\n"
"complex.is_finite() -> bool\n"
"\n"
"\n"
"Returns True if the real and the imaginary part is finite.");
"Returns True if the real and the imaginary part is finite.");
#endif
static PyMethodDef complex_methods[] = {
static PyMethodDef complex_methods[] = {
{"conjugate", (PyCFunction)complex_conjugate, METH_NOARGS,
{"conjugate", (PyCFunction)complex_conjugate, METH_NOARGS,
...
@@ -974,6 +983,7 @@ static PyMemberDef complex_members[] = {
...
@@ -974,6 +983,7 @@ static PyMemberDef complex_members[] = {
"the imaginary part of a complex number"},
"the imaginary part of a complex number"},
{0},
{0},
};
};
#endif
static
PyObject
*
static
PyObject
*
complex_subtype_from_string
(
PyTypeObject
*
type
,
PyObject
*
v
)
complex_subtype_from_string
(
PyTypeObject
*
type
,
PyObject
*
v
)
...
@@ -1136,22 +1146,26 @@ complex_subtype_from_string(PyTypeObject *type, PyObject *v)
...
@@ -1136,22 +1146,26 @@ complex_subtype_from_string(PyTypeObject *type, PyObject *v)
return
NULL
;
return
NULL
;
}
}
static PyObject *
// Pyston changes: change the API, make it no static
complex_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
// and let complex_new accept unpacked arguments
{
PyObject
*
PyObject *r, *i, *tmp;
complex_new
(
PyTypeObject
*
type
,
PyObject
*
r
,
PyObject
*
i
)
{
PyObject
*
tmp
;
PyNumberMethods
*
nbr
,
*
nbi
=
NULL
;
PyNumberMethods
*
nbr
,
*
nbi
=
NULL
;
Py_complex
cr
,
ci
;
Py_complex
cr
,
ci
;
int
own_r
=
0
;
int
own_r
=
0
;
int
cr_is_complex
=
0
;
int
cr_is_complex
=
0
;
int
ci_is_complex
=
0
;
int
ci_is_complex
=
0
;
static char *kwlist[] = {"real", "imag", 0};
r = Py_False;
/* Pyston changes: comment this out, pyston don't use tuple arg.
i = NULL;
static char *kwlist[] = {"real", "imag", 0};
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO:complex", kwlist,
&r, &i))
r = Py_False;
return NULL;
i = NULL;
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO:complex", kwlist,
&r, &i))
return NULL;
*/
/* Special-case for a single argument when type(arg) is complex. */
/* Special-case for a single argument when type(arg) is complex. */
if
(
PyComplex_CheckExact
(
r
)
&&
i
==
NULL
&&
if
(
PyComplex_CheckExact
(
r
)
&&
i
==
NULL
&&
...
@@ -1269,6 +1283,8 @@ complex_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
...
@@ -1269,6 +1283,8 @@ complex_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
return
complex_subtype_from_doubles
(
type
,
cr
.
real
,
ci
.
real
);
return
complex_subtype_from_doubles
(
type
,
cr
.
real
,
ci
.
real
);
}
}
// Pyston changes: comment this out
#if 0
PyDoc_STRVAR(complex_doc,
PyDoc_STRVAR(complex_doc,
"complex(real[, imag]) -> complex number\n"
"complex(real[, imag]) -> complex number\n"
"\n"
"\n"
...
...
src/runtime/complex.cpp
View file @
e98abcb2
This diff is collapsed.
Click to expand it.
src/runtime/types.h
View file @
e98abcb2
...
@@ -390,6 +390,10 @@ public:
...
@@ -390,6 +390,10 @@ public:
DEFAULT_CLASS_SIMPLE
(
complex_cls
);
DEFAULT_CLASS_SIMPLE
(
complex_cls
);
};
};
static_assert
(
sizeof
(
BoxedComplex
)
==
sizeof
(
PyComplexObject
),
""
);
static_assert
(
offsetof
(
BoxedComplex
,
real
)
==
offsetof
(
PyComplexObject
,
cval
.
real
),
""
);
static_assert
(
offsetof
(
BoxedComplex
,
imag
)
==
offsetof
(
PyComplexObject
,
cval
.
imag
),
""
);
class
BoxedBool
:
public
BoxedInt
{
class
BoxedBool
:
public
BoxedInt
{
public:
public:
BoxedBool
(
bool
b
)
__attribute__
((
visibility
(
"default"
)))
:
BoxedInt
(
b
?
1
:
0
)
{}
BoxedBool
(
bool
b
)
__attribute__
((
visibility
(
"default"
)))
:
BoxedInt
(
b
?
1
:
0
)
{}
...
...
test/tests/complex.py
View file @
e98abcb2
...
@@ -22,3 +22,49 @@ try:
...
@@ -22,3 +22,49 @@ try:
complex
(
1
,
1.0
).
real
=
1
complex
(
1
,
1.0
).
real
=
1
except
TypeError
,
e
:
except
TypeError
,
e
:
print
e
print
e
class
C
(
complex
):
pass
print
(
1j
-
C
(
1
))
print
(
1j
+
C
(
1
))
print
(
1j
*
C
(
1
))
print
(
1j
/
C
(
1
))
class
C1
(
complex
):
def
__complex__
(
self
):
return
1j
print
(
C1
(
1
)
+
1j
)
print
(
C1
(
1
)
-
1j
)
print
(
C1
(
1
)
*
1j
)
print
(
C1
(
1
)
/
1j
)
types
=
[
int
,
float
,
long
]
for
_type
in
types
:
try
:
_type
(
1j
)
except
TypeError
as
e
:
print
(
e
.
message
)
data
=
[
"-1j"
,
"0j"
,
"1j"
,
"5+5j"
,
"5-5j"
,
"5"
,
"5L"
,
"5.5"
,
"
\
"
5
\
"
"
,
"None"
,
]
operations
=
[
"__mod__"
,
"__rmod__"
,
"__divmod__"
,
"__rdivmod__"
,
"__truediv__"
,
"__rtruediv__"
,
"__floordiv__"
,
"__rfloordiv__"
,
]
for
x
in
data
:
for
y
in
data
:
for
operation
in
operations
:
try
:
print
(
eval
(
"complex.{op}({arg1}, {arg2})"
.
format
(
op
=
operation
,
arg1
=
x
,
arg2
=
y
)))
except
Exception
as
e
:
print
(
e
.
message
)
Boxiang Sun
@Daetalus
mentioned in commit
c2bac556
·
Sep 08, 2016
mentioned in commit
c2bac556
mentioned in commit c2bac55610136628467e002ba1b8a0ee99389168
Toggle commit list
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