Commit 3ee07211 authored by Robert Bradshaw's avatar Robert Bradshaw

merge

parents f7b4f6fe a7bd92e2
...@@ -210,7 +210,7 @@ class CCodeWriter: ...@@ -210,7 +210,7 @@ class CCodeWriter:
storage_class = "static" storage_class = "static"
if storage_class: if storage_class:
self.put("%s " % storage_class) self.put("%s " % storage_class)
if visibility <> 'public': if visibility != 'public':
dll_linkage = None dll_linkage = None
self.put(entry.type.declaration_code(entry.cname, self.put(entry.type.declaration_code(entry.cname,
dll_linkage = dll_linkage)) dll_linkage = dll_linkage))
......
...@@ -311,7 +311,7 @@ class ExprNode(Node): ...@@ -311,7 +311,7 @@ class ExprNode(Node):
def allocate_target_temps(self, env, rhs): def allocate_target_temps(self, env, rhs):
# Perform temp allocation for the LHS of an assignment. # Perform temp allocation for the LHS of an assignment.
if debug_temp_alloc: if debug_temp_alloc:
print self, "Allocating target temps" print("%s Allocating target temps" % self)
self.allocate_subexpr_temps(env) self.allocate_subexpr_temps(env)
self.result_code = self.target_code() self.result_code = self.target_code()
if rhs: if rhs:
...@@ -325,7 +325,7 @@ class ExprNode(Node): ...@@ -325,7 +325,7 @@ class ExprNode(Node):
# is used as the result instead of allocating a new # is used as the result instead of allocating a new
# one. # one.
if debug_temp_alloc: if debug_temp_alloc:
print self, "Allocating temps" print("%s Allocating temps" % self)
self.allocate_subexpr_temps(env) self.allocate_subexpr_temps(env)
self.allocate_temp(env, result) self.allocate_temp(env, result)
if self.is_temp: if self.is_temp:
...@@ -335,11 +335,11 @@ class ExprNode(Node): ...@@ -335,11 +335,11 @@ class ExprNode(Node):
# Allocate temporary variables for all sub-expressions # Allocate temporary variables for all sub-expressions
# of this node. # of this node.
if debug_temp_alloc: if debug_temp_alloc:
print self, "Allocating temps for:", self.subexprs print("%s Allocating temps for: %s" % (self, self.subexprs))
for node in self.subexpr_nodes(): for node in self.subexpr_nodes():
if node: if node:
if debug_temp_alloc: if debug_temp_alloc:
print self, "Allocating temps for", node print("%s Allocating temps for %s" % (self, node))
node.allocate_temps(env) node.allocate_temps(env)
def allocate_temp(self, env, result = None): def allocate_temp(self, env, result = None):
...@@ -350,7 +350,7 @@ class ExprNode(Node): ...@@ -350,7 +350,7 @@ class ExprNode(Node):
# is used as the result instead of allocating a new # is used as the result instead of allocating a new
# one. # one.
if debug_temp_alloc: if debug_temp_alloc:
print self, "Allocating temp" print("%s Allocating temp" % self)
if result: if result:
if not self.is_temp: if not self.is_temp:
raise InternalError("Result forced on non-temp node") raise InternalError("Result forced on non-temp node")
...@@ -364,7 +364,7 @@ class ExprNode(Node): ...@@ -364,7 +364,7 @@ class ExprNode(Node):
else: else:
self.result_code = None self.result_code = None
if debug_temp_alloc: if debug_temp_alloc:
print self, "Allocated result", self.result_code print("%s Allocated result %s" % (self, self.result_code))
else: else:
self.result_code = self.calculate_result_code() self.result_code = self.calculate_result_code()
...@@ -384,7 +384,7 @@ class ExprNode(Node): ...@@ -384,7 +384,7 @@ class ExprNode(Node):
# otherwise release results of its sub-expressions. # otherwise release results of its sub-expressions.
if self.is_temp: if self.is_temp:
if debug_temp_alloc: if debug_temp_alloc:
print self, "Releasing result", self.result_code print("%s Releasing result %s" % (self, self.result_code))
env.release_temp(self.result_code) env.release_temp(self.result_code)
else: else:
self.release_subexpr_temps(env) self.release_subexpr_temps(env)
...@@ -489,7 +489,7 @@ class ExprNode(Node): ...@@ -489,7 +489,7 @@ class ExprNode(Node):
src = CoerceFromPyTypeNode(dst_type, src, env) src = CoerceFromPyTypeNode(dst_type, src, env)
else: # neither src nor dst are py types else: # neither src nor dst are py types
# Added the string comparison, since for c types that # Added the string comparison, since for c types that
# is enough, but SageX gets confused when the types are # is enough, but Cython gets confused when the types are
# in different files. # in different files.
if not (str(src.type) == str(dst_type) or dst_type.assignable_from(src_type)): if not (str(src.type) == str(dst_type) or dst_type.assignable_from(src_type)):
error(self.pos, "Cannot assign type '%s' to '%s'" % error(self.pos, "Cannot assign type '%s' to '%s'" %
...@@ -588,7 +588,7 @@ class BoolNode(PyConstNode): ...@@ -588,7 +588,7 @@ class BoolNode(PyConstNode):
def coerce_to(self, dst_type, env): def coerce_to(self, dst_type, env):
value = self.value value = self.value
if dst_type.is_numeric: if dst_type.is_numeric:
return IntNode(self.pos, value=self.value).coerce_to(dst_type, env) return IntNode(self.pos, value=int(self.value)).coerce_to(dst_type, env)
else: else:
return PyConstNode.coerce_to(self, dst_type, env) return PyConstNode.coerce_to(self, dst_type, env)
...@@ -977,8 +977,8 @@ class NameNode(AtomicExprNode): ...@@ -977,8 +977,8 @@ class NameNode(AtomicExprNode):
entry.name, entry.name,
rhs.py_result())) rhs.py_result()))
if debug_disposal_code: if debug_disposal_code:
print "NameNode.generate_assignment_code:" print("NameNode.generate_assignment_code:")
print "...generating disposal code for", rhs print("...generating disposal code for %s" % rhs)
rhs.generate_disposal_code(code) rhs.generate_disposal_code(code)
else: else:
...@@ -991,8 +991,8 @@ class NameNode(AtomicExprNode): ...@@ -991,8 +991,8 @@ class NameNode(AtomicExprNode):
code.put_decref(self.result_code, self.ctype()) code.put_decref(self.result_code, self.ctype())
code.putln('%s = %s;' % (self.result_code, rhs.result_as(self.ctype()))) code.putln('%s = %s;' % (self.result_code, rhs.result_as(self.ctype())))
if debug_disposal_code: if debug_disposal_code:
print "NameNode.generate_assignment_code:" print("NameNode.generate_assignment_code:")
print "...generating post-assignment code for", rhs print("...generating post-assignment code for %s" % rhs)
rhs.generate_post_assignment_code(code) rhs.generate_post_assignment_code(code)
def generate_deletion_code(self, code): def generate_deletion_code(self, code):
...@@ -2139,8 +2139,8 @@ class SequenceNode(ExprNode): ...@@ -2139,8 +2139,8 @@ class SequenceNode(ExprNode):
rhs.generate_disposal_code(code) rhs.generate_disposal_code(code)
for i in range(len(self.args)): for i in range(len(self.args)):
item = self.unpacked_items[i] item = self.unpacked_items[i]
unpack_code = "__Pyx_UnpackItem(%s)" % ( unpack_code = "__Pyx_UnpackItem(%s, %d)" % (
self.iterator.py_result()) self.iterator.py_result(), i)
code.putln( code.putln(
"%s = %s; %s" % ( "%s = %s; %s" % (
item.result_code, item.result_code,
...@@ -2153,8 +2153,8 @@ class SequenceNode(ExprNode): ...@@ -2153,8 +2153,8 @@ class SequenceNode(ExprNode):
"__Pyx_EndUnpack(%s)" % ( "__Pyx_EndUnpack(%s)" % (
self.iterator.py_result())) self.iterator.py_result()))
if debug_disposal_code: if debug_disposal_code:
print "UnpackNode.generate_assignment_code:" print("UnpackNode.generate_assignment_code:")
print "...generating disposal code for", iterator print("...generating disposal code for %s" % iterator)
self.iterator.generate_disposal_code(code) self.iterator.generate_disposal_code(code)
code.putln("}") code.putln("}")
...@@ -2261,7 +2261,7 @@ class ListComprehensionNode(SequenceNode): ...@@ -2261,7 +2261,7 @@ class ListComprehensionNode(SequenceNode):
def allocate_temps(self, env, result = None): def allocate_temps(self, env, result = None):
if debug_temp_alloc: if debug_temp_alloc:
print self, "Allocating temps" print("%s Allocating temps" % self)
self.allocate_temp(env, result) self.allocate_temp(env, result)
self.loop.analyse_declarations(env) self.loop.analyse_declarations(env)
self.loop.analyse_expressions(env) self.loop.analyse_expressions(env)
...@@ -3578,7 +3578,7 @@ class CoercionNode(ExprNode): ...@@ -3578,7 +3578,7 @@ class CoercionNode(ExprNode):
self.pos = arg.pos self.pos = arg.pos
self.arg = arg self.arg = arg
if debug_coercion: if debug_coercion:
print self, "Coercing", self.arg print("%s Coercing %s" % (self, self.arg))
def annotate(self, code): def annotate(self, code):
self.arg.annotate(code) self.arg.annotate(code)
...@@ -3906,18 +3906,20 @@ bad: ...@@ -3906,18 +3906,20 @@ bad:
unpacking_utility_code = [ unpacking_utility_code = [
""" """
static PyObject *__Pyx_UnpackItem(PyObject *); /*proto*/ static PyObject *__Pyx_UnpackItem(PyObject *, Py_ssize_t index); /*proto*/
static int __Pyx_EndUnpack(PyObject *); /*proto*/ static int __Pyx_EndUnpack(PyObject *); /*proto*/
""",""" ""","""
static void __Pyx_UnpackError(void) { static PyObject *__Pyx_UnpackItem(PyObject *iter, Py_ssize_t index) {
PyErr_SetString(PyExc_ValueError, "unpack sequence of wrong size");
}
static PyObject *__Pyx_UnpackItem(PyObject *iter) {
PyObject *item; PyObject *item;
if (!(item = PyIter_Next(iter))) { if (!(item = PyIter_Next(iter))) {
if (!PyErr_Occurred()) if (!PyErr_Occurred()) {
__Pyx_UnpackError(); PyErr_Format(PyExc_ValueError,
#if PY_VERSION_HEX < 0x02050000
"need more than %d values to unpack", (int)index);
#else
"need more than %zd values to unpack", index);
#endif
}
} }
return item; return item;
} }
...@@ -3926,7 +3928,7 @@ static int __Pyx_EndUnpack(PyObject *iter) { ...@@ -3926,7 +3928,7 @@ static int __Pyx_EndUnpack(PyObject *iter) {
PyObject *item; PyObject *item;
if ((item = PyIter_Next(iter))) { if ((item = PyIter_Next(iter))) {
Py_DECREF(item); Py_DECREF(item);
__Pyx_UnpackError(); PyErr_SetString(PyExc_ValueError, "too many values to unpack");
return -1; return -1;
} }
else if (!PyErr_Occurred()) else if (!PyErr_Occurred())
......
...@@ -61,7 +61,9 @@ def make_lexicon(): ...@@ -61,7 +61,9 @@ def make_lexicon():
two_oct = octdigit + octdigit two_oct = octdigit + octdigit
three_oct = octdigit + octdigit + octdigit three_oct = octdigit + octdigit + octdigit
two_hex = hexdigit + hexdigit two_hex = hexdigit + hexdigit
escapeseq = Str("\\") + (two_oct | three_oct | two_hex | AnyChar) four_hex = two_hex + two_hex
escapeseq = Str("\\") + (two_oct | three_oct | two_hex |
Str('u') + four_hex | Str('x') + two_hex | AnyChar)
bra = Any("([{") bra = Any("([{")
ket = Any(")]}") ket = Any(")]}")
......
...@@ -48,13 +48,13 @@ class Context: ...@@ -48,13 +48,13 @@ class Context:
# that module, provided its name is not a dotted name. # that module, provided its name is not a dotted name.
debug_find_module = 0 debug_find_module = 0
if debug_find_module: if debug_find_module:
print "Context.find_module: module_name =", module_name, \ print("Context.find_module: module_name = %s, relative_to = %s, pos = %s, need_pxd = %s" % (
"relative_to =", relative_to, "pos =", pos, "need_pxd =", need_pxd module_name, relative_to, pos, need_pxd))
scope = None scope = None
pxd_pathname = None pxd_pathname = None
if "." not in module_name and relative_to: if "." not in module_name and relative_to:
if debug_find_module: if debug_find_module:
print "...trying relative import" print("...trying relative import")
scope = relative_to.lookup_submodule(module_name) scope = relative_to.lookup_submodule(module_name)
if not scope: if not scope:
qualified_name = relative_to.qualify_name(module_name) qualified_name = relative_to.qualify_name(module_name)
...@@ -63,28 +63,28 @@ class Context: ...@@ -63,28 +63,28 @@ class Context:
scope = relative_to.find_submodule(module_name) scope = relative_to.find_submodule(module_name)
if not scope: if not scope:
if debug_find_module: if debug_find_module:
print "...trying absolute import" print("...trying absolute import")
scope = self scope = self
for name in module_name.split("."): for name in module_name.split("."):
scope = scope.find_submodule(name) scope = scope.find_submodule(name)
if debug_find_module: if debug_find_module:
print "...scope =", scope print("...scope =", scope)
if not scope.pxd_file_loaded: if not scope.pxd_file_loaded:
if debug_find_module: if debug_find_module:
print "...pxd not loaded" print("...pxd not loaded")
scope.pxd_file_loaded = 1 scope.pxd_file_loaded = 1
if not pxd_pathname: if not pxd_pathname:
if debug_find_module: if debug_find_module:
print "...looking for pxd file" print("...looking for pxd file")
pxd_pathname = self.find_pxd_file(module_name, pos) pxd_pathname = self.find_pxd_file(module_name, pos)
if debug_find_module: if debug_find_module:
print "......found ", pxd_pathname print("......found ", pxd_pathname)
if not pxd_pathname and need_pxd: if not pxd_pathname and need_pxd:
error(pos, "'%s.pxd' not found" % module_name) error(pos, "'%s.pxd' not found" % module_name)
if pxd_pathname: if pxd_pathname:
try: try:
if debug_find_module: if debug_find_module:
print "Context.find_module: Parsing", pxd_pathname print("Context.find_module: Parsing %s" % pxd_pathname)
pxd_tree = self.parse(pxd_pathname, scope.type_names, pxd = 1, pxd_tree = self.parse(pxd_pathname, scope.type_names, pxd = 1,
full_module_name = module_name) full_module_name = module_name)
pxd_tree.analyse_declarations(scope) pxd_tree.analyse_declarations(scope)
......
...@@ -562,7 +562,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): ...@@ -562,7 +562,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
for entry in env.c_class_entries: for entry in env.c_class_entries:
#print "generate_typeobj_definitions:", entry.name #print "generate_typeobj_definitions:", entry.name
#print "...visibility =", entry.visibility #print "...visibility =", entry.visibility
if entry.visibility <> 'extern': if entry.visibility != 'extern':
type = entry.type type = entry.type
scope = type.scope scope = type.scope
if scope: # could be None if there was an error if scope: # could be None if there was an error
...@@ -681,7 +681,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): ...@@ -681,7 +681,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
% scope.mangle_internal("tp_dealloc")) % scope.mangle_internal("tp_dealloc"))
py_attrs = [] py_attrs = []
for entry in scope.var_entries: for entry in scope.var_entries:
if entry.type.is_pyobject and entry.name <> "__weakref__": if entry.type.is_pyobject and entry.name != "__weakref__":
py_attrs.append(entry) py_attrs.append(entry)
if py_attrs or scope.lookup_here("__weakref__"): if py_attrs or scope.lookup_here("__weakref__"):
self.generate_self_cast(scope, code) self.generate_self_cast(scope, code)
...@@ -1520,7 +1520,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): ...@@ -1520,7 +1520,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
def generate_base_type_import_code(self, env, entry, code): def generate_base_type_import_code(self, env, entry, code):
base_type = entry.type.base_type base_type = entry.type.base_type
if base_type and base_type.module_name <> env.qualified_name: if base_type and base_type.module_name != env.qualified_name:
self.generate_type_import_code(env, base_type, self.pos, code) self.generate_type_import_code(env, base_type, self.pos, code)
def use_type_import_utility_code(self, env): def use_type_import_utility_code(self, env):
...@@ -1569,7 +1569,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): ...@@ -1569,7 +1569,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
typeobj_cname = type.typeobj_cname typeobj_cname = type.typeobj_cname
scope = type.scope scope = type.scope
if scope: # could be None if there was an error if scope: # could be None if there was an error
if entry.visibility <> 'extern': if entry.visibility != 'extern':
for slot in TypeSlots.slot_table: for slot in TypeSlots.slot_table:
slot.generate_dynamic_init_code(scope, code) slot.generate_dynamic_init_code(scope, code)
code.putln( code.putln(
......
...@@ -943,7 +943,7 @@ class CFuncDefNode(FuncDefNode): ...@@ -943,7 +943,7 @@ class CFuncDefNode(FuncDefNode):
dll_linkage = None dll_linkage = None
header = self.return_type.declaration_code(entity, header = self.return_type.declaration_code(entity,
dll_linkage = dll_linkage) dll_linkage = dll_linkage)
if visibility <> 'private': if visibility != 'private':
storage_class = "%s " % Naming.extern_c_macro storage_class = "%s " % Naming.extern_c_macro
else: else:
storage_class = "static " storage_class = "static "
...@@ -1094,6 +1094,8 @@ class DefNode(FuncDefNode): ...@@ -1094,6 +1094,8 @@ class DefNode(FuncDefNode):
if self.signature_has_generic_args(): if self.signature_has_generic_args():
if self.star_arg: if self.star_arg:
env.use_utility_code(get_stararg_utility_code) env.use_utility_code(get_stararg_utility_code)
elif self.signature_has_generic_args():
env.use_utility_code(raise_argtuple_too_long_utility_code)
if not self.signature_has_nongeneric_args(): if not self.signature_has_nongeneric_args():
env.use_utility_code(get_keyword_string_check_utility_code) env.use_utility_code(get_keyword_string_check_utility_code)
elif self.starstar_arg: elif self.starstar_arg:
...@@ -1566,9 +1568,8 @@ class DefNode(FuncDefNode): ...@@ -1566,9 +1568,8 @@ class DefNode(FuncDefNode):
def generate_positional_args_check(self, code, nargs): def generate_positional_args_check(self, code, nargs):
code.putln("if (unlikely(PyTuple_GET_SIZE(%s) > %d)) {" % ( code.putln("if (unlikely(PyTuple_GET_SIZE(%s) > %d)) {" % (
Naming.args_cname, nargs)) Naming.args_cname, nargs))
error_message = "function takes at most %d positional arguments (%d given)" code.putln("__Pyx_RaiseArgtupleTooLong(%d, PyTuple_GET_SIZE(%s));" % (
code.putln("PyErr_Format(PyExc_TypeError, \"%s\", %d, PyTuple_GET_SIZE(%s));" % ( nargs, Naming.args_cname))
error_message, nargs, Naming.args_cname))
code.putln("return %s;" % self.error_value()) code.putln("return %s;" % self.error_value())
code.putln("}") code.putln("}")
...@@ -3147,7 +3148,7 @@ class TryFinallyStatNode(StatNode): ...@@ -3147,7 +3148,7 @@ class TryFinallyStatNode(StatNode):
"__pyx_why = 0; goto %s;" % catch_label) "__pyx_why = 0; goto %s;" % catch_label)
for i in cases_used: for i in cases_used:
new_label = new_labels[i] new_label = new_labels[i]
#if new_label and new_label <> "<try>": #if new_label and new_label != "<try>":
if new_label == new_error_label and self.preserve_exception: if new_label == new_error_label and self.preserve_exception:
self.put_error_catcher(code, self.put_error_catcher(code,
new_error_label, i+1, catch_label) new_error_label, i+1, catch_label)
...@@ -3550,6 +3551,7 @@ static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb) { ...@@ -3550,6 +3551,7 @@ static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb) {
Py_INCREF(type); Py_INCREF(type);
} }
else { else {
type = 0;
PyErr_SetString(PyExc_TypeError, PyErr_SetString(PyExc_TypeError,
"raise: exception must be an old-style class or instance"); "raise: exception must be an old-style class or instance");
goto raise_error; goto raise_error;
...@@ -3646,6 +3648,30 @@ static INLINE int __Pyx_SplitStarArg( ...@@ -3646,6 +3648,30 @@ static INLINE int __Pyx_SplitStarArg(
} }
"""] """]
#------------------------------------------------------------------------------------
#
# __Pyx_RaiseArgtupleTooLong raises the correct exception when too
# many positional arguments were found. This handles Py_ssize_t
# formatting correctly.
raise_argtuple_too_long_utility_code = [
"""
static INLINE void __Pyx_RaiseArgtupleTooLong(Py_ssize_t num_expected, Py_ssize_t num_found); /*proto*/
""","""
static INLINE void __Pyx_RaiseArgtupleTooLong(
Py_ssize_t num_expected,
Py_ssize_t num_found)
{
const char* error_message =
#if PY_VERSION_HEX < 0x02050000
"function takes at most %d positional arguments (%d given)";
#else
"function takes at most %zd positional arguments (%zd given)";
#endif
PyErr_Format(PyExc_TypeError, error_message, num_expected, num_found);
}
"""]
#------------------------------------------------------------------------------------ #------------------------------------------------------------------------------------
# #
# __Pyx_CheckKeywordStrings raises an error if non-string keywords # __Pyx_CheckKeywordStrings raises an error if non-string keywords
......
...@@ -24,7 +24,7 @@ def p_ident_list(s): ...@@ -24,7 +24,7 @@ def p_ident_list(s):
while s.sy == 'IDENT': while s.sy == 'IDENT':
names.append(s.systring) names.append(s.systring)
s.next() s.next()
if s.sy <> ',': if s.sy != ',':
break break
s.next() s.next()
return names return names
...@@ -290,7 +290,7 @@ def p_call(s, function): ...@@ -290,7 +290,7 @@ def p_call(s, function):
s.error("Non-keyword arg following keyword arg", s.error("Non-keyword arg following keyword arg",
pos = arg.pos) pos = arg.pos)
positional_args.append(arg) positional_args.append(arg)
if s.sy <> ',': if s.sy != ',':
break break
s.next() s.next()
if s.sy == '*': if s.sy == '*':
...@@ -376,11 +376,11 @@ def p_subscript(s): ...@@ -376,11 +376,11 @@ def p_subscript(s):
return [ExprNodes.EllipsisNode(pos)] return [ExprNodes.EllipsisNode(pos)]
else: else:
start = p_slice_element(s, (':',)) start = p_slice_element(s, (':',))
if s.sy <> ':': if s.sy != ':':
return [start] return [start]
s.next() s.next()
stop = p_slice_element(s, (':', ',', ']')) stop = p_slice_element(s, (':', ',', ']'))
if s.sy <> ':': if s.sy != ':':
return [start, stop] return [start, stop]
s.next() s.next()
step = p_slice_element(s, (':', ',', ']')) step = p_slice_element(s, (':', ',', ']'))
...@@ -469,9 +469,9 @@ def p_atom(s): ...@@ -469,9 +469,9 @@ def p_atom(s):
if name == "None": if name == "None":
return ExprNodes.NoneNode(pos) return ExprNodes.NoneNode(pos)
elif name == "True": elif name == "True":
return ExprNodes.BoolNode(pos, value=1) return ExprNodes.BoolNode(pos, value=True)
elif name == "False": elif name == "False":
return ExprNodes.BoolNode(pos, value=0) return ExprNodes.BoolNode(pos, value=False)
else: else:
return p_name(s, name) return p_name(s, name)
elif sy == 'NULL': elif sy == 'NULL':
...@@ -489,7 +489,9 @@ def p_name(s, name): ...@@ -489,7 +489,9 @@ def p_name(s, name):
pass pass
else: else:
rep = repr(value) rep = repr(value)
if isinstance(value, int): if isinstance(value, bool):
return ExprNodes.BoolNode(pos, value = value)
elif isinstance(value, int):
return ExprNodes.IntNode(pos, value = rep) return ExprNodes.IntNode(pos, value = rep)
elif isinstance(value, long): elif isinstance(value, long):
return ExprNodes.LongNode(pos, value = rep) return ExprNodes.LongNode(pos, value = rep)
...@@ -506,7 +508,7 @@ def p_cat_string_literal(s): ...@@ -506,7 +508,7 @@ def p_cat_string_literal(s):
# A sequence of one or more adjacent string literals. # A sequence of one or more adjacent string literals.
# Returns (kind, value) where kind in ('', 'c', 'r') # Returns (kind, value) where kind in ('', 'c', 'r')
kind, value = p_string_literal(s) kind, value = p_string_literal(s)
if kind <> 'c': if kind != 'c':
strings = [value] strings = [value]
while s.sy == 'STRING' or s.sy == 'BEGIN_STRING': while s.sy == 'STRING' or s.sy == 'BEGIN_STRING':
next_kind, next_value = p_string_literal(s) next_kind, next_value = p_string_literal(s)
...@@ -563,12 +565,19 @@ def p_string_literal(s): ...@@ -563,12 +565,19 @@ def p_string_literal(s):
c = systr[1] c = systr[1]
if c in "'\"\\abfnrtv01234567": if c in "'\"\\abfnrtv01234567":
chars.append(systr) chars.append(systr)
elif c == 'x':
chars.append('\\x0' + systr[2:])
elif c == '\n': elif c == '\n':
pass pass
elif c == 'u': elif c in 'ux':
chars.append(systr) if kind == 'u':
try:
chars.append(systr.decode('unicode_escape'))
except UnicodeDecodeError:
s.error("Invalid unicode escape '%s'" % systr,
pos = pos)
elif c == 'x':
chars.append('\\x0' + systr[2:])
else:
chars.append(systr)
else: else:
chars.append(r'\\' + systr[1:]) chars.append(r'\\' + systr[1:])
elif sy == 'NEWLINE': elif sy == 'NEWLINE':
...@@ -582,10 +591,7 @@ def p_string_literal(s): ...@@ -582,10 +591,7 @@ def p_string_literal(s):
"Unexpected token %r:%r in string literal" % "Unexpected token %r:%r in string literal" %
(sy, s.systring)) (sy, s.systring))
s.next() s.next()
if kind == 'u': value = ''.join(chars)
value = u''.join(chars)
else:
value = ''.join(chars)
#print "p_string_literal: value =", repr(value) ### #print "p_string_literal: value =", repr(value) ###
return kind, value return kind, value
...@@ -606,7 +612,7 @@ def unquote(s): ...@@ -606,7 +612,7 @@ def unquote(s):
# Split into double quotes, newlines, escape sequences # Split into double quotes, newlines, escape sequences
# and spans of regular chars # and spans of regular chars
l1 = re.split(r'((?:\\[0-7]{1,3})|(?:\\x[0-9A-Fa-f]{2})|(?:\\.)|(?:\\\n)|(?:\n)|")', s) l1 = re.split(r'((?:\\[0-7]{1,3})|(?:\\x[0-9A-Fa-f]{2})|(?:\\.)|(?:\\\n)|(?:\n)|")', s)
print "unquote: l1 =", l1 ### #print "unquote: l1 =", l1 ###
l2 = [] l2 = []
for item in l1: for item in l1:
if item == '"' or item == '\n': if item == '"' or item == '\n':
...@@ -695,12 +701,12 @@ def p_dict_maker(s): ...@@ -695,12 +701,12 @@ def p_dict_maker(s):
pos = s.position() pos = s.position()
s.next() s.next()
items = [] items = []
while s.sy <> '}': while s.sy != '}':
key = p_simple_expr(s) key = p_simple_expr(s)
s.expect(':') s.expect(':')
value = p_simple_expr(s) value = p_simple_expr(s)
items.append((key, value)) items.append((key, value))
if s.sy <> ',': if s.sy != ',':
break break
s.next() s.next()
s.expect('}') s.expect('}')
...@@ -718,7 +724,7 @@ def p_simple_expr_list(s): ...@@ -718,7 +724,7 @@ def p_simple_expr_list(s):
exprs = [] exprs = []
while s.sy not in expr_terminators: while s.sy not in expr_terminators:
exprs.append(p_simple_expr(s)) exprs.append(p_simple_expr(s))
if s.sy <> ',': if s.sy != ',':
break break
s.next() s.next()
return exprs return exprs
...@@ -830,7 +836,7 @@ def find_parallel_assignment_size(input): ...@@ -830,7 +836,7 @@ def find_parallel_assignment_size(input):
rhs_size = len(rhs.args) rhs_size = len(rhs.args)
for lhs in input[:-1]: for lhs in input[:-1]:
lhs_size = len(lhs.args) lhs_size = len(lhs.args)
if lhs_size <> rhs_size: if lhs_size != rhs_size:
error(lhs.pos, "Unpacking sequence of wrong size (expected %d, got %d)" error(lhs.pos, "Unpacking sequence of wrong size (expected %d, got %d)"
% (lhs_size, rhs_size)) % (lhs_size, rhs_size))
return -1 return -1
...@@ -1092,10 +1098,10 @@ def p_for_bounds(s): ...@@ -1092,10 +1098,10 @@ def p_for_bounds(s):
if not target.is_name: if not target.is_name:
error(target.pos, error(target.pos,
"Target of for-from statement must be a variable name") "Target of for-from statement must be a variable name")
elif name2 <> target.name: elif name2 != target.name:
error(name2_pos, error(name2_pos,
"Variable name in for-from range does not match target") "Variable name in for-from range does not match target")
if rel1[0] <> rel2[0]: if rel1[0] != rel2[0]:
error(rel2_pos, error(rel2_pos,
"Relation directions in for-from do not match") "Relation directions in for-from do not match")
return {'target': target, return {'target': target,
...@@ -1129,9 +1135,9 @@ def p_for_target(s): ...@@ -1129,9 +1135,9 @@ def p_for_target(s):
if s.sy == ',': if s.sy == ',':
s.next() s.next()
exprs = [expr] exprs = [expr]
while s.sy <> 'in': while s.sy != 'in':
exprs.append(p_bit_expr(s)) exprs.append(p_bit_expr(s))
if s.sy <> ',': if s.sy != ',':
break break
s.next() s.next()
return ExprNodes.TupleNode(pos, args = exprs) return ExprNodes.TupleNode(pos, args = exprs)
...@@ -1173,7 +1179,7 @@ def p_except_clause(s): ...@@ -1173,7 +1179,7 @@ def p_except_clause(s):
s.next() s.next()
exc_type = None exc_type = None
exc_value = None exc_value = None
if s.sy <> ':': if s.sy != ':':
exc_type = p_simple_expr(s) exc_type = p_simple_expr(s)
if s.sy == ',': if s.sy == ',':
s.next() s.next()
...@@ -1293,7 +1299,7 @@ def p_IF_statement(s, level, cdef_flag, visibility, api): ...@@ -1293,7 +1299,7 @@ def p_IF_statement(s, level, cdef_flag, visibility, api):
if s.compile_time_eval: if s.compile_time_eval:
result = body result = body
current_eval = 0 current_eval = 0
if s.sy <> 'ELIF': if s.sy != 'ELIF':
break break
if s.sy == 'ELSE': if s.sy == 'ELSE':
s.next() s.next()
...@@ -1344,7 +1350,7 @@ def p_statement(s, level, cdef_flag = 0, visibility = 'private', api = 0): ...@@ -1344,7 +1350,7 @@ def p_statement(s, level, cdef_flag = 0, visibility = 'private', api = 0):
s.level = level s.level = level
return p_def_statement(s) return p_def_statement(s)
elif s.sy == 'class': elif s.sy == 'class':
if level <> 'module': if level != 'module':
s.error("class definition not allowed here") s.error("class definition not allowed here")
return p_class_statement(s) return p_class_statement(s)
elif s.sy == 'include': elif s.sy == 'include':
...@@ -1353,7 +1359,7 @@ def p_statement(s, level, cdef_flag = 0, visibility = 'private', api = 0): ...@@ -1353,7 +1359,7 @@ def p_statement(s, level, cdef_flag = 0, visibility = 'private', api = 0):
return p_include_statement(s, level) return p_include_statement(s, level)
elif level == 'c_class' and s.sy == 'IDENT' and s.systring == 'property': elif level == 'c_class' and s.sy == 'IDENT' and s.systring == 'property':
return p_property_decl(s) return p_property_decl(s)
elif s.sy == 'pass' and level <> 'property': elif s.sy == 'pass' and level != 'property':
return p_pass_statement(s, with_newline = 1) return p_pass_statement(s, with_newline = 1)
else: else:
if level in ('c_class_pxd', 'property'): if level in ('c_class_pxd', 'property'):
...@@ -1539,7 +1545,7 @@ def p_c_declarator(s, empty = 0, is_type = 0, cmethod_flag = 0, assignable = 0, ...@@ -1539,7 +1545,7 @@ def p_c_declarator(s, empty = 0, is_type = 0, cmethod_flag = 0, assignable = 0,
s.expect(')') s.expect(')')
else: else:
result = p_c_simple_declarator(s, empty, is_type, cmethod_flag, assignable, nonempty) result = p_c_simple_declarator(s, empty, is_type, cmethod_flag, assignable, nonempty)
if not calling_convention_allowed and result.calling_convention and s.sy <> '(': if not calling_convention_allowed and result.calling_convention and s.sy != '(':
error(s.position(), "%s on something that is not a function" error(s.position(), "%s on something that is not a function"
% result.calling_convention) % result.calling_convention)
while s.sy in ('[', '('): while s.sy in ('[', '('):
...@@ -1555,7 +1561,7 @@ def p_c_declarator(s, empty = 0, is_type = 0, cmethod_flag = 0, assignable = 0, ...@@ -1555,7 +1561,7 @@ def p_c_declarator(s, empty = 0, is_type = 0, cmethod_flag = 0, assignable = 0,
def p_c_array_declarator(s, base): def p_c_array_declarator(s, base):
pos = s.position() pos = s.position()
s.next() # '[' s.next() # '['
if s.sy <> ']': if s.sy != ']':
dim = p_expr(s) dim = p_expr(s)
else: else:
dim = None dim = None
...@@ -1789,7 +1795,7 @@ def p_c_enum_definition(s, pos, level, visibility, typedef_flag = 0): ...@@ -1789,7 +1795,7 @@ def p_c_enum_definition(s, pos, level, visibility, typedef_flag = 0):
items = None items = None
s.expect(':') s.expect(':')
items = [] items = []
if s.sy <> 'NEWLINE': if s.sy != 'NEWLINE':
p_c_enum_line(s, items) p_c_enum_line(s, items)
else: else:
s.next() # 'NEWLINE' s.next() # 'NEWLINE'
...@@ -1802,7 +1808,7 @@ def p_c_enum_definition(s, pos, level, visibility, typedef_flag = 0): ...@@ -1802,7 +1808,7 @@ def p_c_enum_definition(s, pos, level, visibility, typedef_flag = 0):
in_pxd = level == 'module_pxd') in_pxd = level == 'module_pxd')
def p_c_enum_line(s, items): def p_c_enum_line(s, items):
if s.sy <> 'pass': if s.sy != 'pass':
p_c_enum_item(s, items) p_c_enum_item(s, items)
while s.sy == ',': while s.sy == ',':
s.next() s.next()
...@@ -1837,8 +1843,8 @@ def p_c_struct_or_union_definition(s, pos, level, visibility, typedef_flag = 0): ...@@ -1837,8 +1843,8 @@ def p_c_struct_or_union_definition(s, pos, level, visibility, typedef_flag = 0):
s.expect('NEWLINE') s.expect('NEWLINE')
s.expect_indent() s.expect_indent()
attributes = [] attributes = []
while s.sy <> 'DEDENT': while s.sy != 'DEDENT':
if s.sy <> 'pass': if s.sy != 'pass':
attributes.append( attributes.append(
p_c_func_or_var_declaration(s, level = 'other', pos = s.position())) p_c_func_or_var_declaration(s, level = 'other', pos = s.position()))
else: else:
...@@ -1857,7 +1863,7 @@ def p_visibility(s, prev_visibility): ...@@ -1857,7 +1863,7 @@ def p_visibility(s, prev_visibility):
visibility = prev_visibility visibility = prev_visibility
if s.sy == 'IDENT' and s.systring in ('extern', 'public', 'readonly'): if s.sy == 'IDENT' and s.systring in ('extern', 'public', 'readonly'):
visibility = s.systring visibility = s.systring
if prev_visibility <> 'private' and visibility <> prev_visibility: if prev_visibility != 'private' and visibility != prev_visibility:
s.error("Conflicting visibility options '%s' and '%s'" s.error("Conflicting visibility options '%s' and '%s'"
% (prev_visibility, visibility)) % (prev_visibility, visibility))
s.next() s.next()
...@@ -1995,7 +2001,7 @@ def p_c_class_definition(s, level, pos, ...@@ -1995,7 +2001,7 @@ def p_c_class_definition(s, level, pos,
s.next() s.next()
module_path.append(class_name) module_path.append(class_name)
class_name = p_ident(s) class_name = p_ident(s)
if module_path and visibility <> 'extern': if module_path and visibility != 'extern':
error(pos, "Qualified class name only allowed for 'extern' C class") error(pos, "Qualified class name only allowed for 'extern' C class")
if module_path and s.sy == 'IDENT' and s.systring == 'as': if module_path and s.sy == 'IDENT' and s.systring == 'as':
s.next() s.next()
...@@ -2067,7 +2073,7 @@ def p_c_class_options(s): ...@@ -2067,7 +2073,7 @@ def p_c_class_options(s):
typeobj_name = None typeobj_name = None
s.expect('[') s.expect('[')
while 1: while 1:
if s.sy <> 'IDENT': if s.sy != 'IDENT':
break break
if s.systring == 'object': if s.systring == 'object':
s.next() s.next()
...@@ -2075,7 +2081,7 @@ def p_c_class_options(s): ...@@ -2075,7 +2081,7 @@ def p_c_class_options(s):
elif s.systring == 'type': elif s.systring == 'type':
s.next() s.next()
typeobj_name = p_ident(s) typeobj_name = p_ident(s)
if s.sy <> ',': if s.sy != ',':
break break
s.next() s.next()
s.expect(']', "Expected 'object' or 'type'") s.expect(']', "Expected 'object' or 'type'")
...@@ -2091,7 +2097,7 @@ def p_property_decl(s): ...@@ -2091,7 +2097,7 @@ def p_property_decl(s):
def p_doc_string(s): def p_doc_string(s):
if s.sy == 'STRING' or s.sy == 'BEGIN_STRING': if s.sy == 'STRING' or s.sy == 'BEGIN_STRING':
_, result = p_cat_string_literal(s) _, result = p_cat_string_literal(s)
if s.sy <> 'EOF': if s.sy != 'EOF':
s.expect_newline("Syntax error in doc string") s.expect_newline("Syntax error in doc string")
return result return result
else: else:
...@@ -2106,7 +2112,7 @@ def p_module(s, pxd, full_module_name): ...@@ -2106,7 +2112,7 @@ def p_module(s, pxd, full_module_name):
else: else:
level = 'module' level = 'module'
body = p_statement_list(s, level) body = p_statement_list(s, level)
if s.sy <> 'EOF': if s.sy != 'EOF':
s.error("Syntax error in statement [%s,%s]" % ( s.error("Syntax error in statement [%s,%s]" % (
repr(s.sy), repr(s.systring))) repr(s.sy), repr(s.systring)))
return ModuleNode(pos, doc = doc, body = body, full_module_name = full_module_name) return ModuleNode(pos, doc = doc, body = body, full_module_name = full_module_name)
...@@ -2138,7 +2144,7 @@ def print_parse_tree(f, node, level, key = None): ...@@ -2138,7 +2144,7 @@ def print_parse_tree(f, node, level, key = None):
tag = node.__class__.__name__ tag = node.__class__.__name__
f.write("%s @ %s\n" % (tag, node.pos)) f.write("%s @ %s\n" % (tag, node.pos))
for name, value in node.__dict__.items(): for name, value in node.__dict__.items():
if name <> 'tag' and name <> 'pos': if name != 'tag' and name != 'pos':
print_parse_tree(f, value, level+1, name) print_parse_tree(f, value, level+1, name)
return return
elif t == ListType: elif t == ListType:
......
...@@ -630,7 +630,7 @@ class CFuncType(CType): ...@@ -630,7 +630,7 @@ class CFuncType(CType):
if not self.is_overridable and other_type.is_overridable: if not self.is_overridable and other_type.is_overridable:
return 0 return 0
nargs = len(self.args) nargs = len(self.args)
if nargs <> len(other_type.args): if nargs != len(other_type.args):
return 0 return 0
# When comparing C method signatures, the first argument # When comparing C method signatures, the first argument
# is exempt from compatibility checking (the proper check # is exempt from compatibility checking (the proper check
...@@ -639,9 +639,9 @@ class CFuncType(CType): ...@@ -639,9 +639,9 @@ class CFuncType(CType):
if not self.args[i].type.same_as( if not self.args[i].type.same_as(
other_type.args[i].type): other_type.args[i].type):
return 0 return 0
if self.has_varargs <> other_type.has_varargs: if self.has_varargs != other_type.has_varargs:
return 0 return 0
if self.optional_arg_count <> other_type.optional_arg_count: if self.optional_arg_count != other_type.optional_arg_count:
return 0 return 0
if not self.return_type.same_as(other_type.return_type): if not self.return_type.same_as(other_type.return_type):
return 0 return 0
...@@ -695,7 +695,7 @@ class CFuncType(CType): ...@@ -695,7 +695,7 @@ class CFuncType(CType):
if not other_type.is_cfunction: if not other_type.is_cfunction:
return 0 return 0
nargs = len(self.args) nargs = len(self.args)
if nargs <> len(other_type.args): if nargs != len(other_type.args):
return 0 return 0
for i in range(as_cmethod, nargs): for i in range(as_cmethod, nargs):
if not self.args[i].type.subtype_of_resolved_type(other_type.args[i].type): if not self.args[i].type.subtype_of_resolved_type(other_type.args[i].type):
...@@ -703,9 +703,9 @@ class CFuncType(CType): ...@@ -703,9 +703,9 @@ class CFuncType(CType):
else: else:
self.args[i].needs_type_test = other_type.args[i].needs_type_test \ self.args[i].needs_type_test = other_type.args[i].needs_type_test \
or not self.args[i].type.same_as(other_type.args[i].type) or not self.args[i].type.same_as(other_type.args[i].type)
if self.has_varargs <> other_type.has_varargs: if self.has_varargs != other_type.has_varargs:
return 0 return 0
if self.optional_arg_count <> other_type.optional_arg_count: if self.optional_arg_count != other_type.optional_arg_count:
return 0 return 0
if not self.return_type.subtype_of_resolved_type(other_type.return_type): if not self.return_type.subtype_of_resolved_type(other_type.return_type):
return 0 return 0
......
...@@ -42,7 +42,7 @@ def hash_source_file(path): ...@@ -42,7 +42,7 @@ def hash_source_file(path):
f = open(path, "rU") f = open(path, "rU")
text = f.read() text = f.read()
except IOError, e: except IOError, e:
print "Unable to hash scanner source file (%s)" % e print("Unable to hash scanner source file (%s)" % e)
return "" return ""
finally: finally:
f.close() f.close()
...@@ -69,12 +69,12 @@ def open_pickled_lexicon(expected_hash): ...@@ -69,12 +69,12 @@ def open_pickled_lexicon(expected_hash):
result = f result = f
f = None f = None
else: else:
print "Lexicon hash mismatch:" ### print("Lexicon hash mismatch:") ###
print " expected", expected_hash ### print(" expected " + expected_hash) ###
print " got ", actual_hash ### print(" got " + actual_hash) ###
except IOError, e: except IOError, e:
print "Warning: Unable to read pickled lexicon", lexicon_pickle print("Warning: Unable to read pickled lexicon " + lexicon_pickle)
print e print(e)
if f: if f:
f.close() f.close()
return result return result
...@@ -89,37 +89,37 @@ def try_to_unpickle_lexicon(): ...@@ -89,37 +89,37 @@ def try_to_unpickle_lexicon():
if f: if f:
if notify_lexicon_unpickling: if notify_lexicon_unpickling:
t0 = time() t0 = time()
print "Unpickling lexicon..." print("Unpickling lexicon...")
lexicon = pickle.load(f) lexicon = pickle.load(f)
f.close() f.close()
if notify_lexicon_unpickling: if notify_lexicon_unpickling:
t1 = time() t1 = time()
print "Done (%.2f seconds)" % (t1 - t0) print("Done (%.2f seconds)" % (t1 - t0))
def create_new_lexicon(): def create_new_lexicon():
global lexicon global lexicon
t0 = time() t0 = time()
print "Creating lexicon..." print("Creating lexicon...")
lexicon = make_lexicon() lexicon = make_lexicon()
t1 = time() t1 = time()
print "Done (%.2f seconds)" % (t1 - t0) print("Done (%.2f seconds)" % (t1 - t0))
def pickle_lexicon(): def pickle_lexicon():
f = None f = None
try: try:
f = open(lexicon_pickle, "wb") f = open(lexicon_pickle, "wb")
except IOError: except IOError:
print "Warning: Unable to save pickled lexicon in", lexicon_pickle print("Warning: Unable to save pickled lexicon in " + lexicon_pickle)
if f: if f:
if notify_lexicon_pickling: if notify_lexicon_pickling:
t0 = time() t0 = time()
print "Pickling lexicon..." print("Pickling lexicon...")
pickle.dump(lexicon_hash, f, binary_lexicon_pickle) pickle.dump(lexicon_hash, f, binary_lexicon_pickle)
pickle.dump(lexicon, f, binary_lexicon_pickle) pickle.dump(lexicon, f, binary_lexicon_pickle)
f.close() f.close()
if notify_lexicon_pickling: if notify_lexicon_pickling:
t1 = time() t1 = time()
print "Done (%.2f seconds)" % (t1 - t0) print("Done (%.2f seconds)" % (t1 - t0))
def get_lexicon(): def get_lexicon():
global lexicon global lexicon
...@@ -284,9 +284,9 @@ class PyrexScanner(Scanner): ...@@ -284,9 +284,9 @@ class PyrexScanner(Scanner):
self.indentation_char = c self.indentation_char = c
#print "Scanner.indentation_action: setting indent_char to", repr(c) #print "Scanner.indentation_action: setting indent_char to", repr(c)
else: else:
if self.indentation_char <> c: if self.indentation_char != c:
self.error("Mixed use of tabs and spaces") self.error("Mixed use of tabs and spaces")
if text.replace(c, "") <> "": if text.replace(c, "") != "":
self.error("Mixed use of tabs and spaces") self.error("Mixed use of tabs and spaces")
# Figure out how many indents/dedents to do # Figure out how many indents/dedents to do
current_level = self.current_level() current_level = self.current_level()
...@@ -304,7 +304,7 @@ class PyrexScanner(Scanner): ...@@ -304,7 +304,7 @@ class PyrexScanner(Scanner):
self.indentation_stack.pop() self.indentation_stack.pop()
self.produce('DEDENT', '') self.produce('DEDENT', '')
#print "...current level now", self.current_level() ### #print "...current level now", self.current_level() ###
if new_level <> self.current_level(): if new_level != self.current_level():
self.error("Inconsistent indentation") self.error("Inconsistent indentation")
def eof_action(self, text): def eof_action(self, text):
...@@ -328,7 +328,7 @@ class PyrexScanner(Scanner): ...@@ -328,7 +328,7 @@ class PyrexScanner(Scanner):
t = self.sy t = self.sy
else: else:
t = "%s %s" % (self.sy, self.systring) t = "%s %s" % (self.sy, self.systring)
print "--- %3d %2d %s" % (line, col, t) print("--- %3d %2d %s" % (line, col, t))
def put_back(self, sy, systring): def put_back(self, sy, systring):
self.unread(self.sy, self.systring) self.unread(self.sy, self.systring)
...@@ -380,5 +380,5 @@ class PyrexScanner(Scanner): ...@@ -380,5 +380,5 @@ class PyrexScanner(Scanner):
def expect_newline(self, message = "Expected a newline"): def expect_newline(self, message = "Expected a newline"):
# Expect either a newline or end of file # Expect either a newline or end of file
if self.sy <> 'EOF': if self.sy != 'EOF':
self.expect('NEWLINE', message) self.expect('NEWLINE', message)
...@@ -304,12 +304,12 @@ class Scope: ...@@ -304,12 +304,12 @@ class Scope:
return entry return entry
def check_previous_typedef_flag(self, entry, typedef_flag, pos): def check_previous_typedef_flag(self, entry, typedef_flag, pos):
if typedef_flag <> entry.type.typedef_flag: if typedef_flag != entry.type.typedef_flag:
error(pos, "'%s' previously declared using '%s'" % ( error(pos, "'%s' previously declared using '%s'" % (
entry.name, ("cdef", "ctypedef")[entry.type.typedef_flag])) entry.name, ("cdef", "ctypedef")[entry.type.typedef_flag]))
def check_previous_visibility(self, entry, visibility, pos): def check_previous_visibility(self, entry, visibility, pos):
if entry.visibility <> visibility: if entry.visibility != visibility:
error(pos, "'%s' previously declared as '%s'" % ( error(pos, "'%s' previously declared as '%s'" % (
entry.name, entry.visibility)) entry.name, entry.visibility))
...@@ -334,7 +334,7 @@ class Scope: ...@@ -334,7 +334,7 @@ class Scope:
cname = None, visibility = 'private', is_cdef = 0): cname = None, visibility = 'private', is_cdef = 0):
# Add an entry for a variable. # Add an entry for a variable.
if not cname: if not cname:
if visibility <> 'private': if visibility != 'private':
cname = name cname = name
else: else:
cname = self.mangle(Naming.var_prefix, name) cname = self.mangle(Naming.var_prefix, name)
...@@ -361,24 +361,24 @@ class Scope: ...@@ -361,24 +361,24 @@ class Scope:
# Add an entry for a C function. # Add an entry for a C function.
entry = self.lookup_here(name) entry = self.lookup_here(name)
if entry: if entry:
if visibility <> 'private' and visibility <> entry.visibility: if visibility != 'private' and visibility != entry.visibility:
warning(pos, "Function '%s' previously declared as '%s'" % (name, entry.visibility), 1) warning(pos, "Function '%s' previously declared as '%s'" % (name, entry.visibility), 1)
if not entry.type.same_as(type): if not entry.type.same_as(type):
warning(pos, "Function signature does not match previous declaration", 1) warning(pos, "Function signature does not match previous declaration", 1)
entry.type = type entry.type = type
else: else:
if not cname: if not cname:
if api or visibility <> 'private': if api or visibility != 'private':
cname = name cname = name
else: else:
cname = self.mangle(Naming.func_prefix, name) cname = self.mangle(Naming.func_prefix, name)
entry = self.add_cfunction(name, type, pos, cname, visibility) entry = self.add_cfunction(name, type, pos, cname, visibility)
entry.func_cname = cname entry.func_cname = cname
if in_pxd and visibility <> 'extern': if in_pxd and visibility != 'extern':
entry.defined_in_pxd = 1 entry.defined_in_pxd = 1
if api: if api:
entry.api = 1 entry.api = 1
if not defining and not in_pxd and visibility <> 'extern': if not defining and not in_pxd and visibility != 'extern':
error(pos, "Non-extern C function declared but not defined") error(pos, "Non-extern C function declared but not defined")
return entry return entry
...@@ -442,7 +442,7 @@ class Scope: ...@@ -442,7 +442,7 @@ class Scope:
# Python identifier, it will be interned. # Python identifier, it will be interned.
if not entry.pystring_cname: if not entry.pystring_cname:
value = entry.init value = entry.init
if identifier_pattern.match(value): if identifier_pattern.match(value) and isinstance(value, str):
entry.pystring_cname = self.intern(value) entry.pystring_cname = self.intern(value)
entry.is_interned = 1 entry.is_interned = 1
else: else:
...@@ -577,12 +577,6 @@ class BuiltinScope(Scope): ...@@ -577,12 +577,6 @@ class BuiltinScope(Scope):
else: else:
Scope.__init__(self, "__builtin__", PreImportScope(), None) Scope.__init__(self, "__builtin__", PreImportScope(), None)
for name, definition in self.builtin_functions.iteritems():
if len(definition) < 4: definition.append(None) # exception_value
if len(definition) < 5: definition.append(False) # exception_check
cname, type, arg_types, exception_value, exception_check = definition
function = CFuncType(type, [CFuncTypeArg("", t, None) for t in arg_types], False, exception_value, exception_check)
self.add_cfunction(name, function, None, cname, False)
for name, definition in self.builtin_entries.iteritems(): for name, definition in self.builtin_entries.iteritems():
cname, type = definition cname, type = definition
self.declare_var(name, type, None, cname) self.declare_var(name, type, None, cname)
...@@ -612,30 +606,13 @@ class BuiltinScope(Scope): ...@@ -612,30 +606,13 @@ class BuiltinScope(Scope):
def builtin_scope(self): def builtin_scope(self):
return self return self
# TODO: merge this into builtin_function_table when error handling in Pyrex
# is fixed. Also handle pyrex types as functions.
builtin_functions = {
"cmp": ["PyObject_Compare", c_int_type, (py_object_type, py_object_type), None, True],
"unicode": ["PyObject_Unicode", py_object_type, (py_object_type, ), 0],
"type": ["PyObject_Type", py_object_type, (py_object_type, ), 0],
# "str": ["PyObject_Str", py_object_type, (py_object_type, ), 0],
# "int": ["PyNumber_Int", py_object_type, (py_object_type, ), 0],
# "long": ["PyNumber_Long", py_object_type, (py_object_type, ), 0],
# "float": ["PyNumber_Float", py_object_type, (py_object_type, ), 0],
# "list": ["PyNumber_List", py_object_type, (py_object_type, ), 0],
# "tuple": ["PySequence_Tuple", py_object_type, (py_object_type, ), 0],
}
builtin_entries = { builtin_entries = {
"int": ["((PyObject*)&PyInt_Type)", py_object_type], "int": ["((PyObject*)&PyInt_Type)", py_object_type],
"long": ["((PyObject*)&PyLong_Type)", py_object_type], "long": ["((PyObject*)&PyLong_Type)", py_object_type],
"float": ["((PyObject*)&PyFloat_Type)", py_object_type], "float": ["((PyObject*)&PyFloat_Type)", py_object_type],
"str": ["((PyObject*)&PyString_Type)", py_object_type], "str": ["((PyObject*)&PyString_Type)", py_object_type],
"unicode":["((PyObject*)&PyUnicode_Type)", py_object_type],
"tuple": ["((PyObject*)&PyTuple_Type)", py_object_type], "tuple": ["((PyObject*)&PyTuple_Type)", py_object_type],
"list": ["((PyObject*)&PyList_Type)", py_object_type], "list": ["((PyObject*)&PyList_Type)", py_object_type],
"dict": ["((PyObject*)&PyDict_Type)", py_object_type], "dict": ["((PyObject*)&PyDict_Type)", py_object_type],
...@@ -672,6 +649,7 @@ class ModuleScope(Scope): ...@@ -672,6 +649,7 @@ class ModuleScope(Scope):
# cimported_modules [ModuleScope] Modules imported with cimport # cimported_modules [ModuleScope] Modules imported with cimport
# intern_map {string : string} Mapping from Python names to interned strs # intern_map {string : string} Mapping from Python names to interned strs
# interned_names [string] Interned names pending generation of declarations # interned_names [string] Interned names pending generation of declarations
# interned_nums [int/long] Interned numeric constants
# all_pystring_entries [Entry] Python string consts from all scopes # all_pystring_entries [Entry] Python string consts from all scopes
# types_imported {PyrexType : 1} Set of types for which import code generated # types_imported {PyrexType : 1} Set of types for which import code generated
...@@ -871,7 +849,7 @@ class ModuleScope(Scope): ...@@ -871,7 +849,7 @@ class ModuleScope(Scope):
entry = None # Will cause an error when we redeclare it entry = None # Will cause an error when we redeclare it
else: else:
self.check_previous_typedef_flag(entry, typedef_flag, pos) self.check_previous_typedef_flag(entry, typedef_flag, pos)
if base_type <> type.base_type: if base_type != type.base_type:
error(pos, "Base type does not match previous declaration") error(pos, "Base type does not match previous declaration")
# #
# Make a new entry if needed # Make a new entry if needed
...@@ -920,17 +898,17 @@ class ModuleScope(Scope): ...@@ -920,17 +898,17 @@ class ModuleScope(Scope):
entry.defined_in_pxd = 1 entry.defined_in_pxd = 1
if implementing: # So that filenames in runtime exceptions refer to if implementing: # So that filenames in runtime exceptions refer to
entry.pos = pos # the .pyx file and not the .pxd file entry.pos = pos # the .pyx file and not the .pxd file
if visibility <> 'private' and entry.visibility <> visibility: if visibility != 'private' and entry.visibility != visibility:
error(pos, "Class '%s' previously declared as '%s'" error(pos, "Class '%s' previously declared as '%s'"
% (name, entry.visibility)) % (name, entry.visibility))
if api: if api:
entry.api = 1 entry.api = 1
if objstruct_cname: if objstruct_cname:
if type.objstruct_cname and type.objstruct_cname <> objstruct_cname: if type.objstruct_cname and type.objstruct_cname != objstruct_cname:
error(pos, "Object struct name differs from previous declaration") error(pos, "Object struct name differs from previous declaration")
type.objstruct_cname = objstruct_cname type.objstruct_cname = objstruct_cname
if typeobj_cname: if typeobj_cname:
if type.typeobj_cname and type.typeobj_cname <> typeobj_cname: if type.typeobj_cname and type.typeobj_cname != typeobj_cname:
error(pos, "Type object name differs from previous declaration") error(pos, "Type object name differs from previous declaration")
type.typeobj_cname = typeobj_cname type.typeobj_cname = typeobj_cname
# #
...@@ -974,12 +952,12 @@ class ModuleScope(Scope): ...@@ -974,12 +952,12 @@ class ModuleScope(Scope):
# #
debug_check_c_classes = 0 debug_check_c_classes = 0
if debug_check_c_classes: if debug_check_c_classes:
print "Scope.check_c_classes: checking scope", self.qualified_name print("Scope.check_c_classes: checking scope " + self.qualified_name)
for entry in self.c_class_entries: for entry in self.c_class_entries:
if debug_check_c_classes: if debug_check_c_classes:
print "...entry", entry.name, entry print("...entry %s %s" % (entry.name, entry))
print "......type =", entry.type print("......type = " + entry.type)
print "......visibility =", entry.visibility print("......visibility = " + entry.visibility)
type = entry.type type = entry.type
name = entry.name name = entry.name
visibility = entry.visibility visibility = entry.visibility
...@@ -987,7 +965,7 @@ class ModuleScope(Scope): ...@@ -987,7 +965,7 @@ class ModuleScope(Scope):
if not type.scope: if not type.scope:
error(entry.pos, "C class '%s' is declared but not defined" % name) error(entry.pos, "C class '%s' is declared but not defined" % name)
# Generate typeobj_cname # Generate typeobj_cname
if visibility <> 'extern' and not type.typeobj_cname: if visibility != 'extern' and not type.typeobj_cname:
type.typeobj_cname = self.mangle(Naming.typeobj_prefix, name) type.typeobj_cname = self.mangle(Naming.typeobj_prefix, name)
## Generate typeptr_cname ## Generate typeptr_cname
#type.typeptr_cname = self.mangle(Naming.typeptr_prefix, name) #type.typeptr_cname = self.mangle(Naming.typeptr_prefix, name)
...@@ -1076,7 +1054,7 @@ class StructOrUnionScope(Scope): ...@@ -1076,7 +1054,7 @@ class StructOrUnionScope(Scope):
if type.is_pyobject and not allow_pyobject: if type.is_pyobject and not allow_pyobject:
error(pos, error(pos,
"C struct/union member cannot be a Python object") "C struct/union member cannot be a Python object")
if visibility <> 'private': if visibility != 'private':
error(pos, error(pos,
"C struct/union member cannot be declared %s" % visibility) "C struct/union member cannot be declared %s" % visibility)
return entry return entry
...@@ -1170,7 +1148,7 @@ class CClassScope(ClassScope): ...@@ -1170,7 +1148,7 @@ class CClassScope(ClassScope):
def __init__(self, name, outer_scope, visibility): def __init__(self, name, outer_scope, visibility):
ClassScope.__init__(self, name, outer_scope) ClassScope.__init__(self, name, outer_scope)
if visibility <> 'extern': if visibility != 'extern':
self.method_table_cname = outer_scope.mangle(Naming.methtab_prefix, name) self.method_table_cname = outer_scope.mangle(Naming.methtab_prefix, name)
self.member_table_cname = outer_scope.mangle(Naming.memtab_prefix, name) self.member_table_cname = outer_scope.mangle(Naming.memtab_prefix, name)
self.getset_table_cname = outer_scope.mangle(Naming.gstab_prefix, name) self.getset_table_cname = outer_scope.mangle(Naming.gstab_prefix, name)
......
...@@ -147,7 +147,7 @@ class SlotDescriptor: ...@@ -147,7 +147,7 @@ class SlotDescriptor:
def generate_dynamic_init_code(self, scope, code): def generate_dynamic_init_code(self, scope, code):
if self.is_initialised_dynamically: if self.is_initialised_dynamically:
value = self.slot_code(scope) value = self.slot_code(scope)
if value <> "0": if value != "0":
code.putln("%s.%s = %s;" % ( code.putln("%s.%s = %s;" % (
scope.parent_type.typeobj_cname, scope.parent_type.typeobj_cname,
self.slot_name, self.slot_name,
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
def print_call_chain(*args): def print_call_chain(*args):
import sys import sys
print " ".join(map(str, args)) print(" ".join(map(str, args)))
f = sys._getframe(1) f = sys._getframe(1)
while f: while f:
name = f.f_code.co_name name = f.f_code.co_name
...@@ -15,6 +15,6 @@ def print_call_chain(*args): ...@@ -15,6 +15,6 @@ def print_call_chain(*args):
c = getattr(s, "__class__", None) c = getattr(s, "__class__", None)
if c: if c:
name = "%s.%s" % (c.__name__, name) name = "%s.%s" % (c.__name__, name)
print "Called from:", name, f.f_lineno print("Called from: %s %s" % (name, f.f_lineno))
f = f.f_back f = f.f_back
print "-" * 70 print("-" * 70)
...@@ -69,10 +69,10 @@ def c_compile(c_file, verbose_flag = 0, cplus = 0, obj_suffix = ".o"): ...@@ -69,10 +69,10 @@ def c_compile(c_file, verbose_flag = 0, cplus = 0, obj_suffix = ".o"):
compiler = compilers[bool(cplus)] compiler = compilers[bool(cplus)]
args = [compiler] + compiler_options + include_options + [c_file, "-o", o_file] args = [compiler] + compiler_options + include_options + [c_file, "-o", o_file]
if verbose_flag or verbose: if verbose_flag or verbose:
print " ".join(args) print(" ".join(args))
#print compiler, args ### #print compiler, args ###
status = os.spawnvp(os.P_WAIT, compiler, args) status = os.spawnvp(os.P_WAIT, compiler, args)
if status <> 0: if status != 0:
raise CCompilerError("C compiler returned status %s" % status) raise CCompilerError("C compiler returned status %s" % status)
return o_file return o_file
...@@ -87,8 +87,8 @@ def c_link_list(obj_files, verbose_flag = 0, cplus = 0): ...@@ -87,8 +87,8 @@ def c_link_list(obj_files, verbose_flag = 0, cplus = 0):
linker = linkers[bool(cplus)] linker = linkers[bool(cplus)]
args = [linker] + linker_options + obj_files + ["-o", out_file] args = [linker] + linker_options + obj_files + ["-o", out_file]
if verbose_flag or verbose: if verbose_flag or verbose:
print " ".join(args) print(" ".join(args))
status = os.spawnvp(os.P_WAIT, linker, args) status = os.spawnvp(os.P_WAIT, linker, args)
if status <> 0: if status != 0:
raise CCompilerError("Linker returned status %s" % status) raise CCompilerError("Linker returned status %s" % status)
return out_file return out_file
...@@ -124,8 +124,8 @@ def test_c_compile(link = 0): ...@@ -124,8 +124,8 @@ def test_c_compile(link = 0):
except PyrexError, e: except PyrexError, e:
#print "Caught a PyrexError:" ### #print "Caught a PyrexError:" ###
#print repr(e) ### #print repr(e) ###
print "%s.%s:" % (e.__class__.__module__, print("%s.%s: %s" % (e.__class__.__module__,
e.__class__.__name__), e e.__class__.__name__, e))
sys.exit(1) sys.exit(1)
else: else:
obj = arg obj = arg
......
...@@ -111,7 +111,7 @@ class Lexicon: ...@@ -111,7 +111,7 @@ class Lexicon:
tables = None # StateTableMachine tables = None # StateTableMachine
def __init__(self, specifications, debug = None, debug_flags = 7, timings = None): def __init__(self, specifications, debug = None, debug_flags = 7, timings = None):
if type(specifications) <> types.ListType: if type(specifications) != types.ListType:
raise Errors.InvalidScanner("Scanner definition is not a list") raise Errors.InvalidScanner("Scanner definition is not a list")
if timings: if timings:
from Timing import time from Timing import time
...@@ -176,9 +176,9 @@ class Lexicon: ...@@ -176,9 +176,9 @@ class Lexicon:
raise e.__class__("Token number %d: %s" % (token_number, e)) raise e.__class__("Token number %d: %s" % (token_number, e))
def parse_token_definition(self, token_spec): def parse_token_definition(self, token_spec):
if type(token_spec) <> types.TupleType: if type(token_spec) != types.TupleType:
raise Errors.InvalidToken("Token definition is not a tuple") raise Errors.InvalidToken("Token definition is not a tuple")
if len(token_spec) <> 2: if len(token_spec) != 2:
raise Errors.InvalidToken("Wrong number of items in token definition") raise Errors.InvalidToken("Wrong number of items in token definition")
pattern, action = token_spec pattern, action = token_spec
if not isinstance(pattern, Regexps.RE): if not isinstance(pattern, Regexps.RE):
......
...@@ -182,7 +182,7 @@ class FastMachine: ...@@ -182,7 +182,7 @@ class FastMachine:
code0, code1 = event code0, code1 = event
if code0 == -maxint: if code0 == -maxint:
state['else'] = new_state state['else'] = new_state
elif code1 <> maxint: elif code1 != maxint:
while code0 < code1: while code0 < code1:
state[chr(code0)] = new_state state[chr(code0)] = new_state
code0 = code0 + 1 code0 = code0 + 1
......
...@@ -152,12 +152,12 @@ class RE: ...@@ -152,12 +152,12 @@ class RE:
self.wrong_type(num, value, "Plex.RE instance") self.wrong_type(num, value, "Plex.RE instance")
def check_string(self, num, value): def check_string(self, num, value):
if type(value) <> type(''): if type(value) != type(''):
self.wrong_type(num, value, "string") self.wrong_type(num, value, "string")
def check_char(self, num, value): def check_char(self, num, value):
self.check_string(num, value) self.check_string(num, value)
if len(value) <> 1: if len(value) != 1:
raise Errors.PlexValueError("Invalid value for argument %d of Plex.%s." raise Errors.PlexValueError("Invalid value for argument %d of Plex.%s."
"Expected a string of length 1, got: %s" % ( "Expected a string of length 1, got: %s" % (
num, self.__class__.__name__, repr(value))) num, self.__class__.__name__, repr(value)))
...@@ -192,7 +192,7 @@ class RE: ...@@ -192,7 +192,7 @@ class RE:
## def build_machine(self, m, initial_state, final_state, match_bol, nocase): ## def build_machine(self, m, initial_state, final_state, match_bol, nocase):
## c = self.char ## c = self.char
## if match_bol and c <> BOL: ## if match_bol and c != BOL:
## s1 = self.build_opt(m, initial_state, BOL) ## s1 = self.build_opt(m, initial_state, BOL)
## else: ## else:
## s1 = initial_state ## s1 = initial_state
......
...@@ -122,8 +122,8 @@ class Scanner: ...@@ -122,8 +122,8 @@ class Scanner:
action = self.run_machine_inlined() action = self.run_machine_inlined()
if action: if action:
if self.trace: if self.trace:
print "Scanner: read: Performing", action, "%d:%d" % ( print("Scanner: read: Performing %s %d:%d" % (
self.start_pos, self.cur_pos) action, self.start_pos, self.cur_pos))
base = self.buf_start_pos base = self.buf_start_pos
text = self.buffer[self.start_pos - base : self.cur_pos - base] text = self.buffer[self.start_pos - base : self.cur_pos - base]
return (text, action) return (text, action)
...@@ -163,8 +163,8 @@ class Scanner: ...@@ -163,8 +163,8 @@ class Scanner:
trace = self.trace trace = self.trace
while 1: while 1:
if trace: #TRACE# if trace: #TRACE#
print "State %d, %d/%d:%s -->" % ( #TRACE# print("State %d, %d/%d:%s -->" % ( #TRACE#
state['number'], input_state, cur_pos, repr(cur_char)), #TRACE# state['number'], input_state, cur_pos, repr(cur_char))) #TRACE#
# Begin inlined self.save_for_backup() # Begin inlined self.save_for_backup()
#action = state.action #@slow #action = state.action #@slow
action = state['action'] #@fast action = state['action'] #@fast
...@@ -179,7 +179,7 @@ class Scanner: ...@@ -179,7 +179,7 @@ class Scanner:
new_state = c and state.get('else') #@fast new_state = c and state.get('else') #@fast
if new_state: if new_state:
if trace: #TRACE# if trace: #TRACE#
print "State %d" % new_state['number'] #TRACE# print("State %d" % new_state['number']) #TRACE#
state = new_state state = new_state
# Begin inlined: self.next_char() # Begin inlined: self.next_char()
if input_state == 1: if input_state == 1:
...@@ -228,7 +228,7 @@ class Scanner: ...@@ -228,7 +228,7 @@ class Scanner:
# End inlined self.next_char() # End inlined self.next_char()
else: # not new_state else: # not new_state
if trace: #TRACE# if trace: #TRACE#
print "blocked" #TRACE# print("blocked") #TRACE#
# Begin inlined: action = self.back_up() # Begin inlined: action = self.back_up()
if backup_state: if backup_state:
(action, cur_pos, cur_line, cur_line_start, (action, cur_pos, cur_line, cur_line_start,
...@@ -245,7 +245,7 @@ class Scanner: ...@@ -245,7 +245,7 @@ class Scanner:
self.next_pos = next_pos self.next_pos = next_pos
if trace: #TRACE# if trace: #TRACE#
if action: #TRACE# if action: #TRACE#
print "Doing", action #TRACE# print("Doing " + action) #TRACE#
return action return action
# def transition(self): # def transition(self):
...@@ -288,7 +288,7 @@ class Scanner: ...@@ -288,7 +288,7 @@ class Scanner:
def next_char(self): def next_char(self):
input_state = self.input_state input_state = self.input_state
if self.trace: if self.trace:
print "Scanner: next:", " "*20, "[%d] %d" % (input_state, self.cur_pos), print("Scanner: next: %s [%d] %d" % (" "*20, input_state, self.cur_pos))
if input_state == 1: if input_state == 1:
self.cur_pos = self.next_pos self.cur_pos = self.next_pos
c = self.read_char() c = self.read_char()
...@@ -314,7 +314,7 @@ class Scanner: ...@@ -314,7 +314,7 @@ class Scanner:
else: # input_state = 5 else: # input_state = 5
self.cur_char = '' self.cur_char = ''
if self.trace: if self.trace:
print "--> [%d] %d %s" % (input_state, self.cur_pos, repr(self.cur_char)) print("--> [%d] %d %s" % (input_state, self.cur_pos, repr(self.cur_char)))
# def read_char(self): # def read_char(self):
# """ # """
......
...@@ -95,9 +95,9 @@ class REParser: ...@@ -95,9 +95,9 @@ class REParser:
if self.c == ']': if self.c == ']':
char_list.append(']') char_list.append(']')
self.next() self.next()
while not self.end and self.c <> ']': while not self.end and self.c != ']':
c1 = self.get() c1 = self.get()
if self.c == '-' and self.lookahead(1) <> ']': if self.c == '-' and self.lookahead(1) != ']':
self.next() self.next()
c2 = self.get() c2 = self.get()
for a in xrange(ord(c1), ord(c2) + 1): for a in xrange(ord(c1), ord(c2) + 1):
......
...@@ -190,7 +190,7 @@ class TransitionMap: ...@@ -190,7 +190,7 @@ class TransitionMap:
def check(self): def check(self):
"""Check data structure integrity.""" """Check data structure integrity."""
if not self.map[-3] < self.map[-1]: if not self.map[-3] < self.map[-1]:
print self print(self)
assert 0 assert 0
def dump(self, file): def dump(self, file):
......
...@@ -49,10 +49,10 @@ def c_compile(c_file, verbose_flag = 0, cplus = 0, obj_suffix = ".o"): ...@@ -49,10 +49,10 @@ def c_compile(c_file, verbose_flag = 0, cplus = 0, obj_suffix = ".o"):
compiler = compilers[bool(cplus)] compiler = compilers[bool(cplus)]
args = [compiler] + compiler_options + include_options + [c_file, "-o", o_file] args = [compiler] + compiler_options + include_options + [c_file, "-o", o_file]
if verbose_flag or verbose: if verbose_flag or verbose:
print " ".join(args) print(" ".join(args))
#print compiler, args ### #print compiler, args ###
status = os.spawnvp(os.P_WAIT, compiler, args) status = os.spawnvp(os.P_WAIT, compiler, args)
if status <> 0: if status != 0:
raise CCompilerError("C compiler returned status %s" % status) raise CCompilerError("C compiler returned status %s" % status)
return o_file return o_file
...@@ -67,8 +67,8 @@ def c_link_list(obj_files, verbose_flag = 0, cplus = 0): ...@@ -67,8 +67,8 @@ def c_link_list(obj_files, verbose_flag = 0, cplus = 0):
linker = linkers[bool(cplus)] linker = linkers[bool(cplus)]
args = [linker] + linker_options + obj_files + ["-o", out_file] args = [linker] + linker_options + obj_files + ["-o", out_file]
if verbose_flag or verbose: if verbose_flag or verbose:
print " ".join(args) print(" ".join(args))
status = os.spawnvp(os.P_WAIT, linker, args) status = os.spawnvp(os.P_WAIT, linker, args)
if status <> 0: if status != 0:
raise CCompilerError("Linker returned status %s" % status) raise CCompilerError("Linker returned status %s" % status)
return out_file return out_file
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