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
55bc639d
Commit
55bc639d
authored
Nov 17, 2009
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
yield statement and expression support (dummy)
parent
416e3293
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
5 deletions
+37
-5
Cython/Compiler/ExprNodes.py
Cython/Compiler/ExprNodes.py
+26
-0
Cython/Compiler/Parsing.py
Cython/Compiler/Parsing.py
+11
-5
No files found.
Cython/Compiler/ExprNodes.py
View file @
55bc639d
...
@@ -4030,6 +4030,32 @@ class LambdaNode(InnerFunctionNode):
...
@@ -4030,6 +4030,32 @@ class LambdaNode(InnerFunctionNode):
self
.
pymethdef_cname
=
self
.
def_node
.
entry
.
pymethdef_cname
self
.
pymethdef_cname
=
self
.
def_node
.
entry
.
pymethdef_cname
env
.
add_lambda_def
(
self
.
def_node
)
env
.
add_lambda_def
(
self
.
def_node
)
class
YieldExprNode
(
ExprNode
):
# Yield expression node
#
# arg ExprNode the value to return from the generator
# label_name string name of the C label used for this yield
subexprs
=
[]
type
=
py_object_type
def
analyse_types
(
self
,
env
):
self
.
is_temp
=
1
if
self
.
arg
is
not
None
:
self
.
arg
.
analyse_types
(
env
)
if
not
self
.
arg
.
type
.
is_pyobject
:
self
.
arg
=
self
.
arg
.
coerce_to_pyobject
(
env
)
def
generate_result_code
(
self
,
code
):
self
.
label_name
=
code
.
new_label
(
'resume_from_yield'
)
code
.
use_label
(
self
.
label_name
)
code
.
putln
(
"/* FIXME: save temporary variables */"
)
code
.
putln
(
"/* FIXME: return from function, yielding value */"
)
code
.
put_label
(
self
.
label_name
)
code
.
putln
(
"/* FIXME: restore temporary variables and */"
)
code
.
putln
(
"/* FIXME: extract sent value from closure */"
)
#-------------------------------------------------------------------
#-------------------------------------------------------------------
#
#
# Unary operator nodes
# Unary operator nodes
...
...
Cython/Compiler/Parsing.py
View file @
55bc639d
...
@@ -329,10 +329,16 @@ def p_yield_expression(s):
...
@@ -329,10 +329,16 @@ def p_yield_expression(s):
# s.sy == "yield"
# s.sy == "yield"
pos
=
s
.
position
()
pos
=
s
.
position
()
s
.
next
()
s
.
next
()
if
s
.
sy
not
in
(
'EOF'
,
'NEWLINE'
,
')'
):
if
s
.
sy
!=
')'
and
s
.
sy
not
in
statement_terminators
:
expr
=
p_expr
(
s
)
arg
=
p_expr
(
s
)
s
.
error
(
"generators ('yield') are not currently supported"
)
else
:
return
Nodes
.
PassStatNode
(
pos
)
arg
=
None
return
ExprNodes
.
YieldExprNode
(
pos
,
arg
=
arg
)
def
p_yield_statement
(
s
):
# s.sy == "yield"
yield_expr
=
p_yield_expression
(
s
)
return
Nodes
.
ExprStatNode
(
yield_expr
.
pos
,
expr
=
yield_expr
)
#power: atom trailer* ('**' factor)*
#power: atom trailer* ('**' factor)*
...
@@ -1533,7 +1539,7 @@ def p_simple_statement(s, first_statement = 0):
...
@@ -1533,7 +1539,7 @@ def p_simple_statement(s, first_statement = 0):
elif
s
.
sy
==
'from'
:
elif
s
.
sy
==
'from'
:
node
=
p_from_import_statement
(
s
,
first_statement
=
first_statement
)
node
=
p_from_import_statement
(
s
,
first_statement
=
first_statement
)
elif
s
.
sy
==
'yield'
:
elif
s
.
sy
==
'yield'
:
node
=
p_yield_
expression
(
s
)
node
=
p_yield_
statement
(
s
)
elif
s
.
sy
==
'assert'
:
elif
s
.
sy
==
'assert'
:
node
=
p_assert_statement
(
s
)
node
=
p_assert_statement
(
s
)
elif
s
.
sy
==
'pass'
:
elif
s
.
sy
==
'pass'
:
...
...
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