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
real and imaginary parts.
*/
// Pyston change: this is not our object format
#if 0
typedef
struct
{
PyObject_HEAD
Py_complex
cval
;
}
PyComplexObject
;
#endif
typedef
struct
_PyComplexObject
PyComplexObject
;
// Pyston change: this is not a static object any more
// PyAPI_DATA(PyTypeObject) PyComplex_Type;
...
...
from_cpython/Objects/complexobject.c
View file @
e98abcb2
...
...
@@ -215,8 +215,6 @@ c_abs(Py_complex z)
return
result
;
}
// Pyston changes: comment this out
#if 0
static
PyObject
*
complex_subtype_from_c_complex
(
PyTypeObject
*
type
,
Py_complex
cval
)
{
...
...
@@ -356,14 +354,18 @@ PyComplex_AsCComplex(PyObject *op)
}
}
// Pyston changes: comment this out
#if 0
static void
complex_dealloc(PyObject *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
)
{
PyObject
*
result
=
NULL
;
...
...
@@ -426,6 +428,8 @@ complex_format(PyComplexObject *v, int precision, char format_code)
return
result
;
}
// Pyston changes: comment this out
#if 0
static int
complex_print(PyComplexObject *v, FILE *fp, int flags)
{
...
...
@@ -788,8 +792,10 @@ complex_coerce(PyObject **pv, PyObject **pw)
}
return 1; /* Can't do it */
}
#endif
static PyObject *
// Pyston change: make no static
PyObject
*
complex_richcompare
(
PyObject
*
v
,
PyObject
*
w
,
int
op
)
{
PyObject
*
res
;
...
...
@@ -858,6 +864,8 @@ complex_richcompare(PyObject *v, PyObject *w, int op)
return
Py_NotImplemented
;
}
// Pyston change: comment this out
#if 0
static PyObject *
complex_int(PyObject *v)
{
...
...
@@ -907,8 +915,10 @@ PyDoc_STRVAR(complex__format__doc,
"complex.__format__() -> str\n"
"\n"
"Convert to a string according to format_spec.");
#endif
static PyObject *
// Pyston changes: make no static
PyObject
*
complex__format__
(
PyObject
*
self
,
PyObject
*
args
)
{
PyObject
*
format_spec
;
...
...
@@ -952,7 +962,6 @@ PyDoc_STRVAR(complex_is_finite_doc,
"complex.is_finite() -> bool\n"
"\n"
"Returns True if the real and the imaginary part is finite.");
#endif
static PyMethodDef complex_methods[] = {
{"conjugate", (PyCFunction)complex_conjugate, METH_NOARGS,
...
...
@@ -974,6 +983,7 @@ static PyMemberDef complex_members[] = {
"the imaginary part of a complex number"},
{0},
};
#endif
static
PyObject
*
complex_subtype_from_string
(
PyTypeObject
*
type
,
PyObject
*
v
)
...
...
@@ -1136,22 +1146,26 @@ complex_subtype_from_string(PyTypeObject *type, PyObject *v)
return
NULL
;
}
static PyObject *
complex_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
PyObject *r, *i, *tmp;
// Pyston changes: change the API, make it no static
// and let complex_new accept unpacked arguments
PyObject
*
complex_new
(
PyTypeObject
*
type
,
PyObject
*
r
,
PyObject
*
i
)
{
PyObject
*
tmp
;
PyNumberMethods
*
nbr
,
*
nbi
=
NULL
;
Py_complex
cr
,
ci
;
int
own_r
=
0
;
int
cr_is_complex
=
0
;
int
ci_is_complex
=
0
;
static char *kwlist[] = {"real", "imag", 0};
r = Py_False;
i = NULL;
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO:complex", kwlist,
&r, &i))
return NULL;
/* Pyston changes: comment this out, pyston don't use tuple arg.
static char *kwlist[] = {"real", "imag", 0};
r = Py_False;
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. */
if
(
PyComplex_CheckExact
(
r
)
&&
i
==
NULL
&&
...
...
@@ -1269,6 +1283,8 @@ complex_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
return
complex_subtype_from_doubles
(
type
,
cr
.
real
,
ci
.
real
);
}
// Pyston changes: comment this out
#if 0
PyDoc_STRVAR(complex_doc,
"complex(real[, imag]) -> complex number\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:
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
{
public:
BoxedBool
(
bool
b
)
__attribute__
((
visibility
(
"default"
)))
:
BoxedInt
(
b
?
1
:
0
)
{}
...
...
test/tests/complex.py
View file @
e98abcb2
...
...
@@ -22,3 +22,49 @@ try:
complex
(
1
,
1.0
).
real
=
1
except
TypeError
,
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