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
498cbc84
Commit
498cbc84
authored
May 22, 2014
by
xiafan_linux
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
implement list.reverse()
parent
a84f0025
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
1 deletion
+16
-1
src/runtime/list.cpp
src/runtime/list.cpp
+13
-1
test/tests/list.py
test/tests/list.py
+3
-0
No files found.
src/runtime/list.cpp
View file @
498cbc84
...
...
@@ -341,6 +341,18 @@ Box* listRemove(BoxedList* self, Box* elt) {
raiseExcHelper
(
ValueError
,
"list.remove(x): x not in list"
);
}
Box
*
listReverse
(
BoxedList
*
self
)
{
assert
(
self
->
cls
==
list_cls
);
if
(
self
->
size
>
0
)
{
for
(
int
i
=
0
,
j
=
self
->
size
-
1
;
i
<
j
;
i
++
,
j
--
)
{
Box
*
e
=
self
->
elts
->
elts
[
i
];
self
->
elts
->
elts
[
i
]
=
self
->
elts
->
elts
[
j
];
self
->
elts
->
elts
[
j
]
=
e
;
}
}
return
None
;
}
BoxedClass
*
list_iterator_cls
=
NULL
;
extern
"C"
void
listIteratorGCHandler
(
GCVisitor
*
v
,
void
*
p
)
{
...
...
@@ -415,7 +427,7 @@ void setupList() {
list_cls
->
giveAttr
(
"count"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
listCount
,
BOXED_INT
,
2
,
false
)));
list_cls
->
giveAttr
(
"remove"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
listRemove
,
NONE
,
2
,
false
)));
list_cls
->
giveAttr
(
"reverse"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
listReverse
,
NONE
,
1
,
false
)));
list_cls
->
freeze
();
...
...
test/tests/list.py
View file @
498cbc84
...
...
@@ -43,3 +43,6 @@ except ValueError, e:
print
e
print
"ok"
print
l
l
.
reverse
()
print
l
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