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:
in_try_finally = 0
def __init__(self, outfile_name):
self.f = open_new_file(outfile_name)
def __init__(self, f):
#self.f = open_new_file(outfile_name)
self.f = f
self.level = 0
self.bol = 1
self.marker = None
......@@ -80,6 +81,7 @@ class CCodeWriter:
def init_labels(self):
self.label_counter = 0
self.labels_used = {}
self.return_label = self.new_label()
self.new_error_label()
self.continue_label = None
......@@ -135,9 +137,17 @@ class CCodeWriter:
self.set_all_labels(new_labels)
return old_labels
def use_label(self, lbl):
self.labels_used[lbl] = 1
def put_label(self, lbl):
if lbl in self.labels_used:
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,
definition = True):
for entry in entries:
......@@ -146,28 +156,23 @@ class CCodeWriter:
def put_var_declaration(self, entry, static = 0, dll_linkage = None,
definition = True):
#print "Code.put_var_declaration:", entry.name, "definition =", definition
#print "Code.put_var_declaration:", entry.name, "definition =", definition ###
visibility = entry.visibility
if visibility == 'private' and not definition:
return
if not entry.used and visibility == "private":
return
storage_class = ""
if visibility == 'extern':
storage_class = Naming.extern_c_macro
elif visibility == 'public':
if definition:
storage_class = ""
else:
if not definition:
storage_class = Naming.extern_c_macro
elif visibility == 'private':
if static:
storage_class = "static"
else:
storage_class = ""
if 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':
dll_linkage = None
self.put(entry.type.declaration_code(entry.cname,
......@@ -186,10 +191,6 @@ class CCodeWriter:
def as_pyobject(self, cname, type):
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):
self.putln("Py_INCREF(%s);" % self.as_pyobject(cname, type))
......@@ -231,8 +232,9 @@ class CCodeWriter:
self.putln("Py_XDECREF(%s); %s = 0;" % (
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:
if not used_only or entry.used:
if entry.xdecref_cleanup:
self.put_var_xdecref(entry)
else:
......@@ -269,13 +271,15 @@ class CCodeWriter:
term))
def error_goto(self, pos):
lbl = self.error_label
self.use_label(lbl)
return "{%s = %s[%s]; %s = %s; goto %s;}" % (
Naming.filename_cname,
Naming.filetable_cname,
self.lookup_filename(pos[0]),
Naming.lineno_cname,
pos[1],
self.error_label)
lbl)
def lookup_filename(self, filename):
try:
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -8,6 +8,7 @@ from types import ListType, TupleType
from Scanning import PyrexScanner
import Nodes
import ExprNodes
from ModuleNode import ModuleNode
from Errors import error, InternalError
def p_ident(s, message = "Expected an identifier"):
......@@ -413,13 +414,7 @@ def p_atom(s):
elif sy == '`':
return p_backquote_expr(s)
elif sy == 'INT':
digits = s.systring
if digits[:2] == "0x":
value = long(digits[2:], 16)
elif digits[:1] == "0":
value = int(digits, 8)
else:
value = int(s.systring)
value = s.systring
s.next()
return ExprNodes.IntNode(pos, value = value)
elif sy == 'LONG':
......@@ -517,7 +512,7 @@ def p_string_literal(s):
elif c == '\n':
pass
else:
chars.append(systr[1:])
chars.append(r'\\' + systr[1:])
elif sy == 'NEWLINE':
chars.append(r'\n')
elif sy == 'END_STRING':
......@@ -668,7 +663,6 @@ def p_expression_or_assignment(s):
if len(nodes) == 1:
return nodes[0]
else:
#return Nodes.StatListNode(nodes[0].pos, stats = nodes)
return Nodes.ParallelAssignmentNode(nodes[0].pos, stats = nodes)
def flatten_parallel_assignments(input, output):
......@@ -1375,19 +1369,19 @@ def p_exception_value_clause(s):
if s.sy == '?':
exc_check = 1
s.next()
exc_val = p_exception_value(s)
exc_val = p_simple_expr(s) #p_exception_value(s)
return exc_val, exc_check
def p_exception_value(s):
sign = ""
if s.sy == "-":
sign = "-"
s.next()
if s.sy in ('INT', 'LONG', 'FLOAT', 'NULL'):
s.systring = sign + s.systring
return p_atom(s)
else:
s.error("Exception value must be an int or float literal or NULL")
#def p_exception_value(s):
# sign = ""
# if s.sy == "-":
# sign = "-"
# s.next()
# if s.sy in ('INT', 'LONG', 'FLOAT', 'NULL'):
# s.systring = sign + s.systring
# return p_atom(s)
# else:
# s.error("Exception value must be an int or float literal or NULL")
c_arg_list_terminators = ('*', '**', '.', ')')
c_arg_list_trailers = ('.', '*', '**')
......@@ -1780,7 +1774,7 @@ def p_module(s, pxd):
if s.sy <> 'EOF':
s.error("Syntax error in statement [%s,%s]" % (
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):
from_py_function = None
class CSimpleType(CType):
#
# Base class for all unstructured C types.
#
pass
#class CSimpleType(CType):
# #
# # Base class for all unstructured C types.
# #
# pass
class CVoidType(CSimpleType):
class CVoidType(CType):
is_void = 1
def __repr__(self):
......@@ -313,9 +313,6 @@ class CNumericType(CType):
u = "unsigned "
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,
for_display = 0, dll_linkage = None, pyrex = 0):
if self.signed:
......@@ -325,8 +322,6 @@ class CNumericType(CType):
base = public_decl(u + rank_to_type_name[self.rank], dll_linkage)
return "%s %s" % (base, entity_code)
# return "%s%s %s" % (u, rank_to_type_name[self.rank], entity_code)
class CIntType(CNumericType):
......@@ -339,6 +334,9 @@ class CIntType(CNumericType):
CNumericType.__init__(self, rank, signed, pymemberdef_typecode)
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):
......@@ -373,6 +371,9 @@ class CFloatType(CNumericType):
def __init__(self, rank, pymemberdef_typecode = None):
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):
# base_type CType Element type
......@@ -447,6 +448,8 @@ class CPtrType(CType):
return 1
elif self.base_type.is_cfunction and other_type.is_cfunction:
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:
return 0
elif self.base_type.is_void:
......@@ -608,14 +611,16 @@ class CStructOrUnionType(CType):
return self.is_complete()
class CEnumType(CIntType):
class CEnumType(CType):
# name string
# cname string or None
# typedef_flag boolean
is_enum = 1
signed = 1
rank = 2
#signed = 1
#rank = 2
to_py_function = "PyInt_FromLong"
from_py_function = "PyInt_AsLong"
def __init__(self, name, cname, typedef_flag):
self.name = name
......
......@@ -61,6 +61,7 @@ class Entry:
# interned_cname string C name of interned name string
# pystring_cname string C name of Python version of string literal
# is_interned boolean For string const entries, value is interned
# used boolean
borrowed = 0
init = ""
......@@ -91,6 +92,7 @@ class Entry:
interned_cname = None
pystring_cname = None
is_interned = 0
used = 0
def __init__(self, name, cname, type, pos = None, init = None):
self.name = name
......@@ -351,6 +353,7 @@ class Scope:
# Add an entry for a string constant.
cname = self.new_const_cname()
entry = Entry("", cname, c_char_array_type, init = value)
entry.used = 1
self.const_entries.append(entry)
return entry
......@@ -395,6 +398,7 @@ class Scope:
self.temp_counter = n + 1
cname = "%s%d" % (Naming.pyrex_prefix, n)
entry = Entry("", cname, type)
entry.used = 1
if type.is_pyobject:
entry.init = "0"
self.cname_to_entry[entry.cname] = entry
......@@ -476,6 +480,7 @@ class ModuleScope(Scope):
# intern_map {string : string} Mapping from Python names to interned strs
# interned_names [string] Interned names pending generation of declarations
# 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):
self.parent_module = parent_module
......@@ -500,6 +505,7 @@ class ModuleScope(Scope):
self.intern_map = {}
self.interned_names = []
self.all_pystring_entries = []
self.types_imported = {}
def qualifying_scope(self):
return self.parent_module
......@@ -565,6 +571,8 @@ class ModuleScope(Scope):
# None if previously declared as something else.
entry = self.lookup_here(name)
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):
error(pos, "'%s' redeclared" % name)
return None
......@@ -956,6 +964,8 @@ class CClassScope(ClassScope):
if visibility in ('public', 'readonly'):
if type.pymemberdef_typecode:
self.public_attr_entries.append(entry)
if name == "__weakref__":
error(pos, "Special attribute __weakref__ cannot be exposed to Python")
else:
error(pos,
"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 @@
verbose = 0
gcc_pendantic = True
gcc_warnings_are_errors = False
gcc_warnings_are_errors = True
gcc_all_warnings = True
import os
from Pyrex.Utils import replace_suffix
......@@ -23,6 +24,9 @@ if gcc_pendantic:
compiler_options.extend(["-pedantic", "-Wno-long-long"])
if gcc_warnings_are_errors:
compiler_options.append("-Werror")
if gcc_all_warnings:
compiler_options.append("-Wall")
compiler_options.append("-Wno-unused-function")
linkers = ["gcc", "g++"]
linker_options = \
......@@ -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]
if verbose_flag or verbose:
print " ".join(args)
#print compiler, args ###
status = os.spawnvp(os.P_WAIT, compiler, args)
if status <> 0:
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