Commit 83b48537 authored by Dag Sverre Seljebotn's avatar Dag Sverre Seljebotn Committed by Mark Florisson

Populate the cython.view module with some Python objects

parent e8527c58
......@@ -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
......@@ -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
......
......@@ -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;
......
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