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
7d1a5f54
Commit
7d1a5f54
authored
Dec 14, 2010
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Plain Diff
merge
parents
6d88e945
a3f75eea
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
50 additions
and
13 deletions
+50
-13
Cython/Compiler/Code.pxd
Cython/Compiler/Code.pxd
+2
-0
Cython/Compiler/Code.py
Cython/Compiler/Code.py
+5
-1
Cython/Compiler/ExprNodes.py
Cython/Compiler/ExprNodes.py
+6
-2
Cython/Compiler/Nodes.py
Cython/Compiler/Nodes.py
+1
-1
Cython/Compiler/ParseTreeTransforms.py
Cython/Compiler/ParseTreeTransforms.py
+12
-9
tests/errors/e_generators.pyx
tests/errors/e_generators.pyx
+24
-0
No files found.
Cython/Compiler/Code.pxd
View file @
7d1a5f54
...
...
@@ -34,6 +34,8 @@ cdef class FunctionState:
cdef
public
dict
temps_used_type
cdef
public
size_t
temp_counter
cdef
public
object
closure_temps
@
cython
.
locals
(
n
=
size_t
)
cpdef
new_label
(
self
,
name
=*
)
cpdef
tuple
get_loop_labels
(
self
)
...
...
Cython/Compiler/Code.py
View file @
7d1a5f54
...
...
@@ -117,6 +117,7 @@ class FunctionState(object):
self
.
temps_free
=
{}
# (type, manage_ref) -> list of free vars with same type/managed status
self
.
temps_used_type
=
{}
# name -> (type, manage_ref)
self
.
temp_counter
=
0
self
.
closure_temps
=
None
# labels
...
...
@@ -270,6 +271,9 @@ class FunctionState(object):
if
manage_ref
for
cname
in
freelist
]
def
init_closure_temps
(
self
,
scope
):
self
.
closure_temps
=
ClosureTempAllocator
(
scope
)
class
IntConst
(
object
):
"""Global info about a Python integer constant held by GlobalState.
...
...
@@ -1397,7 +1401,7 @@ class PyrexCodeWriter(object):
class
ClosureTempAllocator
(
object
):
def
__init__
(
self
,
klass
=
None
):
def
__init__
(
self
,
klass
):
self
.
klass
=
klass
self
.
temps_allocated
=
{}
self
.
temps_free
=
{}
...
...
Cython/Compiler/ExprNodes.py
View file @
7d1a5f54
...
...
@@ -4978,11 +4978,15 @@ class YieldExprNode(ExprNode):
#
# arg ExprNode the value to return from the generator
# label_name string name of the C label used for this yield
# label_num integer yield label number
subexprs
=
[
'arg'
]
type
=
py_object_type
label_num
=
0
def
analyse_types
(
self
,
env
):
if
not
self
.
label_num
:
error
(
self
.
pos
,
"'yield' not supported here"
)
self
.
is_temp
=
1
if
self
.
arg
is
not
None
:
self
.
arg
.
analyse_types
(
env
)
...
...
@@ -5006,9 +5010,9 @@ class YieldExprNode(ExprNode):
else
:
code
.
put_init_to_py_none
(
Naming
.
retval_cname
,
py_object_type
)
saved
=
[]
code
.
temp_allocator
.
reset
()
code
.
funcstate
.
closure_temps
.
reset
()
for
cname
,
type
,
manage_ref
in
code
.
funcstate
.
temps_in_use
():
save_cname
=
code
.
temp_allocator
.
allocate_temp
(
type
)
save_cname
=
code
.
funcstate
.
closure_temps
.
allocate_temp
(
type
)
saved
.
append
((
cname
,
save_cname
,
type
))
if
type
.
is_pyobject
:
code
.
put_xgiveref
(
cname
)
...
...
Cython/Compiler/Nodes.py
View file @
7d1a5f54
...
...
@@ -1361,7 +1361,7 @@ class FuncDefNode(StatNode, BlockNode):
if
not
self
.
is_generator
:
self
.
generate_preamble
(
env
,
code
)
if
self
.
is_generator
:
code
.
temp_allocator
=
ClosureTempAllocator
(
lenv
.
scope_class
.
type
.
scope
)
code
.
funcstate
.
init_closure_temps
(
lenv
.
scope_class
.
type
.
scope
)
resume_code
=
code
.
insertion_point
()
first_run_label
=
code
.
new_label
(
'first_run'
)
code
.
use_label
(
first_run_label
)
...
...
Cython/Compiler/ParseTreeTransforms.py
View file @
7d1a5f54
...
...
@@ -1308,22 +1308,23 @@ class YieldNodeCollector(TreeVisitor):
def
__init__
(
self
):
super
(
YieldNodeCollector
,
self
).
__init__
()
self
.
yields
=
[]
self
.
has_return
=
False
self
.
returns
=
[]
self
.
has_return_value
=
False
visit_Node
=
TreeVisitor
.
visitchildren
def
visit_YieldExprNode
(
self
,
node
):
if
self
.
has_return
:
if
self
.
has_return
_value
:
error
(
node
.
pos
,
"'yield' outside function"
)
else
:
self
.
yields
.
append
(
node
)
node
.
label_num
=
len
(
self
.
yields
)
self
.
yields
.
append
(
node
)
node
.
label_num
=
len
(
self
.
yields
)
def
visit_ReturnStatNode
(
self
,
node
):
if
self
.
yields
:
error
(
collector
.
returns
[
0
].
pos
,
"'return' with argument inside generator"
)
else
:
self
.
has_return
=
True
if
node
.
value
:
self
.
has_return_value
=
True
if
self
.
yields
:
error
(
node
.
pos
,
"'return' with argument inside generator"
)
self
.
returns
.
append
(
node
)
def
visit_ClassDefNode
(
self
,
node
):
pass
...
...
@@ -1348,6 +1349,8 @@ class MarkClosureVisitor(CythonTransform):
collector
.
visitchildren
(
node
)
if
collector
.
yields
:
if
collector
.
returns
and
not
collector
.
has_return_value
:
error
(
collector
.
returns
[
0
].
pos
,
"'return' inside generators not yet supported "
)
node
.
is_generator
=
True
node
.
needs_closure
=
True
node
.
yields
=
collector
.
yields
...
...
tests/errors/e_generators.pyx
0 → 100644
View file @
7d1a5f54
def
foo
():
yield
return
0
def
bar
(
a
):
return
0
yield
def
xxx
():
yield
return
yield
class
Foo
:
yield
_ERRORS
=
u"""
3:4: 'return' with argument inside generator
7:4: 'yield' outside function
11:4: 'return' inside generators not yet supported
13:0: 'yield' not supported here
16:4: 'yield' not supported here
"""
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