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
afd7ed54
Commit
afd7ed54
authored
Apr 23, 2009
by
Robert Bradshaw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
closure cleanup, test
parent
c6b07f36
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
27 additions
and
10 deletions
+27
-10
Cython/Compiler/Nodes.py
Cython/Compiler/Nodes.py
+6
-2
Cython/Compiler/ParseTreeTransforms.py
Cython/Compiler/ParseTreeTransforms.py
+0
-3
Cython/Compiler/Symtab.py
Cython/Compiler/Symtab.py
+1
-5
tests/run/closures_T82.pyx
tests/run/closures_T82.pyx
+20
-0
No files found.
Cython/Compiler/Nodes.py
View file @
afd7ed54
...
...
@@ -1062,13 +1062,17 @@ class FuncDefNode(StatNode, BlockNode):
lenv
.
scope_class
.
type
.
typeptr_cname
,
Naming
.
empty_tuple
))
# TODO: error handling
# The code below assumes the local variables are innitially NULL
code
.
put_gotref
(
Naming
.
cur_scope_cname
)
# The code below is because we assume the local variables are
# innitially NULL.
# Note that it is unsafe to decref the scope at this point.
for
entry
in
lenv
.
arg_entries
+
lenv
.
var_entries
:
if
entry
.
in_closure
and
entry
.
type
.
is_pyobject
:
code
.
put_gotref
(
entry
.
cname
)
# so the refnanny doesn't whine
code
.
put_var_decref_clear
(
entry
)
if
env
.
is_closure_scope
:
if
lenv
.
is_closure_scope
:
code
.
put_gotref
(
outer_scope_cname
)
code
.
put_decref
(
outer_scope_cname
,
env
.
scope_class
.
type
)
code
.
putln
(
"%s = (%s)%s;"
%
(
outer_scope_cname
,
...
...
@@ -1883,7 +1887,7 @@ class DefNode(FuncDefNode):
if
arg
.
is_generic
:
# or arg.needs_conversion:
if
arg
.
needs_conversion
:
code
.
putln
(
"PyObject *%s = 0;"
%
arg
.
hdr_cname
)
elif
not
entry
.
in_closure
:
elif
not
arg
.
entry
.
in_closure
:
code
.
put_var_declaration
(
arg
.
entry
)
def
generate_keyword_list
(
self
,
code
):
...
...
Cython/Compiler/ParseTreeTransforms.py
View file @
afd7ed54
...
...
@@ -865,8 +865,6 @@ class CreateClosureClasses(CythonTransform):
def
create_class_from_scope
(
self
,
node
,
target_module_scope
):
print
node
.
entry
.
scope
.
is_closure_scope
as_name
=
"%s%s"
%
(
Naming
.
closure_class_prefix
,
node
.
entry
.
cname
)
func_scope
=
node
.
local_scope
...
...
@@ -875,7 +873,6 @@ class CreateClosureClasses(CythonTransform):
func_scope
.
scope_class
=
entry
class_scope
=
entry
.
type
.
scope
if
node
.
entry
.
scope
.
is_closure_scope
:
print
"yes"
,
class_scope
class_scope
.
declare_var
(
pos
=
node
.
pos
,
name
=
Naming
.
outer_scope_cname
,
# this could conflict?
cname
=
Naming
.
outer_scope_cname
,
...
...
Cython/Compiler/Symtab.py
View file @
afd7ed54
...
...
@@ -1057,7 +1057,6 @@ class LocalScope(Scope):
entry = Scope.lookup(self, name)
if entry is not None:
if entry.scope is not self and entry.scope.is_closure_scope:
print "making new entry for", entry.cname, "in", self
# The actual c fragment for the different scopes differs
# on the outside and inside, so we make a new entry
entry.in_closure = True
...
...
@@ -1072,9 +1071,7 @@ class LocalScope(Scope):
return entry
def mangle_closure_cnames(self, outer_scope_cname):
print "mangling", self
for entry in self.entries.values():
print entry.name, entry.in_closure, entry.from_closure
if entry.from_closure:
cname = entry.outer_entry.cname
if cname.startswith(Naming.cur_scope_cname):
...
...
@@ -1083,7 +1080,6 @@ class LocalScope(Scope):
elif entry.in_closure:
entry.original_cname = entry.cname
entry.cname = "%s->%s" % (Naming.cur_scope_cname, entry.cname)
print entry.cname
class ClosureScope(LocalScope):
...
...
tests/run/closures_T82.pyx
0 → 100644
View file @
afd7ed54
__doc__
=
u"""
>>> f = add_n(3)
>>> f(2)
5
>>> a(5)()
8
"""
def
add_n
(
int
n
):
def
f
(
int
x
):
return
x
+
n
return
f
def
a
(
int
x
):
def
b
():
def
c
():
return
3
+
x
return
c
()
return
b
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