checkin of Jack's original version

This commit is contained in:
Guido van Rossum 1995-03-02 14:05:29 +00:00
parent df804f8591
commit d211220cd2
27 changed files with 1525 additions and 0 deletions

View file

@ -0,0 +1,23 @@
/***********************************************************
Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam,
The Netherlands.
All Rights Reserved
Permission to use, copy, modify, and distribute this software and its
documentation for any purpose and without fee is hereby granted,
provided that the above copyright notice appear in all copies and that
both that copyright notice and this permission notice appear in
supporting documentation, and that the names of Stichting Mathematisch
Centrum or CWI not be used in advertising or publicity pertaining to
distribution of the software without specific, written prior permission.
STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
******************************************************************/

View file

@ -0,0 +1,7 @@
#include "allobjects.h"
#include "modsupport.h" /* For getargs() etc. */
static object *ErrorObject;
/* ----------------------------------------------------- */

View file

@ -0,0 +1,12 @@
static object *
$abbrev$_$method$(self, args)
object *self; /* Not used */
object *args;
{
if (!newgetargs(args, ""))
return NULL;
INCREF(None);
return None;
}

View file

@ -0,0 +1,30 @@
/* List of methods defined in the module */
static struct methodlist $abbrev$_methods[] = {
$methodlist$
{NULL, NULL} /* sentinel */
};
/* Initialization function for the module (*must* be called init$name$) */
void
init$name$()
{
object *m, *d;
/* Create the module and add the functions */
m = initmodule("$name$", $abbrev$_methods);
/* Add some symbolic constants to the module */
d = getmoduledict(m);
ErrorObject = newstringobject("$name$.error");
dictinsert(d, "error", ErrorObject);
/* XXXX Add constants here */
/* Check for errors */
if (err_occurred())
fatal("can't initialize module $name$");
}

View file

@ -0,0 +1,12 @@
/* Declarations for objects of type $name$ */
typedef struct {
OB_HEAD
/* XXXX Add your own stuff here */
} $abbrev$object;
staticforward typeobject $Abbrev$type;
#define is_$abbrev$object(v) ((v)->ob_type == &$Abbrev$type)
/* ---------------------------------------------------------------- */

View file

@ -0,0 +1,11 @@
static object *
$abbrev$_$method$(self, args)
$abbrev$object *self;
object *args;
{
if (!newgetargs(args, ""))
return NULL;
INCREF(None);
return None;
}

View file

@ -0,0 +1,7 @@
static struct methodlist $abbrev$_methods[] = {
$methodlist$
{NULL, NULL} /* sentinel */
};
/* ---------- */

View file

@ -0,0 +1,12 @@
static $abbrev$object *
new$abbrev$object()
{
$abbrev$object *self;
self = NEWOBJ($abbrev$object, &$Abbrev$type);
if (self == NULL)
return NULL;
/* XXXX Add your own initializers here */
return self;
}

View file

@ -0,0 +1,41 @@
/* Code to access structure members by accessing attributes */
#include "structmember.h"
#define OFF(x) offsetof(XXXXobject, x)
static struct memberlist $abbrev$_memberlist[] = {
/* XXXX Add lines like { "foo", T_INT, OFF(foo), RO } */
{NULL} /* Sentinel */
};
static object *
$abbrev$_getattr(self, name)
$abbrev$object *self;
char *name;
{
object *rv;
/* XXXX Add your own getattr code here */
rv = getmember((char *)/*XXXX*/0, $abbrev$_memberlist, name);
if (rv)
return rv;
err_clear();
return findmethod($abbrev$_methods, (object *)self, name);
}
static int
$abbrev$_setattr(self, name, v)
$abbrev$object *self;
char *name;
object *v;
{
/* XXXX Add your own setattr code here */
if ( v == NULL ) {
err_setstr(AttributeError, "Cannot delete attribute");
return -1;
}
return setmember((char *)/*XXXX*/0, $abbrev$_memberlist, name, v);
}

View file

@ -0,0 +1,22 @@
static typeobject $Abbrev$type = {
OB_HEAD_INIT(&Typetype)
0, /*ob_size*/
"$name$", /*tp_name*/
sizeof($abbrev$object), /*tp_basicsize*/
0, /*tp_itemsize*/
/* methods */
(destructor)$tp_dealloc$, /*tp_dealloc*/
(printfunc)$tp_print$, /*tp_print*/
(getattrfunc)$tp_getattr$, /*tp_getattr*/
(setattrfunc)$tp_setattr$, /*tp_setattr*/
(cmpfunc)$tp_compare$, /*tp_compare*/
(reprfunc)$tp_repr$, /*tp_repr*/
$tp_as_number$, /*tp_as_number*/
$tp_as_sequence$, /*tp_as_sequence*/
$tp_as_mapping$, /*tp_as_mapping*/
(hashfunc)$tp_hash$, /*tp_hash*/
};
/* End of code for $name$ objects */
/* -------------------------------------------------------- */

View file

@ -0,0 +1,33 @@
/* Code to access $name$ objects as mappings */
static int
$abbrev$_length(self)
$abbrev$object *self;
{
/* XXXX Return the size of the mapping */
}
static object *
$abbrev$_subscript(self, key)
$abbrev$object *self;
object *key;
{
/* XXXX Return the item of self indexed by key */
}
static int
$abbrev$_ass_sub(self, v, w)
$abbrev$object *self;
object *v, *w;
{
/* XXXX Put w in self under key v */
return 0;
}
static mapping_methods $abbrev$_as_mapping = {
(inquiry)$abbrev$_length, /*mp_length*/
(binaryfunc)$abbrev$_subscript, /*mp_subscript*/
(objobjargproc)$abbrev$_ass_sub, /*mp_ass_subscript*/
};
/* -------------------------------------------------------- */

View file

@ -0,0 +1,249 @@
/* Code to access $name$ objects as numbers */
static object *
$abbrev$_add(v, w)
$abbrev$object *v;
$abbrev$object *w;
{
/* XXXX Add them */
err_setstr(SystemError, "not implemented");
return NULL;
}
static object *
$abbrev$_sub(v, w)
$abbrev$object *v;
$abbrev$object *w;
{
/* XXXX Subtract them */
err_setstr(SystemError, "not implemented");
return NULL;
}
static object *
$abbrev$_mul(v, w)
$abbrev$object *v;
$abbrev$object *w;
{
/* XXXX Multiply them */
err_setstr(SystemError, "not implemented");
return NULL;
}
static object *
$abbrev$_div(x, y)
$abbrev$object *x;
$abbrev$object *y;
{
/* XXXX Divide them */
err_setstr(SystemError, "not implemented");
return NULL;
}
static object *
$abbrev$_mod(x, y)
$abbrev$object *x;
$abbrev$object *y;
{
/* XXXX Modulo them */
err_setstr(SystemError, "not implemented");
return NULL;
}
static object *
$abbrev$_divmod(x, y)
$abbrev$object *x;
$abbrev$object *y;
{
/* XXXX Return 2-tuple with div and mod */
err_setstr(SystemError, "not implemented");
return NULL;
}
static object *
$abbrev$_pow(v, w, z)
$abbrev$object *v;
$abbrev$object *w;
$abbrev$object *z;
{
/* XXXX */
err_setstr(SystemError, "not implemented");
return NULL;
}
static object *
$abbrev$_neg(v)
$abbrev$object *v;
{
/* XXXX */
err_setstr(SystemError, "not implemented");
return NULL;
}
static object *
$abbrev$_pos(v)
$abbrev$object *v;
{
/* XXXX */
err_setstr(SystemError, "not implemented");
return NULL;
}
static object *
$abbrev$_abs(v)
$abbrev$object *v;
{
/* XXXX */
err_setstr(SystemError, "not implemented");
return NULL;
}
static int
$abbrev$_nonzero(v)
$abbrev$object *v;
{
/* XXXX Return 1 if non-zero */
err_setstr(SystemError, "not implemented");
return -1;
}
static object *
$abbrev$_invert(v)
$abbrev$object *v;
{
/* XXXX */
err_setstr(SystemError, "not implemented");
return NULL;
}
static object *
$abbrev$_lshift(v, w)
$abbrev$object *v;
$abbrev$object *w;
{
/* XXXX */
err_setstr(SystemError, "not implemented");
return NULL;
}
static object *
$abbrev$_rshift(v, w)
$abbrev$object *v;
$abbrev$object *w;
{
/* XXXX */
err_setstr(SystemError, "not implemented");
return NULL;
}
static object *
$abbrev$_and(v, w)
$abbrev$object *v;
$abbrev$object *w;
{
/* XXXX */
err_setstr(SystemError, "not implemented");
return NULL;
}
static object *
$abbrev$_xor(v, w)
$abbrev$object *v;
$abbrev$object *w;
{
/* XXXX */
err_setstr(SystemError, "not implemented");
return NULL;
}
static object *
$abbrev$_or(v, w)
$abbrev$object *v;
$abbrev$object *w;
{
/* XXXX */
err_setstr(SystemError, "not implemented");
return NULL;
}
static int
$abbrev$_coerce(pv, pw)
object **pv;
object **pw;
{
/* XXXX I haven't a clue... */
return 1;
}
static object *
$abbrev$_int(v)
$abbrev$object *v;
{
/* XXXX */
err_setstr(SystemError, "not implemented");
return NULL;
}
static object *
$abbrev$_long(v)
$abbrev$object *v;
{
/* XXXX */
err_setstr(SystemError, "not implemented");
return NULL;
}
static object *
$abbrev$_float(v)
$abbrev$object *v;
{
/* XXXX */
err_setstr(SystemError, "not implemented");
return NULL;
}
static object *
$abbrev$_oct(v)
$abbrev$object *v;
{
/* XXXX Return object as octal stringobject */
err_setstr(SystemError, "not implemented");
return NULL;
}
static object *
$abbrev$_hex(v)
$abbrev$object *v;
{
/* XXXX Return object as hex stringobject */
err_setstr(SystemError, "not implemented");
return NULL;
}
static number_methods $abbrev$_as_number = {
(binaryfunc)$abbrev$_add, /*nb_add*/
(binaryfunc)$abbrev$_sub, /*nb_subtract*/
(binaryfunc)$abbrev$_mul, /*nb_multiply*/
(binaryfunc)$abbrev$_div, /*nb_divide*/
(binaryfunc)$abbrev$_mod, /*nb_remainder*/
(binaryfunc)$abbrev$_divmod, /*nb_divmod*/
(ternaryfunc)$abbrev$_pow, /*nb_power*/
(unaryfunc)$abbrev$_neg, /*nb_negative*/
(unaryfunc)$abbrev$_pos, /*nb_positive*/
(unaryfunc)$abbrev$_abs, /*nb_absolute*/
(inquiry)$abbrev$_nonzero, /*nb_nonzero*/
(unaryfunc)$abbrev$_invert, /*nb_invert*/
(binaryfunc)$abbrev$_lshift, /*nb_lshift*/
(binaryfunc)$abbrev$_rshift, /*nb_rshift*/
(binaryfunc)$abbrev$_and, /*nb_and*/
(binaryfunc)$abbrev$_xor, /*nb_xor*/
(binaryfunc)$abbrev$_or, /*nb_or*/
(coercion)$abbrev$_coerce, /*nb_coerce*/
(unaryfunc)$abbrev$_int, /*nb_int*/
(unaryfunc)$abbrev$_long, /*nb_long*/
(unaryfunc)$abbrev$_float, /*nb_float*/
(unaryfunc)$abbrev$_oct, /*nb_oct*/
(unaryfunc)$abbrev$_hex, /*nb_hex*/
};
/* ------------------------------------------------------- */

View file

@ -0,0 +1,73 @@
/* Code to handle accessing $name$ objects as sequence objects */
static int
$abbrev$_length(self)
$abbrev$object *self;
{
/* XXXX Return the size of the object */
}
static object *
$abbrev$_concat(self, bb)
$abbrev$object *self;
object *bb;
{
/* XXXX Return the concatenation of self and bb */
}
static object *
$abbrev$_repeat(self, n)
$abbrev$object *self;
int n;
{
/* XXXX Return a new object that is n times self */
}
static object *
$abbrev$_item(self, i)
$abbrev$object *self;
int i;
{
/* XXXX Return the i-th object of self */
}
static object *
$abbrev$_slice(self, ilow, ihigh)
$abbrev$object *self;
int ilow, ihigh;
{
/* XXXX Return the ilow..ihigh slice of self in a new object */
}
static int
$abbrev$_ass_item(self, i, v)
$abbrev$object *self;
int i;
object *v;
{
/* XXXX Assign to the i-th element of self */
return 0;
}
static int
$abbrev$_ass_slice(self, ilow, ihigh, v)
listobject *self;
int ilow, ihigh;
object *v;
{
/* XXXX Replace ilow..ihigh slice of self with v */
return 0;
}
static sequence_methods $abbrev$_as_sequence = {
(inquiry)$abbrev$_length, /*sq_length*/
(binaryfunc)$abbrev$_concat, /*sq_concat*/
(intargfunc)$abbrev$_repeat, /*sq_repeat*/
(intargfunc)$abbrev$_item, /*sq_item*/
(intintargfunc)$abbrev$_slice, /*sq_slice*/
(intobjargproc)$abbrev$_ass_item, /*sq_ass_item*/
(intintobjargproc)$abbrev$_ass_slice, /*sq_ass_slice*/
};
/* -------------------------------------------------------------- */

View file

@ -0,0 +1,7 @@
static int
$abbrev$_compare(v, w)
$abbrev$object *v, *w;
{
/* XXXX Compare objects and return -1, 0 or 1 */
}

View file

@ -0,0 +1,8 @@
static void
$abbrev$_dealloc(self)
$abbrev$object *self;
{
/* XXXX Add your own cleanup code here */
DEL(self);
}

View file

@ -0,0 +1,9 @@
static object *
$abbrev$_getattr(self, name)
$abbrev$object *self;
char *name;
{
/* XXXX Add your own getattr code here */
return findmethod($abbrev$_methods, (object *)self, name);
}

View file

@ -0,0 +1,7 @@
static long
$abbrev$_hash(self)
$abbrev$object *self;
{
/* XXXX Return a hash of self (or -1) */
}

View file

@ -0,0 +1,10 @@
static int
$abbrev$_print(self, fp, flags)
$abbrev$object *self;
FILE *fp;
int flags;
{
/* XXXX Add code here to print self to fp */
return 0;
}

View file

@ -0,0 +1,10 @@
static object *
$abbrev$_repr(self)
$abbrev$object *self;
{
object *s;
/* XXXX Add code here to put self into s */
return s;
}

View file

@ -0,0 +1,10 @@
static int
$abbrev$_setattr(self, name, v)
$abbrev$object *self;
char *name;
object *v;
{
/* XXXX Add your own setattr code here */
return -1;
}