Commit 92135ccf authored by Stefan Behnel's avatar Stefan Behnel

merged in latest cython-unstable

parents f4aa0d53 cb43e5e3
...@@ -13,3 +13,7 @@ a4abf0156540db4d3ebaa95712b65811c43c5acb 0.11-beta ...@@ -13,3 +13,7 @@ a4abf0156540db4d3ebaa95712b65811c43c5acb 0.11-beta
4497f635d5fdbd38ebb841be4869fbfa2bbfdbb6 0.11.1.alpha 4497f635d5fdbd38ebb841be4869fbfa2bbfdbb6 0.11.1.alpha
7bc36a0f81723117a19f92ffde1676a0884fef65 0.11.1.beta 7bc36a0f81723117a19f92ffde1676a0884fef65 0.11.1.beta
6454db601984145f38e28d34176fca8a3a22329c 0.11.1 6454db601984145f38e28d34176fca8a3a22329c 0.11.1
af6f1bed8cd40a2edefb57d3eacbc9274a8788b4 0.11.2.rc1
15ad532e2127840ae09dfbe46ccc80ac8c562f99 0.11.2
eb00d00a73c13b6aa8b440fe07cd7acb52a060e8 0.11.3.rc0
7c695fe49fd6912f52d995fe512d66baacf90ee6 0.11.3
from Cython.Compiler.Visitor import VisitorTransform, ScopeTrackingTransform, TreeVisitor
from Nodes import StatListNode, SingleAssignmentNode, CFuncDefNode
from ExprNodes import (DictNode, DictItemNode, NameNode, UnicodeNode, NoneNode,
ExprNode, AttributeNode, ModuleRefNode, DocstringRefNode)
from PyrexTypes import py_object_type
from Builtin import dict_type
from StringEncoding import EncodedString
import Naming
class AutoTestDictTransform(ScopeTrackingTransform):
# Handles autotestdict directive
def visit_ModuleNode(self, node):
self.scope_type = 'module'
self.scope_node = node
if self.current_directives['autotestdict']:
assert isinstance(node.body, StatListNode)
# First see if __test__ is already created
if u'__test__' in node.scope.entries:
# Do nothing
return node
pos = node.pos
self.tests = []
self.testspos = node.pos
test_dict_entry = node.scope.declare_var(EncodedString(u'__test__'),
py_object_type,
pos,
visibility='public')
create_test_dict_assignment = SingleAssignmentNode(pos,
lhs=NameNode(pos, name=EncodedString(u'__test__'),
entry=test_dict_entry),
rhs=DictNode(pos, key_value_pairs=self.tests))
self.visitchildren(node)
node.body.stats.append(create_test_dict_assignment)
return node
def add_test(self, testpos, name, func_ref_node):
# func_ref_node must evaluate to the function object containing
# the docstring, BUT it should not be the function itself (which
# would lead to a new *definition* of the function)
pos = self.testspos
keystr = u'%s (line %d)' % (name, testpos[1])
key = UnicodeNode(pos, value=EncodedString(keystr))
value = DocstringRefNode(pos, func_ref_node)
self.tests.append(DictItemNode(pos, key=key, value=value))
def visit_FuncDefNode(self, node):
if node.doc:
if isinstance(node, CFuncDefNode) and not node.py_func:
# skip non-cpdef cdef functions
return node
pos = self.testspos
if self.scope_type == 'module':
parent = ModuleRefNode(pos)
name = node.entry.name
elif self.scope_type in ('pyclass', 'cclass'):
mod = ModuleRefNode(pos)
if self.scope_type == 'pyclass':
clsname = self.scope_node.name
else:
clsname = self.scope_node.class_name
parent = AttributeNode(pos, obj=mod,
attribute=clsname,
type=py_object_type,
is_py_attr=True,
is_temp=True)
name = "%s.%s" % (clsname, node.entry.name)
else:
assert False
getfunc = AttributeNode(pos, obj=parent,
attribute=node.entry.name,
type=py_object_type,
is_py_attr=True,
is_temp=True)
self.add_test(node.pos, name, getfunc)
return node
...@@ -82,7 +82,7 @@ class EmbedSignature(CythonTransform): ...@@ -82,7 +82,7 @@ class EmbedSignature(CythonTransform):
def _embed_signature(self, signature, node_doc): def _embed_signature(self, signature, node_doc):
if node_doc: if node_doc:
return signature + '\n' + node_doc return "%s\n%s" % (signature, node_doc)
else: else:
return signature return signature
......
This diff is collapsed.
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
# #
from Symtab import BuiltinScope, StructOrUnionScope from Symtab import BuiltinScope, StructOrUnionScope
from Cython.Utils import UtilityCode from Code import UtilityCode
from TypeSlots import Signature from TypeSlots import Signature
import PyrexTypes import PyrexTypes
import Naming import Naming
...@@ -50,6 +50,7 @@ builtin_function_table = [ ...@@ -50,6 +50,7 @@ builtin_function_table = [
#('round', "", "", ""), #('round', "", "", ""),
('setattr', "OOO", "r", "PyObject_SetAttr"), ('setattr', "OOO", "r", "PyObject_SetAttr"),
#('sum', "", "", ""), #('sum', "", "", ""),
('type', "O", "O", "PyObject_Type"),
#('unichr', "", "", ""), #('unichr', "", "", ""),
#('unicode', "", "", ""), #('unicode', "", "", ""),
#('vars', "", "", ""), #('vars', "", "", ""),
...@@ -159,6 +160,11 @@ bad: ...@@ -159,6 +160,11 @@ bad:
pyexec_utility_code = UtilityCode( pyexec_utility_code = UtilityCode(
proto = """ proto = """
#if PY_VERSION_HEX < 0x02040000
#ifndef Py_EVAL_H
#include "eval.h"
#endif
#endif
static PyObject* __Pyx_PyRun(PyObject*, PyObject*, PyObject*); static PyObject* __Pyx_PyRun(PyObject*, PyObject*, PyObject*);
""", """,
impl = """ impl = """
...@@ -167,40 +173,61 @@ static PyObject* __Pyx_PyRun(PyObject* o, PyObject* globals, PyObject* locals) { ...@@ -167,40 +173,61 @@ static PyObject* __Pyx_PyRun(PyObject* o, PyObject* globals, PyObject* locals) {
PyObject* s = 0; PyObject* s = 0;
char *code = 0; char *code = 0;
if (!locals && !globals) { if (!globals || globals == Py_None) {
globals = PyModule_GetDict(%s);""" % Naming.module_cname + """ globals = PyModule_GetDict(%s);""" % Naming.module_cname + """
if (!globals) if (!globals)
goto bad; goto bad;
} else if (!PyDict_Check(globals)) {
PyErr_Format(PyExc_TypeError, "exec() arg 2 must be a dict, not %.100s",
globals->ob_type->tp_name);
goto bad;
}
if (!locals || locals == Py_None) {
locals = globals; locals = globals;
} else if (!locals) {
locals = globals;
} else if (!globals) {
globals = locals;
} }
if (PyUnicode_Check(o)) {
s = PyUnicode_AsUTF8String(o); if (PyDict_GetItemString(globals, "__builtins__") == NULL) {
if (!s) goto bad; PyDict_SetItemString(globals, "__builtins__", PyEval_GetBuiltins());
o = s;
#if PY_MAJOR_VERSION >= 3
} else if (!PyBytes_Check(o)) {
#else
} else if (!PyString_Check(o)) {
#endif
/* FIXME: support file objects and code objects */
PyErr_SetString(PyExc_TypeError,
"exec currently requires a string as code input.");
goto bad;
} }
#if PY_MAJOR_VERSION >= 3 if (PyCode_Check(o)) {
code = PyBytes_AS_STRING(o); if (PyCode_GetNumFree((PyCodeObject *)o) > 0) {
#else PyErr_SetString(PyExc_TypeError,
code = PyString_AS_STRING(o); "code object passed to exec() may not contain free variables");
#endif goto bad;
result = PyRun_String(code, Py_file_input, globals, locals); }
result = PyEval_EvalCode((PyCodeObject *)o, globals, locals);
} else {
PyCompilerFlags cf;
cf.cf_flags = 0;
if (PyUnicode_Check(o)) {
cf.cf_flags = PyCF_SOURCE_IS_UTF8;
s = PyUnicode_AsUTF8String(o);
if (!s) goto bad;
o = s;
#if PY_MAJOR_VERSION >= 3
} else if (!PyBytes_Check(o)) {
#else
} else if (!PyString_Check(o)) {
#endif
PyErr_SetString(PyExc_TypeError,
"exec: arg 1 must be string, bytes or code object");
goto bad;
}
#if PY_MAJOR_VERSION >= 3
code = PyBytes_AS_STRING(o);
#else
code = PyString_AS_STRING(o);
#endif
if (PyEval_MergeCompilerFlags(&cf)) {
result = PyRun_StringFlags(code, Py_file_input, globals, locals, &cf);
} else {
result = PyRun_String(code, Py_file_input, globals, locals);
}
Py_XDECREF(s);
}
Py_XDECREF(s);
return result; return result;
bad: bad:
Py_XDECREF(s); Py_XDECREF(s);
......
...@@ -126,7 +126,7 @@ def parse_command_line(args): ...@@ -126,7 +126,7 @@ def parse_command_line(args):
options.emit_linenums = True options.emit_linenums = True
elif option in ("-X", "--directive"): elif option in ("-X", "--directive"):
try: try:
options.pragma_overrides = Options.parse_option_list(pop_arg()) options.compiler_directives = Options.parse_option_list(pop_arg())
except ValueError, e: except ValueError, e:
sys.stderr.write("Error in compiler directive: %s\n" % e.message) sys.stderr.write("Error in compiler directive: %s\n" % e.message)
sys.exit(1) sys.exit(1)
...@@ -153,5 +153,9 @@ def parse_command_line(args): ...@@ -153,5 +153,9 @@ def parse_command_line(args):
sys.exit(1) sys.exit(1)
if len(sources) == 0 and not options.show_version: if len(sources) == 0 and not options.show_version:
bad_usage() bad_usage()
if Options.embed and len(sources) > 1:
sys.stderr.write(
"cython: Only one source file allowed when using -embed\n")
sys.exit(1)
return options, sources return options, sources
This diff is collapsed.
...@@ -57,10 +57,36 @@ class ControlFlow(object): ...@@ -57,10 +57,36 @@ class ControlFlow(object):
try: try:
return self.tip[item] return self.tip[item]
except KeyError: except KeyError:
self.tip[item] = pos_state = self._get_pos_state(item, pos) pass
return pos_state pos_state = self._get_pos_state(item, pos)
else: if pos > self.end_pos:
return self._get_pos_state(item, pos) self.tip[item] = pos_state
return pos_state
def _get_pos_state(self, item, pos):
current = self
while current is not None and pos <= current.start_pos:
current = current.incoming
if current is None:
return (None, None)
state = current._get_pos_state_local(item, pos)
while state is None and current.incoming is not None:
current = current.incoming
state = current._get_pos_state_local(item, pos)
if state is None:
return (None, None)
return state
def set_state(self, pos, item, state):
if item in self.tip:
del self.tip[item]
current = self
while pos < current.start_pos and current.incoming is not None:
current = current.incoming
if item in current.tip:
del current.tip[item]
current._set_state_local(pos, item, state)
class LinearControlFlow(ControlFlow): class LinearControlFlow(ControlFlow):
...@@ -68,35 +94,22 @@ class LinearControlFlow(ControlFlow): ...@@ -68,35 +94,22 @@ class LinearControlFlow(ControlFlow):
ControlFlow.__init__(self, start_pos, incoming, parent) ControlFlow.__init__(self, start_pos, incoming, parent)
self.events = {} self.events = {}
def set_state(self, pos, item, state): def _set_state_local(self, pos, item, state):
if item in self.tip: if item in self.events:
del self.tip[item] event_list = self.events[item]
if pos < self.start_pos:
if self.incoming is not None:
self.incoming.set_state(pos, item, state)
else: else:
if item in self.events: event_list = []
event_list = self.events[item] self.events[item] = event_list
else: bisect.insort(event_list, (pos, state))
event_list = []
self.events[item] = event_list def _get_pos_state_local(self, item, pos):
bisect.insort(event_list, (pos, state)) if item in self.events:
event_list = self.events[item]
for event in event_list[::-1]:
def _get_pos_state(self, item, pos): if event[0] < pos:
if pos > self.start_pos: return event
if item in self.events: return None
event_list = self.events[item]
for event in event_list[::-1]:
if event[0] < pos:
return event
if self.incoming is not None:
return self.incoming.get_pos_state(item, pos)
else:
return None, None
def to_string(self, indent='', limit=None): def to_string(self, indent='', limit=None):
if len(self.events) == 0: if len(self.events) == 0:
...@@ -122,37 +135,35 @@ class BranchingControlFlow(ControlFlow): ...@@ -122,37 +135,35 @@ class BranchingControlFlow(ControlFlow):
self.branches = [LinearControlFlow(start_pos, incoming, parent=self)] self.branches = [LinearControlFlow(start_pos, incoming, parent=self)]
self.branch_starts = [start_pos] self.branch_starts = [start_pos]
def set_state(self, pos, item, state): def _set_state_local(self, pos, item, state):
for branch_pos, branch in zip(self.branch_starts[::-1], self.branches[::-1]):
if pos >= branch_pos:
branch._set_state_local(pos, item, state)
return
if item in self.tip: def _get_pos_state_local(self, item, pos, stop_at=None):
del self.tip[item] if pos < self.end_pos:
if pos < self.start_pos:
self.incoming.set_state(pos, item, state)
else:
for branch_pos, branch in zip(self.branch_starts[::-1], self.branches[::-1]): for branch_pos, branch in zip(self.branch_starts[::-1], self.branches[::-1]):
if pos >= branch_pos: if pos >= branch_pos:
branch.set_state(pos, item, state) return branch._get_pos_state_local(item, pos)
return
def _get_pos_state(self, item, pos):
if pos <= self.start_pos:
return self.incoming.get_pos_state(item, pos)
elif pos < self.end_pos:
for branch_pos, branch in zip(self.branch_starts[::-1], self.branches[::-1]):
if pos >= branch_pos:
return branch.get_pos_state(item, pos)
else: else:
last_pos, last_state = self.branches[0].get_pos_state(item, pos) state = self.branches[0]._get_pos_state_local(item, pos)
if state is None:
return None, None
last_pos, last_state = state
if last_state is None: if last_state is None:
return None, None return None, None
for branch in self.branches[1:]: for branch in self.branches[1:]:
other_pos, other_state = branch.get_pos_state(item, pos) state = branch._get_pos_state_local(item, pos)
if other_state is None or other_state != last_state: if state is None:
return None, None
other_pos, other_state = state
if other_state != last_state:
return None, None return None, None
elif last_pos is not other_pos: elif last_pos is not other_pos:
last_pos = max(last_pos, other_pos) last_pos = max(last_pos, other_pos)
return last_pos, last_state return last_pos, last_state
return None
def new_branch(self, pos): def new_branch(self, pos):
self.branches.append(LinearControlFlow(pos, self.incoming, parent=self)) self.branches.append(LinearControlFlow(pos, self.incoming, parent=self))
......
...@@ -10,4 +10,7 @@ debug_temp_code_comments = 0 ...@@ -10,4 +10,7 @@ debug_temp_code_comments = 0
debug_trace_code_generation = 0 debug_trace_code_generation = 0
# Do not replace exceptions with user-friendly error messages # Do not replace exceptions with user-friendly error messages
debug_no_exception_intercept = 0 debug_no_exception_intercept = 1
# Print a message each time a new stage in the pipeline is entered
debug_verbose_pipeline = 0
...@@ -21,28 +21,29 @@ def context(position): ...@@ -21,28 +21,29 @@ def context(position):
F = list(source.get_lines()) F = list(source.get_lines())
except UnicodeDecodeError: except UnicodeDecodeError:
# file has an encoding problem # file has an encoding problem
s = "[unprintable code]\n" s = u"[unprintable code]\n"
else: else:
s =''.join(F[max(0, position[1]-6):position[1]]) s = u''.join(F[max(0, position[1]-6):position[1]])
s = '...\n' + s + ' '*(position[2]-1) + '^\n' s = u'...\n%s%s^\n' % (s, u' '*(position[2]-1))
s = '-'*60 + '\n' + s + '-'*60 + '\n' s = u'%s\n%s%s\n' % (u'-'*60, s, u'-'*60)
return s return s
class CompileError(PyrexError): class CompileError(PyrexError):
def __init__(self, position = None, message = ""): def __init__(self, position = None, message = u""):
self.position = position self.position = position
self.message_only = message self.message_only = message
self.reported = False self.reported = False
# Deprecated and withdrawn in 2.6: # Deprecated and withdrawn in 2.6:
# self.message = message # self.message = message
if position: if position:
pos_str = "%s:%d:%d: " % (position[0].get_description(), position[1], position[2]) pos_str = u"%s:%d:%d: " % (position[0].get_description(), position[1], position[2])
cont = context(position) cont = context(position)
else: else:
pos_str = "" pos_str = u""
cont = '' cont = u''
Exception.__init__(self, '\nError converting Pyrex file to C:\n' + cont + '\n' + pos_str + message ) Exception.__init__(self, u'\nError converting Pyrex file to C:\n%s\n%s%s' % (
cont, pos_str, message))
class CompileWarning(PyrexWarning): class CompileWarning(PyrexWarning):
...@@ -51,9 +52,9 @@ class CompileWarning(PyrexWarning): ...@@ -51,9 +52,9 @@ class CompileWarning(PyrexWarning):
# Deprecated and withdrawn in 2.6: # Deprecated and withdrawn in 2.6:
# self.message = message # self.message = message
if position: if position:
pos_str = "%s:%d:%d: " % (position[0].get_description(), position[1], position[2]) pos_str = u"%s:%d:%d: " % (position[0].get_description(), position[1], position[2])
else: else:
pos_str = "" pos_str = u""
Exception.__init__(self, pos_str + message) Exception.__init__(self, pos_str + message)
...@@ -61,7 +62,7 @@ class InternalError(Exception): ...@@ -61,7 +62,7 @@ class InternalError(Exception):
# If this is ever raised, there is a bug in the compiler. # If this is ever raised, there is a bug in the compiler.
def __init__(self, message): def __init__(self, message):
Exception.__init__(self, "Internal compiler error: %s" Exception.__init__(self, u"Internal compiler error: %s"
% message) % message)
...@@ -73,7 +74,7 @@ class CompilerCrash(CompileError): ...@@ -73,7 +74,7 @@ class CompilerCrash(CompileError):
else: else:
message = u'\n' message = u'\n'
if context: if context:
message = "Compiler crash in " + context + message message = u"Compiler crash in %s%s" % (context, message)
if stacktrace: if stacktrace:
import traceback import traceback
message += ( message += (
...@@ -118,11 +119,15 @@ def report_error(err): ...@@ -118,11 +119,15 @@ def report_error(err):
# See Main.py for why dual reporting occurs. Quick fix for now. # See Main.py for why dual reporting occurs. Quick fix for now.
if err.reported: return if err.reported: return
err.reported = True err.reported = True
line = "%s\n" % err line = u"%s\n" % err
if listing_file: if listing_file:
listing_file.write(line) try: listing_file.write(line)
except UnicodeEncodeError:
listing_file.write(line.encode('ASCII', 'replace'))
if echo_file: if echo_file:
echo_file.write(line) try: echo_file.write(line)
except UnicodeEncodeError:
echo_file.write(line.encode('ASCII', 'replace'))
num_errors = num_errors + 1 num_errors = num_errors + 1
def error(position, message): def error(position, message):
...@@ -145,6 +150,20 @@ def warning(position, message, level=0): ...@@ -145,6 +150,20 @@ def warning(position, message, level=0):
echo_file.write(line) echo_file.write(line)
return warn return warn
_warn_once_seen = {}
def warn_once(position, message, level=0):
if level < LEVEL or message in _warn_once_seen:
return
warn = CompileWarning(position, message)
line = "warning: %s\n" % warn
if listing_file:
listing_file.write(line)
if echo_file:
echo_file.write(line)
_warn_once_seen[message] = True
return warn
# These functions can be used to momentarily suppress errors. # These functions can be used to momentarily suppress errors.
error_stack = [] error_stack = []
......
This diff is collapsed.
...@@ -24,6 +24,7 @@ from Symtab import BuiltinScope, ModuleScope ...@@ -24,6 +24,7 @@ from Symtab import BuiltinScope, ModuleScope
from Cython import Utils from Cython import Utils
from Cython.Utils import open_new_file, replace_suffix from Cython.Utils import open_new_file, replace_suffix
import CythonScope import CythonScope
import DebugFlags
module_name_pattern = re.compile(r"[A-Za-z_][A-Za-z0-9_]*(\.[A-Za-z_][A-Za-z0-9_]*)*$") module_name_pattern = re.compile(r"[A-Za-z_][A-Za-z0-9_]*(\.[A-Za-z_][A-Za-z0-9_]*)*$")
...@@ -34,6 +35,12 @@ def dumptree(t): ...@@ -34,6 +35,12 @@ def dumptree(t):
print t.dump() print t.dump()
return t return t
def abort_on_errors(node):
# Stop the pipeline if there are any errors.
if Errors.num_errors != 0:
raise InternalError, "abort"
return node
class CompilationData(object): class CompilationData(object):
# Bundles the information that is passed from transform to transform. # Bundles the information that is passed from transform to transform.
# (For now, this is only) # (For now, this is only)
...@@ -59,14 +66,14 @@ class Context(object): ...@@ -59,14 +66,14 @@ class Context(object):
# include_directories [string] # include_directories [string]
# future_directives [object] # future_directives [object]
def __init__(self, include_directories, pragma_overrides): def __init__(self, include_directories, compiler_directives):
#self.modules = {"__builtin__" : BuiltinScope()} #self.modules = {"__builtin__" : BuiltinScope()}
import Builtin, CythonScope import Builtin, CythonScope
self.modules = {"__builtin__" : Builtin.builtin_scope} self.modules = {"__builtin__" : Builtin.builtin_scope}
self.modules["cython"] = CythonScope.create_cython_scope(self) self.modules["cython"] = CythonScope.create_cython_scope(self)
self.include_directories = include_directories self.include_directories = include_directories
self.future_directives = set() self.future_directives = set()
self.pragma_overrides = pragma_overrides self.compiler_directives = compiler_directives
self.pxds = {} # full name -> node tree self.pxds = {} # full name -> node tree
...@@ -81,11 +88,12 @@ class Context(object): ...@@ -81,11 +88,12 @@ class Context(object):
from ParseTreeTransforms import CreateClosureClasses, MarkClosureVisitor, DecoratorTransform from ParseTreeTransforms import CreateClosureClasses, MarkClosureVisitor, DecoratorTransform
from ParseTreeTransforms import InterpretCompilerDirectives, TransformBuiltinMethods from ParseTreeTransforms import InterpretCompilerDirectives, TransformBuiltinMethods
from ParseTreeTransforms import AlignFunctionDefinitions, GilCheck from ParseTreeTransforms import AlignFunctionDefinitions, GilCheck
from AnalysedTreeTransforms import AutoTestDictTransform
from AutoDocTransforms import EmbedSignature from AutoDocTransforms import EmbedSignature
from Optimize import FlattenInListTransform, SwitchTransform, IterationTransform from Optimize import FlattenInListTransform, SwitchTransform, IterationTransform
from Optimize import OptimizeBuiltinCalls, ConstantFolding, FinalOptimizePhase from Optimize import OptimizeBuiltinCalls, ConstantFolding, FinalOptimizePhase
from Buffer import IntroduceBufferAuxiliaryVars from Buffer import IntroduceBufferAuxiliaryVars
from ModuleNode import check_c_declarations from ModuleNode import check_c_declarations, check_c_declarations_pxd
# Temporary hack that can be used to ensure that all result_code's # Temporary hack that can be used to ensure that all result_code's
# are generated at code generation time. # are generated at code generation time.
...@@ -97,7 +105,7 @@ class Context(object): ...@@ -97,7 +105,7 @@ class Context(object):
return node return node
if pxd: if pxd:
_check_c_declarations = None _check_c_declarations = check_c_declarations_pxd
_specific_post_parse = PxdPostParse(self) _specific_post_parse = PxdPostParse(self)
else: else:
_check_c_declarations = check_c_declarations _check_c_declarations = check_c_declarations
...@@ -112,7 +120,7 @@ class Context(object): ...@@ -112,7 +120,7 @@ class Context(object):
NormalizeTree(self), NormalizeTree(self),
PostParse(self), PostParse(self),
_specific_post_parse, _specific_post_parse,
InterpretCompilerDirectives(self, self.pragma_overrides), InterpretCompilerDirectives(self, self.compiler_directives),
_align_function_definitions, _align_function_definitions,
MarkClosureVisitor(self), MarkClosureVisitor(self),
ConstantFolding(), ConstantFolding(),
...@@ -121,6 +129,7 @@ class Context(object): ...@@ -121,6 +129,7 @@ class Context(object):
DecoratorTransform(self), DecoratorTransform(self),
AnalyseDeclarationsTransform(self), AnalyseDeclarationsTransform(self),
CreateClosureClasses(self), CreateClosureClasses(self),
AutoTestDictTransform(self),
EmbedSignature(self), EmbedSignature(self),
TransformBuiltinMethods(self), TransformBuiltinMethods(self),
IntroduceBufferAuxiliaryVars(self), IntroduceBufferAuxiliaryVars(self),
...@@ -156,10 +165,16 @@ class Context(object): ...@@ -156,10 +165,16 @@ class Context(object):
module_node.scope.utility_code_list.extend(scope.utility_code_list) module_node.scope.utility_code_list.extend(scope.utility_code_list)
return module_node return module_node
test_support = []
if options.evaluate_tree_assertions:
from Cython.TestUtils import TreeAssertVisitor
test_support.append(TreeAssertVisitor())
return ([ return ([
create_parse(self), create_parse(self),
] + self.create_pipeline(pxd=False, py=py) + [ ] + self.create_pipeline(pxd=False, py=py) + test_support + [
inject_pxd_code, inject_pxd_code,
abort_on_errors,
generate_pyx_code, generate_pyx_code,
]) ])
...@@ -192,20 +207,24 @@ class Context(object): ...@@ -192,20 +207,24 @@ class Context(object):
return Errors.report_error(exc) return Errors.report_error(exc)
def run_pipeline(self, pipeline, source): def run_pipeline(self, pipeline, source):
err = None error = None
data = source data = source
try: try:
for phase in pipeline: for phase in pipeline:
if phase is not None: if phase is not None:
if DebugFlags.debug_verbose_pipeline:
print "Entering pipeline phase %r" % phase
data = phase(data) data = phase(data)
except CompileError, err: except CompileError, err:
# err is set # err is set
Errors.report_error(err) Errors.report_error(err)
error = err
except InternalError, err: except InternalError, err:
# Only raise if there was not an earlier error # Only raise if there was not an earlier error
if Errors.num_errors == 0: if Errors.num_errors == 0:
raise raise
return (err, data) error = err
return (error, data)
def find_module(self, module_name, def find_module(self, module_name,
relative_to = None, pos = None, need_pxd = 1): relative_to = None, pos = None, need_pxd = 1):
...@@ -316,7 +335,9 @@ class Context(object): ...@@ -316,7 +335,9 @@ class Context(object):
else: else:
dirs = [self.find_root_package_dir(file_desc.filename)] + dirs dirs = [self.find_root_package_dir(file_desc.filename)] + dirs
dotted_filename = qualified_name + suffix dotted_filename = qualified_name
if suffix:
dotted_filename += suffix
if not include: if not include:
names = qualified_name.split('.') names = qualified_name.split('.')
package_names = names[:-1] package_names = names[:-1]
...@@ -524,7 +545,7 @@ def create_default_resultobj(compilation_source, options): ...@@ -524,7 +545,7 @@ def create_default_resultobj(compilation_source, options):
def run_pipeline(source, options, full_module_name = None): def run_pipeline(source, options, full_module_name = None):
# Set up context # Set up context
context = Context(options.include_path, options.pragma_overrides) context = Context(options.include_path, options.compiler_directives)
# Set up source object # Set up source object
cwd = os.getcwd() cwd = os.getcwd()
...@@ -577,7 +598,8 @@ class CompilationOptions(object): ...@@ -577,7 +598,8 @@ class CompilationOptions(object):
defaults to true when recursive is true. defaults to true when recursive is true.
verbose boolean Always print source names being compiled verbose boolean Always print source names being compiled
quiet boolean Don't print source names in recursive mode quiet boolean Don't print source names in recursive mode
pragma_overrides dict Overrides for pragma options (see Options.py) compiler_directives dict Overrides for pragma options (see Options.py)
evaluate_tree_assertions boolean Test support: evaluate parse tree assertions
Following options are experimental and only used on MacOSX: Following options are experimental and only used on MacOSX:
...@@ -765,7 +787,8 @@ default_options = dict( ...@@ -765,7 +787,8 @@ default_options = dict(
timestamps = None, timestamps = None,
verbose = 0, verbose = 0,
quiet = 0, quiet = 0,
pragma_overrides = {}, compiler_directives = {},
evaluate_tree_assertions = False,
emit_linenums = False, emit_linenums = False,
) )
if sys.platform == "mac": if sys.platform == "mac":
......
This diff is collapsed.
...@@ -47,6 +47,7 @@ convert_func_prefix = pyrex_prefix + "convert_" ...@@ -47,6 +47,7 @@ convert_func_prefix = pyrex_prefix + "convert_"
closure_scope_prefix = pyrex_prefix + "scope_" closure_scope_prefix = pyrex_prefix + "scope_"
closure_class_prefix = pyrex_prefix + "scope_struct_" closure_class_prefix = pyrex_prefix + "scope_struct_"
lambda_func_prefix = pyrex_prefix + "lambda_" lambda_func_prefix = pyrex_prefix + "lambda_"
module_is_main = pyrex_prefix + "module_is_main_"
args_cname = pyrex_prefix + "args" args_cname = pyrex_prefix + "args"
pykwdlist_cname = pyrex_prefix + "pyargnames" pykwdlist_cname = pyrex_prefix + "pyargnames"
...@@ -77,6 +78,7 @@ c_api_tab_cname = pyrex_prefix + "c_api_tab" ...@@ -77,6 +78,7 @@ c_api_tab_cname = pyrex_prefix + "c_api_tab"
gilstate_cname = pyrex_prefix + "state" gilstate_cname = pyrex_prefix + "state"
skip_dispatch_cname = pyrex_prefix + "skip_dispatch" skip_dispatch_cname = pyrex_prefix + "skip_dispatch"
empty_tuple = pyrex_prefix + "empty_tuple" empty_tuple = pyrex_prefix + "empty_tuple"
empty_bytes = pyrex_prefix + "empty_bytes"
print_function = pyrex_prefix + "print" print_function = pyrex_prefix + "print"
print_function_kwargs = pyrex_prefix + "print_kwargs" print_function_kwargs = pyrex_prefix + "print_kwargs"
cleanup_cname = pyrex_prefix + "module_cleanup" cleanup_cname = pyrex_prefix + "module_cleanup"
...@@ -84,8 +86,11 @@ pymoduledef_cname = pyrex_prefix + "moduledef" ...@@ -84,8 +86,11 @@ pymoduledef_cname = pyrex_prefix + "moduledef"
optional_args_cname = pyrex_prefix + "optional_args" optional_args_cname = pyrex_prefix + "optional_args"
import_star = pyrex_prefix + "import_star" import_star = pyrex_prefix + "import_star"
import_star_set = pyrex_prefix + "import_star_set" import_star_set = pyrex_prefix + "import_star_set"
cur_scope_cname = pyrex_prefix + "scope"
outer_scope_cname= pyrex_prefix + "outer_scope" outer_scope_cname= pyrex_prefix + "outer_scope"
cur_scope_cname = pyrex_prefix + "cur_scope"
enc_scope_cname = pyrex_prefix + "enc_scope"
frame_cname = pyrex_prefix + "frame"
frame_code_cname = pyrex_prefix + "frame_code"
line_c_macro = "__LINE__" line_c_macro = "__LINE__"
......
This diff is collapsed.
This diff is collapsed.
...@@ -54,25 +54,41 @@ c_line_in_traceback = 1 ...@@ -54,25 +54,41 @@ c_line_in_traceback = 1
embed = False embed = False
# Declare pragmas # Declare compiler directives
option_defaults = { option_defaults = {
'boundscheck' : True, 'boundscheck' : True,
'nonecheck' : False, 'nonecheck' : False,
'embedsignature' : False, 'embedsignature' : False,
'locals' : {}, 'locals' : {},
'auto_cpdef': False, 'auto_cpdef': False,
'cdivision': True, # Will be False in 0.12 'cdivision': False, # was True before 0.12
'cdivision_warnings': False, 'cdivision_warnings': False,
'always_allow_keywords': False, 'always_allow_keywords': False,
'wraparound' : True,
'c99_complex' : False, # Don't use macro wrappers for complex arith, not sure what to name this...
'callspec' : "",
'profile': False,
'autotestdict': True,
# test support
'test_assert_path_exists' : [],
'test_fail_if_path_exists' : [],
} }
# Override types possibilities above, if needed # Override types possibilities above, if needed
option_types = { } option_types = {}
for key, val in option_defaults.items(): for key, val in option_defaults.items():
if key not in option_types: if key not in option_types:
option_types[key] = type(val) option_types[key] = type(val)
option_scopes = { # defaults to available everywhere
# 'module', 'function', 'class', 'with statement'
'autotestdict' : ('module',),
'test_assert_path_exists' : ('function',),
'test_fail_if_path_exists' : ('function',),
}
def parse_option_value(name, value): def parse_option_value(name, value):
""" """
Parses value as an option value for the given name and returns Parses value as an option value for the given name and returns
...@@ -94,6 +110,11 @@ def parse_option_value(name, value): ...@@ -94,6 +110,11 @@ def parse_option_value(name, value):
if value == "True": return True if value == "True": return True
elif value == "False": return False elif value == "False": return False
else: raise ValueError("%s directive must be set to True or False" % name) else: raise ValueError("%s directive must be set to True or False" % name)
elif type is int:
try:
return int(value)
except ValueError:
raise ValueError("%s directive must be set to an integer" % name)
else: else:
assert False assert False
......
This diff is collapsed.
...@@ -145,7 +145,7 @@ cpdef p_decorators(PyrexScanner s) ...@@ -145,7 +145,7 @@ cpdef p_decorators(PyrexScanner s)
cpdef p_def_statement(PyrexScanner s, list decorators = *) cpdef p_def_statement(PyrexScanner s, list decorators = *)
cpdef p_varargslist(PyrexScanner s, terminator=*) cpdef p_varargslist(PyrexScanner s, terminator=*)
cpdef p_py_arg_decl(PyrexScanner s) cpdef p_py_arg_decl(PyrexScanner s)
cpdef p_class_statement(PyrexScanner s) cpdef p_class_statement(PyrexScanner s, decorators)
cpdef p_c_class_definition(PyrexScanner s, pos, ctx) cpdef p_c_class_definition(PyrexScanner s, pos, ctx)
cpdef p_c_class_options(PyrexScanner s) cpdef p_c_class_options(PyrexScanner s)
cpdef p_property_decl(PyrexScanner s) cpdef p_property_decl(PyrexScanner s)
......
This diff is collapsed.
This diff is collapsed.
...@@ -65,7 +65,7 @@ def hash_source_file(path): ...@@ -65,7 +65,7 @@ def hash_source_file(path):
# tabs by a single space. # tabs by a single space.
import re import re
text = re.sub("[ \t]+", " ", text) text = re.sub("[ \t]+", " ", text)
hash = new_md5(text).hexdigest() hash = new_md5(text.encode("ASCII")).hexdigest()
return hash return hash
def open_pickled_lexicon(expected_hash): def open_pickled_lexicon(expected_hash):
...@@ -214,14 +214,18 @@ def initial_compile_time_env(): ...@@ -214,14 +214,18 @@ def initial_compile_time_env():
'UNAME_VERSION', 'UNAME_MACHINE') 'UNAME_VERSION', 'UNAME_MACHINE')
for name, value in zip(names, platform.uname()): for name, value in zip(names, platform.uname()):
benv.declare(name, value) benv.declare(name, value)
import __builtin__ import __builtin__ as builtins
names = ('False', 'True', names = ('False', 'True',
'abs', 'bool', 'chr', 'cmp', 'complex', 'dict', 'divmod', 'enumerate', 'abs', 'bool', 'chr', 'cmp', 'complex', 'dict', 'divmod', 'enumerate',
'float', 'hash', 'hex', 'int', 'len', 'list', 'long', 'map', 'max', 'min', 'float', 'hash', 'hex', 'int', 'len', 'list', 'long', 'map', 'max', 'min',
'oct', 'ord', 'pow', 'range', 'reduce', 'repr', 'round', 'slice', 'str', 'oct', 'ord', 'pow', 'range', 'reduce', 'repr', 'round', 'slice', 'str',
'sum', 'tuple', 'xrange', 'zip') 'sum', 'tuple', 'xrange', 'zip')
for name in names: for name in names:
benv.declare(name, getattr(__builtin__, name)) try:
benv.declare(name, getattr(builtins, name))
except AttributeError:
# ignore, likely Py3
pass
denv = CompileTimeScope(benv) denv = CompileTimeScope(benv)
return denv return denv
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
# #
import re import re
from cStringIO import StringIO from StringIO import StringIO
from Scanning import PyrexScanner, StringSourceDescriptor from Scanning import PyrexScanner, StringSourceDescriptor
from Symtab import BuiltinScope, ModuleScope from Symtab import BuiltinScope, ModuleScope
import Symtab import Symtab
...@@ -54,7 +54,7 @@ def parse_from_strings(name, code, pxds={}, level=None, initial_pos=None): ...@@ -54,7 +54,7 @@ def parse_from_strings(name, code, pxds={}, level=None, initial_pos=None):
context = StringParseContext([], name) context = StringParseContext([], name)
scope = context.find_module(module_name, pos = initial_pos, need_pxd = 0) scope = context.find_module(module_name, pos = initial_pos, need_pxd = 0)
buf = StringIO(code.encode(encoding)) buf = StringIO(code)
scanner = PyrexScanner(buf, code_source, source_encoding = encoding, scanner = PyrexScanner(buf, code_source, source_encoding = encoding,
scope = scope, context = context, initial_pos = initial_pos) scope = scope, context = context, initial_pos = initial_pos)
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
version = '0.11.1' version = '0.11.3'
...@@ -5,9 +5,9 @@ cdef class BasicVisitor: ...@@ -5,9 +5,9 @@ cdef class BasicVisitor:
cdef class TreeVisitor(BasicVisitor): cdef class TreeVisitor(BasicVisitor):
cdef public list access_path cdef public list access_path
cpdef visitchild(self, child, parent, attrname, idx) cpdef visitchild(self, child, parent, attrname, idx)
# cpdef visitchildren(self, parent, attrs=*)
cdef class VisitorTransform(TreeVisitor): cdef class VisitorTransform(TreeVisitor):
cdef object _super_visitchildren
cpdef visitchildren(self, parent, attrs=*) cpdef visitchildren(self, parent, attrs=*)
cpdef recurse_to_children(self, node) cpdef recurse_to_children(self, node)
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
...@@ -28,5 +28,5 @@ cdef extern from *: ...@@ -28,5 +28,5 @@ cdef extern from *:
# 0xC (release candidate) # 0xC (release candidate)
# 0xF (final) # 0xF (final)
char[] PY_VERSION char PY_VERSION[]
char[] PY_PATCHLEVEL_REVISION char PY_PATCHLEVEL_REVISION[]
This diff is collapsed.
...@@ -5,7 +5,7 @@ PYTHON := /Local/Build/Pythonic/python/2.3 ...@@ -5,7 +5,7 @@ PYTHON := /Local/Build/Pythonic/python/2.3
INCLUDE := -I$(PYTHON) -I$(PYTHON)/Include -I$(PYTHON)/Mac/Include INCLUDE := -I$(PYTHON) -I$(PYTHON)/Include -I$(PYTHON)/Mac/Include
CCOPTS := -fno-strict-aliasing -Wno-long-double -no-cpp-precomp \ CCOPTS := -fno-strict-aliasing -no-cpp-precomp \
-mno-fused-madd -fno-common -dynamic -mno-fused-madd -fno-common -dynamic
LDOPTS := -Wl,-F.,-w -bundle -framework Python -framework Carbon LDOPTS := -Wl,-F.,-w -bundle -framework Python -framework Carbon
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
ctypedef public class Time [type MyTime_Type, object MyTimeObject]:
cdef public double seconds
ctypedef public class Event [type MyEvent_Type, object MyEventObject]:
cdef public Time time
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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