[cig-commits] r5903 - in cs/babel/trunk/spike: . Demos
Demos/callback Spike Spike/Compiler Spike/Distutils Spike/Mac
leif at geodynamics.org
leif at geodynamics.org
Thu Jan 25 20:10:35 PST 2007
Author: leif
Date: 2007-01-25 20:10:35 -0800 (Thu, 25 Jan 2007)
New Revision: 5903
Added:
cs/babel/trunk/spike/Spike/Compiler/SpikeTypes.py
Removed:
cs/babel/trunk/spike/Spike/Compiler/PyrexTypes.py
Modified:
cs/babel/trunk/spike/Demos/Setup.py
cs/babel/trunk/spike/Demos/callback/Setup.py
cs/babel/trunk/spike/Spike/Compiler/CmdLine.py
cs/babel/trunk/spike/Spike/Compiler/Code.py
cs/babel/trunk/spike/Spike/Compiler/Errors.py
cs/babel/trunk/spike/Spike/Compiler/ExprNodes.py
cs/babel/trunk/spike/Spike/Compiler/Lexicon.pickle
cs/babel/trunk/spike/Spike/Compiler/Lexicon.py
cs/babel/trunk/spike/Spike/Compiler/Main.py
cs/babel/trunk/spike/Spike/Compiler/Naming.py
cs/babel/trunk/spike/Spike/Compiler/Nodes.py
cs/babel/trunk/spike/Spike/Compiler/Options.py
cs/babel/trunk/spike/Spike/Compiler/Parsing.py
cs/babel/trunk/spike/Spike/Compiler/Scanning.py
cs/babel/trunk/spike/Spike/Compiler/Symtab.py
cs/babel/trunk/spike/Spike/Compiler/TypeSlots.py
cs/babel/trunk/spike/Spike/Distutils/build_ext.py
cs/babel/trunk/spike/Spike/Mac/DarwinSystem.py
cs/babel/trunk/spike/Spike/Mac/MacSystem.py
cs/babel/trunk/spike/Spike/Mac/MacUtils.py
cs/babel/trunk/spike/Spike/Utils.py
cs/babel/trunk/spike/setup.py
Log:
Renamed Pyrex -> Spike (2 of 2).
Modified: cs/babel/trunk/spike/Demos/Setup.py
===================================================================
--- cs/babel/trunk/spike/Demos/Setup.py 2007-01-26 03:29:08 UTC (rev 5902)
+++ cs/babel/trunk/spike/Demos/Setup.py 2007-01-26 04:10:35 UTC (rev 5903)
@@ -1,6 +1,6 @@
from distutils.core import setup
from distutils.extension import Extension
-from Pyrex.Distutils import build_ext
+from Spike.Distutils import build_ext
setup(
name = 'Demos',
Modified: cs/babel/trunk/spike/Demos/callback/Setup.py
===================================================================
--- cs/babel/trunk/spike/Demos/callback/Setup.py 2007-01-26 03:29:08 UTC (rev 5902)
+++ cs/babel/trunk/spike/Demos/callback/Setup.py 2007-01-26 04:10:35 UTC (rev 5903)
@@ -1,6 +1,6 @@
from distutils.core import setup
from distutils.extension import Extension
-from Pyrex.Distutils import build_ext
+from Spike.Distutils import build_ext
setup(
name = 'callback',
Modified: cs/babel/trunk/spike/Spike/Compiler/CmdLine.py
===================================================================
--- cs/babel/trunk/spike/Spike/Compiler/CmdLine.py 2007-01-26 03:29:08 UTC (rev 5902)
+++ cs/babel/trunk/spike/Spike/Compiler/CmdLine.py 2007-01-26 04:10:35 UTC (rev 5903)
@@ -1,5 +1,5 @@
#
-# Pyrex - Command Line Parsing
+# Spike - Command Line Parsing
#
import sys
@@ -22,7 +22,7 @@
sys.exit(1)
def parse_command_line(args):
- from Pyrex.Compiler.Main import \
+ from Spike.Compiler.Main import \
CompilationOptions, default_options
def pop_arg():
Modified: cs/babel/trunk/spike/Spike/Compiler/Code.py
===================================================================
--- cs/babel/trunk/spike/Spike/Compiler/Code.py 2007-01-26 03:29:08 UTC (rev 5902)
+++ cs/babel/trunk/spike/Spike/Compiler/Code.py 2007-01-26 04:10:35 UTC (rev 5903)
@@ -1,10 +1,10 @@
#
-# Pyrex - Code output module
+# Spike - Code output module
#
import Naming
-from Pyrex.Utils import open_new_file
-from PyrexTypes import py_object_type, typecast
+from Spike.Utils import open_new_file
+from SpikeTypes import py_object_type, typecast
class CCodeWriter:
# f file output file
@@ -287,7 +287,7 @@
return index
-class PyrexCodeWriter:
+class SpikeCodeWriter:
# f file output file
# level int indentation level
Modified: cs/babel/trunk/spike/Spike/Compiler/Errors.py
===================================================================
--- cs/babel/trunk/spike/Spike/Compiler/Errors.py 2007-01-26 03:29:08 UTC (rev 5902)
+++ cs/babel/trunk/spike/Spike/Compiler/Errors.py 2007-01-26 04:10:35 UTC (rev 5903)
@@ -1,16 +1,16 @@
#
-# Pyrex - Errors
+# Spike - Errors
#
import sys
-from Pyrex.Utils import open_new_file
+from Spike.Utils import open_new_file
-class PyrexError(Exception):
+class SpikeError(Exception):
pass
-class CompileError(PyrexError):
+class CompileError(SpikeError):
def __init__(self, position = None, message = ""):
self.position = position
Modified: cs/babel/trunk/spike/Spike/Compiler/ExprNodes.py
===================================================================
--- cs/babel/trunk/spike/Spike/Compiler/ExprNodes.py 2007-01-26 03:29:08 UTC (rev 5902)
+++ cs/babel/trunk/spike/Spike/Compiler/ExprNodes.py 2007-01-26 04:10:35 UTC (rev 5903)
@@ -1,5 +1,5 @@
#
-# Pyrex - Parse tree nodes for expressions
+# Spike - Parse tree nodes for expressions
#
from string import join
@@ -7,18 +7,18 @@
from Errors import error, InternalError
import Naming
from Nodes import Node
-import PyrexTypes
-from PyrexTypes import py_object_type, typecast
+import SpikeTypes
+from SpikeTypes import py_object_type, typecast
import Symtab
import Options
-from Pyrex.Debugging import print_call_chain
+from Spike.Debugging import print_call_chain
from DebugFlags import debug_disposal_code, debug_temp_alloc, \
debug_coercion
class ExprNode(Node):
# subexprs [string] Class var holding names of subexpr node attrs
- # type PyrexType Type of the result
+ # type SpikeType Type of the result
# result_code string Code fragment
# result_ctype string C type of result_code if different from type
# is_temp boolean Result is in a temporary variable
@@ -346,7 +346,7 @@
type = self.type
if not type.is_void:
if type.is_pyobject:
- type = PyrexTypes.py_object_type
+ type = SpikeTypes.py_object_type
self.result_code = env.allocate_temp(type)
else:
self.result_code = None
@@ -473,7 +473,7 @@
return src
def coerce_to_pyobject(self, env):
- return self.coerce_to(PyrexTypes.py_object_type, env)
+ return self.coerce_to(SpikeTypes.py_object_type, env)
def coerce_to_boolean(self, env):
# Coerce result to something acceptable as
@@ -492,7 +492,7 @@
if self.type.is_int:
return self
else:
- return self.coerce_to(PyrexTypes.c_long_type, env)
+ return self.coerce_to(SpikeTypes.c_long_type, env)
def coerce_to_temp(self, env):
# Ensure that the result is in a temporary.
@@ -575,29 +575,29 @@
class NullNode(ConstNode):
- type = PyrexTypes.c_null_ptr_type
+ type = SpikeTypes.c_null_ptr_type
value = "0"
class CharNode(ConstNode):
- type = PyrexTypes.c_char_type
+ type = SpikeTypes.c_char_type
def calculate_result_code(self):
return "'%s'" % self.value
class IntNode(ConstNode):
- type = PyrexTypes.c_long_type
+ type = SpikeTypes.c_long_type
class FloatNode(ConstNode):
- type = PyrexTypes.c_double_type
+ type = SpikeTypes.c_double_type
class StringNode(ConstNode):
# entry Symtab.Entry
- type = PyrexTypes.c_char_ptr_type
+ type = SpikeTypes.c_char_ptr_type
def analyse_types(self, env):
self.entry = env.add_string_const(self.value)
@@ -724,7 +724,7 @@
else:
error(self.pos, "Assignment to non-lvalue '%s'"
% self.name)
- self.type = PyrexTypes.error_type
+ self.type = SpikeTypes.error_type
def check_identifier_kind(self):
entry = self.entry
@@ -782,7 +782,7 @@
if Options.intern_names:
#assert entry.interned_cname is not None
code.putln(
- '%s = __Pyx_GetName(%s, %s); if (!%s) %s' % (
+ '%s = __Spike_GetName(%s, %s); if (!%s) %s' % (
self.result_code,
namespace,
entry.interned_cname,
@@ -790,7 +790,7 @@
code.error_goto(self.pos)))
else:
code.putln(
- '%s = __Pyx_GetName(%s, "%s"); if (!%s) %s' % (
+ '%s = __Spike_GetName(%s, "%s"); if (!%s) %s' % (
self.result_code,
namespace,
self.entry.name,
@@ -895,7 +895,7 @@
else:
name_list_code = "0"
code.putln(
- "%s = __Pyx_Import(%s, %s); if (!%s) %s" % (
+ "%s = __Spike_Import(%s, %s); if (!%s) %s" % (
self.result_code,
self.module_name.py_result(),
name_list_code,
@@ -970,7 +970,7 @@
def generate_result_code(self, code):
code.putln(
- "%s = __Pyx_GetExcValue(); if (!%s) %s" % (
+ "%s = __Spike_GetExcValue(); if (!%s) %s" % (
self.result_code,
self.result_code,
code.error_goto(self.pos)))
@@ -995,7 +995,7 @@
# TempNode holding a Python value.
def __init__(self, pos, env):
- TempNode.__init__(self, pos, PyrexTypes.py_object_type, env)
+ TempNode.__init__(self, pos, SpikeTypes.py_object_type, env)
#-------------------------------------------------------------------
@@ -1032,10 +1032,10 @@
error(self.pos,
"Attempting to index non-array type '%s'" %
self.base.type)
- self.type = PyrexTypes.error_type
+ self.type = SpikeTypes.error_type
if self.index.type.is_pyobject:
self.index = self.index.coerce_to(
- PyrexTypes.c_int_type, env)
+ SpikeTypes.c_int_type, env)
if not self.index.type.is_int:
error(self.pos,
"Invalid index type '%s'" %
@@ -1107,7 +1107,7 @@
if self.stop:
self.stop.analyse_types(env)
self.base = self.base.coerce_to_pyobject(env)
- c_int = PyrexTypes.c_int_type
+ c_int = SpikeTypes.c_int_type
if self.start:
self.start = self.start.coerce_to(c_int, env)
if self.stop:
@@ -1252,7 +1252,7 @@
if not func_type.is_error:
error(self.pos, "Calling non-function type '%s'" %
func_type)
- self.type = PyrexTypes.error_type
+ self.type = SpikeTypes.error_type
self.result_code = "<error>"
return
# Check no. of args
@@ -1267,7 +1267,7 @@
"Call with wrong number of arguments (expected %s, got %s)"
% (expected_str, actual_nargs))
self.args = None
- self.type = PyrexTypes.error_type
+ self.type = SpikeTypes.error_type
self.result_code = "<error>"
return
# Coerce arguments
@@ -1444,7 +1444,7 @@
is_attribute = 1
subexprs = ['obj']
- type = PyrexTypes.error_type
+ type = SpikeTypes.error_type
result = "<error>"
entry = None
is_called = 0
@@ -1565,7 +1565,7 @@
error(self.pos,
"Cannot select attribute of incomplete type '%s'"
% obj_type)
- obj_type = PyrexTypes.error_type
+ obj_type = SpikeTypes.error_type
self.entry = entry
if entry:
if entry.is_variable or entry.is_cmethod:
@@ -1755,7 +1755,7 @@
def generate_assignment_code(self, rhs, code):
for i in range(len(self.args)):
item = self.unpacked_items[i]
- unpack_code = "__Pyx_UnpackItem(%s, %s)" % (
+ unpack_code = "__Spike_UnpackItem(%s, %s)" % (
rhs.py_result(),
i)
code.putln(
@@ -1768,7 +1768,7 @@
value_node.generate_evaluation_code(code)
self.args[i].generate_assignment_code(value_node, code)
code.putln(
- "if (__Pyx_EndUnpack(%s, %s) < 0) %s" % (
+ "if (__Spike_EndUnpack(%s, %s) < 0) %s" % (
rhs.py_result(),
len(self.args),
code.error_goto(self.pos)))
@@ -1914,7 +1914,7 @@
self.doc.py_result(),
code.error_goto(self.pos)))
code.putln(
- '%s = __Pyx_CreateClass(%s, %s, %s, "%s"); if (!%s) %s' % (
+ '%s = __Spike_CreateClass(%s, %s, %s, "%s"); if (!%s) %s' % (
self.result_code,
self.bases.py_result(),
self.dict.py_result(),
@@ -2027,7 +2027,7 @@
if not self.operand.type.is_error:
error(self.pos, "Invalid operand type for '%s' (%s)" %
(self.operator, self.operand.type))
- self.type = PyrexTypes.error_type
+ self.type = SpikeTypes.error_type
class NotNode(ExprNode):
@@ -2040,7 +2040,7 @@
def analyse_types(self, env):
self.operand.analyse_types(env)
self.operand = self.operand.coerce_to_boolean(env)
- self.type = PyrexTypes.c_int_type
+ self.type = SpikeTypes.c_int_type
def calculate_result_code(self):
return "(!%s)" % self.operand.result_code
@@ -2114,14 +2114,14 @@
if argtype.is_pyobject:
self.error("Cannot take address of Python variable")
return
- self.type = PyrexTypes.c_ptr_type(argtype)
+ self.type = SpikeTypes.c_ptr_type(argtype)
def check_const(self):
self.operand.check_const_addr()
def error(self, mess):
error(self.pos, mess)
- self.type = PyrexTypes.error_type
+ self.type = SpikeTypes.error_type
self.result_code = "<error>"
def calculate_result_code(self):
@@ -2218,7 +2218,7 @@
error(self.pos, "Cannot take sizeof void")
elif not arg_type.is_complete():
error(self.pos, "Cannot take sizeof incomplete type '%s'" % arg_type)
- self.type = PyrexTypes.c_int_type
+ self.type = SpikeTypes.c_int_type
def calculate_result_code(self):
arg_code = self.arg_type.declaration_code("")
@@ -2234,7 +2234,7 @@
def analyse_types(self, env):
self.operand.analyse_types(env)
- self.type = PyrexTypes.c_int_type
+ self.type = SpikeTypes.c_int_type
def calculate_result_code(self):
return "(sizeof(%s))" % self.operand.result_code
@@ -2313,7 +2313,7 @@
error(self.pos, "Invalid operand types for '%s' (%s; %s)" %
(self.operator, self.operand1.type,
self.operand2.type))
- self.type = PyrexTypes.error_type
+ self.type = SpikeTypes.error_type
class NumBinopNode(BinopNode):
@@ -2328,7 +2328,7 @@
def compute_c_result_type(self, type1, type2):
if self.c_types_okay(type1, type2):
- return PyrexTypes.widest_numeric_type(type1, type2)
+ return SpikeTypes.widest_numeric_type(type1, type2)
else:
return None
@@ -2393,7 +2393,7 @@
if type1.is_ptr and type2.is_int:
return type1
elif type1.is_ptr and type2.is_ptr:
- return PyrexTypes.c_int_type
+ return SpikeTypes.c_int_type
else:
return NumBinopNode.compute_c_result_type(
self, type1, type2)
@@ -2430,7 +2430,7 @@
def compute_c_result_type(self, type1, type2):
if self.c_types_okay(type1, type2):
- return PyrexTypes.c_double_type
+ return SpikeTypes.c_double_type
else:
return None
@@ -2459,12 +2459,12 @@
self.operand1 = self.operand1.coerce_to_pyobject(env)
self.operand2 = self.operand2.coerce_to_pyobject(env)
self.temp_bool = TempNode(self.pos,
- PyrexTypes.c_int_type, env)
+ SpikeTypes.c_int_type, env)
self.type = py_object_type
else:
self.operand1 = self.operand1.coerce_to_boolean(env)
self.operand2 = self.operand2.coerce_to_boolean(env)
- self.type = PyrexTypes.c_int_type
+ self.type = SpikeTypes.c_int_type
# For what we're about to do, it's vital that
# both operands be temp nodes.
self.operand1 = self.operand1.coerce_to_temp(env) #CTT
@@ -2639,7 +2639,7 @@
self.operand2 = self.operand2.coerce_to_simple(env)
self.cascade.coerce_cascaded_operands_to_temp(env)
self.check_operand_types(env)
- self.type = PyrexTypes.c_int_type
+ self.type = SpikeTypes.c_int_type
if self.is_pycmp or self.cascade:
self.is_temp = 1
@@ -2854,7 +2854,7 @@
def generate_result_code(self, code):
if self.type.typeobj_is_available():
code.putln(
- "if (!__Pyx_TypeTest(%s, %s)) %s" % (
+ "if (!__Spike_TypeTest(%s, %s)) %s" % (
self.arg.py_result(),
self.type.typeptr_cname,
code.error_goto(self.pos)))
@@ -2919,7 +2919,7 @@
def __init__(self, arg, env):
CoercionNode.__init__(self, arg)
- self.type = PyrexTypes.c_int_type
+ self.type = SpikeTypes.c_int_type
if arg.type.is_pyobject:
self.is_temp = 1
@@ -2997,7 +2997,7 @@
get_name_utility_code = \
"""
-static PyObject *__Pyx_GetName(PyObject *dict, char *name) {
+static PyObject *__Spike_GetName(PyObject *dict, char *name) {
PyObject *result;
result = PyObject_GetAttrString(dict, name);
if (!result)
@@ -3008,7 +3008,7 @@
get_name_interned_utility_code = \
"""
-static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name) {
+static PyObject *__Spike_GetName(PyObject *dict, PyObject *name) {
PyObject *result;
result = PyObject_GetAttr(dict, name);
if (!result)
@@ -3021,7 +3021,7 @@
import_utility_code = \
"""
-static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list) {
+static PyObject *__Spike_Import(PyObject *name, PyObject *from_list) {
PyObject *__import__ = 0;
PyObject *empty_list = 0;
PyObject *module = 0;
@@ -3062,7 +3062,7 @@
get_exception_utility_code = \
"""
-static PyObject *__Pyx_GetExcValue(void) {
+static PyObject *__Spike_GetExcValue(void) {
PyObject *type = 0, *value = 0, *tb = 0;
PyObject *result = 0;
PyThreadState *tstate = PyThreadState_Get();
@@ -3097,24 +3097,24 @@
unpacking_utility_code = \
"""
-static void __Pyx_UnpackError(void) {
+static void __Spike_UnpackError(void) {
PyErr_SetString(PyExc_ValueError, "unpack sequence of wrong size");
}
-static PyObject *__Pyx_UnpackItem(PyObject *seq, int i) {
+static PyObject *__Spike_UnpackItem(PyObject *seq, int i) {
PyObject *item;
if (!(item = PySequence_GetItem(seq, i))) {
if (PyErr_ExceptionMatches(PyExc_IndexError))
- __Pyx_UnpackError();
+ __Spike_UnpackError();
}
return item;
}
-static int __Pyx_EndUnpack(PyObject *seq, int i) {
+static int __Spike_EndUnpack(PyObject *seq, int i) {
PyObject *item;
if (item = PySequence_GetItem(seq, i)) {
Py_DECREF(item);
- __Pyx_UnpackError();
+ __Spike_UnpackError();
return -1;
}
PyErr_Clear();
@@ -3126,7 +3126,7 @@
type_test_utility_code = \
"""
-static int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type) {
+static int __Spike_TypeTest(PyObject *obj, PyTypeObject *type) {
if (!type) {
PyErr_Format(PyExc_SystemError, "Missing type object");
return 0;
@@ -3143,7 +3143,7 @@
create_class_utility_code = \
"""
-static PyObject *__Pyx_CreateClass(
+static PyObject *__Spike_CreateClass(
PyObject *bases, PyObject *dict, PyObject *name, char *modname)
{
PyObject *py_modname;
Modified: cs/babel/trunk/spike/Spike/Compiler/Lexicon.pickle
===================================================================
(Binary files differ)
Modified: cs/babel/trunk/spike/Spike/Compiler/Lexicon.py
===================================================================
--- cs/babel/trunk/spike/Spike/Compiler/Lexicon.py 2007-01-26 03:29:08 UTC (rev 5902)
+++ cs/babel/trunk/spike/Spike/Compiler/Lexicon.py 2007-01-26 04:10:35 UTC (rev 5903)
@@ -1,5 +1,5 @@
#
-# Pyrex Scanner - Lexical Definitions
+# Spike Scanner - Lexical Definitions
#
# Changing anything in this file will cause Lexicon.pickle
# to be rebuilt next time pyrexc is run.
@@ -8,7 +8,7 @@
string_prefixes = "cCrR"
def make_lexicon():
- from Pyrex.Plex import \
+ from Spike.Plex import \
Str, Any, AnyBut, AnyChar, Rep, Rep1, Opt, Bol, Eol, Eof, \
TEXT, IGNORE, State, Lexicon
from Scanning import Method
Modified: cs/babel/trunk/spike/Spike/Compiler/Main.py
===================================================================
--- cs/babel/trunk/spike/Spike/Compiler/Main.py 2007-01-26 03:29:08 UTC (rev 5902)
+++ cs/babel/trunk/spike/Spike/Compiler/Main.py 2007-01-26 04:10:35 UTC (rev 5903)
@@ -1,28 +1,28 @@
#
-# Pyrex Top Level
+# Spike Top Level
#
import os, sys
if sys.version_info[:2] < (2, 2):
- print >>sys.stderr, "Sorry, Pyrex requires Python 2.2 or later"
+ print >>sys.stderr, "Sorry, Spike requires Python 2.2 or later"
sys.exit(1)
import os
from time import time
import Version
-from Scanning import PyrexScanner
+from Scanning import SpikeScanner
import Errors
-from Errors import PyrexError, CompileError, error
+from Errors import SpikeError, CompileError, error
import Parsing
from Symtab import BuiltinScope, ModuleScope
import Code
-from Pyrex.Utils import replace_suffix
+from Spike.Utils import replace_suffix
verbose = 0
class Context:
# This class encapsulates the context needed for compiling
- # one or more Pyrex implementation files along with their
+ # one or more Spike implementation files along with their
# associated and imported declaration files. It includes
# the root of the module import namespace and the list
# of directories to search for include files.
@@ -133,7 +133,7 @@
def parse(self, source_filename, type_names, pxd):
# Parse the given source file and return a parse tree.
f = open(source_filename, "rU")
- s = PyrexScanner(f, source_filename,
+ s = SpikeScanner(f, source_filename,
type_names = type_names, context = self)
try:
tree = Parsing.p_module(s, pxd)
@@ -150,7 +150,7 @@
return name
def compile(self, source, options = None):
- # Compile a Pyrex implementation file in this context
+ # Compile a Spike implementation file in this context
# and return a CompilationResult.
if not options:
options = default_options
@@ -209,7 +209,7 @@
class CompilationOptions:
"""
- Options to the Pyrex compiler:
+ Options to the Spike compiler:
show_version boolean Display version number
use_listing_file boolean Generate a .lis file
@@ -235,7 +235,7 @@
class CompilationResult:
"""
- Results from the Pyrex compiler:
+ Results from the Spike compiler:
c_file string or None The generated C source file
h_file string or None The generated C header file
@@ -259,7 +259,7 @@
"""
compile(source, options = default_options)
- Compile the given Pyrex implementation file and return
+ Compile the given Spike implementation file and return
a CompilationResult object describing what was produced.
"""
if not options:
@@ -288,14 +288,14 @@
options = default_options
sources = args
if options.show_version:
- print >>sys.stderr, "Pyrex version %s" % Version.version
+ print >>sys.stderr, "Spike version %s" % Version.version
context = Context(options.include_path)
for source in sources:
try:
result = context.compile(source, options)
if result.num_errors > 0:
any_failures = 1
- except PyrexError, e:
+ except SpikeError, e:
print >>sys.stderr, e
any_failures = 1
if any_failures:
@@ -317,10 +317,10 @@
output_file = None)
if sys.platform == "mac":
- from Pyrex.Mac.MacSystem import c_compile, c_link, CCompilerError
+ from Spike.Mac.MacSystem import c_compile, c_link, CCompilerError
default_options.use_listing_file = 1
elif sys.platform == "darwin":
- from Pyrex.Mac.DarwinSystem import c_compile, c_link, CCompilerError
+ from Spike.Mac.DarwinSystem import c_compile, c_link, CCompilerError
else:
c_compile = None
c_link = None
Modified: cs/babel/trunk/spike/Spike/Compiler/Naming.py
===================================================================
--- cs/babel/trunk/spike/Spike/Compiler/Naming.py 2007-01-26 03:29:08 UTC (rev 5902)
+++ cs/babel/trunk/spike/Spike/Compiler/Naming.py 2007-01-26 04:10:35 UTC (rev 5903)
@@ -1,54 +1,54 @@
#
-# Pyrex - C naming conventions
+# Spike - C naming conventions
#
#
# Prefixes for generating C names.
# Collected here to facilitate ensuring uniqueness.
#
-pyrex_prefix = "__pyx_"
+spike_prefix = "__spike_"
-arg_prefix = pyrex_prefix + "arg_"
-funcdoc_prefix = pyrex_prefix + "doc_"
-enum_prefix = pyrex_prefix + "e_"
-func_prefix = pyrex_prefix + "f_"
-gstab_prefix = pyrex_prefix + "getsets_"
-prop_get_prefix = pyrex_prefix + "getprop_"
-const_prefix = pyrex_prefix + "k"
-label_prefix = pyrex_prefix + "L"
-pymethdef_prefix = pyrex_prefix + "mdef_"
-methtab_prefix = pyrex_prefix + "methods_"
-memtab_prefix = pyrex_prefix + "members_"
-interned_prefix = pyrex_prefix + "n_"
-objstruct_prefix = pyrex_prefix + "obj_"
-typeptr_prefix = pyrex_prefix + "ptype_"
-prop_set_prefix = pyrex_prefix + "setprop_"
-type_prefix = pyrex_prefix + "t_"
-typeobj_prefix = pyrex_prefix + "type_"
-var_prefix = pyrex_prefix + "v_"
-vtable_prefix = pyrex_prefix + "vtable_"
-vtabptr_prefix = pyrex_prefix + "vtabptr_"
-vtabstruct_prefix = pyrex_prefix + "vtabstruct_"
+arg_prefix = spike_prefix + "arg_"
+funcdoc_prefix = spike_prefix + "doc_"
+enum_prefix = spike_prefix + "e_"
+func_prefix = spike_prefix + "f_"
+gstab_prefix = spike_prefix + "getsets_"
+prop_get_prefix = spike_prefix + "getprop_"
+const_prefix = spike_prefix + "k"
+label_prefix = spike_prefix + "L"
+pymethdef_prefix = spike_prefix + "mdef_"
+methtab_prefix = spike_prefix + "methods_"
+memtab_prefix = spike_prefix + "members_"
+interned_prefix = spike_prefix + "n_"
+objstruct_prefix = spike_prefix + "obj_"
+typeptr_prefix = spike_prefix + "ptype_"
+prop_set_prefix = spike_prefix + "setprop_"
+type_prefix = spike_prefix + "t_"
+typeobj_prefix = spike_prefix + "type_"
+var_prefix = spike_prefix + "v_"
+vtable_prefix = spike_prefix + "vtable_"
+vtabptr_prefix = spike_prefix + "vtabptr_"
+vtabstruct_prefix = spike_prefix + "vtabstruct_"
-args_cname = pyrex_prefix + "args"
-kwdlist_cname = pyrex_prefix + "argnames"
-obj_base_cname = pyrex_prefix + "base"
-builtins_cname = pyrex_prefix + "b"
-moddict_cname = pyrex_prefix + "d"
-dummy_cname = pyrex_prefix + "dummy"
-filename_cname = pyrex_prefix + "filename"
-filetable_cname = pyrex_prefix + "f"
-filenames_cname = pyrex_prefix + "filenames"
-fileinit_cname = pyrex_prefix + "init_filenames"
-intern_tab_cname = pyrex_prefix + "intern_tab"
-kwds_cname = pyrex_prefix + "kwds"
-lineno_cname = pyrex_prefix + "lineno"
-module_cname = pyrex_prefix + "m"
-moddoc_cname = pyrex_prefix + "mdoc"
-methtable_cname = pyrex_prefix + "methods"
-retval_cname = pyrex_prefix + "r"
-self_cname = pyrex_prefix + "self"
-stringtab_cname = pyrex_prefix + "string_tab"
-vtabslot_cname = pyrex_prefix + "vtab"
+args_cname = spike_prefix + "args"
+kwdlist_cname = spike_prefix + "argnames"
+obj_base_cname = spike_prefix + "base"
+builtins_cname = spike_prefix + "b"
+moddict_cname = spike_prefix + "d"
+dummy_cname = spike_prefix + "dummy"
+filename_cname = spike_prefix + "filename"
+filetable_cname = spike_prefix + "f"
+filenames_cname = spike_prefix + "filenames"
+fileinit_cname = spike_prefix + "init_filenames"
+intern_tab_cname = spike_prefix + "intern_tab"
+kwds_cname = spike_prefix + "kwds"
+lineno_cname = spike_prefix + "lineno"
+module_cname = spike_prefix + "m"
+moddoc_cname = spike_prefix + "mdoc"
+methtable_cname = spike_prefix + "methods"
+retval_cname = spike_prefix + "r"
+self_cname = spike_prefix + "self"
+stringtab_cname = spike_prefix + "string_tab"
+vtabslot_cname = spike_prefix + "vtab"
-extern_c_macro = pyrex_prefix.upper() + "EXTERN_C"
+extern_c_macro = spike_prefix.upper() + "EXTERN_C"
Modified: cs/babel/trunk/spike/Spike/Compiler/Nodes.py
===================================================================
--- cs/babel/trunk/spike/Spike/Compiler/Nodes.py 2007-01-26 03:29:08 UTC (rev 5902)
+++ cs/babel/trunk/spike/Spike/Compiler/Nodes.py 2007-01-26 04:10:35 UTC (rev 5903)
@@ -1,5 +1,5 @@
#
-# Pyrex - Parse tree nodes
+# Spike - Parse tree nodes
#
import os, string, sys, time
@@ -7,13 +7,13 @@
import Code
from Errors import error, InternalError
import Naming
-import PyrexTypes
-from PyrexTypes import py_object_type, error_type, CTypedefType
+import SpikeTypes
+from SpikeTypes import py_object_type, error_type, CTypedefType
from Symtab import ModuleScope, LocalScope, \
StructOrUnionScope, PyClassScope, CClassScope
import TypeSlots
import Version
-from Pyrex.Utils import open_new_file, replace_suffix
+from Spike.Utils import open_new_file, replace_suffix
import Options
from DebugFlags import debug_disposal_code
@@ -109,7 +109,7 @@
self.analyse_declarations(env)
env.check_c_classes()
self.body.analyse_expressions(env)
- env.return_type = PyrexTypes.c_void_type
+ env.return_type = SpikeTypes.c_void_type
self.generate_c_code(env, result)
self.generate_h_code(env, result)
@@ -129,7 +129,7 @@
result.h_file = replace_suffix(result.c_file, ".h")
result.i_file = replace_suffix(result.c_file, ".pxi")
h_code = Code.CCodeWriter(result.h_file)
- i_code = Code.PyrexCodeWriter(result.i_file)
+ i_code = Code.SpikeCodeWriter(result.i_file)
self.generate_extern_c_macro_definition(h_code)
for entry in public_vars_and_funcs:
h_code.putln("%s %s;" % (
@@ -196,7 +196,7 @@
module_list.append(env)
def generate_module_preamble(self, env, cimported_modules, code):
- code.putln('/* Generated by Pyrex %s on %s */' % (
+ code.putln('/* Generated by Spike %s on %s */' % (
Version.version, time.asctime()))
code.putln('')
for filename in env.python_include_files:
@@ -1052,7 +1052,7 @@
items.sort()
code.putln("")
code.putln(
- "static __Pyx_InternTabEntry %s[] = {" %
+ "static __Spike_InternTabEntry %s[] = {" %
Naming.intern_tab_cname)
for (name, cname) in items:
code.putln(
@@ -1069,7 +1069,7 @@
if entries:
code.putln("")
code.putln(
- "static __Pyx_StringTabEntry %s[] = {" %
+ "static __Spike_StringTabEntry %s[] = {" %
Naming.stringtab_cname)
for entry in entries:
code.putln(
@@ -1113,7 +1113,7 @@
code.putln("return;")
code.put_label(code.error_label)
code.put_var_xdecrefs(env.temp_entries)
- code.putln('__Pyx_AddTraceback("%s");' % (env.qualified_name))
+ code.putln('__Spike_AddTraceback("%s");' % (env.qualified_name))
env.use_utility_code(traceback_utility_code)
code.putln('}')
@@ -1154,7 +1154,7 @@
if env.intern_map:
env.use_utility_code(init_intern_tab_utility_code);
code.putln(
- "if (__Pyx_InternStrings(%s) < 0) %s;" % (
+ "if (__Spike_InternStrings(%s) < 0) %s;" % (
Naming.intern_tab_cname,
code.error_goto(self.pos)))
@@ -1162,7 +1162,7 @@
if env.all_pystring_entries:
env.use_utility_code(init_string_tab_utility_code)
code.putln(
- "if (__Pyx_InitStrings(%s) < 0) %s;" % (
+ "if (__Spike_InitStrings(%s) < 0) %s;" % (
Naming.stringtab_cname,
code.error_goto(self.pos)))
@@ -1206,7 +1206,7 @@
objstruct = type.objstruct_cname
else:
objstruct = "struct %s" % type.objstruct_cname
- code.putln('%s = __Pyx_ImportType("%s", "%s", sizeof(%s)); if (!%s) %s' % (
+ code.putln('%s = __Spike_ImportType("%s", "%s", sizeof(%s)); if (!%s) %s' % (
type.typeptr_cname,
type.module_name,
type.name,
@@ -1216,7 +1216,7 @@
self.use_type_import_utility_code(env)
if type.vtabptr_cname:
code.putln(
- "if (__Pyx_GetVtable(%s->tp_dict, &%s) < 0) %s" % (
+ "if (__Spike_GetVtable(%s->tp_dict, &%s) < 0) %s" % (
type.typeptr_cname,
type.vtabptr_cname,
code.error_goto(entry.pos)))
@@ -1238,7 +1238,7 @@
code.error_goto(entry.pos)))
if type.vtable_cname:
code.putln(
- "if (__Pyx_SetVtable(%s.tp_dict, %s) < 0) %s" % (
+ "if (__Spike_SetVtable(%s.tp_dict, %s) < 0) %s" % (
typeobj_cname,
type.vtabptr_cname,
code.error_goto(entry.pos)))
@@ -1384,7 +1384,7 @@
class CNameDeclaratorNode(CDeclaratorNode):
- # name string The Pyrex name being declared
+ # name string The Spike name being declared
# cname string or None C name, if specified
def analyse(self, base_type, env):
@@ -1398,7 +1398,7 @@
if base_type.is_pyobject:
error(self.pos,
"Pointer base type cannot be a Python object")
- ptr_type = PyrexTypes.c_ptr_type(base_type)
+ ptr_type = SpikeTypes.c_ptr_type(base_type)
return self.base.analyse(ptr_type, env)
@@ -1421,7 +1421,7 @@
if base_type.is_pyobject:
error(self.pos,
"Array element cannot be a Python object")
- array_type = PyrexTypes.c_array_type(base_type, size)
+ array_type = SpikeTypes.c_array_type(base_type, size)
return self.base.analyse(array_type, env)
@@ -1442,12 +1442,12 @@
"Function argument cannot have C name specification")
# Turn *[] argument into **
if type.is_array:
- type = PyrexTypes.c_ptr_type(type.base_type)
+ type = SpikeTypes.c_ptr_type(type.base_type)
# Catch attempted C-style func(void) decl
if type.is_void:
error(arg_node.pos, "Function argument cannot be void")
func_type_args.append(
- PyrexTypes.CFuncTypeArg(name, type, arg_node.pos))
+ SpikeTypes.CFuncTypeArg(name, type, arg_node.pos))
if arg_node.default:
error(arg_node.pos, "C function argument cannot have default value")
exc_val = None
@@ -1464,7 +1464,7 @@
error(self.exception_value.pos,
"Exception value incompatible with function return type")
exc_check = self.exception_check
- func_type = PyrexTypes.CFuncType(
+ func_type = SpikeTypes.CFuncType(
return_type, func_type_args, self.has_varargs,
exception_value = exc_val, exception_check = exc_check)
return self.base.analyse(func_type, env)
@@ -1510,7 +1510,7 @@
# Return type descriptor.
type = None
if self.is_basic_c_type:
- type = PyrexTypes.simple_c_type(self.signed, self.longness, self.name)
+ type = SpikeTypes.simple_c_type(self.signed, self.longness, self.name)
if not type:
error(self.pos, "Unrecognised type modifier combination")
elif self.name == "object" and not self.module_path:
@@ -1540,7 +1540,7 @@
if type:
return type
else:
- return PyrexTypes.error_type
+ return SpikeTypes.error_type
class CComplexBaseTypeNode(CBaseTypeNode):
@@ -1674,7 +1674,7 @@
class FuncDefNode(StatNode, BlockNode):
# Base class for function definition nodes.
#
- # return_type PyrexType
+ # return_type SpikeType
# #filename string C name of filename string const
# entry Symtab.Entry
@@ -1751,7 +1751,7 @@
exc_check = self.caller_will_check_exceptions()
if err_val is not None or exc_check:
code.putln(
- '__Pyx_AddTraceback("%s");' %
+ '__Spike_AddTraceback("%s");' %
self.entry.qualified_name)
if err_val is not None:
code.putln(
@@ -1760,7 +1760,7 @@
err_val))
else:
code.putln(
- '__Pyx_WriteUnraisable("%s");' %
+ '__Spike_WriteUnraisable("%s");' %
self.entry.qualified_name)
env.use_utility_code(unraisable_exception_utility_code)
# ----- Return cleanup
@@ -2026,7 +2026,7 @@
def declare_python_arg(self, env, arg):
if arg:
arg.entry = env.declare_var(arg.name,
- PyrexTypes.py_object_type, arg.pos)
+ SpikeTypes.py_object_type, arg.pos)
arg.entry.init = "0"
arg.entry.init_to_none = 0
arg.entry.xdecref_cleanup = 1
@@ -2183,7 +2183,7 @@
star_arg_addr = self.arg_address(self.star_arg)
starstar_arg_addr = self.arg_address(self.starstar_arg)
code.putln(
- "if (__Pyx_GetStarArgs(&%s, &%s, %s, %s, %s, %s) < 0) return %s;" % (
+ "if (__Spike_GetStarArgs(&%s, &%s, %s, %s, %s, %s) < 0) return %s;" % (
Naming.args_cname,
Naming.kwds_cname,
Naming.kwdlist_cname,
@@ -2259,7 +2259,7 @@
typeptr_cname = arg.type.typeptr_cname
arg_code = "((PyObject *)%s)" % arg.entry.cname
code.putln(
- 'if (!__Pyx_ArgTypeTest(%s, %s, %d, "%s")) %s' % (
+ 'if (!__Spike_ArgTypeTest(%s, %s, %d, "%s")) %s' % (
arg_code,
typeptr_cname,
not arg.not_none,
@@ -2674,13 +2674,13 @@
for arg in self.args:
arg.generate_evaluation_code(code)
code.putln(
- "if (__Pyx_PrintItem(%s) < 0) %s" % (
+ "if (__Spike_PrintItem(%s) < 0) %s" % (
arg.py_result(),
code.error_goto(self.pos)))
arg.generate_disposal_code(code)
if not self.ends_with_comma:
code.putln(
- "if (__Pyx_PrintNewline() < 0) %s" %
+ "if (__Spike_PrintNewline() < 0) %s" %
code.error_goto(self.pos))
@@ -2751,7 +2751,7 @@
# return statement
#
# value ExprNode or None
- # return_type PyrexType
+ # return_type SpikeType
# temps_in_use [Entry] Temps in use at time of return
def analyse_expressions(self, env):
@@ -2853,13 +2853,13 @@
tb_code = "0"
if self.exc_type or self.exc_value or self.exc_tb:
code.putln(
- "__Pyx_Raise(%s, %s, %s);" % (
+ "__Spike_Raise(%s, %s, %s);" % (
type_code,
value_code,
tb_code))
else:
code.putln(
- "__Pyx_ReRaise();")
+ "__Spike_ReRaise();")
if self.exc_type:
self.exc_type.generate_disposal_code(code)
if self.exc_value:
@@ -3095,7 +3095,7 @@
self.bound2 = self.bound2.coerce_to_temp(env)
target_type = self.target.type
if not (target_type.is_pyobject
- or target_type.assignable_from(PyrexTypes.c_int_type)):
+ or target_type.assignable_from(SpikeTypes.c_int_type)):
error(self.target.pos,
"Cannot assign integer to variable of type '%s'" % target_type)
if target_type.is_int:
@@ -3103,7 +3103,7 @@
self.py_loopvar_node = None
else:
c_loopvar_node = ExprNodes.TempNode(self.pos,
- PyrexTypes.c_long_type, env)
+ SpikeTypes.c_long_type, env)
c_loopvar_node.allocate_temps(env)
self.loopvar_name = c_loopvar_node.result_code
self.py_loopvar_node = \
@@ -3242,7 +3242,7 @@
if self.pattern:
self.pattern.analyse_expressions(env)
self.pattern = self.pattern.coerce_to_pyobject(env)
- self.match_flag = env.allocate_temp(PyrexTypes.c_int_type)
+ self.match_flag = env.allocate_temp(SpikeTypes.c_int_type)
self.pattern.release_temp(env)
env.release_temp(self.match_flag)
self.exc_value = ExprNodes.ExcValueNode(self.pos, env)
@@ -3271,7 +3271,7 @@
code.putln(
"/*except:*/ {")
code.putln(
- '__Pyx_AddTraceback("%s");' % (self.function_name))
+ '__Spike_AddTraceback("%s");' % (self.function_name))
# We always have to fetch the exception value even if
# there is no target, because this also normalises the
# exception and stores it in the thread state.
@@ -3318,11 +3318,11 @@
self.body.analyse_expressions(env)
self.cleanup_list = env.free_temp_entries[:]
self.exc_vars = (
- env.allocate_temp(PyrexTypes.py_object_type),
- env.allocate_temp(PyrexTypes.py_object_type),
- env.allocate_temp(PyrexTypes.py_object_type))
+ env.allocate_temp(SpikeTypes.py_object_type),
+ env.allocate_temp(SpikeTypes.py_object_type),
+ env.allocate_temp(SpikeTypes.py_object_type))
self.lineno_var = \
- env.allocate_temp(PyrexTypes.c_int_type)
+ env.allocate_temp(SpikeTypes.c_int_type)
self.finally_clause.analyse_expressions(env)
for var in self.exc_vars:
env.release_temp(var)
@@ -3540,41 +3540,41 @@
utility_function_predeclarations = \
"""
-typedef struct {PyObject **p; char *s;} __Pyx_InternTabEntry; /*proto*/
-typedef struct {PyObject **p; char *s; long n;} __Pyx_StringTabEntry; /*proto*/
-static PyObject *__Pyx_UnpackItem(PyObject *, int); /*proto*/
-static int __Pyx_EndUnpack(PyObject *, int); /*proto*/
-static int __Pyx_PrintItem(PyObject *); /*proto*/
-static int __Pyx_PrintNewline(void); /*proto*/
-static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb); /*proto*/
-static void __Pyx_ReRaise(void); /*proto*/
-static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list); /*proto*/
-static PyObject *__Pyx_GetExcValue(void); /*proto*/
-static int __Pyx_ArgTypeTest(PyObject *obj, PyTypeObject *type, int none_allowed, char *name); /*proto*/
-static int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type); /*proto*/
-static int __Pyx_GetStarArgs(PyObject **args, PyObject **kwds,\
+typedef struct {PyObject **p; char *s;} __Spike_InternTabEntry; /*proto*/
+typedef struct {PyObject **p; char *s; long n;} __Spike_StringTabEntry; /*proto*/
+static PyObject *__Spike_UnpackItem(PyObject *, int); /*proto*/
+static int __Spike_EndUnpack(PyObject *, int); /*proto*/
+static int __Spike_PrintItem(PyObject *); /*proto*/
+static int __Spike_PrintNewline(void); /*proto*/
+static void __Spike_Raise(PyObject *type, PyObject *value, PyObject *tb); /*proto*/
+static void __Spike_ReRaise(void); /*proto*/
+static PyObject *__Spike_Import(PyObject *name, PyObject *from_list); /*proto*/
+static PyObject *__Spike_GetExcValue(void); /*proto*/
+static int __Spike_ArgTypeTest(PyObject *obj, PyTypeObject *type, int none_allowed, char *name); /*proto*/
+static int __Spike_TypeTest(PyObject *obj, PyTypeObject *type); /*proto*/
+static int __Spike_GetStarArgs(PyObject **args, PyObject **kwds,\
char *kwd_list[], int nargs, PyObject **args2, PyObject **kwds2); /*proto*/
-static void __Pyx_WriteUnraisable(char *name); /*proto*/
-static void __Pyx_AddTraceback(char *funcname); /*proto*/
-static PyTypeObject *__Pyx_ImportType(char *module_name, char *class_name, long size); /*proto*/
-static int __Pyx_SetVtable(PyObject *dict, void *vtable); /*proto*/
-static int __Pyx_GetVtable(PyObject *dict, void *vtabptr); /*proto*/
-static PyObject *__Pyx_CreateClass(PyObject *bases, PyObject *dict, PyObject *name, char *modname); /*proto*/
-static int __Pyx_InternStrings(__Pyx_InternTabEntry *t); /*proto*/
-static int __Pyx_InitStrings(__Pyx_StringTabEntry *t); /*proto*/
+static void __Spike_WriteUnraisable(char *name); /*proto*/
+static void __Spike_AddTraceback(char *funcname); /*proto*/
+static PyTypeObject *__Spike_ImportType(char *module_name, char *class_name, long size); /*proto*/
+static int __Spike_SetVtable(PyObject *dict, void *vtable); /*proto*/
+static int __Spike_GetVtable(PyObject *dict, void *vtabptr); /*proto*/
+static PyObject *__Spike_CreateClass(PyObject *bases, PyObject *dict, PyObject *name, char *modname); /*proto*/
+static int __Spike_InternStrings(__Spike_InternTabEntry *t); /*proto*/
+static int __Spike_InitStrings(__Spike_StringTabEntry *t); /*proto*/
"""
get_name_predeclaration = \
-"static PyObject *__Pyx_GetName(PyObject *dict, char *name); /*proto*/"
+"static PyObject *__Spike_GetName(PyObject *dict, char *name); /*proto*/"
get_name_interned_predeclaration = \
-"static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name); /*proto*/"
+"static PyObject *__Spike_GetName(PyObject *dict, PyObject *name); /*proto*/"
#------------------------------------------------------------------------------------
printing_utility_code = \
r"""
-static PyObject *__Pyx_GetStdout(void) {
+static PyObject *__Spike_GetStdout(void) {
PyObject *f = PySys_GetObject("stdout");
if (!f) {
PyErr_SetString(PyExc_RuntimeError, "lost sys.stdout");
@@ -3582,10 +3582,10 @@
return f;
}
-static int __Pyx_PrintItem(PyObject *v) {
+static int __Spike_PrintItem(PyObject *v) {
PyObject *f;
- if (!(f = __Pyx_GetStdout()))
+ if (!(f = __Spike_GetStdout()))
return -1;
if (PyFile_SoftSpace(f, 1)) {
if (PyFile_WriteString(" ", f) < 0)
@@ -3604,10 +3604,10 @@
return 0;
}
-static int __Pyx_PrintNewline(void) {
+static int __Spike_PrintNewline(void) {
PyObject *f;
- if (!(f = __Pyx_GetStdout()))
+ if (!(f = __Spike_GetStdout()))
return -1;
if (PyFile_WriteString("\n", f) < 0)
return -1;
@@ -3622,7 +3622,7 @@
raise_utility_code = \
"""
-static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb) {
+static void __Spike_Raise(PyObject *type, PyObject *value, PyObject *tb) {
Py_XINCREF(type);
Py_XINCREF(value);
Py_XINCREF(tb);
@@ -3689,7 +3689,7 @@
reraise_utility_code = \
"""
-static void __Pyx_ReRaise(void) {
+static void __Spike_ReRaise(void) {
PyThreadState *tstate = PyThreadState_Get();
PyObject *type = tstate->exc_type;
PyObject *value = tstate->exc_value;
@@ -3705,7 +3705,7 @@
arg_type_test_utility_code = \
"""
-static int __Pyx_ArgTypeTest(PyObject *obj, PyTypeObject *type, int none_allowed, char *name) {
+static int __Spike_ArgTypeTest(PyObject *obj, PyTypeObject *type, int none_allowed, char *name) {
if (!type) {
PyErr_Format(PyExc_SystemError, "Missing type object");
return 0;
@@ -3721,7 +3721,7 @@
#------------------------------------------------------------------------------------
#
-# __Pyx_GetStarArgs splits the args tuple and kwds dict into two parts
+# __Spike_GetStarArgs splits the args tuple and kwds dict into two parts
# each, one part suitable for passing to PyArg_ParseTupleAndKeywords,
# and the other containing any extra arguments. On success, replaces
# the borrowed references *args and *kwds with references to a new
@@ -3735,7 +3735,7 @@
get_starargs_utility_code = \
"""
-static int __Pyx_GetStarArgs(
+static int __Spike_GetStarArgs(
PyObject **args,
PyObject **kwds,
char *kwd_list[],
@@ -3811,7 +3811,7 @@
unraisable_exception_utility_code = \
"""
-static void __Pyx_WriteUnraisable(char *name) {
+static void __Spike_WriteUnraisable(char *name) {
PyObject *old_exc, *old_val, *old_tb;
PyObject *ctx;
PyErr_Fetch(&old_exc, &old_val, &old_tb);
@@ -3831,7 +3831,7 @@
#include "frameobject.h"
#include "traceback.h"
-static void __Pyx_AddTraceback(char *funcname) {
+static void __Spike_AddTraceback(char *funcname) {
PyObject *py_srcfile = 0;
PyObject *py_funcname = 0;
PyObject *py_globals = 0;
@@ -3894,7 +3894,7 @@
type_import_utility_code = \
"""
-static PyTypeObject *__Pyx_ImportType(char *module_name, char *class_name,
+static PyTypeObject *__Spike_ImportType(char *module_name, char *class_name,
long size)
{
PyObject *py_module_name = 0;
@@ -3915,7 +3915,7 @@
Py_INCREF(py_class_name);
if (PyList_SetItem(py_name_list, 0, py_class_name) < 0)
goto bad;
- py_module = __Pyx_Import(py_module_name, py_name_list);
+ py_module = __Spike_Import(py_module_name, py_name_list);
if (!py_module)
goto bad;
result = PyObject_GetAttr(py_module, py_class_name);
@@ -3949,7 +3949,7 @@
set_vtable_utility_code = \
"""
-static int __Pyx_SetVtable(PyObject *dict, void *vtable) {
+static int __Spike_SetVtable(PyObject *dict, void *vtable) {
PyObject *pycobj = 0;
int result;
@@ -3973,7 +3973,7 @@
get_vtable_utility_code = \
r"""
-static int __Pyx_GetVtable(PyObject *dict, void *vtabptr) {
+static int __Spike_GetVtable(PyObject *dict, void *vtabptr) {
int result;
PyObject *pycobj;
@@ -3998,7 +3998,7 @@
init_intern_tab_utility_code = \
"""
-static int __Pyx_InternStrings(__Pyx_InternTabEntry *t) {
+static int __Spike_InternStrings(__Spike_InternTabEntry *t) {
while (t->p) {
*t->p = PyString_InternFromString(t->s);
if (!*t->p)
@@ -4013,7 +4013,7 @@
init_string_tab_utility_code = \
"""
-static int __Pyx_InitStrings(__Pyx_StringTabEntry *t) {
+static int __Spike_InitStrings(__Spike_StringTabEntry *t) {
while (t->p) {
*t->p = PyString_FromStringAndSize(t->s, t->n - 1);
if (!*t->p)
Modified: cs/babel/trunk/spike/Spike/Compiler/Options.py
===================================================================
--- cs/babel/trunk/spike/Spike/Compiler/Options.py 2007-01-26 03:29:08 UTC (rev 5902)
+++ cs/babel/trunk/spike/Spike/Compiler/Options.py 2007-01-26 04:10:35 UTC (rev 5903)
@@ -1,5 +1,5 @@
#
-# Pyrex - Compilation-wide options
+# Spike - Compilation-wide options
#
intern_names = 1 # Intern global variable and attribute names
Modified: cs/babel/trunk/spike/Spike/Compiler/Parsing.py
===================================================================
--- cs/babel/trunk/spike/Spike/Compiler/Parsing.py 2007-01-26 03:29:08 UTC (rev 5902)
+++ cs/babel/trunk/spike/Spike/Compiler/Parsing.py 2007-01-26 04:10:35 UTC (rev 5903)
@@ -1,11 +1,11 @@
#
-# Pyrex Parser
+# Spike Parser
#
import os, re
from string import join, replace
from types import ListType, TupleType
-from Scanning import PyrexScanner
+from Scanning import SpikeScanner
import Nodes
import ExprNodes
from Errors import error, InternalError
@@ -1048,7 +1048,7 @@
include_file_path = s.context.find_include_file(include_file_name, pos)
if include_file_path:
f = open(include_file_path, "rU")
- s2 = PyrexScanner(f, include_file_path, s)
+ s2 = SpikeScanner(f, include_file_path, s)
try:
tree = p_statement_list(s2, level)
finally:
Deleted: cs/babel/trunk/spike/Spike/Compiler/PyrexTypes.py
===================================================================
--- cs/babel/trunk/spike/Spike/Compiler/PyrexTypes.py 2007-01-26 03:29:08 UTC (rev 5902)
+++ cs/babel/trunk/spike/Spike/Compiler/PyrexTypes.py 2007-01-26 04:10:35 UTC (rev 5903)
@@ -1,821 +0,0 @@
-#
-# Pyrex - Types
-#
-
-import string
-import Naming
-
-class PyrexType:
- #
- # Base class for all Pyrex types.
- #
- # is_pyobject boolean Is a Python object type
- # is_extension_type boolean Is a Python extension type
- # is_numeric boolean Is a C numeric type
- # is_int boolean Is a C integer type
- # is_float boolean Is a C floating point type
- # is_void boolean Is the C void type
- # is_array boolean Is a C array type
- # is_ptr boolean Is a C pointer type
- # is_null_ptr boolean Is the type of NULL
- # is_cfunction boolean Is a C function type
- # is_struct_or_union boolean Is a C struct or union type
- # is_enum boolean Is a C enum type
- # is_string boolean Is a C char * type
- # is_returncode boolean Is used only to signal exceptions
- # is_error boolean Is the dummy error type
- # has_attributes boolean Has C dot-selectable attributes
- # default_value string Initial value
- # parsetuple_format string Format char for PyArg_ParseTuple
- # pymemberdef_typecode string Type code for PyMemberDef struct
- #
- # declaration_code(entity_code,
- # for_display = 0, dll_linkage = None, pyrex = 0)
- # Returns a code fragment for the declaration of an entity
- # of this type, given a code fragment for the entity.
- # * If for_display, this is for reading by a human in an error
- # message; otherwise it must be valid C code.
- # * If dll_linkage is not None, it must be 'DL_EXPORT' or
- # 'DL_IMPORT', and will be added to the base type part of
- # the declaration.
- # * If pyrex = 1, this is for use in a 'cdef extern'
- # statement of a Pyrex include file.
- #
- # assignable_from(src_type)
- # Tests whether a variable of this type can be
- # assigned a value of type src_type.
- #
- # same_as(other_type)
- # Tests whether this type represents the same type
- # as other_type.
- #
- # as_argument_type():
- # Coerces array type into pointer type for use as
- # a formal argument type.
- #
-
- is_pyobject = 0
- is_extension_type = 0
- is_numeric = 0
- is_int = 0
- is_float = 0
- is_void = 0
- is_array = 0
- is_ptr = 0
- is_null_ptr = 0
- is_cfunction = 0
- is_struct_or_union = 0
- is_enum = 0
- is_string = 0
- is_returncode = 0
- is_error = 0
- has_attributes = 0
- default_value = ""
- parsetuple_format = ""
- pymemberdef_typecode = None
-
- def resolve(self):
- # If a typedef, returns the base type.
- return self
-
- def literal_code(self, value):
- # Returns a C code fragment representing a literal
- # value of this type.
- return str(value)
-
- def __str__(self):
- return string.strip(self.declaration_code("", for_display = 1))
-
- def same_as(self, other_type, **kwds):
- return self.same_as_resolved_type(other_type.resolve(), **kwds)
-
- def same_as_resolved_type(self, other_type):
- return self is other_type or other_type is error_type
-
- def subtype_of(self, other_type):
- return self.subtype_of_resolved_type(other_type.resolve())
-
- def subtype_of_resolved_type(self, other_type):
- return self.same_as(other_type)
-
- def assignable_from(self, src_type):
- return self.assignable_from_resolved_type(src_type.resolve())
-
- def assignable_from_resolved_type(self, src_type):
- return self.same_as(src_type)
-
- def as_argument_type(self):
- return self
-
- def is_complete(self):
- # A type is incomplete if it is an unsized array,
- # a struct whose attributes are not defined, etc.
- return 1
-
- def cast_code(self, expr_code):
- return "((%s)%s)" % (self.declaration_code(""), expr_code)
-
-
-class CTypedefType:
- #
- # Type defined with a ctypedef statement in a
- # 'cdef extern from' block. Delegates most attribute
- # lookups to the base type.
- #
-
- def __init__(self, cname, base_type):
- self.typedef_cname = cname
- self.typedef_base_type = base_type
-
- def resolve(self):
- return self.typedef_base_type.resolve()
-
- def declaration_code(self, entity_code,
- for_display = 0, dll_linkage = None, pyrex = 0):
- return "%s %s" % (self.typedef_cname, entity_code)
-
- def __str__(self):
- return self.typedef_cname
-
- def __getattr__(self, name):
- return getattr(self.typedef_base_type, name)
-
-
-class PyObjectType(PyrexType):
- #
- # Base class for all Python object types (reference-counted).
- #
-
- is_pyobject = 1
- default_value = "0"
- parsetuple_format = "O"
- pymemberdef_typecode = "T_OBJECT"
-
- def __str__(self):
- return "Python object"
-
- def __repr__(self):
- return "PyObjectType"
-
- def assignable_from(self, src_type):
- return 1 # Conversion will be attempted
-
- def declaration_code(self, entity_code,
- for_display = 0, dll_linkage = None, pyrex = 0):
- if pyrex:
- return "object %s" % entity_code
- else:
- return "%s *%s" % (public_decl("PyObject", dll_linkage), entity_code)
-
-
-class PyExtensionType(PyObjectType):
- #
- # A Python extension type.
- #
- # name string
- # scope CClassScope Attribute namespace
- # visibility string
- # typedef_flag boolean
- # base_type PyExtensionType or None
- # module_name string or None Qualified name of defining module
- # objstruct_cname string Name of PyObject struct
- # typeobj_cname string or None C code fragment referring to type object
- # typeptr_cname string or None Name of pointer to external type object
- # vtabslot_cname string Name of C method table member
- # vtabstruct_cname string Name of C method table struct
- # vtabptr_cname string Name of pointer to C method table
- # vtable_cname string Name of C method table definition
-
- is_extension_type = 1
- has_attributes = 1
-
- def __init__(self, name, typedef_flag, base_type):
- self.name = name
- self.scope = None
- self.typedef_flag = typedef_flag
- self.base_type = base_type
- self.module_name = None
- self.objstruct_cname = None
- self.typeobj_cname = None
- self.typeptr_cname = None
- self.vtabslot_cname = None
- self.vtabstruct_cname = None
- self.vtabptr_cname = None
- self.vtable_cname = None
-
- def set_scope(self, scope):
- self.scope = scope
- if scope:
- scope.parent_type = self
-
- def subtype_of_resolved_type(self, other_type):
- if other_type.is_extension_type:
- return self is other_type or (
- self.base_type and self.base_type.subtype_of(other_type))
- else:
- return other_type is py_object_type
-
- def typeobj_is_available(self):
- # Do we have a pointer to the type object?
- return self.typeptr_cname
-
- def typeobj_is_imported(self):
- # If we don't know the C name of the type object but we do
- # know which module it's defined in, it will be imported.
- return self.typeobj_cname is None and self.module_name is not None
-
- def declaration_code(self, entity_code,
- for_display = 0, dll_linkage = None, pyrex = 0):
- if pyrex:
- return "%s %s" % (self.name, entity_code)
- else:
- if self.typedef_flag:
- base_format = "%s"
- else:
- base_format = "struct %s"
- base = public_decl(base_format % self.objstruct_cname, dll_linkage)
- return "%s *%s" % (base, entity_code)
-
- def attributes_known(self):
- return self.scope is not None
-
- def __str__(self):
- return self.name
-
- def __repr__(self):
- return "PyExtensionType(%s%s)" % (self.scope.class_name,
- ("", ".typedef_flag=1")[self.typedef_flag])
-
-
-class CType(PyrexType):
- #
- # Base class for all C types (non-reference-counted).
- #
- # to_py_function string C function for converting to Python object
- # from_py_function string C function for constructing from Python object
- #
-
- to_py_function = None
- from_py_function = None
-
-
-class CSimpleType(CType):
- #
- # Base class for all unstructured C types.
- #
- pass
-
-
-class CVoidType(CSimpleType):
- is_void = 1
-
- def __repr__(self):
- return "<CVoidType>"
-
- def declaration_code(self, entity_code,
- for_display = 0, dll_linkage = None, pyrex = 0):
- base = public_decl("void", dll_linkage)
- return "%s %s" % (base, entity_code)
-
- def is_complete(self):
- return 0
-
-
-class CNumericType(CType):
- #
- # Base class for all C numeric types.
- #
- # rank integer Relative size
- # signed boolean
- #
-
- is_numeric = 1
- default_value = "0"
-
- parsetuple_formats = ( # rank -> format
- "?HIkK???", # unsigned
- "chilLfd?", # signed
- )
-
- def __init__(self, rank, signed = 1, pymemberdef_typecode = None):
- self.rank = rank
- self.signed = signed
- ptf = self.parsetuple_formats[signed][rank]
- if ptf == '?':
- ptf = None
- self.parsetuple_format = ptf
- self.pymemberdef_typecode = pymemberdef_typecode
-
- def __repr__(self):
- if self.signed:
- u = ""
- else:
- 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:
- u = ""
- else:
- u = "unsigned "
- 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):
-
- is_int = 1
- typedef_flag = 0
- to_py_function = "PyInt_FromLong"
- from_py_function = "PyInt_AsLong"
-
- def __init__(self, rank, signed, pymemberdef_typecode = None, is_returncode = 0):
- CNumericType.__init__(self, rank, signed, pymemberdef_typecode)
- self.is_returncode = is_returncode
-
-
-class CUIntType(CIntType):
-
- to_py_function = "PyLong_FromUnsignedLong"
- from_py_function = "PyInt_AsUnsignedLongMask"
-
-
-class CULongType(CIntType):
-
- to_py_function = "PyLong_FromUnsignedLong"
- from_py_function = "PyInt_AsUnsignedLongMask"
-
-
-class CLongLongType(CIntType):
-
- to_py_function = "PyLong_FromLongLong"
- from_py_function = "PyInt_AsUnsignedLongLongMask"
-
-
-class CULongLongType(CIntType):
-
- to_py_function = "PyLong_FromUnsignedLongLong"
- from_py_function = "PyInt_AsUnsignedLongLongMask"
-
-
-class CFloatType(CNumericType):
-
- is_float = 1
- to_py_function = "PyFloat_FromDouble"
- from_py_function = "PyFloat_AsDouble"
-
- def __init__(self, rank, pymemberdef_typecode = None):
- CNumericType.__init__(self, rank, 1, pymemberdef_typecode)
-
-
-class CArrayType(CType):
- # base_type CType Element type
- # size integer or None Number of elements
-
- is_array = 1
-
- def __init__(self, base_type, size):
- self.base_type = base_type
- self.size = size
- if base_type is c_char_type:
- self.is_string = 1
-
- def __repr__(self):
- return "CArrayType(%s,%s)" % (self.size, repr(self.base_type))
-
- def same_as_resolved_type(self, other_type):
- return ((other_type.is_array and
- self.base_type.same_as(other_type.base_type))
- or other_type is error_type)
-
- def assignable_from_resolved_type(self, src_type):
- # Can't assign to a variable of an array type
- return 0
-
- def element_ptr_type(self):
- return c_ptr_type(self.base_type)
-
- def declaration_code(self, entity_code,
- for_display = 0, dll_linkage = None, pyrex = 0):
- if self.size is not None:
- dimension_code = self.size
- else:
- dimension_code = ""
- return self.base_type.declaration_code(
- "(%s[%s])" % (entity_code, dimension_code),
- for_display, dll_linkage, pyrex)
-
- def as_argument_type(self):
- return c_ptr_type(self.base_type)
-
- def is_complete(self):
- return self.size is not None
-
-
-class CPtrType(CType):
- # base_type CType Referenced type
-
- is_ptr = 1
- default_value = 0
-
- def __init__(self, base_type):
- self.base_type = base_type
-
- def __repr__(self):
- return "CPtrType(%s)" % repr(self.base_type)
-
- def same_as_resolved_type(self, other_type):
- return ((other_type.is_ptr and
- self.base_type.same_as(other_type.base_type))
- or other_type is error_type)
-
- def declaration_code(self, entity_code,
- for_display = 0, dll_linkage = None, pyrex = 0):
- #print "CPtrType.declaration_code: pointer to", self.base_type ###
- return self.base_type.declaration_code(
- "(*%s)" % entity_code,
- for_display, dll_linkage, pyrex)
-
- def assignable_from_resolved_type(self, other_type):
- if other_type is error_type:
- return 1
- elif self.base_type.is_cfunction and other_type.is_cfunction:
- return self.base_type.same_as(other_type)
- elif not other_type.is_ptr:
- return 0
- elif self.base_type.is_void:
- return 1
- elif other_type.is_null_ptr:
- return 1
- else:
- return self.base_type.same_as(other_type.base_type)
-
-
-class CNullPtrType(CPtrType):
-
- is_null_ptr = 1
-
-
-class CFuncType(CType):
- # return_type CType
- # args [CFuncTypeArg]
- # has_varargs boolean
- # exception_value string
- # exception_check boolean True if PyErr_Occurred check needed
-
- is_cfunction = 1
-
- def __init__(self, return_type, args, has_varargs,
- exception_value = None, exception_check = 0):
- self.return_type = return_type
- self.args = args
- self.has_varargs = has_varargs
- self.exception_value = exception_value
- self.exception_check = exception_check
-
- def __repr__(self):
- arg_reprs = map(repr, self.args)
- if self.has_varargs:
- arg_reprs.append("...")
- return "CFuncType(%s,[%s])" % (
- repr(self.return_type),
- string.join(arg_reprs, ","))
-
- def same_c_signature_as(self, other_type, as_cmethod = 0):
- return self.same_c_signature_as_resolved_type(
- other_type.resolve(), as_cmethod)
-
- def same_c_signature_as_resolved_type(self, other_type, as_cmethod):
- if other_type is error_type:
- return 1
- if not other_type.is_cfunction:
- return 0
- nargs = len(self.args)
- if nargs <> len(other_type.args):
- return 0
- # When comparing C method signatures, the first argument
- # is exempt from compatibility checking (the proper check
- # is performed elsewhere).
- for i in range(as_cmethod, nargs):
- if not self.args[i].type.same_as(
- other_type.args[i].type):
- return 0
- if self.has_varargs <> other_type.has_varargs:
- return 0
- if not self.return_type.same_as(other_type.return_type):
- return 0
- return 1
-
- def same_exception_signature_as(self, other_type):
- return self.same_exception_signature_as_resolved_type(
- other_type.resolve())
-
- def same_exception_signature_as_resolved_type(self, other_type):
- return self.exception_value == other_type.exception_value \
- and self.exception_check == other_type.exception_check
-
- def same_as_resolved_type(self, other_type, as_cmethod = 0):
- return self.same_c_signature_as_resolved_type(other_type, as_cmethod) \
- and self.same_exception_signature_as_resolved_type(other_type)
-
- def declaration_code(self, entity_code,
- for_display = 0, dll_linkage = None, pyrex = 0):
- arg_decl_list = []
- for arg in self.args:
- arg_decl_list.append(
- arg.type.declaration_code("", for_display, pyrex = pyrex))
- if self.has_varargs:
- arg_decl_list.append("...")
- arg_decl_code = string.join(arg_decl_list, ",")
- if not arg_decl_code and not pyrex:
- arg_decl_code = "void"
- exc_clause = ""
- if pyrex or for_display:
- if self.exception_value and self.exception_check:
- exc_clause = " except? %s" % self.exception_value
- elif self.exception_value:
- exc_clause = " except %s" % self.exception_value
- elif self.exception_check:
- exc_clause = " except *"
- return self.return_type.declaration_code(
- "(%s(%s)%s)" % (entity_code, arg_decl_code, exc_clause),
- for_display, dll_linkage, pyrex)
-
-
-class CFuncTypeArg:
- # name string
- # cname string
- # type PyrexType
- # pos source file position
-
- def __init__(self, name, type, pos):
- self.name = name
- self.cname = Naming.var_prefix + name
- self.type = type
- self.pos = pos
-
- def __repr__(self):
- return "%s:%s" % (self.name, repr(self.type))
-
- def declaration_code(self, for_display = 0):
- return self.type.declaration_code(self.cname, for_display)
-
-
-class CStructOrUnionType(CType):
- # name string
- # cname string
- # kind string "struct" or "union"
- # scope StructOrUnionScope, or None if incomplete
- # typedef_flag boolean
-
- is_struct_or_union = 1
- has_attributes = 1
-
- def __init__(self, name, kind, scope, typedef_flag, cname):
- self.name = name
- self.cname = cname
- self.kind = kind
- self.scope = scope
- self.typedef_flag = typedef_flag
-
- def __repr__(self):
- return "CStructOrUnionType(%s,%s%s)" % (self.name, self.cname,
- ("", ",typedef_flag=1")[self.typedef_flag])
-
- def declaration_code(self, entity_code,
- for_display = 0, dll_linkage = None, pyrex = 0):
- if pyrex:
- return "%s %s" % (self.name, entity_code)
- else:
- if for_display:
- base = self.name
- elif self.typedef_flag:
- base = self.cname
- else:
- base = "%s %s" % (self.kind, self.cname)
- return "%s %s" % (public_decl(base, dll_linkage), entity_code)
-
- def is_complete(self):
- return self.scope is not None
-
- def attributes_known(self):
- return self.is_complete()
-
-
-class CEnumType(CIntType):
- # name string
- # cname string or None
- # typedef_flag boolean
-
- is_enum = 1
- signed = 1
- rank = 2
-
- def __init__(self, name, cname, typedef_flag):
- self.name = name
- self.cname = cname
- self.values = []
- self.typedef_flag = typedef_flag
-
- def __repr__(self):
- return "CEnumType(%s,%s%s)" % (self.name, self.cname,
- ("", ",typedef_flag=1")[self.typedef_flag])
-
- def declaration_code(self, entity_code,
- for_display = 0, dll_linkage = None, pyrex = 0):
- if pyrex:
- return "%s %s" % (self.cname, entity_code)
- else:
- if self.typedef_flag:
- base = self.cname
- else:
- base = "enum %s" % self.cname
- return "%s %s" % (public_decl(base, dll_linkage), entity_code)
-
-
-class CStringType:
- # Mixin class for C string types.
-
- is_string = 1
-
- to_py_function = "PyString_FromString"
- from_py_function = "PyString_AsString"
-
- def literal_code(self, value):
- return '"%s"' % value
-
-
-class CCharArrayType(CStringType, CArrayType):
- # C 'char []' type.
-
- parsetuple_format = "s"
- pymemberdef_typecode = "T_STRING_INPLACE"
-
- def __init__(self, size):
- CArrayType.__init__(self, c_char_type, size)
-
-
-class CCharPtrType(CStringType, CPtrType):
- # C 'char *' type.
-
- parsetuple_format = "s"
- pymemberdef_typecode = "T_STRING"
-
- def __init__(self):
- CPtrType.__init__(self, c_char_type)
-
-
-class ErrorType(PyrexType):
- # Used to prevent propagation of error messages.
-
- is_error = 1
- exception_value = "0"
- exception_check = 0
- to_py_function = "dummy"
- from_py_function = "dummy"
-
- def declaration_code(self, entity_code,
- for_display = 0, dll_linkage = None, pyrex = 0):
- return "<error>"
-
- def same_as_resolved_type(self, other_type):
- return 1
-
-
-py_object_type = PyObjectType()
-
-c_void_type = CVoidType()
-c_void_ptr_type = CPtrType(c_void_type)
-c_void_ptr_ptr_type = CPtrType(c_void_ptr_type)
-
-c_char_type = CIntType(0, 1, "T_CHAR")
-c_short_type = CIntType(1, 1, "T_SHORT")
-c_int_type = CIntType(2, 1, "T_INT")
-c_long_type = CIntType(3, 1, "T_LONG")
-c_longlong_type = CLongLongType(4, 1, "T_LONGLONG")
-
-c_uchar_type = CIntType(0, 0, "T_UBYTE")
-c_ushort_type = CIntType(1, 0, "T_USHORT")
-c_uint_type = CUIntType(2, 0, "T_UINT")
-c_ulong_type = CULongType(3, 0, "T_ULONG")
-c_ulonglong_type = CULongLongType(4, 0, "T_ULONGLONG")
-
-c_float_type = CFloatType(5, "T_FLOAT")
-c_double_type = CFloatType(6, "T_DOUBLE")
-c_longdouble_type = CFloatType(7)
-
-c_null_ptr_type = CNullPtrType(c_void_type)
-c_char_array_type = CCharArrayType(None)
-c_char_ptr_type = CCharPtrType()
-c_char_ptr_ptr_type = CPtrType(c_char_ptr_type)
-c_int_ptr_type = CPtrType(c_int_type)
-
-c_returncode_type = CIntType(2, 1, "T_INT", is_returncode = 1)
-
-error_type = ErrorType()
-
-lowest_float_rank = 5
-
-rank_to_type_name = (
- "char", # 0
- "short", # 1
- "int", # 2
- "long", # 3
- "PY_LONG_LONG", # 4
- "float", # 5
- "double", # 6
- "long double", # 7
-)
-
-sign_and_rank_to_type = {
- #(signed, rank)
- (0, 0, ): c_uchar_type,
- (0, 1): c_ushort_type,
- (0, 2): c_uint_type,
- (0, 3): c_ulong_type,
- (0, 4): c_ulonglong_type,
- (1, 0): c_char_type,
- (1, 1): c_short_type,
- (1, 2): c_int_type,
- (1, 3): c_long_type,
- (1, 4): c_longlong_type,
- (1, 5): c_float_type,
- (1, 6): c_double_type,
- (1, 7): c_longdouble_type,
-}
-
-modifiers_and_name_to_type = {
- #(signed, longness, name)
- (0, 0, "char"): c_uchar_type,
- (0, -1, "int"): c_ushort_type,
- (0, 0, "int"): c_uint_type,
- (0, 1, "int"): c_ulong_type,
- (0, 2, "int"): c_ulonglong_type,
- (1, 0, "void"): c_void_type,
- (1, 0, "char"): c_char_type,
- (1, -1, "int"): c_short_type,
- (1, 0, "int"): c_int_type,
- (1, 1, "int"): c_long_type,
- (1, 2, "int"): c_longlong_type,
- (1, 0, "float"): c_float_type,
- (1, 0, "double"): c_double_type,
- (1, 1, "double"): c_longdouble_type,
- (1, 0, "object"): py_object_type,
-}
-
-def widest_numeric_type(type1, type2):
- # Given two numeric types, return the narrowest type
- # encompassing both of them.
- signed = type1.signed
- rank = max(type1.rank, type2.rank)
- if rank >= lowest_float_rank:
- signed = 1
- return sign_and_rank_to_type[signed, rank]
-
-def simple_c_type(signed, longness, name):
- # Find type descriptor for simple type given name and modifiers.
- # Returns None if arguments don't make sense.
- return modifiers_and_name_to_type.get((signed, longness, name))
-
-def c_array_type(base_type, size):
- # Construct a C array type.
- if base_type is c_char_type:
- return CCharArrayType(size)
- else:
- return CArrayType(base_type, size)
-
-def c_ptr_type(base_type):
- # Construct a C pointer type.
- if base_type is c_char_type:
- return c_char_ptr_type
- else:
- return CPtrType(base_type)
-
-def public_decl(base, dll_linkage):
- if dll_linkage:
- return "%s(%s)" % (dll_linkage, base)
- else:
- return base
-
-def same_type(type1, type2):
- return type1.same_as(type2)
-
-def assignable_from(type1, type2):
- return type1.assignable_from(type2)
-
-def typecast(to_type, from_type, expr_code):
- # Return expr_code cast to a C type which can be
- # assigned to to_type, assuming its existing C type
- # is from_type.
- if to_type is from_type or \
- (not to_type.is_pyobject and assignable_from(to_type, from_type)):
- return expr_code
- else:
- #print "typecast: to", to_type, "from", from_type ###
- return to_type.cast_code(expr_code)
Modified: cs/babel/trunk/spike/Spike/Compiler/Scanning.py
===================================================================
--- cs/babel/trunk/spike/Spike/Compiler/Scanning.py 2007-01-26 03:29:08 UTC (rev 5902)
+++ cs/babel/trunk/spike/Spike/Compiler/Scanning.py 2007-01-26 04:10:35 UTC (rev 5903)
@@ -1,5 +1,5 @@
#
-# Pyrex Scanner
+# Spike Scanner
#
#import pickle
@@ -10,9 +10,9 @@
import sys
from time import time
-from Pyrex import Plex
-from Pyrex.Plex import Scanner
-from Pyrex.Plex.Errors import UnrecognizedInput
+from Spike import Plex
+from Spike.Plex import Scanner
+from Spike.Plex.Errors import UnrecognizedInput
from Errors import CompileError, error
from Lexicon import string_prefixes, make_lexicon
@@ -160,7 +160,7 @@
#------------------------------------------------------------------
-class PyrexScanner(Scanner):
+class SpikeScanner(Scanner):
resword_dict = build_resword_dict()
Copied: cs/babel/trunk/spike/Spike/Compiler/SpikeTypes.py (from rev 5902, cs/babel/trunk/spike/Spike/Compiler/PyrexTypes.py)
===================================================================
--- cs/babel/trunk/spike/Spike/Compiler/PyrexTypes.py 2007-01-26 03:29:08 UTC (rev 5902)
+++ cs/babel/trunk/spike/Spike/Compiler/SpikeTypes.py 2007-01-26 04:10:35 UTC (rev 5903)
@@ -0,0 +1,821 @@
+#
+# Spike - Types
+#
+
+import string
+import Naming
+
+class SpikeType:
+ #
+ # Base class for all Spike types.
+ #
+ # is_pyobject boolean Is a Python object type
+ # is_extension_type boolean Is a Python extension type
+ # is_numeric boolean Is a C numeric type
+ # is_int boolean Is a C integer type
+ # is_float boolean Is a C floating point type
+ # is_void boolean Is the C void type
+ # is_array boolean Is a C array type
+ # is_ptr boolean Is a C pointer type
+ # is_null_ptr boolean Is the type of NULL
+ # is_cfunction boolean Is a C function type
+ # is_struct_or_union boolean Is a C struct or union type
+ # is_enum boolean Is a C enum type
+ # is_string boolean Is a C char * type
+ # is_returncode boolean Is used only to signal exceptions
+ # is_error boolean Is the dummy error type
+ # has_attributes boolean Has C dot-selectable attributes
+ # default_value string Initial value
+ # parsetuple_format string Format char for PyArg_ParseTuple
+ # pymemberdef_typecode string Type code for PyMemberDef struct
+ #
+ # declaration_code(entity_code,
+ # for_display = 0, dll_linkage = None, pyrex = 0)
+ # Returns a code fragment for the declaration of an entity
+ # of this type, given a code fragment for the entity.
+ # * If for_display, this is for reading by a human in an error
+ # message; otherwise it must be valid C code.
+ # * If dll_linkage is not None, it must be 'DL_EXPORT' or
+ # 'DL_IMPORT', and will be added to the base type part of
+ # the declaration.
+ # * If pyrex = 1, this is for use in a 'cdef extern'
+ # statement of a Spike include file.
+ #
+ # assignable_from(src_type)
+ # Tests whether a variable of this type can be
+ # assigned a value of type src_type.
+ #
+ # same_as(other_type)
+ # Tests whether this type represents the same type
+ # as other_type.
+ #
+ # as_argument_type():
+ # Coerces array type into pointer type for use as
+ # a formal argument type.
+ #
+
+ is_pyobject = 0
+ is_extension_type = 0
+ is_numeric = 0
+ is_int = 0
+ is_float = 0
+ is_void = 0
+ is_array = 0
+ is_ptr = 0
+ is_null_ptr = 0
+ is_cfunction = 0
+ is_struct_or_union = 0
+ is_enum = 0
+ is_string = 0
+ is_returncode = 0
+ is_error = 0
+ has_attributes = 0
+ default_value = ""
+ parsetuple_format = ""
+ pymemberdef_typecode = None
+
+ def resolve(self):
+ # If a typedef, returns the base type.
+ return self
+
+ def literal_code(self, value):
+ # Returns a C code fragment representing a literal
+ # value of this type.
+ return str(value)
+
+ def __str__(self):
+ return string.strip(self.declaration_code("", for_display = 1))
+
+ def same_as(self, other_type, **kwds):
+ return self.same_as_resolved_type(other_type.resolve(), **kwds)
+
+ def same_as_resolved_type(self, other_type):
+ return self is other_type or other_type is error_type
+
+ def subtype_of(self, other_type):
+ return self.subtype_of_resolved_type(other_type.resolve())
+
+ def subtype_of_resolved_type(self, other_type):
+ return self.same_as(other_type)
+
+ def assignable_from(self, src_type):
+ return self.assignable_from_resolved_type(src_type.resolve())
+
+ def assignable_from_resolved_type(self, src_type):
+ return self.same_as(src_type)
+
+ def as_argument_type(self):
+ return self
+
+ def is_complete(self):
+ # A type is incomplete if it is an unsized array,
+ # a struct whose attributes are not defined, etc.
+ return 1
+
+ def cast_code(self, expr_code):
+ return "((%s)%s)" % (self.declaration_code(""), expr_code)
+
+
+class CTypedefType:
+ #
+ # Type defined with a ctypedef statement in a
+ # 'cdef extern from' block. Delegates most attribute
+ # lookups to the base type.
+ #
+
+ def __init__(self, cname, base_type):
+ self.typedef_cname = cname
+ self.typedef_base_type = base_type
+
+ def resolve(self):
+ return self.typedef_base_type.resolve()
+
+ def declaration_code(self, entity_code,
+ for_display = 0, dll_linkage = None, pyrex = 0):
+ return "%s %s" % (self.typedef_cname, entity_code)
+
+ def __str__(self):
+ return self.typedef_cname
+
+ def __getattr__(self, name):
+ return getattr(self.typedef_base_type, name)
+
+
+class PyObjectType(SpikeType):
+ #
+ # Base class for all Python object types (reference-counted).
+ #
+
+ is_pyobject = 1
+ default_value = "0"
+ parsetuple_format = "O"
+ pymemberdef_typecode = "T_OBJECT"
+
+ def __str__(self):
+ return "Python object"
+
+ def __repr__(self):
+ return "PyObjectType"
+
+ def assignable_from(self, src_type):
+ return 1 # Conversion will be attempted
+
+ def declaration_code(self, entity_code,
+ for_display = 0, dll_linkage = None, pyrex = 0):
+ if pyrex:
+ return "object %s" % entity_code
+ else:
+ return "%s *%s" % (public_decl("PyObject", dll_linkage), entity_code)
+
+
+class PyExtensionType(PyObjectType):
+ #
+ # A Python extension type.
+ #
+ # name string
+ # scope CClassScope Attribute namespace
+ # visibility string
+ # typedef_flag boolean
+ # base_type PyExtensionType or None
+ # module_name string or None Qualified name of defining module
+ # objstruct_cname string Name of PyObject struct
+ # typeobj_cname string or None C code fragment referring to type object
+ # typeptr_cname string or None Name of pointer to external type object
+ # vtabslot_cname string Name of C method table member
+ # vtabstruct_cname string Name of C method table struct
+ # vtabptr_cname string Name of pointer to C method table
+ # vtable_cname string Name of C method table definition
+
+ is_extension_type = 1
+ has_attributes = 1
+
+ def __init__(self, name, typedef_flag, base_type):
+ self.name = name
+ self.scope = None
+ self.typedef_flag = typedef_flag
+ self.base_type = base_type
+ self.module_name = None
+ self.objstruct_cname = None
+ self.typeobj_cname = None
+ self.typeptr_cname = None
+ self.vtabslot_cname = None
+ self.vtabstruct_cname = None
+ self.vtabptr_cname = None
+ self.vtable_cname = None
+
+ def set_scope(self, scope):
+ self.scope = scope
+ if scope:
+ scope.parent_type = self
+
+ def subtype_of_resolved_type(self, other_type):
+ if other_type.is_extension_type:
+ return self is other_type or (
+ self.base_type and self.base_type.subtype_of(other_type))
+ else:
+ return other_type is py_object_type
+
+ def typeobj_is_available(self):
+ # Do we have a pointer to the type object?
+ return self.typeptr_cname
+
+ def typeobj_is_imported(self):
+ # If we don't know the C name of the type object but we do
+ # know which module it's defined in, it will be imported.
+ return self.typeobj_cname is None and self.module_name is not None
+
+ def declaration_code(self, entity_code,
+ for_display = 0, dll_linkage = None, pyrex = 0):
+ if pyrex:
+ return "%s %s" % (self.name, entity_code)
+ else:
+ if self.typedef_flag:
+ base_format = "%s"
+ else:
+ base_format = "struct %s"
+ base = public_decl(base_format % self.objstruct_cname, dll_linkage)
+ return "%s *%s" % (base, entity_code)
+
+ def attributes_known(self):
+ return self.scope is not None
+
+ def __str__(self):
+ return self.name
+
+ def __repr__(self):
+ return "PyExtensionType(%s%s)" % (self.scope.class_name,
+ ("", ".typedef_flag=1")[self.typedef_flag])
+
+
+class CType(SpikeType):
+ #
+ # Base class for all C types (non-reference-counted).
+ #
+ # to_py_function string C function for converting to Python object
+ # from_py_function string C function for constructing from Python object
+ #
+
+ to_py_function = None
+ from_py_function = None
+
+
+class CSimpleType(CType):
+ #
+ # Base class for all unstructured C types.
+ #
+ pass
+
+
+class CVoidType(CSimpleType):
+ is_void = 1
+
+ def __repr__(self):
+ return "<CVoidType>"
+
+ def declaration_code(self, entity_code,
+ for_display = 0, dll_linkage = None, pyrex = 0):
+ base = public_decl("void", dll_linkage)
+ return "%s %s" % (base, entity_code)
+
+ def is_complete(self):
+ return 0
+
+
+class CNumericType(CType):
+ #
+ # Base class for all C numeric types.
+ #
+ # rank integer Relative size
+ # signed boolean
+ #
+
+ is_numeric = 1
+ default_value = "0"
+
+ parsetuple_formats = ( # rank -> format
+ "?HIkK???", # unsigned
+ "chilLfd?", # signed
+ )
+
+ def __init__(self, rank, signed = 1, pymemberdef_typecode = None):
+ self.rank = rank
+ self.signed = signed
+ ptf = self.parsetuple_formats[signed][rank]
+ if ptf == '?':
+ ptf = None
+ self.parsetuple_format = ptf
+ self.pymemberdef_typecode = pymemberdef_typecode
+
+ def __repr__(self):
+ if self.signed:
+ u = ""
+ else:
+ 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:
+ u = ""
+ else:
+ u = "unsigned "
+ 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):
+
+ is_int = 1
+ typedef_flag = 0
+ to_py_function = "PyInt_FromLong"
+ from_py_function = "PyInt_AsLong"
+
+ def __init__(self, rank, signed, pymemberdef_typecode = None, is_returncode = 0):
+ CNumericType.__init__(self, rank, signed, pymemberdef_typecode)
+ self.is_returncode = is_returncode
+
+
+class CUIntType(CIntType):
+
+ to_py_function = "PyLong_FromUnsignedLong"
+ from_py_function = "PyInt_AsUnsignedLongMask"
+
+
+class CULongType(CIntType):
+
+ to_py_function = "PyLong_FromUnsignedLong"
+ from_py_function = "PyInt_AsUnsignedLongMask"
+
+
+class CLongLongType(CIntType):
+
+ to_py_function = "PyLong_FromLongLong"
+ from_py_function = "PyInt_AsUnsignedLongLongMask"
+
+
+class CULongLongType(CIntType):
+
+ to_py_function = "PyLong_FromUnsignedLongLong"
+ from_py_function = "PyInt_AsUnsignedLongLongMask"
+
+
+class CFloatType(CNumericType):
+
+ is_float = 1
+ to_py_function = "PyFloat_FromDouble"
+ from_py_function = "PyFloat_AsDouble"
+
+ def __init__(self, rank, pymemberdef_typecode = None):
+ CNumericType.__init__(self, rank, 1, pymemberdef_typecode)
+
+
+class CArrayType(CType):
+ # base_type CType Element type
+ # size integer or None Number of elements
+
+ is_array = 1
+
+ def __init__(self, base_type, size):
+ self.base_type = base_type
+ self.size = size
+ if base_type is c_char_type:
+ self.is_string = 1
+
+ def __repr__(self):
+ return "CArrayType(%s,%s)" % (self.size, repr(self.base_type))
+
+ def same_as_resolved_type(self, other_type):
+ return ((other_type.is_array and
+ self.base_type.same_as(other_type.base_type))
+ or other_type is error_type)
+
+ def assignable_from_resolved_type(self, src_type):
+ # Can't assign to a variable of an array type
+ return 0
+
+ def element_ptr_type(self):
+ return c_ptr_type(self.base_type)
+
+ def declaration_code(self, entity_code,
+ for_display = 0, dll_linkage = None, pyrex = 0):
+ if self.size is not None:
+ dimension_code = self.size
+ else:
+ dimension_code = ""
+ return self.base_type.declaration_code(
+ "(%s[%s])" % (entity_code, dimension_code),
+ for_display, dll_linkage, pyrex)
+
+ def as_argument_type(self):
+ return c_ptr_type(self.base_type)
+
+ def is_complete(self):
+ return self.size is not None
+
+
+class CPtrType(CType):
+ # base_type CType Referenced type
+
+ is_ptr = 1
+ default_value = 0
+
+ def __init__(self, base_type):
+ self.base_type = base_type
+
+ def __repr__(self):
+ return "CPtrType(%s)" % repr(self.base_type)
+
+ def same_as_resolved_type(self, other_type):
+ return ((other_type.is_ptr and
+ self.base_type.same_as(other_type.base_type))
+ or other_type is error_type)
+
+ def declaration_code(self, entity_code,
+ for_display = 0, dll_linkage = None, pyrex = 0):
+ #print "CPtrType.declaration_code: pointer to", self.base_type ###
+ return self.base_type.declaration_code(
+ "(*%s)" % entity_code,
+ for_display, dll_linkage, pyrex)
+
+ def assignable_from_resolved_type(self, other_type):
+ if other_type is error_type:
+ return 1
+ elif self.base_type.is_cfunction and other_type.is_cfunction:
+ return self.base_type.same_as(other_type)
+ elif not other_type.is_ptr:
+ return 0
+ elif self.base_type.is_void:
+ return 1
+ elif other_type.is_null_ptr:
+ return 1
+ else:
+ return self.base_type.same_as(other_type.base_type)
+
+
+class CNullPtrType(CPtrType):
+
+ is_null_ptr = 1
+
+
+class CFuncType(CType):
+ # return_type CType
+ # args [CFuncTypeArg]
+ # has_varargs boolean
+ # exception_value string
+ # exception_check boolean True if PyErr_Occurred check needed
+
+ is_cfunction = 1
+
+ def __init__(self, return_type, args, has_varargs,
+ exception_value = None, exception_check = 0):
+ self.return_type = return_type
+ self.args = args
+ self.has_varargs = has_varargs
+ self.exception_value = exception_value
+ self.exception_check = exception_check
+
+ def __repr__(self):
+ arg_reprs = map(repr, self.args)
+ if self.has_varargs:
+ arg_reprs.append("...")
+ return "CFuncType(%s,[%s])" % (
+ repr(self.return_type),
+ string.join(arg_reprs, ","))
+
+ def same_c_signature_as(self, other_type, as_cmethod = 0):
+ return self.same_c_signature_as_resolved_type(
+ other_type.resolve(), as_cmethod)
+
+ def same_c_signature_as_resolved_type(self, other_type, as_cmethod):
+ if other_type is error_type:
+ return 1
+ if not other_type.is_cfunction:
+ return 0
+ nargs = len(self.args)
+ if nargs <> len(other_type.args):
+ return 0
+ # When comparing C method signatures, the first argument
+ # is exempt from compatibility checking (the proper check
+ # is performed elsewhere).
+ for i in range(as_cmethod, nargs):
+ if not self.args[i].type.same_as(
+ other_type.args[i].type):
+ return 0
+ if self.has_varargs <> other_type.has_varargs:
+ return 0
+ if not self.return_type.same_as(other_type.return_type):
+ return 0
+ return 1
+
+ def same_exception_signature_as(self, other_type):
+ return self.same_exception_signature_as_resolved_type(
+ other_type.resolve())
+
+ def same_exception_signature_as_resolved_type(self, other_type):
+ return self.exception_value == other_type.exception_value \
+ and self.exception_check == other_type.exception_check
+
+ def same_as_resolved_type(self, other_type, as_cmethod = 0):
+ return self.same_c_signature_as_resolved_type(other_type, as_cmethod) \
+ and self.same_exception_signature_as_resolved_type(other_type)
+
+ def declaration_code(self, entity_code,
+ for_display = 0, dll_linkage = None, pyrex = 0):
+ arg_decl_list = []
+ for arg in self.args:
+ arg_decl_list.append(
+ arg.type.declaration_code("", for_display, pyrex = pyrex))
+ if self.has_varargs:
+ arg_decl_list.append("...")
+ arg_decl_code = string.join(arg_decl_list, ",")
+ if not arg_decl_code and not pyrex:
+ arg_decl_code = "void"
+ exc_clause = ""
+ if pyrex or for_display:
+ if self.exception_value and self.exception_check:
+ exc_clause = " except? %s" % self.exception_value
+ elif self.exception_value:
+ exc_clause = " except %s" % self.exception_value
+ elif self.exception_check:
+ exc_clause = " except *"
+ return self.return_type.declaration_code(
+ "(%s(%s)%s)" % (entity_code, arg_decl_code, exc_clause),
+ for_display, dll_linkage, pyrex)
+
+
+class CFuncTypeArg:
+ # name string
+ # cname string
+ # type SpikeType
+ # pos source file position
+
+ def __init__(self, name, type, pos):
+ self.name = name
+ self.cname = Naming.var_prefix + name
+ self.type = type
+ self.pos = pos
+
+ def __repr__(self):
+ return "%s:%s" % (self.name, repr(self.type))
+
+ def declaration_code(self, for_display = 0):
+ return self.type.declaration_code(self.cname, for_display)
+
+
+class CStructOrUnionType(CType):
+ # name string
+ # cname string
+ # kind string "struct" or "union"
+ # scope StructOrUnionScope, or None if incomplete
+ # typedef_flag boolean
+
+ is_struct_or_union = 1
+ has_attributes = 1
+
+ def __init__(self, name, kind, scope, typedef_flag, cname):
+ self.name = name
+ self.cname = cname
+ self.kind = kind
+ self.scope = scope
+ self.typedef_flag = typedef_flag
+
+ def __repr__(self):
+ return "CStructOrUnionType(%s,%s%s)" % (self.name, self.cname,
+ ("", ",typedef_flag=1")[self.typedef_flag])
+
+ def declaration_code(self, entity_code,
+ for_display = 0, dll_linkage = None, pyrex = 0):
+ if pyrex:
+ return "%s %s" % (self.name, entity_code)
+ else:
+ if for_display:
+ base = self.name
+ elif self.typedef_flag:
+ base = self.cname
+ else:
+ base = "%s %s" % (self.kind, self.cname)
+ return "%s %s" % (public_decl(base, dll_linkage), entity_code)
+
+ def is_complete(self):
+ return self.scope is not None
+
+ def attributes_known(self):
+ return self.is_complete()
+
+
+class CEnumType(CIntType):
+ # name string
+ # cname string or None
+ # typedef_flag boolean
+
+ is_enum = 1
+ signed = 1
+ rank = 2
+
+ def __init__(self, name, cname, typedef_flag):
+ self.name = name
+ self.cname = cname
+ self.values = []
+ self.typedef_flag = typedef_flag
+
+ def __repr__(self):
+ return "CEnumType(%s,%s%s)" % (self.name, self.cname,
+ ("", ",typedef_flag=1")[self.typedef_flag])
+
+ def declaration_code(self, entity_code,
+ for_display = 0, dll_linkage = None, pyrex = 0):
+ if pyrex:
+ return "%s %s" % (self.cname, entity_code)
+ else:
+ if self.typedef_flag:
+ base = self.cname
+ else:
+ base = "enum %s" % self.cname
+ return "%s %s" % (public_decl(base, dll_linkage), entity_code)
+
+
+class CStringType:
+ # Mixin class for C string types.
+
+ is_string = 1
+
+ to_py_function = "PyString_FromString"
+ from_py_function = "PyString_AsString"
+
+ def literal_code(self, value):
+ return '"%s"' % value
+
+
+class CCharArrayType(CStringType, CArrayType):
+ # C 'char []' type.
+
+ parsetuple_format = "s"
+ pymemberdef_typecode = "T_STRING_INPLACE"
+
+ def __init__(self, size):
+ CArrayType.__init__(self, c_char_type, size)
+
+
+class CCharPtrType(CStringType, CPtrType):
+ # C 'char *' type.
+
+ parsetuple_format = "s"
+ pymemberdef_typecode = "T_STRING"
+
+ def __init__(self):
+ CPtrType.__init__(self, c_char_type)
+
+
+class ErrorType(SpikeType):
+ # Used to prevent propagation of error messages.
+
+ is_error = 1
+ exception_value = "0"
+ exception_check = 0
+ to_py_function = "dummy"
+ from_py_function = "dummy"
+
+ def declaration_code(self, entity_code,
+ for_display = 0, dll_linkage = None, pyrex = 0):
+ return "<error>"
+
+ def same_as_resolved_type(self, other_type):
+ return 1
+
+
+py_object_type = PyObjectType()
+
+c_void_type = CVoidType()
+c_void_ptr_type = CPtrType(c_void_type)
+c_void_ptr_ptr_type = CPtrType(c_void_ptr_type)
+
+c_char_type = CIntType(0, 1, "T_CHAR")
+c_short_type = CIntType(1, 1, "T_SHORT")
+c_int_type = CIntType(2, 1, "T_INT")
+c_long_type = CIntType(3, 1, "T_LONG")
+c_longlong_type = CLongLongType(4, 1, "T_LONGLONG")
+
+c_uchar_type = CIntType(0, 0, "T_UBYTE")
+c_ushort_type = CIntType(1, 0, "T_USHORT")
+c_uint_type = CUIntType(2, 0, "T_UINT")
+c_ulong_type = CULongType(3, 0, "T_ULONG")
+c_ulonglong_type = CULongLongType(4, 0, "T_ULONGLONG")
+
+c_float_type = CFloatType(5, "T_FLOAT")
+c_double_type = CFloatType(6, "T_DOUBLE")
+c_longdouble_type = CFloatType(7)
+
+c_null_ptr_type = CNullPtrType(c_void_type)
+c_char_array_type = CCharArrayType(None)
+c_char_ptr_type = CCharPtrType()
+c_char_ptr_ptr_type = CPtrType(c_char_ptr_type)
+c_int_ptr_type = CPtrType(c_int_type)
+
+c_returncode_type = CIntType(2, 1, "T_INT", is_returncode = 1)
+
+error_type = ErrorType()
+
+lowest_float_rank = 5
+
+rank_to_type_name = (
+ "char", # 0
+ "short", # 1
+ "int", # 2
+ "long", # 3
+ "PY_LONG_LONG", # 4
+ "float", # 5
+ "double", # 6
+ "long double", # 7
+)
+
+sign_and_rank_to_type = {
+ #(signed, rank)
+ (0, 0, ): c_uchar_type,
+ (0, 1): c_ushort_type,
+ (0, 2): c_uint_type,
+ (0, 3): c_ulong_type,
+ (0, 4): c_ulonglong_type,
+ (1, 0): c_char_type,
+ (1, 1): c_short_type,
+ (1, 2): c_int_type,
+ (1, 3): c_long_type,
+ (1, 4): c_longlong_type,
+ (1, 5): c_float_type,
+ (1, 6): c_double_type,
+ (1, 7): c_longdouble_type,
+}
+
+modifiers_and_name_to_type = {
+ #(signed, longness, name)
+ (0, 0, "char"): c_uchar_type,
+ (0, -1, "int"): c_ushort_type,
+ (0, 0, "int"): c_uint_type,
+ (0, 1, "int"): c_ulong_type,
+ (0, 2, "int"): c_ulonglong_type,
+ (1, 0, "void"): c_void_type,
+ (1, 0, "char"): c_char_type,
+ (1, -1, "int"): c_short_type,
+ (1, 0, "int"): c_int_type,
+ (1, 1, "int"): c_long_type,
+ (1, 2, "int"): c_longlong_type,
+ (1, 0, "float"): c_float_type,
+ (1, 0, "double"): c_double_type,
+ (1, 1, "double"): c_longdouble_type,
+ (1, 0, "object"): py_object_type,
+}
+
+def widest_numeric_type(type1, type2):
+ # Given two numeric types, return the narrowest type
+ # encompassing both of them.
+ signed = type1.signed
+ rank = max(type1.rank, type2.rank)
+ if rank >= lowest_float_rank:
+ signed = 1
+ return sign_and_rank_to_type[signed, rank]
+
+def simple_c_type(signed, longness, name):
+ # Find type descriptor for simple type given name and modifiers.
+ # Returns None if arguments don't make sense.
+ return modifiers_and_name_to_type.get((signed, longness, name))
+
+def c_array_type(base_type, size):
+ # Construct a C array type.
+ if base_type is c_char_type:
+ return CCharArrayType(size)
+ else:
+ return CArrayType(base_type, size)
+
+def c_ptr_type(base_type):
+ # Construct a C pointer type.
+ if base_type is c_char_type:
+ return c_char_ptr_type
+ else:
+ return CPtrType(base_type)
+
+def public_decl(base, dll_linkage):
+ if dll_linkage:
+ return "%s(%s)" % (dll_linkage, base)
+ else:
+ return base
+
+def same_type(type1, type2):
+ return type1.same_as(type2)
+
+def assignable_from(type1, type2):
+ return type1.assignable_from(type2)
+
+def typecast(to_type, from_type, expr_code):
+ # Return expr_code cast to a C type which can be
+ # assigned to to_type, assuming its existing C type
+ # is from_type.
+ if to_type is from_type or \
+ (not to_type.is_pyobject and assignable_from(to_type, from_type)):
+ return expr_code
+ else:
+ #print "typecast: to", to_type, "from", from_type ###
+ return to_type.cast_code(expr_code)
Modified: cs/babel/trunk/spike/Spike/Compiler/Symtab.py
===================================================================
--- cs/babel/trunk/spike/Spike/Compiler/Symtab.py 2007-01-26 03:29:08 UTC (rev 5902)
+++ cs/babel/trunk/spike/Spike/Compiler/Symtab.py 2007-01-26 04:10:35 UTC (rev 5903)
@@ -1,12 +1,12 @@
#
-# Pyrex - Symbol Table
+# Spike - Symbol Table
#
import re
from Errors import error, InternalError
import Options
import Naming
-from PyrexTypes import c_int_type, \
+from SpikeTypes import c_int_type, \
py_object_type, c_char_array_type, \
CEnumType, CStructOrUnionType, PyExtensionType
from TypeSlots import \
@@ -20,7 +20,7 @@
#
# name string Python name of entity
# cname string C name of entity
- # type PyrexType Type of entity
+ # type SpikeType Type of entity
# doc string Doc string
# init string Initial value
# visibility 'private' or 'public' or 'extern'
@@ -116,7 +116,7 @@
# temp_counter integer Counter for naming temp vars
# cname_to_entry {string : Entry} Temp cname to entry mapping
# pow_function_used boolean The C pow() function is used
- # return_type PyrexType or None Return type of function owning scope
+ # return_type SpikeType or None Return type of function owning scope
# is_py_class_scope boolean Is a Python class scope
# is_c_class_scope boolean Is an extension type scope
# scope_prefix string Disambiguator for C names
@@ -181,7 +181,7 @@
def mangle_internal(self, name):
# Mangle an internal name so as not to clash with any
# user-defined name in this scope.
- prefix = "%s%s_" % (Naming.pyrex_prefix, name)
+ prefix = "%s%s_" % (Naming.spike_prefix, name)
return self.mangle(prefix)
#return self.parent_scope.mangle(prefix, self.name)
@@ -393,7 +393,7 @@
return entry.cname
n = self.temp_counter
self.temp_counter = n + 1
- cname = "%s%d" % (Naming.pyrex_prefix, n)
+ cname = "%s%d" % (Naming.spike_prefix, n)
entry = Entry("", cname, type)
if type.is_pyobject:
entry.init = "0"
@@ -847,7 +847,7 @@
# Abstract base class for namespace of
# Python class or extension type.
#
- # class_name string Pyrex name of the class
+ # class_name string Spike name of the class
# scope_prefix string Additional prefix for names
# declared in the class
# doc string or None Doc string
Modified: cs/babel/trunk/spike/Spike/Compiler/TypeSlots.py
===================================================================
--- cs/babel/trunk/spike/Spike/Compiler/TypeSlots.py 2007-01-26 03:29:08 UTC (rev 5902)
+++ cs/babel/trunk/spike/Spike/Compiler/TypeSlots.py 2007-01-26 04:10:35 UTC (rev 5903)
@@ -1,10 +1,10 @@
#
-# Pyrex - Tables describing slots in the type object
+# Spike - Tables describing slots in the type object
# and associated know-how.
#
import Naming
-import PyrexTypes
+import SpikeTypes
class Signature:
# Method slot signature descriptor.
@@ -35,16 +35,16 @@
# char in format string)
format_map = {
- 'O': PyrexTypes.py_object_type,
- 'v': PyrexTypes.c_void_type,
- 'p': PyrexTypes.c_void_ptr_type,
- 'P': PyrexTypes.c_void_ptr_ptr_type,
- 'i': PyrexTypes.c_int_type,
- 'I': PyrexTypes.c_int_ptr_type,
- 'l': PyrexTypes.c_long_type,
- 's': PyrexTypes.c_char_ptr_type,
- 'S': PyrexTypes.c_char_ptr_ptr_type,
- 'r': PyrexTypes.c_returncode_type,
+ 'O': SpikeTypes.py_object_type,
+ 'v': SpikeTypes.c_void_type,
+ 'p': SpikeTypes.c_void_ptr_type,
+ 'P': SpikeTypes.c_void_ptr_ptr_type,
+ 'i': SpikeTypes.c_int_type,
+ 'I': SpikeTypes.c_int_ptr_type,
+ 'l': SpikeTypes.c_long_type,
+ 's': SpikeTypes.c_char_ptr_type,
+ 'S': SpikeTypes.c_char_ptr_ptr_type,
+ 'r': SpikeTypes.c_returncode_type,
# 'T', '-' and '*' are handled otherwise
# and are not looked up in here
}
@@ -177,7 +177,7 @@
class InternalMethodSlot(SlotDescriptor):
# Type slot descriptor for a method which is always
- # synthesized by Pyrex.
+ # synthesized by Spike.
#
# slot_name string Member name of the slot in the type object
@@ -557,7 +557,7 @@
#
# Descriptors for special methods which don't appear directly
# in the type object or its substructures. These methods are
-# called from slot functions synthesized by Pyrex.
+# called from slot functions synthesized by Spike.
#
#------------------------------------------------------------------------------------------
Modified: cs/babel/trunk/spike/Spike/Distutils/build_ext.py
===================================================================
--- cs/babel/trunk/spike/Spike/Distutils/build_ext.py 2007-01-26 03:29:08 UTC (rev 5902)
+++ cs/babel/trunk/spike/Spike/Distutils/build_ext.py 2007-01-26 04:10:35 UTC (rev 5903)
@@ -1,5 +1,5 @@
# Subclasses disutils.command.build_ext,
-# replacing it with a Pyrex version that compiles pyx->c
+# replacing it with a Spike version that compiles pyx->c
# before calling the original build_ext command.
# July 2002, Graham Fawcett
# Modified by Darrell Gallion <dgallion1 at yahoo.com>
@@ -7,9 +7,9 @@
# Pyrex is (c) Greg Ewing.
import distutils.command.build_ext
-#import Pyrex.Compiler.Main
-from Pyrex.Compiler.Main import CompilationOptions, default_options, compile
-from Pyrex.Compiler.Errors import PyrexError
+#import Spike.Compiler.Main
+from Spike.Compiler.Main import CompilationOptions, default_options, compile
+from Spike.Compiler.Errors import SpikeError
from distutils.dep_util import newer
import os
import sys
@@ -19,7 +19,7 @@
class build_ext (distutils.command.build_ext.build_ext):
- description = "compile Pyrex scripts, then build C/C++ extensions (compile/link to build directory)"
+ description = "compile Spike scripts, then build C/C++ extensions (compile/link to build directory)"
def finalize_options (self):
distutils.command.build_ext.build_ext.finalize_options(self)
Modified: cs/babel/trunk/spike/Spike/Mac/DarwinSystem.py
===================================================================
--- cs/babel/trunk/spike/Spike/Mac/DarwinSystem.py 2007-01-26 03:29:08 UTC (rev 5902)
+++ cs/babel/trunk/spike/Spike/Mac/DarwinSystem.py 2007-01-26 04:10:35 UTC (rev 5903)
@@ -1,5 +1,5 @@
#
-# Pyrex - Darwin system interface
+# Spike - Darwin system interface
#
verbose = 0
@@ -7,8 +7,8 @@
gcc_warnings_are_errors = False
import os
-from Pyrex.Utils import replace_suffix
-from Pyrex.Compiler.Errors import PyrexError
+from Spike.Utils import replace_suffix
+from Spike.Compiler.Errors import SpikeError
py_include_dirs = [
"/Library/Frameworks/Python.framework/Headers"
@@ -29,7 +29,7 @@
"-Wl,-F.,-w -bundle -framework Python" \
.split()
-class CCompilerError(PyrexError):
+class CCompilerError(SpikeError):
pass
def c_compile(c_file, verbose_flag = 0, cplus = 0, obj_suffix = ".o"):
Modified: cs/babel/trunk/spike/Spike/Mac/MacSystem.py
===================================================================
--- cs/babel/trunk/spike/Spike/Mac/MacSystem.py 2007-01-26 03:29:08 UTC (rev 5902)
+++ cs/babel/trunk/spike/Spike/Mac/MacSystem.py 2007-01-26 04:10:35 UTC (rev 5903)
@@ -1,13 +1,13 @@
#
-# Pyrex -- Mac system interface
+# Spike -- Mac system interface
#
import os, sys, string
import aetools
from aetools import TalkTo
from StdSuites.Standard_Suite import Standard_Suite_Events as Standard_Suite
-from Pyrex.Utils import replace_suffix
-from Pyrex.Compiler.Errors import PyrexError
+from Spike.Utils import replace_suffix
+from Spike.Compiler.Errors import SpikeError
c_compiler = "MWCPPC"
c_optimizations = "off"
@@ -35,7 +35,7 @@
#mwlibdir + "MathLib",
)
-class CCompilerError(PyrexError):
+class CCompilerError(SpikeError):
pass
#---------------- ToolServer ---------------------------
@@ -121,8 +121,8 @@
if arg.endswith(".c"):
try:
obj = c_compile(arg)
- except PyrexError, e:
- #print "Caught a PyrexError:" ###
+ except SpikeError, e:
+ #print "Caught a SpikeError:" ###
#print repr(e) ###
print "%s.%s:" % (e.__class__.__module__,
e.__class__.__name__), e
Modified: cs/babel/trunk/spike/Spike/Mac/MacUtils.py
===================================================================
--- cs/babel/trunk/spike/Spike/Mac/MacUtils.py 2007-01-26 03:29:08 UTC (rev 5902)
+++ cs/babel/trunk/spike/Spike/Mac/MacUtils.py 2007-01-26 04:10:35 UTC (rev 5903)
@@ -1,5 +1,5 @@
#
-# Pyrex -- Misc Mac-specific things
+# Spike -- Misc Mac-specific things
#
import os, MacOS, macfs
Modified: cs/babel/trunk/spike/Spike/Utils.py
===================================================================
--- cs/babel/trunk/spike/Spike/Utils.py 2007-01-26 03:29:08 UTC (rev 5902)
+++ cs/babel/trunk/spike/Spike/Utils.py 2007-01-26 04:10:35 UTC (rev 5903)
@@ -1,5 +1,5 @@
#
-# Pyrex -- Things that don't belong
+# Spike -- Things that don't belong
# anywhere else in particular
#
Modified: cs/babel/trunk/spike/setup.py
===================================================================
--- cs/babel/trunk/spike/setup.py 2007-01-26 03:29:08 UTC (rev 5902)
+++ cs/babel/trunk/spike/setup.py 2007-01-26 04:10:35 UTC (rev 5903)
@@ -1,7 +1,7 @@
from distutils.core import setup
from distutils.sysconfig import get_python_lib
import os
-from Pyrex.Compiler.Version import version
+from Spike.Compiler.Version import version
compiler_dir = os.path.join(get_python_lib(prefix=''), 'Spike/Compiler')
More information about the cig-commits
mailing list