Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
cython
Commits
cd3a0429
Commit
cd3a0429
authored
May 04, 2009
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Plain Diff
merged in latest cython-devel
parents
f5bbfcc6
cdfded6a
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
81 additions
and
6 deletions
+81
-6
Cython/Compiler/Builtin.py
Cython/Compiler/Builtin.py
+2
-1
Cython/Compiler/ExprNodes.py
Cython/Compiler/ExprNodes.py
+15
-5
Cython/Compiler/Parsing.py
Cython/Compiler/Parsing.py
+2
-0
tests/run/typed_slice.pyx
tests/run/typed_slice.pyx
+62
-0
No files found.
Cython/Compiler/Builtin.py
View file @
cd3a0429
...
...
@@ -365,12 +365,13 @@ def init_builtins():
init_builtin_funcs
()
init_builtin_types
()
init_builtin_structs
()
global
list_type
,
tuple_type
,
dict_type
,
set_type
,
unicode_type
,
type_type
global
list_type
,
tuple_type
,
dict_type
,
set_type
,
bytes_type
,
unicode_type
,
type_type
type_type
=
builtin_scope
.
lookup
(
'type'
).
type
list_type
=
builtin_scope
.
lookup
(
'list'
).
type
tuple_type
=
builtin_scope
.
lookup
(
'tuple'
).
type
dict_type
=
builtin_scope
.
lookup
(
'dict'
).
type
set_type
=
builtin_scope
.
lookup
(
'set'
).
type
bytes_type
=
builtin_scope
.
lookup
(
'bytes'
).
type
unicode_type
=
builtin_scope
.
lookup
(
'unicode'
).
type
init_builtins
()
Cython/Compiler/ExprNodes.py
View file @
cd3a0429
...
...
@@ -13,7 +13,7 @@ import Nodes
from
Nodes
import
Node
import
PyrexTypes
from
PyrexTypes
import
py_object_type
,
c_long_type
,
typecast
,
error_type
from
Builtin
import
list_type
,
tuple_type
,
set_type
,
dict_type
,
unicode_type
from
Builtin
import
list_type
,
tuple_type
,
set_type
,
dict_type
,
unicode_type
,
bytes_type
import
Builtin
import
Symtab
import
Options
...
...
@@ -1884,6 +1884,12 @@ class SliceIndexNode(ExprNode):
def
analyse_target_declaration
(
self
,
env
):
pass
def
analyse_target_types
(
self
,
env
):
self
.
analyse_types
(
env
)
# when assigning, we must accept any Python type
if
self
.
type
.
is_pyobject
:
self
.
type
=
py_object_type
def
analyse_types
(
self
,
env
):
self
.
base
.
analyse_types
(
env
)
...
...
@@ -1891,16 +1897,20 @@ class SliceIndexNode(ExprNode):
self
.
start
.
analyse_types
(
env
)
if
self
.
stop
:
self
.
stop
.
analyse_types
(
env
)
if
self
.
base
.
type
.
is_string
:
self
.
type
=
py_object_type
elif
self
.
base
.
type
.
is_array
or
self
.
base
.
type
.
is_ptr
:
base_type
=
self
.
base
.
type
if
base_type
.
is_string
:
self
.
type
=
bytes_type
elif
base_type
.
is_array
or
base_type
.
is_ptr
:
# we need a ptr type here instead of an array type, as
# array types can result in invalid type casts in the C
# code
self
.
type
=
PyrexTypes
.
CPtrType
(
self
.
base
.
type
.
base_type
)
self
.
type
=
PyrexTypes
.
CPtrType
(
base_
type
.
base_type
)
else
:
self
.
base
=
self
.
base
.
coerce_to_pyobject
(
env
)
self
.
type
=
py_object_type
if
base_type
.
is_builtin_type
:
# slicing builtin types returns something of the same type
self
.
type
=
base_type
c_int
=
PyrexTypes
.
c_py_ssize_t_type
if
self
.
start
:
self
.
start
=
self
.
start
.
coerce_to
(
c_int
,
env
)
...
...
Cython/Compiler/Parsing.py
View file @
cd3a0429
...
...
@@ -1769,6 +1769,8 @@ def p_c_simple_base_type(s, self_flag, nonempty):
longness
=
0
module_path
=
[]
pos
=
s
.
position
()
if
not
s
.
sy
==
'IDENT'
:
error
(
pos
,
"Expected an identifier, found '%s'"
%
s
.
sy
)
if
looking_at_base_type
(
s
):
#print "p_c_simple_base_type: looking_at_base_type at", s.position()
is_basic
=
1
...
...
tests/run/typed_slice.pyx
0 → 100644
View file @
cd3a0429
__doc__
=
u"""
>>> l = [1,2,3,4]
>>> slice_list(l)
[2, 3]
>>> slice_tuple(tuple(l))
(2, 3)
>>> l2 = l[:]
>>> slice_list_assign_list(l2)
[1, 1, 2, 3, 4, 4]
>>> l2 = l[:]
>>> slice_list_assign_tuple(l2)
[1, 1, 2, 3, 4, 4]
>>> l2 = l[:]
>>> slice_list_assign(l2, (1,2,3,4))
[1, 1, 2, 3, 4, 4]
>>> l2 = l[:]
>>> slice_list_assign(l2, dict(zip(l,l)))
[1, 1, 2, 3, 4, 4]
>>> slice_charp('abcdefg')
'bc'
>>> slice_charp_repeat('abcdefg')
'cd'
"""
def
slice_list
(
list
l
):
return
l
[
1
:
3
]
def
slice_list_copy
(
list
l
):
cdef
list
retlist
=
l
[
1
:
3
]
return
retlist
def
slice_tuple
(
tuple
t
):
return
t
[
1
:
3
]
def
slice_list_assign_list
(
list
l
):
l
[
1
:
3
]
=
[
1
,
2
,
3
,
4
]
return
l
def
slice_list_assign_tuple
(
list
l
):
l
[
1
:
3
]
=
(
1
,
2
,
3
,
4
)
return
l
def
slice_list_assign
(
list
l
,
value
):
l
[
1
:
3
]
=
value
return
l
def
slice_charp
(
str
py_string
):
cdef
char
*
s
=
py_string
return
s
[
1
:
3
]
def
slice_charp_repeat
(
str
py_string
):
cdef
char
*
s
=
py_string
cdef
str
slice_val
=
s
[
1
:
6
]
s
=
slice_val
return
s
[
1
:
3
]
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