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
71e74437
Commit
71e74437
authored
Mar 26, 2015
by
Marius Wachtler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add PyNumber_TrueDivide and basic long.__truediv__() support
but both args have to fit into an int...
parent
47ba50be
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
50 additions
and
6 deletions
+50
-6
src/capi/abstract.cpp
src/capi/abstract.cpp
+7
-2
src/runtime/long.cpp
src/runtime/long.cpp
+40
-0
test/tests/long.py
test/tests/long.py
+3
-4
No files found.
src/capi/abstract.cpp
View file @
71e74437
...
...
@@ -1209,8 +1209,13 @@ extern "C" PyObject* PyNumber_FloorDivide(PyObject*, PyObject*) noexcept {
Py_FatalError
(
"unimplemented"
);
}
extern
"C"
PyObject
*
PyNumber_TrueDivide
(
PyObject
*
,
PyObject
*
)
noexcept
{
Py_FatalError
(
"unimplemented"
);
extern
"C"
PyObject
*
PyNumber_TrueDivide
(
PyObject
*
lhs
,
PyObject
*
rhs
)
noexcept
{
try
{
return
binop
(
lhs
,
rhs
,
AST_TYPE
::
TrueDiv
);
}
catch
(
ExcInfo
e
)
{
setCAPIException
(
e
);
return
NULL
;
}
}
extern
"C"
PyObject
*
PyNumber_Remainder
(
PyObject
*
lhs
,
PyObject
*
rhs
)
noexcept
{
...
...
src/runtime/long.cpp
View file @
71e74437
...
...
@@ -980,6 +980,44 @@ Box* longRdiv(BoxedLong* v1, Box* _v2) {
}
}
Box
*
longTrueDiv
(
BoxedLong
*
v1
,
Box
*
_v2
)
{
if
(
!
isSubclass
(
v1
->
cls
,
long_cls
))
raiseExcHelper
(
TypeError
,
"descriptor '__truediv__' requires a 'long' object but received a '%s'"
,
getTypeName
(
v1
));
// We only support args which fit into an int for now...
int
overflow
=
0
;
long
lhs
=
PyLong_AsLongAndOverflow
(
v1
,
&
overflow
);
if
(
overflow
)
return
NotImplemented
;
long
rhs
=
PyLong_AsLongAndOverflow
(
_v2
,
&
overflow
);
if
(
overflow
)
return
NotImplemented
;
if
(
rhs
==
0
)
raiseExcHelper
(
ZeroDivisionError
,
"division by zero"
);
return
boxFloat
(
lhs
/
(
double
)
rhs
);
}
Box
*
longRTrueDiv
(
BoxedLong
*
v1
,
Box
*
_v2
)
{
if
(
!
isSubclass
(
v1
->
cls
,
long_cls
))
raiseExcHelper
(
TypeError
,
"descriptor '__rtruediv__' requires a 'long' object but received a '%s'"
,
getTypeName
(
v1
));
// We only support args which fit into an int for now...
int
overflow
=
0
;
long
lhs
=
PyLong_AsLongAndOverflow
(
_v2
,
&
overflow
);
if
(
overflow
)
return
NotImplemented
;
long
rhs
=
PyLong_AsLongAndOverflow
(
v1
,
&
overflow
);
if
(
overflow
)
return
NotImplemented
;
if
(
rhs
==
0
)
raiseExcHelper
(
ZeroDivisionError
,
"division by zero"
);
return
boxFloat
(
lhs
/
(
double
)
rhs
);
}
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
));
...
...
@@ -1074,6 +1112,8 @@ void setupLong() {
long_cls
->
giveAttr
(
"__div__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
longDiv
,
UNKNOWN
,
2
)));
long_cls
->
giveAttr
(
"__rdiv__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
longRdiv
,
UNKNOWN
,
2
)));
long_cls
->
giveAttr
(
"__truediv__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
longTrueDiv
,
UNKNOWN
,
2
)));
long_cls
->
giveAttr
(
"__rtruediv__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
longRTrueDiv
,
UNKNOWN
,
2
)));
long_cls
->
giveAttr
(
"__divmod__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
longDivmod
,
UNKNOWN
,
2
)));
...
...
test/tests/long.py
View file @
71e74437
...
...
@@ -31,10 +31,9 @@ for a in [-5, -1, 1, 5, -2L, -1L, 1L, 2L, 15L]:
test
(
1L
,
2.0
)
test
(
3.0
,
2L
)
print
(
2L
).
__rdiv__
(
-
1
)
print
(
2L
).
__rdiv__
(
-
1L
)
print
(
-
2L
).
__rdiv__
(
1L
)
print
(
-
2L
).
__rdiv__
(
1
)
for
lhs
in
[
2L
,
-
2L
]:
for
rhs
in
[
-
1
,
-
1L
,
1
,
2L
]:
print
lhs
.
__rdiv__
(
rhs
),
lhs
.
__truediv__
(
rhs
),
lhs
.
__rtruediv__
(
rhs
)
print
(
1L
)
<<
(
2L
)
print
(
1L
)
<<
(
2
)
...
...
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