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
6440f39f
Commit
6440f39f
authored
Jul 17, 2010
by
Craig Citro
Browse files
Options
Browse Files
Download
Plain Diff
merge
parents
e31d6a86
d002e6a7
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
21 additions
and
15 deletions
+21
-15
Cython/Compiler/Optimize.py
Cython/Compiler/Optimize.py
+15
-8
Cython/Compiler/Parsing.py
Cython/Compiler/Parsing.py
+2
-1
tests/run/inop.pyx
tests/run/inop.pyx
+4
-6
No files found.
Cython/Compiler/Optimize.py
View file @
6440f39f
...
...
@@ -1046,6 +1046,7 @@ class EarlyReplaceBuiltinCalls(Visitor.EnvTransform):
class
YieldNodeCollector
(
Visitor
.
TreeVisitor
):
def
__init__
(
self
):
Visitor
.
TreeVisitor
.
__init__
(
self
)
self
.
yield_stat_nodes
=
{}
self
.
yield_nodes
=
[]
visit_Node
=
Visitor
.
TreeVisitor
.
visitchildren
...
...
@@ -1053,12 +1054,18 @@ class EarlyReplaceBuiltinCalls(Visitor.EnvTransform):
self
.
yield_nodes
.
append
(
node
)
self
.
visitchildren
(
node
)
def
visit_ExprStatNode
(
self
,
node
):
self
.
visitchildren
(
node
)
if
node
.
expr
in
self
.
yield_nodes
:
self
.
yield_stat_nodes
[
node
.
expr
]
=
node
def
_find_single_yield_node
(
self
,
node
):
collector
=
self
.
YieldNodeCollector
()
collector
.
visitchildren
(
node
)
if
len
(
collector
.
yield_nodes
)
!=
1
:
return
None
return
collector
.
yield_nodes
[
0
]
return
None
,
None
yield_node
=
collector
.
yield_nodes
[
0
]
return
(
yield_node
,
collector
.
yield_stat_nodes
.
get
(
yield_node
))
def
_handle_simple_function_all
(
self
,
node
,
pos_args
):
"""Transform
...
...
@@ -1107,8 +1114,8 @@ class EarlyReplaceBuiltinCalls(Visitor.EnvTransform):
return
node
gen_expr_node
=
pos_args
[
0
]
loop_node
=
gen_expr_node
.
loop
yield_node
=
self
.
_find_single_yield_node
(
loop_node
)
if
yield_node
is
None
:
yield_node
,
yield_stat_node
=
self
.
_find_single_yield_node
(
loop_node
)
if
yield_node
is
None
or
yield_stat_node
is
None
:
return
node
yield_expression
=
yield_node
.
arg
...
...
@@ -1150,7 +1157,7 @@ class EarlyReplaceBuiltinCalls(Visitor.EnvTransform):
rhs
=
ExprNodes
.
BoolNode
(
yield_node
.
pos
,
value
=
not
is_any
,
constant_result
=
not
is_any
))
Visitor
.
recursively_replace_node
(
loop_node
,
yield_node
,
test_node
)
Visitor
.
recursively_replace_node
(
loop_node
,
yield_
stat_
node
,
test_node
)
return
ExprNodes
.
InlinedGeneratorExpressionNode
(
gen_expr_node
.
pos
,
loop
=
loop_node
,
result_node
=
result_ref
,
...
...
@@ -1166,8 +1173,8 @@ class EarlyReplaceBuiltinCalls(Visitor.EnvTransform):
gen_expr_node
=
pos_args
[
0
]
loop_node
=
gen_expr_node
.
loop
yield_node
=
self
.
_find_single_yield_node
(
loop_node
)
if
yield_node
is
None
:
yield_node
,
yield_stat_node
=
self
.
_find_single_yield_node
(
loop_node
)
if
yield_node
is
None
or
yield_stat_node
is
None
:
return
node
yield_expression
=
yield_node
.
arg
...
...
@@ -1183,7 +1190,7 @@ class EarlyReplaceBuiltinCalls(Visitor.EnvTransform):
rhs
=
ExprNodes
.
binop_node
(
node
.
pos
,
'+'
,
result_ref
,
yield_expression
)
)
Visitor
.
recursively_replace_node
(
loop_node
,
yield_node
,
add_node
)
Visitor
.
recursively_replace_node
(
loop_node
,
yield_
stat_
node
,
add_node
)
exec_code
=
Nodes
.
StatListNode
(
node
.
pos
,
...
...
Cython/Compiler/Parsing.py
View file @
6440f39f
...
...
@@ -958,7 +958,8 @@ def p_testlist_comp(s):
def
p_genexp
(
s
,
expr
):
# s.sy == 'for'
loop
=
p_comp_for
(
s
,
ExprNodes
.
YieldExprNode
(
expr
.
pos
,
arg
=
expr
))
loop
=
p_comp_for
(
s
,
Nodes
.
ExprStatNode
(
expr
.
pos
,
expr
=
ExprNodes
.
YieldExprNode
(
expr
.
pos
,
arg
=
expr
)))
return
ExprNodes
.
GeneratorExpressionNode
(
expr
.
pos
,
loop
=
loop
)
expr_terminators
=
(
')'
,
']'
,
'}'
,
':'
,
'='
,
'NEWLINE'
)
...
...
tests/run/inop.pyx
View file @
6440f39f
...
...
@@ -197,10 +197,8 @@ def m_unicode_literal(Py_UNICODE a):
cdef
unicode
wide_unicode_character
=
u'
\
U0010FEDC
'
py_wide_unicode_character
=
wide_unicode_character
cdef
unicode
wide_unicode_character_surrogate1
=
u'
\
uDBFF
'
cdef
unicode
wide_unicode_character_surrogate2
=
u'
\
uDEDC
'
py_wide_unicode_character_surrogate1
=
wide_unicode_character_surrogate1
py_wide_unicode_character_surrogate2
=
wide_unicode_character_surrogate2
wide_unicode_character_surrogate1
=
0xDBFF
wide_unicode_character_surrogate2
=
0xDEDC
@
cython
.
test_fail_if_path_exists
(
"//SwitchStatNode"
)
@
cython
.
test_assert_path_exists
(
"//PrimaryCmpNode"
)
...
...
@@ -212,8 +210,8 @@ def m_wide_unicode_literal(Py_UNICODE a):
0
>>> import sys
>>> if sys.maxunicode == 65535:
... m_wide_unicode_literal(
ord(py_wide_unicode_character_surrogate1)
)
... m_wide_unicode_literal(
ord(py_wide_unicode_character_surrogate2)
)
... m_wide_unicode_literal(
py_wide_unicode_character_surrogate1
)
... m_wide_unicode_literal(
py_wide_unicode_character_surrogate2
)
... else:
... m_wide_unicode_literal(ord(py_wide_unicode_character))
... 1
...
...
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