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
fec260af
Commit
fec260af
authored
May 25, 2015
by
Kevin Modzelewski
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #551 from tjhance/long_pos
implement long.__pos__
parents
1c40ea0f
cd32dc6e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
0 deletions
+19
-0
src/runtime/long.cpp
src/runtime/long.cpp
+14
-0
test/tests/long.py
test/tests/long.py
+5
-0
No files found.
src/runtime/long.cpp
View file @
fec260af
...
...
@@ -719,6 +719,19 @@ Box* longNeg(BoxedLong* v1) {
return
r
;
}
Box
*
longPos
(
BoxedLong
*
v
)
{
if
(
!
isSubclass
(
v
->
cls
,
long_cls
))
raiseExcHelper
(
TypeError
,
"descriptor '__pos__' requires a 'long' object but received a '%s'"
,
getTypeName
(
v
));
if
(
v
->
cls
==
long_cls
)
{
return
v
;
}
else
{
BoxedLong
*
r
=
new
BoxedLong
();
mpz_init_set
(
r
->
n
,
v
->
n
);
return
r
;
}
}
Box
*
longAbs
(
BoxedLong
*
v1
)
{
assert
(
isSubclass
(
v1
->
cls
,
long_cls
));
BoxedLong
*
r
=
new
BoxedLong
();
...
...
@@ -1461,6 +1474,7 @@ void setupLong() {
long_cls
->
giveAttr
(
"__invert__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
longInvert
,
UNKNOWN
,
1
)));
long_cls
->
giveAttr
(
"__neg__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
longNeg
,
UNKNOWN
,
1
)));
long_cls
->
giveAttr
(
"__pos__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
longPos
,
UNKNOWN
,
1
)));
long_cls
->
giveAttr
(
"__nonzero__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
longNonzero
,
BOXED_BOOL
,
1
)));
long_cls
->
giveAttr
(
"__hash__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
longHash
,
BOXED_INT
,
1
)));
...
...
test/tests/long.py
View file @
fec260af
...
...
@@ -106,3 +106,8 @@ print type(x)
print
type
(
long
(
C
()))
print
repr
(
int
(
"123456789123456789123456789"
,
16
))
a
=
2389134823414823408429384238403228392384028439480234823
print
+
a
print
+
long
.
__new__
(
C
,
5L
)
print
type
(
+
long
.
__new__
(
C
,
5L
))
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