Commits

Guido van Rossum  committed a693438

"Compiling" version

  • Participants
  • Parent commits 06c92f4
  • Branches legacy-trunk

Comments (0)

Files changed (72)

File Include/allobjects.h

+/* "allobjects.c" -- Source for precompiled header "allobjects.h" */
+
+#include <stdio.h>
+#include "string.h"
+
+#include "PROTO.h"
+
+#include "object.h"
+#include "objimpl.h"
+
+#include "intobject.h"
+#include "floatobject.h"
+#include "stringobject.h"
+#include "tupleobject.h"
+#include "listobject.h"
+#include "dictobject.h"
+#include "methodobject.h"
+#include "moduleobject.h"
+#include "funcobject.h"
+#include "classobject.h"
+#include "fileobject.h"
+
+#include "errors.h"
+#include "malloc.h"
+
+extern char *strdup PROTO((const char *));

File Include/bltinmodule.h

+/* Built-in module interface */
+
+extern object *getbuiltin PROTO((char *));

File Include/ceval.h

+/* Interface to execute compiled code */
+/* This header depends on "compile.h" */
+
+object *eval_code PROTO((codeobject *, object *, object *, object *));
+
+object *getglobals PROTO((void));
+object *getlocals PROTO((void));
+
+void printtraceback PROTO((FILE *));

File Include/classobject.h

 #define is_classmemberobject(op) ((op)->ob_type == &Classmembertype)
 #define is_classmethodobject(op) ((op)->ob_type == &Classmethodtype)
 
-extern object *newclassobject PROTO((node *, object *, object *));
+extern object *newclassobject PROTO((object *, object *));
 extern object *newclassmemberobject PROTO((object *));
 extern object *newclassmethodobject PROTO((object *, object *));
 

File Include/compile.h

+/* Definitions for compiled intermediate code */
+
+
+/* An intermediate code fragment contains:
+   - a string that encodes the instructions,
+   - a list of the constants,
+   - and a list of the names used. */
+
+typedef struct {
+	OB_HEAD
+	stringobject *co_code;	/* instruction opcodes */
+	object *co_consts;	/* list of immutable constant objects */
+	object *co_names;	/* list of stringobjects */
+	object *co_filename;	/* string */
+} codeobject;
+
+extern typeobject Codetype;
+
+#define is_codeobject(op) ((op)->ob_type == &Codetype)
+
+
+/* Public interface */
+codeobject *compile PROTO((struct _node *, char *));

File Include/errors.h

 void err_get PROTO((object **, object **));
 void err_clear PROTO((void));
 
-/* Predefined exceptions (in run.c) */
+/* Predefined exceptions */
 
 extern object *RuntimeError;
 extern object *EOFError;
 extern int err_badarg PROTO((void));
 extern object *err_nomem PROTO((void));
 extern object *err_errno PROTO((object *));
+extern void err_input PROTO((int));
 
 extern void err_badcall PROTO((void));

File Include/frameobject.h

+/* Frame object interface */
+
+typedef struct {
+	int b_type;		/* what kind of block this is */
+	int b_handler;		/* where to jump to find handler */
+	int b_level;		/* value stack level to pop to */
+} block;
+
+typedef struct _frame {
+	OB_HEAD
+	struct _frame *f_back;	/* previous frame, or NULL */
+	codeobject *f_code;	/* code segment */
+	object *f_globals;	/* global symbol table (dictobject) */
+	object *f_locals;	/* local symbol table (dictobject) */
+	object **f_valuestack;	/* malloc'ed array */
+	block *f_blockstack;	/* malloc'ed array */
+	int f_nvalues;		/* size of f_valuestack */
+	int f_nblocks;		/* size of f_blockstack */
+	int f_iblock;		/* index in f_blockstack */
+} frameobject;
+
+
+/* Standard object interface */
+
+extern typeobject Frametype;
+
+#define is_frameobject(op) ((op)->ob_type == &Frametype)
+
+frameobject * newframeobject PROTO(
+	(frameobject *, codeobject *, object *, object *, int, int));
+
+
+/* The rest of the interface is specific for frame objects */
+
+/* List access macros */
+
+#ifdef NDEBUG
+#define GETITEM(v, i) GETLISTITEM((listobject *)(v), (i))
+#define GETITEMNAME(v, i) GETSTRINGVALUE((stringobject *)GETITEM((v), (i)))
+#else
+#define GETITEM(v, i) getlistitem((v), (i))
+#define GETITEMNAME(v, i) getstringvalue(getlistitem((v), (i)))
+#endif
+
+#define GETUSTRINGVALUE(s) ((unsigned char *)GETSTRINGVALUE(s))
+
+/* Code access macros */
+
+#define Getconst(f, i)	(GETITEM((f)->f_code->co_consts, (i)))
+#define Getname(f, i)	(GETITEMNAME((f)->f_code->co_names, (i)))
+
+
+/* Block management functions */
+
+void setup_block PROTO((frameobject *, int, int, int));
+block *pop_block PROTO((frameobject *));

File Include/grammar.h

 void addfirstsets PROTO((grammar *g));
 
 void addaccellerators PROTO((grammar *g));
+
+void printgrammar PROTO((grammar *g, FILE *fp));
+void printnonterminals PROTO((grammar *g, FILE *fp));

File Include/import.h

 /* Module definition and import interface */
 
-object *new_module PROTO((char *name));
-object *import_module PROTO((struct _context *ctx, char *name));
-object *reload_module PROTO((struct _context *ctx, object *m));
+object *get_modules PROTO((void));
+object *add_module PROTO((char *name));
+object *import_module PROTO((char *name));
+object *reload_module PROTO((object *m));
+void doneimport PROTO((void));

File Include/listobject.h

 returned item's reference count.
 */
 
+typedef struct {
+	OB_VARHEAD
+	object **ob_item;
+} listobject;
+
 extern typeobject Listtype;
 
 #define is_listobject(op) ((op)->ob_type == &Listtype)
 extern int inslistitem PROTO((object *, int, object *));
 extern int addlistitem PROTO((object *, object *));
 extern int sortlist PROTO((object *));
+
+/* Macro, trading safety for speed */
+#define GETLISTITEM(op, i) ((op)->ob_item[i])

File Include/methodobject.h

 extern object *newmethodobject PROTO((char *, method, object *));
 extern method getmethod PROTO((object *));
 extern object *getself PROTO((object *));
+
+struct methodlist {
+	char *ml_name;
+	method ml_meth;
+};
+
+extern object *findmethod PROTO((struct methodlist *, object *, char *));

File Include/modsupport.h

 /* Module support interface */
 
-struct methodlist {
-	char *ml_name;
-	method ml_meth;
-};
-
-extern object *findmethod PROTO((struct methodlist *, object *, char *));
 extern object *initmodule PROTO((char *, struct methodlist *));

File Include/moduleobject.h

 
 extern object *newmoduleobject PROTO((char *));
 extern object *getmoduledict PROTO((object *));
-extern int setmoduledict PROTO((object *, object *));
 extern char *getmodulename PROTO((object *));

File Include/node.h

 typedef struct _node {
 	int		n_type;
 	char		*n_str;
+	int		n_lineno;
 	int		n_nchildren;
 	struct _node	*n_child;
 } node;
 
-extern node *newnode PROTO((int type));
-extern node *addchild PROTO((node *n, int type, char *str));
-extern void freenode PROTO((node *n));
+extern node *newtree PROTO((int type));
+extern node *addchild PROTO((node *n, int type, char *str, int lineno));
+extern void freetree PROTO((node *n));
 
 /* Node access functions */
 #define NCH(n)		((n)->n_nchildren)
 		abort(); \
 	} }
 #endif
+
+extern void listtree PROTO((node *));
+extern void listnode PROTO((FILE *, node *));

File Include/object.h

+#define NDEBUG
 /* Object and type object interface */
 
 /*
 123456789-123456789-123456789-123456789-123456789-123456789-123456789-12
 */
 
-#ifdef THINK_C
-/* Debugging options for THINK_C (which has no -D compiler option): */
-/*#define TRACE_REFS*/
-/*#define REF_DEBUG*/
-#endif
+#ifndef NDEBUG
+
+/* Turn on heavy reference debugging */
+#define TRACE_REFS
+
+/* Turn on reference counting */
+#define REF_DEBUG
+
+#endif /* NDEBUG */
 
 #ifdef TRACE_REFS
 #define OB_HEAD \
 
 #define is_typeobject(op) ((op)->ob_type == &Typetype)
 
+/* Generic operations on objects */
 extern void printobject PROTO((object *, FILE *, int));
 extern object * reprobject PROTO((object *));
 extern int cmpobject PROTO((object *, object *));
+extern object *getattr PROTO((object *, char *));
+extern int setattr PROTO((object *, char *, object *));
 
 /* Flag bits for printing: */
 #define PRINT_RAW	1	/* No string quotes etc. */
 		DELREF(op)
 #endif
 
+/* Macros to use in case the object pointer may be NULL: */
+
+#define XINCREF(op) if ((op) == NULL) ; else INCREF(op)
+#define XDECREF(op) if ((op) == NULL) ; else DECREF(op)
 
 /* Definition of NULL, so you don't have to include <stdio.h> */
 
 -------------
 
 Functions may fail for a variety of reasons, including running out of
-memory.  This is communicated to the caller in two ways: 'errno' is set
-to indicate the error, and the function result differs: functions that
-normally return a pointer return nil for failure, functions returning
-an integer return -1 (which can be a legal return value too!), and
-other functions return 0 for success and the error number for failure.
-Callers should always check for errors before using the result.  The
-following error codes are used:
-
-	EBADF		bad object type (first argument only)
-	EINVAL		bad argument type (second and further arguments)
-	ENOMEM		no memory (malloc failed)
-	ENOENT		key not found in dictionary
-	EDOM		index out of range or division by zero
-	ERANGE		result not representable
-	
-	XXX any others?
+memory.  This is communicated to the caller in two ways: an error string
+is set (see errors.h), and the function result differs: functions that
+normally return a pointer return NULL for failure, functions returning
+an integer return -1 (which could be a legal return value too!), and
+other functions return 0 for success and -1 for failure.
+Callers should always check for errors before using the result.
 
 Reference Counts
 ----------------
 
 123456789-123456789-123456789-123456789-123456789-123456789-123456789-12
 */
-
-/* Error number interface */
-#include <errno.h>
-
-#ifndef errno
-extern int errno;
-#endif
-
-#ifdef THINK_C
-/* Lightspeed C doesn't define these in <errno.h> */
-#define EDOM 33
-#define ERANGE 34
-#endif

File Include/objimpl.h

 #define NEWVAROBJ(type, typeobj, n) ((type *) newvarobject(typeobj, n))
 
 extern int StopPrint; /* Set when printing is interrupted */
-
-/* Malloc interface */
-#include "malloc.h"
-
-extern char *strdup PROTO((const char *));

File Include/opcode.h

 /* Instruction opcodes for compiled code */
 
-#define DUP_TOP		0
+#define STOP_CODE	0
 #define POP_TOP		1
 #define ROT_TWO		2
 #define ROT_THREE	3
+#define DUP_TOP		4
 
 #define UNARY_POSITIVE	10
 #define UNARY_NEGATIVE	11
 #define SETUP_EXCEPT	121	/* "" */
 #define SETUP_FINALLY	122	/* "" */
 
+#define SET_LINENO	127	/* Current line number */
+
 /* Comparison operator codes (argument to COMPARE_OP) */
 enum cmp_op {LT, LE, EQ, NE, GT, GE, IN, NOT_IN, IS, IS_NOT, EXC_MATCH, BAD};
+
+#define HAS_ARG(op) ((op) >= HAVE_ARGUMENT)

File Include/parsetok.h

 /* Parser-tokenizer link interface */
 
-#if 0
-extern int parsetok PROTO((struct tok_state *, grammar *, int start,
-							node **n_ret));
-#endif
 extern int parsestring PROTO((char *, grammar *, int start, node **n_ret));
-extern int parsefile PROTO((FILE *, grammar *, int start,
+extern int parsefile PROTO((FILE *, char *, grammar *, int start,
 					char *ps1, char *ps2, node **n_ret));

File Include/pgenheaders.h

+/* Include files and extern declarations used by most of the parser.
+   This is a precompiled header for THINK C. */
+
+#include <stdio.h>
+
+#ifdef THINK_C
+#define label label_
+#include <proto.h>
+#undef label
+#endif
+
+#include "PROTO.h"
+#include "malloc.h"
+
+extern void fatal PROTO((char *));

File Include/pyerrors.h

 void err_get PROTO((object **, object **));
 void err_clear PROTO((void));
 
-/* Predefined exceptions (in run.c) */
+/* Predefined exceptions */
 
 extern object *RuntimeError;
 extern object *EOFError;
 extern int err_badarg PROTO((void));
 extern object *err_nomem PROTO((void));
 extern object *err_errno PROTO((object *));
+extern void err_input PROTO((int));
 
 extern void err_badcall PROTO((void));

File Include/pythonrun.h

+/* Interfaces to parse and execute pieces of python code */
+
+void initall PROTO((void));
+
+int run PROTO((FILE *, char *));
+
+int run_script PROTO((FILE *, char *));
+int run_tty_1 PROTO((FILE *, char *));
+int run_tty_loop PROTO((FILE *, char *));
+
+int parse_string PROTO((char *, int, struct _node **));
+int parse_file PROTO((FILE *, char *, int, struct _node **));
+
+object *eval_node PROTO((struct _node *, char *, object *, object *));
+
+object *run_string PROTO((char *, int, object *, object *));
+object *run_file PROTO((FILE *, char *, int, object *, object *));
+object *run_err_node PROTO((int, struct _node *, char *, object *, object *));
+object *run_node PROTO((struct _node *, char *, object *, object *));
+
+void print_error PROTO((void));
+
+void goaway PROTO((int));

File Include/structmember.h

+/* Interface to map C struct members to Python object attributes */
+
+/* The offsetof() macro calculates the offset of a structure member
+   in its structure.  Unfortunately this cannot be written down
+   portably, hence it is provided by a Standard C header file.
+   For pre-Standard C compilers, here is a version that usually works
+   (but watch out!): */
+
+#ifndef offsetof
+#define offsetof(type, member) ( (int) & ((type*)0) -> member )
+#endif
+
+/* An array of memberlist structures defines the name, type and offset
+   of selected members of a C structure.  These can be read by
+   getmember() and set by setmember() (except if their READONLY flag
+   is set).  The array must be terminated with an entry whose name
+   pointer is NULL. */
+
+struct memberlist {
+	char *name;
+	int type;
+	int offset;
+	int readonly;
+};
+
+/* Types */
+#define T_SHORT		0
+#define T_INT		1
+#define T_LONG		2
+#define T_FLOAT		3
+#define T_DOUBLE	4
+#define T_STRING	5
+#define T_OBJECT	6
+
+/* Readonly flag */
+#define READONLY	1
+#define RO		READONLY		/* Shorthand */
+
+object *getmember PROTO((char *, struct memberlist *, char *));
+int setmember PROTO((char *, struct memberlist *, char *, object *));

File Include/sysmodule.h

 object *sysget PROTO((char *));
 int sysset PROTO((char *, object *));
 FILE *sysgetfile PROTO((char *, FILE *));
-void initsys PROTO((int, char **));
+void initsys PROTO((void));

File Include/traceback.h

+/* Traceback interface */
+
+int tb_here PROTO((struct _frame *, int, int));
+object *tb_fetch PROTO((void));
+int tb_store PROTO((object *));
+int tb_print PROTO((object *, FILE *));

File Include/tupleobject.h

 returned item's reference count.
 */
 
+typedef struct {
+	OB_VARHEAD
+	object *ob_item[1];
+} tupleobject;
+
 extern typeobject Tupletype;
 
 #define is_tupleobject(op) ((op)->ob_type == &Tupletype)
 extern int gettuplesize PROTO((object *));
 extern object *gettupleitem PROTO((object *, int));
 extern int settupleitem PROTO((object *, int, object *));
+
+/* Macro, trading safety for speed */
+#define GETTUPLEITEM(op, i) ((op)->ob_item[i])

File Modules/cgen.py

 #
 def getnum(s):
 	n = ''
-	while s[:1] in digits:
-		n = n + s[:1]
+	while s and s[0] in digits:
+		n = n + s[0]
 		s = s[1:]
 	return n, s
 

File Modules/cstubs

 		N*retval
 */
 
-#include <stdio.h>
 #include <gl.h>
 #include <device.h>
-#include "PROTO.h"
-#include "object.h"
-#include "intobject.h"
-#include "floatobject.h"
-#include "listobject.h"
-#include "tupleobject.h"
-#include "dictobject.h"
-#include "methodobject.h"
-#include "moduleobject.h"
-#include "objimpl.h"
+
+#include "allobjects.h"
 #include "import.h"
-#include "sigtype.h"
 #include "modsupport.h"
 #include "cgensupport.h"
-#include "errors.h"
 
 /*
 Some stubs are too complicated for the stub generator.

File Modules/mathmodule.c

 /* Math module -- standard C math library functions, pi and e */
 
-#include <stdio.h>
+#include "allobjects.h"
+
+#include "modsupport.h"
+
 #include <math.h>
 
-#include "PROTO.h"
-#include "object.h"
-#include "intobject.h"
-#include "tupleobject.h"
-#include "floatobject.h"
-#include "dictobject.h"
-#include "methodobject.h"
-#include "moduleobject.h"
-#include "objimpl.h"
-#include "import.h"
-#include "modsupport.h"
-
 static int
 getdoublearg(args, px)
 	register object *args;

File Modules/posixmodule.c

 /* POSIX module implementation */
 
-#include <stdio.h>
 #include <signal.h>
 #include <string.h>
 #include <setjmp.h>
 #include <sys/dir.h>
 #endif
 
-#include "PROTO.h"
-#include "object.h"
-#include "intobject.h"
-#include "stringobject.h"
-#include "tupleobject.h"
-#include "listobject.h"
-#include "dictobject.h"
-#include "methodobject.h"
-#include "moduleobject.h"
-#include "objimpl.h"
-#include "import.h"
-#include "sigtype.h"
+#include "allobjects.h"
 #include "modsupport.h"
-#include "errors.h"
 
 extern char *strerror PROTO((int));
 
 	v = newtupleobject(10);
 	if (v == NULL)
 		return NULL;
-	errno = 0;
 #define SET(i, st_member) settupleitem(v, i, newintobject((long)st.st_member))
 	SET(0, st_mode);
 	SET(1, st_ino);
 	SET(8, st_mtime);
 	SET(9, st_ctime);
 #undef SET
-	if (errno != 0) {
+	if (err_occurred()) {
 		DECREF(v);
-		return err_nomem();
+		return NULL;
 	}
 	return v;
 }
 
 #ifdef NO_GETCWD
 
+#include "errno.h"
+
 /* Quick hack to get posix.getcwd() working for pure BSD 4.3 */
 /* XXX This assumes MAXPATHLEN = 1024 !!! */
 

File Modules/stdwinmodule.c

    XXX more?
 */
 
-#include <stdio.h>
+#include "allobjects.h"
+
+#include "modsupport.h"
+
 #include "stdwin.h"
 
-#include "PROTO.h"
-#include "object.h"
-#include "intobject.h"
-#include "stringobject.h"
-#include "tupleobject.h"
-#include "dictobject.h"
-#include "methodobject.h"
-#include "moduleobject.h"
-#include "objimpl.h"
-#include "import.h"
-#include "modsupport.h"
-#include "errors.h"
-
-
 /* Window and menu object types declared here because of forward references */
 
 typedef struct {

File Modules/timemodule.c

 /* Time module */
 
-#include <stdio.h>
+#include "allobjects.h"
+
+#include "modsupport.h"
+
+#include "sigtype.h"
+
 #include <signal.h>
 #include <setjmp.h>
 
 extern time_t time();
 #endif /* !__STDC__ */
 
-#include "PROTO.h"
-#include "object.h"
-#include "intobject.h"
-#include "dictobject.h"
-#include "methodobject.h"
-#include "moduleobject.h"
-#include "objimpl.h"
-#include "import.h"
-#include "sigtype.h"
-#include "modsupport.h"
-#include "errors.h"
-
 
 /* Time methods */
 

File Objects/classobject.c

 /* Class object implementation */
 
-#include <stdio.h>
+#include "allobjects.h"
 
-#include "PROTO.h"
-#include "node.h"
-#include "object.h"
-#include "stringobject.h"
-#include "tupleobject.h"
-#include "dictobject.h"
-#include "funcobject.h"
-#include "classobject.h"
-#include "objimpl.h"
-#include "errors.h"
+#include "structmember.h"
 
 typedef struct {
 	OB_HEAD
-	node	*cl_tree;	/* The entire classdef parse tree */
 	object	*cl_bases;	/* A tuple */
 	object	*cl_methods;	/* A dictionary */
 } classobject;
 
 object *
-newclassobject(tree, bases, methods)
-	node *tree;
+newclassobject(bases, methods)
 	object *bases; /* NULL or tuple of classobjects! */
 	object *methods;
 {
 	op = NEWOBJ(classobject, &Classtype);
 	if (op == NULL)
 		return NULL;
-	op->cl_tree = tree;
 	if (bases != NULL)
 		INCREF(bases);
 	op->cl_bases = bases;
 			v = class_getattr(gettupleitem(op->cl_bases, i), name);
 			if (v != NULL)
 				return v;
+			err_clear();
 		}
 	}
 	err_setstr(NameError, name);
 
 /* Class method methods */
 
+#define OFF(x) offsetof(classmethodobject, x)
+
+static struct memberlist classmethod_memberlist[] = {
+	{"cm_func",	T_OBJECT,	OFF(cm_func)},
+	{"cm_self",	T_OBJECT,	OFF(cm_self)},
+	{NULL}	/* Sentinel */
+};
+
+static object *
+classmethod_getattr(cm, name)
+	register classmethodobject *cm;
+	char *name;
+{
+	return getmember((char *)cm, classmethod_memberlist, name);
+}
+
 static void
 classmethod_dealloc(cm)
 	register classmethodobject *cm;
 	0,
 	classmethod_dealloc,	/*tp_dealloc*/
 	0,			/*tp_print*/
-	0,			/*tp_getattr*/
+	classmethod_getattr,	/*tp_getattr*/
 	0,			/*tp_setattr*/
 	0,			/*tp_compare*/
 	0,			/*tp_repr*/

File Objects/fileobject.c

 
 /* XXX This should become a built-in module 'io'.  It should support more
    functionality, better exception handling for invalid calls, etc.
+   (Especially reading on a write-only file or vice versa!)
    It should also cooperate with posix to support popen(), which should
    share most code but have a special close function. */
 
-#include <stdio.h>
+#include "allobjects.h"
 
-#include "PROTO.h"
-#include "object.h"
-#include "stringobject.h"
-#include "intobject.h"
-#include "fileobject.h"
-#include "methodobject.h"
-#include "objimpl.h"
-#include "errors.h"
+#include "errno.h"
+#ifndef errno
+extern int errno;
+#endif
 
 typedef struct {
 	OB_HEAD
 	object *f;
 {
 	if (!is_fileobject(f)) {
-		errno = EBADF;
+		err_badcall();
 		return NULL;
 	}
 	return ((fileobject *)f)->f_fp;
 	f->f_mode = newstringobject(mode);
 	if (f->f_name == NULL || f->f_mode == NULL) {
 		DECREF(f);
-		errno = ENOMEM;
 		return NULL;
 	}
 	f->f_fp = fp;
 		return NULL;
 	if ((f->f_fp = fopen(name, mode)) == NULL) {
 		DECREF(f);
+		err_errno(RuntimeError); /* XXX Should use another error */
 		return NULL;
 	}
 	return (object *)f;
 /* Methods */
 
 static void
-filedealloc(f)
+file_dealloc(f)
 	fileobject *f;
 {
 	if (f->f_fp != NULL)
 }
 
 static void
-fileprint(f, fp, flags)
+file_print(f, fp, flags)
 	fileobject *f;
 	FILE *fp;
 	int flags;
 }
 
 static object *
-filerepr(f)
+file_repr(f)
 	fileobject *f;
 {
 	char buf[300];
-	/* XXX This differs from fileprint if the filename contains
+	/* XXX This differs from file_print if the filename contains
 	   quotes or other funny characters. */
 	sprintf(buf, "<%s file '%.256s', mode '%.10s'>",
 		f->f_fp == NULL ? "closed" : "open",
 }
 
 static object *
-fileclose(f, args)
+file_close(f, args)
 	fileobject *f;
 	object *args;
 {
 	if (args != NULL) {
-		errno = EINVAL;
+		err_badarg();
 		return NULL;
 	}
 	if (f->f_fp != NULL) {
 }
 
 static object *
-fileread(f, args)
+file_read(f, args)
 	fileobject *f;
 	object *args;
 {
 	int n;
 	object *v;
 	if (f->f_fp == NULL) {
-		errno = EBADF;
+		err_badarg();
 		return NULL;
 	}
 	if (args == NULL || !is_intobject(args)) {
-		errno = EINVAL;
+		err_badarg();
 		return NULL;
 	}
 	n = getintvalue(args);
 	if (n < 0) {
-		errno = EDOM;
+		err_badarg();
 		return NULL;
 	}
 	v = newsizedstringobject((char *)NULL, n);
-	if (v == NULL) {
-		errno = ENOMEM;
+	if (v == NULL)
 		return NULL;
-	}
 	n = fread(getstringvalue(v), 1, n, f->f_fp);
 	/* EOF is reported as an empty string */
 	/* XXX should detect real I/O errors? */
 /* XXX Should this be unified with raw_input()? */
 
 static object *
-filereadline(f, args)
+file_readline(f, args)
 	fileobject *f;
 	object *args;
 {
 	int n;
 	object *v;
 	if (f->f_fp == NULL) {
-		errno = EBADF;
+		err_badarg();
 		return NULL;
 	}
 	if (args == NULL) {
 	}
 	else if (is_intobject(args)) {
 		n = getintvalue(args);
-		if (n < 0 || n > 0x7fff /*XXX*/ ) {
-			errno = EDOM;
+		if (n < 0) {
+			err_badarg();
 			return NULL;
 		}
 	}
 	else {
-		errno = EINVAL;
+		err_badarg();
 		return NULL;
 	}
 	v = newsizedstringobject((char *)NULL, n);
-	if (v == NULL) {
-		errno = ENOMEM;
+	if (v == NULL)
 		return NULL;
-	}
-	if (fgets(getstringvalue(v), n+1, f->f_fp) == NULL) {
+#ifndef THINK_C
+	/* XXX Think C reads n characters, others read n-1 characters... */
+	n = n+1;
+#endif
+	if (fgets(getstringvalue(v), n, f->f_fp) == NULL) {
 		/* EOF is reported as an empty string */
 		/* XXX should detect real I/O errors? */
 		n = 0;
 }
 
 static object *
-filewrite(f, args)
+file_write(f, args)
 	fileobject *f;
 	object *args;
 {
 	int n, n2;
 	if (f->f_fp == NULL) {
-		errno = EBADF;
+		err_badarg();
 		return NULL;
 	}
 	if (args == NULL || !is_stringobject(args)) {
-		errno = EINVAL;
+		err_badarg();
 		return NULL;
 	}
 	errno = 0;
 	if (n2 != n) {
 		if (errno == 0)
 			errno = EIO;
+		err_errno(RuntimeError);
 		return NULL;
 	}
 	INCREF(None);
 	return None;
 }
 
-static struct methodlist {
-	char *ml_name;
-	method ml_meth;
-} filemethods[] = {
-	{"write",	filewrite},
-	{"read",	fileread},
-	{"readline",	filereadline},
-	{"close",	fileclose},
+static struct methodlist file_methods[] = {
+	{"write",	file_write},
+	{"read",	file_read},
+	{"readline",	file_readline},
+	{"close",	file_close},
 	{NULL,		NULL}		/* sentinel */
 };
 
 static object *
-filegetattr(f, name)
+file_getattr(f, name)
 	fileobject *f;
 	char *name;
 {
-	struct methodlist *ml = filemethods;
-	for (; ml->ml_name != NULL; ml++) {
-		if (strcmp(name, ml->ml_name) == 0)
-			return newmethodobject(ml->ml_name, ml->ml_meth,
-				(object *)f);
-	}
-	err_setstr(NameError, name);
-	return NULL;
+	return findmethod(file_methods, (object *)f, name);
 }
 
 typeobject Filetype = {
 	"file",
 	sizeof(fileobject),
 	0,
-	filedealloc,	/*tp_dealloc*/
-	fileprint,	/*tp_print*/
-	filegetattr,	/*tp_getattr*/
+	file_dealloc,	/*tp_dealloc*/
+	file_print,	/*tp_print*/
+	file_getattr,	/*tp_getattr*/
 	0,		/*tp_setattr*/
 	0,		/*tp_compare*/
-	filerepr,	/*tp_repr*/
+	file_repr,	/*tp_repr*/
 };

File Objects/floatobject.c

 /* XXX There should be overflow checks here, but it's hard to check
    for any kind of float exception without losing portability. */
 
-#include <stdio.h>
+#include "allobjects.h"
+
+#include <ctype.h>
 #include <math.h>
-#include <ctype.h>
-
-#include "PROTO.h"
-#include "object.h"
-#include "floatobject.h"
-#include "stringobject.h"
-#include "objimpl.h"
-#include "errors.h"
 
 #ifndef THINK_C
 extern double fmod PROTO((double, double));

File Objects/frameobject.c

+/* Frame object implementation */
+
+#include "allobjects.h"
+
+#include "compile.h"
+#include "frameobject.h"
+#include "opcode.h"
+#include "structmember.h"
+
+#define OFF(x) offsetof(frameobject, x)
+
+static struct memberlist frame_memberlist[] = {
+	{"f_back",	T_OBJECT,	OFF(f_back)},
+	{"f_code",	T_OBJECT,	OFF(f_code)},
+	{"f_globals",	T_OBJECT,	OFF(f_globals)},
+	{"f_locals",	T_OBJECT,	OFF(f_locals)},
+	{NULL}	/* Sentinel */
+};
+
+static object *
+frame_getattr(f, name)
+	frameobject *f;
+	char *name;
+{
+	return getmember((char *)f, frame_memberlist, name);
+}
+
+static void
+frame_dealloc(f)
+	frameobject *f;
+{
+	XDECREF(f->f_back);
+	XDECREF(f->f_code);
+	XDECREF(f->f_globals);
+	XDECREF(f->f_locals);
+	XDEL(f->f_valuestack);
+	XDEL(f->f_blockstack);
+	DEL(f);
+}
+
+typeobject Frametype = {
+	OB_HEAD_INIT(&Typetype)
+	0,
+	"frame",
+	sizeof(frameobject),
+	0,
+	frame_dealloc,	/*tp_dealloc*/
+	0,		/*tp_print*/
+	frame_getattr,	/*tp_getattr*/
+	0,		/*tp_setattr*/
+	0,		/*tp_compare*/
+	0,		/*tp_repr*/
+	0,		/*tp_as_number*/
+	0,		/*tp_as_sequence*/
+	0,		/*tp_as_mapping*/
+};
+
+frameobject *
+newframeobject(back, code, globals, locals, nvalues, nblocks)
+	frameobject *back;
+	codeobject *code;
+	object *globals;
+	object *locals;
+	int nvalues;
+	int nblocks;
+{
+	frameobject *f;
+	if ((back != NULL && !is_frameobject(back)) ||
+		code == NULL || !is_codeobject(code) ||
+		globals == NULL || !is_dictobject(globals) ||
+		locals == NULL || !is_dictobject(locals) ||
+		nvalues < 0 || nblocks < 0) {
+		err_badcall();
+		return NULL;
+	}
+	f = NEWOBJ(frameobject, &Frametype);
+	if (f != NULL) {
+		if (back)
+			INCREF(back);
+		f->f_back = back;
+		INCREF(code);
+		f->f_code = code;
+		INCREF(globals);
+		f->f_globals = globals;
+		INCREF(locals);
+		f->f_locals = locals;
+		f->f_valuestack = NEW(object *, nvalues+1);
+		f->f_blockstack = NEW(block, nblocks+1);
+		f->f_nvalues = nvalues;
+		f->f_nblocks = nblocks;
+		f->f_iblock = 0;
+		if (f->f_valuestack == NULL || f->f_blockstack == NULL) {
+			err_nomem();
+			DECREF(f);
+			f = NULL;
+		}
+	}
+	return f;
+}
+
+/* Block management */
+
+void
+setup_block(f, type, handler, level)
+	frameobject *f;
+	int type;
+	int handler;
+	int level;
+{
+	block *b;
+	if (f->f_iblock >= f->f_nblocks) {
+		fprintf(stderr, "XXX block stack overflow\n");
+		abort();
+	}
+	b = &f->f_blockstack[f->f_iblock++];
+	b->b_type = type;
+	b->b_level = level;
+	b->b_handler = handler;
+}
+
+block *
+pop_block(f)
+	frameobject *f;
+{
+	block *b;
+	if (f->f_iblock <= 0) {
+		fprintf(stderr, "XXX block stack underflow\n");
+		abort();
+	}
+	b = &f->f_blockstack[--f->f_iblock];
+	return b;
+}

File Objects/funcobject.c

 /* Function object implementation */
 
-#include <stdio.h>
+#include "allobjects.h"
 
-#include "PROTO.h"
-#include "object.h"
-#include "funcobject.h"
-#include "objimpl.h"
+#include "structmember.h"
 
 typedef struct {
 	OB_HEAD
 
 /* Methods */
 
+#define OFF(x) offsetof(funcobject, x)
+
+static struct memberlist func_memberlist[] = {
+	{"func_code",	T_OBJECT,	OFF(func_code)},
+	{"func_globals",T_OBJECT,	OFF(func_globals)},
+	{NULL}	/* Sentinel */
+};
+
+static object *
+func_getattr(op, name)
+	funcobject *op;
+	char *name;
+{
+	return getmember((char *)op, func_memberlist, name);
+}
+
 static void
-funcdealloc(op)
+func_dealloc(op)
 	funcobject *op;
 {
 	DECREF(op->func_code);
 	"function",
 	sizeof(funcobject),
 	0,
-	funcdealloc,	/*tp_dealloc*/
+	func_dealloc,	/*tp_dealloc*/
 	0,		/*tp_print*/
-	0,		/*tp_getattr*/
+	func_getattr,	/*tp_getattr*/
 	0,		/*tp_setattr*/
 	0,		/*tp_compare*/
 	0,		/*tp_repr*/

File Objects/intobject.c

 /* Integer object implementation */
 
-#include <stdio.h>
-
-#include "PROTO.h"
-#include "object.h"
-#include "intobject.h"
-#include "stringobject.h"
-#include "objimpl.h"
-#include "errors.h"
+#include "allobjects.h"
 
 /* Standard Booleans */
+
 intobject FalseObject = {
 	OB_HEAD_INIT(&Inttype)
 	0
 };
+
 intobject TrueObject = {
 	OB_HEAD_INIT(&Inttype)
 	1
 	return NULL;
 }
 
+/* Integers are quite normal objects, to make object handling uniform.
+   (Using odd pointers to represent integers would save much space
+   but require extra checks for this special case throughout the code.)
+   Since, a typical Python program spends much of its time allocating
+   and deallocating integers, these operations should be very fast.
+   Therefore we use a dedicated allocation scheme with a much lower
+   overhead (in space and time) than straight malloc(): a simple
+   dedicated free list, filled when necessary with memory from malloc().
+*/
+
+#define BLOCK_SIZE	1000	/* 1K less typical malloc overhead */
+#define N_INTOBJECTS	(BLOCK_SIZE / sizeof(intobject))
+
+static intobject *
+fill_free_list()
+{
+	intobject *p, *q;
+	p = NEW(intobject, N_INTOBJECTS);
+	if (p == NULL)
+		return (intobject *)err_nomem();
+	q = p + N_INTOBJECTS;
+	while (--q > p)
+		*(intobject **)q = q-1;
+	*(intobject **)q = NULL;
+	return p + N_INTOBJECTS - 1;
+}
+
+static intobject *free_list = NULL;
+
 object *
 newintobject(ival)
 	long ival;
 {
-	/* For efficiency, this code is copied from newobject() */
-	register intobject *op = (intobject *) malloc(sizeof(intobject));
-	if (op == NULL) {
-		err_nomem();
+	register intobject *v;
+	if (free_list == NULL) {
+		if ((free_list = fill_free_list()) == NULL)
+			return NULL;
 	}
-	else {
-		NEWREF(op);
-		op->ob_type = &Inttype;
-		op->ob_ival = ival;
-	}
-	return (object *) op;
+	v = free_list;
+	free_list = *(intobject **)free_list;
+	NEWREF(v);
+	v->ob_type = &Inttype;
+	v->ob_ival = ival;
+	return (object *) v;
+}
+
+static void
+int_dealloc(v)
+	intobject *v;
+{
+	*(intobject **)v = free_list;
+	free_list = v;
 }
 
 long
 /* Methods */
 
 static void
-intprint(v, fp, flags)
+int_print(v, fp, flags)
 	intobject *v;
 	FILE *fp;
 	int flags;
 }
 
 static object *
-intrepr(v)
+int_repr(v)
 	intobject *v;
 {
 	char buf[20];
 }
 
 static int
-intcompare(v, w)
+int_compare(v, w)
 	intobject *v, *w;
 {
 	register long i = v->ob_ival;
 }
 
 static object *
-intadd(v, w)
+int_add(v, w)
 	intobject *v;
 	register object *w;
 {
 }
 
 static object *
-intsub(v, w)
+int_sub(v, w)
 	intobject *v;
 	register object *w;
 {
 }
 
 static object *
-intmul(v, w)
+int_mul(v, w)
 	intobject *v;
 	register object *w;
 {
 }
 
 static object *
-intdiv(v, w)
+int_div(v, w)
 	intobject *v;
 	register object *w;
 {
 }
 
 static object *
-intrem(v, w)
+int_rem(v, w)
 	intobject *v;
 	register object *w;
 {
 }
 
 static object *
-intpow(v, w)
+int_pow(v, w)
 	intobject *v;
 	register object *w;
 {
 }
 
 static object *
-intneg(v)
+int_neg(v)
 	intobject *v;
 {
 	register long a, x;
 }
 
 static object *
-intpos(v)
+int_pos(v)
 	intobject *v;
 {
 	INCREF(v);
 }
 
 static number_methods int_as_number = {
-	intadd,	/*tp_add*/
-	intsub,	/*tp_subtract*/
-	intmul,	/*tp_multiply*/
-	intdiv,	/*tp_divide*/
-	intrem,	/*tp_remainder*/
-	intpow,	/*tp_power*/
-	intneg,	/*tp_negate*/
-	intpos,	/*tp_plus*/
+	int_add,	/*tp_add*/
+	int_sub,	/*tp_subtract*/
+	int_mul,	/*tp_multiply*/
+	int_div,	/*tp_divide*/
+	int_rem,	/*tp_remainder*/
+	int_pow,	/*tp_power*/
+	int_neg,	/*tp_negate*/
+	int_pos,	/*tp_plus*/
 };
 
 typeobject Inttype = {
 	"int",
 	sizeof(intobject),
 	0,
-	free,		/*tp_dealloc*/
-	intprint,	/*tp_print*/
+	int_dealloc,	/*tp_dealloc*/
+	int_print,	/*tp_print*/
 	0,		/*tp_getattr*/
 	0,		/*tp_setattr*/
-	intcompare,	/*tp_compare*/
-	intrepr,	/*tp_repr*/
+	int_compare,	/*tp_compare*/
+	int_repr,	/*tp_repr*/
 	&int_as_number,	/*tp_as_number*/
 	0,		/*tp_as_sequence*/
 	0,		/*tp_as_mapping*/

File Objects/listobject.c

 /* List object implementation */
 
-#include <stdio.h>
-
-#include "PROTO.h"
-#include "object.h"
-#include "intobject.h"
-#include "stringobject.h"
-#include "tupleobject.h"
-#include "methodobject.h"
-#include "listobject.h"
-#include "objimpl.h"
-#include "modsupport.h"
-#include "errors.h"
-
-typedef struct {
-	OB_VARHEAD
-	object **ob_item;
-} listobject;
+#include "allobjects.h"
 
 object *
 newlistobject(size)

File Objects/methodobject.c

 /* Method object implementation */
 
-#include <stdio.h>
+#include "allobjects.h"
 
-#include "PROTO.h"
-#include "object.h"
-#include "node.h"
-#include "stringobject.h"
-#include "methodobject.h"
-#include "objimpl.h"
 #include "token.h"
-#include "errors.h"
 
 typedef struct {
 	OB_HEAD
 	int flags;
 {
 	if (m->m_self == NULL)
-		fprintf(fp, "<%s method>", m->m_name);
+		fprintf(fp, "<built-in function '%s'>", m->m_name);
 	else
-		fprintf(fp, "<%s method of %s object at %lx>",
-			m->m_name, m->m_self->ob_type->tp_name,
-			(long)m->m_self);
+		fprintf(fp, "<built-in method '%s' of some %s object>",
+			m->m_name, m->m_self->ob_type->tp_name);
 }
 
 static object *
 {
 	char buf[200];
 	if (m->m_self == NULL)
-		sprintf(buf, "<%.80s method>", m->m_name);
+		sprintf(buf, "<built-in function '%.80s'>", m->m_name);
 	else
-		sprintf(buf, "<%.80s method of %.80s object at %lx>",
-			m->m_name, m->m_self->ob_type->tp_name,
-			(long)m->m_self);
+		sprintf(buf,
+			"<built-in method '%.80s' of some %.80s object>",
+			m->m_name, m->m_self->ob_type->tp_name);
 	return newstringobject(buf);
 }
 
 	0,		/*tp_as_sequence*/
 	0,		/*tp_as_mapping*/
 };
+
+/* Find a method in a module's method table.
+   Usually called from an object's getattr method. */
+
+object *
+findmethod(ml, op, name)
+	struct methodlist *ml;
+	object *op;
+	char *name;
+{
+	for (; ml->ml_name != NULL; ml++) {
+		if (strcmp(name, ml->ml_name) == 0)
+			return newmethodobject(ml->ml_name, ml->ml_meth, op);
+	}
+	err_setstr(NameError, name);
+	return NULL;
+}

File Objects/moduleobject.c

 /* Module object implementation */
 
-#include <stdio.h>
-
-#include "PROTO.h"
-#include "object.h"
-#include "stringobject.h"
-#include "dictobject.h"
-#include "moduleobject.h"
-#include "objimpl.h"
-#include "errors.h"
+#include "allobjects.h"
 
 typedef struct {
 	OB_HEAD
 	object *m;
 {
 	if (!is_moduleobject(m)) {
-		err_badarg();
+		err_badcall();
 		return NULL;
 	}
 	return ((moduleobject *)m) -> md_dict;
 }
 
-int
-setmoduledict(m, v)
-	object *m;
-	object *v;
-{
-	if (!is_moduleobject(m)) {
-		err_badarg();
-		return -1;
-	}
-	if (!is_dictobject(v)) {
-		err_badarg();
-		return -1;
-	}
-	DECREF(((moduleobject *)m) -> md_dict);
-	INCREF(v);
-	((moduleobject *)m) -> md_dict = v;
-	return 0;
-}
-
 char *
 getmodulename(m)
 	object *m;
 /* Methods */
 
 static void
-moduledealloc(m)
+module_dealloc(m)
 	moduleobject *m;
 {
 	if (m->md_name != NULL)
 }
 
 static void
-moduleprint(m, fp, flags)
+module_print(m, fp, flags)
 	moduleobject *m;
 	FILE *fp;
 	int flags;
 {
-	fprintf(fp, "<module %s>", getstringvalue(m->md_name));
+	fprintf(fp, "<module '%s'>", getstringvalue(m->md_name));
 }
 
 static object *
-modulerepr(m)
+module_repr(m)
 	moduleobject *m;
 {
 	char buf[100];
-	sprintf(buf, "<module %.80s>", getstringvalue(m->md_name));
+	sprintf(buf, "<module '%.80s'>", getstringvalue(m->md_name));
 	return newstringobject(buf);
 }
 
 static object *
-modulegetattr(m, name)
+module_getattr(m, name)
 	moduleobject *m;
 	char *name;
 {
 	object *res;
-	if (strcmp(name, "__dict") == 0) {
+	if (strcmp(name, "__dict__") == 0) {
 		INCREF(m->md_dict);
 		return m->md_dict;
 	}
+	if (strcmp(name, "__name__") == 0) {
+		INCREF(m->md_name);
+		return m->md_name;
+	}
 	res = dictlookup(m->md_dict, name);
 	if (res == NULL)
 		err_setstr(NameError, name);
 }
 
 static int
-modulesetattr(m, name, v)
+module_setattr(m, name, v)
 	moduleobject *m;
 	char *name;
 	object *v;
 {
-	if (strcmp(name, "__dict") == 0) {
-		/* Can't allow assignment to __dict, it would screw up
-		   module's functions which still use the old dictionary. */
-		err_setstr(NameError, "__dict is a reserved member name");
+	if (strcmp(name, "__dict__") == 0 || strcmp(name, "__name__") == 0) {
+		err_setstr(NameError, "can't assign to reserved member name");
 		return NULL;
 	}
 	if (v == NULL)
 	"module",		/*tp_name*/
 	sizeof(moduleobject),	/*tp_size*/
 	0,			/*tp_itemsize*/
-	moduledealloc,	/*tp_dealloc*/
-	moduleprint,	/*tp_print*/
-	modulegetattr,	/*tp_getattr*/
-	modulesetattr,	/*tp_setattr*/
-	0,		/*tp_compare*/
-	modulerepr,	/*tp_repr*/
+	module_dealloc,		/*tp_dealloc*/
+	module_print,		/*tp_print*/
+	module_getattr,		/*tp_getattr*/
+	module_setattr,		/*tp_setattr*/
+	0,			/*tp_compare*/
+	module_repr,		/*tp_repr*/
 };

File Objects/object.c

-/* Object implementation; and 'noobject' implementation */
+/* Generic object operations; and implementation of None (NoObject) */
 
-#include <stdio.h>
+#include "allobjects.h"
 
-#include "PROTO.h"
-#include "object.h"
-#include "stringobject.h"
-#include "objimpl.h"
-#include "errors.h"
+#ifdef REF_DEBUG
+long ref_total;
+#endif
 
-int StopPrint; /* Flag to indicate printing must be stopped */
-
-/* Object allocation routines used by NEWOBJ and NEWVAROBJ macros */
+/* Object allocation routines used by NEWOBJ and NEWVAROBJ macros.
+   These are used by the individual routines for object creation.
+   Do not call them otherwise, they do not initialize the object! */
 
 object *
 newobject(tp)
 
 #endif
 
+int StopPrint; /* Flag to indicate printing must be stopped */
+
 static int prlevel;
 
 void
 	int flags;
 {
 	/* Hacks to make printing a long or recursive object interruptible */
+	/* XXX Interrupts should leave a more permanent error */
 	prlevel++;
 	if (!StopPrint && intrcheck()) {
 		fprintf(fp, "\n[print interrupted]\n");
 		if (op == NULL) {
 			fprintf(fp, "<nil>");
 		}
-		else if (op->ob_type->tp_print == NULL) {
-			fprintf(fp, "<%s object at %lx>",
-				op->ob_type->tp_name, (long)op);
-		}
 		else {
-			(*op->ob_type->tp_print)(op, fp, flags);
+			if (op->ob_refcnt <= 0)
+				fprintf(fp, "(refcnt %d):", op->ob_refcnt);
+			if (op->ob_type->tp_print == NULL) {
+				fprintf(fp, "<%s object at %lx>",
+					op->ob_type->tp_name, (long)op);
+			}
+			else {
+				(*op->ob_type->tp_print)(op, fp, flags);
+			}
 		}
 	}
 	prlevel--;
 reprobject(v)
 	object *v;
 {
-	object *w;
+	object *w = NULL;
 	/* Hacks to make converting a long or recursive object interruptible */
 	prlevel++;
 	if (!StopPrint && intrcheck()) {
 		StopPrint = 1;
-		w = NULL;
 		err_set(KeyboardInterrupt);
 	}
 	if (!StopPrint) {
 		if (v == NULL) {
-			w = newstringobject("<nil>");
+			w = newstringobject("<NULL>");
 		}
 		else if (v->ob_type->tp_repr == NULL) {
 			char buf[100];
 		else {
 			w = (*v->ob_type->tp_repr)(v);
 		}
+		if (StopPrint) {
+			XDECREF(w);
+			w = NULL;
+		}
 	}
 	prlevel--;
 	if (prlevel == 0)
 	return ((*tp->tp_compare)(v, w));
 }
 
+object *
+getattr(v, name)
+	object *v;
+	char *name;
+{
+	if (v->ob_type->tp_getattr == NULL) {
+		err_setstr(TypeError, "attribute-less object");
+		return NULL;
+	}
+	else {
+		return (*v->ob_type->tp_getattr)(v, name);
+	}
+}
+
+int
+setattr(v, name, w)
+	object *v;
+	char *name;
+	object *w;
+{
+	if (v->ob_type->tp_setattr == NULL) {
+		if (v->ob_type->tp_getattr == NULL)
+			err_setstr(TypeError, "attribute-less object");
+		else
+			err_setstr(TypeError, "object has read-only attributes");
+		return NULL;
+	}
+	else {
+		return (*v->ob_type->tp_setattr)(v, name, w);
+	}
+}
+
 
 /*
 NoObject is usable as a non-NULL undefined value, used by the macro None.
 There is (and should be!) no way to create other objects of this type,
-so there is exactly one.
+so there is exactly one (which is indestructible, by the way).
 */
 
 static void
-noprint(op, fp, flags)
+none_print(op, fp, flags)
 	object *op;
 	FILE *fp;
 	int flags;
 {
-	fprintf(fp, "<no value>");
+	fprintf(fp, "None");
+}
+
+static object *
+none_repr(op)
+	object *op;
+{
+	return newstringobject("None");
 }
 
 static typeobject Notype = {
 	OB_HEAD_INIT(&Typetype)
 	0,
-	"novalue",
+	"None",
 	0,
 	0,
 	0,		/*tp_dealloc*/ /*never called*/
-	noprint,	/*tp_print*/
+	none_print,	/*tp_print*/
+	0,		/*tp_getattr*/
+	0,		/*tp_setattr*/
+	0,		/*tp_compare*/
+	none_repr,	/*tp_repr*/
+	0,		/*tp_as_number*/
+	0,		/*tp_as_sequence*/
+	0,		/*tp_as_mapping*/
 };
 
 object NoObject = {
 	refchain._ob_next = op;
 }
 
-DELREF(op)
-	object *op;
+UNREF(op)
+	register object *op;
 {
+	register object *p;
 	if (op->ob_refcnt < 0) {
-		fprintf(stderr, "negative refcnt\n");
+		fprintf(stderr, "UNREF negative refcnt\n");
+		abort();
+	}
+	for (p = refchain._ob_next; p != &refchain; p = p->_ob_next) {
+		if (p == op)
+			break;
+	}
+	if (p == &refchain) { /* Not found */
+		fprintf(stderr, "UNREF unknown object\n");
 		abort();
 	}
 	op->_ob_next->_ob_prev = op->_ob_prev;
 	op->_ob_prev->_ob_next = op->_ob_next;
+}
+
+DELREF(op)
+	object *op;
+{
+	UNREF(op);
 	(*(op)->ob_type->tp_dealloc)(op);
 }
 

File Objects/stringobject.c

 /* String object implementation */
 
-#include <stdio.h>
-
-#include "PROTO.h"
-#include "object.h"
-#include "stringobject.h"
-#include "intobject.h"
-#include "objimpl.h"
-#include "errors.h"
+#include "allobjects.h"
 
 object *
 newsizedstringobject(str, size)

File Objects/tupleobject.c

 /* Tuple object implementation */
 
-#include <stdio.h>
-
-#include "PROTO.h"
-#include "object.h"
-#include "stringobject.h"
-#include "tupleobject.h"
-#include "intobject.h"
-#include "objimpl.h"
-#include "errors.h"
-
-typedef struct {
-	OB_VARHEAD
-	object *ob_item[1];
-} tupleobject;
+#include "allobjects.h"
 
 object *
 newtupleobject(size)

File Objects/typeobject.c

 /* Type object implementation */
 
-#include <stdio.h>
-
-#include "PROTO.h"
-#include "object.h"
-#include "stringobject.h"
-#include "objimpl.h"
+#include "allobjects.h"
 
 /* Type object implementation */
 
 static void
-typeprint(v, fp, flags)
+type_print(v, fp, flags)
 	typeobject *v;
 	FILE *fp;
 	int flags;
 }
 
 static object *
-typerepr(v)
+type_repr(v)
 	typeobject *v;
 {