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
4b61e74c
Commit
4b61e74c
authored
Apr 01, 2011
by
Haoyu Bai
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
@cython.cfunc decorator
parent
1e4a346e
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
89 additions
and
4 deletions
+89
-4
Cython/Compiler/Main.py
Cython/Compiler/Main.py
+2
-1
Cython/Compiler/Nodes.py
Cython/Compiler/Nodes.py
+2
-2
Cython/Compiler/Options.py
Cython/Compiler/Options.py
+1
-0
Cython/Compiler/ParseTreeTransforms.py
Cython/Compiler/ParseTreeTransforms.py
+45
-0
Cython/Compiler/Parsing.py
Cython/Compiler/Parsing.py
+1
-1
Cython/Shadow.py
Cython/Shadow.py
+2
-0
tests/run/purecdef.py
tests/run/purecdef.py
+36
-0
No files found.
Cython/Compiler/Main.py
View file @
4b61e74c
...
...
@@ -108,7 +108,7 @@ class Context(object):
from
ParseTreeTransforms
import
InterpretCompilerDirectives
,
TransformBuiltinMethods
from
ParseTreeTransforms
import
ExpandInplaceOperators
from
TypeInference
import
MarkAssignments
,
MarkOverflowingArithmetic
from
ParseTreeTransforms
import
AlignFunctionDefinitions
,
GilCheck
from
ParseTreeTransforms
import
A
djustDefByDirectives
,
A
lignFunctionDefinitions
,
GilCheck
from
AnalysedTreeTransforms
import
AutoTestDictTransform
from
AutoDocTransforms
import
EmbedSignature
from
Optimize
import
FlattenInListTransform
,
SwitchTransform
,
IterationTransform
...
...
@@ -135,6 +135,7 @@ class Context(object):
PostParse
(
self
),
_specific_post_parse
,
InterpretCompilerDirectives
(
self
,
self
.
compiler_directives
),
AdjustDefByDirectives
(
self
),
_align_function_definitions
,
MarkClosureVisitor
(
self
),
ConstantFolding
(),
...
...
Cython/Compiler/Nodes.py
View file @
4b61e74c
...
...
@@ -1947,7 +1947,7 @@ class DefNode(FuncDefNode):
self
.
num_required_kw_args
=
rk
self
.
num_required_args
=
r
def
as_cfunction
(
self
,
cfunc
=
None
,
scope
=
None
):
def
as_cfunction
(
self
,
cfunc
=
None
,
scope
=
None
,
overridable
=
True
):
if
self
.
star_arg
:
error
(
self
.
star_arg
.
pos
,
"cdef function cannot have star argument"
)
if
self
.
starstar_arg
:
...
...
@@ -1967,7 +1967,7 @@ class DefNode(FuncDefNode):
exception_check
=
False
,
nogil
=
False
,
with_gil
=
False
,
is_overridable
=
Tru
e
)
is_overridable
=
overridabl
e
)
cfunc
=
CVarDefNode
(
self
.
pos
,
type
=
cfunc_type
)
else
:
if
scope
is
None
:
...
...
Cython/Compiler/Options.py
View file @
4b61e74c
...
...
@@ -95,6 +95,7 @@ directive_types = {
'final'
:
bool
,
# final cdef classes and methods
'internal'
:
bool
,
# cdef class visibility in the module dict
'infer_types'
:
bool
,
# values can be True/None/False
'cfunc'
:
None
,
# decorators do not take directive value
}
for
key
,
val
in
directive_defaults
.
items
():
...
...
Cython/Compiler/ParseTreeTransforms.py
View file @
4b61e74c
...
...
@@ -1378,6 +1378,51 @@ class ExpandInplaceOperators(EnvTransform):
# In-place assignments can't happen within an expression.
return
node
class
AdjustDefByDirectives
(
CythonTransform
,
SkipDeclarations
):
"""
Adjust function and class definitions by the decorator directives:
@cython.cfunc
@cython.cclass
@cython.ccall
"""
def
visit_ModuleNode
(
self
,
node
):
self
.
directives
=
node
.
directives
self
.
in_py_class
=
False
self
.
visitchildren
(
node
)
return
node
def
visit_CompilerDirectivesNode
(
self
,
node
):
old_directives
=
self
.
directives
self
.
directives
=
node
.
directives
self
.
visitchildren
(
node
)
self
.
directives
=
old_directives
return
node
def
visit_DefNode
(
self
,
node
):
if
'cfunc'
in
self
.
directives
:
if
self
.
in_py_class
:
error
(
node
.
pos
,
"cfunc directive is not allowed here"
)
else
:
node
=
node
.
as_cfunction
(
overridable
=
False
)
return
self
.
visit
(
node
)
self
.
visitchildren
(
node
)
return
node
def
visit_PyClassDefNode
(
self
,
node
):
old_in_pyclass
=
self
.
in_py_class
self
.
in_py_class
=
True
self
.
visitchildren
(
node
)
self
.
in_py_class
=
old_in_pyclass
return
node
def
visit_CClassDefNode
(
self
,
node
):
old_in_pyclass
=
self
.
in_py_class
self
.
in_py_class
=
False
self
.
visitchildren
(
node
)
self
.
in_py_class
=
old_in_pyclass
return
node
class
AlignFunctionDefinitions
(
CythonTransform
):
"""
...
...
Cython/Compiler/Parsing.py
View file @
4b61e74c
...
...
@@ -1711,7 +1711,7 @@ def p_statement(s, ctx, first_statement = 0):
elif
s
.
sy
==
'IF'
:
return
p_IF_statement
(
s
,
ctx
)
elif
s
.
sy
==
'DECORATOR'
:
if
ctx
.
level
not
in
(
'module'
,
'class'
,
'c_class'
,
'function'
,
'property'
,
'module_pxd'
,
'c_class_pxd'
):
if
ctx
.
level
not
in
(
'module'
,
'class'
,
'c_class'
,
'function'
,
'property'
,
'module_pxd'
,
'c_class_pxd'
,
'other'
):
s
.
error
(
'decorator not allowed here'
)
s
.
level
=
ctx
.
level
decorators
=
p_decorators
(
s
)
...
...
Cython/Shadow.py
View file @
4b61e74c
...
...
@@ -23,6 +23,8 @@ class _EmptyDecoratorAndManager(object):
def
__exit__
(
self
,
exc_type
,
exc_value
,
traceback
):
pass
cfunc
=
_EmptyDecoratorAndManager
()
def
inline
(
f
,
*
args
,
**
kwds
):
if
isinstance
(
f
,
basestring
):
from
Cython.Build.Inline
import
cython_inline
...
...
tests/run/purecdef.py
0 → 100644
View file @
4b61e74c
import
cython
from
cython
import
cfunc
@
cython
.
test_assert_path_exists
(
'//CFuncDefNode'
)
@
cython
.
cfunc
def
ftang
():
x
=
0
@
cython
.
test_assert_path_exists
(
'//CFuncDefNode'
)
@
cfunc
def
fpure
(
a
):
return
a
*
2
def
test
():
"""
>>> test()
4
"""
ftang
()
return
fpure
(
2
)
with
cfunc
:
@
cython
.
test_assert_path_exists
(
'//CFuncDefNode'
)
def
fwith1
(
a
):
return
a
*
3
@
cython
.
test_assert_path_exists
(
'//CFuncDefNode'
)
def
fwith2
(
a
):
return
a
*
4
def
test_with
():
"""
>>> test_with()
(3, 4)
"""
return
fwith1
(
1
),
fwith2
(
1
)
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