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
69903def
Commit
69903def
authored
Aug 10, 2014
by
Joris Vankerschaver
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Factor out tupleGetitemInt.
parent
32ccd8a8
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
14 deletions
+27
-14
src/runtime/tuple.cpp
src/runtime/tuple.cpp
+22
-14
test/tests/tuples.py
test/tests/tuples.py
+5
-0
No files found.
src/runtime/tuple.cpp
View file @
69903def
...
...
@@ -33,23 +33,27 @@ extern "C" Box* createTuple(int64_t nelts, Box** elts) {
return
new
BoxedTuple
(
std
::
move
(
velts
));
}
Box
*
tupleGetitem
(
BoxedTuple
*
self
,
Box
*
slice
)
{
assert
(
self
->
cls
==
tuple_cls
);
Box
*
tupleGetitem
Int
(
BoxedTuple
*
self
,
BoxedInt
*
slice
)
{
i64
n
=
slice
->
n
;
i64
size
=
self
->
elts
.
size
();
if
(
slice
->
cls
==
int_cls
)
{
i64
n
=
static_cast
<
BoxedInt
*>
(
slice
)
->
n
;
if
(
n
<
0
)
n
=
size
-
n
;
if
(
n
<
0
||
n
>=
size
)
{
fprintf
(
stderr
,
"IndexError: tuple index out of range
\n
"
);
raiseExcHelper
(
IndexError
,
""
);
}
if
(
n
<
0
)
n
=
size
-
n
;
if
(
n
<
0
||
n
>=
size
)
{
fprintf
(
stderr
,
"IndexError: tuple index out of range
\n
"
);
raiseExcHelper
(
IndexError
,
""
);
}
Box
*
rtn
=
self
->
elts
[
n
];
return
rtn
;
}
Box
*
rtn
=
self
->
elts
[
n
];
return
rtn
;
Box
*
tupleGetitem
(
BoxedTuple
*
self
,
Box
*
slice
)
{
assert
(
self
->
cls
==
tuple_cls
);
if
(
slice
->
cls
==
int_cls
)
{
return
tupleGetitemInt
(
self
,
static_cast
<
BoxedInt
*>
(
slice
));
}
else
{
RELEASE_ASSERT
(
0
,
""
);
}
...
...
@@ -214,7 +218,11 @@ void setupTuple() {
tuple_cls
->
giveAttr
(
"__name__"
,
boxStrConstant
(
"tuple"
));
tuple_cls
->
giveAttr
(
"__getitem__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
tupleGetitem
,
UNKNOWN
,
2
)));
CLFunction
*
getitem
=
createRTFunction
(
2
,
0
,
0
,
0
);
addRTFunction
(
getitem
,
(
void
*
)
tupleGetitemInt
,
UNKNOWN
,
std
::
vector
<
ConcreteCompilerType
*>
{
BOXED_TUPLE
,
BOXED_INT
});
addRTFunction
(
getitem
,
(
void
*
)
tupleGetitem
,
UNKNOWN
,
std
::
vector
<
ConcreteCompilerType
*>
{
BOXED_TUPLE
,
UNKNOWN
});
tuple_cls
->
giveAttr
(
"__getitem__"
,
new
BoxedFunction
(
getitem
));
tuple_cls
->
giveAttr
(
"__contains__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
tupleContains
,
BOXED_BOOL
,
2
)));
tuple_cls
->
giveAttr
(
"__iter__"
,
...
...
test/tests/tuples.py
View file @
69903def
...
...
@@ -76,3 +76,8 @@ print () + ()
print
(
1
,
2
,
3
)
+
()
print
()
+
(
1
,
2
,
3
)
print
(
1
,
2
)
+
(
2
,
3
)
# __getitem__
t
=
(
1
,
"2"
)
assert
t
[
0
]
==
1
assert
t
[
1
]
==
"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