diff options
author | Guido van Rossum <guido@python.org> | 1995-03-02 14:05:29 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1995-03-02 14:05:29 (GMT) |
commit | d211220cd2ea4e51f58cd30fb8fa22a1a62b3b2d (patch) | |
tree | 64cc091fbaf5531ea833bdc2cad32f4731617a7e /Tools/modulator/Templates | |
parent | df804f8591bcb38ffd4a915c76bd6277ce766a5e (diff) | |
download | cpython-d211220cd2ea4e51f58cd30fb8fa22a1a62b3b2d.zip cpython-d211220cd2ea4e51f58cd30fb8fa22a1a62b3b2d.tar.gz cpython-d211220cd2ea4e51f58cd30fb8fa22a1a62b3b2d.tar.bz2 |
checkin of Jack's original version
Diffstat (limited to 'Tools/modulator/Templates')
20 files changed, 593 insertions, 0 deletions
diff --git a/Tools/modulator/Templates/copyright b/Tools/modulator/Templates/copyright new file mode 100644 index 0000000..86206c3 --- /dev/null +++ b/Tools/modulator/Templates/copyright @@ -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. + +******************************************************************/ diff --git a/Tools/modulator/Templates/module_head b/Tools/modulator/Templates/module_head new file mode 100644 index 0000000..d1fafdc --- /dev/null +++ b/Tools/modulator/Templates/module_head @@ -0,0 +1,7 @@ + +#include "allobjects.h" +#include "modsupport.h" /* For getargs() etc. */ + +static object *ErrorObject; + +/* ----------------------------------------------------- */ diff --git a/Tools/modulator/Templates/module_method b/Tools/modulator/Templates/module_method new file mode 100644 index 0000000..bf64e79 --- /dev/null +++ b/Tools/modulator/Templates/module_method @@ -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; +} diff --git a/Tools/modulator/Templates/module_tail b/Tools/modulator/Templates/module_tail new file mode 100644 index 0000000..466c84a --- /dev/null +++ b/Tools/modulator/Templates/module_tail @@ -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$"); +} diff --git a/Tools/modulator/Templates/object_head b/Tools/modulator/Templates/object_head new file mode 100644 index 0000000..bf69a51 --- /dev/null +++ b/Tools/modulator/Templates/object_head @@ -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) + +/* ---------------------------------------------------------------- */ diff --git a/Tools/modulator/Templates/object_method b/Tools/modulator/Templates/object_method new file mode 100644 index 0000000..20896de --- /dev/null +++ b/Tools/modulator/Templates/object_method @@ -0,0 +1,11 @@ + +static object * +$abbrev$_$method$(self, args) + $abbrev$object *self; + object *args; +{ + if (!newgetargs(args, "")) + return NULL; + INCREF(None); + return None; +} diff --git a/Tools/modulator/Templates/object_mlist b/Tools/modulator/Templates/object_mlist new file mode 100644 index 0000000..62d5894 --- /dev/null +++ b/Tools/modulator/Templates/object_mlist @@ -0,0 +1,7 @@ + +static struct methodlist $abbrev$_methods[] = { + $methodlist$ + {NULL, NULL} /* sentinel */ +}; + +/* ---------- */ diff --git a/Tools/modulator/Templates/object_new b/Tools/modulator/Templates/object_new new file mode 100644 index 0000000..1817a55 --- /dev/null +++ b/Tools/modulator/Templates/object_new @@ -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; +} diff --git a/Tools/modulator/Templates/object_structure b/Tools/modulator/Templates/object_structure new file mode 100644 index 0000000..6a54518 --- /dev/null +++ b/Tools/modulator/Templates/object_structure @@ -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); +} + diff --git a/Tools/modulator/Templates/object_tail b/Tools/modulator/Templates/object_tail new file mode 100644 index 0000000..9bc78ca --- /dev/null +++ b/Tools/modulator/Templates/object_tail @@ -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 */ +/* -------------------------------------------------------- */ diff --git a/Tools/modulator/Templates/object_tp_as_mapping b/Tools/modulator/Templates/object_tp_as_mapping new file mode 100644 index 0000000..c5edf3e --- /dev/null +++ b/Tools/modulator/Templates/object_tp_as_mapping @@ -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*/ +}; + +/* -------------------------------------------------------- */ diff --git a/Tools/modulator/Templates/object_tp_as_number b/Tools/modulator/Templates/object_tp_as_number new file mode 100644 index 0000000..b97d473 --- /dev/null +++ b/Tools/modulator/Templates/object_tp_as_number @@ -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*/ +}; + +/* ------------------------------------------------------- */ diff --git a/Tools/modulator/Templates/object_tp_as_sequence b/Tools/modulator/Templates/object_tp_as_sequence new file mode 100644 index 0000000..50f2f91 --- /dev/null +++ b/Tools/modulator/Templates/object_tp_as_sequence @@ -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*/ +}; + +/* -------------------------------------------------------------- */ diff --git a/Tools/modulator/Templates/object_tp_compare b/Tools/modulator/Templates/object_tp_compare new file mode 100644 index 0000000..a2e2e9d --- /dev/null +++ b/Tools/modulator/Templates/object_tp_compare @@ -0,0 +1,7 @@ + +static int +$abbrev$_compare(v, w) + $abbrev$object *v, *w; +{ + /* XXXX Compare objects and return -1, 0 or 1 */ +} diff --git a/Tools/modulator/Templates/object_tp_dealloc b/Tools/modulator/Templates/object_tp_dealloc new file mode 100644 index 0000000..b4d573e --- /dev/null +++ b/Tools/modulator/Templates/object_tp_dealloc @@ -0,0 +1,8 @@ + +static void +$abbrev$_dealloc(self) + $abbrev$object *self; +{ + /* XXXX Add your own cleanup code here */ + DEL(self); +} diff --git a/Tools/modulator/Templates/object_tp_getattr b/Tools/modulator/Templates/object_tp_getattr new file mode 100644 index 0000000..3e5542f --- /dev/null +++ b/Tools/modulator/Templates/object_tp_getattr @@ -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); +} diff --git a/Tools/modulator/Templates/object_tp_hash b/Tools/modulator/Templates/object_tp_hash new file mode 100644 index 0000000..1681b4a --- /dev/null +++ b/Tools/modulator/Templates/object_tp_hash @@ -0,0 +1,7 @@ + +static long +$abbrev$_hash(self) + $abbrev$object *self; +{ + /* XXXX Return a hash of self (or -1) */ +} diff --git a/Tools/modulator/Templates/object_tp_print b/Tools/modulator/Templates/object_tp_print new file mode 100644 index 0000000..017712e --- /dev/null +++ b/Tools/modulator/Templates/object_tp_print @@ -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; +} diff --git a/Tools/modulator/Templates/object_tp_repr b/Tools/modulator/Templates/object_tp_repr new file mode 100644 index 0000000..45c78df --- /dev/null +++ b/Tools/modulator/Templates/object_tp_repr @@ -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; +} diff --git a/Tools/modulator/Templates/object_tp_setattr b/Tools/modulator/Templates/object_tp_setattr new file mode 100644 index 0000000..d4da0ce --- /dev/null +++ b/Tools/modulator/Templates/object_tp_setattr @@ -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; +} |