From c6ecb09cabe061af4c4c06765909aa5a0167ec2b Mon Sep 17 00:00:00 2001 From: Stefan Behnel Date: Thu, 9 Dec 2010 09:51:27 +0100 Subject: [PATCH] compile Code.py --- Cython/Compiler/Code.pxd | 72 ++++++++++++++++++++++++++++++++++++++++ Cython/Compiler/Code.py | 30 ++++++++++------- setup.py | 1 + 3 files changed, 91 insertions(+), 12 deletions(-) create mode 100644 Cython/Compiler/Code.pxd diff --git a/Cython/Compiler/Code.pxd b/Cython/Compiler/Code.pxd new file mode 100644 index 00000000..67bf72fa --- /dev/null +++ b/Cython/Compiler/Code.pxd @@ -0,0 +1,72 @@ + +cdef class UtilityCode: + cdef public object proto + cdef public object impl + cdef public object init + cdef public object cleanup + cdef public object requires + cdef public dict _cache + cdef public list specialize_list + cdef public object proto_block + + cpdef put_code(self, dict output) + +cdef class FunctionState: + cdef public set names_taken + cdef public object owner + + cdef public object error_label + cdef public Py_ssize_t label_counter + cdef public set labels_used + cdef public object return_label + cdef public object continue_label + cdef public object break_label + + cdef public object return_from_error_cleanup_label # not used in __init__ ? + + cdef public bint in_try_finally + cdef public object exc_vars + + cdef public list temps_allocated + cdef public dict temps_free + cdef public dict temps_used_type + cdef public Py_ssize_t temp_counter + + cpdef tuple get_loop_labels(self) + cpdef set_loop_labels(self, labels) + cpdef tuple get_all_labels(self) + cpdef set_all_labels(self, labels) + + cpdef list temps_in_use(self) + +cdef class IntConst: + cdef public object cname + cdef public object value + cdef public bint is_long + +cdef class PyObjectConst: + cdef public object cname + cdef public object type + +cdef class StringConst: + cdef public object cname + cdef public object text + cdef public object escaped_value + cdef public dict py_strings + +## cdef class PyStringConst: +## cdef public object cname +## cdef public object encoding +## cdef public bint is_str +## cdef public bint is_unicode +## cdef public bint intern + +#class GlobalState(object): + +#def funccontext_property(name): + +#class CCodeWriter(object): + +cdef class PyrexCodeWriter: + cdef public object f + cdef public Py_ssize_t level diff --git a/Cython/Compiler/Code.py b/Cython/Compiler/Code.py index 46b4b818..fe46430d 100644 --- a/Cython/Compiler/Code.py +++ b/Cython/Compiler/Code.py @@ -1,7 +1,13 @@ +# cython: language_level = 3 # # Pyrex - Code output module # +import cython +cython.declare(re=object, Naming=object, Options=object, StringEncoding=object, + Utils=object, SourceDescriptor=object, StringIOTree=object, + DebugFlags=object, none_or_sub=object) + import re import Naming import Options @@ -9,13 +15,13 @@ import StringEncoding from Cython import Utils from Scanning import SourceDescriptor from Cython.StringIOTree import StringIOTree -try: - set -except NameError: - from sets import Set as set import DebugFlags from Cython.Utils import none_or_sub +try: + basestring +except NameError: + basestring = str class UtilityCode(object): # Stores utility code to add during code generation. @@ -92,13 +98,13 @@ class FunctionState(object): # exc_vars (string * 3) exception variables for reraise, or None # Not used for now, perhaps later - def __init__(self, owner, names_taken=set()): + def __init__(self, owner, names_taken=cython.set()): self.names_taken = names_taken self.owner = owner self.error_label = None self.label_counter = 0 - self.labels_used = {} + self.labels_used = cython.set() self.return_label = self.new_label() self.new_error_label() self.continue_label = None @@ -168,7 +174,7 @@ class FunctionState(object): return old_labels def use_label(self, lbl): - self.labels_used[lbl] = 1 + self.labels_used.add(lbl) def label_used(self, lbl): return lbl in self.labels_used @@ -260,7 +266,7 @@ class FunctionState(object): error case. """ return [(cname, type) - for (type, manage_ref), freelist in self.temps_free.iteritems() + for (type, manage_ref), freelist in self.temps_free.items() if manage_ref for cname in freelist] @@ -436,7 +442,7 @@ class GlobalState(object): self.filename_table = {} self.filename_list = [] self.input_file_contents = {} - self.utility_codes = set() + self.utility_codes = cython.set() self.declared_cnames = {} self.in_utility_code_generation = False self.emit_linenums = emit_linenums @@ -683,7 +689,7 @@ class GlobalState(object): def generate_string_constants(self): c_consts = [ (len(c.cname), c.cname, c) - for c in self.string_const_index.itervalues() ] + for c in self.string_const_index.values() ] c_consts.sort() py_strings = [] @@ -692,7 +698,7 @@ class GlobalState(object): decls_writer.putln('static char %s[] = "%s";' % ( cname, StringEncoding.split_string_literal(c.escaped_value))) if c.py_strings is not None: - for py_string in c.py_strings.itervalues(): + for py_string in c.py_strings.values(): py_strings.append((c.cname, len(py_string.cname), py_string)) if py_strings: @@ -735,7 +741,7 @@ class GlobalState(object): def generate_int_constants(self): consts = [ (len(c.value), c.value, c.is_long, c) - for c in self.int_const_index.itervalues() ] + for c in self.int_const_index.values() ] consts.sort() decls_writer = self.parts['decls'] for _, value, longness, c in consts: diff --git a/setup.py b/setup.py index 4325a2d3..8b973782 100644 --- a/setup.py +++ b/setup.py @@ -92,6 +92,7 @@ def compile_cython_modules(profile=False, compile_more=False, cython_with_refnan "Cython.Compiler.Scanning", "Cython.Compiler.Parsing", "Cython.Compiler.Visitor", + "Cython.Compiler.Code", "Cython.Runtime.refnanny"] if compile_more: compiled_modules.extend([ -- 2.26.2