"Compiling" version
diff --git a/Include/allobjects.h b/Include/allobjects.h
new file mode 100644
index 0000000..ed37609
--- /dev/null
+++ b/Include/allobjects.h
@@ -0,0 +1,26 @@
+/* "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 *));
diff --git a/Include/bltinmodule.h b/Include/bltinmodule.h
new file mode 100644
index 0000000..1f7f67b
--- /dev/null
+++ b/Include/bltinmodule.h
@@ -0,0 +1,3 @@
+/* Built-in module interface */
+
+extern object *getbuiltin PROTO((char *));
diff --git a/Include/ceval.h b/Include/ceval.h
new file mode 100644
index 0000000..1495bb7
--- /dev/null
+++ b/Include/ceval.h
@@ -0,0 +1,9 @@
+/* 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 *));
diff --git a/Include/classobject.h b/Include/classobject.h
index 0514634..4b947b5 100644
--- a/Include/classobject.h
+++ b/Include/classobject.h
@@ -12,7 +12,7 @@
 #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 *));
 
diff --git a/Include/compile.h b/Include/compile.h
new file mode 100644
index 0000000..3306930
--- /dev/null
+++ b/Include/compile.h
@@ -0,0 +1,23 @@
+/* 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 *));
diff --git a/Include/errors.h b/Include/errors.h
index f0e3762..21c57d1 100755
--- a/Include/errors.h
+++ b/Include/errors.h
@@ -7,7 +7,7 @@
 void err_get PROTO((object **, object **));
 void err_clear PROTO((void));
 
-/* Predefined exceptions (in run.c) */
+/* Predefined exceptions */
 
 extern object *RuntimeError;
 extern object *EOFError;
@@ -29,5 +29,6 @@
 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));
diff --git a/Include/frameobject.h b/Include/frameobject.h
new file mode 100644
index 0000000..92d18d7
--- /dev/null
+++ b/Include/frameobject.h
@@ -0,0 +1,56 @@
+/* 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 *));
diff --git a/Include/grammar.h b/Include/grammar.h
index 423d862..07ce2b9 100644
--- a/Include/grammar.h
+++ b/Include/grammar.h
@@ -76,3 +76,6 @@
 void addfirstsets PROTO((grammar *g));
 
 void addaccellerators PROTO((grammar *g));
+
+void printgrammar PROTO((grammar *g, FILE *fp));
+void printnonterminals PROTO((grammar *g, FILE *fp));
diff --git a/Include/import.h b/Include/import.h
index cdeb3d1..4cdb6eb 100644
--- a/Include/import.h
+++ b/Include/import.h
@@ -1,5 +1,7 @@
 /* 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));
diff --git a/Include/listobject.h b/Include/listobject.h
index 5ff057e..4a2bd72 100644
--- a/Include/listobject.h
+++ b/Include/listobject.h
@@ -14,6 +14,11 @@
 returned item's reference count.
 */
 
+typedef struct {
+	OB_VARHEAD
+	object **ob_item;
+} listobject;
+
 extern typeobject Listtype;
 
 #define is_listobject(op) ((op)->ob_type == &Listtype)
@@ -25,3 +30,6 @@
 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])
diff --git a/Include/methodobject.h b/Include/methodobject.h
index b11ccd7..9dd05b4 100644
--- a/Include/methodobject.h
+++ b/Include/methodobject.h
@@ -9,3 +9,10 @@
 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 *));
diff --git a/Include/modsupport.h b/Include/modsupport.h
index d406bf6..db63eb5 100644
--- a/Include/modsupport.h
+++ b/Include/modsupport.h
@@ -1,9 +1,3 @@
 /* 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 *));
diff --git a/Include/moduleobject.h b/Include/moduleobject.h
index 99d3d52..c9ce6ad 100644
--- a/Include/moduleobject.h
+++ b/Include/moduleobject.h
@@ -6,5 +6,4 @@
 
 extern object *newmoduleobject PROTO((char *));
 extern object *getmoduledict PROTO((object *));
-extern int setmoduledict PROTO((object *, object *));
 extern char *getmodulename PROTO((object *));
diff --git a/Include/node.h b/Include/node.h
index 9730e57..ff2ca7c 100644
--- a/Include/node.h
+++ b/Include/node.h
@@ -3,13 +3,14 @@
 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)
@@ -28,3 +29,6 @@
 		abort(); \
 	} }
 #endif
+
+extern void listtree PROTO((node *));
+extern void listnode PROTO((FILE *, node *));
diff --git a/Include/object.h b/Include/object.h
index dcfdfb4..c0deb7d 100644
--- a/Include/object.h
+++ b/Include/object.h
@@ -1,3 +1,4 @@
+#define NDEBUG
 /* Object and type object interface */
 
 /*
@@ -47,11 +48,15 @@
 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 \
@@ -147,9 +152,12 @@
 
 #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. */
@@ -215,6 +223,10 @@
 		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> */
 
@@ -252,22 +264,12 @@
 -------------
 
 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
 ----------------
@@ -296,16 +298,3 @@
 
 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
diff --git a/Include/objimpl.h b/Include/objimpl.h
index e6f9929..4ed2975 100644
--- a/Include/objimpl.h
+++ b/Include/objimpl.h
@@ -24,8 +24,3 @@
 #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 *));
diff --git a/Include/opcode.h b/Include/opcode.h
index a4fe6b2..b0dc71d 100644
--- a/Include/opcode.h
+++ b/Include/opcode.h
@@ -1,9 +1,10 @@
 /* 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
@@ -76,5 +77,9 @@
 #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)
diff --git a/Include/parsetok.h b/Include/parsetok.h
index c8142b0..07d9715 100644
--- a/Include/parsetok.h
+++ b/Include/parsetok.h
@@ -1,9 +1,5 @@
 /* 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));
diff --git a/Include/pgenheaders.h b/Include/pgenheaders.h
new file mode 100644
index 0000000..95fdbf2
--- /dev/null
+++ b/Include/pgenheaders.h
@@ -0,0 +1,15 @@
+/* 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 *));
diff --git a/Include/pyerrors.h b/Include/pyerrors.h
index f0e3762..21c57d1 100644
--- a/Include/pyerrors.h
+++ b/Include/pyerrors.h
@@ -7,7 +7,7 @@
 void err_get PROTO((object **, object **));
 void err_clear PROTO((void));
 
-/* Predefined exceptions (in run.c) */
+/* Predefined exceptions */
 
 extern object *RuntimeError;
 extern object *EOFError;
@@ -29,5 +29,6 @@
 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));
diff --git a/Include/pythonrun.h b/Include/pythonrun.h
new file mode 100644
index 0000000..51ff3b7
--- /dev/null
+++ b/Include/pythonrun.h
@@ -0,0 +1,23 @@
+/* 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));
diff --git a/Include/structmember.h b/Include/structmember.h
new file mode 100644
index 0000000..13af70d
--- /dev/null
+++ b/Include/structmember.h
@@ -0,0 +1,40 @@
+/* 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 *));
diff --git a/Include/sysmodule.h b/Include/sysmodule.h
index 8a2644a..7f449cf 100644
--- a/Include/sysmodule.h
+++ b/Include/sysmodule.h
@@ -3,4 +3,4 @@
 object *sysget PROTO((char *));
 int sysset PROTO((char *, object *));
 FILE *sysgetfile PROTO((char *, FILE *));
-void initsys PROTO((int, char **));
+void initsys PROTO((void));
diff --git a/Include/traceback.h b/Include/traceback.h
new file mode 100644
index 0000000..920feff
--- /dev/null
+++ b/Include/traceback.h
@@ -0,0 +1,6 @@
+/* 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 *));
diff --git a/Include/tupleobject.h b/Include/tupleobject.h
index d22e6b9..46a0031 100644
--- a/Include/tupleobject.h
+++ b/Include/tupleobject.h
@@ -14,6 +14,11 @@
 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)
@@ -22,3 +27,6 @@
 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])