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
009e735d
Commit
009e735d
authored
Aug 27, 2014
by
Kevin Modzelewski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow usage of the name 'complex'
parent
23b7712d
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
33 additions
and
0 deletions
+33
-0
src/runtime/builtin_modules/builtins.cpp
src/runtime/builtin_modules/builtins.cpp
+1
-0
src/runtime/complex.cpp
src/runtime/complex.cpp
+30
-0
test/tests/complex.py
test/tests/complex.py
+2
-0
No files found.
src/runtime/builtin_modules/builtins.cpp
View file @
009e735d
...
...
@@ -698,5 +698,6 @@ void setupBuiltins() {
builtins_module
->
giveAttr
(
"frozenset"
,
frozenset_cls
);
builtins_module
->
giveAttr
(
"tuple"
,
tuple_cls
);
builtins_module
->
giveAttr
(
"instancemethod"
,
instancemethod_cls
);
builtins_module
->
giveAttr
(
"complex"
,
complex_cls
);
}
}
src/runtime/complex.cpp
View file @
009e735d
...
...
@@ -205,9 +205,39 @@ Box* complexRepr(BoxedComplex* self) {
return
boxString
(
complexFmt
(
self
->
real
,
self
->
imag
,
16
,
'g'
));
}
Box
*
complexNew
(
Box
*
_cls
,
Box
*
real
,
Box
*
imag
)
{
RELEASE_ASSERT
(
_cls
==
complex_cls
,
""
);
double
real_f
;
if
(
real
->
cls
==
int_cls
)
{
real_f
=
static_cast
<
BoxedInt
*>
(
real
)
->
n
;
}
else
if
(
real
->
cls
==
float_cls
)
{
real_f
=
static_cast
<
BoxedFloat
*>
(
real
)
->
d
;
}
else
{
// TODO: implement taking a string argument
raiseExcHelper
(
TypeError
,
"complex() argument must be a string or number"
);
}
double
imag_f
;
if
(
imag
->
cls
==
int_cls
)
{
imag_f
=
static_cast
<
BoxedInt
*>
(
imag
)
->
n
;
}
else
if
(
imag
->
cls
==
float_cls
)
{
imag_f
=
static_cast
<
BoxedFloat
*>
(
imag
)
->
d
;
}
else
if
(
imag
->
cls
==
str_cls
)
{
raiseExcHelper
(
TypeError
,
"complex() second arg can't be a string"
);
}
else
{
raiseExcHelper
(
TypeError
,
"complex() argument must be a string or number"
);
}
return
new
BoxedComplex
(
real_f
,
imag_f
);
}
void
setupComplex
()
{
complex_cls
->
giveAttr
(
"__name__"
,
boxStrConstant
(
"complex"
));
complex_cls
->
giveAttr
(
"__new__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
complexNew
,
UNKNOWN
,
3
,
2
,
false
,
false
),
{
boxInt
(
0
),
boxInt
(
0
)
}));
_addFunc
(
"__add__"
,
BOXED_COMPLEX
,
(
void
*
)
complexAddComplex
,
(
void
*
)
complexAddFloat
,
(
void
*
)
complexAddInt
,
(
void
*
)
complexAdd
);
...
...
test/tests/complex.py
View file @
009e735d
...
...
@@ -15,3 +15,5 @@ print 0.5j * 1.5
print
(
0.5j
+
1.5
).
real
print
(
0.5j
+
1.5
).
imag
print
complex
(
1
,
1.0
)
/
2.0
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