From 0fdf2f78dec950152564e5293c18049255218006 Mon Sep 17 00:00:00 2001 From: Robert Bradshaw Date: Wed, 25 Mar 2009 18:25:51 -0700 Subject: [PATCH] More utility code specialization. --- Cython/Compiler/PyrexTypes.py | 10 +++++++--- Cython/Utils.py | 5 ++++- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/Cython/Compiler/PyrexTypes.py b/Cython/Compiler/PyrexTypes.py index d1418bde..a2b79438 100644 --- a/Cython/Compiler/PyrexTypes.py +++ b/Cython/Compiler/PyrexTypes.py @@ -14,6 +14,9 @@ class BaseType(object): def cast_code(self, expr_code): return "((%s)%s)" % (self.declaration_code(""), expr_code) + def specalization_name(self): + return self.declaration_code("").replace(" ", "__") + def base_declaration_code(self, base_code, entity_code): if entity_code: return "%s %s" % (base_code, entity_code) @@ -601,8 +604,9 @@ class CFloatType(CNumericType): to_py_function = "PyFloat_FromDouble" from_py_function = "__pyx_PyFloat_AsDouble" - def __init__(self, rank, pymemberdef_typecode = None): + def __init__(self, rank, pymemberdef_typecode = None, math_h_modifier = ''): CNumericType.__init__(self, rank, 1, pymemberdef_typecode) + self.math_h_modifier = math_h_modifier def assignable_from_resolved_type(self, src_type): return src_type.is_numeric or src_type is error_type @@ -1193,9 +1197,9 @@ c_slonglong_type = CLongLongType(6, 2, "T_LONGLONG") c_py_ssize_t_type = CPySSizeTType(4, 2, "T_PYSSIZET") c_size_t_type = CSizeTType(5, 0, "T_SIZET") -c_float_type = CFloatType(7, "T_FLOAT") +c_float_type = CFloatType(7, "T_FLOAT", math_h_modifier='f') c_double_type = CFloatType(8, "T_DOUBLE") -c_longdouble_type = CFloatType(9) +c_longdouble_type = CFloatType(9, math_h_modifier='l') c_null_ptr_type = CNullPtrType(c_void_type) c_char_array_type = CCharArrayType(None) diff --git a/Cython/Utils.py b/Cython/Utils.py index 685aa4a1..a4dfb3b8 100644 --- a/Cython/Utils.py +++ b/Cython/Utils.py @@ -122,8 +122,11 @@ class UtilityCode(object): else: writer.put(self.cleanup) - def specialize(self, **data): + 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] -- 2.26.2