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
fc46bc42
Commit
fc46bc42
authored
Feb 11, 2016
by
Kevin Modzelewski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add a whole bunch of refcounting annotations
parent
0b1acea8
Changes
16
Hide whitespace changes
Inline
Side-by-side
Showing
16 changed files
with
150 additions
and
106 deletions
+150
-106
src/codegen/ast_interpreter.cpp
src/codegen/ast_interpreter.cpp
+23
-3
src/codegen/irgen/hooks.cpp
src/codegen/irgen/hooks.cpp
+1
-1
src/runtime/classobj.cpp
src/runtime/classobj.cpp
+2
-2
src/runtime/complex.cpp
src/runtime/complex.cpp
+10
-10
src/runtime/dict.cpp
src/runtime/dict.cpp
+1
-1
src/runtime/float.cpp
src/runtime/float.cpp
+10
-10
src/runtime/inline/list.cpp
src/runtime/inline/list.cpp
+8
-0
src/runtime/int.cpp
src/runtime/int.cpp
+16
-16
src/runtime/list.cpp
src/runtime/list.cpp
+32
-23
src/runtime/list.h
src/runtime/list.h
+1
-1
src/runtime/long.cpp
src/runtime/long.cpp
+20
-20
src/runtime/objmodel.cpp
src/runtime/objmodel.cpp
+4
-0
src/runtime/set.cpp
src/runtime/set.cpp
+8
-8
src/runtime/str.cpp
src/runtime/str.cpp
+9
-9
src/runtime/tuple.cpp
src/runtime/tuple.cpp
+4
-1
src/runtime/types.cpp
src/runtime/types.cpp
+1
-1
No files found.
src/codegen/ast_interpreter.cpp
View file @
fc46bc42
...
...
@@ -544,6 +544,10 @@ void ASTInterpreter::doStore(AST_expr* node, STOLEN(Value) value) {
Value
target
=
visit_expr
(
subscript
->
value
);
Value
slice
=
visit_slice
(
subscript
->
slice
);
AUTO_DECREF
(
target
.
o
);
AUTO_DECREF
(
slice
.
o
);
AUTO_DECREF
(
value
.
o
);
if
(
jit
)
jit
->
emitSetItem
(
target
,
slice
,
value
);
setitem
(
target
.
o
,
slice
.
o
,
value
.
o
);
...
...
@@ -602,6 +606,9 @@ Value ASTInterpreter::visit_slice(AST_Slice* node) {
Value
lower
=
node
->
lower
?
visit_expr
(
node
->
lower
)
:
getNone
();
Value
upper
=
node
->
upper
?
visit_expr
(
node
->
upper
)
:
getNone
();
Value
step
=
node
->
step
?
visit_expr
(
node
->
step
)
:
getNone
();
AUTO_DECREF
(
lower
.
o
);
AUTO_DECREF
(
upper
.
o
);
AUTO_DECREF
(
step
.
o
);
Value
v
;
if
(
jit
)
...
...
@@ -877,11 +884,15 @@ Value ASTInterpreter::visit_langPrimitive(AST_LangPrimitive* node) {
assert
(
node
->
args
[
1
]
->
type
==
AST_TYPE
::
Str
);
Value
module
=
visit_expr
(
node
->
args
[
0
]);
AUTO_DECREF
(
module
.
o
);
auto
ast_str
=
ast_cast
<
AST_Str
>
(
node
->
args
[
1
]);
assert
(
ast_str
->
str_type
==
AST_Str
::
STR
);
const
std
::
string
&
name
=
ast_str
->
str_data
;
assert
(
name
.
size
());
BoxedString
*
name_boxed
=
source_info
->
parent_module
->
getStringConstant
(
name
,
true
);
AUTO_DECREF
(
name_boxed
);
if
(
jit
)
v
.
var
=
jit
->
emitImportFrom
(
module
,
name_boxed
);
v
.
o
=
importFrom
(
module
.
o
,
name_boxed
);
...
...
@@ -1246,6 +1257,8 @@ Value ASTInterpreter::visit_delete(AST_Delete* node) {
AST_Subscript
*
sub
=
(
AST_Subscript
*
)
target_
;
Value
value
=
visit_expr
(
sub
->
value
);
Value
slice
=
visit_slice
(
sub
->
slice
);
AUTO_DECREF
(
value
.
o
);
AUTO_DECREF
(
slice
.
o
);
if
(
jit
)
jit
->
emitDelItem
(
value
,
slice
);
delitem
(
value
.
o
,
slice
.
o
);
...
...
@@ -1625,6 +1638,9 @@ Value ASTInterpreter::visit_subscript(AST_Subscript* node) {
Value
value
=
visit_expr
(
node
->
value
);
Value
slice
=
visit_slice
(
node
->
slice
);
AUTO_DECREF
(
value
.
o
);
AUTO_DECREF
(
slice
.
o
);
return
Value
(
getitem
(
value
.
o
,
slice
.
o
),
jit
?
jit
->
emitGetItem
(
node
,
value
,
slice
)
:
NULL
);
}
...
...
@@ -1634,9 +1650,13 @@ Value ASTInterpreter::visit_list(AST_List* node) {
BoxedList
*
list
=
new
BoxedList
();
list
->
ensure
(
node
->
elts
.
size
());
for
(
AST_expr
*
e
:
node
->
elts
)
{
Value
v
=
visit_expr
(
e
);
items
.
push_back
(
v
);
listAppendInternalStolen
(
list
,
v
.
o
);
try
{
Value
v
=
visit_expr
(
e
);
items
.
push_back
(
v
);
listAppendInternalStolen
(
list
,
v
.
o
);
}
catch
(
ExcInfo
e
)
{
RELEASE_ASSERT
(
0
,
"check refcounting"
);
}
}
return
Value
(
list
,
jit
?
jit
->
emitCreateList
(
items
)
:
NULL
);
...
...
src/codegen/irgen/hooks.cpp
View file @
fc46bc42
...
...
@@ -331,7 +331,7 @@ void compileAndRunModule(AST_Module* m, BoxedModule* bm) {
static
BoxedString
*
builtins_str
=
getStaticString
(
"__builtins__"
);
if
(
!
bm
->
hasattr
(
builtins_str
))
bm
->
giveAttr
(
incref
(
builtins_str
),
PyModule_GetDict
(
builtins_module
)
);
bm
->
setattr
(
builtins_str
,
PyModule_GetDict
(
builtins_module
),
NULL
);
md
=
new
FunctionMetadata
(
0
,
false
,
false
,
std
::
move
(
si
));
}
...
...
src/runtime/classobj.cpp
View file @
fc46bc42
...
...
@@ -913,7 +913,7 @@ static int instance_compare(PyObject* v, PyObject* w) noexcept {
Box
*
instanceCompare
(
Box
*
_inst
,
Box
*
other
)
{
int
rtn
=
instance_compare
(
_inst
,
other
);
if
(
rtn
==
2
)
return
NotImplemented
;
return
incref
(
NotImplemented
)
;
if
(
rtn
==
-
2
)
throwCAPIException
();
return
boxInt
(
rtn
);
...
...
@@ -1212,7 +1212,7 @@ static Box* _instanceBinary(Box* _inst, Box* other, BoxedString* attr) {
Box
*
func
=
_instanceGetattribute
(
inst
,
attr
,
false
);
if
(
!
func
)
return
NotImplemented
;
return
incref
(
NotImplemented
)
;
return
runtimeCall
(
func
,
ArgPassSpec
(
1
),
other
,
NULL
,
NULL
,
NULL
,
NULL
);
}
...
...
src/runtime/complex.cpp
View file @
fc46bc42
...
...
@@ -156,7 +156,7 @@ extern "C" Box* complexAdd(BoxedComplex* lhs, Box* rhs) {
}
else
if
(
rhs
->
cls
==
complex_cls
)
{
return
complexAddComplex
(
lhs
,
static_cast
<
BoxedComplex
*>
(
rhs
));
}
else
{
return
NotImplemented
;
return
incref
(
NotImplemented
)
;
}
}
...
...
@@ -189,7 +189,7 @@ extern "C" Box* complexSub(BoxedComplex* lhs, Box* rhs) {
}
else
if
(
rhs
->
cls
==
complex_cls
)
{
return
complexSubComplex
(
lhs
,
static_cast
<
BoxedComplex
*>
(
rhs
));
}
else
{
return
NotImplemented
;
return
incref
(
NotImplemented
)
;
}
}
...
...
@@ -205,7 +205,7 @@ extern "C" Box* complexRSub(BoxedComplex* _lhs, Box* _rhs) {
}
else
if
(
_rhs
->
cls
==
complex_cls
)
{
lhs
=
static_cast
<
BoxedComplex
*>
(
_rhs
);
}
else
{
return
NotImplemented
;
return
incref
(
NotImplemented
)
;
}
return
complexSubComplex
(
lhs
,
_lhs
);
}
...
...
@@ -239,7 +239,7 @@ extern "C" Box* complexMul(BoxedComplex* lhs, Box* rhs) {
}
else
if
(
rhs
->
cls
==
complex_cls
)
{
return
complexMulComplex
(
lhs
,
static_cast
<
BoxedComplex
*>
(
rhs
));
}
else
{
return
NotImplemented
;
return
incref
(
NotImplemented
)
;
}
}
...
...
@@ -308,7 +308,7 @@ extern "C" Box* complexDiv(BoxedComplex* lhs, Box* rhs) {
}
else
if
(
rhs
->
cls
==
complex_cls
)
{
return
complexDivComplex
(
lhs
,
static_cast
<
BoxedComplex
*>
(
rhs
));
}
else
{
return
NotImplemented
;
return
incref
(
NotImplemented
)
;
}
}
...
...
@@ -324,7 +324,7 @@ extern "C" Box* complexRDiv(BoxedComplex* _lhs, Box* _rhs) {
}
else
if
(
_rhs
->
cls
==
complex_cls
)
{
lhs
=
static_cast
<
BoxedComplex
*>
(
_rhs
);
}
else
{
return
NotImplemented
;
return
incref
(
NotImplemented
)
;
}
return
complexDivComplex
(
lhs
,
_lhs
);
}
...
...
@@ -584,7 +584,7 @@ Box* complexCoerce(Box* lhs, Box* rhs) {
cval
.
real
=
PyFloat_AsDouble
(
rhs
);
rhs
=
PyComplex_FromCComplex
(
cval
);
}
else
if
(
!
PyComplex_Check
(
rhs
))
{
return
NotImplemented
;
return
incref
(
NotImplemented
)
;
}
return
BoxedTuple
::
create
({
lhs
,
rhs
});
}
...
...
@@ -830,7 +830,7 @@ static Box* to_complex(Box* self) noexcept {
}
else
if
(
self
->
cls
==
long_cls
)
{
r
=
new
BoxedComplex
(
PyLong_AsDouble
(
self
),
0.0
);
}
else
{
return
NotImplemented
;
return
incref
(
NotImplemented
)
;
}
return
r
;
}
...
...
@@ -1023,7 +1023,7 @@ extern "C" Box* complexMod(BoxedComplex* lhs, Box* _rhs) {
Box
*
res
=
to_complex
(
_rhs
);
if
(
res
==
NotImplemented
)
{
return
NotImplemented
;
return
incref
(
NotImplemented
)
;
}
BoxedComplex
*
rhs
=
(
BoxedComplex
*
)
res
;
...
...
@@ -1046,7 +1046,7 @@ extern "C" Box* complexFloordiv(BoxedComplex* lhs, Box* _rhs) {
Box
*
res
=
to_complex
(
_rhs
);
if
(
res
==
NotImplemented
)
{
return
NotImplemented
;
return
incref
(
NotImplemented
)
;
}
BoxedComplex
*
rhs
=
(
BoxedComplex
*
)
res
;
...
...
src/runtime/dict.cpp
View file @
fc46bc42
...
...
@@ -607,7 +607,7 @@ Box* dictEq(BoxedDict* self, Box* _rhs) {
_rhs
=
attrwrapperToDict
(
_rhs
);
if
(
!
PyDict_Check
(
_rhs
))
return
NotImplemented
;
return
incref
(
NotImplemented
)
;
BoxedDict
*
rhs
=
static_cast
<
BoxedDict
*>
(
_rhs
);
...
...
src/runtime/float.cpp
View file @
fc46bc42
...
...
@@ -127,7 +127,7 @@ extern "C" Box* floatAdd(BoxedFloat* lhs, Box* rhs) {
}
else
if
(
rhs
->
cls
==
long_cls
)
{
return
boxFloat
(
lhs
->
d
+
PyLong_AsDouble
(
rhs
));
}
else
{
return
NotImplemented
;
return
incref
(
NotImplemented
)
;
}
}
...
...
@@ -154,7 +154,7 @@ extern "C" Box* floatDiv(BoxedFloat* lhs, Box* rhs) {
}
else
if
(
rhs
->
cls
==
long_cls
)
{
return
boxFloat
(
lhs
->
d
/
PyLong_AsDouble
(
rhs
));
}
else
{
return
NotImplemented
;
return
incref
(
NotImplemented
)
;
}
}
...
...
@@ -167,7 +167,7 @@ extern "C" Box* floatTruediv(BoxedFloat* lhs, Box* rhs) {
}
else
if
(
rhs
->
cls
==
long_cls
)
{
return
boxFloat
(
lhs
->
d
/
PyLong_AsDouble
(
rhs
));
}
else
{
return
NotImplemented
;
return
incref
(
NotImplemented
)
;
}
}
...
...
@@ -194,7 +194,7 @@ extern "C" Box* floatRDiv(BoxedFloat* lhs, Box* rhs) {
}
else
if
(
rhs
->
cls
==
long_cls
)
{
return
boxFloat
(
PyLong_AsDouble
(
rhs
)
/
lhs
->
d
);
}
else
{
return
NotImplemented
;
return
incref
(
NotImplemented
)
;
}
}
...
...
@@ -219,7 +219,7 @@ extern "C" Box* floatFloorDiv(BoxedFloat* lhs, Box* rhs) {
}
else
if
(
rhs
->
cls
==
float_cls
)
{
return
floatFloorDivFloat
(
lhs
,
static_cast
<
BoxedFloat
*>
(
rhs
));
}
else
{
return
NotImplemented
;
return
incref
(
NotImplemented
)
;
}
}
...
...
@@ -546,7 +546,7 @@ extern "C" Box* floatMod(BoxedFloat* lhs, Box* rhs) {
}
else
if
(
rhs
->
cls
==
long_cls
)
{
return
boxFloat
(
mod_float_float
(
lhs
->
d
,
PyLong_AsDouble
(
rhs
)));
}
else
{
return
NotImplemented
;
return
incref
(
NotImplemented
)
;
}
}
...
...
@@ -571,7 +571,7 @@ extern "C" Box* floatRMod(BoxedFloat* lhs, Box* rhs) {
}
else
if
(
rhs
->
cls
==
long_cls
)
{
return
boxFloat
(
mod_float_float
(
PyLong_AsDouble
(
rhs
),
lhs
->
d
));
}
else
{
return
NotImplemented
;
return
incref
(
NotImplemented
)
;
}
}
...
...
@@ -628,7 +628,7 @@ extern "C" Box* floatMul(BoxedFloat* lhs, Box* rhs) {
}
else
if
(
rhs
->
cls
==
long_cls
)
{
return
boxFloat
(
lhs
->
d
*
PyLong_AsDouble
(
rhs
));
}
else
{
return
NotImplemented
;
return
incref
(
NotImplemented
)
;
}
}
...
...
@@ -653,7 +653,7 @@ extern "C" Box* floatSub(BoxedFloat* lhs, Box* rhs) {
}
else
if
(
rhs
->
cls
==
long_cls
)
{
return
boxFloat
(
lhs
->
d
-
PyLong_AsDouble
(
rhs
));
}
else
{
return
NotImplemented
;
return
incref
(
NotImplemented
)
;
}
}
...
...
@@ -678,7 +678,7 @@ extern "C" Box* floatRSub(BoxedFloat* lhs, Box* rhs) {
}
else
if
(
rhs
->
cls
==
long_cls
)
{
return
boxFloat
(
PyLong_AsDouble
(
rhs
)
-
lhs
->
d
);
}
else
{
return
NotImplemented
;
return
incref
(
NotImplemented
)
;
}
}
...
...
src/runtime/inline/list.cpp
View file @
fc46bc42
...
...
@@ -23,6 +23,7 @@
namespace
pyston
{
BoxedListIterator
::
BoxedListIterator
(
BoxedList
*
l
,
int
start
)
:
l
(
l
),
pos
(
start
)
{
Py_INCREF
(
l
);
}
Box
*
listIterIter
(
Box
*
s
)
{
...
...
@@ -45,6 +46,7 @@ Box* listiterHasnext(Box* s) {
bool
ans
=
(
self
->
pos
<
self
->
l
->
size
);
if
(
!
ans
)
{
Py_DECREF
(
self
->
l
);
self
->
l
=
NULL
;
}
return
boxBool
(
ans
);
...
...
@@ -60,6 +62,7 @@ i1 listiterHasnextUnboxed(Box* s) {
bool
ans
=
(
self
->
pos
<
self
->
l
->
size
);
if
(
!
ans
)
{
Py_DECREF
(
self
->
l
);
self
->
l
=
NULL
;
}
return
ans
;
...
...
@@ -73,6 +76,7 @@ Box* listiter_next(Box* s) noexcept {
return
NULL
;
if
(
!
(
self
->
pos
>=
0
&&
self
->
pos
<
self
->
l
->
size
))
{
Py_DECREF
(
self
->
l
);
self
->
l
=
NULL
;
return
NULL
;
}
...
...
@@ -163,6 +167,10 @@ extern "C" void listAppendArrayInternal(Box* s, Box** v, int nelts) {
assert
(
self
->
size
<=
self
->
capacity
);
self
->
ensure
(
nelts
);
for
(
int
i
=
0
;
i
<
nelts
;
i
++
)
{
Py_INCREF
(
v
[
i
]);
}
assert
(
self
->
size
<=
self
->
capacity
);
memcpy
(
&
self
->
elts
->
elts
[
self
->
size
],
&
v
[
0
],
nelts
*
sizeof
(
Box
*
));
...
...
src/runtime/int.cpp
View file @
fc46bc42
...
...
@@ -515,7 +515,7 @@ extern "C" Box* intAdd(BoxedInt* lhs, Box* rhs) {
BoxedFloat
*
rhs_float
=
static_cast
<
BoxedFloat
*>
(
rhs
);
return
boxFloat
(
lhs
->
n
+
rhs_float
->
d
);
}
else
{
return
NotImplemented
;
return
incref
(
NotImplemented
)
;
}
}
...
...
@@ -530,7 +530,7 @@ extern "C" Box* intAnd(BoxedInt* lhs, Box* rhs) {
raiseExcHelper
(
TypeError
,
"descriptor '__and__' requires a 'int' object but received a '%s'"
,
getTypeName
(
lhs
));
if
(
!
PyInt_Check
(
rhs
))
{
return
NotImplemented
;
return
incref
(
NotImplemented
)
;
}
BoxedInt
*
rhs_int
=
static_cast
<
BoxedInt
*>
(
rhs
);
return
boxInt
(
lhs
->
n
&
rhs_int
->
n
);
...
...
@@ -547,7 +547,7 @@ extern "C" Box* intOr(BoxedInt* lhs, Box* rhs) {
raiseExcHelper
(
TypeError
,
"descriptor '__or__' requires a 'int' object but received a '%s'"
,
getTypeName
(
lhs
));
if
(
!
PyInt_Check
(
rhs
))
{
return
NotImplemented
;
return
incref
(
NotImplemented
)
;
}
BoxedInt
*
rhs_int
=
static_cast
<
BoxedInt
*>
(
rhs
);
return
boxInt
(
lhs
->
n
|
rhs_int
->
n
);
...
...
@@ -564,7 +564,7 @@ extern "C" Box* intXor(BoxedInt* lhs, Box* rhs) {
raiseExcHelper
(
TypeError
,
"descriptor '__xor__' requires a 'int' object but received a '%s'"
,
getTypeName
(
lhs
));
if
(
!
PyInt_Check
(
rhs
))
{
return
NotImplemented
;
return
incref
(
NotImplemented
)
;
}
BoxedInt
*
rhs_int
=
static_cast
<
BoxedInt
*>
(
rhs
);
return
boxInt
(
lhs
->
n
^
rhs_int
->
n
);
...
...
@@ -595,7 +595,7 @@ extern "C" Box* intDiv(BoxedInt* lhs, Box* rhs) {
}
else
if
(
rhs
->
cls
==
float_cls
)
{
return
intDivFloat
(
lhs
,
static_cast
<
BoxedFloat
*>
(
rhs
));
}
else
{
return
NotImplemented
;
return
incref
(
NotImplemented
)
;
}
}
...
...
@@ -625,7 +625,7 @@ extern "C" Box* intFloordiv(BoxedInt* lhs, Box* rhs) {
}
else
if
(
rhs
->
cls
==
float_cls
)
{
return
intFloordivFloat
(
lhs
,
static_cast
<
BoxedFloat
*>
(
rhs
));
}
else
{
return
NotImplemented
;
return
incref
(
NotImplemented
)
;
}
}
...
...
@@ -659,7 +659,7 @@ extern "C" Box* intTruediv(BoxedInt* lhs, Box* rhs) {
}
else
if
(
rhs
->
cls
==
float_cls
)
{
return
intTruedivFloat
(
lhs
,
static_cast
<
BoxedFloat
*>
(
rhs
));
}
else
{
return
NotImplemented
;
return
incref
(
NotImplemented
)
;
}
}
...
...
@@ -688,7 +688,7 @@ extern "C" Box* intLShift(BoxedInt* lhs, Box* rhs) {
return
longLshift
(
boxLong
(
lhs
->
n
),
rhs
);
if
(
!
PyInt_Check
(
rhs
))
{
return
NotImplemented
;
return
incref
(
NotImplemented
)
;
}
BoxedInt
*
rhs_int
=
static_cast
<
BoxedInt
*>
(
rhs
);
return
intLShiftInt
(
lhs
,
rhs_int
);
...
...
@@ -705,7 +705,7 @@ extern "C" Box* intMod(BoxedInt* lhs, Box* rhs) {
raiseExcHelper
(
TypeError
,
"descriptor '__mod__' requires a 'int' object but received a '%s'"
,
getTypeName
(
lhs
));
if
(
!
PyInt_Check
(
rhs
))
{
return
NotImplemented
;
return
incref
(
NotImplemented
)
;
}
BoxedInt
*
rhs_int
=
static_cast
<
BoxedInt
*>
(
rhs
);
return
boxInt
(
mod_i64_i64
(
lhs
->
n
,
rhs_int
->
n
));
...
...
@@ -719,13 +719,13 @@ extern "C" Box* intDivmod(BoxedInt* lhs, Box* rhs) {
Box
*
divResult
=
intDiv
(
lhs
,
rhs
);
if
(
divResult
==
NotImplemented
)
{
return
NotImplemented
;
return
incref
(
NotImplemented
)
;
}
Box
*
modResult
=
intMod
(
lhs
,
rhs
);
if
(
modResult
==
NotImplemented
)
{
return
NotImplemented
;
return
incref
(
NotImplemented
)
;
}
Box
*
arg
[
2
]
=
{
divResult
,
modResult
};
...
...
@@ -756,7 +756,7 @@ extern "C" Box* intMul(BoxedInt* lhs, Box* rhs) {
BoxedFloat
*
rhs_float
=
static_cast
<
BoxedFloat
*>
(
rhs
);
return
intMulFloat
(
lhs
,
rhs_float
);
}
else
{
return
NotImplemented
;
return
incref
(
NotImplemented
)
;
}
}
...
...
@@ -796,7 +796,7 @@ extern "C" Box* intPow(BoxedInt* lhs, Box* rhs, Box* mod) {
else
if
(
PyFloat_Check
(
rhs
))
return
intPowFloat
(
lhs
,
static_cast
<
BoxedFloat
*>
(
rhs
),
mod
);
else
if
(
!
PyInt_Check
(
rhs
))
return
NotImplemented
;
return
incref
(
NotImplemented
)
;
BoxedInt
*
rhs_int
=
static_cast
<
BoxedInt
*>
(
rhs
);
BoxedInt
*
mod_int
=
static_cast
<
BoxedInt
*>
(
mod
);
...
...
@@ -806,7 +806,7 @@ extern "C" Box* intPow(BoxedInt* lhs, Box* rhs, Box* mod) {
raiseExcHelper
(
TypeError
,
"pow() 2nd argument "
"cannot be negative when 3rd argument specified"
);
if
(
!
PyInt_Check
(
mod
))
{
return
NotImplemented
;
return
incref
(
NotImplemented
)
;
}
else
if
(
mod_int
->
n
==
0
)
{
raiseExcHelper
(
ValueError
,
"pow() 3rd argument cannot be 0"
);
}
...
...
@@ -837,7 +837,7 @@ extern "C" Box* intRShift(BoxedInt* lhs, Box* rhs) {
return
longRshift
(
boxLong
(
lhs
->
n
),
rhs
);
if
(
!
PyInt_Check
(
rhs
))
{
return
NotImplemented
;
return
incref
(
NotImplemented
)
;
}
BoxedInt
*
rhs_int
=
static_cast
<
BoxedInt
*>
(
rhs
);
return
intRShiftInt
(
lhs
,
rhs_int
);
...
...
@@ -866,7 +866,7 @@ extern "C" Box* intSub(BoxedInt* lhs, Box* rhs) {
BoxedFloat
*
rhs_float
=
static_cast
<
BoxedFloat
*>
(
rhs
);
return
intSubFloat
(
lhs
,
rhs_float
);
}
else
{
return
NotImplemented
;
return
incref
(
NotImplemented
)
;
}
}
...
...
src/runtime/list.cpp
View file @
fc46bc42
...
...
@@ -198,6 +198,9 @@ Box* _listSlice(BoxedList* self, i64 start, i64 stop, i64 step, i64 length) {
if
(
length
>
0
)
{
rtn
->
ensure
(
length
);
copySlice
(
&
rtn
->
elts
->
elts
[
0
],
&
self
->
elts
->
elts
[
0
],
start
,
step
,
length
);
for
(
int
i
=
0
;
i
<
length
;
i
++
)
{
Py_INCREF
(
rtn
->
elts
->
elts
[
i
]);
}
rtn
->
size
+=
length
;
}
return
rtn
;
...
...
@@ -235,7 +238,7 @@ static Box* list_slice(Box* o, Py_ssize_t ilow, Py_ssize_t ihigh) noexcept {
return
(
PyObject
*
)
np
;
}
static
inline
B
ox
*
listGetitemUnboxed
(
BoxedList
*
self
,
int64_t
n
)
{
static
inline
B
ORROWED
(
Box
*
)
listGetitemUnboxed
(
BoxedList
*
self
,
int64_t
n
)
{
assert
(
PyList_Check
(
self
));
if
(
n
<
0
)
n
=
self
->
size
+
n
;
...
...
@@ -249,7 +252,7 @@ static inline Box* listGetitemUnboxed(BoxedList* self, int64_t n) {
extern
"C"
Box
*
listGetitemInt
(
BoxedList
*
self
,
BoxedInt
*
slice
)
{
assert
(
PyInt_Check
(
slice
));
return
listGetitemUnboxed
(
self
,
slice
->
n
);
return
incref
(
listGetitemUnboxed
(
self
,
slice
->
n
)
);
}
extern
"C"
PyObject
*
PyList_GetItem
(
PyObject
*
op
,
Py_ssize_t
i
)
noexcept
{
...
...
@@ -293,7 +296,7 @@ extern "C" Box* listGetslice(BoxedList* self, Box* boxedStart, Box* boxedStop) {
static
PyObject
*
list_item
(
PyListObject
*
a
,
Py_ssize_t
i
)
noexcept
{
try
{
BoxedList
*
self
=
(
BoxedList
*
)
a
;
return
listGetitemUnboxed
(
self
,
i
);
return
incref
(
listGetitemUnboxed
(
self
,
i
)
);
}
catch
(
ExcInfo
e
)
{
setCAPIException
(
e
);
return
NULL
;
...
...
@@ -315,7 +318,7 @@ template <ExceptionStyle S> Box* listGetitem(BoxedList* self, Box* slice) {
Py_ssize_t
i
=
PyNumber_AsSsize_t
(
slice
,
PyExc_IndexError
);
if
(
i
==
-
1
&&
PyErr_Occurred
())
throwCAPIException
();
return
listGetitemUnboxed
(
self
,
i
);
return
incref
(
listGetitemUnboxed
(
self
,
i
)
);
}
else
if
(
slice
->
cls
==
slice_cls
)
{
return
listGetitemSlice
<
CXX
>
(
self
,
static_cast
<
BoxedSlice
*>
(
slice
));
}
else
{
...
...
@@ -331,7 +334,10 @@ static void _listSetitem(BoxedList* self, int64_t n, Box* v) {
raiseExcHelper
(
IndexError
,
"list index out of range"
);
}
Py_INCREF
(
v
);
Box
*
prev
=
self
->
elts
->
elts
[
n
];
self
->
elts
->
elts
[
n
]
=
v
;
Py_DECREF
(
prev
);
}
extern
"C"
Box
*
listSetitemUnboxed
(
BoxedList
*
self
,
int64_t
n
,
Box
*
v
)
{
...
...
@@ -524,10 +530,11 @@ static inline void listSetitemSliceInt64(BoxedList* self, i64 start, i64 stop, i
v_size
=
0
;
v_elts
=
NULL
;
}
else
{
if
(
self
==
v
)
// handle self assignment by creating a copy
v
=
_listSlice
(
self
,
0
,
self
->
size
,
1
,
self
->
size
);
v_as_seq
=
PySequence_Fast
(
v
,
"can only assign an iterable"
);
if
(
self
==
v
)
{
// handle self assignment by creating a copy
v_as_seq
=
_listSlice
(
self
,
0
,
self
->
size
,
1
,
self
->
size
);
assert
(
v_as_seq
->
cls
==
list_cls
);
}
else
v_as_seq
=
PySequence_Fast
(
v
,
"can only assign an iterable"
);
if
(
v_as_seq
==
NULL
)
throwCAPIException
();
...
...
@@ -632,8 +639,10 @@ extern "C" Box* listDelitemInt(BoxedList* self, BoxedInt* slice) {
if
(
n
<
0
||
n
>=
self
->
size
)
{
raiseExcHelper
(
IndexError
,
"list index out of range"
);
}
Box
*
e
=
self
->
elts
->
elts
[
n
];
memmove
(
self
->
elts
->
elts
+
n
,
self
->
elts
->
elts
+
n
+
1
,
(
self
->
size
-
n
-
1
)
*
sizeof
(
Box
*
));
self
->
size
--
;
Py_DECREF
(
e
);
Py_RETURN_NONE
;
}
...
...
@@ -708,8 +717,6 @@ extern "C" int PyList_Insert(PyObject* op, Py_ssize_t where, PyObject* newitem)
}
Box
*
listMul
(
BoxedList
*
self
,
Box
*
rhs
)
{
static
BoxedString
*
index_str
=
getStaticString
(
"__index__"
);
Py_ssize_t
n
=
PyNumber_AsSsize_t
(
rhs
,
PyExc_IndexError
);
if
(
n
==
-
1
&&
PyErr_Occurred
())
throwCAPIException
();
...
...
@@ -732,8 +739,6 @@ Box* listMul(BoxedList* self, Box* rhs) {
}
Box
*
listImul
(
BoxedList
*
self
,
Box
*
rhs
)
{
static
BoxedString
*
index_str
=
getStaticString
(
"__index__"
);
Py_ssize_t
n
=
PyNumber_AsSsize_t
(
rhs
,
PyExc_IndexError
);
if
(
n
==
-
1
&&
PyErr_Occurred
())
throwCAPIException
();
...
...
@@ -744,7 +749,7 @@ Box* listImul(BoxedList* self, Box* rhs) {
if
(
n
==
0
)
{
listSetitemSliceInt64
(
self
,
0
,
s
,
1
,
NULL
);
}
else
if
(
n
==
1
)
{
return
self
;
return
incref
(
self
)
;
}
else
if
(
s
==
1
)
{
for
(
long
i
=
1
;
i
<
n
;
i
++
)
{
listAppendInternal
(
self
,
self
->
elts
->
elts
[
0
]);
...
...
@@ -755,7 +760,7 @@ Box* listImul(BoxedList* self, Box* rhs) {
}
}
return
self
;
return
incref
(
self
)
;
}
Box
*
listIAdd
(
BoxedList
*
self
,
Box
*
_rhs
)
{
...
...
@@ -817,7 +822,7 @@ Box* listIAdd(BoxedList* self, Box* _rhs) {
Box
*
listAdd
(
BoxedList
*
self
,
Box
*
_rhs
)
{
if
(
!
PyList_Check
(
_rhs
))
{
return
NotImplemented
;
return
incref
(
NotImplemented
)
;
raiseExcHelper
(
TypeError
,
"can only concatenate list (not
\"
%s
\"
) to list"
,
getTypeName
(
_rhs
));
}
...
...
@@ -832,6 +837,9 @@ Box* listAdd(BoxedList* self, Box* _rhs) {
memcpy
(
rtn
->
elts
->
elts
,
self
->
elts
->
elts
,
sizeof
(
self
->
elts
->
elts
[
0
])
*
s1
);
memcpy
(
rtn
->
elts
->
elts
+
s1
,
rhs
->
elts
->
elts
,
sizeof
(
rhs
->
elts
->
elts
[
0
])
*
s2
);
rtn
->
size
=
s1
+
s2
;
for
(
int
i
=
0
;
i
<
s1
+
s2
;
i
++
)
{
Py_INCREF
(
rtn
->
elts
->
elts
[
i
]);
}
return
rtn
;
}
...
...
@@ -853,7 +861,7 @@ extern "C" int PyList_Reverse(PyObject* v) noexcept {
}
try
{
listReverse
(
static_cast
<
BoxedList
*>
(
v
));
autoDecref
(
listReverse
(
static_cast
<
BoxedList
*>
(
v
)
));
}
catch
(
ExcInfo
e
)
{
setCAPIException
(
e
);
return
-
1
;
...
...
@@ -1086,7 +1094,7 @@ Box* listIndex(BoxedList* self, Box* elt, Box* _start, Box** args) {
}
BoxedString
*
tostr
=
static_cast
<
BoxedString
*>
(
repr
(
elt
));
raiseExcHelper
(
ValueError
,
"%s is not in list"
,
tostr
->
data
());
raiseExcHelper
(
ValueError
,
"%s is not in list"
,
autoDecref
(
tostr
)
->
data
());
}
Box
*
listRemove
(
BoxedList
*
self
,
Box
*
elt
)
{
...
...
@@ -1102,6 +1110,7 @@ Box* listRemove(BoxedList* self, Box* elt) {
if
(
r
)
{
memmove
(
self
->
elts
->
elts
+
i
,
self
->
elts
->
elts
+
i
+
1
,
(
self
->
size
-
i
-
1
)
*
sizeof
(
Box
*
));
self
->
size
--
;
Py_DECREF
(
e
);
Py_RETURN_NONE
;
}
}
...
...
@@ -1195,7 +1204,7 @@ Box* _listCmp(BoxedList* lhs, BoxedList* rhs, AST_TYPE::AST_TYPE op_type) {
Box
*
listEq
(
BoxedList
*
self
,
Box
*
rhs
)
{
if
(
!
PyList_Check
(
rhs
))
{
return
NotImplemented
;
return
incref
(
NotImplemented
)
;
}
return
_listCmp
(
self
,
static_cast
<
BoxedList
*>
(
rhs
),
AST_TYPE
::
Eq
);
...
...
@@ -1203,7 +1212,7 @@ Box* listEq(BoxedList* self, Box* rhs) {
Box
*
listNe
(
BoxedList
*
self
,
Box
*
rhs
)
{
if
(
!
PyList_Check
(
rhs
))
{
return
NotImplemented
;
return
incref
(
NotImplemented
)
;
}
return
_listCmp
(
self
,
static_cast
<
BoxedList
*>
(
rhs
),
AST_TYPE
::
NotEq
);
...
...
@@ -1211,7 +1220,7 @@ Box* listNe(BoxedList* self, Box* rhs) {
Box
*
listLt
(
BoxedList
*
self
,
Box
*
rhs
)
{
if
(
!
PyList_Check
(
rhs
))
{
return
NotImplemented
;
return
incref
(
NotImplemented
)
;
}
return
_listCmp
(
self
,
static_cast
<
BoxedList
*>
(
rhs
),
AST_TYPE
::
Lt
);
...
...
@@ -1219,7 +1228,7 @@ Box* listLt(BoxedList* self, Box* rhs) {
Box
*
listLe
(
BoxedList
*
self
,
Box
*
rhs
)
{
if
(
!
PyList_Check
(
rhs
))
{
return
NotImplemented
;
return
incref
(
NotImplemented
)
;
}
return
_listCmp
(
self
,
static_cast
<
BoxedList
*>
(
rhs
),
AST_TYPE
::
LtE
);
...
...
@@ -1227,7 +1236,7 @@ Box* listLe(BoxedList* self, Box* rhs) {
Box
*
listGt
(
BoxedList
*
self
,
Box
*
rhs
)
{
if
(
!
PyList_Check
(
rhs
))
{
return
NotImplemented
;
return
incref
(
NotImplemented
)
;
}
return
_listCmp
(
self
,
static_cast
<
BoxedList
*>
(
rhs
),
AST_TYPE
::
Gt
);
...
...
@@ -1235,7 +1244,7 @@ Box* listGt(BoxedList* self, Box* rhs) {
Box
*
listGe
(
BoxedList
*
self
,
Box
*
rhs
)
{
if
(
!
PyList_Check
(
rhs
))
{
return
NotImplemented
;
return
incref
(
NotImplemented
)
;
}
return
_listCmp
(
self
,
static_cast
<
BoxedList
*>
(
rhs
),
AST_TYPE
::
GtE
);
...
...
src/runtime/list.h
View file @
fc46bc42
...
...
@@ -32,7 +32,7 @@ public:
static
void
dealloc
(
BoxedListIterator
*
o
)
noexcept
{
PyObject_GC_UnTrack
(
o
);
Py_DECREF
(
o
->
l
);
Py_
X
DECREF
(
o
->
l
);
o
->
cls
->
tp_free
(
o
);
}
...
...
src/runtime/long.cpp
View file @
fc46bc42
...
...
@@ -861,7 +861,7 @@ Box* longAdd(BoxedLong* v1, Box* _v2) {
mpz_sub_ui
(
r
->
n
,
v1
->
n
,
-
v2
->
n
);
return
r
;
}
else
{
return
NotImplemented
;
return
incref
(
NotImplemented
)
;
}
}
...
...
@@ -889,7 +889,7 @@ extern "C" Box* longAnd(BoxedLong* v1, Box* _v2) {
mpz_and
(
r
->
n
,
v1
->
n
,
v2_long
);
return
r
;
}
return
NotImplemented
;
return
incref
(
NotImplemented
)
;
}
extern
"C"
Box
*
longOr
(
BoxedLong
*
v1
,
Box
*
_v2
)
{
...
...
@@ -915,7 +915,7 @@ extern "C" Box* longOr(BoxedLong* v1, Box* _v2) {
mpz_ior
(
r
->
n
,
v1
->
n
,
v2_long
);
return
r
;
}
return
NotImplemented
;
return
incref
(
NotImplemented
)
;
}
extern
"C"
Box
*
longXor
(
BoxedLong
*
v1
,
Box
*
_v2
)
{
...
...
@@ -941,7 +941,7 @@ extern "C" Box* longXor(BoxedLong* v1, Box* _v2) {
mpz_xor
(
r
->
n
,
v1
->
n
,
v2_long
);
return
r
;
}
return
NotImplemented
;
return
incref
(
NotImplemented
)
;
}
static
PyObject
*
long_richcompare
(
Box
*
_v1
,
Box
*
_v2
,
int
op
)
noexcept
{
...
...
@@ -957,7 +957,7 @@ static PyObject* long_richcompare(Box* _v1, Box* _v2, int op) noexcept {
return
convert_3way_to_object
(
op
,
mpz_cmp_si
(
v1
->
n
,
v2
->
n
));
}
else
{
return
NotImplemented
;
return
incref
(
NotImplemented
)
;
}
}
...
...
@@ -987,7 +987,7 @@ Box* longLshift(BoxedLong* v1, Box* _v2) {
mpz_mul_2exp
(
r
->
n
,
v1
->
n
,
v2
->
n
);
return
r
;
}
else
{
return
NotImplemented
;
return
incref
(
NotImplemented
)
;
}
}
...
...
@@ -1017,7 +1017,7 @@ Box* longRshift(BoxedLong* v1, Box* _v2) {
mpz_div_2exp
(
r
->
n
,
v1
->
n
,
v2
->
n
);
return
r
;
}
else
{
return
NotImplemented
;
return
incref
(
NotImplemented
)
;
}
}
...
...
@@ -1043,7 +1043,7 @@ Box* longSub(BoxedLong* v1, Box* _v2) {
mpz_add_ui
(
r
->
n
,
v1
->
n
,
-
v2
->
n
);
return
r
;
}
else
{
return
NotImplemented
;
return
incref
(
NotImplemented
)
;
}
}
...
...
@@ -1074,7 +1074,7 @@ Box* longMul(BoxedLong* v1, Box* _v2) {
mpz_mul_si
(
r
->
n
,
v1
->
n
,
v2
->
n
);
return
r
;
}
else
{
return
NotImplemented
;
return
incref
(
NotImplemented
)
;
}
}
...
...
@@ -1103,7 +1103,7 @@ Box* longDiv(BoxedLong* v1, Box* _v2) {
mpz_fdiv_q
(
r
->
n
,
v1
->
n
,
r
->
n
);
return
r
;
}
else
{
return
NotImplemented
;
return
incref
(
NotImplemented
)
;
}
}
...
...
@@ -1139,7 +1139,7 @@ Box* longMod(BoxedLong* v1, Box* _v2) {
mpz_mmod
(
r
->
n
,
v1
->
n
,
r
->
n
);
return
r
;
}
else
{
return
NotImplemented
;
return
incref
(
NotImplemented
)
;
}
}
...
...
@@ -1155,7 +1155,7 @@ Box* longRMod(BoxedLong* v1, Box* _v2) {
}
else
if
(
PyInt_Check
(
lhs
))
{
return
longMod
(
boxLong
(((
BoxedInt
*
)
lhs
)
->
n
),
rhs
);
}
else
{
return
NotImplemented
;
return
incref
(
NotImplemented
)
;
}
}
...
...
@@ -1189,7 +1189,7 @@ extern "C" Box* longDivmod(BoxedLong* lhs, Box* _rhs) {
mpz_fdiv_qr
(
q
->
n
,
r
->
n
,
lhs
->
n
,
r
->
n
);
return
BoxedTuple
::
create
({
q
,
r
});
}
else
{
return
NotImplemented
;
return
incref
(
NotImplemented
)
;
}
}
...
...
@@ -1216,7 +1216,7 @@ Box* longRdiv(BoxedLong* v1, Box* _v2) {
mpz_fdiv_q
(
r
->
n
,
r
->
n
,
v1
->
n
);
return
r
;
}
else
{
return
NotImplemented
;
return
incref
(
NotImplemented
)
;
}
}
...
...
@@ -1237,10 +1237,10 @@ Box* longTrueDiv(BoxedLong* v1, Box* _v2) {
int
overflow
=
0
;
long
lhs
=
PyLong_AsLongAndOverflow
(
v1
,
&
overflow
);
if
(
overflow
)
return
NotImplemented
;
return
incref
(
NotImplemented
)
;
long
rhs
=
PyLong_AsLongAndOverflow
(
_v2
,
&
overflow
);
if
(
overflow
)
return
NotImplemented
;
return
incref
(
NotImplemented
)
;
if
(
rhs
==
0
)
raiseExcHelper
(
ZeroDivisionError
,
"division by zero"
);
...
...
@@ -1256,10 +1256,10 @@ Box* longRTrueDiv(BoxedLong* v1, Box* _v2) {
int
overflow
=
0
;
long
lhs
=
PyLong_AsLongAndOverflow
(
_v2
,
&
overflow
);
if
(
overflow
)
return
NotImplemented
;
return
incref
(
NotImplemented
)
;
long
rhs
=
PyLong_AsLongAndOverflow
(
v1
,
&
overflow
);
if
(
overflow
)
return
NotImplemented
;
return
incref
(
NotImplemented
)
;
if
(
rhs
==
0
)
raiseExcHelper
(
ZeroDivisionError
,
"division by zero"
);
...
...
@@ -1295,7 +1295,7 @@ Box* longPow(BoxedLong* lhs, Box* rhs, Box* mod) {
}
else
if
(
PyInt_Check
(
mod
))
{
mod_long
=
boxLong
(
static_cast
<
BoxedInt
*>
(
mod
)
->
n
);
}
else
{
return
NotImplemented
;
return
incref
(
NotImplemented
)
;
}
}
...
...
@@ -1305,7 +1305,7 @@ Box* longPow(BoxedLong* lhs, Box* rhs, Box* mod) {
}
else
if
(
PyInt_Check
(
rhs
))
{
rhs_long
=
boxLong
(
static_cast
<
BoxedInt
*>
(
rhs
)
->
n
);
}
else
{
return
NotImplemented
;
return
incref
(
NotImplemented
)
;
}
if
(
mod
!=
None
)
{
...
...
src/runtime/objmodel.cpp
View file @
fc46bc42
...
...
@@ -3460,6 +3460,7 @@ Box* callattrInternal(Box* obj, BoxedString* attr, LookupScope scope, CallattrRe
arg_array
->
setAttr
(
8
,
rewrite_args
->
rewriter
->
loadConst
(
0
));
auto
r_rtn
=
rewrite_args
->
rewriter
->
call
(
true
,
(
void
*
)
Helper
::
call
,
arg_vec
)
->
setType
(
RefType
::
OWNED
);
rewrite_args
->
obj
->
refConsumed
();
rewrite_args
->
setReturn
(
r_rtn
,
S
==
CXX
?
ReturnConvention
::
HAS_RETURN
:
ReturnConvention
::
CAPI_RETURN
);
void
*
_args
[
2
]
=
{
args
,
const_cast
<
std
::
vector
<
BoxedString
*>*>
(
keyword_names
)
};
...
...
@@ -5948,6 +5949,7 @@ extern "C" void setitem(Box* target, Box* slice, Box* value) {
if
(
rtn
==
NULL
)
{
raiseExcHelper
(
TypeError
,
"'%s' object does not support item assignment"
,
getTypeName
(
target
));
}
Py_DECREF
(
rtn
);
if
(
rewriter
.
get
())
rewriter
->
commit
();
...
...
@@ -5984,6 +5986,8 @@ extern "C" void delitem(Box* target, Box* slice) {
raiseExcHelper
(
TypeError
,
"'%s' object does not support item deletion"
,
getTypeName
(
target
));
}
Py_DECREF
(
rtn
);
if
(
rewriter
.
get
())
rewriter
->
commit
();
}
...
...
src/runtime/set.cpp
View file @
fc46bc42
...
...
@@ -274,7 +274,7 @@ static Box* setIntersectionUpdate2(BoxedSet* self, Box* other) {
Box
*
setIOr
(
BoxedSet
*
lhs
,
BoxedSet
*
rhs
)
{
RELEASE_ASSERT
(
PyAnySet_Check
(
lhs
),
""
);
if
(
!
PyAnySet_Check
(
rhs
))
return
NotImplemented
;
return
incref
(
NotImplemented
)
;
// TODO just [write and] call setUnionUpdate2
for
(
auto
&&
elt
:
rhs
->
s
)
{
...
...
@@ -286,7 +286,7 @@ Box* setIOr(BoxedSet* lhs, BoxedSet* rhs) {
Box
*
setOr
(
BoxedSet
*
lhs
,
BoxedSet
*
rhs
)
{
RELEASE_ASSERT
(
PyAnySet_Check
(
lhs
),
""
);
if
(
!
PyAnySet_Check
(
rhs
))
return
NotImplemented
;
return
incref
(
NotImplemented
)
;
BoxedSet
*
rtn
=
makeNewSet
(
lhs
->
cls
,
lhs
);
return
setIOr
(
rtn
,
rhs
);
...
...
@@ -295,7 +295,7 @@ Box* setOr(BoxedSet* lhs, BoxedSet* rhs) {
Box
*
setIAnd
(
BoxedSet
*
lhs
,
BoxedSet
*
rhs
)
{
RELEASE_ASSERT
(
PyAnySet_Check
(
lhs
),
""
);
if
(
!
PyAnySet_Check
(
rhs
))
return
NotImplemented
;
return
incref
(
NotImplemented
)
;
setIntersectionUpdate2
(
lhs
,
rhs
);
return
lhs
;
...
...
@@ -304,7 +304,7 @@ Box* setIAnd(BoxedSet* lhs, BoxedSet* rhs) {
Box
*
setAnd
(
BoxedSet
*
lhs
,
BoxedSet
*
rhs
)
{
RELEASE_ASSERT
(
PyAnySet_Check
(
lhs
),
""
);
if
(
!
PyAnySet_Check
(
rhs
))
return
NotImplemented
;
return
incref
(
NotImplemented
)
;
return
setIntersection2
(
lhs
,
rhs
);
}
...
...
@@ -312,7 +312,7 @@ Box* setAnd(BoxedSet* lhs, BoxedSet* rhs) {
Box
*
setISub
(
BoxedSet
*
lhs
,
BoxedSet
*
rhs
)
{
RELEASE_ASSERT
(
PyAnySet_Check
(
lhs
),
""
);
if
(
!
PyAnySet_Check
(
rhs
))
return
NotImplemented
;
return
incref
(
NotImplemented
)
;
// TODO: write and call setDifferenceUpdate2
for
(
auto
&&
elt
:
rhs
->
s
)
{
...
...
@@ -324,7 +324,7 @@ Box* setISub(BoxedSet* lhs, BoxedSet* rhs) {
Box
*
setSub
(
BoxedSet
*
lhs
,
BoxedSet
*
rhs
)
{
RELEASE_ASSERT
(
PyAnySet_Check
(
lhs
),
""
);
if
(
!
PyAnySet_Check
(
rhs
))
return
NotImplemented
;
return
incref
(
NotImplemented
)
;
BoxedSet
*
rtn
=
makeNewSet
(
lhs
->
cls
,
lhs
);
return
setISub
(
rtn
,
rhs
);
...
...
@@ -333,7 +333,7 @@ Box* setSub(BoxedSet* lhs, BoxedSet* rhs) {
Box
*
setIXor
(
BoxedSet
*
lhs
,
BoxedSet
*
rhs
)
{
RELEASE_ASSERT
(
PyAnySet_Check
(
lhs
),
""
);
if
(
!
PyAnySet_Check
(
rhs
))
return
NotImplemented
;
return
incref
(
NotImplemented
)
;
_setSymmetricDifferenceUpdate
(
lhs
,
rhs
);
...
...
@@ -343,7 +343,7 @@ Box* setIXor(BoxedSet* lhs, BoxedSet* rhs) {
Box
*
setXor
(
BoxedSet
*
lhs
,
BoxedSet
*
rhs
)
{
RELEASE_ASSERT
(
PyAnySet_Check
(
lhs
),
""
);
if
(
!
PyAnySet_Check
(
rhs
))
return
NotImplemented
;
return
incref
(
NotImplemented
)
;
BoxedSet
*
rtn
=
makeNewSet
(
lhs
->
cls
,
lhs
);
return
setIXor
(
rtn
,
rhs
);
...
...
src/runtime/str.cpp
View file @
fc46bc42
...
...
@@ -349,8 +349,8 @@ extern "C" Box* strAdd(BoxedString* lhs, Box* _rhs) {
}
else
{
// This is a compatibility break with CPython, which has their sq_concat method
// directly throw a TypeError. Since we're not implementing this as a sq_concat,
//
return
NotImplemented for now.
return
NotImplemented
;
//
Give
NotImplemented for now.
return
incref
(
NotImplemented
)
;
}
}
...
...
@@ -1196,7 +1196,7 @@ Box* str_richcompare(Box* lhs, Box* rhs, int op) {
// statement, rather than out here. It's functionally equivalent but the
// generated assembly is somehow quite better:
// if (unlikely(!PyString_Check(rhs)))
// return
NotImplemented
;
// return
incref(NotImplemented)
;
BoxedString
*
slhs
=
static_cast
<
BoxedString
*>
(
lhs
);
BoxedString
*
srhs
=
static_cast
<
BoxedString
*>
(
rhs
);
...
...
@@ -1204,27 +1204,27 @@ Box* str_richcompare(Box* lhs, Box* rhs, int op) {
switch
(
op
)
{
case
Py_EQ
:
if
(
unlikely
(
!
PyString_Check
(
rhs
)))
return
NotImplemented
;
return
incref
(
NotImplemented
)
;
return
boxBool
(
slhs
->
s
()
==
srhs
->
s
());
case
Py_NE
:
if
(
unlikely
(
!
PyString_Check
(
rhs
)))
return
NotImplemented
;
return
incref
(
NotImplemented
)
;
return
boxBool
(
slhs
->
s
()
!=
srhs
->
s
());
case
Py_LT
:
if
(
unlikely
(
!
PyString_Check
(
rhs
)))
return
NotImplemented
;
return
incref
(
NotImplemented
)
;
return
boxBool
(
slhs
->
s
()
<
srhs
->
s
());
case
Py_LE
:
if
(
unlikely
(
!
PyString_Check
(
rhs
)))
return
NotImplemented
;
return
incref
(
NotImplemented
)
;
return
boxBool
(
slhs
->
s
()
<=
srhs
->
s
());
case
Py_GT
:
if
(
unlikely
(
!
PyString_Check
(
rhs
)))
return
NotImplemented
;
return
incref
(
NotImplemented
)
;
return
boxBool
(
slhs
->
s
()
>
srhs
->
s
());
case
Py_GE
:
if
(
unlikely
(
!
PyString_Check
(
rhs
)))
return
NotImplemented
;
return
incref
(
NotImplemented
)
;
return
boxBool
(
slhs
->
s
()
>=
srhs
->
s
());
default:
llvm_unreachable
(
"invalid op"
);
...
...
src/runtime/tuple.cpp
View file @
fc46bc42
...
...
@@ -47,6 +47,9 @@ Box* _tupleSlice(BoxedTuple* self, i64 start, i64 stop, i64 step, i64 length) {
auto
rtn
=
BoxedTuple
::
create
(
length
);
if
(
length
>
0
)
copySlice
(
&
rtn
->
elts
[
0
],
&
self
->
elts
[
0
],
start
,
step
,
length
);
for
(
int
i
=
0
;
i
<
length
;
i
++
)
{
Py_INCREF
(
rtn
->
elts
[
i
]);
}
return
rtn
;
}
...
...
@@ -157,7 +160,7 @@ template <ExceptionStyle S> Box* tupleGetitem(BoxedTuple* self, Box* slice) {
Box
*
tupleAdd
(
BoxedTuple
*
self
,
Box
*
rhs
)
{
if
(
!
PyTuple_Check
(
rhs
))
{
return
NotImplemented
;
return
incref
(
NotImplemented
)
;
}
BoxedTuple
*
_rhs
=
static_cast
<
BoxedTuple
*>
(
rhs
);
...
...
src/runtime/types.cpp
View file @
fc46bc42
...
...
@@ -2694,7 +2694,7 @@ Box* objectSetattr(Box* obj, Box* attr, Box* value) {
}
Box
*
objectSubclasshook
(
Box
*
cls
,
Box
*
a
)
{
return
NotImplemented
;
return
incref
(
NotImplemented
)
;
}
static
PyObject
*
import_copyreg
(
void
)
noexcept
{
...
...
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