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
87d1620d
Commit
87d1620d
authored
Apr 30, 2014
by
Kevin Modzelewski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tuple.__contains__
parent
6a1d65dd
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
19 additions
and
24 deletions
+19
-24
src/runtime/objmodel.cpp
src/runtime/objmodel.cpp
+3
-0
src/runtime/tuple.cpp
src/runtime/tuple.cpp
+13
-0
test/tests/contains.py
test/tests/contains.py
+3
-0
test/tests/t2.py
test/tests/t2.py
+0
-24
No files found.
src/runtime/objmodel.cpp
View file @
87d1620d
...
@@ -1774,6 +1774,9 @@ Box* compareInternal(Box* lhs, Box* rhs, int op_type, CompareRewriteArgs *rewrit
...
@@ -1774,6 +1774,9 @@ Box* compareInternal(Box* lhs, Box* rhs, int op_type, CompareRewriteArgs *rewrit
if
(
getitem
)
if
(
getitem
)
ASSERT
(
isUserDefined
(
rhs
->
cls
),
"%s should probably have a __contains__"
,
getTypeName
(
rhs
)
->
c_str
());
ASSERT
(
isUserDefined
(
rhs
->
cls
),
"%s should probably have a __contains__"
,
getTypeName
(
rhs
)
->
c_str
());
RELEASE_ASSERT
(
getitem
==
NULL
,
"need to try old iteration protocol"
);
RELEASE_ASSERT
(
getitem
==
NULL
,
"need to try old iteration protocol"
);
fprintf
(
stderr
,
"TypeError: argument of type '%s' is not iterable
\n
"
,
getTypeName
(
rhs
)
->
c_str
());
raiseExc
();
}
}
bool
b
=
nonzero
(
contained
);
bool
b
=
nonzero
(
contained
);
...
...
src/runtime/tuple.cpp
View file @
87d1620d
...
@@ -162,10 +162,23 @@ Box* tupleNe(BoxedTuple *self, Box *rhs) {
...
@@ -162,10 +162,23 @@ Box* tupleNe(BoxedTuple *self, Box *rhs) {
return
_tupleCmp
(
self
,
static_cast
<
BoxedTuple
*>
(
rhs
),
AST_TYPE
::
NotEq
);
return
_tupleCmp
(
self
,
static_cast
<
BoxedTuple
*>
(
rhs
),
AST_TYPE
::
NotEq
);
}
}
Box
*
tupleContains
(
BoxedTuple
*
self
,
Box
*
elt
)
{
int
size
=
self
->
elts
.
size
();
for
(
int
i
=
0
;
i
<
size
;
i
++
)
{
Box
*
e
=
self
->
elts
[
i
];
Box
*
cmp
=
compareInternal
(
e
,
elt
,
AST_TYPE
::
Eq
,
NULL
);
bool
b
=
nonzero
(
cmp
);
if
(
b
)
return
True
;
}
return
False
;
}
void
setupTuple
()
{
void
setupTuple
()
{
tuple_cls
->
giveAttr
(
"__name__"
,
boxStrConstant
(
"tuple"
));
tuple_cls
->
giveAttr
(
"__name__"
,
boxStrConstant
(
"tuple"
));
tuple_cls
->
giveAttr
(
"__getitem__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
tupleGetitem
,
NULL
,
2
,
false
)));
tuple_cls
->
giveAttr
(
"__getitem__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
tupleGetitem
,
NULL
,
2
,
false
)));
tuple_cls
->
giveAttr
(
"__contains__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
tupleContains
,
NULL
,
2
,
false
)));
tuple_cls
->
giveAttr
(
"__lt__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
tupleLt
,
NULL
,
2
,
false
)));
tuple_cls
->
giveAttr
(
"__lt__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
tupleLt
,
NULL
,
2
,
false
)));
tuple_cls
->
giveAttr
(
"__le__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
tupleLe
,
NULL
,
2
,
false
)));
tuple_cls
->
giveAttr
(
"__le__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
tupleLe
,
NULL
,
2
,
false
)));
...
...
test/tests/contains.py
View file @
87d1620d
...
@@ -18,3 +18,6 @@ print 2 in [C("")] # False
...
@@ -18,3 +18,6 @@ print 2 in [C("")] # False
for
i
in
xrange
(
1
,
4
):
for
i
in
xrange
(
1
,
4
):
print
i
in
range
(
6
),
i
not
in
range
(
5
)
print
i
in
range
(
6
),
i
not
in
range
(
5
)
print
i
in
(
1
,
2
,
5
)
test/tests/t2.py
deleted
100644 → 0
View file @
6a1d65dd
t
=
(
1
,
"h"
)
print
t
,
str
(
t
),
repr
(
t
)
if
1
:
t
=
(
3
,)
print
t
def
f
():
t
=
(
1
,
3
)
print
t
f
()
print
()
print
(
1
,)
print
(
1
,
2
)
print
(
1
,
2
,
3
)
t
=
1
,
3
print
t
print
(
2
,)
<
(
2
,)
print
(
2
,)
<
(
2
,
3
)
print
(
3
,)
<
(
2
,
3
)
print
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