Commit 5aab5520 authored by Robert Bradshaw's avatar Robert Bradshaw

Pyrex Official version 0.9.5.1a

parent 54ab11e7
...@@ -22,8 +22,9 @@ class CCodeWriter: ...@@ -22,8 +22,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
...@@ -80,6 +81,7 @@ class CCodeWriter: ...@@ -80,6 +81,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
...@@ -135,9 +137,17 @@ class CCodeWriter: ...@@ -135,9 +137,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:
...@@ -146,28 +156,23 @@ class CCodeWriter: ...@@ -146,28 +156,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 = ""
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,
...@@ -186,10 +191,6 @@ class CCodeWriter: ...@@ -186,10 +191,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))
...@@ -231,8 +232,9 @@ class CCodeWriter: ...@@ -231,8 +232,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:
...@@ -269,13 +271,15 @@ class CCodeWriter: ...@@ -269,13 +271,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"):
...@@ -413,13 +414,7 @@ def p_atom(s): ...@@ -413,13 +414,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':
...@@ -517,7 +512,7 @@ def p_string_literal(s): ...@@ -517,7 +512,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':
...@@ -668,7 +663,6 @@ def p_expression_or_assignment(s): ...@@ -668,7 +663,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):
...@@ -1375,19 +1369,19 @@ def p_exception_value_clause(s): ...@@ -1375,19 +1369,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 = ('.', '*', '**')
...@@ -1780,7 +1774,7 @@ def p_module(s, pxd): ...@@ -1780,7 +1774,7 @@ def p_module(s, pxd):
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) return ModuleNode(pos, doc = doc, body = body)
#---------------------------------------------- #----------------------------------------------
# #
......
...@@ -259,14 +259,14 @@ class CType(PyrexType): ...@@ -259,14 +259,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):
...@@ -313,9 +313,6 @@ class CNumericType(CType): ...@@ -313,9 +313,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:
...@@ -325,8 +322,6 @@ class CNumericType(CType): ...@@ -325,8 +322,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):
...@@ -339,6 +334,9 @@ class CIntType(CNumericType): ...@@ -339,6 +334,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 CUIntType(CIntType): class CUIntType(CIntType):
...@@ -373,6 +371,9 @@ class CFloatType(CNumericType): ...@@ -373,6 +371,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
...@@ -447,6 +448,8 @@ class CPtrType(CType): ...@@ -447,6 +448,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:
...@@ -608,14 +611,16 @@ class CStructOrUnionType(CType): ...@@ -608,14 +611,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
......
...@@ -61,6 +61,7 @@ class Entry: ...@@ -61,6 +61,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 = ""
...@@ -91,6 +92,7 @@ class Entry: ...@@ -91,6 +92,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
...@@ -351,6 +353,7 @@ class Scope: ...@@ -351,6 +353,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
...@@ -395,6 +398,7 @@ class Scope: ...@@ -395,6 +398,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
...@@ -476,6 +480,7 @@ class ModuleScope(Scope): ...@@ -476,6 +480,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
...@@ -500,6 +505,7 @@ class ModuleScope(Scope): ...@@ -500,6 +505,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
...@@ -565,6 +571,8 @@ class ModuleScope(Scope): ...@@ -565,6 +571,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):
error(pos, "'%s' redeclared" % name) error(pos, "'%s' redeclared" % name)
return None return None
...@@ -956,6 +964,8 @@ class CClassScope(ClassScope): ...@@ -956,6 +964,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.
"""Suite Misc Suite: Suite that adds additional features to the Application.
Level 1, version 1
Generated from MPW:MPW Shell
AETE/AEUT resource version 1/0, language 0, script 0
"""
import aetools
import MacOS
_code = 'misc'
class MPW_Misc_Suite:
def DoScript(self, _object, _attributes={}, **_arguments):
"""DoScript: Execute an MPW command, any command that could be executed from the command line can be sent as a script.
Required argument: The script to execute
Keyword argument _attributes: AppleEvent attribute dictionary
"""
_code = 'misc'
_subcode = 'dosc'
if _arguments: raise TypeError, 'No optional args expected'
_arguments['----'] = _object
_reply, _arguments, _attributes = self.send(_code, _subcode,
_arguments, _attributes)
if _arguments.has_key('errn'):
raise aetools.Error, aetools.decodeerror(_arguments)
# XXXX Optionally decode result
if _arguments.has_key('----'):
return _arguments['----']
#
# Indices of types declared in this module
#
_classdeclarations = {
}
_propdeclarations = {
}
_compdeclarations = {
}
_enumdeclarations = {
}
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