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
24e0f10e
Commit
24e0f10e
authored
Jan 20, 2016
by
Boxiang Sun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
loosen the type check
parent
6e17f0e0
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
101 additions
and
85 deletions
+101
-85
src/runtime/float.cpp
src/runtime/float.cpp
+70
-70
src/runtime/int.cpp
src/runtime/int.cpp
+15
-15
test/tests/future_division.py
test/tests/future_division.py
+16
-0
No files found.
src/runtime/float.cpp
View file @
24e0f10e
...
...
@@ -115,24 +115,24 @@ extern "C" double floordiv_float_float(double lhs, double rhs) {
}
extern
"C"
Box
*
floatAddFloat
(
BoxedFloat
*
lhs
,
BoxedFloat
*
rhs
)
{
assert
(
lhs
->
cls
==
float_cls
);
assert
(
rhs
->
cls
==
float_cls
);
assert
(
PyFloat_Check
(
lhs
)
);
assert
(
PyFloat_Check
(
rhs
)
);
return
boxFloat
(
lhs
->
d
+
rhs
->
d
);
}
extern
"C"
Box
*
floatAddInt
(
BoxedFloat
*
lhs
,
BoxedInt
*
rhs
)
{
assert
(
lhs
->
cls
==
float_cls
);
assert
(
PyFloat_Check
(
lhs
)
);
assert
(
PyInt_Check
(
rhs
));
return
boxFloat
(
lhs
->
d
+
rhs
->
n
);
}
extern
"C"
Box
*
floatAdd
(
BoxedFloat
*
lhs
,
Box
*
rhs
)
{
assert
(
lhs
->
cls
==
float_cls
);
assert
(
PyFloat_Check
(
lhs
)
);
if
(
PyInt_Check
(
rhs
))
{
return
floatAddInt
(
lhs
,
static_cast
<
BoxedInt
*>
(
rhs
));
}
else
if
(
rhs
->
cls
==
float_cls
)
{
}
else
if
(
PyFloat_Check
(
rhs
)
)
{
return
floatAddFloat
(
lhs
,
static_cast
<
BoxedFloat
*>
(
rhs
));
}
else
if
(
rhs
->
cls
==
long_cls
)
{
}
else
if
(
PyLong_Check
(
rhs
)
)
{
double
rhs_f
=
PyLong_AsDouble
(
rhs
);
if
(
rhs_f
==
-
1.0
&&
PyErr_Occurred
())
{
throwCAPIException
();
...
...
@@ -144,26 +144,26 @@ extern "C" Box* floatAdd(BoxedFloat* lhs, Box* rhs) {
}
extern
"C"
Box
*
floatDivFloat
(
BoxedFloat
*
lhs
,
BoxedFloat
*
rhs
)
{
assert
(
lhs
->
cls
==
float_cls
);
assert
(
rhs
->
cls
==
float_cls
);
assert
(
PyFloat_Check
(
lhs
)
);
assert
(
PyFloat_Check
(
rhs
)
);
raiseDivZeroExcIfZero
(
rhs
->
d
);
return
boxFloat
(
lhs
->
d
/
rhs
->
d
);
}
extern
"C"
Box
*
floatDivInt
(
BoxedFloat
*
lhs
,
BoxedInt
*
rhs
)
{
assert
(
lhs
->
cls
==
float_cls
);
assert
(
PyFloat_Check
(
lhs
)
);
assert
(
PyInt_Check
(
rhs
));
raiseDivZeroExcIfZero
(
rhs
->
n
);
return
boxFloat
(
lhs
->
d
/
rhs
->
n
);
}
extern
"C"
Box
*
floatDiv
(
BoxedFloat
*
lhs
,
Box
*
rhs
)
{
assert
(
lhs
->
cls
==
float_cls
);
assert
(
PyFloat_Check
(
lhs
)
);
if
(
PyInt_Check
(
rhs
))
{
return
floatDivInt
(
lhs
,
static_cast
<
BoxedInt
*>
(
rhs
));
}
else
if
(
rhs
->
cls
==
float_cls
)
{
}
else
if
(
PyFloat_Check
(
rhs
)
)
{
return
floatDivFloat
(
lhs
,
static_cast
<
BoxedFloat
*>
(
rhs
));
}
else
if
(
rhs
->
cls
==
long_cls
)
{
}
else
if
(
PyLong_Check
(
rhs
)
)
{
double
rhs_f
=
PyLong_AsDouble
(
rhs
);
if
(
rhs_f
==
-
1.0
&&
PyErr_Occurred
())
{
throwCAPIException
();
...
...
@@ -175,12 +175,12 @@ extern "C" Box* floatDiv(BoxedFloat* lhs, Box* rhs) {
}
extern
"C"
Box
*
floatTruediv
(
BoxedFloat
*
lhs
,
Box
*
rhs
)
{
assert
(
lhs
->
cls
==
float_cls
);
assert
(
PyFloat_Check
(
lhs
)
);
if
(
PyInt_Check
(
rhs
))
{
return
floatDivInt
(
lhs
,
static_cast
<
BoxedInt
*>
(
rhs
));
}
else
if
(
rhs
->
cls
==
float_cls
)
{
}
else
if
(
PyFloat_Check
(
rhs
)
)
{
return
floatDivFloat
(
lhs
,
static_cast
<
BoxedFloat
*>
(
rhs
));
}
else
if
(
rhs
->
cls
==
long_cls
)
{
}
else
if
(
PyLong_Check
(
rhs
)
)
{
double
rhs_f
=
PyLong_AsDouble
(
rhs
);
if
(
rhs_f
==
-
1.0
&&
PyErr_Occurred
())
{
throwCAPIException
();
...
...
@@ -192,26 +192,26 @@ extern "C" Box* floatTruediv(BoxedFloat* lhs, Box* rhs) {
}
extern
"C"
Box
*
floatRDivFloat
(
BoxedFloat
*
lhs
,
BoxedFloat
*
rhs
)
{
assert
(
lhs
->
cls
==
float_cls
);
assert
(
rhs
->
cls
==
float_cls
);
assert
(
PyFloat_Check
(
lhs
)
);
assert
(
PyFloat_Check
(
rhs
)
);
raiseDivZeroExcIfZero
(
lhs
->
d
);
return
boxFloat
(
rhs
->
d
/
lhs
->
d
);
}
extern
"C"
Box
*
floatRDivInt
(
BoxedFloat
*
lhs
,
BoxedInt
*
rhs
)
{
assert
(
lhs
->
cls
==
float_cls
);
assert
(
PyFloat_Check
(
lhs
)
);
assert
(
PyInt_Check
(
rhs
));
raiseDivZeroExcIfZero
(
lhs
->
d
);
return
boxFloat
(
rhs
->
n
/
lhs
->
d
);
}
extern
"C"
Box
*
floatRDiv
(
BoxedFloat
*
lhs
,
Box
*
rhs
)
{
assert
(
lhs
->
cls
==
float_cls
);
assert
(
PyFloat_Check
(
lhs
)
);
if
(
PyInt_Check
(
rhs
))
{
return
floatRDivInt
(
lhs
,
static_cast
<
BoxedInt
*>
(
rhs
));
}
else
if
(
rhs
->
cls
==
float_cls
)
{
}
else
if
(
PyFloat_Check
(
rhs
)
)
{
return
floatRDivFloat
(
lhs
,
static_cast
<
BoxedFloat
*>
(
rhs
));
}
else
if
(
rhs
->
cls
==
long_cls
)
{
}
else
if
(
PyLong_Check
(
rhs
)
)
{
double
rhs_f
=
PyLong_AsDouble
(
rhs
);
if
(
rhs_f
==
-
1.0
&&
PyErr_Occurred
())
{
throwCAPIException
();
...
...
@@ -245,26 +245,26 @@ Box* floatRTruediv(BoxedFloat* lhs, Box* rhs) {
}
extern
"C"
Box
*
floatFloorDivFloat
(
BoxedFloat
*
lhs
,
BoxedFloat
*
rhs
)
{
assert
(
lhs
->
cls
==
float_cls
);
assert
(
rhs
->
cls
==
float_cls
);
assert
(
PyFloat_Check
(
lhs
)
);
assert
(
PyFloat_Check
(
rhs
)
);
raiseDivZeroExcIfZero
(
rhs
->
d
);
return
boxFloat
(
floor
(
lhs
->
d
/
rhs
->
d
));
}
extern
"C"
Box
*
floatFloorDivInt
(
BoxedFloat
*
lhs
,
BoxedInt
*
rhs
)
{
assert
(
lhs
->
cls
==
float_cls
);
assert
(
PyFloat_Check
(
lhs
)
);
assert
(
PyInt_Check
(
rhs
));
raiseDivZeroExcIfZero
(
rhs
->
n
);
return
boxFloat
(
floor
(
lhs
->
d
/
rhs
->
n
));
}
extern
"C"
Box
*
floatFloorDiv
(
BoxedFloat
*
lhs
,
Box
*
rhs
)
{
assert
(
lhs
->
cls
==
float_cls
);
assert
(
PyFloat_Check
(
lhs
)
);
if
(
PyInt_Check
(
rhs
))
{
return
floatFloorDivInt
(
lhs
,
static_cast
<
BoxedInt
*>
(
rhs
));
}
else
if
(
rhs
->
cls
==
float_cls
)
{
}
else
if
(
PyFloat_Check
(
rhs
)
)
{
return
floatFloorDivFloat
(
lhs
,
static_cast
<
BoxedFloat
*>
(
rhs
));
}
else
if
(
rhs
->
cls
==
long_cls
)
{
}
else
if
(
PyLong_Check
(
rhs
)
)
{
double
rhs_f
=
PyLong_AsDouble
(
rhs
);
if
(
rhs_f
==
-
1.0
&&
PyErr_Occurred
())
{
throwCAPIException
();
...
...
@@ -276,16 +276,16 @@ extern "C" Box* floatFloorDiv(BoxedFloat* lhs, Box* rhs) {
}
extern
"C"
Box
*
floatRFloorDiv
(
BoxedFloat
*
lhs
,
Box
*
_rhs
)
{
assert
(
lhs
->
cls
==
float_cls
);
assert
(
PyFloat_Check
(
lhs
)
);
if
(
PyInt_Check
(
_rhs
))
{
BoxedInt
*
rhs
=
(
BoxedInt
*
)
_rhs
;
raiseDivZeroExcIfZero
(
lhs
->
d
);
return
boxFloat
(
floor
(
rhs
->
n
/
lhs
->
d
));
}
else
if
(
_rhs
->
cls
==
float_cls
)
{
}
else
if
(
PyFloat_Check
(
_rhs
)
)
{
BoxedFloat
*
rhs
=
(
BoxedFloat
*
)
_rhs
;
raiseDivZeroExcIfZero
(
lhs
->
d
);
return
boxFloat
(
floor
(
rhs
->
d
/
lhs
->
d
));
}
else
if
(
_rhs
->
cls
==
long_cls
)
{
}
else
if
(
PyLong_Check
(
_rhs
)
)
{
double
rhs_f
=
PyLong_AsDouble
(
_rhs
);
if
(
rhs_f
==
-
1.0
&&
PyErr_Occurred
())
{
throwCAPIException
();
...
...
@@ -599,24 +599,24 @@ extern "C" Box* floatGt(BoxedFloat* lhs, Box* rhs) {
}
extern
"C"
Box
*
floatModFloat
(
BoxedFloat
*
lhs
,
BoxedFloat
*
rhs
)
{
assert
(
lhs
->
cls
==
float_cls
);
assert
(
rhs
->
cls
==
float_cls
);
assert
(
PyFloat_Check
(
lhs
)
);
assert
(
PyFloat_Check
(
rhs
)
);
return
boxFloat
(
mod_float_float
(
lhs
->
d
,
rhs
->
d
));
}
extern
"C"
Box
*
floatModInt
(
BoxedFloat
*
lhs
,
BoxedInt
*
rhs
)
{
assert
(
lhs
->
cls
==
float_cls
);
assert
(
PyFloat_Check
(
lhs
)
);
assert
(
PyInt_Check
(
rhs
));
return
boxFloat
(
mod_float_float
(
lhs
->
d
,
rhs
->
n
));
}
extern
"C"
Box
*
floatMod
(
BoxedFloat
*
lhs
,
Box
*
rhs
)
{
assert
(
lhs
->
cls
==
float_cls
);
assert
(
PyFloat_Check
(
lhs
)
);
if
(
PyInt_Check
(
rhs
))
{
return
floatModInt
(
lhs
,
static_cast
<
BoxedInt
*>
(
rhs
));
}
else
if
(
rhs
->
cls
==
float_cls
)
{
}
else
if
(
PyFloat_Check
(
rhs
)
)
{
return
floatModFloat
(
lhs
,
static_cast
<
BoxedFloat
*>
(
rhs
));
}
else
if
(
rhs
->
cls
==
long_cls
)
{
}
else
if
(
PyLong_Check
(
rhs
)
)
{
double
rhs_f
=
PyLong_AsDouble
(
rhs
);
if
(
rhs_f
==
-
1.0
&&
PyErr_Occurred
())
{
throwCAPIException
();
...
...
@@ -628,24 +628,24 @@ extern "C" Box* floatMod(BoxedFloat* lhs, Box* rhs) {
}
extern
"C"
Box
*
floatRModFloat
(
BoxedFloat
*
lhs
,
BoxedFloat
*
rhs
)
{
assert
(
lhs
->
cls
==
float_cls
);
assert
(
rhs
->
cls
==
float_cls
);
assert
(
PyFloat_Check
(
lhs
)
);
assert
(
PyFloat_Check
(
rhs
)
);
return
boxFloat
(
mod_float_float
(
rhs
->
d
,
lhs
->
d
));
}
extern
"C"
Box
*
floatRModInt
(
BoxedFloat
*
lhs
,
BoxedInt
*
rhs
)
{
assert
(
lhs
->
cls
==
float_cls
);
assert
(
PyFloat_Check
(
lhs
)
);
assert
(
PyInt_Check
(
rhs
));
return
boxFloat
(
mod_float_float
(
rhs
->
n
,
lhs
->
d
));
}
extern
"C"
Box
*
floatRMod
(
BoxedFloat
*
lhs
,
Box
*
rhs
)
{
assert
(
lhs
->
cls
==
float_cls
);
assert
(
PyFloat_Check
(
lhs
)
);
if
(
PyInt_Check
(
rhs
))
{
return
floatRModInt
(
lhs
,
static_cast
<
BoxedInt
*>
(
rhs
));
}
else
if
(
rhs
->
cls
==
float_cls
)
{
}
else
if
(
PyFloat_Check
(
rhs
)
)
{
return
floatRModFloat
(
lhs
,
static_cast
<
BoxedFloat
*>
(
rhs
));
}
else
if
(
rhs
->
cls
==
long_cls
)
{
}
else
if
(
PyLong_Check
(
rhs
)
)
{
double
rhs_f
=
PyLong_AsDouble
(
rhs
);
if
(
rhs_f
==
-
1.0
&&
PyErr_Occurred
())
{
throwCAPIException
();
...
...
@@ -690,14 +690,14 @@ extern "C" Box* floatPow(BoxedFloat* lhs, Box* rhs, Box* mod) {
extern
"C"
Box
*
floatPowFloat
(
BoxedFloat
*
lhs
,
BoxedFloat
*
rhs
,
Box
*
mod
=
None
)
{
// TODO to specialize this, need to account for all the special cases in float_pow
assert
(
lhs
->
cls
==
float_cls
);
assert
(
rhs
->
cls
==
float_cls
);
assert
(
PyFloat_Check
(
lhs
)
);
assert
(
PyFloat_Check
(
rhs
)
);
return
floatPow
(
lhs
,
rhs
,
mod
);
}
extern
"C"
Box
*
floatPowInt
(
BoxedFloat
*
lhs
,
BoxedInt
*
rhs
,
Box
*
mod
=
None
)
{
// TODO to specialize this, need to account for all the special cases in float_pow
assert
(
lhs
->
cls
==
float_cls
);
assert
(
PyFloat_Check
(
lhs
)
);
assert
(
PyInt_Check
(
rhs
));
return
floatPow
(
lhs
,
rhs
,
mod
);
}
...
...
@@ -725,24 +725,24 @@ extern "C" double pow_float_float(double lhs, double rhs) {
}
extern
"C"
Box
*
floatMulFloat
(
BoxedFloat
*
lhs
,
BoxedFloat
*
rhs
)
{
assert
(
lhs
->
cls
==
float_cls
);
assert
(
rhs
->
cls
==
float_cls
);
assert
(
PyFloat_Check
(
lhs
)
);
assert
(
PyFloat_Check
(
rhs
)
);
return
boxFloat
(
lhs
->
d
*
rhs
->
d
);
}
extern
"C"
Box
*
floatMulInt
(
BoxedFloat
*
lhs
,
BoxedInt
*
rhs
)
{
assert
(
lhs
->
cls
==
float_cls
);
assert
(
PyFloat_Check
(
lhs
)
);
assert
(
PyInt_Check
(
rhs
));
return
boxFloat
(
lhs
->
d
*
rhs
->
n
);
}
extern
"C"
Box
*
floatMul
(
BoxedFloat
*
lhs
,
Box
*
rhs
)
{
assert
(
lhs
->
cls
==
float_cls
);
assert
(
PyFloat_Check
(
lhs
)
);
if
(
PyInt_Check
(
rhs
))
{
return
floatMulInt
(
lhs
,
static_cast
<
BoxedInt
*>
(
rhs
));
}
else
if
(
rhs
->
cls
==
float_cls
)
{
}
else
if
(
PyFloat_Check
(
rhs
)
)
{
return
floatMulFloat
(
lhs
,
static_cast
<
BoxedFloat
*>
(
rhs
));
}
else
if
(
rhs
->
cls
==
long_cls
)
{
}
else
if
(
PyLong_Check
(
rhs
)
)
{
double
rhs_f
=
PyLong_AsDouble
(
rhs
);
if
(
rhs_f
==
-
1.0
&&
PyErr_Occurred
())
{
throwCAPIException
();
...
...
@@ -754,24 +754,24 @@ extern "C" Box* floatMul(BoxedFloat* lhs, Box* rhs) {
}
extern
"C"
Box
*
floatSubFloat
(
BoxedFloat
*
lhs
,
BoxedFloat
*
rhs
)
{
assert
(
lhs
->
cls
==
float_cls
);
assert
(
rhs
->
cls
==
float_cls
);
assert
(
PyFloat_Check
(
lhs
)
);
assert
(
PyFloat_Check
(
rhs
)
);
return
boxFloat
(
lhs
->
d
-
rhs
->
d
);
}
extern
"C"
Box
*
floatSubInt
(
BoxedFloat
*
lhs
,
BoxedInt
*
rhs
)
{
assert
(
lhs
->
cls
==
float_cls
);
assert
(
PyFloat_Check
(
lhs
)
);
assert
(
PyInt_Check
(
rhs
));
return
boxFloat
(
lhs
->
d
-
rhs
->
n
);
}
extern
"C"
Box
*
floatSub
(
BoxedFloat
*
lhs
,
Box
*
rhs
)
{
assert
(
lhs
->
cls
==
float_cls
);
assert
(
PyFloat_Check
(
lhs
)
);
if
(
PyInt_Check
(
rhs
))
{
return
floatSubInt
(
lhs
,
static_cast
<
BoxedInt
*>
(
rhs
));
}
else
if
(
rhs
->
cls
==
float_cls
)
{
}
else
if
(
PyFloat_Check
(
rhs
)
)
{
return
floatSubFloat
(
lhs
,
static_cast
<
BoxedFloat
*>
(
rhs
));
}
else
if
(
rhs
->
cls
==
long_cls
)
{
}
else
if
(
PyLong_Check
(
rhs
)
)
{
double
rhs_f
=
PyLong_AsDouble
(
rhs
);
if
(
rhs_f
==
-
1.0
&&
PyErr_Occurred
())
{
throwCAPIException
();
...
...
@@ -783,24 +783,24 @@ extern "C" Box* floatSub(BoxedFloat* lhs, Box* rhs) {
}
extern
"C"
Box
*
floatRSubFloat
(
BoxedFloat
*
lhs
,
BoxedFloat
*
rhs
)
{
assert
(
lhs
->
cls
==
float_cls
);
assert
(
rhs
->
cls
==
float_cls
);
assert
(
PyFloat_Check
(
lhs
)
);
assert
(
PyFloat_Check
(
rhs
)
);
return
boxFloat
(
rhs
->
d
-
lhs
->
d
);
}
extern
"C"
Box
*
floatRSubInt
(
BoxedFloat
*
lhs
,
BoxedInt
*
rhs
)
{
assert
(
lhs
->
cls
==
float_cls
);
assert
(
PyFloat_Check
(
lhs
)
);
assert
(
PyInt_Check
(
rhs
));
return
boxFloat
(
rhs
->
n
-
lhs
->
d
);
}
extern
"C"
Box
*
floatRSub
(
BoxedFloat
*
lhs
,
Box
*
rhs
)
{
assert
(
lhs
->
cls
==
float_cls
);
assert
(
PyFloat_Check
(
lhs
)
);
if
(
PyInt_Check
(
rhs
))
{
return
floatRSubInt
(
lhs
,
static_cast
<
BoxedInt
*>
(
rhs
));
}
else
if
(
rhs
->
cls
==
float_cls
)
{
}
else
if
(
PyFloat_Check
(
rhs
)
)
{
return
floatRSubFloat
(
lhs
,
static_cast
<
BoxedFloat
*>
(
rhs
));
}
else
if
(
rhs
->
cls
==
long_cls
)
{
}
else
if
(
PyLong_Check
(
rhs
)
)
{
double
rhs_f
=
PyLong_AsDouble
(
rhs
);
if
(
rhs_f
==
-
1.0
&&
PyErr_Occurred
())
{
throwCAPIException
();
...
...
@@ -812,12 +812,12 @@ extern "C" Box* floatRSub(BoxedFloat* lhs, Box* rhs) {
}
Box
*
floatNeg
(
BoxedFloat
*
self
)
{
assert
(
self
->
cls
==
float_cls
);
assert
(
PyFloat_Check
(
self
)
);
return
boxFloat
(
-
self
->
d
);
}
Box
*
floatPos
(
BoxedFloat
*
self
)
{
assert
(
self
->
cls
==
float_cls
);
assert
(
PyFloat_Check
(
self
)
);
return
PyFloat_FromDouble
(
self
->
d
);
}
...
...
@@ -830,7 +830,7 @@ Box* floatAbs(BoxedFloat* self) {
}
bool
floatNonzeroUnboxed
(
BoxedFloat
*
self
)
{
assert
(
self
->
cls
==
float_cls
);
assert
(
PyFloat_Check
(
self
)
);
return
self
->
d
!=
0.0
;
}
...
...
@@ -1115,18 +1115,18 @@ extern "C" void printFloat(double d) {
static
void
_addFunc
(
const
char
*
name
,
ConcreteCompilerType
*
rtn_type
,
void
*
float_func
,
void
*
int_func
,
void
*
boxed_func
)
{
std
::
vector
<
ConcreteCompilerType
*>
v_ff
,
v_fi
,
v_
f
u
;
std
::
vector
<
ConcreteCompilerType
*>
v_ff
,
v_fi
,
v_
u
u
;
v_ff
.
push_back
(
BOXED_FLOAT
);
v_ff
.
push_back
(
BOXED_FLOAT
);
v_fi
.
push_back
(
BOXED_FLOAT
);
v_fi
.
push_back
(
BOXED_INT
);
v_
fu
.
push_back
(
BOXED_FLOAT
);
v_
f
u
.
push_back
(
UNKNOWN
);
v_
uu
.
push_back
(
UNKNOWN
);
v_
u
u
.
push_back
(
UNKNOWN
);
FunctionMetadata
*
md
=
new
FunctionMetadata
(
2
,
false
,
false
);
md
->
addVersion
(
float_func
,
rtn_type
,
v_ff
);
md
->
addVersion
(
int_func
,
rtn_type
,
v_fi
);
md
->
addVersion
(
boxed_func
,
UNKNOWN
,
v_
f
u
);
md
->
addVersion
(
boxed_func
,
UNKNOWN
,
v_
u
u
);
float_cls
->
giveAttr
(
name
,
new
BoxedFunction
(
md
));
}
...
...
src/runtime/int.cpp
View file @
24e0f10e
...
...
@@ -415,7 +415,7 @@ extern "C" Box* intAddInt(BoxedInt* lhs, BoxedInt* rhs) {
extern
"C"
Box
*
intAddFloat
(
BoxedInt
*
lhs
,
BoxedFloat
*
rhs
)
{
assert
(
PyInt_Check
(
lhs
));
assert
(
rhs
->
cls
==
float_cls
);
assert
(
PyFloat_Check
(
rhs
)
);
return
boxFloat
(
lhs
->
n
+
rhs
->
d
);
}
...
...
@@ -426,7 +426,7 @@ extern "C" Box* intAdd(BoxedInt* lhs, Box* rhs) {
if
(
PyInt_Check
(
rhs
))
{
BoxedInt
*
rhs_int
=
static_cast
<
BoxedInt
*>
(
rhs
);
return
add_i64_i64
(
lhs
->
n
,
rhs_int
->
n
);
}
else
if
(
rhs
->
cls
==
float_cls
)
{
}
else
if
(
PyFloat_Check
(
rhs
)
)
{
BoxedFloat
*
rhs_float
=
static_cast
<
BoxedFloat
*>
(
rhs
);
return
boxFloat
(
lhs
->
n
+
rhs_float
->
d
);
}
else
{
...
...
@@ -541,7 +541,7 @@ extern "C" Box* intDivInt(BoxedInt* lhs, BoxedInt* rhs) {
extern
"C"
Box
*
intDivFloat
(
BoxedInt
*
lhs
,
BoxedFloat
*
rhs
)
{
assert
(
PyInt_Check
(
lhs
));
assert
(
rhs
->
cls
==
float_cls
);
assert
(
PyFloat_Check
(
rhs
)
);
if
(
rhs
->
d
==
0
)
{
raiseExcHelper
(
ZeroDivisionError
,
"float divide by zero"
);
...
...
@@ -555,7 +555,7 @@ extern "C" Box* intDiv(BoxedInt* lhs, Box* rhs) {
if
(
PyInt_Check
(
rhs
))
{
return
intDivInt
(
lhs
,
static_cast
<
BoxedInt
*>
(
rhs
));
}
else
if
(
rhs
->
cls
==
float_cls
)
{
}
else
if
(
PyFloat_Check
(
rhs
)
)
{
return
intDivFloat
(
lhs
,
static_cast
<
BoxedFloat
*>
(
rhs
));
}
else
{
return
NotImplemented
;
...
...
@@ -582,7 +582,7 @@ extern "C" Box* intFloordivInt(BoxedInt* lhs, BoxedInt* rhs) {
extern
"C"
Box
*
intFloordivFloat
(
BoxedInt
*
lhs
,
BoxedFloat
*
rhs
)
{
assert
(
PyInt_Check
(
lhs
));
assert
(
rhs
->
cls
==
float_cls
);
assert
(
PyFloat_Check
(
rhs
)
);
if
(
rhs
->
d
==
0
)
{
raiseExcHelper
(
ZeroDivisionError
,
"float divide by zero"
);
...
...
@@ -597,7 +597,7 @@ extern "C" Box* intFloordiv(BoxedInt* lhs, Box* rhs) {
if
(
PyInt_Check
(
rhs
))
{
return
intFloordivInt
(
lhs
,
static_cast
<
BoxedInt
*>
(
rhs
));
}
else
if
(
rhs
->
cls
==
float_cls
)
{
}
else
if
(
PyFloat_Check
(
rhs
)
)
{
return
intFloordivFloat
(
lhs
,
static_cast
<
BoxedFloat
*>
(
rhs
));
}
else
{
return
NotImplemented
;
...
...
@@ -628,7 +628,7 @@ extern "C" Box* intTruedivInt(BoxedInt* lhs, BoxedInt* rhs) {
extern
"C"
Box
*
intTruedivFloat
(
BoxedInt
*
lhs
,
BoxedFloat
*
rhs
)
{
assert
(
PyInt_Check
(
lhs
));
assert
(
rhs
->
cls
==
float_cls
);
assert
(
PyFloat_Check
(
rhs
)
);
if
(
rhs
->
d
==
0
)
{
raiseExcHelper
(
ZeroDivisionError
,
"division by zero"
);
...
...
@@ -643,7 +643,7 @@ extern "C" Box* intTruediv(BoxedInt* lhs, Box* rhs) {
if
(
PyInt_Check
(
rhs
))
{
return
intTruedivInt
(
lhs
,
static_cast
<
BoxedInt
*>
(
rhs
));
}
else
if
(
rhs
->
cls
==
float_cls
)
{
}
else
if
(
PyFloat_Check
(
rhs
)
)
{
return
intTruedivFloat
(
lhs
,
static_cast
<
BoxedFloat
*>
(
rhs
));
}
else
{
return
NotImplemented
;
...
...
@@ -683,7 +683,7 @@ extern "C" Box* intLShift(BoxedInt* lhs, Box* rhs) {
raiseExcHelper
(
TypeError
,
"descriptor '__lshift__' requires a 'int' object but received a '%s'"
,
getTypeName
(
lhs
));
if
(
rhs
->
cls
==
long_cls
)
if
(
PyLong_Check
(
rhs
)
)
return
longLShiftLong
(
boxLong
(
lhs
->
n
),
rhs
);
if
(
!
PyInt_Check
(
rhs
))
{
...
...
@@ -775,7 +775,7 @@ extern "C" Box* intMulInt(BoxedInt* lhs, BoxedInt* rhs) {
extern
"C"
Box
*
intMulFloat
(
BoxedInt
*
lhs
,
BoxedFloat
*
rhs
)
{
assert
(
PyInt_Check
(
lhs
));
assert
(
rhs
->
cls
==
float_cls
);
assert
(
PyFloat_Check
(
rhs
)
);
return
boxFloat
(
lhs
->
n
*
rhs
->
d
);
}
...
...
@@ -786,7 +786,7 @@ extern "C" Box* intMul(BoxedInt* lhs, Box* rhs) {
if
(
PyInt_Check
(
rhs
))
{
BoxedInt
*
rhs_int
=
static_cast
<
BoxedInt
*>
(
rhs
);
return
intMulInt
(
lhs
,
rhs_int
);
}
else
if
(
rhs
->
cls
==
float_cls
)
{
}
else
if
(
PyFloat_Check
(
rhs
)
)
{
BoxedFloat
*
rhs_float
=
static_cast
<
BoxedFloat
*>
(
rhs
);
return
intMulFloat
(
lhs
,
rhs_float
);
}
else
{
...
...
@@ -824,7 +824,7 @@ extern "C" Box* intPowLong(BoxedInt* lhs, BoxedLong* rhs, Box* mod) {
extern
"C"
Box
*
intPowFloat
(
BoxedInt
*
lhs
,
BoxedFloat
*
rhs
,
Box
*
mod
)
{
assert
(
PyInt_Check
(
lhs
));
assert
(
rhs
->
cls
==
float_cls
);
assert
(
PyFloat_Check
(
rhs
)
);
if
(
mod
!=
None
)
{
raiseExcHelper
(
TypeError
,
"pow() 3rd argument not allowed unless all arguments are integers"
);
...
...
@@ -892,7 +892,7 @@ extern "C" Box* intRShift(BoxedInt* lhs, Box* rhs) {
raiseExcHelper
(
TypeError
,
"descriptor '__rshift__' requires a 'int' object but received a '%s'"
,
getTypeName
(
lhs
));
if
(
rhs
->
cls
==
long_cls
)
if
(
PyLong_Check
(
rhs
)
)
return
longRShiftLong
(
boxLong
(
lhs
->
n
),
rhs
);
if
(
!
PyInt_Check
(
rhs
))
{
...
...
@@ -922,7 +922,7 @@ extern "C" Box* intSubInt(BoxedInt* lhs, BoxedInt* rhs) {
extern
"C"
Box
*
intSubFloat
(
BoxedInt
*
lhs
,
BoxedFloat
*
rhs
)
{
assert
(
PyInt_Check
(
lhs
));
assert
(
rhs
->
cls
==
float_cls
);
assert
(
PyFloat_Check
(
rhs
)
);
return
boxFloat
(
lhs
->
n
-
rhs
->
d
);
}
...
...
@@ -933,7 +933,7 @@ extern "C" Box* intSub(BoxedInt* lhs, Box* rhs) {
if
(
PyInt_Check
(
rhs
))
{
BoxedInt
*
rhs_int
=
static_cast
<
BoxedInt
*>
(
rhs
);
return
intSubInt
(
lhs
,
rhs_int
);
}
else
if
(
rhs
->
cls
==
float_cls
)
{
}
else
if
(
PyFloat_Check
(
rhs
)
)
{
BoxedFloat
*
rhs_float
=
static_cast
<
BoxedFloat
*>
(
rhs
);
return
intSubFloat
(
lhs
,
rhs_float
);
}
else
{
...
...
test/tests/future_division.py
View file @
24e0f10e
...
...
@@ -22,3 +22,19 @@ test(-3.0, -2.0)
test
(
1.0
+
1.0j
,
2
)
test
(
1.0
+
1.0j
,
2.0
)
test
(
1.0
+
1.0j
,
2.0j
)
class
PhysicalQuantity
(
float
):
def
__new__
(
cls
,
value
):
return
float
.
__new__
(
cls
,
value
)
def
__div__
(
self
,
x
):
print
(
'__div__ get called'
)
return
PhysicalQuantity
(
float
(
self
)
/
float
(
x
))
def
__rdiv__
(
self
,
x
):
print
(
'__rdiv__ get called'
)
return
PhysicalQuantity
(
float
(
x
)
/
float
(
self
))
a
=
PhysicalQuantity
(
2.0
)
print
(
a
/
3.0
)
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