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
83b48537
Commit
83b48537
authored
Jun 27, 2009
by
Dag Sverre Seljebotn
Committed by
Mark Florisson
Sep 30, 2011
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Populate the cython.view module with some Python objects
parent
e8527c58
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
34 additions
and
7 deletions
+34
-7
Cython/Compiler/CythonScope.py
Cython/Compiler/CythonScope.py
+21
-0
Cython/Compiler/ExprNodes.py
Cython/Compiler/ExprNodes.py
+1
-0
Cython/Compiler/UtilityCode.py
Cython/Compiler/UtilityCode.py
+12
-7
No files found.
Cython/Compiler/CythonScope.py
View file @
83b48537
...
...
@@ -82,6 +82,11 @@ class CythonScope(ModuleScope):
cythonview_testscope_utility_code
.
declare_in_scope
(
viewscope
)
for
x
in
(
'strided'
,
'contig'
,
'follow'
,
'direct'
,
'ptr'
,
'full'
):
entry
=
viewscope
.
declare_var
(
x
,
py_object_type
,
None
,
cname
=
'__pyx_viewaxis_%s'
%
x
,
is_cdef
=
True
)
entry
.
utility_code_definition
=
view_utility_code
def
create_cython_scope
(
context
,
create_testscope
):
# One could in fact probably make it a singleton,
...
...
@@ -172,3 +177,19 @@ cythonview_testscope_utility_code = CythonUtilityCode(u"""
cdef object _testscope(int value):
return "hello from cython.view scope, value=%d" % value
"""
)
view_utility_code
=
CythonUtilityCode
(
u"""
cdef class Enum:
cdef object name
def __init__(self, name):
self.name = name
def __repr__(self):
return self.name
cdef strided = Enum("<strided axis packing mode>")
cdef contig = Enum("<contig axis packing mode>")
cdef follow = Enum("<follow axis packing mode>")
cdef direct = Enum("<direct axis access mode>")
cdef ptr = Enum("<ptr axis access mode>")
cdef full = Enum("<full axis access mode>")
"""
,
prefix
=
"__pyx_viewaxis_"
)
\ No newline at end of file
Cython/Compiler/ExprNodes.py
View file @
83b48537
...
...
@@ -3683,6 +3683,7 @@ class AttributeNode(ExprNode):
entry
.
is_cglobal
or
entry
.
is_cfunction
or
entry
.
is_type
or
entry
.
is_const
):
self
.
mutate_into_name_node
(
env
,
entry
,
target
)
entry
.
used
=
1
return
1
return
0
...
...
Cython/Compiler/UtilityCode.py
View file @
83b48537
...
...
@@ -6,20 +6,24 @@ from Cython.Compiler import Visitor
class
NonManglingModuleScope
(
Symtab
.
ModuleScope
):
def
__init__
(
self
,
prefix
,
*
args
,
**
kw
):
self
.
prefix
=
prefix
Symtab
.
ModuleScope
.
__init__
(
self
,
*
args
,
**
kw
)
def
add_imported_entry
(
self
,
name
,
entry
,
pos
):
entry
.
used
=
True
return
super
(
NonManglingModuleScope
,
self
).
add_imported_entry
(
name
,
entry
,
pos
)
def
mangle
(
self
,
prefix
,
name
=
None
):
if
name
:
if
prefix
in
(
Naming
.
typeobj_prefix
,
Naming
.
func_prefix
):
if
prefix
in
(
Naming
.
typeobj_prefix
,
Naming
.
func_prefix
,
Naming
.
var_prefix
):
# Functions, classes etc. gets a manually defined prefix easily
# manually callable instead (the one passed to CythonUtilityCode)
prefix
=
self
.
prefix
return
"%s%s"
%
(
prefix
,
name
)
else
:
return
self
.
base
.
name
return
Symtab
.
ModuleScope
.
mangle
(
self
,
prefix
)
class
CythonUtilityCodeContext
(
StringParseContext
):
scope
=
None
...
...
@@ -31,9 +35,10 @@ class CythonUtilityCodeContext(StringParseContext):
"from string code snippets"
)
if
self
.
scope
is
None
:
self
.
scope
=
NonManglingModuleScope
(
module_name
,
parent_module
=
None
,
context
=
self
)
self
.
scope
.
prefix
=
self
.
prefix
self
.
scope
=
NonManglingModuleScope
(
self
.
prefix
,
module_name
,
parent_module
=
None
,
context
=
self
)
return
self
.
scope
...
...
@@ -57,7 +62,7 @@ class CythonUtilityCode(object):
is_cython_utility
=
True
def
__init__
(
self
,
impl
,
name
=
"
CythonUtilityCode
"
,
prefix
=
""
,
requires
=
None
):
def
__init__
(
self
,
impl
,
name
=
"
__pyxutil
"
,
prefix
=
""
,
requires
=
None
):
# 1) We need to delay the parsing/processing, so that all modules can be
# imported without import loops
# 2) The same utility code object can be used for multiple source files;
...
...
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