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
84201c50
Commit
84201c50
authored
Sep 04, 2015
by
Boxiang Sun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add __imul__ and let list could multiple with instance which has __index__ attribute
parent
3f73110a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
35 additions
and
6 deletions
+35
-6
src/runtime/list.cpp
src/runtime/list.cpp
+35
-6
No files found.
src/runtime/list.cpp
View file @
84201c50
...
...
@@ -657,21 +657,22 @@ extern "C" int PyList_Insert(PyObject* op, Py_ssize_t where, PyObject* newitem)
}
Box
*
listMul
(
BoxedList
*
self
,
Box
*
rhs
)
{
if
(
rhs
->
cls
!=
int_cls
)
{
raiseExcHelper
(
TypeError
,
"can't multiply sequence by non-int of type '%s'"
,
getTypeName
(
rhs
));
}
static
BoxedString
*
index_str
=
internStringImmortal
(
"__index__"
);
Py_ssize_t
n
=
PyNumber_AsSsize_t
(
rhs
,
PyExc_IndexError
);
if
(
n
==
-
1
&&
PyErr_Occurred
())
throwCAPIException
();
int
n
=
static_cast
<
BoxedInt
*>
(
rhs
)
->
n
;
int
s
=
self
->
size
;
BoxedList
*
rtn
=
new
BoxedList
();
rtn
->
ensure
(
n
*
s
);
if
(
s
==
1
)
{
for
(
int
i
=
0
;
i
<
n
;
i
++
)
{
for
(
long
i
=
0
;
i
<
n
;
i
++
)
{
listAppendInternal
(
rtn
,
self
->
elts
->
elts
[
0
]);
}
}
else
{
for
(
int
i
=
0
;
i
<
n
;
i
++
)
{
for
(
long
i
=
0
;
i
<
n
;
i
++
)
{
listAppendArrayInternal
(
rtn
,
&
self
->
elts
->
elts
[
0
],
s
);
}
}
...
...
@@ -679,6 +680,33 @@ Box* listMul(BoxedList* self, Box* rhs) {
return
rtn
;
}
Box
*
listImul
(
BoxedList
*
self
,
Box
*
rhs
)
{
static
BoxedString
*
index_str
=
internStringImmortal
(
"__index__"
);
Py_ssize_t
n
=
PyNumber_AsSsize_t
(
rhs
,
PyExc_IndexError
);
if
(
n
==
-
1
&&
PyErr_Occurred
())
throwCAPIException
();
int
s
=
self
->
size
;
self
->
ensure
(
n
*
s
);
if
(
n
==
0
)
{
listSetitemSliceInt64
(
self
,
0
,
s
,
1
,
NULL
);
}
else
if
(
n
==
1
)
{
return
self
;
}
else
if
(
s
==
1
)
{
for
(
long
i
=
1
;
i
<
n
;
i
++
)
{
listAppendInternal
(
self
,
self
->
elts
->
elts
[
0
]);
}
}
else
{
for
(
long
i
=
1
;
i
<
n
;
i
++
)
{
listAppendArrayInternal
(
self
,
&
self
->
elts
->
elts
[
0
],
s
);
}
}
return
self
;
}
Box
*
listIAdd
(
BoxedList
*
self
,
Box
*
_rhs
)
{
if
(
_rhs
->
cls
==
list_cls
)
{
// This branch is safe if self==rhs:
...
...
@@ -1230,6 +1258,7 @@ void setupList() {
list_cls
->
giveAttr
(
"insert"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
listInsert
,
NONE
,
3
)));
list_cls
->
giveAttr
(
"__mul__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
listMul
,
LIST
,
2
)));
list_cls
->
giveAttr
(
"__rmul__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
listMul
,
LIST
,
2
)));
list_cls
->
giveAttr
(
"__imul__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
listImul
,
LIST
,
2
)));
list_cls
->
giveAttr
(
"__iadd__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
listIAdd
,
UNKNOWN
,
2
)));
list_cls
->
giveAttr
(
"__add__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
listAdd
,
UNKNOWN
,
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