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
18873875
Commit
18873875
authored
May 21, 2014
by
Kevin Modzelewski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement list.remove
parent
bf51b63a
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
57 additions
and
15 deletions
+57
-15
src/runtime/dict.cpp
src/runtime/dict.cpp
+2
-7
src/runtime/list.cpp
src/runtime/list.cpp
+19
-0
src/runtime/objmodel.cpp
src/runtime/objmodel.cpp
+19
-0
src/runtime/objmodel.h
src/runtime/objmodel.h
+2
-0
src/runtime/stacktrace.cpp
src/runtime/stacktrace.cpp
+3
-7
test/tests/dict.py
test/tests/dict.py
+2
-1
test/tests/list.py
test/tests/list.py
+10
-0
No files found.
src/runtime/dict.cpp
View file @
18873875
...
...
@@ -108,15 +108,10 @@ Box* dictPop2(BoxedDict* self, Box* k) {
auto
it
=
self
->
d
.
find
(
k
);
if
(
it
==
self
->
d
.
end
())
{
Box
*
s
=
NULL
;
try
{
s
=
repr
(
k
);
}
catch
(
Box
*
e
)
{
s
=
NULL
;
}
BoxedString
*
s
=
reprOrNull
(
k
);
if
(
s
)
raiseExcHelper
(
KeyError
,
"%s"
,
s
tatic_cast
<
BoxedString
*>
(
s
)
->
s
.
c_str
());
raiseExcHelper
(
KeyError
,
"%s"
,
s
->
s
.
c_str
());
else
raiseExcHelper
(
KeyError
,
""
);
}
...
...
src/runtime/list.cpp
View file @
18873875
...
...
@@ -323,6 +323,24 @@ Box* listCount(BoxedList* self, Box* elt) {
return
new
BoxedInt
(
count
);
}
Box
*
listRemove
(
BoxedList
*
self
,
Box
*
elt
)
{
assert
(
self
->
cls
==
list_cls
);
for
(
int
i
=
0
;
i
<
self
->
size
;
i
++
)
{
Box
*
e
=
self
->
elts
->
elts
[
i
];
Box
*
cmp
=
compareInternal
(
e
,
elt
,
AST_TYPE
::
Eq
,
NULL
);
bool
b
=
nonzero
(
cmp
);
if
(
b
)
{
memmove
(
self
->
elts
->
elts
+
i
,
self
->
elts
->
elts
+
i
+
1
,
(
self
->
size
-
i
-
1
)
*
sizeof
(
Box
*
));
self
->
size
--
;
return
None
;
}
}
raiseExcHelper
(
ValueError
,
"list.remove(x): x not in list"
);
}
BoxedClass
*
list_iterator_cls
=
NULL
;
extern
"C"
void
listIteratorGCHandler
(
GCVisitor
*
v
,
void
*
p
)
{
...
...
@@ -396,6 +414,7 @@ void setupList() {
list_cls
->
giveAttr
(
"__new__"
,
new
BoxedFunction
(
new_
));
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
->
freeze
();
...
...
src/runtime/objmodel.cpp
View file @
18873875
...
...
@@ -1028,6 +1028,25 @@ extern "C" Box* repr(Box* obj) {
return
static_cast
<
BoxedString
*>
(
obj
);
}
extern
"C"
BoxedString
*
reprOrNull
(
Box
*
obj
)
{
try
{
Box
*
r
=
repr
(
obj
);
assert
(
r
->
cls
==
str_cls
);
// this should be checked by repr()
return
static_cast
<
BoxedString
*>
(
r
);
}
catch
(
Box
*
b
)
{
return
nullptr
;
}
}
extern
"C"
BoxedString
*
strOrNull
(
Box
*
obj
)
{
try
{
BoxedString
*
r
=
str
(
obj
);
return
static_cast
<
BoxedString
*>
(
r
);
}
catch
(
Box
*
b
)
{
return
nullptr
;
}
}
extern
"C"
bool
isinstance
(
Box
*
obj
,
Box
*
cls
,
int64_t
flags
)
{
bool
false_on_noncls
=
(
flags
&
0x1
);
...
...
src/runtime/objmodel.h
View file @
18873875
...
...
@@ -43,6 +43,8 @@ extern "C" Box* runtimeCall(Box*, int64_t, Box*, Box*, Box*, Box**);
extern
"C"
Box
*
callattr
(
Box
*
,
std
::
string
*
,
bool
,
int64_t
,
Box
*
,
Box
*
,
Box
*
,
Box
**
);
extern
"C"
BoxedString
*
str
(
Box
*
obj
);
extern
"C"
Box
*
repr
(
Box
*
obj
);
extern
"C"
BoxedString
*
reprOrNull
(
Box
*
obj
);
// similar to repr, but returns NULL on exception
extern
"C"
BoxedString
*
strOrNull
(
Box
*
obj
);
// similar to str, but returns NULL on exception
extern
"C"
bool
isinstance
(
Box
*
obj
,
Box
*
cls
,
int64_t
flags
);
extern
"C"
BoxedInt
*
hash
(
Box
*
obj
);
// extern "C" Box* abs_(Box* obj);
...
...
src/runtime/stacktrace.cpp
View file @
18873875
...
...
@@ -144,16 +144,12 @@ std::string formatException(Box* b) {
if
(
attr
==
nullptr
)
return
*
name
;
Box
*
r
;
try
{
r
=
str
(
attr
);
}
catch
(
Box
*
b
)
{
BoxedString
*
r
=
strOrNull
(
attr
);
if
(
!
r
)
return
*
name
;
}
assert
(
r
->
cls
==
str_cls
);
const
std
::
string
*
msg
=
&
static_cast
<
BoxedString
*>
(
r
)
->
s
;
const
std
::
string
*
msg
=
&
r
->
s
;
return
*
name
+
": "
+
*
msg
;
}
}
test/tests/dict.py
View file @
18873875
...
...
@@ -19,6 +19,7 @@ print d.pop(4)
try
:
d
.
pop
(
5
)
assert
0
except
KeyError
:
except
KeyError
,
e
:
print
e
.
message
print
"ok"
print
sorted
(
d
.
items
())
test/tests/list.py
View file @
18873875
...
...
@@ -33,3 +33,13 @@ print [1, 2, 3, 4, 5]
l
=
[
1
,
2
,
1
,
2
,
3
]
print
l
.
count
(
1
)
print
l
.
count
(
42
)
print
l
.
remove
(
1
)
print
l
try
:
l
.
remove
(
54
)
assert
0
except
ValueError
,
e
:
print
e
print
"ok"
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