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
d455a565
Commit
d455a565
authored
May 18, 2014
by
Leandro Lameiro
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adds a non-optimal implementation of int.__divmod__
parent
b0d50771
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
0 deletions
+24
-0
src/runtime/int.cpp
src/runtime/int.cpp
+20
-0
test/tests/intmethods.py
test/tests/intmethods.py
+4
-0
No files found.
src/runtime/int.cpp
View file @
d455a565
...
...
@@ -297,6 +297,25 @@ extern "C" Box* intMod(BoxedInt* lhs, Box* rhs) {
return
boxInt
(
mod_i64_i64
(
lhs
->
n
,
rhs_int
->
n
));
}
extern
"C"
Box
*
intDivmod
(
BoxedInt
*
lhs
,
Box
*
rhs
)
{
assert
(
lhs
->
cls
==
int_cls
);
Box
*
divResult
=
intDiv
(
lhs
,
rhs
);
if
(
divResult
==
NotImplemented
)
{
return
NotImplemented
;
}
Box
*
modResult
=
intMod
(
lhs
,
rhs
);
if
(
modResult
==
NotImplemented
)
{
return
NotImplemented
;
}
Box
*
arg
[
2
]
=
{
divResult
,
modResult
};
return
createTuple
(
2
,
arg
);
}
extern
"C"
Box
*
intMulInt
(
BoxedInt
*
lhs
,
BoxedInt
*
rhs
)
{
assert
(
lhs
->
cls
==
int_cls
);
assert
(
rhs
->
cls
==
int_cls
);
...
...
@@ -519,6 +538,7 @@ void setupInt() {
int_cls
->
giveAttr
(
"__repr__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
intRepr
,
STR
,
1
,
false
)));
int_cls
->
setattr
(
"__str__"
,
int_cls
->
peekattr
(
"__repr__"
),
NULL
,
NULL
);
int_cls
->
giveAttr
(
"__hash__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
intHash
,
BOXED_INT
,
1
,
false
)));
int_cls
->
giveAttr
(
"__divmod__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
intDivmod
,
BOXED_TUPLE
,
2
,
false
)));
CLFunction
*
__new__
=
boxRTFunction
((
void
*
)
intNew1
,
NULL
,
1
,
false
);
addRTFunction
(
__new__
,
(
void
*
)
intNew2
,
NULL
,
2
,
false
);
...
...
test/tests/intmethods.py
0 → 100644
View file @
d455a565
# can't try large numbers yet due to lack of long
for
i
in
xrange
(
1
,
100
):
for
j
in
xrange
(
1
,
100
):
print
i
.
__divmod__
(
j
)
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