Commit 1c96a947 authored by Robert Bradshaw's avatar Robert Bradshaw

initial merge

parents c1131235 5aab5520
...@@ -25,8 +25,9 @@ class CCodeWriter: ...@@ -25,8 +25,9 @@ class CCodeWriter:
in_try_finally = 0 in_try_finally = 0
def __init__(self, outfile_name): def __init__(self, f):
self.f = open_new_file(outfile_name) #self.f = open_new_file(outfile_name)
self.f = f
self.level = 0 self.level = 0
self.bol = 1 self.bol = 1
self.marker = None self.marker = None
...@@ -101,6 +102,7 @@ class CCodeWriter: ...@@ -101,6 +102,7 @@ class CCodeWriter:
def init_labels(self): def init_labels(self):
self.label_counter = 0 self.label_counter = 0
self.labels_used = {}
self.return_label = self.new_label() self.return_label = self.new_label()
self.new_error_label() self.new_error_label()
self.continue_label = None self.continue_label = None
...@@ -156,9 +158,17 @@ class CCodeWriter: ...@@ -156,9 +158,17 @@ class CCodeWriter:
self.set_all_labels(new_labels) self.set_all_labels(new_labels)
return old_labels return old_labels
def use_label(self, lbl):
self.labels_used[lbl] = 1
def put_label(self, lbl): def put_label(self, lbl):
if lbl in self.labels_used:
self.putln("%s:;" % lbl) self.putln("%s:;" % lbl)
def put_goto(self, lbl):
self.use_label(lbl)
self.putln("goto %s;" % lbl)
def put_var_declarations(self, entries, static = 0, dll_linkage = None, def put_var_declarations(self, entries, static = 0, dll_linkage = None,
definition = True): definition = True):
for entry in entries: for entry in entries:
...@@ -167,30 +177,23 @@ class CCodeWriter: ...@@ -167,30 +177,23 @@ class CCodeWriter:
def put_var_declaration(self, entry, static = 0, dll_linkage = None, def put_var_declaration(self, entry, static = 0, dll_linkage = None,
definition = True): definition = True):
#print "Code.put_var_declaration:", entry.name, "definition =", definition #print "Code.put_var_declaration:", entry.name, "definition =", definition ###
visibility = entry.visibility visibility = entry.visibility
if visibility == 'private' and not definition: if visibility == 'private' and not definition:
return return
if not entry.used and visibility == "private":
return
storage_class = ""
if visibility == 'extern': if visibility == 'extern':
storage_class = Naming.extern_c_macro storage_class = Naming.extern_c_macro
elif visibility == 'public': elif visibility == 'public':
if definition: if not definition:
storage_class = ""
else:
storage_class = Naming.extern_c_macro storage_class = Naming.extern_c_macro
elif visibility == 'private': elif visibility == 'private':
if static: if static:
storage_class = "static" storage_class = "static"
else:
storage_class = ""
else:
storage_class = ""
if storage_class: if storage_class:
self.put("%s " % storage_class) self.put("%s " % storage_class)
#if visibility == 'extern' or visibility == 'public' and not definition:
# self.put("%s " % Naming.extern_c_macro)
#elif static and visibility <> 'public':
# self.put("static ")
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,
...@@ -209,10 +212,6 @@ class CCodeWriter: ...@@ -209,10 +212,6 @@ class CCodeWriter:
def as_pyobject(self, cname, type): def as_pyobject(self, cname, type):
return typecast(py_object_type, type, cname) return typecast(py_object_type, type, cname)
#if type.is_extension_type and type.base_type:
# return "(PyObject *)" + cname
#else:
# return cname
def put_incref(self, cname, type): def put_incref(self, cname, type):
self.putln("Py_INCREF(%s);" % self.as_pyobject(cname, type)) self.putln("Py_INCREF(%s);" % self.as_pyobject(cname, type))
...@@ -257,8 +256,9 @@ class CCodeWriter: ...@@ -257,8 +256,9 @@ class CCodeWriter:
self.putln("Py_XDECREF(%s); %s = 0;" % ( self.putln("Py_XDECREF(%s); %s = 0;" % (
self.entry_as_pyobject(entry), entry.cname)) self.entry_as_pyobject(entry), entry.cname))
def put_var_decrefs(self, entries): def put_var_decrefs(self, entries, used_only = 0):
for entry in entries: for entry in entries:
if not used_only or entry.used:
if entry.xdecref_cleanup: if entry.xdecref_cleanup:
self.put_var_xdecref(entry) self.put_var_xdecref(entry)
else: else:
...@@ -295,13 +295,15 @@ class CCodeWriter: ...@@ -295,13 +295,15 @@ class CCodeWriter:
term)) term))
def error_goto(self, pos): def error_goto(self, pos):
lbl = self.error_label
self.use_label(lbl)
return "{%s = %s[%s]; %s = %s; goto %s;}" % ( return "{%s = %s[%s]; %s = %s; goto %s;}" % (
Naming.filename_cname, Naming.filename_cname,
Naming.filetable_cname, Naming.filetable_cname,
self.lookup_filename(pos[0]), self.lookup_filename(pos[0]),
Naming.lineno_cname, Naming.lineno_cname,
pos[1], pos[1],
self.error_label) lbl)
def lookup_filename(self, filename): def lookup_filename(self, filename):
try: try:
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
...@@ -8,6 +8,7 @@ from types import ListType, TupleType ...@@ -8,6 +8,7 @@ from types import ListType, TupleType
from Scanning import PyrexScanner from Scanning import PyrexScanner
import Nodes import Nodes
import ExprNodes import ExprNodes
from ModuleNode import ModuleNode
from Errors import error, InternalError from Errors import error, InternalError
def p_ident(s, message = "Expected an identifier"): def p_ident(s, message = "Expected an identifier"):
...@@ -435,13 +436,7 @@ def p_atom(s): ...@@ -435,13 +436,7 @@ def p_atom(s):
elif sy == '`': elif sy == '`':
return p_backquote_expr(s) return p_backquote_expr(s)
elif sy == 'INT': elif sy == 'INT':
digits = s.systring value = s.systring
if digits[:2] == "0x":
value = long(digits[2:], 16)
elif digits[:1] == "0":
value = int(digits, 8)
else:
value = int(s.systring)
s.next() s.next()
return ExprNodes.IntNode(pos, value = value) return ExprNodes.IntNode(pos, value = value)
elif sy == 'LONG': elif sy == 'LONG':
...@@ -539,7 +534,7 @@ def p_string_literal(s): ...@@ -539,7 +534,7 @@ def p_string_literal(s):
elif c == '\n': elif c == '\n':
pass pass
else: else:
chars.append(systr[1:]) chars.append(r'\\' + systr[1:])
elif sy == 'NEWLINE': elif sy == 'NEWLINE':
chars.append(r'\n') chars.append(r'\n')
elif sy == 'END_STRING': elif sy == 'END_STRING':
...@@ -764,7 +759,6 @@ def p_expression_or_assignment(s): ...@@ -764,7 +759,6 @@ def p_expression_or_assignment(s):
if len(nodes) == 1: if len(nodes) == 1:
return nodes[0] return nodes[0]
else: else:
#return Nodes.StatListNode(nodes[0].pos, stats = nodes)
return Nodes.ParallelAssignmentNode(nodes[0].pos, stats = nodes) return Nodes.ParallelAssignmentNode(nodes[0].pos, stats = nodes)
def flatten_parallel_assignments(input, output): def flatten_parallel_assignments(input, output):
...@@ -1480,19 +1474,19 @@ def p_exception_value_clause(s): ...@@ -1480,19 +1474,19 @@ def p_exception_value_clause(s):
if s.sy == '?': if s.sy == '?':
exc_check = 1 exc_check = 1
s.next() s.next()
exc_val = p_exception_value(s) exc_val = p_simple_expr(s) #p_exception_value(s)
return exc_val, exc_check return exc_val, exc_check
def p_exception_value(s): #def p_exception_value(s):
sign = "" # sign = ""
if s.sy == "-": # if s.sy == "-":
sign = "-" # sign = "-"
s.next() # s.next()
if s.sy in ('INT', 'LONG', 'FLOAT', 'NULL'): # if s.sy in ('INT', 'LONG', 'FLOAT', 'NULL'):
s.systring = sign + s.systring # s.systring = sign + s.systring
return p_atom(s) # return p_atom(s)
else: # else:
s.error("Exception value must be an int or float literal or NULL") # s.error("Exception value must be an int or float literal or NULL")
c_arg_list_terminators = ('*', '**', '.', ')') c_arg_list_terminators = ('*', '**', '.', ')')
c_arg_list_trailers = ('.', '*', '**') c_arg_list_trailers = ('.', '*', '**')
...@@ -1894,7 +1888,7 @@ def p_module(s, pxd, full_module_name): ...@@ -1894,7 +1888,7 @@ def p_module(s, pxd, full_module_name):
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 Nodes.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)
#---------------------------------------------- #----------------------------------------------
# #
......
...@@ -262,14 +262,14 @@ class CType(PyrexType): ...@@ -262,14 +262,14 @@ class CType(PyrexType):
from_py_function = None from_py_function = None
class CSimpleType(CType): #class CSimpleType(CType):
# # #
# Base class for all unstructured C types. # # Base class for all unstructured C types.
# # #
pass # pass
class CVoidType(CSimpleType): class CVoidType(CType):
is_void = 1 is_void = 1
def __repr__(self): def __repr__(self):
...@@ -316,9 +316,6 @@ class CNumericType(CType): ...@@ -316,9 +316,6 @@ class CNumericType(CType):
u = "unsigned " u = "unsigned "
return "<CNumericType %s%s>" % (u, rank_to_type_name[self.rank]) return "<CNumericType %s%s>" % (u, rank_to_type_name[self.rank])
def assignable_from_resolved_type(self, src_type):
return src_type.is_numeric or src_type is error_type
def declaration_code(self, entity_code, def declaration_code(self, entity_code,
for_display = 0, dll_linkage = None, pyrex = 0): for_display = 0, dll_linkage = None, pyrex = 0):
if self.signed: if self.signed:
...@@ -328,8 +325,6 @@ class CNumericType(CType): ...@@ -328,8 +325,6 @@ class CNumericType(CType):
base = public_decl(u + rank_to_type_name[self.rank], dll_linkage) base = public_decl(u + rank_to_type_name[self.rank], dll_linkage)
return "%s %s" % (base, entity_code) return "%s %s" % (base, entity_code)
# return "%s%s %s" % (u, rank_to_type_name[self.rank], entity_code)
class CIntType(CNumericType): class CIntType(CNumericType):
...@@ -342,6 +337,9 @@ class CIntType(CNumericType): ...@@ -342,6 +337,9 @@ class CIntType(CNumericType):
CNumericType.__init__(self, rank, signed, pymemberdef_typecode) CNumericType.__init__(self, rank, signed, pymemberdef_typecode)
self.is_returncode = is_returncode self.is_returncode = is_returncode
def assignable_from_resolved_type(self, src_type):
return src_type.is_int or src_type.is_enum or src_type is error_type
class CBIntType(CIntType): class CBIntType(CIntType):
...@@ -390,6 +388,9 @@ class CFloatType(CNumericType): ...@@ -390,6 +388,9 @@ class CFloatType(CNumericType):
def __init__(self, rank, pymemberdef_typecode = None): def __init__(self, rank, pymemberdef_typecode = None):
CNumericType.__init__(self, rank, 1, pymemberdef_typecode) CNumericType.__init__(self, rank, 1, pymemberdef_typecode)
def assignable_from_resolved_type(self, src_type):
return src_type.is_numeric or src_type is error_type
class CArrayType(CType): class CArrayType(CType):
# base_type CType Element type # base_type CType Element type
...@@ -464,6 +465,8 @@ class CPtrType(CType): ...@@ -464,6 +465,8 @@ class CPtrType(CType):
return 1 return 1
elif self.base_type.is_cfunction and other_type.is_cfunction: elif self.base_type.is_cfunction and other_type.is_cfunction:
return self.base_type.same_as(other_type) return self.base_type.same_as(other_type)
elif other_type.is_array:
return self.base_type.same_as(other_type.base_type)
elif not other_type.is_ptr: elif not other_type.is_ptr:
return 0 return 0
elif self.base_type.is_void: elif self.base_type.is_void:
...@@ -651,14 +654,16 @@ class CStructOrUnionType(CType): ...@@ -651,14 +654,16 @@ class CStructOrUnionType(CType):
return self.is_complete() return self.is_complete()
class CEnumType(CIntType): class CEnumType(CType):
# name string # name string
# cname string or None # cname string or None
# typedef_flag boolean # typedef_flag boolean
is_enum = 1 is_enum = 1
signed = 1 #signed = 1
rank = 2 #rank = 2
to_py_function = "PyInt_FromLong"
from_py_function = "PyInt_AsLong"
def __init__(self, name, cname, typedef_flag): def __init__(self, name, cname, typedef_flag):
self.name = name self.name = name
...@@ -743,7 +748,6 @@ c_int_type = CIntType(2, 1, "T_INT") ...@@ -743,7 +748,6 @@ c_int_type = CIntType(2, 1, "T_INT")
c_long_type = CIntType(3, 1, "T_LONG") c_long_type = CIntType(3, 1, "T_LONG")
c_longlong_type = CLongLongType(4, 1, "T_LONGLONG") c_longlong_type = CLongLongType(4, 1, "T_LONGLONG")
c_py_ssize_t_type = CPySSizeTType(5, 1) c_py_ssize_t_type = CPySSizeTType(5, 1)
c_bint_type = CBIntType(2, 1, "T_INT") c_bint_type = CBIntType(2, 1, "T_INT")
c_uchar_type = CIntType(0, 0, "T_UBYTE") c_uchar_type = CIntType(0, 0, "T_UBYTE")
......
...@@ -60,6 +60,7 @@ class Entry: ...@@ -60,6 +60,7 @@ class Entry:
# interned_cname string C name of interned name string # interned_cname string C name of interned name string
# pystring_cname string C name of Python version of string literal # pystring_cname string C name of Python version of string literal
# is_interned boolean For string const entries, value is interned # is_interned boolean For string const entries, value is interned
# used boolean
borrowed = 0 borrowed = 0
init = "" init = ""
...@@ -90,6 +91,7 @@ class Entry: ...@@ -90,6 +91,7 @@ class Entry:
interned_cname = None interned_cname = None
pystring_cname = None pystring_cname = None
is_interned = 0 is_interned = 0
used = 0
def __init__(self, name, cname, type, pos = None, init = None): def __init__(self, name, cname, type, pos = None, init = None):
self.name = name self.name = name
...@@ -354,6 +356,7 @@ class Scope: ...@@ -354,6 +356,7 @@ class Scope:
# Add an entry for a string constant. # Add an entry for a string constant.
cname = self.new_const_cname() cname = self.new_const_cname()
entry = Entry("", cname, c_char_array_type, init = value) entry = Entry("", cname, c_char_array_type, init = value)
entry.used = 1
self.const_entries.append(entry) self.const_entries.append(entry)
return entry return entry
...@@ -398,6 +401,7 @@ class Scope: ...@@ -398,6 +401,7 @@ class Scope:
self.temp_counter = n + 1 self.temp_counter = n + 1
cname = "%s%d" % (Naming.pyrex_prefix, n) cname = "%s%d" % (Naming.pyrex_prefix, n)
entry = Entry("", cname, type) entry = Entry("", cname, type)
entry.used = 1
if type.is_pyobject: if type.is_pyobject:
entry.init = "0" entry.init = "0"
self.cname_to_entry[entry.cname] = entry self.cname_to_entry[entry.cname] = entry
...@@ -550,6 +554,7 @@ class ModuleScope(Scope): ...@@ -550,6 +554,7 @@ class ModuleScope(Scope):
# 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
# 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
def __init__(self, name, parent_module, context): def __init__(self, name, parent_module, context):
self.parent_module = parent_module self.parent_module = parent_module
...@@ -574,6 +579,7 @@ class ModuleScope(Scope): ...@@ -574,6 +579,7 @@ class ModuleScope(Scope):
self.intern_map = {} self.intern_map = {}
self.interned_names = [] self.interned_names = []
self.all_pystring_entries = [] self.all_pystring_entries = []
self.types_imported = {}
def qualifying_scope(self): def qualifying_scope(self):
return self.parent_module return self.parent_module
...@@ -639,6 +645,8 @@ class ModuleScope(Scope): ...@@ -639,6 +645,8 @@ class ModuleScope(Scope):
# None if previously declared as something else. # None if previously declared as something else.
entry = self.lookup_here(name) entry = self.lookup_here(name)
if entry: if entry:
if entry.is_pyglobal and entry.as_module is scope:
return entry # Already declared as the same module
if not (entry.is_pyglobal and not entry.as_module): if not (entry.is_pyglobal and not entry.as_module):
# SAGE -- I put this here so Pyrex # SAGE -- I put this here so Pyrex
# cimport's work across directories. # cimport's work across directories.
...@@ -1038,6 +1046,8 @@ class CClassScope(ClassScope): ...@@ -1038,6 +1046,8 @@ class CClassScope(ClassScope):
if visibility in ('public', 'readonly'): if visibility in ('public', 'readonly'):
if type.pymemberdef_typecode: if type.pymemberdef_typecode:
self.public_attr_entries.append(entry) self.public_attr_entries.append(entry)
if name == "__weakref__":
error(pos, "Special attribute __weakref__ cannot be exposed to Python")
else: else:
error(pos, error(pos,
"C attribute of type '%s' cannot be accessed from Python" % type) "C attribute of type '%s' cannot be accessed from Python" % type)
......
version = '0.9.4.1' version = '0.9.5.1a'
...@@ -4,7 +4,8 @@ ...@@ -4,7 +4,8 @@
verbose = 0 verbose = 0
gcc_pendantic = True gcc_pendantic = True
gcc_warnings_are_errors = False gcc_warnings_are_errors = True
gcc_all_warnings = True
import os import os
from Pyrex.Utils import replace_suffix from Pyrex.Utils import replace_suffix
...@@ -23,6 +24,9 @@ if gcc_pendantic: ...@@ -23,6 +24,9 @@ if gcc_pendantic:
compiler_options.extend(["-pedantic", "-Wno-long-long"]) compiler_options.extend(["-pedantic", "-Wno-long-long"])
if gcc_warnings_are_errors: if gcc_warnings_are_errors:
compiler_options.append("-Werror") compiler_options.append("-Werror")
if gcc_all_warnings:
compiler_options.append("-Wall")
compiler_options.append("-Wno-unused-function")
linkers = ["gcc", "g++"] linkers = ["gcc", "g++"]
linker_options = \ linker_options = \
...@@ -45,6 +49,7 @@ def c_compile(c_file, verbose_flag = 0, cplus = 0, obj_suffix = ".o"): ...@@ -45,6 +49,7 @@ def c_compile(c_file, verbose_flag = 0, cplus = 0, obj_suffix = ".o"):
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 ###
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)
......
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