Commit 4510e2ef authored by Robert Bradshaw's avatar Robert Bradshaw

First pass at PersistentLocalScope

parent ec7cd84b
...@@ -349,13 +349,14 @@ def create_generate_code(context, options): ...@@ -349,13 +349,14 @@ def create_generate_code(context, options):
def create_default_pipeline(context, options): def create_default_pipeline(context, options):
from ParseTreeTransforms import WithTransform, PostParse from ParseTreeTransforms import WithTransform, PostParse
from ParseTreeTransforms import AnalyseDeclarationsTransform, AnalyseExpressionsTransform from ParseTreeTransforms import AnalyseDeclarationsTransform, AnalyseExpressionsTransform, MarkClosureVisitor
from ModuleNode import check_c_classes from ModuleNode import check_c_classes
return [ return [
create_parse(context), create_parse(context),
PostParse(), PostParse(),
WithTransform(), WithTransform(),
MarkClosureVisitor(),
AnalyseDeclarationsTransform(), AnalyseDeclarationsTransform(),
check_c_classes, check_c_classes,
AnalyseExpressionsTransform(), AnalyseExpressionsTransform(),
......
...@@ -72,6 +72,7 @@ optional_args_cname = pyrex_prefix + "optional_args" ...@@ -72,6 +72,7 @@ optional_args_cname = pyrex_prefix + "optional_args"
no_opt_args = pyrex_prefix + "no_opt_args" no_opt_args = pyrex_prefix + "no_opt_args"
import_star = pyrex_prefix + "import_star" import_star = pyrex_prefix + "import_star"
import_star_set = pyrex_prefix + "import_star_set" import_star_set = pyrex_prefix + "import_star_set"
scope_obj_cname = pyrex_prefix + "scope"
line_c_macro = "__LINE__" line_c_macro = "__LINE__"
......
...@@ -10,7 +10,7 @@ import Naming ...@@ -10,7 +10,7 @@ import Naming
import PyrexTypes import PyrexTypes
import TypeSlots import TypeSlots
from PyrexTypes import py_object_type, error_type, CTypedefType, CFuncType from PyrexTypes import py_object_type, error_type, CTypedefType, CFuncType
from Symtab import ModuleScope, LocalScope, \ from Symtab import ModuleScope, LocalScope, PersistentLocalScope, \
StructOrUnionScope, PyClassScope, CClassScope StructOrUnionScope, PyClassScope, CClassScope
from Cython.Utils import open_new_file, replace_suffix, EncodedString from Cython.Utils import open_new_file, replace_suffix, EncodedString
import Options import Options
...@@ -773,9 +773,11 @@ class FuncDefNode(StatNode, BlockNode): ...@@ -773,9 +773,11 @@ class FuncDefNode(StatNode, BlockNode):
# return_type PyrexType # return_type PyrexType
# #filename string C name of filename string const # #filename string C name of filename string const
# entry Symtab.Entry # entry Symtab.Entry
# needs_closure boolean Whether or not this function has inner functions/classes/yield
py_func = None py_func = None
assmt = None assmt = None
needs_closure = False
def analyse_default_values(self, env): def analyse_default_values(self, env):
genv = env.global_scope() genv = env.global_scope()
...@@ -807,6 +809,9 @@ class FuncDefNode(StatNode, BlockNode): ...@@ -807,6 +809,9 @@ class FuncDefNode(StatNode, BlockNode):
genv = env genv = env
while env.is_py_class_scope or env.is_c_class_scope: while env.is_py_class_scope or env.is_c_class_scope:
env = env.outer_scope env = env.outer_scope
if self.needs_closure:
lenv = PersistentLocalScope(name = self.entry.name, outer_scope = genv)
else:
lenv = LocalScope(name = self.entry.name, outer_scope = genv) lenv = LocalScope(name = self.entry.name, outer_scope = genv)
lenv.return_type = self.return_type lenv.return_type = self.return_type
type = self.entry.type type = self.entry.type
......
...@@ -185,7 +185,7 @@ class AnalyseExpressionsTransform(VisitorTransform): ...@@ -185,7 +185,7 @@ class AnalyseExpressionsTransform(VisitorTransform):
self.visitchildren(node) self.visitchildren(node)
return node return node
class MarkClosureNode(VisitorTransform): class MarkClosureVisitor(VisitorTransform):
needs_closure = False needs_closure = False
......
# #
# Pyrex - Symbol Table # Symbol Table
# #
import re import re
...@@ -1121,6 +1121,11 @@ class LocalScope(Scope): ...@@ -1121,6 +1121,11 @@ class LocalScope(Scope):
self.entries[name] = entry self.entries[name] = entry
class PersistentLocalScope(LocalScope):
def mangle(self, prefix, name):
return "%s->%s" % (scope_obj_cname, name)
class StructOrUnionScope(Scope): class StructOrUnionScope(Scope):
# Namespace of a C struct or union. # Namespace of a C struct or union.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment