Commit 482e38c4 authored by Kirill Smelkov's avatar Kirill Smelkov

X on ctuple <- std::pair

parent 14acda8e
...@@ -855,7 +855,7 @@ class ExprNode(Node): ...@@ -855,7 +855,7 @@ class ExprNode(Node):
for node in self.subexpr_nodes(): for node in self.subexpr_nodes():
node.annotate(code) node.annotate(code)
# ----------------- Coercion ---------------------- # ----------------- Coercion ---------------------- NOTE here
def coerce_to(self, dst_type, env): def coerce_to(self, dst_type, env):
# Coerce the result so that it can be assigned to # Coerce the result so that it can be assigned to
......
...@@ -179,6 +179,7 @@ def create_pipeline(context, mode, exclude_classes=()): ...@@ -179,6 +179,7 @@ def create_pipeline(context, mode, exclude_classes=()):
# code in pxd files. So it will be run multiple times in a # code in pxd files. So it will be run multiple times in a
# compilation stage. # compilation stage.
stages = [ stages = [
#PrintTree(),
NormalizeTree(context), NormalizeTree(context),
PostParse(context), PostParse(context),
_specific_post_parse, _specific_post_parse,
...@@ -209,7 +210,11 @@ def create_pipeline(context, mode, exclude_classes=()): ...@@ -209,7 +210,11 @@ def create_pipeline(context, mode, exclude_classes=()):
IntroduceBufferAuxiliaryVars(context), IntroduceBufferAuxiliaryVars(context),
_check_c_declarations, _check_c_declarations,
InlineDefNodeCalls(context), InlineDefNodeCalls(context),
#PrintTree(),
AnalyseExpressionsTransform(context), AnalyseExpressionsTransform(context),
#PrintTree(),
FindInvalidUseOfFusedTypes(context), FindInvalidUseOfFusedTypes(context),
ExpandInplaceOperators(context), ExpandInplaceOperators(context),
IterationTransform(context), IterationTransform(context),
......
...@@ -4062,6 +4062,23 @@ class CTupleType(CType): ...@@ -4062,6 +4062,23 @@ class CTupleType(CType):
env.use_utility_code(self._convert_from_py_code) env.use_utility_code(self._convert_from_py_code)
return True return True
def assignable_from_resolved_type(self, src_type):
if src_type.is_cpp_class and src_type.cname == "std::pair" and len(src_type.templates) == 2:
# XXX len self.xxx == len src_type.templates
# XXX types are assignable
print
#from Cython.Compiler.Pipeline import dumptree
#dumptree(src_type)
print src_type
print src_type.name
print src_type.cname
print src_type.templates
print
return 1 # XXX check types match
return super(CTupleType, self).assignable_from_resolved_type(src_type)
def c_tuple_type(components): def c_tuple_type(components):
components = tuple(components) components = tuple(components)
......
# mode: run
# tag: cpp
from libcpp.utility cimport pair
cdef (int, double) _coerce_from_pair(pair[int, double] pxy) nogil:
cdef (int, double) txy = pxy
return txy
def coerce_from_pair(int x, double y):
"""
>>> coerce_from_pair(1, 3.14)
(1, 3.14)
"""
cdef pair[int, double] pxy = (x,y)
return _coerce_from_pair(pxy)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment