From 7e498e6514c74c61839fed4f43cd429a0add5f53 Mon Sep 17 00:00:00 2001 From: Robert Bradshaw Date: Sun, 31 Jan 2010 02:24:26 -0800 Subject: [PATCH] Work towards #494, binding directive. --- Cython/Compiler/Nodes.py | 17 ++++++++++++----- Cython/Compiler/Options.py | 3 +++ 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/Cython/Compiler/Nodes.py b/Cython/Compiler/Nodes.py index 3c6b1644..d230f331 100644 --- a/Cython/Compiler/Nodes.py +++ b/Cython/Compiler/Nodes.py @@ -1076,7 +1076,7 @@ class FuncDefNode(StatNode, BlockNode): self.generate_cached_builtins_decls(lenv, code) # ----- Function header code.putln("") - with_pymethdef = env.is_py_class_scope or env.is_closure_scope + with_pymethdef = self.needs_assignment_synthesis(env, code) if self.py_func: self.py_func.generate_function_header(code, with_pymethdef = with_pymethdef, @@ -1635,7 +1635,6 @@ class DefNode(FuncDefNode): # name string the Python name of the function # lambda_name string the internal name of a lambda 'function' # decorators [DecoratorNode] list of decorators - # binding bool bind like a Python function # args [CArgDeclNode] formal arguments # star_arg PyArgDeclNode or None * argument # starstar_arg PyArgDeclNode or None ** argument @@ -1662,7 +1661,6 @@ class DefNode(FuncDefNode): entry = None acquire_gil = 0 self_in_stararg = 0 - binding = False def __init__(self, pos, **kwds): FuncDefNode.__init__(self, pos, **kwds) @@ -1962,10 +1960,19 @@ class DefNode(FuncDefNode): def analyse_expressions(self, env): self.local_scope.directives = env.directives self.analyse_default_values(env) - if env.is_py_class_scope or env.is_closure_scope: + if self.needs_assignment_synthesis(env): # Shouldn't we be doing this at the module level too? self.synthesize_assignment_node(env) + def needs_assignment_synthesis(self, env, code=None): + # Should enable for module level as well, that will require more testing... + if env.is_module_scope: + if code is None: + return env.directives['binding'] + else: + return code.globalstate.directives['binding'] + return env.is_py_class_scope or env.is_closure_scope + def synthesize_assignment_node(self, env): import ExprNodes if env.is_py_class_scope: @@ -1977,7 +1984,7 @@ class DefNode(FuncDefNode): self.pos, pymethdef_cname = self.entry.pymethdef_cname) else: rhs = ExprNodes.PyCFunctionNode( - self.pos, pymethdef_cname = self.entry.pymethdef_cname, binding = self.binding) + self.pos, pymethdef_cname = self.entry.pymethdef_cname, binding = env.directives['binding']) self.assmt = SingleAssignmentNode(self.pos, lhs = ExprNodes.NameNode(self.pos, name = self.name), rhs = rhs) diff --git a/Cython/Compiler/Options.py b/Cython/Compiler/Options.py index 7970ddeb..1e6e42cd 100644 --- a/Cython/Compiler/Options.py +++ b/Cython/Compiler/Options.py @@ -72,6 +72,9 @@ directive_defaults = { # test support 'test_assert_path_exists' : [], 'test_fail_if_path_exists' : [], + +# experimental, subject to change + 'binding': False, } # Override types possibilities above, if needed -- 2.26.2