from Cython.Compiler.TreeFragment import TreeFragment
from Cython.Utils import EncodedString
from Cython.Compiler.Errors import CompileError
+import Interpreter
import PyrexTypes
- from sets import Set as set
+
+ try:
+ set
+ except NameError:
+ from sets import Set as set
+
import textwrap
+
+# Code cleanup ideas:
+# - One could be more smart about casting in some places
+# - Start using CCodeWriters to generate utility functions
+# - Create a struct type per ndim rather than keeping loose local vars
+
+
def dedent(text, reindent=0):
text = textwrap.dedent(text)
if reindent > 0:
are searched from)
-D, --no-docstrings Remove docstrings.
- -a, --annotate Produce an colorized version of the source.
+ -a, --annotate Produce a colorized HTML version of the source.
--convert-range Convert for loops using range() function to for...from loops.
--cplus Output a c++ rather than c file.
+ -O, --option <name>=<value>[,<name=value,...] Overrides an optimization/code generation option
"""
#The following experimental options are supported only on MacOSX:
# -C, --compile Compile generated .c file to .o file
from TypeSlots import method_coexist
from Scanning import SourceDescriptor
from Cython.StringIOTree import StringIOTree
- from sets import Set as set
+ try:
+ set
+ except NameError:
+ from sets import Set as set
-class FunctionContext(object):
+class FunctionState(object):
+ # return_label string function return point label
+ # error_label string error catch point label
+ # continue_label string loop continue point label
+ # break_label string loop break point label
+ # return_from_error_cleanup_label string
+ # label_counter integer counter for naming labels
+ # in_try_finally boolean inside try of try...finally
+ # exc_vars (string * 3) exception variables for reraise, or None
+
# Not used for now, perhaps later
def __init__(self, names_taken=set()):
self.names_taken = names_taken
self.write("/* %s */\n" % self.marker[1])
self.last_marker_line = self.marker[0]
self.marker = None
+ return self
+ def put_safe(self, code):
+ # put code, but ignore {}
+ self.write(code)
+ self.bol = 0
+
def put(self, code):
+ fix_indent = False
dl = code.count("{") - code.count("}")
if dl < 0:
self.level += dl
self.bol = 0
if dl > 0:
self.level += dl
- elif dl == 0 and code.startswith('}'):
+ elif fix_indent:
self.level += 1
+ return self
def increase_indent(self):
self.level = self.level + 1
two_hex = hexdigit + hexdigit
four_hex = two_hex + two_hex
escapeseq = Str("\\") + (two_oct | three_oct | two_hex |
- Str('u') + four_hex | Str('x') + two_hex | AnyChar)
+ Str('u') + four_hex | Str('x') + two_hex |
+ Str('U') + four_hex + four_hex | AnyChar)
+
deco = Str("@")
bra = Any("([{")
ket = Any(")]}")
else:
c_suffix = ".c"
result.c_file = Utils.replace_suffix(source_desc.filename, c_suffix)
- # The below doesn't make any sense? Why is it there?
- c_stat = None
- if result.c_file:
- try:
- c_stat = os.stat(result.c_file)
- except EnvironmentError:
- pass
return result
-def run_pipeline(source, context, options, full_module_name = None):
+def run_pipeline(source, options, full_module_name = None):
+ # Set up context
+ context = Context(options.include_path, options.pragma_overrides)
+
# Set up source object
cwd = os.getcwd()
source_desc = FileSourceDescriptor(os.path.join(cwd, source))
Always compiles a single file; does not perform timestamp checking or
recursion.
"""
- context = Context(options.include_path)
- return run_pipeline(source, context, options, full_module_name)
-# context = Context(options.include_path)
-# return context.compile(source, options, full_module_name)
+ return run_pipeline(source, options, full_module_name)
- # context = Context(options.include_path)
- # return context.compile(source, options, full_module_name)
def compile_multiple(sources, options):
if verbose:
sys.stderr.write("Compiling %s\n" % source)
- result = context.compile(source, options)
- # Compiling multiple sources in one context doesn't quite
- # work properly yet.
- result = run_pipeline(source, context, options)
++ result = run_pipeline(source, options)
results.add(source, result)
processed.add(source)
if recursive:
from Cython.Compiler.TreeFragment import TreeFragment
from Cython.Utils import EncodedString
from Cython.Compiler.Errors import CompileError
- from sets import Set as set
+ try:
+ set
+ except NameError:
+ from sets import Set as set
+import copy
class NormalizeTree(CythonTransform):
"""
>>> d.write('alpha\n')
>>> b.write('gamma\n')
>>> c.write('beta\n')
- >>> print b.getvalue()
- second
- alpha
- beta
- gamma
- <BLANKLINE>
-
+ >>> b.getvalue().split()
+ ['second', 'alpha', 'beta', 'gamma']
-
+>>> i = StringIOTree()
+>>> d.insert(i)
+>>> i.write('inserted\n')
>>> out = StringIO()
>>> a.copyto(out)
- >>> print out.getvalue()
- first
- second
- alpha
- inserted
- beta
- gamma
- third
- <BLANKLINE>
- """
-
- if __name__ == "__main__":
- import doctest
- doctest.testmod()
+ >>> out.getvalue().split()
-['first', 'second', 'alpha', 'beta', 'gamma', 'third']
-"""
-
-if __name__ == "__main__":
- import doctest
- doctest.testmod()
++['first', 'second', 'alpha', 'inserted', 'beta', 'gamma', 'third']
++"""