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
00324770
Commit
00324770
authored
Mar 10, 2015
by
Marius Wachtler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add 'long**long', 'long**int' and '-(1L)' support
parent
e2115cba
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
11 deletions
+26
-11
src/runtime/long.cpp
src/runtime/long.cpp
+22
-11
test/tests/long.py
test/tests/long.py
+4
-0
No files found.
src/runtime/long.cpp
View file @
00324770
...
...
@@ -972,19 +972,27 @@ Box* longPow(BoxedLong* v1, Box* _v2) {
if
(
!
isSubclass
(
v1
->
cls
,
long_cls
))
raiseExcHelper
(
TypeError
,
"descriptor '__pow__' requires a 'long' object but received a '%s'"
,
getTypeName
(
v1
));
if
(
!
isSubclass
(
_v2
->
cls
,
long_cls
))
return
NotImplemented
;
BoxedLong
*
v2
=
static_cast
<
BoxedLong
*>
(
_v2
);
if
(
isSubclass
(
_v2
->
cls
,
long_cls
))
{
BoxedLong
*
v2
=
static_cast
<
BoxedLong
*>
(
_v2
);
RELEASE_ASSERT
(
mpz_sgn
(
v2
->
n
)
>=
0
,
""
);
RELEASE_ASSERT
(
mpz_fits_ulong_p
(
v2
->
n
),
""
);
uint64_t
n2
=
mpz_get_ui
(
v2
->
n
);
RELEASE_ASSERT
(
mpz_sgn
(
v2
->
n
)
>=
0
,
""
);
RELEASE_ASSERT
(
mpz_fits_ulong_p
(
v2
->
n
),
""
);
uint64_t
n2
=
mpz_get_ui
(
v2
->
n
);
BoxedLong
*
r
=
new
BoxedLong
();
mpz_init
(
r
->
n
);
mpz_pow_ui
(
r
->
n
,
v1
->
n
,
n2
);
return
r
;
BoxedLong
*
r
=
new
BoxedLong
();
mpz_init
(
r
->
n
);
mpz_pow_ui
(
r
->
n
,
v1
->
n
,
n2
);
return
r
;
}
else
if
(
isSubclass
(
_v2
->
cls
,
int_cls
))
{
BoxedInt
*
v2
=
static_cast
<
BoxedInt
*>
(
_v2
);
RELEASE_ASSERT
(
v2
->
n
>=
0
,
""
);
BoxedLong
*
r
=
new
BoxedLong
();
mpz_init
(
r
->
n
);
mpz_pow_ui
(
r
->
n
,
v1
->
n
,
v2
->
n
);
return
r
;
}
else
{
return
NotImplemented
;
}
}
extern
"C"
Box
*
longInvert
(
BoxedLong
*
v
)
{
...
...
@@ -1055,6 +1063,8 @@ void setupLong() {
long_cls
->
giveAttr
(
"__add__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
longAdd
,
UNKNOWN
,
2
)));
long_cls
->
giveAttr
(
"__radd__"
,
long_cls
->
getattr
(
"__add__"
));
long_cls
->
giveAttr
(
"__pow__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
longPow
,
UNKNOWN
,
2
)));
long_cls
->
giveAttr
(
"__and__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
longAnd
,
UNKNOWN
,
2
)));
long_cls
->
giveAttr
(
"__rand__"
,
long_cls
->
getattr
(
"__and__"
));
long_cls
->
giveAttr
(
"__or__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
longOr
,
UNKNOWN
,
2
)));
...
...
@@ -1079,6 +1089,7 @@ void setupLong() {
long_cls
->
giveAttr
(
"__oct__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
longOct
,
STR
,
1
)));
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
(
"__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 @
00324770
...
...
@@ -53,6 +53,10 @@ print ~(1L)
print
~
(
10L
)
print
~
(
-
10L
)
print
-
(
1L
)
print
1L
**
2L
print
1L
**
2
print
long
(
"100"
,
16
)
print
long
(
"100"
,
10
)
print
long
(
"100"
,
26
)
...
...
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