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
Gwenaël Samain
cython
Commits
3d641eac
Commit
3d641eac
authored
Oct 06, 2014
by
Robert Bradshaw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
CTuple arithmetic.
Fall back to Python conversion for now.
parent
efd0d426
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
3 deletions
+43
-3
Cython/Compiler/ExprNodes.py
Cython/Compiler/ExprNodes.py
+10
-3
tests/run/ctuple.pyx
tests/run/ctuple.pyx
+33
-0
No files found.
Cython/Compiler/ExprNodes.py
View file @
3d641eac
...
...
@@ -819,6 +819,10 @@ class ExprNode(Node):
return
self
elif
type
.
is_pyobject
or
type
.
is_int
or
type
.
is_ptr
or
type
.
is_float
:
return
CoerceToBooleanNode
(
self
,
env
)
elif
type
.
is_ctuple
:
bool_value
=
len
(
type
.
components
)
==
0
return
BoolNode
(
self
.
pos
,
value
=
bool_value
,
constant_result
=
bool_value
)
else
:
error
(
self
.
pos
,
"Type '%s' not acceptable as a boolean"
%
type
)
return
self
...
...
@@ -8395,7 +8399,7 @@ class UnopNode(ExprNode):
return
self
.
operand
.
check_const
()
def
is_py_operation
(
self
):
return
self
.
operand
.
type
.
is_pyobject
return
self
.
operand
.
type
.
is_pyobject
or
self
.
operand
.
type
.
is_ctuple
def
nogil_check
(
self
,
env
):
if
self
.
is_py_operation
():
...
...
@@ -9249,7 +9253,7 @@ class BinopNode(ExprNode):
return
self
.
is_py_operation_types
(
self
.
operand1
.
type
,
self
.
operand2
.
type
)
def
is_py_operation_types
(
self
,
type1
,
type2
):
return
type1
.
is_pyobject
or
type2
.
is_pyobject
return
type1
.
is_pyobject
or
type2
.
is_pyobject
or
type1
.
is_ctuple
or
type2
.
is_ctuple
def
is_cpp_operation
(
self
):
return
(
self
.
operand1
.
type
.
is_cpp_class
...
...
@@ -10368,7 +10372,10 @@ class CmpNode(object):
if
new_common_type
is
None
:
# fall back to generic type compatibility tests
if
type1
==
type2
:
new_common_type
=
type1
if
type1
.
is_ctuple
:
new_common_type
=
py_object_type
else
:
new_common_type
=
type1
elif
type1
.
is_pyobject
or
type2
.
is_pyobject
:
if
type2
.
is_numeric
or
type2
.
is_string
:
if
operand2
.
check_for_coercion_error
(
type1
,
env
):
...
...
tests/run/ctuple.pyx
View file @
3d641eac
...
...
@@ -107,3 +107,36 @@ def test_type_inference():
assert
cython
.
typeof
(
xy
)
==
"(int, double)"
,
cython
.
typeof
(
xy
)
xo
=
(
x
,
o
)
assert
cython
.
typeof
(
xo
)
==
"tuple object"
,
cython
.
typeof
(
xo
)
def
test_equality
((
int
,
int
)
ab
,
(
int
,
int
)
cd
,
(
int
,
int
)
ef
):
"""
>>> test_equality((1, 2), (3, 4), (5, 6))
True
>>> test_equality((1, 2), (3, 4), (3, 4))
True
>>> test_equality((3, 4), (3, 4), (3, 4))
False
"""
return
ab
<
cd
<=
ef
def
test_binop
((
int
,
int
)
ab
,
(
double
,
double
)
cd
):
"""
>>> test_binop((1, 2), (3, 4))
(1, 2, 3.0, 4.0)
"""
return
ab
+
cd
def
test_mul
((
int
,
int
)
ab
,
int
c
):
"""
>>> test_mul((1, 2), 3)
(1, 2, 1, 2, 1, 2)
"""
return
ab
*
c
def
test_unop
((
int
,
int
)
ab
):
"""
>>> test_unop((1, 2))
True
"""
return
not
ab
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