-from Cython.Compiler.Visitor import VisitorTransform, CythonTransform
-from Cython.Compiler.ModuleNode import ModuleNode
-from Cython.Compiler.Nodes import *
-from Cython.Compiler.ExprNodes import *
-from Cython.Compiler.StringEncoding import EncodedString
-from Cython.Compiler.Errors import CompileError
-from Cython.Utils import UtilityCode
+from Visitor import VisitorTransform, CythonTransform
+from ModuleNode import ModuleNode
+from Nodes import *
+from ExprNodes import *
+from StringEncoding import EncodedString
+from Errors import CompileError
+from Code import UtilityCode
import Interpreter
import PyrexTypes
#
from Symtab import BuiltinScope, StructOrUnionScope
-from Cython.Utils import UtilityCode
+from Code import UtilityCode
from TypeSlots import Signature
import PyrexTypes
import Naming
import Options
import StringEncoding
from Cython import Utils
-from PyrexTypes import py_object_type, typecast
-import PyrexTypes
-from TypeSlots import method_coexist
from Scanning import SourceDescriptor
from Cython.StringIOTree import StringIOTree
try:
from sets import Set as set
import DebugFlags
+from Cython.Utils import none_or_sub
+
+# a simple class that simplifies the usage of utility code
+
+class UtilityCode(object):
+ def __init__(self, proto=None, impl=None, init=None, cleanup=None, requires=None):
+ self.proto = proto
+ self.impl = impl
+ self.init = init
+ self.cleanup = cleanup
+ self.requires = requires
+ self._cache = {}
+ self.specialize_list = []
+
+ def write_init_code(self, writer, pos):
+ if not self.init:
+ return
+ if isinstance(self.init, basestring):
+ writer.put(self.init)
+ else:
+ self.init(writer, pos)
+
+ def write_cleanup_code(self, writer, pos):
+ if not self.cleanup:
+ return
+ if isinstance(self.cleanup, basestring):
+ writer.put(self.cleanup)
+ else:
+ self.cleanup(writer, pos)
+
+ def specialize(self, pyrex_type=None, **data):
+ # Dicts aren't hashable...
+ if pyrex_type is not None:
+ data['type'] = pyrex_type.declaration_code('')
+ data['type_name'] = pyrex_type.specalization_name()
+ key = data.items(); key.sort(); key = tuple(key)
+ try:
+ return self._cache[key]
+ except KeyError:
+ if self.requires is None:
+ requires = None
+ else:
+ requires = [r.specialize(data) for r in self.requires]
+ s = self._cache[key] = UtilityCode(
+ none_or_sub(self.proto, data),
+ none_or_sub(self.impl, data),
+ none_or_sub(self.init, data),
+ none_or_sub(self.cleanup, data),
+ requires)
+ self.specialize_list.append(s)
+ return s
+
class FunctionState(object):
# return_label string function return point label
# error_label string error catch point label
# utility_code_def
#
code = self.parts['utility_code_def']
+ import PyrexTypes
code.put(PyrexTypes.type_conversion_functions)
code.putln("")
return entry.cname
def as_pyobject(self, cname, type):
+ from PyrexTypes import py_object_type, typecast
return typecast(py_object_type, type, cname)
def put_gotref(self, cname):
self.putln("__Pyx_INCREF(%s);" % self.entry_as_pyobject(entry))
def put_decref_clear(self, cname, type, nanny=True):
+ from PyrexTypes import py_object_type, typecast
if nanny:
self.putln("__Pyx_DECREF(%s); %s = 0;" % (
typecast(py_object_type, type, cname), cname))
self.put_var_xdecref_clear(entry)
def put_init_to_py_none(self, cname, type, nanny=True):
+ from PyrexTypes import py_object_type, typecast
py_none = typecast(type, py_object_type, "Py_None")
if nanny:
self.putln("%s = %s; __Pyx_INCREF(Py_None);" % (cname, py_none))
self.put_init_to_py_none(code, entry.type, nanny)
def put_pymethoddef(self, entry, term):
+ from TypeSlots import method_coexist
if entry.doc:
doc_code = entry.doc_cname
else:
from Errors import error, warning, InternalError
from Errors import hold_errors, release_errors, held_errors, report_error
-from Cython.Utils import UtilityCode
+from Code import UtilityCode
import StringEncoding
import Naming
import Nodes
from Errors import error, warning
from PyrexTypes import py_object_type
-from Cython.Utils import open_new_file, replace_suffix, UtilityCode
+from Cython.Utils import open_new_file, replace_suffix
+from Code import UtilityCode
from StringEncoding import escape_byte_string, EncodedString
from PyrexTypes import py_object_type, error_type, CTypedefType, CFuncType
from Symtab import ModuleScope, LocalScope, GeneratorLocalScope, \
StructOrUnionScope, PyClassScope, CClassScope
-from Cython.Utils import open_new_file, replace_suffix, UtilityCode
+from Cython.Utils import open_new_file, replace_suffix
+from Code import UtilityCode
from StringEncoding import EncodedString, escape_byte_string, split_docstring
import Options
import ControlFlow
import Symtab
import Options
-from Cython.Utils import UtilityCode
+from Code import UtilityCode
from StringEncoding import EncodedString
from Errors import error
from ParseTreeTransforms import SkipDeclarations
# Pyrex - Types
#
-from Cython.Utils import UtilityCode
+from Code import UtilityCode
import StringEncoding
import Naming
import copy
pyfunction_signature, pymethod_signature, \
get_special_method_signature, get_property_accessor_signature
import ControlFlow
+import Code
import __builtin__
try:
set
# Should this go elsewhere (and then get imported)?
#------------------------------------------------------------------------------------
-classmethod_utility_code = Utils.UtilityCode(
+classmethod_utility_code = Code.UtilityCode(
proto = """
#include "descrobject.h"
static PyObject* __Pyx_Method_ClassMethod(PyObject *method); /*proto*/
else:
return s % data
-# a simple class that simplifies the usage of utility code
-
-class UtilityCode(object):
- def __init__(self, proto=None, impl=None, init=None, cleanup=None, requires=None):
- self.proto = proto
- self.impl = impl
- self.init = init
- self.cleanup = cleanup
- self.requires = requires
- self._cache = {}
- self.specialize_list = []
-
- def write_init_code(self, writer, pos):
- if not self.init:
- return
- if isinstance(self.init, basestring):
- writer.put(self.init)
- else:
- self.init(writer, pos)
-
- def write_cleanup_code(self, writer, pos):
- if not self.cleanup:
- return
- if isinstance(self.cleanup, basestring):
- writer.put(self.cleanup)
- else:
- self.cleanup(writer, pos)
-
- def specialize(self, pyrex_type=None, **data):
- # Dicts aren't hashable...
- if pyrex_type is not None:
- data['type'] = pyrex_type.declaration_code('')
- data['type_name'] = pyrex_type.specalization_name()
- key = data.items(); key.sort(); key = tuple(key)
- try:
- return self._cache[key]
- except KeyError:
- if self.requires is None:
- requires = None
- else:
- requires = [r.specialize(data) for r in self.requires]
- s = self._cache[key] = UtilityCode(
- none_or_sub(self.proto, data),
- none_or_sub(self.impl, data),
- none_or_sub(self.init, data),
- none_or_sub(self.cleanup, data),
- requires)
- self.specialize_list.append(s)
- return s