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
d021017c
Commit
d021017c
authored
Aug 27, 2014
by
Kevin Modzelewski
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #139 from tjhance/complex2
Complex2
parents
8e952a4e
ebdaab07
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
16 additions
and
5 deletions
+16
-5
src/codegen/parse_ast.py
src/codegen/parse_ast.py
+3
-0
src/runtime/complex.cpp
src/runtime/complex.cpp
+4
-0
src/runtime/complex.h
src/runtime/complex.h
+0
-5
src/runtime/objmodel.cpp
src/runtime/objmodel.cpp
+5
-0
src/runtime/types.h
src/runtime/types.h
+1
-0
test/tests/complex.py
test/tests/complex.py
+3
-0
No files found.
src/codegen/parse_ast.py
View file @
d021017c
...
...
@@ -163,6 +163,9 @@ def convert(n, f):
elif
isinstance
(
v
,
float
):
f
.
write
(
struct
.
pack
(
">d"
,
v
))
elif
isinstance
(
v
,
complex
):
# Complex constants can only be pure imaginary
# (e.g., in 1+0j, 1 and 0j are separate literals)
assert
v
.
real
==
0.0
f
.
write
(
struct
.
pack
(
">d"
,
v
.
imag
))
elif
v
is
None
or
isinstance
(
v
,
_ast
.
AST
):
convert
(
v
,
f
)
...
...
src/runtime/complex.cpp
View file @
d021017c
...
...
@@ -222,6 +222,10 @@ void setupComplex() {
complex_cls
->
giveAttr
(
"__str__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
complexStr
,
STR
,
1
)));
complex_cls
->
giveAttr
(
"__repr__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
complexRepr
,
STR
,
1
)));
complex_cls
->
giveAttr
(
"real"
,
new
BoxedMemberDescriptor
(
BoxedMemberDescriptor
::
FLOAT
,
offsetof
(
BoxedComplex
,
real
)));
complex_cls
->
giveAttr
(
"imag"
,
new
BoxedMemberDescriptor
(
BoxedMemberDescriptor
::
FLOAT
,
offsetof
(
BoxedComplex
,
imag
)));
complex_cls
->
freeze
();
}
...
...
src/runtime/complex.h
View file @
d021017c
...
...
@@ -20,11 +20,6 @@
namespace
pyston
{
extern
"C"
Box
*
createPureImaginary
(
double
i
);
extern
"C"
double
mod_complex_complex
(
double
lhs
,
double
rhs
);
extern
"C"
double
div_complex_complex
(
double
lhs
,
double
rhs
);
extern
"C"
double
floordiv_complex_complex
(
double
lhs
,
double
rhs
);
extern
"C"
double
pow_complex_complex
(
double
lhs
,
double
rhs
);
}
#endif
src/runtime/objmodel.cpp
View file @
d021017c
...
...
@@ -842,6 +842,11 @@ Box* dataDescriptorInstanceSpecialCases(GetattrRewriteArgs* rewrite_args, Box* o
int
rtn
=
reinterpret_cast
<
int
*>
(
obj
)[
member_desc
->
offset
/
sizeof
(
int
)];
return
boxInt
(
rtn
);
}
case
BoxedMemberDescriptor
:
:
FLOAT
:
{
rewrite_args
=
NULL
;
double
rtn
=
reinterpret_cast
<
double
*>
(
obj
)[
member_desc
->
offset
/
sizeof
(
double
)];
return
boxFloat
(
rtn
);
}
default:
RELEASE_ASSERT
(
0
,
"%d"
,
member_desc
->
type
);
}
...
...
src/runtime/types.h
View file @
d021017c
...
...
@@ -346,6 +346,7 @@ public:
BYTE
=
T_BYTE
,
INT
=
T_INT
,
OBJECT
=
T_OBJECT
,
FLOAT
=
T_FLOAT
,
}
type
;
int
offset
;
...
...
test/tests/complex.py
View file @
d021017c
...
...
@@ -12,3 +12,6 @@ print 0.5j - 1.5
print
0.5j
*
1.5
print
0.5j
*
1.5
print
0.5j
*
1.5
print
(
0.5j
+
1.5
).
real
print
(
0.5j
+
1.5
).
imag
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