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
fa4bf00c
Commit
fa4bf00c
authored
Sep 05, 2014
by
Marius Wachtler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Teach abs how to handle longs
this let's us import random
parent
71620917
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
11 additions
and
0 deletions
+11
-0
src/runtime/builtin_modules/builtins.cpp
src/runtime/builtin_modules/builtins.cpp
+2
-0
src/runtime/long.cpp
src/runtime/long.cpp
+8
-0
src/runtime/long.h
src/runtime/long.h
+1
-0
No files found.
src/runtime/builtin_modules/builtins.cpp
View file @
fa4bf00c
...
...
@@ -90,6 +90,8 @@ extern "C" Box* abs_(Box* x) {
}
else
if
(
x
->
cls
==
float_cls
)
{
double
d
=
static_cast
<
BoxedFloat
*>
(
x
)
->
d
;
return
boxFloat
(
d
>=
0
?
d
:
-
d
);
}
else
if
(
x
->
cls
==
long_cls
)
{
return
longAbs
(
static_cast
<
BoxedLong
*>
(
x
));
}
else
{
RELEASE_ASSERT
(
0
,
"%s"
,
getTypeName
(
x
)
->
c_str
());
}
...
...
src/runtime/long.cpp
View file @
fa4bf00c
...
...
@@ -224,6 +224,14 @@ Box* longNeg(BoxedLong* v1) {
return
r
;
}
Box
*
longAbs
(
BoxedLong
*
v1
)
{
assert
(
isSubclass
(
v1
->
cls
,
long_cls
));
BoxedLong
*
r
=
new
BoxedLong
(
long_cls
);
mpz_init
(
r
->
n
);
mpz_abs
(
r
->
n
,
v1
->
n
);
return
r
;
}
Box
*
longAdd
(
BoxedLong
*
v1
,
Box
*
_v2
)
{
if
(
!
isSubclass
(
v1
->
cls
,
long_cls
))
raiseExcHelper
(
TypeError
,
"descriptor '__add__' requires a 'long' object but received a '%s'"
,
...
...
src/runtime/long.h
View file @
fa4bf00c
...
...
@@ -37,6 +37,7 @@ extern "C" Box* createLong(const std::string* s);
extern
"C"
BoxedLong
*
boxLong
(
int64_t
n
);
Box
*
longNeg
(
BoxedLong
*
lhs
);
Box
*
longAbs
(
BoxedLong
*
v1
);
Box
*
longAdd
(
BoxedLong
*
lhs
,
Box
*
rhs
);
Box
*
longSub
(
BoxedLong
*
lhs
,
Box
*
rhs
);
...
...
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