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
ad4b2066
Commit
ad4b2066
authored
Feb 13, 2008
by
Robert Bradshaw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Module-level cpdef functions
parent
be3c7caf
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
37 additions
and
13 deletions
+37
-13
Cython/Compiler/Nodes.py
Cython/Compiler/Nodes.py
+28
-11
Cython/Compiler/Options.py
Cython/Compiler/Options.py
+6
-0
Cython/Compiler/Parsing.py
Cython/Compiler/Parsing.py
+0
-2
Cython/Compiler/Symtab.py
Cython/Compiler/Symtab.py
+3
-0
No files found.
Cython/Compiler/Nodes.py
View file @
ad4b2066
...
@@ -867,7 +867,7 @@ class CFuncDefNode(FuncDefNode):
...
@@ -867,7 +867,7 @@ class CFuncDefNode(FuncDefNode):
if
self
.
overridable
:
if
self
.
overridable
:
import
ExprNodes
import
ExprNodes
py_func_body
=
self
.
call_self_node
()
py_func_body
=
self
.
call_self_node
(
is_module_scope
=
env
.
is_module_scope
)
self
.
py_func
=
DefNode
(
pos
=
self
.
pos
,
self
.
py_func
=
DefNode
(
pos
=
self
.
pos
,
name
=
self
.
declarator
.
base
.
name
,
name
=
self
.
declarator
.
base
.
name
,
args
=
self
.
declarator
.
args
,
args
=
self
.
declarator
.
args
,
...
@@ -875,23 +875,30 @@ class CFuncDefNode(FuncDefNode):
...
@@ -875,23 +875,30 @@ class CFuncDefNode(FuncDefNode):
starstar_arg
=
None
,
starstar_arg
=
None
,
doc
=
self
.
doc
,
doc
=
self
.
doc
,
body
=
py_func_body
)
body
=
py_func_body
)
self
.
py_func
.
is_module_scope
=
env
.
is_module_scope
self
.
py_func
.
analyse_declarations
(
env
)
self
.
py_func
.
analyse_declarations
(
env
)
self
.
entry
.
as_variable
=
self
.
py_func
.
entry
# Reset scope entry the above cfunction
# Reset scope entry the above cfunction
env
.
entries
[
name
]
=
self
.
entry
env
.
entries
[
name
]
=
self
.
entry
if
Options
.
intern_names
:
if
Options
.
intern_names
:
self
.
py_func
.
interned_attr_cname
=
env
.
intern
(
self
.
py_func
.
entry
.
name
)
self
.
py_func
.
interned_attr_cname
=
env
.
intern
(
self
.
py_func
.
entry
.
name
)
if
not
env
.
is_module_scope
or
Options
.
lookup_module_cpdef
:
self
.
override
=
OverrideCheckNode
(
self
.
pos
,
py_func
=
self
.
py_func
)
self
.
override
=
OverrideCheckNode
(
self
.
pos
,
py_func
=
self
.
py_func
)
self
.
body
=
StatListNode
(
self
.
pos
,
stats
=
[
self
.
override
,
self
.
body
])
self
.
body
=
StatListNode
(
self
.
pos
,
stats
=
[
self
.
override
,
self
.
body
])
def
call_self_node
(
self
,
omit_optional_args
=
0
):
def
call_self_node
(
self
,
omit_optional_args
=
0
,
is_module_scope
=
0
):
import
ExprNodes
import
ExprNodes
args
=
self
.
type
.
args
args
=
self
.
type
.
args
if
omit_optional_args
:
if
omit_optional_args
:
args
=
args
[:
len
(
args
)
-
self
.
type
.
optional_arg_count
]
args
=
args
[:
len
(
args
)
-
self
.
type
.
optional_arg_count
]
arg_names
=
[
arg
.
name
for
arg
in
args
]
arg_names
=
[
arg
.
name
for
arg
in
args
]
if
is_module_scope
:
cfunc
=
ExprNodes
.
NameNode
(
self
.
pos
,
name
=
self
.
declarator
.
base
.
name
)
else
:
self_arg
=
ExprNodes
.
NameNode
(
self
.
pos
,
name
=
arg_names
[
0
])
self_arg
=
ExprNodes
.
NameNode
(
self
.
pos
,
name
=
arg_names
[
0
])
cfunc
=
ExprNodes
.
AttributeNode
(
self
.
pos
,
obj
=
self_arg
,
attribute
=
self
.
declarator
.
base
.
name
)
cfunc
=
ExprNodes
.
AttributeNode
(
self
.
pos
,
obj
=
self_arg
,
attribute
=
self
.
declarator
.
base
.
name
)
c_call
=
ExprNodes
.
SimpleCallNode
(
self
.
pos
,
function
=
cfunc
,
args
=
[
ExprNodes
.
NameNode
(
self
.
pos
,
name
=
n
)
for
n
in
arg_names
[
1
:]],
wrapper_call
=
True
)
skip_dispatch
=
not
is_module_scope
or
Options
.
lookup_module_cpdef
c_call
=
ExprNodes
.
SimpleCallNode
(
self
.
pos
,
function
=
cfunc
,
args
=
[
ExprNodes
.
NameNode
(
self
.
pos
,
name
=
n
)
for
n
in
arg_names
[
1
-
is_module_scope
:]],
wrapper_call
=
skip_dispatch
)
return
ReturnStatNode
(
pos
=
self
.
pos
,
return_type
=
PyrexTypes
.
py_object_type
,
value
=
c_call
)
return
ReturnStatNode
(
pos
=
self
.
pos
,
return_type
=
PyrexTypes
.
py_object_type
,
value
=
c_call
)
def
declare_arguments
(
self
,
env
):
def
declare_arguments
(
self
,
env
):
...
@@ -1667,12 +1674,16 @@ class OverrideCheckNode(StatNode):
...
@@ -1667,12 +1674,16 @@ class OverrideCheckNode(StatNode):
def
analyse_expressions
(
self
,
env
):
def
analyse_expressions
(
self
,
env
):
self
.
args
=
env
.
arg_entries
self
.
args
=
env
.
arg_entries
if
self
.
py_func
.
is_module_scope
:
first_arg
=
0
else
:
first_arg
=
1
import
ExprNodes
import
ExprNodes
self
.
func_node
=
ExprNodes
.
PyTempNode
(
self
.
pos
,
env
)
self
.
func_node
=
ExprNodes
.
PyTempNode
(
self
.
pos
,
env
)
call_tuple
=
ExprNodes
.
TupleNode
(
self
.
pos
,
args
=
[
ExprNodes
.
NameNode
(
self
.
pos
,
name
=
arg
.
name
)
for
arg
in
self
.
args
[
1
:]])
call_tuple
=
ExprNodes
.
TupleNode
(
self
.
pos
,
args
=
[
ExprNodes
.
NameNode
(
self
.
pos
,
name
=
arg
.
name
)
for
arg
in
self
.
args
[
first_arg
:]])
call_node
=
ExprNodes
.
SimpleCallNode
(
self
.
pos
,
call_node
=
ExprNodes
.
SimpleCallNode
(
self
.
pos
,
function
=
self
.
func_node
,
function
=
self
.
func_node
,
args
=
[
ExprNodes
.
NameNode
(
self
.
pos
,
name
=
arg
.
name
)
for
arg
in
self
.
args
[
1
:]])
args
=
[
ExprNodes
.
NameNode
(
self
.
pos
,
name
=
arg
.
name
)
for
arg
in
self
.
args
[
first_arg
:]])
self
.
body
=
ReturnStatNode
(
self
.
pos
,
value
=
call_node
)
self
.
body
=
ReturnStatNode
(
self
.
pos
,
value
=
call_node
)
# self.func_temp = env.allocate_temp_pyobject()
# self.func_temp = env.allocate_temp_pyobject()
self
.
body
.
analyse_expressions
(
env
)
self
.
body
.
analyse_expressions
(
env
)
...
@@ -1680,10 +1691,16 @@ class OverrideCheckNode(StatNode):
...
@@ -1680,10 +1691,16 @@ class OverrideCheckNode(StatNode):
def
generate_execution_code
(
self
,
code
):
def
generate_execution_code
(
self
,
code
):
# Check to see if we are an extension type
# Check to see if we are an extension type
if
self
.
py_func
.
is_module_scope
:
self_arg
=
"((PyObject *)%s)"
%
Naming
.
module_cname
else
:
self_arg
=
"((PyObject *)%s)"
%
self
.
args
[
0
].
cname
self_arg
=
"((PyObject *)%s)"
%
self
.
args
[
0
].
cname
code
.
putln
(
"/* Check if called by wrapper */"
)
code
.
putln
(
"/* Check if called by wrapper */"
)
code
.
putln
(
"if (unlikely(%s)) %s = 0;"
%
(
Naming
.
skip_dispatch_cname
,
Naming
.
skip_dispatch_cname
))
code
.
putln
(
"if (unlikely(%s)) %s = 0;"
%
(
Naming
.
skip_dispatch_cname
,
Naming
.
skip_dispatch_cname
))
code
.
putln
(
"/* Check if overriden in Python */"
)
code
.
putln
(
"/* Check if overriden in Python */"
)
if
self
.
py_func
.
is_module_scope
:
code
.
putln
(
"else {"
)
else
:
code
.
putln
(
"else if (unlikely(%s->ob_type->tp_dictoffset != 0)) {"
%
self_arg
)
code
.
putln
(
"else if (unlikely(%s->ob_type->tp_dictoffset != 0)) {"
%
self_arg
)
err
=
code
.
error_goto_if_null
(
self_arg
,
self
.
pos
)
err
=
code
.
error_goto_if_null
(
self_arg
,
self
.
pos
)
# need to get attribute manually--scope would return cdef method
# need to get attribute manually--scope would return cdef method
...
...
Cython/Compiler/Options.py
View file @
ad4b2066
...
@@ -33,3 +33,9 @@ annotate = 0
...
@@ -33,3 +33,9 @@ annotate = 0
# raised before the loop is entered, wheras without this option the loop
# raised before the loop is entered, wheras without this option the loop
# will execute util a overflowing value is encountered.
# will execute util a overflowing value is encountered.
convert_range
=
0
convert_range
=
0
# Enable this to allow one to write your_module.foo = ... to overwrite the
# definition if the cpdef function foo, at the cost of an extra dictionary
# lookup on every call.
# If this is 0 it simply creates a wrapper.
lookup_module_cpdef
=
0
Cython/Compiler/Parsing.py
View file @
ad4b2066
...
@@ -1722,8 +1722,6 @@ def p_api(s):
...
@@ -1722,8 +1722,6 @@ def p_api(s):
def
p_cdef_statement
(
s
,
level
,
visibility
=
'private'
,
api
=
0
,
def
p_cdef_statement
(
s
,
level
,
visibility
=
'private'
,
api
=
0
,
overridable
=
False
):
overridable
=
False
):
pos
=
s
.
position
()
pos
=
s
.
position
()
if
overridable
and
level
not
in
(
'c_class'
,
'c_class_pxd'
):
error
(
pos
,
"Overridable cdef function not allowed here"
)
visibility
=
p_visibility
(
s
,
visibility
)
visibility
=
p_visibility
(
s
,
visibility
)
api
=
api
or
p_api
(
s
)
api
=
api
or
p_api
(
s
)
if
api
:
if
api
:
...
...
Cython/Compiler/Symtab.py
View file @
ad4b2066
...
@@ -148,6 +148,7 @@ class Scope:
...
@@ -148,6 +148,7 @@ class Scope:
is_py_class_scope
=
0
is_py_class_scope
=
0
is_c_class_scope
=
0
is_c_class_scope
=
0
is_module_scope
=
0
scope_prefix
=
""
scope_prefix
=
""
in_cinclude
=
0
in_cinclude
=
0
...
@@ -674,6 +675,8 @@ class ModuleScope(Scope):
...
@@ -674,6 +675,8 @@ class ModuleScope(Scope):
# all_pystring_entries [Entry] Python string consts from all scopes
# all_pystring_entries [Entry] Python string consts from all scopes
# types_imported {PyrexType : 1} Set of types for which import code generated
# types_imported {PyrexType : 1} Set of types for which import code generated
is_module_scope
=
1
def
__init__
(
self
,
name
,
parent_module
,
context
):
def
__init__
(
self
,
name
,
parent_module
,
context
):
self
.
parent_module
=
parent_module
self
.
parent_module
=
parent_module
outer_scope
=
context
.
find_submodule
(
"__builtin__"
)
outer_scope
=
context
.
find_submodule
(
"__builtin__"
)
...
...
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