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
42928403
Commit
42928403
authored
Jan 09, 2011
by
Vitja Makarov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Don't store yield expressions list as yields can be copied
parent
7970cad9
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
6 deletions
+10
-6
Cython/Compiler/Nodes.py
Cython/Compiler/Nodes.py
+6
-3
Cython/Compiler/ParseTreeTransforms.py
Cython/Compiler/ParseTreeTransforms.py
+4
-3
No files found.
Cython/Compiler/Nodes.py
View file @
42928403
...
@@ -2944,11 +2944,10 @@ class GeneratorBodyDefNode(DefNode):
...
@@ -2944,11 +2944,10 @@ class GeneratorBodyDefNode(DefNode):
child_attrs
=
[
"args"
,
"star_arg"
,
"starstar_arg"
,
"body"
,
"decorators"
]
child_attrs
=
[
"args"
,
"star_arg"
,
"starstar_arg"
,
"body"
,
"decorators"
]
def
__init__
(
self
,
pos
=
None
,
name
=
None
,
body
=
None
,
yields
=
None
):
def
__init__
(
self
,
pos
=
None
,
name
=
None
,
body
=
None
):
super
(
GeneratorBodyDefNode
,
self
).
__init__
(
pos
=
pos
,
body
=
body
,
name
=
name
,
doc
=
None
,
super
(
GeneratorBodyDefNode
,
self
).
__init__
(
pos
=
pos
,
body
=
body
,
name
=
name
,
doc
=
None
,
args
=
[],
args
=
[],
star_arg
=
None
,
starstar_arg
=
None
)
star_arg
=
None
,
starstar_arg
=
None
)
self
.
yields
=
yields
def
declare_generator_body
(
self
,
env
):
def
declare_generator_body
(
self
,
env
):
prefix
=
env
.
next_id
(
env
.
scope_prefix
)
prefix
=
env
.
next_id
(
env
.
scope_prefix
)
...
@@ -3030,7 +3029,11 @@ class GeneratorBodyDefNode(DefNode):
...
@@ -3030,7 +3029,11 @@ class GeneratorBodyDefNode(DefNode):
# ----- Generator resume code
# ----- Generator resume code
resume_code
.
putln
(
"switch (%s->%s.resume_label) {"
%
(
Naming
.
cur_scope_cname
,
Naming
.
obj_base_cname
));
resume_code
.
putln
(
"switch (%s->%s.resume_label) {"
%
(
Naming
.
cur_scope_cname
,
Naming
.
obj_base_cname
));
resume_code
.
putln
(
"case 0: goto %s;"
%
first_run_label
)
resume_code
.
putln
(
"case 0: goto %s;"
%
first_run_label
)
for
yield_expr
in
self
.
yields
:
from
ParseTreeTransforms
import
YieldNodeCollector
collector
=
YieldNodeCollector
()
collector
.
visitchildren
(
self
)
for
yield_expr
in
collector
.
yields
:
resume_code
.
putln
(
"case %d: goto %s;"
%
(
yield_expr
.
label_num
,
yield_expr
.
label_name
));
resume_code
.
putln
(
"case %d: goto %s;"
%
(
yield_expr
.
label_num
,
yield_expr
.
label_name
));
resume_code
.
putln
(
"default: /* CPython raises the right error here */"
);
resume_code
.
putln
(
"default: /* CPython raises the right error here */"
);
resume_code
.
put_finish_refcount_context
()
resume_code
.
put_finish_refcount_context
()
...
...
Cython/Compiler/ParseTreeTransforms.py
View file @
42928403
...
@@ -1332,7 +1332,6 @@ class YieldNodeCollector(TreeVisitor):
...
@@ -1332,7 +1332,6 @@ class YieldNodeCollector(TreeVisitor):
if
self
.
has_return_value
:
if
self
.
has_return_value
:
error
(
node
.
pos
,
"'yield' outside function"
)
error
(
node
.
pos
,
"'yield' outside function"
)
self
.
yields
.
append
(
node
)
self
.
yields
.
append
(
node
)
node
.
label_num
=
len
(
self
.
yields
)
def
visit_ReturnStatNode
(
self
,
node
):
def
visit_ReturnStatNode
(
self
,
node
):
if
node
.
value
:
if
node
.
value
:
...
@@ -1370,10 +1369,12 @@ class MarkClosureVisitor(CythonTransform):
...
@@ -1370,10 +1369,12 @@ class MarkClosureVisitor(CythonTransform):
collector
.
visitchildren
(
node
)
collector
.
visitchildren
(
node
)
if
collector
.
yields
:
if
collector
.
yields
:
for
i
,
yield_expr
in
enumerate
(
collector
.
yields
):
yield_expr
.
label_num
=
i
+
1
gbody
=
Nodes
.
GeneratorBodyDefNode
(
pos
=
node
.
pos
,
gbody
=
Nodes
.
GeneratorBodyDefNode
(
pos
=
node
.
pos
,
name
=
node
.
name
,
name
=
node
.
name
,
body
=
node
.
body
,
body
=
node
.
body
)
yields
=
collector
.
yields
)
generator
=
Nodes
.
GeneratorDefNode
(
pos
=
node
.
pos
,
generator
=
Nodes
.
GeneratorDefNode
(
pos
=
node
.
pos
,
name
=
node
.
name
,
name
=
node
.
name
,
args
=
node
.
args
,
args
=
node
.
args
,
...
...
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