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
ff6fe32f
Commit
ff6fe32f
authored
Aug 03, 2015
by
Kevin Modzelewski
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #791 from Daetalus/test_slice
Enable `test slice` and add missing function.
parents
ea3daebf
6fd62fdf
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
46 additions
and
1 deletion
+46
-1
from_cpython/Lib/test/test_slice.py
from_cpython/Lib/test/test_slice.py
+0
-1
src/runtime/types.cpp
src/runtime/types.cpp
+46
-0
No files found.
from_cpython/Lib/test/test_slice.py
View file @
ff6fe32f
# expected: fail
# tests for slice objects; in particular the indices method.
# tests for slice objects; in particular the indices method.
import
unittest
import
unittest
...
...
src/runtime/types.cpp
View file @
ff6fe32f
...
@@ -1719,6 +1719,48 @@ Box* sliceRepr(BoxedSlice* self) {
...
@@ -1719,6 +1719,48 @@ Box* sliceRepr(BoxedSlice* self) {
return
boxStringTwine
(
llvm
::
Twine
(
"slice("
)
+
start
->
s
()
+
", "
+
stop
->
s
()
+
", "
+
step
->
s
()
+
")"
);
return
boxStringTwine
(
llvm
::
Twine
(
"slice("
)
+
start
->
s
()
+
", "
+
stop
->
s
()
+
", "
+
step
->
s
()
+
")"
);
}
}
Box
*
sliceHash
(
BoxedSlice
*
self
)
{
raiseExcHelper
(
TypeError
,
"unhashable type"
);
return
boxLong
(
-
1l
);
}
Box
*
sliceReduce
(
BoxedSlice
*
self
)
{
return
Py_BuildValue
(
"O(OOO)"
,
self
->
cls
,
self
->
start
,
self
->
stop
,
self
->
step
);
}
Box
*
sliceIndices
(
BoxedSlice
*
self
,
Box
*
len
)
{
Py_ssize_t
ilen
,
start
,
stop
,
step
,
slicelength
;
ilen
=
PyNumber_AsSsize_t
(
len
,
PyExc_OverflowError
);
if
(
ilen
==
-
1
&&
PyErr_Occurred
())
{
throwCAPIException
();
}
if
(
PySlice_GetIndicesEx
((
PySliceObject
*
)
self
,
ilen
,
&
start
,
&
stop
,
&
step
,
&
slicelength
)
<
0
)
{
throwCAPIException
();
}
return
BoxedTuple
::
create
({
boxInt
(
start
),
boxInt
(
stop
),
boxInt
(
step
)
});
}
static
int
slice_compare
(
PySliceObject
*
v
,
PySliceObject
*
w
)
noexcept
{
int
result
=
0
;
if
(
v
==
w
)
return
0
;
if
(
PyObject_Cmp
(
v
->
start
,
w
->
start
,
&
result
)
<
0
)
return
-
2
;
if
(
result
!=
0
)
return
result
;
if
(
PyObject_Cmp
(
v
->
stop
,
w
->
stop
,
&
result
)
<
0
)
return
-
2
;
if
(
result
!=
0
)
return
result
;
if
(
PyObject_Cmp
(
v
->
step
,
w
->
step
,
&
result
)
<
0
)
return
-
2
;
return
result
;
}
extern
"C"
int
PySlice_GetIndices
(
PySliceObject
*
r
,
Py_ssize_t
length
,
Py_ssize_t
*
start
,
Py_ssize_t
*
stop
,
extern
"C"
int
PySlice_GetIndices
(
PySliceObject
*
r
,
Py_ssize_t
length
,
Py_ssize_t
*
start
,
Py_ssize_t
*
stop
,
Py_ssize_t
*
step
)
noexcept
{
Py_ssize_t
*
step
)
noexcept
{
/* XXX support long ints */
/* XXX support long ints */
...
@@ -3541,10 +3583,14 @@ void setupRuntime() {
...
@@ -3541,10 +3583,14 @@ void setupRuntime() {
slice_cls
->
giveAttr
(
"__new__"
,
slice_cls
->
giveAttr
(
"__new__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
sliceNew
,
UNKNOWN
,
4
,
2
,
false
,
false
),
{
NULL
,
None
}));
new
BoxedFunction
(
boxRTFunction
((
void
*
)
sliceNew
,
UNKNOWN
,
4
,
2
,
false
,
false
),
{
NULL
,
None
}));
slice_cls
->
giveAttr
(
"__repr__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
sliceRepr
,
STR
,
1
)));
slice_cls
->
giveAttr
(
"__repr__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
sliceRepr
,
STR
,
1
)));
slice_cls
->
giveAttr
(
"__hash__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
sliceHash
,
UNKNOWN
,
1
)));
slice_cls
->
giveAttr
(
"indices"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
sliceIndices
,
BOXED_TUPLE
,
2
)));
slice_cls
->
giveAttr
(
"__reduce__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
sliceReduce
,
BOXED_TUPLE
,
1
)));
slice_cls
->
giveAttr
(
"start"
,
new
BoxedMemberDescriptor
(
BoxedMemberDescriptor
::
OBJECT
,
offsetof
(
BoxedSlice
,
start
)));
slice_cls
->
giveAttr
(
"start"
,
new
BoxedMemberDescriptor
(
BoxedMemberDescriptor
::
OBJECT
,
offsetof
(
BoxedSlice
,
start
)));
slice_cls
->
giveAttr
(
"stop"
,
new
BoxedMemberDescriptor
(
BoxedMemberDescriptor
::
OBJECT
,
offsetof
(
BoxedSlice
,
stop
)));
slice_cls
->
giveAttr
(
"stop"
,
new
BoxedMemberDescriptor
(
BoxedMemberDescriptor
::
OBJECT
,
offsetof
(
BoxedSlice
,
stop
)));
slice_cls
->
giveAttr
(
"step"
,
new
BoxedMemberDescriptor
(
BoxedMemberDescriptor
::
OBJECT
,
offsetof
(
BoxedSlice
,
step
)));
slice_cls
->
giveAttr
(
"step"
,
new
BoxedMemberDescriptor
(
BoxedMemberDescriptor
::
OBJECT
,
offsetof
(
BoxedSlice
,
step
)));
slice_cls
->
freeze
();
slice_cls
->
freeze
();
slice_cls
->
tp_compare
=
(
cmpfunc
)
slice_compare
;
attrwrapper_cls
->
giveAttr
(
"__setitem__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
AttrWrapper
::
setitem
,
UNKNOWN
,
3
)));
attrwrapper_cls
->
giveAttr
(
"__setitem__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
AttrWrapper
::
setitem
,
UNKNOWN
,
3
)));
attrwrapper_cls
->
giveAttr
(
attrwrapper_cls
->
giveAttr
(
...
...
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