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
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cython
Commits
12eaff05
Commit
12eaff05
authored
Oct 28, 2017
by
scoder
Committed by
GitHub
Oct 28, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1954 from nils-braun/pythran-multiple-line-support
Type inference for Pythran expressions
parents
33c4f688
b1d62ad5
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
36 additions
and
9 deletions
+36
-9
Cython/Compiler/ExprNodes.py
Cython/Compiler/ExprNodes.py
+18
-3
Cython/Compiler/PyrexTypes.py
Cython/Compiler/PyrexTypes.py
+9
-0
Cython/Compiler/Pythran.py
Cython/Compiler/Pythran.py
+7
-6
Cython/Compiler/TypeInference.py
Cython/Compiler/TypeInference.py
+2
-0
No files found.
Cython/Compiler/ExprNodes.py
View file @
12eaff05
...
...
@@ -2284,7 +2284,11 @@ class NameNode(AtomicExprNode):
code
.
putln
(
'%s = %s;'
%
(
self
.
result
(),
result
))
else
:
result
=
rhs
.
result_as
(
self
.
ctype
())
code
.
putln
(
'%s = %s;'
%
(
self
.
result
(),
result
))
if
is_pythran_expr
(
self
.
type
):
code
.
putln
(
'new (&%s) decltype(%s){%s};'
%
(
self
.
result
(),
self
.
result
(),
result
))
else
:
code
.
putln
(
'%s = %s;'
%
(
self
.
result
(),
result
))
if
debug_disposal_code
:
print
(
"NameNode.generate_assignment_code:"
)
print
(
"...generating post-assignment code for %s"
%
rhs
)
...
...
@@ -3450,6 +3454,10 @@ class IndexNode(_IndexingBaseNode):
if
index_func
is
not
None
:
return
index_func
.
type
.
return_type
if
is_pythran_expr
(
base_type
)
and
is_pythran_expr
(
index_type
):
index_with_type
=
(
self
.
index
,
index_type
)
return
PythranExpr
(
pythran_indexing_type
(
base_type
,
[
index_with_type
]))
# may be slicing or indexing, we don't know
if
base_type
in
(
unicode_type
,
str_type
):
# these types always returns their own type on Python indexing/slicing
...
...
@@ -4100,7 +4108,8 @@ class BufferIndexNode(_IndexingBaseNode):
def
analyse_buffer_index
(
self
,
env
,
getting
):
if
is_pythran_expr
(
self
.
base
.
type
):
self
.
type
=
PythranExpr
(
pythran_indexing_type
(
self
.
base
.
type
,
self
.
indices
))
index_with_type_list
=
[(
idx
,
idx
.
type
)
for
idx
in
self
.
indices
]
self
.
type
=
PythranExpr
(
pythran_indexing_type
(
self
.
base
.
type
,
index_with_type_list
))
else
:
self
.
base
=
self
.
base
.
coerce_to_simple
(
env
)
self
.
type
=
self
.
base
.
type
.
dtype
...
...
@@ -12241,7 +12250,13 @@ class PrimaryCmpNode(ExprNode, CmpNode):
is_memslice_nonecheck
=
False
def
infer_type
(
self
,
env
):
# TODO: Actually implement this (after merging with -unstable).
type1
=
self
.
operand1
.
infer_type
(
env
)
type2
=
self
.
operand2
.
infer_type
(
env
)
if
is_pythran_expr
(
type1
)
or
is_pythran_expr
(
type2
):
if
is_pythran_supported_type
(
type1
)
and
is_pythran_supported_type
(
type2
):
return
PythranExpr
(
pythran_binop_type
(
self
.
operator
,
type1
,
type2
))
return
py_object_type
def
type_dependencies
(
self
,
env
):
...
...
Cython/Compiler/PyrexTypes.py
View file @
12eaff05
...
...
@@ -1506,6 +1506,15 @@ class PythranExpr(CType):
return
True
def
__eq__
(
self
,
other
):
"""Equality operation for PythranExpr using the str representation"""
return
str
(
self
)
==
str
(
other
)
def
__hash__
(
self
):
"""Hash function using the str representation"""
return
hash
(
str
(
self
))
class
CConstType
(
BaseType
):
is_const
=
1
...
...
Cython/Compiler/Pythran.py
View file @
12eaff05
...
...
@@ -66,7 +66,8 @@ def _index_access(index_code, indices):
return
(
'[%s]'
if
len
(
indices
)
==
1
else
'(%s)'
)
%
indexing
def
_index_type_code
(
idx
):
def
_index_type_code
(
index_with_type
):
idx
,
index_type
=
index_with_type
if
idx
.
is_slice
:
if
idx
.
step
.
is_none
:
func
=
"contiguous_slice"
...
...
@@ -76,11 +77,11 @@ def _index_type_code(idx):
n
=
3
return
"pythonic::types::%s(%s)"
%
(
func
,
","
.
join
([
"0"
]
*
n
))
elif
i
dx
.
type
.
is_int
:
return
"std::declval<%s>()"
%
i
dx
.
type
.
sign_and_name
()
elif
i
dx
.
type
.
is_pythran_expr
:
return
"std::declval<%s>()"
%
i
dx
.
type
.
pythran_type
raise
ValueError
(
"unsupported indexing type %s!"
%
i
dx
.
type
)
elif
i
ndex_
type
.
is_int
:
return
"std::declval<%s>()"
%
i
ndex_
type
.
sign_and_name
()
elif
i
ndex_
type
.
is_pythran_expr
:
return
"std::declval<%s>()"
%
i
ndex_
type
.
pythran_type
raise
ValueError
(
"unsupported indexing type %s!"
%
i
ndex_
type
)
def
_index_code
(
idx
):
...
...
Cython/Compiler/TypeInference.py
View file @
12eaff05
...
...
@@ -561,6 +561,8 @@ def safe_spanning_type(types, might_overflow, pos, scope):
# find_spanning_type() only returns 'bint' for clean boolean
# operations without other int types, so this is safe, too
return
result_type
elif
result_type
.
is_pythran_expr
:
return
result_type
elif
result_type
.
is_ptr
:
# Any pointer except (signed|unsigned|) char* can't implicitly
# become a PyObject, and inferring char* is now accepted, too.
...
...
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