[Python-checkins] r42241 - in python/branches/ast-objects: Include/compile.h Include/pythonrun.h Include/symtable.h Parser/asdl_c.py Python/Python-ast.c Python/ast.c Python/compile.c Python/future.c Python/import.c Python/pythonrun.c Python/symtable.c

neal.norwitz python-checkins at python.org
Sun Feb 5 02:54:32 CET 2006


Author: neal.norwitz
Date: Sun Feb  5 02:54:29 2006
New Revision: 42241

Modified:
   python/branches/ast-objects/Include/compile.h
   python/branches/ast-objects/Include/pythonrun.h
   python/branches/ast-objects/Include/symtable.h
   python/branches/ast-objects/Parser/asdl_c.py
   python/branches/ast-objects/Python/Python-ast.c
   python/branches/ast-objects/Python/ast.c
   python/branches/ast-objects/Python/compile.c
   python/branches/ast-objects/Python/future.c
   python/branches/ast-objects/Python/import.c
   python/branches/ast-objects/Python/pythonrun.c
   python/branches/ast-objects/Python/symtable.c
Log:
Changes from Simon Burton to get everything to compile.  I made some formatting
changes and fixed a few warnings.  Here are some of his notes:

(0) still a lot of XDECREF'ing to do (and probably some other refcount woes)
(1) runs simple code OK, site.py OK
(2) using function intrumentation, I've checked the AST control flow
    against the trunk (42025) and it's OK (except it seems that the trunk
    has changed ast_for_try_stmt slightly)
(3) bombs on "import sys" -> python: Python/compile.c:2809: compiler_nameop:
    Assertion `scope || (((PyStringObject *)(name))->ob_sval)[0] == '_'' failed.

Bombs for me in a different place.



Modified: python/branches/ast-objects/Include/compile.h
==============================================================================
--- python/branches/ast-objects/Include/compile.h	(original)
+++ python/branches/ast-objects/Include/compile.h	Sun Feb  5 02:54:29 2006
@@ -23,9 +23,9 @@
 #define FUTURE_GENERATORS "generators"
 #define FUTURE_DIVISION "division"
 
-PyAPI_FUNC(PyCodeObject *) PyAST_Compile(PyTypeObject *, const char *,
+PyAPI_FUNC(PyCodeObject *) PyAST_Compile(PyObject *, const char *,
 					PyCompilerFlags *);
-PyAPI_FUNC(PyFutureFeatures *) PyFuture_FromAST(PyTypeObject *, const char *);
+PyAPI_FUNC(PyFutureFeatures *) PyFuture_FromAST(PyObject *, const char *);
 
 #define ERR_LATE_FUTURE \
 "from __future__ imports must occur at the beginning of the file"

Modified: python/branches/ast-objects/Include/pythonrun.h
==============================================================================
--- python/branches/ast-objects/Include/pythonrun.h	(original)
+++ python/branches/ast-objects/Include/pythonrun.h	Sun Feb  5 02:54:29 2006
@@ -36,9 +36,9 @@
 PyAPI_FUNC(int) PyRun_InteractiveOneFlags(FILE *, const char *, PyCompilerFlags *);
 PyAPI_FUNC(int) PyRun_InteractiveLoopFlags(FILE *, const char *, PyCompilerFlags *);
 
-PyAPI_FUNC(PyTypeObject *) PyParser_ASTFromString(const char *, const char *, 
+PyAPI_FUNC(PyObject *) PyParser_ASTFromString(const char *, const char *, 
 						 int, PyCompilerFlags *flags);
-PyAPI_FUNC(PyTypeObject *) PyParser_ASTFromFile(FILE *, const char *, int, 
+PyAPI_FUNC(PyObject *) PyParser_ASTFromFile(FILE *, const char *, int, 
 					       char *, char *,
                                                PyCompilerFlags *, int *);
 #define PyParser_SimpleParseString(S, B) \

Modified: python/branches/ast-objects/Include/symtable.h
==============================================================================
--- python/branches/ast-objects/Include/symtable.h	(original)
+++ python/branches/ast-objects/Include/symtable.h	Sun Feb  5 02:54:29 2006
@@ -52,7 +52,7 @@
 	PySTEntry_New(struct symtable *, PyObject *name, _Py_block_ty, void *, int);
 PyAPI_FUNC(int) PyST_GetScope(PySTEntryObject *, PyObject *);
 
-PyAPI_FUNC(struct symtable *) PySymtable_Build(PyTypeObject *, const char *, 
+PyAPI_FUNC(struct symtable *) PySymtable_Build(PyObject *, const char *, 
 					      PyFutureFeatures *);
 PyAPI_FUNC(PySTEntryObject *) PySymtable_Lookup(struct symtable *, void *);
 

Modified: python/branches/ast-objects/Parser/asdl_c.py
==============================================================================
--- python/branches/ast-objects/Parser/asdl_c.py	(original)
+++ python/branches/ast-objects/Parser/asdl_c.py	Sun Feb  5 02:54:29 2006
@@ -258,6 +258,8 @@
                     emit("%s = PyList_New(0);" % f.name, 2)
                 emit("Py_INCREF(%s);" % f.name, 1)
             emit("result->%s = %s;" % (f.name, f.name), 1)
+        if str(name)[0].isupper(): # HACK !
+            emit("result->_base._kind = %s_kind;" % name, 1)
         for argtype, argname, opt in attrs:
             if argtype == "PyObject*":
                 emit("Py_INCREF(%s);" % argname, 1)
@@ -308,7 +310,7 @@
         depth = 1
         def emit(s):
             self.emit(s, depth)
-        emit("if (obj->%s != Py_None) /* empty */;" % f.name)
+        emit("if (obj->%s == Py_None) /* empty */;" % f.name)
         check = self.check(f.type)
         emit("else if (!%s(obj->%s)) {" % (check, f.name))
         emit('    failed_check("%s", "%s", obj->%s);' % (f.name, f.type, f.name))

Modified: python/branches/ast-objects/Python/Python-ast.c
==============================================================================
--- python/branches/ast-objects/Python/Python-ast.c	(original)
+++ python/branches/ast-objects/Python/Python-ast.c	Sun Feb  5 02:54:29 2006
@@ -183,6 +183,7 @@
                 body = PyList_New(0);
         Py_INCREF(body);
         result->body = body;
+        result->_base._kind = Module_kind;
         return (PyObject*)result;
 }
 
@@ -268,6 +269,7 @@
                 body = PyList_New(0);
         Py_INCREF(body);
         result->body = body;
+        result->_base._kind = Interactive_kind;
         return (PyObject*)result;
 }
 
@@ -351,6 +353,7 @@
                 return NULL;
         Py_INCREF(body);
         result->body = body;
+        result->_base._kind = Expression_kind;
         return (PyObject*)result;
 }
 
@@ -427,6 +430,7 @@
                 body = PyList_New(0);
         Py_INCREF(body);
         result->body = body;
+        result->_base._kind = Suite_kind;
         return (PyObject*)result;
 }
 
@@ -620,6 +624,7 @@
                 decorators = PyList_New(0);
         Py_INCREF(decorators);
         result->decorators = decorators;
+        result->_base._kind = FunctionDef_kind;
         result->_base.lineno = lineno;
         return (PyObject*)result;
 }
@@ -736,6 +741,7 @@
                 body = PyList_New(0);
         Py_INCREF(body);
         result->body = body;
+        result->_base._kind = ClassDef_kind;
         result->_base.lineno = lineno;
         return (PyObject*)result;
 }
@@ -843,6 +849,7 @@
         }
         Py_INCREF(value);
         result->value = value;
+        result->_base._kind = Return_kind;
         result->_base.lineno = lineno;
         return (PyObject*)result;
 }
@@ -903,7 +910,7 @@
 Return_validate(PyObject *_obj)
 {
         struct _Return *obj = (struct _Return*)_obj;
-        if (obj->value != Py_None) /* empty */;
+        if (obj->value == Py_None) /* empty */;
         else if (!expr_Check(obj->value)) {
             failed_check("value", "expr", obj->value);
             return -1;
@@ -923,6 +930,7 @@
                 targets = PyList_New(0);
         Py_INCREF(targets);
         result->targets = targets;
+        result->_base._kind = Delete_kind;
         result->_base.lineno = lineno;
         return (PyObject*)result;
 }
@@ -1012,6 +1020,7 @@
         result->targets = targets;
         Py_INCREF(value);
         result->value = value;
+        result->_base._kind = Assign_kind;
         result->_base.lineno = lineno;
         return (PyObject*)result;
 }
@@ -1106,6 +1115,7 @@
         result->op = op;
         Py_INCREF(value);
         result->value = value;
+        result->_base._kind = AugAssign_kind;
         result->_base.lineno = lineno;
         return (PyObject*)result;
 }
@@ -1201,6 +1211,7 @@
         result->values = values;
         Py_INCREF(nl);
         result->nl = nl;
+        result->_base._kind = Print_kind;
         result->_base.lineno = lineno;
         return (PyObject*)result;
 }
@@ -1264,7 +1275,7 @@
 {
         struct _Print *obj = (struct _Print*)_obj;
         int i;
-        if (obj->dest != Py_None) /* empty */;
+        if (obj->dest == Py_None) /* empty */;
         else if (!expr_Check(obj->dest)) {
             failed_check("dest", "expr", obj->dest);
             return -1;
@@ -1310,6 +1321,7 @@
                 orelse = PyList_New(0);
         Py_INCREF(orelse);
         result->orelse = orelse;
+        result->_base._kind = For_kind;
         result->_base.lineno = lineno;
         return (PyObject*)result;
 }
@@ -1426,6 +1438,7 @@
                 orelse = PyList_New(0);
         Py_INCREF(orelse);
         result->orelse = orelse;
+        result->_base._kind = While_kind;
         result->_base.lineno = lineno;
         return (PyObject*)result;
 }
@@ -1537,6 +1550,7 @@
                 orelse = PyList_New(0);
         Py_INCREF(orelse);
         result->orelse = orelse;
+        result->_base._kind = If_kind;
         result->_base.lineno = lineno;
         return (PyObject*)result;
 }
@@ -1656,6 +1670,7 @@
         }
         Py_INCREF(tback);
         result->tback = tback;
+        result->_base._kind = Raise_kind;
         result->_base.lineno = lineno;
         return (PyObject*)result;
 }
@@ -1718,21 +1733,21 @@
 Raise_validate(PyObject *_obj)
 {
         struct _Raise *obj = (struct _Raise*)_obj;
-        if (obj->type != Py_None) /* empty */;
+        if (obj->type == Py_None) /* empty */;
         else if (!expr_Check(obj->type)) {
             failed_check("type", "expr", obj->type);
             return -1;
         }
         else if (expr_validate(obj->type) < 0)
             return -1;
-        if (obj->inst != Py_None) /* empty */;
+        if (obj->inst == Py_None) /* empty */;
         else if (!expr_Check(obj->inst)) {
             failed_check("inst", "expr", obj->inst);
             return -1;
         }
         else if (expr_validate(obj->inst) < 0)
             return -1;
-        if (obj->tback != Py_None) /* empty */;
+        if (obj->tback == Py_None) /* empty */;
         else if (!expr_Check(obj->tback)) {
             failed_check("tback", "expr", obj->tback);
             return -1;
@@ -1761,6 +1776,7 @@
                 orelse = PyList_New(0);
         Py_INCREF(orelse);
         result->orelse = orelse;
+        result->_base._kind = TryExcept_kind;
         result->_base.lineno = lineno;
         return (PyObject*)result;
 }
@@ -1880,6 +1896,7 @@
                 finalbody = PyList_New(0);
         Py_INCREF(finalbody);
         result->finalbody = finalbody;
+        result->_base._kind = TryFinally_kind;
         result->_base.lineno = lineno;
         return (PyObject*)result;
 }
@@ -1984,6 +2001,7 @@
         }
         Py_INCREF(msg);
         result->msg = msg;
+        result->_base._kind = Assert_kind;
         result->_base.lineno = lineno;
         return (PyObject*)result;
 }
@@ -2049,7 +2067,7 @@
             failed_check("test", "expr", obj->test);
             return -1;
         }
-        if (obj->msg != Py_None) /* empty */;
+        if (obj->msg == Py_None) /* empty */;
         else if (!expr_Check(obj->msg)) {
             failed_check("msg", "expr", obj->msg);
             return -1;
@@ -2069,6 +2087,7 @@
                 names = PyList_New(0);
         Py_INCREF(names);
         result->names = names;
+        result->_base._kind = Import_kind;
         result->_base.lineno = lineno;
         return (PyObject*)result;
 }
@@ -2158,6 +2177,7 @@
                 names = PyList_New(0);
         Py_INCREF(names);
         result->names = names;
+        result->_base._kind = ImportFrom_kind;
         result->_base.lineno = lineno;
         return (PyObject*)result;
 }
@@ -2260,6 +2280,7 @@
         }
         Py_INCREF(locals);
         result->locals = locals;
+        result->_base._kind = Exec_kind;
         result->_base.lineno = lineno;
         return (PyObject*)result;
 }
@@ -2326,14 +2347,14 @@
             failed_check("body", "expr", obj->body);
             return -1;
         }
-        if (obj->globals != Py_None) /* empty */;
+        if (obj->globals == Py_None) /* empty */;
         else if (!expr_Check(obj->globals)) {
             failed_check("globals", "expr", obj->globals);
             return -1;
         }
         else if (expr_validate(obj->globals) < 0)
             return -1;
-        if (obj->locals != Py_None) /* empty */;
+        if (obj->locals == Py_None) /* empty */;
         else if (!expr_Check(obj->locals)) {
             failed_check("locals", "expr", obj->locals);
             return -1;
@@ -2353,6 +2374,7 @@
                 names = PyList_New(0);
         Py_INCREF(names);
         result->names = names;
+        result->_base._kind = Global_kind;
         result->_base.lineno = lineno;
         return (PyObject*)result;
 }
@@ -2436,6 +2458,7 @@
                 return NULL;
         Py_INCREF(value);
         result->value = value;
+        result->_base._kind = Expr_kind;
         result->_base.lineno = lineno;
         return (PyObject*)result;
 }
@@ -2509,6 +2532,7 @@
         struct _Pass *result = PyObject_New(struct _Pass, &Py_Pass_Type);
         if (result == NULL)
                 return NULL;
+        result->_base._kind = Pass_kind;
         result->_base.lineno = lineno;
         return (PyObject*)result;
 }
@@ -2576,6 +2600,7 @@
         struct _Break *result = PyObject_New(struct _Break, &Py_Break_Type);
         if (result == NULL)
                 return NULL;
+        result->_base._kind = Break_kind;
         result->_base.lineno = lineno;
         return (PyObject*)result;
 }
@@ -2643,6 +2668,7 @@
         struct _Continue *result = PyObject_New(struct _Continue, &Py_Continue_Type);
         if (result == NULL)
                 return NULL;
+        result->_base._kind = Continue_kind;
         result->_base.lineno = lineno;
         return (PyObject*)result;
 }
@@ -2807,6 +2833,7 @@
                 values = PyList_New(0);
         Py_INCREF(values);
         result->values = values;
+        result->_base._kind = BoolOp_kind;
         result->_base.lineno = lineno;
         return (PyObject*)result;
 }
@@ -2901,6 +2928,7 @@
         result->op = op;
         Py_INCREF(right);
         result->right = right;
+        result->_base._kind = BinOp_kind;
         result->_base.lineno = lineno;
         return (PyObject*)result;
 }
@@ -2988,6 +3016,7 @@
         result->op = op;
         Py_INCREF(operand);
         result->operand = operand;
+        result->_base._kind = UnaryOp_kind;
         result->_base.lineno = lineno;
         return (PyObject*)result;
 }
@@ -3070,6 +3099,7 @@
         result->args = args;
         Py_INCREF(body);
         result->body = body;
+        result->_base._kind = Lambda_kind;
         result->_base.lineno = lineno;
         return (PyObject*)result;
 }
@@ -3156,6 +3186,7 @@
                 values = PyList_New(0);
         Py_INCREF(values);
         result->values = values;
+        result->_base._kind = Dict_kind;
         result->_base.lineno = lineno;
         return (PyObject*)result;
 }
@@ -3258,6 +3289,7 @@
                 generators = PyList_New(0);
         Py_INCREF(generators);
         result->generators = generators;
+        result->_base._kind = ListComp_kind;
         result->_base.lineno = lineno;
         return (PyObject*)result;
 }
@@ -3353,6 +3385,7 @@
                 generators = PyList_New(0);
         Py_INCREF(generators);
         result->generators = generators;
+        result->_base._kind = GeneratorExp_kind;
         result->_base.lineno = lineno;
         return (PyObject*)result;
 }
@@ -3448,6 +3481,7 @@
         }
         Py_INCREF(value);
         result->value = value;
+        result->_base._kind = Yield_kind;
         result->_base.lineno = lineno;
         return (PyObject*)result;
 }
@@ -3508,7 +3542,7 @@
 Yield_validate(PyObject *_obj)
 {
         struct _Yield *obj = (struct _Yield*)_obj;
-        if (obj->value != Py_None) /* empty */;
+        if (obj->value == Py_None) /* empty */;
         else if (!expr_Check(obj->value)) {
             failed_check("value", "expr", obj->value);
             return -1;
@@ -3534,6 +3568,7 @@
                 comparators = PyList_New(0);
         Py_INCREF(comparators);
         result->comparators = comparators;
+        result->_base._kind = Compare_kind;
         result->_base.lineno = lineno;
         return (PyObject*)result;
 }
@@ -3658,6 +3693,7 @@
         }
         Py_INCREF(kwargs);
         result->kwargs = kwargs;
+        result->_base._kind = Call_kind;
         result->_base.lineno = lineno;
         return (PyObject*)result;
 }
@@ -3752,14 +3788,14 @@
                 if (keyword_validate(PyList_GET_ITEM(obj->keywords, i)) < 0)
                     return -1;
         }
-        if (obj->starargs != Py_None) /* empty */;
+        if (obj->starargs == Py_None) /* empty */;
         else if (!expr_Check(obj->starargs)) {
             failed_check("starargs", "expr", obj->starargs);
             return -1;
         }
         else if (expr_validate(obj->starargs) < 0)
             return -1;
-        if (obj->kwargs != Py_None) /* empty */;
+        if (obj->kwargs == Py_None) /* empty */;
         else if (!expr_Check(obj->kwargs)) {
             failed_check("kwargs", "expr", obj->kwargs);
             return -1;
@@ -3777,6 +3813,7 @@
                 return NULL;
         Py_INCREF(value);
         result->value = value;
+        result->_base._kind = Repr_kind;
         result->_base.lineno = lineno;
         return (PyObject*)result;
 }
@@ -3852,6 +3889,7 @@
                 return NULL;
         Py_INCREF(n);
         result->n = n;
+        result->_base._kind = Num_kind;
         result->_base.lineno = lineno;
         return (PyObject*)result;
 }
@@ -3927,6 +3965,7 @@
                 return NULL;
         Py_INCREF(s);
         result->s = s;
+        result->_base._kind = Str_kind;
         result->_base.lineno = lineno;
         return (PyObject*)result;
 }
@@ -4006,6 +4045,7 @@
         result->attr = attr;
         Py_INCREF(ctx);
         result->ctx = ctx;
+        result->_base._kind = Attribute_kind;
         result->_base.lineno = lineno;
         return (PyObject*)result;
 }
@@ -4095,6 +4135,7 @@
         result->slice = slice;
         Py_INCREF(ctx);
         result->ctx = ctx;
+        result->_base._kind = Subscript_kind;
         result->_base.lineno = lineno;
         return (PyObject*)result;
 }
@@ -4182,6 +4223,7 @@
         result->id = id;
         Py_INCREF(ctx);
         result->ctx = ctx;
+        result->_base._kind = Name_kind;
         result->_base.lineno = lineno;
         return (PyObject*)result;
 }
@@ -4266,6 +4308,7 @@
         result->elts = elts;
         Py_INCREF(ctx);
         result->ctx = ctx;
+        result->_base._kind = List_kind;
         result->_base.lineno = lineno;
         return (PyObject*)result;
 }
@@ -4359,6 +4402,7 @@
         result->elts = elts;
         Py_INCREF(ctx);
         result->ctx = ctx;
+        result->_base._kind = Tuple_kind;
         result->_base.lineno = lineno;
         return (PyObject*)result;
 }
@@ -4513,6 +4557,7 @@
         struct _Load *result = PyObject_New(struct _Load, &Py_Load_Type);
         if (result == NULL)
                 return NULL;
+        result->_base._kind = Load_kind;
         return (PyObject*)result;
 }
 
@@ -4579,6 +4624,7 @@
         struct _Store *result = PyObject_New(struct _Store, &Py_Store_Type);
         if (result == NULL)
                 return NULL;
+        result->_base._kind = Store_kind;
         return (PyObject*)result;
 }
 
@@ -4645,6 +4691,7 @@
         struct _Del *result = PyObject_New(struct _Del, &Py_Del_Type);
         if (result == NULL)
                 return NULL;
+        result->_base._kind = Del_kind;
         return (PyObject*)result;
 }
 
@@ -4711,6 +4758,7 @@
         struct _AugLoad *result = PyObject_New(struct _AugLoad, &Py_AugLoad_Type);
         if (result == NULL)
                 return NULL;
+        result->_base._kind = AugLoad_kind;
         return (PyObject*)result;
 }
 
@@ -4777,6 +4825,7 @@
         struct _AugStore *result = PyObject_New(struct _AugStore, &Py_AugStore_Type);
         if (result == NULL)
                 return NULL;
+        result->_base._kind = AugStore_kind;
         return (PyObject*)result;
 }
 
@@ -4843,6 +4892,7 @@
         struct _Param *result = PyObject_New(struct _Param, &Py_Param_Type);
         if (result == NULL)
                 return NULL;
+        result->_base._kind = Param_kind;
         return (PyObject*)result;
 }
 
@@ -4972,6 +5022,7 @@
         struct _Ellipsis *result = PyObject_New(struct _Ellipsis, &Py_Ellipsis_Type);
         if (result == NULL)
                 return NULL;
+        result->_base._kind = Ellipsis_kind;
         return (PyObject*)result;
 }
 
@@ -5056,6 +5107,7 @@
         }
         Py_INCREF(step);
         result->step = step;
+        result->_base._kind = Slice_kind;
         return (PyObject*)result;
 }
 
@@ -5117,21 +5169,21 @@
 Slice_validate(PyObject *_obj)
 {
         struct _Slice *obj = (struct _Slice*)_obj;
-        if (obj->lower != Py_None) /* empty */;
+        if (obj->lower == Py_None) /* empty */;
         else if (!expr_Check(obj->lower)) {
             failed_check("lower", "expr", obj->lower);
             return -1;
         }
         else if (expr_validate(obj->lower) < 0)
             return -1;
-        if (obj->upper != Py_None) /* empty */;
+        if (obj->upper == Py_None) /* empty */;
         else if (!expr_Check(obj->upper)) {
             failed_check("upper", "expr", obj->upper);
             return -1;
         }
         else if (expr_validate(obj->upper) < 0)
             return -1;
-        if (obj->step != Py_None) /* empty */;
+        if (obj->step == Py_None) /* empty */;
         else if (!expr_Check(obj->step)) {
             failed_check("step", "expr", obj->step);
             return -1;
@@ -5151,6 +5203,7 @@
                 dims = PyList_New(0);
         Py_INCREF(dims);
         result->dims = dims;
+        result->_base._kind = ExtSlice_kind;
         return (PyObject*)result;
 }
 
@@ -5235,6 +5288,7 @@
                 return NULL;
         Py_INCREF(value);
         result->value = value;
+        result->_base._kind = Index_kind;
         return (PyObject*)result;
 }
 
@@ -5366,6 +5420,7 @@
         struct _And *result = PyObject_New(struct _And, &Py_And_Type);
         if (result == NULL)
                 return NULL;
+        result->_base._kind = And_kind;
         return (PyObject*)result;
 }
 
@@ -5432,6 +5487,7 @@
         struct _Or *result = PyObject_New(struct _Or, &Py_Or_Type);
         if (result == NULL)
                 return NULL;
+        result->_base._kind = Or_kind;
         return (PyObject*)result;
 }
 
@@ -5577,6 +5633,7 @@
         struct _Add *result = PyObject_New(struct _Add, &Py_Add_Type);
         if (result == NULL)
                 return NULL;
+        result->_base._kind = Add_kind;
         return (PyObject*)result;
 }
 
@@ -5643,6 +5700,7 @@
         struct _Sub *result = PyObject_New(struct _Sub, &Py_Sub_Type);
         if (result == NULL)
                 return NULL;
+        result->_base._kind = Sub_kind;
         return (PyObject*)result;
 }
 
@@ -5709,6 +5767,7 @@
         struct _Mult *result = PyObject_New(struct _Mult, &Py_Mult_Type);
         if (result == NULL)
                 return NULL;
+        result->_base._kind = Mult_kind;
         return (PyObject*)result;
 }
 
@@ -5775,6 +5834,7 @@
         struct _Div *result = PyObject_New(struct _Div, &Py_Div_Type);
         if (result == NULL)
                 return NULL;
+        result->_base._kind = Div_kind;
         return (PyObject*)result;
 }
 
@@ -5841,6 +5901,7 @@
         struct _Mod *result = PyObject_New(struct _Mod, &Py_Mod_Type);
         if (result == NULL)
                 return NULL;
+        result->_base._kind = Mod_kind;
         return (PyObject*)result;
 }
 
@@ -5907,6 +5968,7 @@
         struct _Pow *result = PyObject_New(struct _Pow, &Py_Pow_Type);
         if (result == NULL)
                 return NULL;
+        result->_base._kind = Pow_kind;
         return (PyObject*)result;
 }
 
@@ -5973,6 +6035,7 @@
         struct _LShift *result = PyObject_New(struct _LShift, &Py_LShift_Type);
         if (result == NULL)
                 return NULL;
+        result->_base._kind = LShift_kind;
         return (PyObject*)result;
 }
 
@@ -6039,6 +6102,7 @@
         struct _RShift *result = PyObject_New(struct _RShift, &Py_RShift_Type);
         if (result == NULL)
                 return NULL;
+        result->_base._kind = RShift_kind;
         return (PyObject*)result;
 }
 
@@ -6105,6 +6169,7 @@
         struct _BitOr *result = PyObject_New(struct _BitOr, &Py_BitOr_Type);
         if (result == NULL)
                 return NULL;
+        result->_base._kind = BitOr_kind;
         return (PyObject*)result;
 }
 
@@ -6171,6 +6236,7 @@
         struct _BitXor *result = PyObject_New(struct _BitXor, &Py_BitXor_Type);
         if (result == NULL)
                 return NULL;
+        result->_base._kind = BitXor_kind;
         return (PyObject*)result;
 }
 
@@ -6237,6 +6303,7 @@
         struct _BitAnd *result = PyObject_New(struct _BitAnd, &Py_BitAnd_Type);
         if (result == NULL)
                 return NULL;
+        result->_base._kind = BitAnd_kind;
         return (PyObject*)result;
 }
 
@@ -6303,6 +6370,7 @@
         struct _FloorDiv *result = PyObject_New(struct _FloorDiv, &Py_FloorDiv_Type);
         if (result == NULL)
                 return NULL;
+        result->_base._kind = FloorDiv_kind;
         return (PyObject*)result;
 }
 
@@ -6432,6 +6500,7 @@
         struct _Invert *result = PyObject_New(struct _Invert, &Py_Invert_Type);
         if (result == NULL)
                 return NULL;
+        result->_base._kind = Invert_kind;
         return (PyObject*)result;
 }
 
@@ -6498,6 +6567,7 @@
         struct _Not *result = PyObject_New(struct _Not, &Py_Not_Type);
         if (result == NULL)
                 return NULL;
+        result->_base._kind = Not_kind;
         return (PyObject*)result;
 }
 
@@ -6564,6 +6634,7 @@
         struct _UAdd *result = PyObject_New(struct _UAdd, &Py_UAdd_Type);
         if (result == NULL)
                 return NULL;
+        result->_base._kind = UAdd_kind;
         return (PyObject*)result;
 }
 
@@ -6630,6 +6701,7 @@
         struct _USub *result = PyObject_New(struct _USub, &Py_USub_Type);
         if (result == NULL)
                 return NULL;
+        result->_base._kind = USub_kind;
         return (PyObject*)result;
 }
 
@@ -6771,6 +6843,7 @@
         struct _Eq *result = PyObject_New(struct _Eq, &Py_Eq_Type);
         if (result == NULL)
                 return NULL;
+        result->_base._kind = Eq_kind;
         return (PyObject*)result;
 }
 
@@ -6837,6 +6910,7 @@
         struct _NotEq *result = PyObject_New(struct _NotEq, &Py_NotEq_Type);
         if (result == NULL)
                 return NULL;
+        result->_base._kind = NotEq_kind;
         return (PyObject*)result;
 }
 
@@ -6903,6 +6977,7 @@
         struct _Lt *result = PyObject_New(struct _Lt, &Py_Lt_Type);
         if (result == NULL)
                 return NULL;
+        result->_base._kind = Lt_kind;
         return (PyObject*)result;
 }
 
@@ -6969,6 +7044,7 @@
         struct _LtE *result = PyObject_New(struct _LtE, &Py_LtE_Type);
         if (result == NULL)
                 return NULL;
+        result->_base._kind = LtE_kind;
         return (PyObject*)result;
 }
 
@@ -7035,6 +7111,7 @@
         struct _Gt *result = PyObject_New(struct _Gt, &Py_Gt_Type);
         if (result == NULL)
                 return NULL;
+        result->_base._kind = Gt_kind;
         return (PyObject*)result;
 }
 
@@ -7101,6 +7178,7 @@
         struct _GtE *result = PyObject_New(struct _GtE, &Py_GtE_Type);
         if (result == NULL)
                 return NULL;
+        result->_base._kind = GtE_kind;
         return (PyObject*)result;
 }
 
@@ -7167,6 +7245,7 @@
         struct _Is *result = PyObject_New(struct _Is, &Py_Is_Type);
         if (result == NULL)
                 return NULL;
+        result->_base._kind = Is_kind;
         return (PyObject*)result;
 }
 
@@ -7233,6 +7312,7 @@
         struct _IsNot *result = PyObject_New(struct _IsNot, &Py_IsNot_Type);
         if (result == NULL)
                 return NULL;
+        result->_base._kind = IsNot_kind;
         return (PyObject*)result;
 }
 
@@ -7299,6 +7379,7 @@
         struct _In *result = PyObject_New(struct _In, &Py_In_Type);
         if (result == NULL)
                 return NULL;
+        result->_base._kind = In_kind;
         return (PyObject*)result;
 }
 
@@ -7365,6 +7446,7 @@
         struct _NotIn *result = PyObject_New(struct _NotIn, &Py_NotIn_Type);
         if (result == NULL)
                 return NULL;
+        result->_base._kind = NotIn_kind;
         return (PyObject*)result;
 }
 
@@ -7608,14 +7690,14 @@
 {
         struct _excepthandler *obj = (struct _excepthandler*)_obj;
         int i;
-        if (obj->type != Py_None) /* empty */;
+        if (obj->type == Py_None) /* empty */;
         else if (!expr_Check(obj->type)) {
             failed_check("type", "expr", obj->type);
             return -1;
         }
         else if (expr_validate(obj->type) < 0)
             return -1;
-        if (obj->name != Py_None) /* empty */;
+        if (obj->name == Py_None) /* empty */;
         else if (!expr_Check(obj->name)) {
             failed_check("name", "expr", obj->name);
             return -1;
@@ -7739,12 +7821,12 @@
                 if (expr_validate(PyList_GET_ITEM(obj->args, i)) < 0)
                     return -1;
         }
-        if (obj->vararg != Py_None) /* empty */;
+        if (obj->vararg == Py_None) /* empty */;
         else if (!PyString_Check(obj->vararg)) {
             failed_check("vararg", "identifier", obj->vararg);
             return -1;
         }
-        if (obj->kwarg != Py_None) /* empty */;
+        if (obj->kwarg == Py_None) /* empty */;
         else if (!PyString_Check(obj->kwarg)) {
             failed_check("kwarg", "identifier", obj->kwarg);
             return -1;
@@ -7924,7 +8006,7 @@
             failed_check("name", "identifier", obj->name);
             return -1;
         }
-        if (obj->asname != Py_None) /* empty */;
+        if (obj->asname == Py_None) /* empty */;
         else if (!PyString_Check(obj->asname)) {
             failed_check("asname", "identifier", obj->asname);
             return -1;

Modified: python/branches/ast-objects/Python/ast.c
==============================================================================
--- python/branches/ast-objects/Python/ast.c	(original)
+++ python/branches/ast-objects/Python/ast.c	Sun Feb  5 02:54:29 2006
@@ -21,50 +21,27 @@
 */
 
 /*
-  Note:
-  
-  You should rarely need to use the asdl_seq_free() in this file.
-  If you use asdl_seq_free(), you will leak any objects held in the seq.
-  If there is an appropriate asdl_*_seq_free() function, use it.
-  If there isn't an asdl_*_seq_free() function for you, you will
-  need to loop over the data in the sequence and free it.
+  Instructions:
 
-  asdl_seq* seq;
-  int i;
+It's all pretty mechanic. All functions returning PyObject* give you
+a new reference, which you have to release, both in success and error
+cases. All references which you receive as parameters and wish to
+keep, you have to duplicate.
+
+Move all local variables of PyObject* to the beginning of the function,
+and make sure they are all NULL-initialized. Arrange to have a single
+exit point from each function, reachable through goto's. Make sure
+the value actually returned is stored in a variable named "result".
+Make sure all other PyObject* variables are DECREFed at the end of
+the function. Pay particular attention to loops: if a variable is
+overwritten in the beginning of the loop, it needs to be DECREF'ed
+around the end of the loop.
 
-  for (i = 0; i < asdl_seq_LEN(seq); i++)
-      free_***(asdl_seq_GET(seq, i));
-  asdl_seq_free(seq); / * ok * /
-
-  Almost all of the ast functions return a seq of expr, so you should
-  use asdl_expr_seq_free().  The exception is ast_for_suite() which
-  returns a seq of stmt's, so use asdl_stmt_seq_free() to free it.
-
-  If asdl_seq_free is appropriate, you should mark it with an ok comment.
-
-  There are still many memory problems in this file even though
-  it runs clean in valgrind, save one problem that may have existed
-  before the AST.
-
-  Any code which does something like this:
-
-      return ASTconstruct(local, LINENO(n));
-
-  will leak memory.  The problem is if ASTconstruct (e.g., TryFinally)
-  cannot allocate memory, local will be leaked.
-
-  There was discussion on python-dev to replace the entire allocation
-  scheme in this file with arenas.  Basically rather than allocate
-  memory in little blocks with malloc(), we allocate one big honking
-  hunk and deref everything into this block.  We would still need
-  another block or technique to handle the PyObject*s.
-
-  http://mail.python.org/pipermail/python-dev/2005-November/058138.html
 */
 
 /* Data structure used internally */
 struct compiling {
-	char *c_encoding; /* source encoding */
+        char *c_encoding; /* source encoding */
 };
 
 static PyObject *seq_for_testlist(struct compiling *, const node *);
@@ -83,7 +60,7 @@
 static PyObject *parsestrplus(struct compiling *, const node *n);
 
 #ifndef LINENO
-#define LINENO(n)	((n)->n_lineno)
+#define LINENO(n)        ((n)->n_lineno)
 #endif
 
 #define NEW_IDENTIFIER(n) PyString_InternFromString(STR(n))
@@ -104,7 +81,7 @@
 {
     PyObject *u = Py_BuildValue("zi", errstr, LINENO(n));
     if (!u)
-	return 0;
+        return 0;
     PyErr_SetObject(PyExc_SyntaxError, u);
     Py_DECREF(u);
     return 0;
@@ -118,32 +95,32 @@
 
     assert(PyErr_Occurred());
     if (!PyErr_ExceptionMatches(PyExc_SyntaxError))
-	return;
+        return;
 
     PyErr_Fetch(&type, &value, &tback);
     errstr = PyTuple_GetItem(value, 0);
     if (!errstr)
-	return;
+        return;
     Py_INCREF(errstr);
     lineno = PyInt_AsLong(PyTuple_GetItem(value, 1));
     if (lineno == -1)
-	return;
+        return;
     Py_DECREF(value);
 
     loc = PyErr_ProgramText(filename, lineno);
     if (!loc) {
-	Py_INCREF(Py_None);
-	loc = Py_None;
+        Py_INCREF(Py_None);
+        loc = Py_None;
     }
     tmp = Py_BuildValue("(ziOO)", filename, lineno, Py_None, loc);
     Py_DECREF(loc);
     if (!tmp)
-	return;
+        return;
     value = Py_BuildValue("(OO)", errstr, tmp);
     Py_DECREF(errstr);
     Py_DECREF(tmp);
     if (!value)
-	return;
+        return;
     PyErr_Restore(type, value, tback);
 }
 
@@ -234,9 +211,9 @@
     switch (TYPE(n)) {
         case file_input:
             stmts = PyList_New(num_stmts(n));
-	    pos = 0;
+            pos = 0;
             if (!stmts)
-		goto error;
+                goto error;
             for (i = 0; i < NCH(n) - 1; i++) {
                 ch = CHILD(n, i);
                 if (TYPE(ch) == NEWLINE)
@@ -260,39 +237,39 @@
                     }
                 }
             }
-	    assert(pos==PyList_GET_SIZE(stmts));
+            assert(pos==PyList_GET_SIZE(stmts));
             result = Module(stmts);
-	    goto success;
+            goto success;
         case eval_input: {
             /* XXX Why not gen_for here? */
             testlist_ast = ast_for_testlist(&c, CHILD(n, 0));
             if (!testlist_ast)
                 goto error;
             result = Expression(testlist_ast);
-	    goto success;
+            goto success;
         }
         case single_input:
             if (TYPE(CHILD(n, 0)) == NEWLINE) {
                 stmts = PyList_New(1);
                 if (!stmts)
-		    goto error;
-		s = Pass(n->n_lineno);
-		if (!s)
-		    goto error;
-		STEAL_ITEM(stmts, 0, s);
-		result = Interactive(stmts);
-		goto success;
+                    goto error;
+                s = Pass(n->n_lineno);
+                if (!s)
+                    goto error;
+                STEAL_ITEM(stmts, 0, s);
+                result = Interactive(stmts);
+                goto success;
             }
             else {
                 n = CHILD(n, 0);
                 num = num_stmts(n);
                 stmts = PyList_New(num);
                 if (!stmts)
-		    goto error;
+                    goto error;
                 if (num == 1) {
-		    s = ast_for_stmt(&c, n);
-		    if (!s)
-			goto error;
+                    s = ast_for_stmt(&c, n);
+                    if (!s)
+                        goto error;
                     STEAL_ITEM(stmts, 0, s);
                 }
                 else {
@@ -308,8 +285,8 @@
                     }
                 }
 
-		result = Interactive(stmts);
-		goto success;
+                result = Interactive(stmts);
+                goto success;
             }
         default:
             goto error;
@@ -318,6 +295,7 @@
     Py_XDECREF(stmts);
     Py_XDECREF(s);
     Py_XDECREF(testlist_ast);
+    if (result && PyAST_Validate(result) == -1) return NULL;
     return result;
   error:
     Py_XDECREF(stmts);
@@ -357,7 +335,7 @@
         case PERCENT:
             return Mod();
         default:
-	    PyErr_BadInternalCall();
+            PyErr_BadInternalCall();
             return NULL;
     }
 }
@@ -382,40 +360,40 @@
 #define SET_CTX(x) Py_DECREF(x); Py_INCREF(ctx); x = ctx
     switch (e->_kind) {
         case Attribute_kind:
-	    if (Store_Check(ctx) &&
-		!strcmp(PyString_AS_STRING(Attribute_attr(e)), "None")) {
-		    return ast_error(n, "assignment to None");
-	    }
-	    SET_CTX(Attribute_ctx(e));
-	    break;
+            if (Store_Check(ctx) &&
+                !strcmp(PyString_AS_STRING(Attribute_attr(e)), "None")) {
+                    return ast_error(n, "assignment to None");
+            }
+            SET_CTX(Attribute_ctx(e));
+            break;
         case Subscript_kind:
-	    SET_CTX(Subscript_ctx(e));
-	    break;
+            SET_CTX(Subscript_ctx(e));
+            break;
         case Name_kind:
-	    if (Store_Check(ctx) &&
-		!strcmp(PyString_AS_STRING(Name_id(e)), "None")) {
-		    return ast_error(n, "assignment to None");
-	    }
-	    SET_CTX(Name_ctx(e));
-	    break;
+            if (Store_Check(ctx) &&
+                !strcmp(PyString_AS_STRING(Name_id(e)), "None")) {
+                    return ast_error(n, "assignment to None");
+            }
+            SET_CTX(Name_ctx(e));
+            break;
         case List_kind:
-	    SET_CTX(List_ctx(e));
-	    s = List_elts(e);
-	    break;
+            SET_CTX(List_ctx(e));
+            s = List_elts(e);
+            break;
         case Tuple_kind:
             if (PyList_GET_SIZE(Tuple_elts(e)) == 0) 
                 return ast_error(n, "can't assign to ()");
-	    SET_CTX(Tuple_ctx(e));
-	    s = Tuple_elts(e);
-	    break;
+            SET_CTX(Tuple_ctx(e));
+            s = Tuple_elts(e);
+            break;
         case Call_kind:
-	    if (Store_Check(ctx))
-		return ast_error(n, "can't assign to function call");
-	    else if (Del_Check(ctx))
-		return ast_error(n, "can't delete function call");
-	    else
-		return ast_error(n, "unexpected operation on function call");
-	    break;
+            if (Store_Check(ctx))
+                return ast_error(n, "can't assign to function call");
+            else if (Del_Check(ctx))
+                return ast_error(n, "can't delete function call");
+            else
+                return ast_error(n, "unexpected operation on function call");
+            break;
         case BinOp_kind:
             return ast_error(n, "can't assign to operator");
         case GeneratorExp_kind:
@@ -423,25 +401,25 @@
                              "not possible");
         case Num_kind:
         case Str_kind:
-	    return ast_error(n, "can't assign to literal");
+            return ast_error(n, "can't assign to literal");
         default: {
-	   char buf[300];
-	   PyOS_snprintf(buf, sizeof(buf), 
-			 "unexpected expression in assignment %d (line %d)", 
-			 e->_kind, e->lineno);
-	   return ast_error(n, buf);
+           char buf[300];
+           PyOS_snprintf(buf, sizeof(buf), 
+                         "unexpected expression in assignment %d (line %d)", 
+                         e->_kind, e->lineno);
+           return ast_error(n, buf);
        }
     }
     /* If the LHS is a list or tuple, we need to set the assignment
        context for all the tuple elements.  
     */
     if (s) {
-	int i;
+        int i;
 
-	for (i = 0; i < PyList_GET_SIZE(s); i++) {
-	    if (!set_context(PyList_GET_ITEM(s, i), ctx, n))
-		return 0;
-	}
+        for (i = 0; i < PyList_GET_SIZE(s); i++) {
+            if (!set_context(PyList_GET_ITEM(s, i), ctx, n))
+                return 0;
+        }
     }
     return 1;
 #undef SET_CTX
@@ -493,13 +471,13 @@
     */
     REQ(n, comp_op);
     if (NCH(n) == 1) {
-	n = CHILD(n, 0);
-	switch (TYPE(n)) {
+        n = CHILD(n, 0);
+        switch (TYPE(n)) {
             case LESS:
                 return Lt();
             case GREATER:
                 return Gt();
-            case EQEQUAL:			/* == */
+            case EQEQUAL:                        /* == */
                 return Eq();
             case LESSEQUAL:
                 return LtE();
@@ -516,11 +494,11 @@
                 PyErr_Format(PyExc_SystemError, "invalid comp_op: %s",
                              STR(n));
                 return 0;
-	}
+        }
     }
     else if (NCH(n) == 2) {
-	/* handle "not in" and "is not" */
-	switch (TYPE(CHILD(n, 0))) {
+        /* handle "not in" and "is not" */
+        switch (TYPE(CHILD(n, 0))) {
             case NAME:
                 if (strcmp(STR(CHILD(n, 1)), "in") == 0)
                     return NotIn();
@@ -530,7 +508,7 @@
                 PyErr_Format(PyExc_SystemError, "invalid comp_op: %s %s",
                              STR(CHILD(n, 0)), STR(CHILD(n, 1)));
                 return 0;
-	}
+        }
     }
     PyErr_Format(PyExc_SystemError, "invalid comp_op: has %d children",
                  NCH(n));
@@ -546,10 +524,10 @@
     PyObject *expression;
     int i;
     assert(TYPE(n) == testlist
-	   || TYPE(n) == listmaker
-	   || TYPE(n) == testlist_gexp
-	   || TYPE(n) == testlist_safe
-	   );
+           || TYPE(n) == listmaker
+           || TYPE(n) == testlist_gexp
+           || TYPE(n) == testlist_safe
+           );
 
     seq = PyList_New((NCH(n) + 1) / 2);
     if (!seq)
@@ -560,10 +538,10 @@
 
         expression = ast_for_expr(c, CHILD(n, i));
         if (!expression) {
-	    goto error;
+            goto error;
         }
 
-        assert(i / 2 < seq->size);
+        /* assert(i / 2 < seq->size); */ // ??
         PyList_SET_ITEM(seq, i / 2, expression);
     }
     result = seq;
@@ -583,26 +561,26 @@
     PyObject *store = NULL;
     PyObject *arg = NULL;
     if (!args)
-	goto error;
+        goto error;
     store = Store();
     if (!store)
-	goto error;
+        goto error;
 
     REQ(n, fplist);
 
     for (i = 0; i < len; i++) {
         const node *child = CHILD(CHILD(n, 2*i), 0);
         if (TYPE(child) == NAME) {
-	    if (!strcmp(STR(child), "None")) {
-		ast_error(child, "assignment to None");
-		goto error;
-	    }
+            if (!strcmp(STR(child), "None")) {
+                ast_error(child, "assignment to None");
+                goto error;
+            }
             arg = Name(NEW_IDENTIFIER(child), store, LINENO(child));
-	}
+        }
         else
             arg = compiler_complex_args(CHILD(CHILD(n, 2*i), 1));
-	if (!set_context(arg, store, n))
-	    goto error;
+        if (!set_context(arg, store, n))
+            goto error;
         PyList_SET_ITEM(args, i, arg);
     }
 
@@ -612,6 +590,7 @@
     Py_XDECREF(args);
     Py_XDECREF(arg);
     Py_XDECREF(store);
+    if (result && PyAST_Validate(result) == -1) return NULL;
     return result;
 }
 
@@ -641,24 +620,24 @@
     node *ch;
 
     if (TYPE(n) == parameters) {
-	if (NCH(n) == 2) /* () as argument list */
-	    return arguments(NULL, NULL, NULL, NULL);
-	n = CHILD(n, 1);
+        if (NCH(n) == 2) /* () as argument list */
+            return arguments(NULL, NULL, NULL, NULL);
+        n = CHILD(n, 1);
     }
     REQ(n, varargslist);
 
     /* first count the number of normal args & defaults */
     for (i = 0; i < NCH(n); i++) {
-	ch = CHILD(n, i);
-	if (TYPE(ch) == fpdef) {
-	    n_args++;
-	}
-	if (TYPE(ch) == EQUAL)
-	    n_defaults++;
+        ch = CHILD(n, i);
+        if (TYPE(ch) == fpdef) {
+            n_args++;
+        }
+        if (TYPE(ch) == EQUAL)
+            n_defaults++;
     }
     args = (n_args ? PyList_New(n_args) : NULL);
     if (!args && n_args)
-    	goto error;
+            goto error;
     defaults = (n_defaults ? PyList_New(n_defaults) : NULL);
     if (!defaults && n_defaults)
         goto error;
@@ -668,67 +647,67 @@
     */
     i = 0;
     while (i < NCH(n)) {
-	ch = CHILD(n, i);
-	switch (TYPE(ch)) {
+        ch = CHILD(n, i);
+        switch (TYPE(ch)) {
             case fpdef:
                 /* XXX Need to worry about checking if TYPE(CHILD(n, i+1)) is
                    anything other than EQUAL or a comma? */
                 /* XXX Should NCH(n) check be made a separate check? */
                 if (i + 1 < NCH(n) && TYPE(CHILD(n, i + 1)) == EQUAL) {
-		    e = ast_for_expr(c, CHILD(n, i + 2));
-		    if (!e)
-			goto error;
+                    e = ast_for_expr(c, CHILD(n, i + 2));
+                    if (!e)
+                        goto error;
                     STEAL_ITEM(defaults, defno++, e);
                     i += 2;
-		    found_default = 1;
+                    found_default = 1;
+                }
+                else if (found_default) {
+                    ast_error(n, 
+                             "non-default argument follows default argument");
+                    goto error;
                 }
-		else if (found_default) {
-		    ast_error(n, 
-			     "non-default argument follows default argument");
-		    goto error;
-		}
 
                 if (NCH(ch) == 3) {
-		    e = compiler_complex_args(CHILD(ch, 1));
-		    if (!e)
-			goto error;
+                    e = compiler_complex_args(CHILD(ch, 1));
+                    if (!e)
+                        goto error;
                     STEAL_ITEM(args, argno++, e);
-		}
+                }
                 else if (TYPE(CHILD(ch, 0)) == NAME) {
-		    if (!strcmp(STR(CHILD(ch, 0)), "None")) {
-			    ast_error(CHILD(ch, 0), "assignment to None");
-			    goto error;
-		    }
-		    id = NEW_IDENTIFIER(CHILD(ch, 0));
-		    if (!id) goto error;
-		    if (!param) param = Param();
-		    if (!param) goto error;
+                    if (!strcmp(STR(CHILD(ch, 0)), "None")) {
+                            ast_error(CHILD(ch, 0), "assignment to None");
+                            goto error;
+                    }
+                    id = NEW_IDENTIFIER(CHILD(ch, 0));
+                    if (!id) goto error;
+                    if (!param) param = Param();
+                    if (!param) goto error;
                     e = Name(id, param, LINENO(ch));
                     if (!e)
                         goto error;
                     STEAL_ITEM(args, argno++, e);
-					 
-		}
+                                         
+                }
                 i += 2; /* the name and the comma */
                 break;
             case STAR:
-		if (!strcmp(STR(CHILD(n, i+1)), "None")) {
-			ast_error(CHILD(n, i+1), "assignment to None");
-			goto error;
-		}
+                if (!strcmp(STR(CHILD(n, i+1)), "None")) {
+                        ast_error(CHILD(n, i+1), "assignment to None");
+                        goto error;
+                }
                 vararg = NEW_IDENTIFIER(CHILD(n, i+1));
-		if (!vararg)
-		    goto error;
+                if (!vararg)
+                    goto error;
                 i += 3;
                 break;
             case DOUBLESTAR:
-		if (!strcmp(STR(CHILD(n, i+1)), "None")) {
-			ast_error(CHILD(n, i+1), "assignment to None");
-			goto error;
-		}
+                if (!strcmp(STR(CHILD(n, i+1)), "None")) {
+                        ast_error(CHILD(n, i+1), "assignment to None");
+                        goto error;
+                }
                 kwarg = NEW_IDENTIFIER(CHILD(n, i+1));
-		if (!kwarg)
-		    goto error;
+                if (!kwarg)
+                    goto error;
                 i += 3;
                 break;
             default:
@@ -736,7 +715,7 @@
                              "unexpected node in varargslist: %d @ %d",
                              TYPE(ch), i);
                 goto error;
-	}
+        }
     }
 
     result = arguments(args, vararg, kwarg, defaults);
@@ -748,6 +727,7 @@
     Py_XDECREF(e);
     Py_XDECREF(id);
     Py_XDECREF(param);
+    if (result && PyAST_Validate(result) == -1) return NULL;
     return result;
 }
 
@@ -768,21 +748,21 @@
         goto error;
     load = Load();
     if (!load)
-	goto error;
+        goto error;
     e = Name(id, load, LINENO(n));
     if (!result)
-	goto error;
+        goto error;
     id = NULL;
 
     for (i = 2; i < NCH(n); i+=2) {
         id = NEW_IDENTIFIER(CHILD(n, i));
-	if (!id)
-	    goto error;
-	attrib = Attribute(e, id, load, LINENO(CHILD(n, i)));
-	if (!attrib)
-	    goto error;
-	e = attrib;
-	attrib = NULL;
+        if (!id)
+            goto error;
+        attrib = Attribute(e, id, load, LINENO(CHILD(n, i)));
+        if (!attrib)
+            goto error;
+        e = attrib;
+        attrib = NULL;
     }
     result = e;
     e = NULL;
@@ -792,7 +772,8 @@
     Py_XDECREF(e);
     Py_XDECREF(attrib);
     Py_XDECREF(load);
-    return NULL;
+    if (result && PyAST_Validate(result) == -1) return NULL;
+    return result;
 }
 
 static PyObject*
@@ -806,28 +787,28 @@
     REQ(n, decorator);
     
     if ((NCH(n) < 3 && NCH(n) != 5 && NCH(n) != 6)
-	|| TYPE(CHILD(n, 0)) != AT || TYPE(RCHILD(n, -1)) != NEWLINE) {
-	ast_error(n, "Invalid decorator node");
-	goto error;
+        || TYPE(CHILD(n, 0)) != AT || TYPE(RCHILD(n, -1)) != NEWLINE) {
+        ast_error(n, "Invalid decorator node");
+        goto error;
     }
     
     name_expr = ast_for_dotted_name(c, CHILD(n, 1));
     if (!name_expr)
-	goto error;
-	
+        goto error;
+        
     if (NCH(n) == 3) { /* No arguments */
-	d = name_expr;
-	name_expr = NULL;
+        d = name_expr;
+        name_expr = NULL;
     }
     else if (NCH(n) == 5) { /* Call with no arguments */
-	d = Call(name_expr, NULL, NULL, NULL, NULL, LINENO(n));
-	if (!d)
-	    goto error;
+        d = Call(name_expr, NULL, NULL, NULL, NULL, LINENO(n));
+        if (!d)
+            goto error;
     }
     else {
-	d = ast_for_call(c, CHILD(n, 3), name_expr);
-	if (!d)
-	    goto error;
+        d = ast_for_call(c, CHILD(n, 3), name_expr);
+        if (!d)
+            goto error;
     }
 
     result = d;
@@ -836,6 +817,7 @@
   error:
     Py_XDECREF(name_expr);
     Py_XDECREF(d);
+    if (result && PyAST_Validate(result) == -1) return NULL;
     return result;
 }
 
@@ -852,12 +834,12 @@
     decorator_seq = PyList_New(NCH(n));
     if (!decorator_seq)
         goto error;
-	
+        
     for (i = 0; i < NCH(n); i++) {
-	d = ast_for_decorator(c, CHILD(n, i));
-	if (!d)
-	    goto error;
-	STEAL_ITEM(decorator_seq, i, d);
+        d = ast_for_decorator(c, CHILD(n, i));
+        if (!d)
+            goto error;
+        STEAL_ITEM(decorator_seq, i, d);
     }
     result = decorator_seq;
     decorator_seq = NULL;
@@ -881,28 +863,28 @@
     REQ(n, funcdef);
 
     if (NCH(n) == 6) { /* decorators are present */
-	decorator_seq = ast_for_decorators(c, CHILD(n, 0));
-	if (!decorator_seq)
-	    goto error;
-	name_i = 2;
+        decorator_seq = ast_for_decorators(c, CHILD(n, 0));
+        if (!decorator_seq)
+            goto error;
+        name_i = 2;
     }
     else {
-	name_i = 1;
+        name_i = 1;
     }
 
     name = NEW_IDENTIFIER(CHILD(n, name_i));
     if (!name)
-	goto error;
+        goto error;
     else if (!strcmp(STR(CHILD(n, name_i)), "None")) {
-	ast_error(CHILD(n, name_i), "assignment to None");
-	goto error;
+        ast_error(CHILD(n, name_i), "assignment to None");
+        goto error;
     }
     args = ast_for_arguments(c, CHILD(n, name_i + 1));
     if (!args)
-	goto error;
+        goto error;
     body = ast_for_suite(c, CHILD(n, name_i + 3));
     if (!body)
-	goto error;
+        goto error;
 
     result = FunctionDef(name, args, body, decorator_seq, LINENO(n));
 
@@ -911,6 +893,7 @@
     Py_XDECREF(decorator_seq);
     Py_XDECREF(args);
     Py_XDECREF(name);
+    if (result && PyAST_Validate(result) == -1) return NULL;
     return result;
 }
 
@@ -943,6 +926,7 @@
  error:
     Py_XDECREF(args);
     Py_XDECREF(expression);
+    if (result && PyAST_Validate(result) == -1) return NULL;
     return result;
 }
 
@@ -961,14 +945,14 @@
     n_fors++;
     REQ(ch, list_for);
     if (NCH(ch) == 5)
-	ch = CHILD(ch, 4);
+        ch = CHILD(ch, 4);
     else
-	return n_fors;
+        return n_fors;
  count_list_iter:
     REQ(ch, list_iter);
     ch = CHILD(ch, 0);
     if (TYPE(ch) == list_for)
-	goto count_list_for;
+        goto count_list_for;
     else if (TYPE(ch) == list_if) {
         if (NCH(ch) == 3) {
             ch = CHILD(ch, 2);
@@ -997,12 +981,12 @@
  count_list_iter:
     REQ(n, list_iter);
     if (TYPE(CHILD(n, 0)) == list_for)
-	return n_ifs;
+        return n_ifs;
     n = CHILD(n, 0);
     REQ(n, list_if);
     n_ifs++;
     if (NCH(n) == 2)
-	return n_ifs;
+        return n_ifs;
     n = CHILD(n, 2);
     goto count_list_iter;
 }
@@ -1016,7 +1000,7 @@
        list_if: 'if' test [list_iter]
        testlist_safe: test [(',' test)+ [',']]
     */
-    PyObject *result;
+    PyObject *result = NULL;
     PyObject *elt = NULL;
     PyObject *listcomps = NULL;
     PyObject *t = NULL;
@@ -1041,77 +1025,77 @@
 
     listcomps = PyList_New(n_fors);
     if (!listcomps)
-    	goto error;
+            goto error;
     
     ch = CHILD(n, 1);
     for (i = 0; i < n_fors; i++) {
-	/* each variable should be NULL each round */
-	assert(lc == NULL);
-	assert(t == NULL);
-	assert(expression == NULL);
-	assert(ifs == NULL);
-
-	REQ(ch, list_for);
-
-	if (!store) store = Store();
-	if (!store) goto error;
-	t = ast_for_exprlist(c, CHILD(ch, 1), store);
+        /* each variable should be NULL each round */
+        assert(lc == NULL);
+        assert(t == NULL);
+        assert(expression == NULL);
+        assert(ifs == NULL);
+
+        REQ(ch, list_for);
+
+        if (!store) store = Store();
+        if (!store) goto error;
+        t = ast_for_exprlist(c, CHILD(ch, 1), store);
         if (!t)
-	    goto error;
+            goto error;
         expression = ast_for_testlist(c, CHILD(ch, 3));
         if (!expression)
-	    goto error;
+            goto error;
 
-	if (PyList_GET_SIZE(t) == 1) {
-	    lc = comprehension(PyList_GET_ITEM(t, 0), expression, NULL);
-	    if (!lc)
-		goto error;
-	}
-	else {
-	    tmp = Tuple(t, store, LINENO(ch));
-	    if (!t)
-		goto error;
-	    lc = comprehension(tmp, expression, NULL);
-	    if (!lc)
-		goto error;
-	    Py_RELEASE(tmp);
-	}
-	Py_RELEASE(t);
-	Py_RELEASE(expression);
+        if (PyList_GET_SIZE(t) == 1) {
+            lc = comprehension(PyList_GET_ITEM(t, 0), expression, NULL);
+            if (!lc)
+                goto error;
+        }
+        else {
+            tmp = Tuple(t, store, LINENO(ch));
+            if (!t)
+                goto error;
+            lc = comprehension(tmp, expression, NULL);
+            if (!lc)
+                goto error;
+            Py_RELEASE(tmp);
+        }
+        Py_RELEASE(t);
+        Py_RELEASE(expression);
 
-	if (NCH(ch) == 5) {
-	    int j, n_ifs;
+        if (NCH(ch) == 5) {
+            int j, n_ifs;
 
-	    ch = CHILD(ch, 4);
-	    n_ifs = count_list_ifs(ch);
+            ch = CHILD(ch, 4);
+            n_ifs = count_list_ifs(ch);
             if (n_ifs == -1)
-		goto error;
+                goto error;
+
+            ifs = PyList_New(n_ifs);
+            if (!ifs)
+                goto error;
 
-	    ifs = PyList_New(n_ifs);
-	    if (!ifs)
-		goto error;
-
-	    for (j = 0; j < n_ifs; j++) {
-		REQ(ch, list_iter);
-
-		ch = CHILD(ch, 0);
-		REQ(ch, list_if);
-
-		t = ast_for_expr(c, CHILD(ch, 1));
-		if (!t)
-		    goto error;
-		STEAL_ITEM(ifs, j, t);
-		if (NCH(ch) == 3)
-		    ch = CHILD(ch, 2);
-	    }
-	    /* on exit, must guarantee that ch is a list_for */
-	    if (TYPE(ch) == list_iter)
-		ch = CHILD(ch, 0);
-	    Py_DECREF(comprehension_ifs(lc));
-	    comprehension_ifs(lc) = ifs;
-	    ifs = NULL;
-	}
-	STEAL_ITEM(listcomps, i, lc);
+            for (j = 0; j < n_ifs; j++) {
+                REQ(ch, list_iter);
+
+                ch = CHILD(ch, 0);
+                REQ(ch, list_if);
+
+                t = ast_for_expr(c, CHILD(ch, 1));
+                if (!t)
+                    goto error;
+                STEAL_ITEM(ifs, j, t);
+                if (NCH(ch) == 3)
+                    ch = CHILD(ch, 2);
+            }
+            /* on exit, must guarantee that ch is a list_for */
+            if (TYPE(ch) == list_iter)
+                ch = CHILD(ch, 0);
+            Py_DECREF(comprehension_ifs(lc));
+            comprehension_ifs(lc) = ifs;
+            ifs = NULL;
+        }
+        STEAL_ITEM(listcomps, i, lc);
     }
 
     result = ListComp(elt, listcomps, LINENO(n));
@@ -1124,6 +1108,7 @@
     Py_XDECREF(store);
     Py_XDECREF(ifs);
     Py_XDECREF(tmp);
+    if (result && PyAST_Validate(result) == -1) return NULL;
     return result;
 }
 
@@ -1136,35 +1121,35 @@
 static int
 count_gen_fors(const node *n)
 {
-	int n_fors = 0;
-	node *ch = CHILD(n, 1);
+        int n_fors = 0;
+        node *ch = CHILD(n, 1);
 
  count_gen_for:
-	n_fors++;
-	REQ(ch, gen_for);
-	if (NCH(ch) == 5)
-		ch = CHILD(ch, 4);
-	else
-		return n_fors;
+        n_fors++;
+        REQ(ch, gen_for);
+        if (NCH(ch) == 5)
+                ch = CHILD(ch, 4);
+        else
+                return n_fors;
  count_gen_iter:
-	REQ(ch, gen_iter);
-	ch = CHILD(ch, 0);
-	if (TYPE(ch) == gen_for)
-		goto count_gen_for;
-	else if (TYPE(ch) == gen_if) {
-		if (NCH(ch) == 3) {
-			ch = CHILD(ch, 2);
-			goto count_gen_iter;
-		}
-		else
-		    return n_fors;
-	}
-	else {
-		/* Should never be reached */
-		PyErr_SetString(PyExc_SystemError,
-				"logic error in count_gen_fors");
-		return -1;
-	}
+        REQ(ch, gen_iter);
+        ch = CHILD(ch, 0);
+        if (TYPE(ch) == gen_for)
+                goto count_gen_for;
+        else if (TYPE(ch) == gen_if) {
+                if (NCH(ch) == 3) {
+                        ch = CHILD(ch, 2);
+                        goto count_gen_iter;
+                }
+                else
+                    return n_fors;
+        }
+        else {
+                /* Should never be reached */
+                PyErr_SetString(PyExc_SystemError,
+                                "logic error in count_gen_fors");
+                return -1;
+        }
 }
 
 /* Count the number of 'if' statements in a generator expression.
@@ -1175,26 +1160,26 @@
 static int
 count_gen_ifs(const node *n)
 {
-	int n_ifs = 0;
+        int n_ifs = 0;
 
-	while (1) {
-		REQ(n, gen_iter);
-		if (TYPE(CHILD(n, 0)) == gen_for)
-			return n_ifs;
-		n = CHILD(n, 0);
-		REQ(n, gen_if);
-		n_ifs++;
-		if (NCH(n) == 2)
-			return n_ifs;
-		n = CHILD(n, 2);
-	}
+        while (1) {
+                REQ(n, gen_iter);
+                if (TYPE(CHILD(n, 0)) == gen_for)
+                        return n_ifs;
+                n = CHILD(n, 0);
+                REQ(n, gen_if);
+                n_ifs++;
+                if (NCH(n) == 2)
+                        return n_ifs;
+                n = CHILD(n, 2);
+        }
 }
 
 static PyObject*
 ast_for_genexp(struct compiling *c, const node *n)
 {
     /* testlist_gexp: test ( gen_for | (',' test)* [','] )
-       argument: [test '='] test [gen_for]	 # Really [keyword '='] test */
+       argument: [test '='] test [gen_for]         # Really [keyword '='] test */
     PyObject *result = NULL;
     PyObject *elt = NULL;
     PyObject *genexps = NULL;
@@ -1211,7 +1196,7 @@
     
     elt = ast_for_expr(c, CHILD(n, 0));
     if (!elt)
-	goto error;
+        goto error;
     
     n_fors = count_gen_fors(n);
     if (n_fors == -1)
@@ -1219,45 +1204,45 @@
     
     genexps = PyList_New(n_fors);
     if (!genexps)
-	goto error;
+        goto error;
 
     store = Store();
     if (!store)
-	goto error;
+        goto error;
     
     ch = CHILD(n, 1);
     for (i = 0; i < n_fors; i++) {
         assert(ge == NULL);
-	assert(t == NULL);
-	assert(expression == NULL);
+        assert(t == NULL);
+        assert(expression == NULL);
         
         REQ(ch, gen_for);
         
         t = ast_for_exprlist(c, CHILD(ch, 1), store);
         if (!t)
-	    goto error;
+            goto error;
         expression = ast_for_expr(c, CHILD(ch, 3));
         if (!expression) 
-	    goto error;
+            goto error;
         
         if (PyList_GET_SIZE(t) == 1) {
             ge = comprehension(PyList_GET_ITEM(t, 0), expression,
                                NULL);
-	}
+        }
         else {
-	    tmp = Tuple(t, store, LINENO(ch));
-	    if (!tmp)
-		goto error;
+            tmp = Tuple(t, store, LINENO(ch));
+            if (!tmp)
+                goto error;
             ge = comprehension(tmp, expression, NULL);
-	    if (!ge)
-		goto error;
-	    Py_RELEASE(tmp);
-	}
-
-	if (!ge)
-	    goto error;
-	Py_RELEASE(t);
-	Py_RELEASE(expression);
+            if (!ge)
+                goto error;
+            Py_RELEASE(tmp);
+        }
+
+        if (!ge)
+            goto error;
+        Py_RELEASE(t);
+        Py_RELEASE(expression);
         
         if (NCH(ch) == 5) {
             int j, n_ifs;
@@ -1266,11 +1251,11 @@
             ch = CHILD(ch, 4);
             n_ifs = count_gen_ifs(ch);
             if (n_ifs == -1)
-		goto error;
+                goto error;
             
             ifs = PyList_New(n_ifs);
             if (!ifs)
-		goto error;
+                goto error;
             
             for (j = 0; j < n_ifs; j++) {
                 REQ(ch, gen_iter);
@@ -1279,7 +1264,7 @@
                 
                 expression = ast_for_expr(c, CHILD(ch, 1));
                 if (!expression)
-		    goto error;
+                    goto error;
                 STEAL_ITEM(ifs, j, expression);
                 if (NCH(ch) == 3)
                     ch = CHILD(ch, 2);
@@ -1287,9 +1272,9 @@
             /* on exit, must guarantee that ch is a gen_for */
             if (TYPE(ch) == gen_iter)
                 ch = CHILD(ch, 0);
-	    Py_DECREF(comprehension_ifs(ge));
-	    Py_INCREF(ifs);
-	    comprehension_ifs(ge) = ifs;
+            Py_DECREF(comprehension_ifs(ge));
+            Py_INCREF(ifs);
+            comprehension_ifs(ge) = ifs;
         }
         STEAL_ITEM(genexps, i, ge);
     }
@@ -1301,6 +1286,7 @@
     Py_XDECREF(ge);
     Py_XDECREF(t);
     Py_XDECREF(expression);
+    if (result && PyAST_Validate(result) == -1) return NULL;
     return result;
 }
 
@@ -1319,119 +1305,120 @@
     
     switch (TYPE(ch)) {
     case NAME: {
-	/* All names start in Load context, but may later be
-	   changed. */
-	PyObject *tmp = Load();
-	if (!tmp)
-	    goto error;
-	result = Name(NEW_IDENTIFIER(ch), tmp, LINENO(n));
-	break;
+        /* All names start in Load context, but may later be
+           changed. */
+        PyObject *tmp = Load();
+        if (!tmp)
+            goto error;
+        result = Name(NEW_IDENTIFIER(ch), tmp, LINENO(n));
+        break;
     }
     case STRING: {
-	PyObject *str = parsestrplus(c, n);
-	
-	if (!str)
-	    goto error;
-	
-	result = Str(str, LINENO(n));
-	break;
+        PyObject *str = parsestrplus(c, n);
+        
+        if (!str)
+            goto error;
+        
+        result = Str(str, LINENO(n));
+        break;
     }
     case NUMBER: {
-	tmp = parsenumber(STR(ch));
-	
-	if (!tmp)
-	    goto error;
-	
-	result = Num(tmp, LINENO(n));
-	break;
+        tmp = parsenumber(STR(ch));
+        
+        if (!tmp)
+            goto error;
+        
+        result = Num(tmp, LINENO(n));
+        break;
     }
     case LPAR: {/* some parenthesized expressions */
-	ch = CHILD(n, 1);
-	
-	if (TYPE(ch) == RPAR) {
-	    tmp = Load();
-	    if (!tmp)
-		goto error;
-	    result = Tuple(NULL, tmp, LINENO(n));
-	} 
-	else if (TYPE(ch) == yield_expr)
-	    result = ast_for_expr(c, ch);
-	else if ((NCH(ch) > 1) && (TYPE(CHILD(ch, 1)) == gen_for))
-	    result = ast_for_genexp(c, ch);
-	else
-	    result = ast_for_testlist_gexp(c, ch);
-	break;
+        ch = CHILD(n, 1);
+        
+        if (TYPE(ch) == RPAR) {
+            tmp = Load();
+            if (!tmp)
+                goto error;
+            result = Tuple(NULL, tmp, LINENO(n));
+        } 
+        else if (TYPE(ch) == yield_expr)
+            result = ast_for_expr(c, ch);
+        else if ((NCH(ch) > 1) && (TYPE(CHILD(ch, 1)) == gen_for))
+            result = ast_for_genexp(c, ch);
+        else
+            result = ast_for_testlist_gexp(c, ch);
+        break;
     }
     case LSQB: /* list (or list comprehension) */
-	tmp = Load();
-	if (!tmp)
-	    goto error;
-	ch = CHILD(n, 1);
-	
-	if (TYPE(ch) == RSQB)
-	    result = List(NULL, tmp, LINENO(n));
-	else {
-	    REQ(ch, listmaker);
-	    if (NCH(ch) == 1 || TYPE(CHILD(ch, 1)) == COMMA) {
-		elts = seq_for_testlist(c, ch);
-		
-		if (!elts)
-		    return NULL;
-	    
-		result = List(elts, tmp, LINENO(n));
-	    }
-	    else
-		result = ast_for_listcomp(c, ch);
-	}
-	break;
+        tmp = Load();
+        if (!tmp)
+            goto error;
+        ch = CHILD(n, 1);
+        
+        if (TYPE(ch) == RSQB)
+            result = List(NULL, tmp, LINENO(n));
+        else {
+            REQ(ch, listmaker);
+            if (NCH(ch) == 1 || TYPE(CHILD(ch, 1)) == COMMA) {
+                elts = seq_for_testlist(c, ch);
+                
+                if (!elts)
+                    return NULL;
+            
+                result = List(elts, tmp, LINENO(n));
+            }
+            else
+                result = ast_for_listcomp(c, ch);
+        }
+        break;
     case LBRACE: {
-	/* dictmaker: test ':' test (',' test ':' test)* [','] */
-	int i, size;
-	
-	ch = CHILD(n, 1);
-	size = (NCH(ch) + 1) / 4; /* +1 in case no trailing comma */
-	keys = PyList_New(size);
-	if (!keys)
-	    goto error;
-	
-	values = PyList_New(size);
-	if (!values)
-	    goto error;
-	
-	for (i = 0; i < NCH(ch); i += 4) {
-	    
-	    tmp = ast_for_expr(c, CHILD(ch, i));
-	    if (!tmp)
-		goto error;
-	    
-	    STEAL_ITEM(keys, i / 4, tmp);
-	    
-	    tmp = ast_for_expr(c, CHILD(ch, i + 2));
-	    if (!tmp)
-		goto error;
-
-	    STEAL_ITEM(values, i / 4, tmp);
-	}
-	result = Dict(keys, values, LINENO(n));
-	break;
+        /* dictmaker: test ':' test (',' test ':' test)* [','] */
+        int i, size;
+        
+        ch = CHILD(n, 1);
+        size = (NCH(ch) + 1) / 4; /* +1 in case no trailing comma */
+        keys = PyList_New(size);
+        if (!keys)
+            goto error;
+        
+        values = PyList_New(size);
+        if (!values)
+            goto error;
+        
+        for (i = 0; i < NCH(ch); i += 4) {
+            
+            tmp = ast_for_expr(c, CHILD(ch, i));
+            if (!tmp)
+                goto error;
+            
+            STEAL_ITEM(keys, i / 4, tmp);
+            
+            tmp = ast_for_expr(c, CHILD(ch, i + 2));
+            if (!tmp)
+                goto error;
+
+            STEAL_ITEM(values, i / 4, tmp);
+        }
+        result = Dict(keys, values, LINENO(n));
+        break;
     }
     case BACKQUOTE: { /* repr */
-	tmp = ast_for_testlist(c, CHILD(n, 1));
-	
-	if (!tmp)
-	    goto error;
-	
-	result = Repr(tmp, LINENO(n));
-	break;
+        tmp = ast_for_testlist(c, CHILD(n, 1));
+        
+        if (!tmp)
+            goto error;
+        
+        result = Repr(tmp, LINENO(n));
+        break;
     }
     default:
-	PyErr_Format(PyExc_SystemError, "unhandled atom %d", TYPE(ch));
+        PyErr_Format(PyExc_SystemError, "unhandled atom %d", TYPE(ch));
     }
  error:
     Py_XDECREF(tmp);
     Py_XDECREF(elts);
     Py_XDECREF(keys);
     Py_XDECREF(values);
+    if (result && PyAST_Validate(result) == -1) return NULL;
     return result;
 }
 
@@ -1452,7 +1439,7 @@
     */
     ch = CHILD(n, 0);
     if (TYPE(ch) == DOT)
-	return Ellipsis();
+        return Ellipsis();
 
     if (NCH(n) == 1 && TYPE(ch) == test) {
         /* 'step' variable hold no significance in terms of being used over
@@ -1461,32 +1448,32 @@
         if (!step)
             goto error;
             
-	result = Index(step);
-	goto success;
+        result = Index(step);
+        goto success;
     }
 
     if (TYPE(ch) == test) {
-	lower = ast_for_expr(c, ch);
+        lower = ast_for_expr(c, ch);
         if (!lower)
             goto error;
     }
 
     /* If there's an upper bound it's in the second or third position. */
     if (TYPE(ch) == COLON) {
-	if (NCH(n) > 1) {
-	    node *n2 = CHILD(n, 1);
+        if (NCH(n) > 1) {
+            node *n2 = CHILD(n, 1);
 
-	    if (TYPE(n2) == test) {
-		upper = ast_for_expr(c, n2);
+            if (TYPE(n2) == test) {
+                upper = ast_for_expr(c, n2);
                 if (!upper)
                     goto error;
             }
-	}
+        }
     } else if (NCH(n) > 2) {
-	node *n2 = CHILD(n, 2);
+        node *n2 = CHILD(n, 2);
 
-	if (TYPE(n2) == test) {
-	    upper = ast_for_expr(c, n2);
+        if (TYPE(n2) == test) {
+            upper = ast_for_expr(c, n2);
             if (!upper)
                 goto error;
         }
@@ -1494,14 +1481,14 @@
 
     ch = CHILD(n, NCH(n) - 1);
     if (TYPE(ch) == sliceop) {
-	if (NCH(ch) == 1)
+        if (NCH(ch) == 1)
             /* XXX: If only 1 child, then should just be a colon.  Should we
                just skip assigning and just get to the return? */
-	    ch = CHILD(ch, 0);
-	else
-	    ch = CHILD(ch, 1);
-	if (TYPE(ch) == test) {
-	    step = ast_for_expr(c, ch);
+            ch = CHILD(ch, 0);
+        else
+            ch = CHILD(ch, 1);
+        if (TYPE(ch) == test) {
+            step = ast_for_expr(c, ch);
             if (!step)
                 goto error;
         }
@@ -1513,24 +1500,25 @@
     Py_XDECREF(lower);
     Py_XDECREF(upper);
     Py_XDECREF(step);
+    if (result && PyAST_Validate(result) == -1) return NULL;
     return result;
 }
 
 static PyObject*
 ast_for_binop(struct compiling *c, const node *n)
 {
-	/* Must account for a sequence of expressions.
-	   How should A op B op C by represented?  
-	   BinOp(BinOp(A, op, B), op, C).
-	*/
-
-	PyObject *result = NULL;
-	int i, nops;
-	PyObject *expr1 = NULL; 
-	PyObject *expr2 = NULL; 
-	PyObject *tmp_result = NULL;
-	PyObject *tmp1 = NULL;
-	PyObject *tmp2 = NULL;
+        /* Must account for a sequence of expressions.
+           How should A op B op C by represented?  
+           BinOp(BinOp(A, op, B), op, C).
+        */
+
+        PyObject *result = NULL;
+        int i, nops;
+        PyObject *expr1 = NULL; 
+        PyObject *expr2 = NULL; 
+        PyObject *tmp_result = NULL;
+        PyObject *tmp1 = NULL;
+        PyObject *tmp2 = NULL;
         PyObject *operator = NULL;
 
         expr1 = ast_for_expr(c, CHILD(n, 0));
@@ -1545,15 +1533,15 @@
         if (!operator)
             return NULL;
 
-	tmp_result = BinOp(expr1, operator, expr2, LINENO(n));
-	if (!tmp_result)
+        tmp_result = BinOp(expr1, operator, expr2, LINENO(n));
+        if (!tmp_result)
             return NULL;
 
-	nops = (NCH(n) - 1) / 2;
-	for (i = 1; i < nops; i++) {
-		const node* next_oper = CHILD(n, i * 2 + 1);
+        nops = (NCH(n) - 1) / 2;
+        for (i = 1; i < nops; i++) {
+                const node* next_oper = CHILD(n, i * 2 + 1);
 
-		operator = get_operator(next_oper);
+                operator = get_operator(next_oper);
                 if (!operator)
                     goto error;
 
@@ -1562,29 +1550,31 @@
                     goto error;
 
                 tmp2 = BinOp(tmp_result, operator, tmp1, 
-			     LINENO(next_oper));
-		if (!tmp_result) 
-		    goto error;
-		tmp_result = tmp2;
-		tmp2 = NULL;
-		Py_RELEASE(tmp1);
-	}
-	result = tmp_result;
-	tmp_result = NULL;
- error:
-	Py_XDECREF(expr1);
-	Py_XDECREF(expr2);
-	Py_XDECREF(operator);
-	Py_XDECREF(tmp_result);
-	Py_XDECREF(tmp1);
-	Py_XDECREF(tmp2);
-	return NULL;
+                             LINENO(next_oper));
+                if (!tmp_result) 
+                    goto error;
+                tmp_result = tmp2;
+                tmp2 = NULL;
+                Py_RELEASE(tmp1);
+        }
+        result = tmp_result;
+        tmp_result = NULL;
+ error:
+        Py_XDECREF(expr1);
+        Py_XDECREF(expr2);
+        Py_XDECREF(operator);
+        Py_XDECREF(tmp_result);
+        Py_XDECREF(tmp1);
+        Py_XDECREF(tmp2);
+        return result;
 }
 
 static PyObject*
-ast_for_trailer(struct compiling *c, const node *n, expr_ty left_expr)
+ast_for_trailer(struct compiling *c, const node *n, PyObject *left_expr)
 {
     /* trailer: '(' [arglist] ')' | '[' subscriptlist ']' | '.' NAME */
+    PyObject *slc = NULL;
+    PyObject *slices = NULL;
     PyObject *result = NULL;
     PyObject *e = NULL;
     REQ(n, trailer);
@@ -1598,45 +1588,44 @@
         REQ(CHILD(n, 2), RSQB);
         n = CHILD(n, 1);
         if (NCH(n) <= 2) {
-            slice_ty slc = ast_for_slice(c, CHILD(n, 0));
+            slc = ast_for_slice(c, CHILD(n, 0));
             if (!slc)
-                return NULL;
-            e = Subscript(left_expr, slc, Load, LINENO(n));
+                goto error;
+            e = Subscript(left_expr, slc, Load(), LINENO(n));
             if (!e) {
-                free_slice(slc);
-                return NULL;
+                goto error;
             }
         }
         else {
             int j;
-            slice_ty slc;
-            asdl_seq *slices = asdl_seq_new((NCH(n) + 1) / 2);
+            slices = PyList_New((NCH(n) + 1) / 2);
             if (!slices)
-                return NULL;
+                goto error;
             for (j = 0; j < NCH(n); j += 2) {
                 slc = ast_for_slice(c, CHILD(n, j));
                 if (!slc) {
-		    for (j = j / 2; j >= 0; j--)
-                        free_slice(asdl_seq_GET(slices, j));
-                    asdl_seq_free(slices); /* ok */
-                    return NULL;
+                    goto error;
                 }
-                asdl_seq_SET(slices, j / 2, slc);
+                STEAL_ITEM(slices, j / 2, slc);
             }
-            e = Subscript(left_expr, ExtSlice(slices), Load, LINENO(n));
+            e = Subscript(left_expr, ExtSlice(slices), Load(), LINENO(n));
             if (!e) {
-		for (j = 0; j < asdl_seq_LEN(slices); j++)
-                    free_slice(asdl_seq_GET(slices, j));
-                asdl_seq_free(slices); /* ok */
-                return NULL;
+                goto error;
             }
         }
     }
     else {
         assert(TYPE(CHILD(n, 0)) == DOT);
-        e = Attribute(left_expr, NEW_IDENTIFIER(CHILD(n, 1)), Load, LINENO(n));
+        e = Attribute(left_expr, NEW_IDENTIFIER(CHILD(n, 1)), Load(), LINENO(n));
     }
-    return e;
+    result = e;
+    e = NULL;
+ error:
+    Py_XDECREF(slc);
+    Py_XDECREF(slices);
+    Py_XDECREF(e);
+    if (result && PyAST_Validate(result) == -1) return NULL;
+    return result;
 }
 
 static PyObject*
@@ -1644,41 +1633,49 @@
 {
     /* power: atom trailer* ('**' factor)*
      */
+    PyObject *f = NULL;
     PyObject *result = NULL;
+    PyObject *tmp = NULL;
+    PyObject *e = NULL;
     int i;
-    PyObject *e = NULL; PyObject *tmp = NULL;
     REQ(n, power);
     e = ast_for_atom(c, CHILD(n, 0));
     if (!e)
-        return NULL;
+        goto error;
     if (NCH(n) == 1)
-        return e;
+        return e; // BAD BAD
     for (i = 1; i < NCH(n); i++) {
         node *ch = CHILD(n, i);
         if (TYPE(ch) != trailer)
             break;
         tmp = ast_for_trailer(c, ch, e);
         if (!tmp) {
-            free_expr(e);
-            return NULL;
+            goto error;
         }
+        // Py_XDECREF(e); // UNCOMMENT
         e = tmp;
+        tmp = NULL;
     }
     if (TYPE(CHILD(n, NCH(n) - 1)) == factor) {
-        expr_ty f = ast_for_expr(c, CHILD(n, NCH(n) - 1));
+        f = ast_for_expr(c, CHILD(n, NCH(n) - 1));
         if (!f) {
-            free_expr(e);
-            return NULL;
+            goto error;
         }
-        tmp = BinOp(e, Pow, f, LINENO(n));
+        tmp = BinOp(e, Pow(), f, LINENO(n));
         if (!tmp) {
-            free_expr(f);
-            free_expr(e);
-            return NULL;
+            goto error;
         }
         e = tmp;
+        tmp = NULL;
     }
-    return e;
+    result = e;
+    e = NULL;
+ error:
+    Py_XDECREF(f);
+    Py_XDECREF(e);
+    Py_XDECREF(tmp);
+    if (result && PyAST_Validate(result) == -1) return NULL;
+    return result;
 }
 
 /* Do not name a variable 'expr'!  Will cause a compile error.
@@ -1704,33 +1701,39 @@
 
     PyObject *result = NULL;
     PyObject *seq = NULL;
+    PyObject *e = NULL;
+    PyObject *expression = NULL;
+    PyObject *ops = NULL;
+    PyObject *cmps = NULL;
+    PyObject *exp = NULL;
+    PyObject *operator = NULL;
     int i;
 
  loop:
     switch (TYPE(n)) {
         case test:
             if (TYPE(CHILD(n, 0)) == lambdef)
-                return ast_for_lambdef(c, CHILD(n, 0));
+                result = ast_for_lambdef(c, CHILD(n, 0));
             /* Fall through to and_test */
         case and_test:
             if (NCH(n) == 1) {
                 n = CHILD(n, 0);
                 goto loop;
             }
-            seq = asdl_seq_new((NCH(n) + 1) / 2);
+            seq = PyList_New((NCH(n) + 1) / 2);
             if (!seq)
-                return NULL;
+                goto error;
             for (i = 0; i < NCH(n); i += 2) {
-                expr_ty e = ast_for_expr(c, CHILD(n, i));
+                e = ast_for_expr(c, CHILD(n, i));
                 if (!e)
-                    return NULL;
-                asdl_seq_SET(seq, i / 2, e);
+                    goto error;
+                STEAL_ITEM(seq, i / 2, e);
             }
             if (!strcmp(STR(CHILD(n, 1)), "and"))
-                return BoolOp(And, seq, LINENO(n));
+                result = BoolOp(And(), seq, LINENO(n));
             else {
                 assert(!strcmp(STR(CHILD(n, 1)), "or"));
-                return BoolOp(Or, seq, LINENO(n));
+                result = BoolOp(Or(), seq, LINENO(n));
             }
             break;
         case not_test:
@@ -1739,12 +1742,13 @@
                 goto loop;
             }
             else {
-                expr_ty expression = ast_for_expr(c, CHILD(n, 1));
+                expression = ast_for_expr(c, CHILD(n, 1));
                 if (!expression)
-                    return NULL;
+                    goto error;
 
-                return UnaryOp(Not, expression, LINENO(n));
+                result = UnaryOp(Not(), expression, LINENO(n));
             }
+            break;
         case comparison:
             if (NCH(n) == 1) {
                 n = CHILD(n, 0);
@@ -1753,43 +1757,33 @@
             else {
                 PyObject *expression = NULL;
                 PyObject *ops = NULL; PyObject *cmps = NULL;
-                ops = asdl_seq_new(NCH(n) / 2);
+                ops = PyList_New(NCH(n) / 2);
                 if (!ops)
-                    return NULL;
-                cmps = asdl_seq_new(NCH(n) / 2);
+                    goto error;
+                cmps = PyList_New(NCH(n) / 2);
                 if (!cmps) {
-                    asdl_seq_free(ops); /* ok */
-                    return NULL;
+                    goto error;
                 }
                 for (i = 1; i < NCH(n); i += 2) {
-                    /* XXX cmpop_ty is just an enum */
-                    cmpop_ty operator;
-
                     operator = ast_for_comp_op(CHILD(n, i));
                     if (!operator) {
-		        asdl_expr_seq_free(ops);
-		        asdl_expr_seq_free(cmps);
-                        return NULL;
-		    }
+                        goto error;
+                    }
 
                     expression = ast_for_expr(c, CHILD(n, i + 1));
                     if (!expression) {
-		        asdl_expr_seq_free(ops);
-		        asdl_expr_seq_free(cmps);
-                        return NULL;
-		    }
+                        goto error;
+                    }
                         
-                    asdl_seq_SET(ops, i / 2, (void *)operator);
-                    asdl_seq_SET(cmps, i / 2, expression);
+                    STEAL_ITEM(ops, i / 2, operator);
+                    STEAL_ITEM(cmps, i / 2, expression);
                 }
                 expression = ast_for_expr(c, CHILD(n, 0));
                 if (!expression) {
-		    asdl_expr_seq_free(ops);
-		    asdl_expr_seq_free(cmps);
-                    return NULL;
-		}
+                    goto error;
+                }
                     
-                return Compare(expression, ops, cmps, LINENO(n));
+                result = Compare(expression, ops, cmps, LINENO(n));
             }
             break;
 
@@ -1807,19 +1801,18 @@
                 n = CHILD(n, 0);
                 goto loop;
             }
-            return ast_for_binop(c, n);
+            result = ast_for_binop(c, n);
+            break;
         case yield_expr: {
-	    expr_ty exp = NULL;
-	    if (NCH(n) == 2) {
-		exp = ast_for_testlist(c, CHILD(n, 1));
-		if (!exp)
-		    return NULL;
-	    }
-	    return Yield(exp, LINENO(n));
-	}
+            if (NCH(n) == 2) {
+                exp = ast_for_testlist(c, CHILD(n, 1));
+                if (!exp)
+                    goto error;
+            }
+            result = Yield(exp, LINENO(n));
+            break;
+        }
         case factor: {
-            PyObject *expression = NULL;
-            
             if (NCH(n) == 1) {
                 n = CHILD(n, 0);
                 goto loop;
@@ -1827,44 +1820,60 @@
 
             expression = ast_for_expr(c, CHILD(n, 1));
             if (!expression)
-                return NULL;
+                goto error;
 
             switch (TYPE(CHILD(n, 0))) {
                 case PLUS:
-                    return UnaryOp(UAdd, expression, LINENO(n));
+                    result = UnaryOp(UAdd(), expression, LINENO(n));
+                    break;
                 case MINUS:
-                    return UnaryOp(USub, expression, LINENO(n));
+                    result = UnaryOp(USub(), expression, LINENO(n));
+                    break;
                 case TILDE:
-                    return UnaryOp(Invert, expression, LINENO(n));
+                    result = UnaryOp(Invert(), expression, LINENO(n));
+                    break;
             }
             PyErr_Format(PyExc_SystemError, "unhandled factor: %d",
-	    		 TYPE(CHILD(n, 0)));
+                             TYPE(CHILD(n, 0)));
             break;
         }
         case power:
-            return ast_for_power(c, n);
+            result = ast_for_power(c, n);
+            break;
         default:
             PyErr_Format(PyExc_SystemError, "unhandled expr: %d", TYPE(n));
-            return NULL;
+            goto error;
     }
-    /* should never get here */
-    return NULL;
+ error:
+    Py_XDECREF(seq);
+    Py_XDECREF(e);
+    Py_XDECREF(expression);
+    Py_XDECREF(ops);
+    Py_XDECREF(cmps);
+    Py_XDECREF(exp);
+    Py_XDECREF(operator);
+    if (result && PyAST_Validate(result) == -1) return NULL;
+    return result;
 }
 
 static PyObject*
-ast_for_call(struct compiling *c, const node *n, expr_ty func)
+ast_for_call(struct compiling *c, const node *n, PyObject *func)
 {
     /*
       arglist: (argument ',')* (argument [',']| '*' test [',' '**' test]
                | '**' test)
-      argument: [test '='] test [gen_for]	 # Really [keyword '='] test
+      argument: [test '='] test [gen_for]         # Really [keyword '='] test
     */
 
     PyObject *result = NULL;
     int i, nargs, nkeywords, ngens;
-    asdl_seq *args = NULL;
-    asdl_seq *keywords = NULL;
-    expr_ty vararg = NULL, kwarg = NULL;
+    PyObject *args = NULL;
+    PyObject *keywords = NULL;
+    PyObject *vararg = NULL;
+    PyObject *kwarg = NULL;
+    PyObject *e = NULL;
+    PyObject *kw = NULL;
+    PyObject *key = NULL;
 
     REQ(n, arglist);
 
@@ -1872,57 +1881,53 @@
     nkeywords = 0;
     ngens = 0;
     for (i = 0; i < NCH(n); i++) {
-	node *ch = CHILD(n, i);
-	if (TYPE(ch) == argument) {
-	    if (NCH(ch) == 1)
-		nargs++;
-	    else if (TYPE(CHILD(ch, 1)) == gen_for)
-		ngens++;
+        node *ch = CHILD(n, i);
+        if (TYPE(ch) == argument) {
+            if (NCH(ch) == 1)
+                nargs++;
+            else if (TYPE(CHILD(ch, 1)) == gen_for)
+                ngens++;
             else
-		nkeywords++;
-	}
+                nkeywords++;
+        }
     }
     if (ngens > 1 || (ngens && (nargs || nkeywords))) {
         ast_error(n, "Generator expression must be parenthesised "
-		  "if not sole argument");
-	return NULL;
+                  "if not sole argument");
+        goto error;
     }
 
     if (nargs + nkeywords + ngens > 255) {
       ast_error(n, "more than 255 arguments");
-      return NULL;
+      goto error;
     }
 
-    args = asdl_seq_new(nargs + ngens);
+    args = PyList_New(nargs + ngens);
     if (!args)
         goto error;
-    keywords = asdl_seq_new(nkeywords);
+    keywords = PyList_New(nkeywords);
     if (!keywords)
         goto error;
     nargs = 0;
     nkeywords = 0;
     for (i = 0; i < NCH(n); i++) {
-	node *ch = CHILD(n, i);
-	if (TYPE(ch) == argument) {
-	    PyObject *e = NULL;
-	    if (NCH(ch) == 1) {
-		e = ast_for_expr(c, CHILD(ch, 0));
+        node *ch = CHILD(n, i);
+        if (TYPE(ch) == argument) {
+            if (NCH(ch) == 1) {
+                e = ast_for_expr(c, CHILD(ch, 0));
                 if (!e)
                     goto error;
-		asdl_seq_SET(args, nargs++, e);
-	    }  
-	    else if (TYPE(CHILD(ch, 1)) == gen_for) {
-        	e = ast_for_genexp(c, ch);
+                STEAL_ITEM(args, nargs++, e);
+            }  
+            else if (TYPE(CHILD(ch, 1)) == gen_for) {
+                e = ast_for_genexp(c, ch);
                 if (!e)
                     goto error;
-		asdl_seq_SET(args, nargs++, e);
+                STEAL_ITEM(args, nargs++, e);
             }
-	    else {
-		keyword_ty kw;
-		identifier key;
-
-		/* CHILD(ch, 0) is test, but must be an identifier? */ 
-		e = ast_for_expr(c, CHILD(ch, 0));
+            else {
+                /* CHILD(ch, 0) is test, but must be an identifier? */ 
+                e = ast_for_expr(c, CHILD(ch, 0));
                 if (!e)
                     goto error;
                 /* f(lambda x: x[0] = 3) ends up getting parsed with
@@ -1930,47 +1935,38 @@
                  * SF bug 132313 points out that complaining about a keyword
                  * then is very confusing.
                  */
-                if (e->kind == Lambda_kind) {
+                if (expr_kind(e) == Lambda_kind) {
                   ast_error(CHILD(ch, 0), "lambda cannot contain assignment");
                   goto error;
-                } else if (e->kind != Name_kind) {
+                } else if (expr_kind(e) != Name_kind) {
                   ast_error(CHILD(ch, 0), "keyword can't be an expression");
                   goto error;
                 }
-		key = Name_id(e);
-		free(e); /* XXX: is free correct here? */
-		e = ast_for_expr(c, CHILD(ch, 2));
+                key = Name_id(e);
+                e = ast_for_expr(c, CHILD(ch, 2));
                 if (!e)
                     goto error;
-		kw = keyword(key, e);
+                kw = keyword(key, e);
                 if (!kw)
                     goto error;
-		asdl_seq_SET(keywords, nkeywords++, kw);
-	    }
-	}
-	else if (TYPE(ch) == STAR) {
-	    vararg = ast_for_expr(c, CHILD(n, i+1));
-	    i++;
-	}
-	else if (TYPE(ch) == DOUBLESTAR) {
-	    kwarg = ast_for_expr(c, CHILD(n, i+1));
-	    i++;
-	}
-    }
-
-    return Call(func, args, keywords, vararg, kwarg, LINENO(n));
-
- error:
-    free_expr(vararg);
-    free_expr(kwarg);
-    if (args)
-        asdl_expr_seq_free(args);
-    if (keywords) {
-	for (i = 0; i < asdl_seq_LEN(keywords); i++)
-            free_keyword(asdl_seq_GET(keywords, i));
-        asdl_seq_free(keywords); /* ok */
-    }
-    return NULL;
+                STEAL_ITEM(keywords, nkeywords++, kw);
+            }
+        }
+        else if (TYPE(ch) == STAR) {
+            vararg = ast_for_expr(c, CHILD(n, i+1));
+            i++;
+        }
+        else if (TYPE(ch) == DOUBLESTAR) {
+            kwarg = ast_for_expr(c, CHILD(n, i+1));
+            i++;
+        }
+    }
+
+    result = Call(func, args, keywords, vararg, kwarg, LINENO(n));
+
+ error:
+    if (result && PyAST_Validate(result) == -1) return NULL;
+    return result;
 }
 
 static PyObject*
@@ -1992,13 +1988,16 @@
                TYPE(n) == testlist1);
     }
     if (NCH(n) == 1)
-	return ast_for_expr(c, CHILD(n, 0));
+        result = ast_for_expr(c, CHILD(n, 0));
     else {
-        asdl_seq *tmp = seq_for_testlist(c, n);
+        PyObject *tmp = seq_for_testlist(c, n);
         if (!tmp)
-            return NULL;
-	return Tuple(tmp, Load, LINENO(n));
+            goto error;
+        result = Tuple(tmp, Load(), LINENO(n));
     }
+ error:
+    if (result && PyAST_Validate(result) == -1) return NULL;
+    return result;
 }
 
 static PyObject*
@@ -2009,147 +2008,146 @@
     PyObject *result = NULL;
     assert(TYPE(n) == testlist_gexp || TYPE(n) == argument);
     if (NCH(n) > 1 && TYPE(CHILD(n, 1)) == gen_for) {
-	return ast_for_genexp(c, n);
+        result = ast_for_genexp(c, n);
     }
     else
-        return ast_for_testlist(c, n);
+        result = ast_for_testlist(c, n);
+    if (result && PyAST_Validate(result) == -1) return NULL;
+    return result;
 }
 
 /* like ast_for_testlist() but returns a sequence */
-static asdl_seq*
+static PyObject*
 ast_for_class_bases(struct compiling *c, const node* n)
 {
     /* testlist: test (',' test)* [','] */
     PyObject *result = NULL;
+    PyObject *base = NULL;
+    PyObject *bases = NULL;
     assert(NCH(n) > 0);
     REQ(n, testlist);
     if (NCH(n) == 1) {
-        PyObject *base = NULL;
-        asdl_seq *bases = asdl_seq_new(1);
+        bases = PyList_New(1);
         if (!bases)
-            return NULL;
+            goto error;
         base = ast_for_expr(c, CHILD(n, 0));
         if (!base) {
-            asdl_seq_free(bases); /* ok */
-            return NULL;
+            goto error;
         }
-        asdl_seq_SET(bases, 0, base);
-        return bases;
+        STEAL_ITEM(bases, 0, base);
+        result = bases;
     }
     else {
-        return seq_for_testlist(c, n);
+        result = seq_for_testlist(c, n);
     }
+ error:
+    return result;
 }
 
 static PyObject*
 ast_for_expr_stmt(struct compiling *c, const node *n)
 {
     PyObject *result = NULL;
+    PyObject *e = NULL;
+    PyObject *expr1 = NULL;
+    PyObject *expr2 = NULL;
+    PyObject *operator = NULL;
+    PyObject *targets = NULL;
+    PyObject *expression = NULL;
     REQ(n, expr_stmt);
     /* expr_stmt: testlist (augassign (yield_expr|testlist) 
                 | ('=' (yield_expr|testlist))*)
        testlist: test (',' test)* [',']
        augassign: '+=' | '-=' | '*=' | '/=' | '%=' | '&=' | '|=' | '^='
-	        | '<<=' | '>>=' | '**=' | '//='
+                | '<<=' | '>>=' | '**=' | '//='
        test: ... here starts the operator precendence dance
      */
 
     if (NCH(n) == 1) {
-	expr_ty e = ast_for_testlist(c, CHILD(n, 0));
+        e = ast_for_testlist(c, CHILD(n, 0));
         if (!e)
-            return NULL;
+            goto error;
 
-	return Expr(e, LINENO(n));
+        result = Expr(e, LINENO(n));
     }
     else if (TYPE(CHILD(n, 1)) == augassign) {
-        PyObject *expr1 = NULL; PyObject *expr2 = NULL;
-        operator_ty operator;
-	node *ch = CHILD(n, 0);
-
-	if (TYPE(ch) == testlist)
-	    expr1 = ast_for_testlist(c, ch);
-	else
-	    expr1 = Yield(ast_for_expr(c, CHILD(ch, 0)), LINENO(ch));
+        node *ch = CHILD(n, 0);
+
+        if (TYPE(ch) == testlist)
+            expr1 = ast_for_testlist(c, ch);
+        else
+            expr1 = Yield(ast_for_expr(c, CHILD(ch, 0)), LINENO(ch));
 
         if (!expr1)
-            return NULL;
-        if (expr1->kind == GeneratorExp_kind) {
-	    free_expr(expr1);
-	    ast_error(ch, "augmented assignment to generator "
-		      "expression not possible");
-	    return NULL;
-        }
-	if (expr1->kind == Name_kind) {
-		char *var_name = PyString_AS_STRING(expr1->v.Name.id);
-		if (var_name[0] == 'N' && !strcmp(var_name, "None")) {
-			free_expr(expr1);
-			ast_error(ch, "assignment to None");
-			return NULL;
-		}
-	}
-
-	ch = CHILD(n, 2);
-	if (TYPE(ch) == testlist)
-	    expr2 = ast_for_testlist(c, ch);
-	else
-	    expr2 = Yield(ast_for_expr(c, ch), LINENO(ch));
+            goto error;
+        if (expr_kind(expr1) == GeneratorExp_kind) {
+            ast_error(ch, "augmented assignment to generator " 
+                      "expression not possible"); 
+            goto error;
+        }
+        if (expr_kind(expr1) == Name_kind) {
+                char *var_name = PyString_AS_STRING(Name_id(expr1));
+                if (var_name[0] == 'N' && !strcmp(var_name, "None")) {
+                        ast_error(ch, "assignment to None");
+                        goto error;
+                }
+        }
+
+        ch = CHILD(n, 2);
+        if (TYPE(ch) == testlist)
+            expr2 = ast_for_testlist(c, ch);
+        else
+            expr2 = Yield(ast_for_expr(c, ch), LINENO(ch));
         if (!expr2) {
-            free_expr(expr1);
-            return NULL;
+            goto error;
         }
 
         operator = ast_for_augassign(CHILD(n, 1));
         if (!operator) {
-            free_expr(expr1);
-            free_expr(expr2);
-            return NULL;
+            goto error;
         }
 
-	return AugAssign(expr1, operator, expr2, LINENO(n));
+        result = AugAssign(expr1, operator, expr2, LINENO(n));
     }
     else {
-	int i;
-	PyObject *targets = NULL;
-	node *value;
-        PyObject *expression = NULL;
-
-	/* a normal assignment */
-	REQ(CHILD(n, 1), EQUAL);
-	targets = asdl_seq_new(NCH(n) / 2);
-	if (!targets)
-	    return NULL;
-	for (i = 0; i < NCH(n) - 2; i += 2) {
-	    PyObject *e = NULL;
-	    node *ch = CHILD(n, i);
-	    if (TYPE(ch) == yield_expr) {
-		ast_error(ch, "assignment to yield expression not possible");
-		goto error;
-	    }
-	    e = ast_for_testlist(c, ch);
-
-	    /* set context to assign */
-	    if (!e) 
-	      goto error;
-
-	    if (!set_context(e, Store, CHILD(n, i))) {
-              free_expr(e);
-	      goto error;
-            }
-
-	    asdl_seq_SET(targets, i / 2, e);
-	}
-	value = CHILD(n, NCH(n) - 1);
-	if (TYPE(value) == testlist)
-	    expression = ast_for_testlist(c, value);
-	else
-	    expression = ast_for_expr(c, value);
-	if (!expression)
-	    goto error;
-	return Assign(targets, expression, LINENO(n));
-    error:
-        asdl_expr_seq_free(targets);
+        int i;
+        node *value;
+
+        /* a normal assignment */
+        REQ(CHILD(n, 1), EQUAL);
+        targets = PyList_New(NCH(n) / 2);
+        if (!targets)
+            goto error;
+        for (i = 0; i < NCH(n) - 2; i += 2) {
+            node *ch = CHILD(n, i);
+            if (TYPE(ch) == yield_expr) {
+                ast_error(ch, "assignment to yield expression not possible");
+                goto error;
+            }
+            e = ast_for_testlist(c, ch);
+
+            /* set context to assign */
+            if (!e) 
+              goto error;
+
+            if (!set_context(e, Store(), CHILD(n, i))) {
+              goto error;
+            }
+
+            STEAL_ITEM(targets, i / 2, e);
+        }
+        value = CHILD(n, NCH(n) - 1);
+        if (TYPE(value) == testlist)
+            expression = ast_for_testlist(c, value);
+        else
+            expression = ast_for_expr(c, value);
+        if (!expression)
+            goto error;
+        result = Assign(targets, expression, LINENO(n));
     }
-    return NULL;
+ error:
+    if (result && PyAST_Validate(result) == -1) return NULL;
+    return result;
 }
 
 static PyObject*
@@ -2159,62 +2157,65 @@
                              | '>>' test [ (',' test)+ [','] ] )
      */
     PyObject *result = NULL;
-    expr_ty dest = NULL, expression;
+    PyObject *dest = NULL, *expression;
     PyObject *seq = NULL;
-    int nl;
+    PyObject *nl = NULL;
     int i, start = 1;
+    int pos = 0;
 
     REQ(n, print_stmt);
     if (NCH(n) >= 2 && TYPE(CHILD(n, 1)) == RIGHTSHIFT) {
-	dest = ast_for_expr(c, CHILD(n, 2));
+        dest = ast_for_expr(c, CHILD(n, 2));
         if (!dest)
-            return NULL;
-	start = 4;
+            goto error;
+        start = 4;
     }
-    seq = asdl_seq_new((NCH(n) + 1 - start) / 2);
+    seq = PyList_New((NCH(n) + 1 - start) / 2);
     if (!seq)
-	return NULL;
+        goto error;
     for (i = start; i < NCH(n); i += 2) {
         expression = ast_for_expr(c, CHILD(n, i));
         if (!expression) {
-	    free_expr(dest);
-	    asdl_expr_seq_free(seq);
-            return NULL;
-	}
+            goto error;
+        }
 
-	asdl_seq_APPEND(seq, expression);
+        STEAL_ITEM(seq, pos++, expression);
     }
-    nl = (TYPE(CHILD(n, NCH(n) - 1)) == COMMA) ? false : true;
-    return Print(dest, seq, nl, LINENO(n));
+    assert(pos==PyList_GET_SIZE(seq));
+    nl = (TYPE(CHILD(n, NCH(n) - 1)) == COMMA) ? Py_False : Py_True;
+    result = Print(dest, seq, nl, LINENO(n));
+ error:
+    if (result && PyAST_Validate(result) == -1) return NULL;
+    return result;
 }
 
-static asdl_seq *
+static PyObject *
 ast_for_exprlist(struct compiling *c, const node *n, PyObject* context)
 {
+    PyObject *result = NULL;
     PyObject *seq = NULL;
     int i;
     PyObject *e = NULL;
 
     REQ(n, exprlist);
 
-    seq = asdl_seq_new((NCH(n) + 1) / 2);
+    seq = PyList_New((NCH(n) + 1) / 2);
     if (!seq)
-	return NULL;
+        goto error;
     for (i = 0; i < NCH(n); i += 2) {
-	e = ast_for_expr(c, CHILD(n, i));
-	if (!e)
-	    goto error;
-	asdl_seq_SET(seq, i / 2, e);
-	if (context) {
-	    if (!set_context(e, context, CHILD(n, i)))
-	    	goto error;
+        e = ast_for_expr(c, CHILD(n, i));
+        if (!e)
+            goto error;
+        PyList_SET_ITEM(seq,i/2,e); // e=NULL; // ???
+        if (context) {
+            if (!set_context(e, context, CHILD(n, i)))
+                    goto error;
         }
     }
-    return seq;
+    result = seq;
 
 error:
-    asdl_expr_seq_free(seq);
-    return NULL;
+    return result;
 }
 
 static PyObject*
@@ -2226,10 +2227,13 @@
     /* del_stmt: 'del' exprlist */
     REQ(n, del_stmt);
 
-    expr_list = ast_for_exprlist(c, CHILD(n, 1), Del);
+    expr_list = ast_for_exprlist(c, CHILD(n, 1), Del());
     if (!expr_list)
-        return NULL;
-    return Delete(expr_list, LINENO(n));
+        goto error;
+    result = Delete(expr_list, LINENO(n));
+ error:
+    if (result && PyAST_Validate(result) == -1) return NULL;
+    return result;
 }
 
 static PyObject*
@@ -2246,71 +2250,80 @@
       raise_stmt: 'raise' [test [',' test [',' test]]]
     */
     PyObject *result = NULL;
+    PyObject *exp = NULL;
+    PyObject *expression = NULL;
+    PyObject *expr1 = NULL;
+    PyObject *expr2 = NULL;
+    PyObject *expr3 = NULL;
     node *ch;
 
     REQ(n, flow_stmt);
     ch = CHILD(n, 0);
     switch (TYPE(ch)) {
         case break_stmt:
-            return Break(LINENO(n));
+            result = Break(LINENO(n));
+            break;
         case continue_stmt:
-            return Continue(LINENO(n));
+            result = Continue(LINENO(n));
+            break;
         case yield_stmt: { /* will reduce to yield_expr */
-	    expr_ty exp = ast_for_expr(c, CHILD(ch, 0));
-	    if (!exp)
-		return NULL;
-            return Expr(exp, LINENO(n));
+            exp = ast_for_expr(c, CHILD(ch, 0));
+            if (!exp)
+                goto error;
+            result = Expr(exp, LINENO(n));
+            break;
         }
         case return_stmt:
             if (NCH(ch) == 1)
-                return Return(NULL, LINENO(n));
+                result = Return(NULL, LINENO(n));
             else {
-                expr_ty expression = ast_for_testlist(c, CHILD(ch, 1));
+                expression = ast_for_testlist(c, CHILD(ch, 1));
                 if (!expression)
-                    return NULL;
-                return Return(expression, LINENO(n));
+                    goto error;
+                result = Return(expression, LINENO(n));
             }
+            break;
         case raise_stmt:
             if (NCH(ch) == 1)
-                return Raise(NULL, NULL, NULL, LINENO(n));
+                result = Raise(NULL, NULL, NULL, LINENO(n));
             else if (NCH(ch) == 2) {
-                expr_ty expression = ast_for_expr(c, CHILD(ch, 1));
+                expression = ast_for_expr(c, CHILD(ch, 1));
                 if (!expression)
-                    return NULL;
-                return Raise(expression, NULL, NULL, LINENO(n));
+                    goto error;
+                result = Raise(expression, NULL, NULL, LINENO(n));
             }
             else if (NCH(ch) == 4) {
-                PyObject *expr1 = NULL; PyObject *expr2 = NULL;
-
                 expr1 = ast_for_expr(c, CHILD(ch, 1));
                 if (!expr1)
-                    return NULL;
+                    goto error;
                 expr2 = ast_for_expr(c, CHILD(ch, 3));
                 if (!expr2)
-                    return NULL;
+                    goto error;
 
-                return Raise(expr1, expr2, NULL, LINENO(n));
+                result = Raise(expr1, expr2, NULL, LINENO(n));
             }
             else if (NCH(ch) == 6) {
-                PyObject *expr1 = NULL; PyObject *expr2 = NULL; PyObject *expr3 = NULL;
-
                 expr1 = ast_for_expr(c, CHILD(ch, 1));
                 if (!expr1)
-                    return NULL;
+                    goto error;
                 expr2 = ast_for_expr(c, CHILD(ch, 3));
                 if (!expr2)
-                    return NULL;
+                    goto error;
                 expr3 = ast_for_expr(c, CHILD(ch, 5));
                 if (!expr3)
-                    return NULL;
+                    goto error;
                     
-                return Raise(expr1, expr2, expr3, LINENO(n));
+                result = Raise(expr1, expr2, expr3, LINENO(n));
             }
+            break;
         default:
             PyErr_Format(PyExc_SystemError,
                          "unexpected flow_stmt: %d", TYPE(ch));
-            return NULL;
+            goto error;
     }
+ error:
+    if (result && PyAST_Validate(result) == -1) return NULL;
+    return result;
 }
 
 static PyObject*
@@ -2322,15 +2335,14 @@
       dotted_name: NAME ('.' NAME)*
     */
     PyObject *result = NULL;
+    PyObject *a = NULL;
  loop:
     switch (TYPE(n)) {
         case import_as_name:
             if (NCH(n) == 3)
-                return alias(NEW_IDENTIFIER(CHILD(n, 0)),
-                             NEW_IDENTIFIER(CHILD(n, 2)));
+                result = alias(NEW_IDENTIFIER(CHILD(n, 0)), NEW_IDENTIFIER(CHILD(n, 2)));
             else
-                return alias(NEW_IDENTIFIER(CHILD(n, 0)),
-                             NULL);
+                result = alias(NEW_IDENTIFIER(CHILD(n, 0)), NULL);
             break;
         case dotted_as_name:
             if (NCH(n) == 1) {
@@ -2338,15 +2350,15 @@
                 goto loop;
             }
             else {
-                alias_ty a = alias_for_import_name(CHILD(n, 0));
-                assert(!a->asname);
-                a->asname = NEW_IDENTIFIER(CHILD(n, 2));
-                return a;
+                a = alias_for_import_name(CHILD(n, 0));
+                assert(!alias_asname(a));
+                alias_asname(a) = NEW_IDENTIFIER(CHILD(n, 2));
+                result = a;
             }
             break;
         case dotted_name:
             if (NCH(n) == 1)
-                return alias(NEW_IDENTIFIER(CHILD(n, 0)), NULL);
+                result = alias(NEW_IDENTIFIER(CHILD(n, 0)), NULL);
             else {
                 /* Create a string of the form "a.b.c" */
                 int i, len;
@@ -2360,10 +2372,10 @@
                 len--; /* the last name doesn't have a dot */
                 str = PyString_FromStringAndSize(NULL, len);
                 if (!str)
-                    return NULL;
+                    goto error;
                 s = PyString_AS_STRING(str);
                 if (!s)
-                    return NULL;
+                    goto error;
                 for (i = 0; i < NCH(n); i += 2) {
                     char *sch = STR(CHILD(n, i));
                     strcpy(s, STR(CHILD(n, i)));
@@ -2373,17 +2385,20 @@
                 --s;
                 *s = '\0';
                 PyString_InternInPlace(&str);
-                return alias(str, NULL);
+                result = alias(str, NULL);
             }
             break;
         case STAR:
-            return alias(PyString_InternFromString("*"), NULL);
+            result = alias(PyString_InternFromString("*"), NULL);
+            break;
         default:
             PyErr_Format(PyExc_SystemError,
                          "unexpected import name: %d", TYPE(n));
-            return NULL;
+            goto error;
     }
-    return NULL;
+ error:
+    if (result && PyAST_Validate(result) == -1) return NULL;
+    return result;
 }
 
 static PyObject*
@@ -2399,33 +2414,35 @@
     PyObject *result = NULL;
     int i;
     PyObject *aliases = NULL;
+    PyObject *mod = NULL;
+    PyObject *import = NULL;
+    PyObject *import_alias = NULL;
 
     REQ(n, import_stmt);
     n = CHILD(n, 0);
     if (STR(CHILD(n, 0))[0] == 'i') { /* import */
         n = CHILD(n, 1);
-	REQ(n, dotted_as_names);
-	aliases = asdl_seq_new((NCH(n) + 1) / 2);
-	if (!aliases)
-		return NULL;
-	for (i = 0; i < NCH(n); i += 2) {
-            alias_ty import_alias = alias_for_import_name(CHILD(n, i));
+        REQ(n, dotted_as_names);
+        aliases = PyList_New((NCH(n) + 1) / 2);
+        if (!aliases)
+                goto error;
+        for (i = 0; i < NCH(n); i += 2) {
+            import_alias = alias_for_import_name(CHILD(n, i));
             if (!import_alias) {
-                asdl_alias_seq_free(aliases);
-                return NULL;
+                goto error;
             }
-	    asdl_seq_SET(aliases, i / 2, import_alias);
+            STEAL_ITEM(aliases, i / 2, import_alias);
         }
-	return Import(aliases, LINENO(n));
+        result = Import(aliases, LINENO(n));
     }
     else if (STR(CHILD(n, 0))[0] == 'f') { /* from */
-	stmt_ty import;
         int n_children;
         const char *from_modules;
-	int lineno = LINENO(n);
-	alias_ty mod = alias_for_import_name(CHILD(n, 1));
-	if (!mod)
-            return NULL;
+        int lineno = LINENO(n);
+        int pos = 0;
+        mod = alias_for_import_name(CHILD(n, 1));
+        if (!mod)
+            goto error;
 
         /* XXX this needs to be cleaned up */
 
@@ -2434,10 +2451,9 @@
             n = CHILD(n, 3);                  /* from ... import x, y, z */
             if (NCH(n) % 2 == 0) {
                 /* it ends with a comma, not valid but the parser allows it */
-		free_alias(mod);
                 ast_error(n, "trailing comma not allowed without"
                              " surrounding parentheses");
-                return NULL;
+                goto error;
             }
         }
         else if (from_modules[0] == '*') {
@@ -2446,50 +2462,47 @@
         else if (from_modules[0] == '(')
             n = CHILD(n, 4);                  /* from ... import (x, y, z) */
         else {
-	    /* XXX: don't we need to call ast_error(n, "..."); */
-	    free_alias(mod);
-            return NULL;
-	}
+            /* XXX: don't we need to call ast_error(n, "..."); */
+            goto error;
+        }
 
         n_children = NCH(n);
         if (from_modules && from_modules[0] == '*')
             n_children = 1;
 
-	aliases = asdl_seq_new((n_children + 1) / 2);
-	if (!aliases) {
-            free_alias(mod);
-            return NULL;
-	}
+        aliases = PyList_New((n_children + 1) / 2);
+        if (!aliases) {
+            goto error;
+        }
 
         /* handle "from ... import *" special b/c there's no children */
         if (from_modules && from_modules[0] == '*') {
-            alias_ty import_alias = alias_for_import_name(n);
+            import_alias = alias_for_import_name(n);
             if (!import_alias) {
-                asdl_alias_seq_free(aliases);
-                free_alias(mod);
-                return NULL;
+                goto error;
             }
-	    asdl_seq_APPEND(aliases, import_alias);
+            PyList_SET_ITEM(aliases, pos++, import_alias);
         }
 
-	for (i = 0; i < NCH(n); i += 2) {
-            alias_ty import_alias = alias_for_import_name(CHILD(n, i));
+        for (i = 0; i < NCH(n); i += 2) {
+            import_alias = alias_for_import_name(CHILD(n, i));
             if (!import_alias) {
-                asdl_alias_seq_free(aliases);
-                free_alias(mod);
-                return NULL;
+                goto error;
             }
-	    asdl_seq_APPEND(aliases, import_alias);
+            PyList_SET_ITEM(aliases, pos++, import_alias);
         }
-        Py_INCREF(mod->name);
-	import = ImportFrom(mod->name, aliases, lineno);
-	free_alias(mod);
-	return import;
-    }
-    PyErr_Format(PyExc_SystemError,
-                 "unknown import statement: starts with command '%s'",
-                 STR(CHILD(n, 0)));
-    return NULL;
+        assert(pos == PyList_GET_SIZE(aliases));
+        Py_INCREF(alias_name(mod));
+        import = ImportFrom(alias_name(mod), aliases, lineno);
+        result = import;
+    }
+    else
+        PyErr_Format(PyExc_SystemError,
+                     "unknown import statement: starts with command '%s'",
+                     STR(CHILD(n, 0)));
+ error:
+    if (result && PyAST_Validate(result) == -1) return NULL;
+    return result;
 }
 
 static PyObject*
@@ -2497,56 +2510,60 @@
 {
     /* global_stmt: 'global' NAME (',' NAME)* */
     PyObject *result = NULL;
-    identifier name;
+    PyObject *name = NULL;
     PyObject *s = NULL;
     int i;
 
     REQ(n, global_stmt);
-    s = asdl_seq_new(NCH(n) / 2);
+    s = PyList_New(NCH(n) / 2);
     if (!s)
-    	return NULL;
+            goto error;
     for (i = 1; i < NCH(n); i += 2) {
-	name = NEW_IDENTIFIER(CHILD(n, i));
-	if (!name) {
-	    for (i = i / 2; i > 0; i--)
-                Py_XDECREF((identifier) asdl_seq_GET(s, i));
-	    asdl_seq_free(s); /* ok */
-	    return NULL;
-	}
-	asdl_seq_SET(s, i / 2, name);
+        name = NEW_IDENTIFIER(CHILD(n, i));
+        if (!name) {
+            goto error;
+        }
+        STEAL_ITEM(s, i / 2, name);
     }
-    return Global(s, LINENO(n));
+    result = Global(s, LINENO(n));
+ error:
+    if (result && PyAST_Validate(result) == -1) return NULL;
+    return result;
 }
 
 static PyObject*
 ast_for_exec_stmt(struct compiling *c, const node *n)
 {
-    expr_ty expr1, globals = NULL, locals = NULL;
+    PyObject *result = NULL;
+    PyObject *expr1 = NULL, *globals = NULL, *locals = NULL;
     int n_children = NCH(n);
     if (n_children != 2 && n_children != 4 && n_children != 6) {
         PyErr_Format(PyExc_SystemError,
                      "poorly formed 'exec' statement: %d parts to statement",
                      n_children);
-        return NULL;
+        goto error;
     }
 
     /* exec_stmt: 'exec' expr ['in' test [',' test]] */
     REQ(n, exec_stmt);
     expr1 = ast_for_expr(c, CHILD(n, 1));
     if (!expr1)
-        return NULL;
+        goto error;
     if (n_children >= 4) {
         globals = ast_for_expr(c, CHILD(n, 3));
         if (!globals)
-            return NULL;
+            goto error;
     }
     if (n_children == 6) {
         locals = ast_for_expr(c, CHILD(n, 5));
         if (!locals)
-            return NULL;
+            goto error;
     }
 
-    return Exec(expr1, globals, locals, LINENO(n));
+    result = Exec(expr1, globals, locals, LINENO(n));
+ error:
+    if (result && PyAST_Validate(result) == -1) return NULL;
+    return result;
 }
 
 static PyObject*
@@ -2554,94 +2571,97 @@
 {
     /* assert_stmt: 'assert' test [',' test] */
     PyObject *result = NULL;
+    PyObject *expression = NULL;
+    PyObject *expr1 = NULL;
+    PyObject *expr2 = NULL;
     REQ(n, assert_stmt);
     if (NCH(n) == 2) {
-        expr_ty expression = ast_for_expr(c, CHILD(n, 1));
+        expression = ast_for_expr(c, CHILD(n, 1));
         if (!expression)
-            return NULL;
-	return Assert(expression, NULL, LINENO(n));
+            goto error;
+        result = Assert(expression, NULL, LINENO(n));
     }
     else if (NCH(n) == 4) {
-        PyObject *expr1 = NULL; PyObject *expr2 = NULL;
-
         expr1 = ast_for_expr(c, CHILD(n, 1));
         if (!expr1)
-            return NULL;
+            goto error;
         expr2 = ast_for_expr(c, CHILD(n, 3));
         if (!expr2)
-            return NULL;
+            goto error;
             
-	return Assert(expr1, expr2, LINENO(n));
+        result = Assert(expr1, expr2, LINENO(n));
     }
-    PyErr_Format(PyExc_SystemError,
-                 "improper number of parts to 'assert' statement: %d",
-                 NCH(n));
-    return NULL;
+    else
+        PyErr_Format(PyExc_SystemError,
+                     "improper number of parts to 'assert' statement: %d",
+                     NCH(n));
+ error:
+    if (result && PyAST_Validate(result) == -1) return NULL;
+    return result;
 }
 
-static asdl_seq *
+static PyObject *
 ast_for_suite(struct compiling *c, const node *n)
 {
     /* suite: simple_stmt | NEWLINE INDENT stmt+ DEDENT */
-    asdl_seq *seq = NULL;
-    stmt_ty s;
+    PyObject *result = NULL;
+    PyObject *seq = NULL;
+    PyObject *s = NULL;
     int i, total, num, end, pos = 0;
     node *ch;
 
     REQ(n, suite);
 
     total = num_stmts(n);
-    seq = asdl_seq_new(total);
+    seq = PyList_New(total);
     if (!seq)
-    	return NULL;
+            goto error;
     if (TYPE(CHILD(n, 0)) == simple_stmt) {
-	n = CHILD(n, 0);
-	/* simple_stmt always ends with a NEWLINE,
-	   and may have a trailing SEMI 
-	*/
-	end = NCH(n) - 1;
-	if (TYPE(CHILD(n, end - 1)) == SEMI)
-	    end--;
+        n = CHILD(n, 0);
+        /* simple_stmt always ends with a NEWLINE,
+           and may have a trailing SEMI 
+        */
+        end = NCH(n) - 1;
+        if (TYPE(CHILD(n, end - 1)) == SEMI)
+            end--;
         /* loop by 2 to skip semi-colons */
-	for (i = 0; i < end; i += 2) {
-	    ch = CHILD(n, i);
-	    s = ast_for_stmt(c, ch);
-	    if (!s)
-		goto error;
-	    asdl_seq_SET(seq, pos++, s);
-	}
+        for (i = 0; i < end; i += 2) {
+            ch = CHILD(n, i);
+            s = ast_for_stmt(c, ch);
+            if (!s)
+                goto error;
+            STEAL_ITEM(seq, pos++, s);
+        }
     }
     else {
-	for (i = 2; i < (NCH(n) - 1); i++) {
-	    ch = CHILD(n, i);
-	    REQ(ch, stmt);
-	    num = num_stmts(ch);
-	    if (num == 1) {
-		/* small_stmt or compound_stmt with only one child */
-		s = ast_for_stmt(c, ch);
-		if (!s)
-		    goto error;
-		asdl_seq_SET(seq, pos++, s);
-	    }
-	    else {
-		int j;
-		ch = CHILD(ch, 0);
-		REQ(ch, simple_stmt);
-		for (j = 0; j < NCH(ch); j += 2) {
-		    s = ast_for_stmt(c, CHILD(ch, j));
-		    if (!s)
-			goto error;
-		    asdl_seq_SET(seq, pos++, s);
-		}
-	    }
-	}
+        for (i = 2; i < (NCH(n) - 1); i++) {
+            ch = CHILD(n, i);
+            REQ(ch, stmt);
+            num = num_stmts(ch);
+            if (num == 1) {
+                /* small_stmt or compound_stmt with only one child */
+                s = ast_for_stmt(c, ch);
+                if (!s)
+                    goto error;
+                STEAL_ITEM(seq, pos++, s);
+            }
+            else {
+                int j;
+                ch = CHILD(ch, 0);
+                REQ(ch, simple_stmt);
+                for (j = 0; j < NCH(ch); j += 2) {
+                    s = ast_for_stmt(c, CHILD(ch, j));
+                    if (!s)
+                        goto error;
+                    STEAL_ITEM(seq, pos++, s);
+                }
+            }
+        }
     }
-    assert(pos == seq->size);
-    return seq;
+    assert(pos == PyList_GET_SIZE(seq));
+    result = seq;
  error:
-    if (seq)
-	asdl_stmt_seq_free(seq);
-    return NULL;
+    return result;
 }
 
 static PyObject*
@@ -2651,135 +2671,116 @@
        ['else' ':' suite]
     */
     PyObject *result = NULL;
+    PyObject *expression = NULL;
+    PyObject *suite_seq = NULL;
+    PyObject *seq1 = NULL;
+    PyObject *seq2 = NULL;
+    PyObject *orelse = NULL;
+    PyObject *new = NULL;
     char *s;
 
     REQ(n, if_stmt);
 
     if (NCH(n) == 4) {
-        PyObject *expression = NULL;
-        PyObject *suite_seq = NULL;
-
         expression = ast_for_expr(c, CHILD(n, 1));
         if (!expression)
-            return NULL;
+            goto error;
         suite_seq = ast_for_suite(c, CHILD(n, 3)); 
         if (!suite_seq) {
-	    free_expr(expression);
-            return NULL;
-	}
+            goto error;
+        }
             
-	return If(expression, suite_seq, NULL, LINENO(n));
-    }
-    s = STR(CHILD(n, 4));
-    /* s[2], the third character in the string, will be
-       's' for el_s_e, or
-       'i' for el_i_f
-    */
-    if (s[2] == 's') {
-        PyObject *expression = NULL;
-        PyObject *seq1 = NULL; PyObject *seq2 = NULL;
-
-        expression = ast_for_expr(c, CHILD(n, 1));
-        if (!expression)
-            return NULL;
-        seq1 = ast_for_suite(c, CHILD(n, 3));
-        if (!seq1) {
-	    free_expr(expression);
-            return NULL;
-	}
-        seq2 = ast_for_suite(c, CHILD(n, 6));
-        if (!seq2) {
-	    asdl_stmt_seq_free(seq1);
-	    free_expr(expression);
-            return NULL;
-	}
-
-	return If(expression, seq1, seq2, LINENO(n));
+        result = If(expression, suite_seq, NULL, LINENO(n));
     }
-    else if (s[2] == 'i') {
-	int i, n_elif, has_else = 0;
-	asdl_seq *orelse = NULL;
-	n_elif = NCH(n) - 4;
-        /* must reference the child n_elif+1 since 'else' token is third,
-           not fourth, child from the end. */
-	if (TYPE(CHILD(n, (n_elif + 1))) == NAME
-	    && STR(CHILD(n, (n_elif + 1)))[2] == 's') {
-	    has_else = 1;
-	    n_elif -= 3;
-	}
-	n_elif /= 4;
-
-	if (has_else) {
-            PyObject *expression = NULL;
-            PyObject *seq1 = NULL; PyObject *seq2 = NULL;
-
-	    orelse = asdl_seq_new(1);
-	    if (!orelse)
-		return NULL;
-            expression = ast_for_expr(c, CHILD(n, NCH(n) - 6));
-            if (!expression) {
-                asdl_seq_free(orelse); /* ok */
-                return NULL;
-            }
-            seq1 = ast_for_suite(c, CHILD(n, NCH(n) - 4));
+    else {
+        s = STR(CHILD(n, 4));
+        /* s[2], the third character in the string, will be
+           's' for el_s_e, or
+           'i' for el_i_f
+        */
+        if (s[2] == 's') {
+            expression = ast_for_expr(c, CHILD(n, 1));
+            if (!expression)
+                goto error;
+            seq1 = ast_for_suite(c, CHILD(n, 3));
             if (!seq1) {
-                free_expr(expression);
-                asdl_seq_free(orelse); /* ok */
-                return NULL;
+                goto error;
             }
-            seq2 = ast_for_suite(c, CHILD(n, NCH(n) - 1));
+            seq2 = ast_for_suite(c, CHILD(n, 6));
             if (!seq2) {
-                free_expr(expression);
-                asdl_stmt_seq_free(seq1);
-                asdl_seq_free(orelse); /* ok */
-                return NULL;
+                goto error;
             }
-
-	    asdl_seq_SET(orelse, 0, If(expression, seq1, seq2, 
-				       LINENO(CHILD(n, NCH(n) - 6))));
-	    /* the just-created orelse handled the last elif */
-	    n_elif--;
-	}
-        else
-            orelse  = NULL;
-
-	for (i = 0; i < n_elif; i++) {
-	    int off = 5 + (n_elif - i - 1) * 4;
-            PyObject *expression = NULL;
-            PyObject *suite_seq = NULL;
-	    asdl_seq *new = asdl_seq_new(1);
-	    if (!new) {
-		asdl_stmt_seq_free(orelse);
-		return NULL;
-	    }
-            expression = ast_for_expr(c, CHILD(n, off));
-            if (!expression) {
-		asdl_stmt_seq_free(orelse);
-                asdl_seq_free(new); /* ok */
-                return NULL;
+    
+            result = If(expression, seq1, seq2, LINENO(n));
+        }
+        else if (s[2] == 'i') {
+            int i, n_elif, has_else = 0;
+            n_elif = NCH(n) - 4;
+            /* must reference the child n_elif+1 since 'else' token is third,
+               not fourth, child from the end. */
+            if (TYPE(CHILD(n, (n_elif + 1))) == NAME
+                && STR(CHILD(n, (n_elif + 1)))[2] == 's') {
+                has_else = 1;
+                n_elif -= 3;
             }
-            suite_seq = ast_for_suite(c, CHILD(n, off + 2));
-            if (!suite_seq) {
-		asdl_stmt_seq_free(orelse);
-	        free_expr(expression);
-                asdl_seq_free(new); /* ok */
-                return NULL;
+            n_elif /= 4;
+    
+            if (has_else) {
+    
+                orelse = PyList_New(1);
+                if (!orelse)
+                    goto error;
+                expression = ast_for_expr(c, CHILD(n, NCH(n) - 6));
+                if (!expression) {
+                    goto error;
+                }
+                seq1 = ast_for_suite(c, CHILD(n, NCH(n) - 4));
+                if (!seq1) {
+                    goto error;
+                }
+                seq2 = ast_for_suite(c, CHILD(n, NCH(n) - 1));
+                if (!seq2) {
+                    goto error;
+                }
+    
+                PyList_SET_ITEM(orelse, 0, If(expression, seq1, seq2, LINENO(CHILD(n, NCH(n) - 6))));
+                /* the just-created orelse handled the last elif */
+                n_elif--;
             }
-
-	    asdl_seq_SET(new, 0,
-			 If(expression, suite_seq, orelse, 
-			    LINENO(CHILD(n, off))));
-	    orelse = new;
-	}
-	return If(ast_for_expr(c, CHILD(n, 1)),
-		  ast_for_suite(c, CHILD(n, 3)),
-		  orelse, LINENO(n));
-    }
-    else {
-        PyErr_Format(PyExc_SystemError,
-                     "unexpected token in 'if' statement: %s", s);
-        return NULL;
+            else
+                orelse  = NULL;
+    
+            for (i = 0; i < n_elif; i++) {
+                int off = 5 + (n_elif - i - 1) * 4;
+                new = PyList_New(1);
+                if (!new) {
+                    goto error;
+                }
+                expression = ast_for_expr(c, CHILD(n, off));
+                if (!expression) {
+                    goto error;
+                }
+                suite_seq = ast_for_suite(c, CHILD(n, off + 2));
+                if (!suite_seq) {
+                    goto error;
+                }
+    
+                PyList_SET_ITEM(new, 0, If(expression, suite_seq, orelse, LINENO(CHILD(n, off))));
+                orelse = new;
+            }
+            result = If(ast_for_expr(c, CHILD(n, 1)),
+                      ast_for_suite(c, CHILD(n, 3)),
+                      orelse, LINENO(n));
+        }
+        else {
+            PyErr_Format(PyExc_SystemError,
+                         "unexpected token in 'if' statement: %s", s);
+            goto error;
+        }
     }
+ error:
+    if (result && PyAST_Validate(result) == -1) return NULL;
+    return result;
 }
 
 static PyObject*
@@ -2787,94 +2788,91 @@
 {
     /* while_stmt: 'while' test ':' suite ['else' ':' suite] */
     PyObject *result = NULL;
+    PyObject *expression = NULL;
+    PyObject *suite_seq = NULL;
+    PyObject *seq1 = NULL;
+    PyObject *seq2 = NULL;
     REQ(n, while_stmt);
 
     if (NCH(n) == 4) {
-        PyObject *expression = NULL;
-        PyObject *suite_seq = NULL;
 
         expression = ast_for_expr(c, CHILD(n, 1));
         if (!expression)
-            return NULL;
+            goto error;
         suite_seq = ast_for_suite(c, CHILD(n, 3));
         if (!suite_seq) {
-	    free_expr(expression);
-            return NULL;
-	}
-	return While(expression, suite_seq, NULL, LINENO(n));
+            goto error;
+        }
+        result = While(expression, suite_seq, NULL, LINENO(n));
     }
     else if (NCH(n) == 7) {
-        PyObject *expression = NULL;
-        PyObject *seq1 = NULL; PyObject *seq2 = NULL;
 
         expression = ast_for_expr(c, CHILD(n, 1));
         if (!expression)
-            return NULL;
+            goto error;
         seq1 = ast_for_suite(c, CHILD(n, 3));
         if (!seq1) {
-	    free_expr(expression);
-            return NULL;
-	}
+            goto error;
+        }
         seq2 = ast_for_suite(c, CHILD(n, 6));
         if (!seq2) {
-	    asdl_stmt_seq_free(seq1);
-	    free_expr(expression);
-            return NULL;
-	}
+            goto error;
+        }
 
-	return While(expression, seq1, seq2, LINENO(n));
+        result = While(expression, seq1, seq2, LINENO(n));
     }
     else {
         PyErr_Format(PyExc_SystemError,
                      "wrong number of tokens for 'while' statement: %d",
                      NCH(n));
-        return NULL;
+        goto error;
     }
+ error:
+    if (result && PyAST_Validate(result) == -1) return NULL;
+    return result;
 }
 
 static PyObject*
 ast_for_for_stmt(struct compiling *c, const node *n)
 {
     PyObject *result = NULL;
-    asdl_seq *_target = NULL, *seq = NULL, *suite_seq = NULL;
+    PyObject *_target = NULL;
+    PyObject *seq = NULL;
+    PyObject *suite_seq = NULL;
     PyObject *expression = NULL;
     PyObject *target = NULL;
     /* for_stmt: 'for' exprlist 'in' testlist ':' suite ['else' ':' suite] */
     REQ(n, for_stmt);
 
     if (NCH(n) == 9) {
-	seq = ast_for_suite(c, CHILD(n, 8));
+        seq = ast_for_suite(c, CHILD(n, 8));
         if (!seq)
-            return NULL;
+            goto error;
     }
 
-    _target = ast_for_exprlist(c, CHILD(n, 1), Store);
+    _target = ast_for_exprlist(c, CHILD(n, 1), Store());
     if (!_target) {
-	asdl_stmt_seq_free(seq);
-        return NULL;
+        goto error;
     }
-    if (asdl_seq_LEN(_target) == 1) {
-	target = asdl_seq_GET(_target, 0);
-	asdl_seq_free(_target); /* ok */
+    if (PyList_GET_SIZE(_target) == 1) {
+        target = PyList_GET_ITEM(_target, 0);
     }
     else
-	target = Tuple(_target, Store, LINENO(n));
+        target = Tuple(_target, Store(), LINENO(n));
 
     expression = ast_for_testlist(c, CHILD(n, 3));
     if (!expression) {
-	free_expr(target);
-	asdl_stmt_seq_free(seq);
-        return NULL;
+        goto error;
     }
     suite_seq = ast_for_suite(c, CHILD(n, 5));
     if (!suite_seq) {
-	free_expr(target);
-	free_expr(expression);
-	asdl_stmt_seq_free(seq);
-        return NULL;
+        goto error;
     }
 
-    return For(target, expression, suite_seq, seq, LINENO(n));
+    result = For(target, expression, suite_seq, seq, LINENO(n));
+ error:
+    if (result && PyAST_Validate(result) == -1) return NULL;
+    return result;
 }
 
 static PyObject*
@@ -2882,137 +2880,127 @@
 {
     /* except_clause: 'except' [test [',' test]] */
     PyObject *result = NULL;
+    PyObject *suite_seq = NULL;
+    PyObject *expression = NULL;
+    PyObject *e = NULL;
     REQ(exc, except_clause);
     REQ(body, suite);
 
     if (NCH(exc) == 1) {
-        asdl_seq *suite_seq = ast_for_suite(c, body);
+        suite_seq = ast_for_suite(c, body);
         if (!suite_seq)
-            return NULL;
+            goto error;
 
-	return excepthandler(NULL, NULL, suite_seq);
+        result = excepthandler(NULL, NULL, suite_seq);
     }
     else if (NCH(exc) == 2) {
-        PyObject *expression = NULL;
-        PyObject *suite_seq = NULL;
 
         expression = ast_for_expr(c, CHILD(exc, 1));
         if (!expression)
-            return NULL;
+            goto error;
         suite_seq = ast_for_suite(c, body);
         if (!suite_seq) {
-	    free_expr(expression);
-            return NULL;
-	}
+            goto error;
+        }
 
-	return excepthandler(expression, NULL, suite_seq);
+        result = excepthandler(expression, NULL, suite_seq);
     }
     else if (NCH(exc) == 4) {
-        PyObject *suite_seq = NULL;
-        PyObject *expression = NULL;
-	expr_ty e = ast_for_expr(c, CHILD(exc, 3));
-	if (!e)
-            return NULL;
-	if (!set_context(e, Store, CHILD(exc, 3))) {
-	    free_expr(e);
-            return NULL;
-	}
+        e = ast_for_expr(c, CHILD(exc, 3));
+        if (!e)
+            goto error;
+        if (!set_context(e, Store(), CHILD(exc, 3))) {
+            goto error;
+        }
         expression = ast_for_expr(c, CHILD(exc, 1));
         if (!expression) {
-	    free_expr(e);
-            return NULL;
-	}
+            goto error;
+        }
         suite_seq = ast_for_suite(c, body);
         if (!suite_seq) {
-	    free_expr(expression);
-	    free_expr(e);
-            return NULL;
-	}
+            goto error;
+        }
 
-	return excepthandler(expression, e, suite_seq);
+        result = excepthandler(expression, e, suite_seq);
     }
     else {
         PyErr_Format(PyExc_SystemError,
                      "wrong number of children for 'except' clause: %d",
                      NCH(exc));
-        return NULL;
+        goto error;
     }
+ error:
+    if (result && PyAST_Validate(result) == -1) return NULL;
+    return result;
 }
 
 static PyObject*
 ast_for_try_stmt(struct compiling *c, const node *n)
 {
+    PyObject *e = NULL;
+    PyObject *s1 = NULL;
+    PyObject *s2 = NULL;
+    PyObject *suite_seq1 = NULL;
+    PyObject *suite_seq2 = NULL;
+    PyObject *handlers = NULL;
     PyObject *result = NULL;
     REQ(n, try_stmt);
 
     if (TYPE(CHILD(n, 3)) == NAME) {/* must be 'finally' */
-	/* try_stmt: 'try' ':' suite 'finally' ':' suite) */
-        PyObject *s1 = NULL; PyObject *s2 = NULL;
+        /* try_stmt: 'try' ':' suite 'finally' ':' suite) */
         s1 = ast_for_suite(c, CHILD(n, 2));
         if (!s1)
-            return NULL;
+            goto error;
         s2 = ast_for_suite(c, CHILD(n, 5));
         if (!s2) {
-	    asdl_stmt_seq_free(s1);
-            return NULL;
-	}
+            goto error;
+        }
             
-	return TryFinally(s1, s2, LINENO(n));
+        result = TryFinally(s1, s2, LINENO(n));
     }
     else if (TYPE(CHILD(n, 3)) == except_clause) {
-	/* try_stmt: ('try' ':' suite (except_clause ':' suite)+
+        /* try_stmt: ('try' ':' suite (except_clause ':' suite)+
            ['else' ':' suite]
-	*/
-        PyObject *suite_seq1 = NULL; PyObject *suite_seq2 = NULL;
-	PyObject *handlers = NULL;
-	int i, has_else = 0, n_except = NCH(n) - 3;
-	if (TYPE(CHILD(n, NCH(n) - 3)) == NAME) {
-	    has_else = 1;
-	    n_except -= 3;
-	}
-	n_except /= 3;
-	handlers = asdl_seq_new(n_except);
-	if (!handlers)
-		return NULL;
-	for (i = 0; i < n_except; i++) {
-            excepthandler_ty e = ast_for_except_clause(c,
-                                                       CHILD(n, 3 + i * 3),
-                                                       CHILD(n, 5 + i * 3));
+        */
+        int i, has_else = 0, n_except = NCH(n) - 3;
+        if (TYPE(CHILD(n, NCH(n) - 3)) == NAME) {
+            has_else = 1;
+            n_except -= 3;
+        }
+        n_except /= 3;
+        handlers = PyList_New(n_except);
+        if (!handlers)
+                goto error;
+        for (i = 0; i < n_except; i++) {
+            e = ast_for_except_clause(c, CHILD(n, 3 + i * 3), CHILD(n, 5 + i * 3));
             if (!e) {
-		for ( ; i >= 0; i--)
-		    free_excepthandler(asdl_seq_GET(handlers, i));
-	        asdl_seq_free(handlers); /* ok */
-                return NULL;
-	    }
-	    asdl_seq_SET(handlers, i, e);
+                goto error;
+            }
+            STEAL_ITEM(handlers, i, e);
         }
 
         suite_seq1 = ast_for_suite(c, CHILD(n, 2));
         if (!suite_seq1) {
-	    for (i = 0; i < asdl_seq_LEN(handlers); i++)
-		free_excepthandler(asdl_seq_GET(handlers, i));
-	    asdl_seq_free(handlers); /* ok */
-            return NULL;
-	}
+            goto error;
+        }
         if (has_else) {
             suite_seq2 = ast_for_suite(c, CHILD(n, NCH(n) - 1));
             if (!suite_seq2) {
-	        for (i = 0; i < asdl_seq_LEN(handlers); i++)
-		    free_excepthandler(asdl_seq_GET(handlers, i));
-	        asdl_seq_free(handlers); /* ok */
-		asdl_stmt_seq_free(suite_seq1);
-                return NULL;
-	    }
+                goto error;
+            }
         }
         else
             suite_seq2 = NULL;
 
-	return TryExcept(suite_seq1, handlers, suite_seq2, LINENO(n));
+        result = TryExcept(suite_seq1, handlers, suite_seq2, LINENO(n));
     }
     else {
         ast_error(n, "malformed 'try' statement");
-        return NULL;
+        goto error;
     }
+ error:
+    if (result && PyAST_Validate(result) == -1) return NULL;
+    return result;
 }
 
 static PyObject*
@@ -3025,35 +3013,38 @@
     REQ(n, classdef);
 
     if (!strcmp(STR(CHILD(n, 1)), "None")) {
-	    ast_error(n, "assignment to None");
-	    return NULL;
+            ast_error(n, "assignment to None");
+            goto error;
     }
 
     if (NCH(n) == 4) {
         s = ast_for_suite(c, CHILD(n, 3));
         if (!s)
-            return NULL;
-	return ClassDef(NEW_IDENTIFIER(CHILD(n, 1)), NULL, s, LINENO(n));
+            goto error;
+        result = ClassDef(NEW_IDENTIFIER(CHILD(n, 1)), NULL, s, LINENO(n));
     }
     /* check for empty base list */
-    if (TYPE(CHILD(n,3)) == RPAR) {
-	s = ast_for_suite(c, CHILD(n,5));
-	if (!s)
-		return NULL;
-	return ClassDef(NEW_IDENTIFIER(CHILD(n, 1)), NULL, s, LINENO(n));
+    else if (TYPE(CHILD(n,3)) == RPAR) {
+        s = ast_for_suite(c, CHILD(n,5));
+        if (!s)
+                goto error;
+        result = ClassDef(NEW_IDENTIFIER(CHILD(n, 1)), NULL, s, LINENO(n));
     }
-
-    /* else handle the base class list */
-    bases = ast_for_class_bases(c, CHILD(n, 3));
-    if (!bases)
-        return NULL;
-
-    s = ast_for_suite(c, CHILD(n, 6));
-    if (!s) {
-        asdl_expr_seq_free(bases);
-        return NULL;
+    else {
+        /* else handle the base class list */
+        bases = ast_for_class_bases(c, CHILD(n, 3));
+        if (!bases)
+            goto error;
+    
+        s = ast_for_suite(c, CHILD(n, 6));
+        if (!s) {
+            goto error;
+        }
+        result = ClassDef(NEW_IDENTIFIER(CHILD(n, 1)), bases, s, LINENO(n));
     }
-    return ClassDef(NEW_IDENTIFIER(CHILD(n, 1)), bases, s, LINENO(n));
+ error:
+    if (result && PyAST_Validate(result) == -1) return NULL;
+    return result;
 }
 
 static PyObject*
@@ -3061,211 +3052,231 @@
 {
     PyObject *result = NULL;
     if (TYPE(n) == stmt) {
-	assert(NCH(n) == 1);
-	n = CHILD(n, 0);
+        assert(NCH(n) == 1);
+        n = CHILD(n, 0);
     }
     if (TYPE(n) == simple_stmt) {
-	assert(num_stmts(n) == 1);
-	n = CHILD(n, 0);
+        assert(num_stmts(n) == 1);
+        n = CHILD(n, 0);
     }
     if (TYPE(n) == small_stmt) {
-	REQ(n, small_stmt);
-	n = CHILD(n, 0);
-	/* small_stmt: expr_stmt | print_stmt  | del_stmt | pass_stmt
-	             | flow_stmt | import_stmt | global_stmt | exec_stmt
+        REQ(n, small_stmt);
+        n = CHILD(n, 0);
+        /* small_stmt: expr_stmt | print_stmt  | del_stmt | pass_stmt
+                     | flow_stmt | import_stmt | global_stmt | exec_stmt
                      | assert_stmt
-	*/
-	switch (TYPE(n)) {
+        */
+        switch (TYPE(n)) {
             case expr_stmt:
-                return ast_for_expr_stmt(c, n);
+                result = ast_for_expr_stmt(c, n);
+                break;
             case print_stmt:
-                return ast_for_print_stmt(c, n);
+                result = ast_for_print_stmt(c, n);
+                break;
             case del_stmt:
-                return ast_for_del_stmt(c, n);
+                result = ast_for_del_stmt(c, n);
+                break;
             case pass_stmt:
-                return Pass(LINENO(n));
+                result = Pass(LINENO(n));
+                break;
             case flow_stmt:
-                return ast_for_flow_stmt(c, n);
+                result = ast_for_flow_stmt(c, n);
+                break;
             case import_stmt:
-                return ast_for_import_stmt(c, n);
+                result = ast_for_import_stmt(c, n);
+                break;
             case global_stmt:
-                return ast_for_global_stmt(c, n);
+                result = ast_for_global_stmt(c, n);
+                break;
             case exec_stmt:
-                return ast_for_exec_stmt(c, n);
+                result = ast_for_exec_stmt(c, n);
+                break;
             case assert_stmt:
-                return ast_for_assert_stmt(c, n);
+                result = ast_for_assert_stmt(c, n);
+                break;
             default:
                 PyErr_Format(PyExc_SystemError,
                              "unhandled small_stmt: TYPE=%d NCH=%d\n",
                              TYPE(n), NCH(n));
-                return NULL;
+                goto error;
         }
     }
     else {
         /* compound_stmt: if_stmt | while_stmt | for_stmt | try_stmt
-	                | funcdef | classdef
-	*/
-	node *ch = CHILD(n, 0);
-	REQ(n, compound_stmt);
-	switch (TYPE(ch)) {
+                        | funcdef | classdef
+        */
+        node *ch = CHILD(n, 0);
+        REQ(n, compound_stmt);
+        switch (TYPE(ch)) {
             case if_stmt:
-                return ast_for_if_stmt(c, ch);
+                result = ast_for_if_stmt(c, ch);
+                break;
             case while_stmt:
-                return ast_for_while_stmt(c, ch);
+                result = ast_for_while_stmt(c, ch);
+                break;
             case for_stmt:
-                return ast_for_for_stmt(c, ch);
+                result = ast_for_for_stmt(c, ch);
+                break;
             case try_stmt:
-                return ast_for_try_stmt(c, ch);
+                result = ast_for_try_stmt(c, ch);
+                break;
             case funcdef:
-                return ast_for_funcdef(c, ch);
+                result = ast_for_funcdef(c, ch);
+                break;
             case classdef:
-                return ast_for_classdef(c, ch);
+                result = ast_for_classdef(c, ch);
+                break;
             default:
                 PyErr_Format(PyExc_SystemError,
                              "unhandled small_stmt: TYPE=%d NCH=%d\n",
                              TYPE(n), NCH(n));
-                return NULL;
-	}
+                goto error;
+        }
     }
+ error:
+    if (result && PyAST_Validate(result) == -1) return NULL;
+    return result;
 }
 
+/* ------------ ALL GOOD BELOW ----------------------- */
+
 static PyObject *
 parsenumber(const char *s)
 {
-	PyObject *result = NULL;
-	const char *end;
-	long x;
-	double dx;
+        PyObject *result = NULL;
+        const char *end;
+        long x;
+        double dx;
 #ifndef WITHOUT_COMPLEX
-	Py_complex c;
-	int imflag;
+        Py_complex c;
+        int imflag;
 #endif
 
-	errno = 0;
-	end = s + strlen(s) - 1;
+        errno = 0;
+        end = s + strlen(s) - 1;
 #ifndef WITHOUT_COMPLEX
-	imflag = *end == 'j' || *end == 'J';
+        imflag = *end == 'j' || *end == 'J';
 #endif
-	if (*end == 'l' || *end == 'L')
-		return PyLong_FromString((char *)s, (char **)0, 0);
-	if (s[0] == '0') {
-		x = (long) PyOS_strtoul((char *)s, (char **)&end, 0);
- 		if (x < 0 && errno == 0) {
-	 			return PyLong_FromString((char *)s,
-							 (char **)0,
-							 0);
-		}
-	}
-	else
-		x = PyOS_strtol((char *)s, (char **)&end, 0);
-	if (*end == '\0') {
-		if (errno != 0)
-			return PyLong_FromString((char *)s, (char **)0, 0);
-		return PyInt_FromLong(x);
-	}
-	/* XXX Huge floats may silently fail */
+        if (*end == 'l' || *end == 'L')
+                return PyLong_FromString((char *)s, (char **)0, 0);
+        if (s[0] == '0') {
+                x = (long) PyOS_strtoul((char *)s, (char **)&end, 0);
+                 if (x < 0 && errno == 0) {
+                                 return PyLong_FromString((char *)s,
+                                                         (char **)0,
+                                                         0);
+                }
+        }
+        else
+                x = PyOS_strtol((char *)s, (char **)&end, 0);
+        if (*end == '\0') {
+                if (errno != 0)
+                        return PyLong_FromString((char *)s, (char **)0, 0);
+                return PyInt_FromLong(x);
+        }
+        /* XXX Huge floats may silently fail */
 #ifndef WITHOUT_COMPLEX
-	if (imflag) {
-		c.real = 0.;
-		PyFPE_START_PROTECT("atof", return 0)
-		c.imag = atof(s);
-		PyFPE_END_PROTECT(c)
-		return PyComplex_FromCComplex(c);
-	}
-	else
+        if (imflag) {
+                c.real = 0.;
+                PyFPE_START_PROTECT("atof", return 0)
+                c.imag = atof(s);
+                PyFPE_END_PROTECT(c)
+                return PyComplex_FromCComplex(c);
+        }
+        else
 #endif
-	{
-		PyFPE_START_PROTECT("atof", return 0)
-		dx = atof(s);
-		PyFPE_END_PROTECT(dx)
-		return PyFloat_FromDouble(dx);
-	}
+        {
+                PyFPE_START_PROTECT("atof", return 0)
+                dx = atof(s);
+                PyFPE_END_PROTECT(dx)
+                return PyFloat_FromDouble(dx);
+        }
 }
 
 static PyObject *
 decode_utf8(const char **sPtr, const char *end, char* encoding)
 {
-	PyObject *result = NULL;
+        PyObject *result = NULL;
 #ifndef Py_USING_UNICODE
-	Py_FatalError("decode_utf8 should not be called in this build.");
-        return NULL;
+        Py_FatalError("decode_utf8 should not be called in this build.");
+        goto error;
 #else
-	PyObject *u, *v;
-	char *s, *t;
-	t = s = (char *)*sPtr;
-	/* while (s < end && *s != '\\') s++; */ /* inefficient for u".." */
-	while (s < end && (*s & 0x80)) s++;
-	*sPtr = s;
-	u = PyUnicode_DecodeUTF8(t, s - t, NULL);
-	if (u == NULL)
-		return NULL;
-	v = PyUnicode_AsEncodedString(u, encoding, NULL);
-	Py_DECREF(u);
-	return v;
+        PyObject *u, *v;
+        char *s, *t;
+        t = s = (char *)*sPtr;
+        /* while (s < end && *s != '\\') s++; */ /* inefficient for u".." */
+        while (s < end && (*s & 0x80)) s++;
+        *sPtr = s;
+        u = PyUnicode_DecodeUTF8(t, s - t, NULL);
+        if (u == NULL)
+                return NULL;
+        v = PyUnicode_AsEncodedString(u, encoding, NULL);
+        Py_DECREF(u);
+        return v;
 #endif
 }
 
 static PyObject *
 decode_unicode(const char *s, size_t len, int rawmode, const char *encoding)
 {
-	PyObject *result = NULL;
-	PyObject *v, *u;
-	char *buf;
-	char *p;
-	const char *end;
-	if (encoding == NULL) {
-	     	buf = (char *)s;
-		u = NULL;
-	} else if (strcmp(encoding, "iso-8859-1") == 0) {
-	     	buf = (char *)s;
-		u = NULL;
-	} else {
-		/* "\XX" may become "\u005c\uHHLL" (12 bytes) */
-		u = PyString_FromStringAndSize((char *)NULL, len * 4);
-		if (u == NULL)
-			return NULL;
-		p = buf = PyString_AsString(u);
-		end = s + len;
-		while (s < end) {
-			if (*s == '\\') {
-				*p++ = *s++;
-				if (*s & 0x80) {
-					strcpy(p, "u005c");
-					p += 5;
-				}
-			}
-			if (*s & 0x80) { /* XXX inefficient */
-				PyObject *w;
-				char *r;
-				int rn, i;
-				w = decode_utf8(&s, end, "utf-16-be");
-				if (w == NULL) {
-					Py_DECREF(u);
-					return NULL;
-				}
-				r = PyString_AsString(w);
-				rn = PyString_Size(w);
-				assert(rn % 2 == 0);
-				for (i = 0; i < rn; i += 2) {
-					sprintf(p, "\\u%02x%02x",
-						r[i + 0] & 0xFF,
-						r[i + 1] & 0xFF);
-					p += 6;
-				}
-				Py_DECREF(w);
-			} else {
-				*p++ = *s++;
-			}
-		}
-		len = p - buf;
-		s = buf;
-	}
-	if (rawmode)
-		v = PyUnicode_DecodeRawUnicodeEscape(s, len, NULL);
-	else
-		v = PyUnicode_DecodeUnicodeEscape(s, len, NULL);
-	Py_XDECREF(u);
-	return v;
+        PyObject *result = NULL;
+        PyObject *v, *u;
+        char *buf;
+        char *p;
+        const char *end;
+        if (encoding == NULL) {
+                     buf = (char *)s;
+                u = NULL;
+        } else if (strcmp(encoding, "iso-8859-1") == 0) {
+                     buf = (char *)s;
+                u = NULL;
+        } else {
+                /* "\XX" may become "\u005c\uHHLL" (12 bytes) */
+                u = PyString_FromStringAndSize((char *)NULL, len * 4);
+                if (u == NULL)
+                        return NULL;
+                p = buf = PyString_AsString(u);
+                end = s + len;
+                while (s < end) {
+                        if (*s == '\\') {
+                                *p++ = *s++;
+                                if (*s & 0x80) {
+                                        strcpy(p, "u005c");
+                                        p += 5;
+                                }
+                        }
+                        if (*s & 0x80) { /* XXX inefficient */
+                                PyObject *w;
+                                char *r;
+                                int rn, i;
+                                w = decode_utf8(&s, end, "utf-16-be");
+                                if (w == NULL) {
+                                        Py_DECREF(u);
+                                        return NULL;
+                                }
+                                r = PyString_AsString(w);
+                                rn = PyString_Size(w);
+                                assert(rn % 2 == 0);
+                                for (i = 0; i < rn; i += 2) {
+                                        sprintf(p, "\\u%02x%02x",
+                                                r[i + 0] & 0xFF,
+                                                r[i + 1] & 0xFF);
+                                        p += 6;
+                                }
+                                Py_DECREF(w);
+                        } else {
+                                *p++ = *s++;
+                        }
+                }
+                len = p - buf;
+                s = buf;
+        }
+        if (rawmode)
+                v = PyUnicode_DecodeRawUnicodeEscape(s, len, NULL);
+        else
+                v = PyUnicode_DecodeUnicodeEscape(s, len, NULL);
+        Py_XDECREF(u);
+        return v;
 }
 
 /* s is a Python string literal, including the bracketing quote characters,
@@ -3275,77 +3286,77 @@
 static PyObject *
 parsestr(const char *s, const char *encoding)
 {
-	PyObject *result = NULL;
-	PyObject *v;
-	size_t len;
-	int quote = *s;
-	int rawmode = 0;
-	int need_encoding;
-	int unicode = 0;
-
-	if (isalpha(quote) || quote == '_') {
-		if (quote == 'u' || quote == 'U') {
-			quote = *++s;
-			unicode = 1;
-		}
-		if (quote == 'r' || quote == 'R') {
-			quote = *++s;
-			rawmode = 1;
-		}
-	}
-	if (quote != '\'' && quote != '\"') {
-		PyErr_BadInternalCall();
-		return NULL;
-	}
-	s++;
-	len = strlen(s);
-	if (len > INT_MAX) {
-		PyErr_SetString(PyExc_OverflowError, 
-				"string to parse is too long");
-		return NULL;
-	}
-	if (s[--len] != quote) {
-		PyErr_BadInternalCall();
-		return NULL;
-	}
-	if (len >= 4 && s[0] == quote && s[1] == quote) {
-		s += 2;
-		len -= 2;
-		if (s[--len] != quote || s[--len] != quote) {
-			PyErr_BadInternalCall();
-			return NULL;
-		}
-	}
+        PyObject *result = NULL;
+        PyObject *v;
+        size_t len;
+        int quote = *s;
+        int rawmode = 0;
+        int need_encoding;
+        int unicode = 0;
+
+        if (isalpha(quote) || quote == '_') {
+                if (quote == 'u' || quote == 'U') {
+                        quote = *++s;
+                        unicode = 1;
+                }
+                if (quote == 'r' || quote == 'R') {
+                        quote = *++s;
+                        rawmode = 1;
+                }
+        }
+        if (quote != '\'' && quote != '\"') {
+                PyErr_BadInternalCall();
+                return NULL;
+        }
+        s++;
+        len = strlen(s);
+        if (len > INT_MAX) {
+                PyErr_SetString(PyExc_OverflowError, 
+                                "string to parse is too long");
+                return NULL;
+        }
+        if (s[--len] != quote) {
+                PyErr_BadInternalCall();
+                return NULL;
+        }
+        if (len >= 4 && s[0] == quote && s[1] == quote) {
+                s += 2;
+                len -= 2;
+                if (s[--len] != quote || s[--len] != quote) {
+                        PyErr_BadInternalCall();
+                        return NULL;
+                }
+        }
 #ifdef Py_USING_UNICODE
-	if (unicode || Py_UnicodeFlag) {
-		return decode_unicode(s, len, rawmode, encoding);
-	}
+        if (unicode || Py_UnicodeFlag) {
+                return decode_unicode(s, len, rawmode, encoding);
+        }
 #endif
-	need_encoding = (encoding != NULL &&
-			 strcmp(encoding, "utf-8") != 0 &&
-			 strcmp(encoding, "iso-8859-1") != 0);
-	if (rawmode || strchr(s, '\\') == NULL) {
-		if (need_encoding) {
+        need_encoding = (encoding != NULL &&
+                         strcmp(encoding, "utf-8") != 0 &&
+                         strcmp(encoding, "iso-8859-1") != 0);
+        if (rawmode || strchr(s, '\\') == NULL) {
+                if (need_encoding) {
 #ifndef Py_USING_UNICODE
-			/* This should not happen - we never see any other
-			   encoding. */
-			Py_FatalError("cannot deal with encodings in this build.");
+                        /* This should not happen - we never see any other
+                           encoding. */
+                        Py_FatalError("cannot deal with encodings in this build.");
 #else
-			PyObject* u = PyUnicode_DecodeUTF8(s, len, NULL);
-			if (u == NULL)
-				return NULL;
-			v = PyUnicode_AsEncodedString(u, encoding, NULL);
-			Py_DECREF(u);
-			return v;
+                        PyObject* u = PyUnicode_DecodeUTF8(s, len, NULL);
+                        if (u == NULL)
+                                return NULL;
+                        v = PyUnicode_AsEncodedString(u, encoding, NULL);
+                        Py_DECREF(u);
+                        return v;
 #endif
-		} else {
-			return PyString_FromStringAndSize(s, len);
-		}
-	}
-
-	v = PyString_DecodeEscape(s, len, NULL, unicode,
-				  need_encoding ? encoding : NULL);
-	return v;
+                } else {
+                        return PyString_FromStringAndSize(s, len);
+                }
+        }
+
+        v = PyString_DecodeEscape(s, len, NULL, unicode,
+                                  need_encoding ? encoding : NULL);
+        return v;
 }
 
 /* Build a Python string object out of a STRING atom.  This takes care of
@@ -3355,38 +3366,38 @@
 static PyObject *
 parsestrplus(struct compiling *c, const node *n)
 {
-	PyObject *result = NULL;
-	PyObject *v;
-	int i;
-	REQ(CHILD(n, 0), STRING);
-	if ((v = parsestr(STR(CHILD(n, 0)), c->c_encoding)) != NULL) {
-		/* String literal concatenation */
-		for (i = 1; i < NCH(n); i++) {
-			PyObject *s;
-			s = parsestr(STR(CHILD(n, i)), c->c_encoding);
-			if (s == NULL)
-				goto onError;
-			if (PyString_Check(v) && PyString_Check(s)) {
-				PyString_ConcatAndDel(&v, s);
-				if (v == NULL)
-				    goto onError;
-			}
+        PyObject *result = NULL;
+        PyObject *v;
+        int i;
+        REQ(CHILD(n, 0), STRING);
+        if ((v = parsestr(STR(CHILD(n, 0)), c->c_encoding)) != NULL) {
+                /* String literal concatenation */
+                for (i = 1; i < NCH(n); i++) {
+                        PyObject *s;
+                        s = parsestr(STR(CHILD(n, i)), c->c_encoding);
+                        if (s == NULL)
+                                goto onError;
+                        if (PyString_Check(v) && PyString_Check(s)) {
+                                PyString_ConcatAndDel(&v, s);
+                                if (v == NULL)
+                                    goto onError;
+                        }
 #ifdef Py_USING_UNICODE
-			else {
-				PyObject *temp;
-				temp = PyUnicode_Concat(v, s);
-				Py_DECREF(s);
-				if (temp == NULL)
-					goto onError;
-				Py_DECREF(v);
-				v = temp;
-			}
+                        else {
+                                PyObject *temp;
+                                temp = PyUnicode_Concat(v, s);
+                                Py_DECREF(s);
+                                if (temp == NULL)
+                                        goto onError;
+                                Py_DECREF(v);
+                                v = temp;
+                        }
 #endif
-		}
-	}
-	return v;
+                }
+        }
+        return v;
 
  onError:
-	Py_XDECREF(v);
-	return NULL;
+        Py_XDECREF(v);
+        return NULL;
 }

Modified: python/branches/ast-objects/Python/compile.c
==============================================================================
--- python/branches/ast-objects/Python/compile.c	(original)
+++ python/branches/ast-objects/Python/compile.c	Sun Feb  5 02:54:29 2006
@@ -161,7 +161,7 @@
 	int a_lineno_off;      /* bytecode offset of last lineno */
 };
 
-static int compiler_enter_scope(struct compiler *, identifier, void *, int);
+static int compiler_enter_scope(struct compiler *, PyObject *, void *, int);
 static void compiler_free(struct compiler *);
 static basicblock *compiler_new_block(struct compiler *);
 static int compiler_next_instr(struct compiler *, basicblock *);
@@ -172,23 +172,22 @@
 static void compiler_use_block(struct compiler *, basicblock *);
 static basicblock *compiler_use_new_block(struct compiler *);
 static int compiler_error(struct compiler *, const char *);
-static int compiler_nameop(struct compiler *, identifier, expr_context_ty);
+static int compiler_nameop(struct compiler *, PyObject *, PyObject *);
 
-static PyCodeObject *compiler_mod(struct compiler *, mod_ty);
-static int compiler_visit_stmt(struct compiler *, stmt_ty);
-static int compiler_visit_keyword(struct compiler *, keyword_ty);
-static int compiler_visit_expr(struct compiler *, expr_ty);
-static int compiler_augassign(struct compiler *, stmt_ty);
-static int compiler_visit_slice(struct compiler *, slice_ty,
-				expr_context_ty);
+static PyCodeObject *compiler_mod(struct compiler *, PyObject *);
+static int compiler_visit_stmt(struct compiler *, PyObject *);
+static int compiler_visit_keyword(struct compiler *, PyObject *);
+static int compiler_visit_expr(struct compiler *, PyObject *);
+static int compiler_augassign(struct compiler *, PyObject *);
+static int compiler_visit_slice(struct compiler *, PyObject *, PyObject *);
 
 static int compiler_push_fblock(struct compiler *, enum fblocktype,
 				basicblock *);
 static void compiler_pop_fblock(struct compiler *, enum fblocktype,
 				basicblock *);
 
-static int inplace_binop(struct compiler *, operator_ty);
-static int expr_constant(expr_ty e);
+static int inplace_binop(struct compiler *, PyObject *);
+static int expr_constant(PyObject * e);
 
 static PyCodeObject *assemble(struct compiler *, int addNone);
 static PyObject *__doc__;
@@ -243,7 +242,7 @@
 }
 
 PyCodeObject *
-PyAST_Compile(mod_ty mod, const char *filename, PyCompilerFlags *flags)
+PyAST_Compile(PyObject *mod, const char *filename, PyCompilerFlags *flags)
 {
 	struct compiler c;
 	PyCodeObject *co = NULL;
@@ -293,11 +292,10 @@
 PyNode_Compile(struct _node *n, const char *filename)
 {
 	PyCodeObject *co;
-	mod_ty mod = PyAST_FromNode(n, NULL, filename);
+	PyObject *mod = PyAST_FromNode(n, NULL, filename);
 	if (!mod)
 		return NULL;
 	co = PyAST_Compile(mod, filename, NULL);
-	free_mod(mod);
 	return co;
 }
 
@@ -547,7 +545,7 @@
 static int
 fold_unaryops_on_constants(unsigned char *codestr, PyObject *consts)
 {
-	PyObject *newconst=NULL, *v;
+	PyObject *newconst = NULL, *v;
 	int len_consts, opcode;
 
 	/* Pre-conditions */
@@ -787,8 +785,8 @@
 			     (opcode == BUILD_LIST && 
 			     codestr[i+3]==COMPARE_OP && 
 			     ISBASICBLOCK(blocks, h, 3*(j+2)) &&
-			     (GETARG(codestr,i+3)==6 ||
-				      GETARG(codestr,i+3)==7))) &&
+			     (GETARG(codestr,i+3) == 6 ||
+				      GETARG(codestr,i+3) == 7))) &&
 			     tuple_of_constants(&codestr[h], j, consts)) {
 				assert(codestr[i] == LOAD_CONST);
 				cumlc = 1;
@@ -1064,7 +1062,7 @@
 }
 
 static int
-compiler_enter_scope(struct compiler *c, identifier name, void *key,
+compiler_enter_scope(struct compiler *c, PyObject *name, void *key,
 		     int lineno)
 {
 	struct compiler_unit *u;
@@ -1672,9 +1670,9 @@
 
 #define VISIT_SEQ(C, TYPE, SEQ) { \
 	int i; \
-	asdl_seq *seq = (SEQ); /* avoid variable capture */ \
-	for (i = 0; i < asdl_seq_LEN(seq); i++) { \
-		TYPE ## _ty elt = asdl_seq_GET(seq, i); \
+	PyObject *seq = (SEQ); /* avoid variable capture */ \
+	for (i = 0; i < PyList_GET_SIZE(seq); i++) { \
+		/*TYPE ## _ty*/ PyObject *elt = PyList_GET_ITEM(seq, i); \
 		if (!compiler_visit_ ## TYPE((C), elt)) \
 			return 0; \
 	} \
@@ -1682,9 +1680,9 @@
 
 #define VISIT_SEQ_IN_SCOPE(C, TYPE, SEQ) { \
 	int i; \
-	asdl_seq *seq = (SEQ); /* avoid variable capture */ \
-	for (i = 0; i < asdl_seq_LEN(seq); i++) { \
-		TYPE ## _ty elt = asdl_seq_GET(seq, i); \
+	PyObject *seq = (SEQ); /* avoid variable capture */ \
+	for (i = 0; i < PyList_GET_SIZE(seq); i++) { \
+		/*TYPE ## _ty*/PyObject *elt = PyList_GET_ITEM(seq, i); \
 		if (!compiler_visit_ ## TYPE((C), elt)) { \
 			compiler_exit_scope(c); \
 			return 0; \
@@ -1693,37 +1691,37 @@
 }
 
 static int
-compiler_isdocstring(stmt_ty s)
+compiler_isdocstring(PyObject *s)
 {
-    if (s->kind != Expr_kind)
+    if (stmt_kind(s) != Expr_kind)
         return 0;
-    return s->v.Expr.value->kind == Str_kind;
+    return expr_kind(Expr_value(s)) == Str_kind;
 }
 
 /* Compile a sequence of statements, checking for a docstring. */
 
 static int
-compiler_body(struct compiler *c, asdl_seq *stmts)
+compiler_body(struct compiler *c, PyObject *stmts)
 {
 	int i = 0;
-	stmt_ty st;
+	PyObject *st;
 
-	if (!asdl_seq_LEN(stmts))
+	if (!PyList_GET_SIZE(stmts))
 		return 1;
-	st = asdl_seq_GET(stmts, 0);
+	st = PyList_GET_ITEM(stmts, 0);
 	if (compiler_isdocstring(st)) {
 		i = 1;
-		VISIT(c, expr, st->v.Expr.value);
-		if (!compiler_nameop(c, __doc__, Store))
+		VISIT(c, expr, Expr_value(st));
+		if (!compiler_nameop(c, __doc__, Store()))
 			return 0;
 	}
-        for (; i < asdl_seq_LEN(stmts); i++)
-            VISIT(c, stmt, asdl_seq_GET(stmts, i));
+        for (; i < PyList_GET_SIZE(stmts); i++)
+            VISIT(c, stmt, PyList_GET_ITEM(stmts, i));
 	return 1;
 }
 
 static PyCodeObject *
-compiler_mod(struct compiler *c, mod_ty mod)
+compiler_mod(struct compiler *c, PyObject *mod)
 {
 	PyCodeObject *co;
         int addNone = 1;
@@ -1735,19 +1733,19 @@
 	}
 	if (!compiler_enter_scope(c, module, mod, 1))
 		return NULL;
-	switch (mod->kind) {
+	switch (mod_kind(mod)) {
 	case Module_kind: 
-		if (!compiler_body(c, mod->v.Module.body)) {
+		if (!compiler_body(c, Module_body(mod))) {
 			compiler_exit_scope(c);
 			return 0;
 		}
 		break;
 	case Interactive_kind:
 		c->c_interactive = 1;
-		VISIT_SEQ_IN_SCOPE(c, stmt, mod->v.Interactive.body);
+		VISIT_SEQ_IN_SCOPE(c, stmt, Interactive_body(mod));
 		break;
 	case Expression_kind:
-		VISIT_IN_SCOPE(c, expr, mod->v.Expression.body);
+		VISIT_IN_SCOPE(c, expr, Expression_body(mod));
                 addNone = 0;
 		break;
 	case Suite_kind:
@@ -1757,7 +1755,7 @@
         default:
 		PyErr_Format(PyExc_SystemError,
 			     "module kind %d should not be possible",
-			     mod->kind);
+			     mod_kind(mod));
 		return 0;
 	}
 	co = assemble(c, addNone);
@@ -1853,33 +1851,33 @@
 }
 
 static int
-compiler_decorators(struct compiler *c, asdl_seq* decos)
+compiler_decorators(struct compiler *c, PyObject* decos)
 {
 	int i;
 
 	if (!decos)
 		return 1;
 
-	for (i = 0; i < asdl_seq_LEN(decos); i++) {
-		VISIT(c, expr, asdl_seq_GET(decos, i));
+	for (i = 0; i < PyList_GET_SIZE(decos); i++) {
+		VISIT(c, expr, PyList_GET_ITEM(decos, i));
 	}
 	return 1;
 }
 
 static int
-compiler_arguments(struct compiler *c, arguments_ty args)
+compiler_arguments(struct compiler *c, PyObject *args)
 {
 	int i;
-	int n = asdl_seq_LEN(args->args);
+	int n = PyList_GET_SIZE(arguments_args(args));
 	/* Correctly handle nested argument lists */
 	for (i = 0; i < n; i++) {
-		expr_ty arg = asdl_seq_GET(args->args, i);
-		if (arg->kind == Tuple_kind) {
+		PyObject *arg = PyList_GET_ITEM(arguments_args(args), i);
+		if (expr_kind(arg) == Tuple_kind) {
 			PyObject *id = PyString_FromFormat(".%d", i);
 			if (id == NULL) {
 				return 0;
 			}
-			if (!compiler_nameop(c, id, Load)) {
+			if (!compiler_nameop(c, id, Load())) {
 				Py_DECREF(id);
 				return 0;
 			}
@@ -1891,29 +1889,30 @@
 }
 
 static int
-compiler_function(struct compiler *c, stmt_ty s)
+compiler_function(struct compiler *c, PyObject *s)
 {
 	PyCodeObject *co;
         PyObject *first_const = Py_None;
-	arguments_ty args = s->v.FunctionDef.args;
-	asdl_seq* decos = s->v.FunctionDef.decorators;
-        stmt_ty st;
+	PyObject *args = FunctionDef_args(s);
+	PyObject *decos = FunctionDef_decorators(s);
+        PyObject *st;
 	int i, n, docstring;
 
-	assert(s->kind == FunctionDef_kind);
+	assert(stmt_kind(s) == FunctionDef_kind);
 
 	if (!compiler_decorators(c, decos))
 		return 0;
-	if (args->defaults)
-		VISIT_SEQ(c, expr, args->defaults);
-	if (!compiler_enter_scope(c, s->v.FunctionDef.name, (void *)s,
-				  s->lineno))
+	/* if (arguments_defaults(args)) */
+	VISIT_SEQ(c, expr, arguments_defaults(args));
+				  /* s->lineno)) */
+	if (!compiler_enter_scope(c, FunctionDef_name(s), (void *)s,
+				  ((struct _stmt*)s)->lineno ))
 		return 0;
 
-        st = asdl_seq_GET(s->v.FunctionDef.body, 0);
+        st = PyList_GET_ITEM(FunctionDef_body(s), 0);
         docstring = compiler_isdocstring(st);
         if (docstring)
-            first_const = st->v.Expr.value->v.Str.s;
+            first_const = Str_s(Expr_value(st));
         if (compiler_add_o(c, c->u->u_consts, first_const) < 0)  {
 	    compiler_exit_scope(c);
             return 0;
@@ -1922,13 +1921,13 @@
         /* unpack nested arguments */
 	compiler_arguments(c, args);
 
-	c->u->u_argcount = asdl_seq_LEN(args->args);
-	n = asdl_seq_LEN(s->v.FunctionDef.body);
+	c->u->u_argcount = PyList_GET_SIZE(arguments_args(args));
+	n = PyList_GET_SIZE(FunctionDef_body(s));
         /* if there was a docstring, we need to skip the first statement */
 	for (i = docstring; i < n; i++) {
-		stmt_ty s2 = asdl_seq_GET(s->v.FunctionDef.body, i);
-		if (i == 0 && s2->kind == Expr_kind &&
-		    s2->v.Expr.value->kind == Str_kind)
+		PyObject *s2 = PyList_GET_ITEM(FunctionDef_body(s), i);
+		if (i == 0 && stmt_kind(s2) == Expr_kind &&
+		    expr_kind(Expr_value(s2)) == Str_kind)
 			continue;
 		VISIT_IN_SCOPE(c, stmt, s2);
 	}
@@ -1937,36 +1936,36 @@
 	if (co == NULL)
 		return 0;
 
-        compiler_make_closure(c, co, asdl_seq_LEN(args->defaults));
+        compiler_make_closure(c, co, PyList_GET_SIZE(arguments_defaults(args)));
 	Py_DECREF(co);
 
-	for (i = 0; i < asdl_seq_LEN(decos); i++) {
+	for (i = 0; i < PyList_GET_SIZE(decos); i++) {
 		ADDOP_I(c, CALL_FUNCTION, 1);
 	}
 
-	return compiler_nameop(c, s->v.FunctionDef.name, Store);
+	return compiler_nameop(c, FunctionDef_name(s), Store());
 }
 
 static int
-compiler_class(struct compiler *c, stmt_ty s)
+compiler_class(struct compiler *c, PyObject *s)
 {
 	int n;
 	PyCodeObject *co;
         PyObject *str;
 	/* push class name on stack, needed by BUILD_CLASS */
-	ADDOP_O(c, LOAD_CONST, s->v.ClassDef.name, consts);
+	ADDOP_O(c, LOAD_CONST, ClassDef_name(s), consts);
 	/* push the tuple of base classes on the stack */
-	n = asdl_seq_LEN(s->v.ClassDef.bases);
+	n = PyList_GET_SIZE(ClassDef_bases(s));
 	if (n > 0)
-		VISIT_SEQ(c, expr, s->v.ClassDef.bases);
+		VISIT_SEQ(c, expr, ClassDef_bases(s));
 	ADDOP_I(c, BUILD_TUPLE, n);
-	if (!compiler_enter_scope(c, s->v.ClassDef.name, (void *)s,
-				  s->lineno))
+	if (!compiler_enter_scope(c, ClassDef_name(s), (void *)s,
+				  ((struct _stmt*)s)->lineno))
 		return 0;
-        c->u->u_private = s->v.ClassDef.name;
+        c->u->u_private = ClassDef_name(s);
         Py_INCREF(c->u->u_private);
         str = PyString_InternFromString("__name__");
-	if (!str || !compiler_nameop(c, str, Load)) {
+	if (!str || !compiler_nameop(c, str, Load())) {
 		Py_XDECREF(str);
 		compiler_exit_scope(c);
 		return 0;
@@ -1974,14 +1973,14 @@
         
         Py_DECREF(str);
         str = PyString_InternFromString("__module__");
-	if (!str || !compiler_nameop(c, str, Store)) {
+	if (!str || !compiler_nameop(c, str, Store())) {
 		Py_XDECREF(str);
 		compiler_exit_scope(c);
 		return 0;
         }
         Py_DECREF(str);
 
-	if (!compiler_body(c, s->v.ClassDef.body)) {
+	if (!compiler_body(c, ClassDef_body(s))) {
 		compiler_exit_scope(c);
 		return 0;
 	}
@@ -1998,18 +1997,18 @@
 
 	ADDOP_I(c, CALL_FUNCTION, 0);
 	ADDOP(c, BUILD_CLASS);
-	if (!compiler_nameop(c, s->v.ClassDef.name, Store))
+	if (!compiler_nameop(c, ClassDef_name(s), Store()))
 		return 0;
 	return 1;
 }
 
 static int
-compiler_lambda(struct compiler *c, expr_ty e)
+compiler_lambda(struct compiler *c, PyObject *e)
 {
 	PyCodeObject *co;
-	static identifier name;
-	arguments_ty args = e->v.Lambda.args;
-	assert(e->kind == Lambda_kind);
+	static PyObject *name;
+	PyObject *args = Lambda_args(e);
+	assert(expr_kind(e) == Lambda_kind);
 
 	if (!name) {
 		name = PyString_InternFromString("<lambda>");
@@ -2017,43 +2016,43 @@
 			return 0;
 	}
 
-	if (args->defaults)
-		VISIT_SEQ(c, expr, args->defaults);
-	if (!compiler_enter_scope(c, name, (void *)e, e->lineno))
+	if (arguments_defaults(args))
+		VISIT_SEQ(c, expr, arguments_defaults(args));
+	if (!compiler_enter_scope(c, name, (void *)e, ((struct _expr*)e)->lineno))
 		return 0;
 
         /* unpack nested arguments */
 	compiler_arguments(c, args);
 	
-	c->u->u_argcount = asdl_seq_LEN(args->args);
-	VISIT_IN_SCOPE(c, expr, e->v.Lambda.body);
+	c->u->u_argcount = PyList_GET_SIZE(arguments_args(args));
+	VISIT_IN_SCOPE(c, expr, Lambda_body(e));
 	ADDOP_IN_SCOPE(c, RETURN_VALUE);
 	co = assemble(c, 1);
 	compiler_exit_scope(c);
 	if (co == NULL)
 		return 0;
 
-        compiler_make_closure(c, co, asdl_seq_LEN(args->defaults));
+        compiler_make_closure(c, co, PyList_GET_SIZE(arguments_defaults(args)));
 	Py_DECREF(co);
 
 	return 1;
 }
 
 static int
-compiler_print(struct compiler *c, stmt_ty s)
+compiler_print(struct compiler *c, PyObject *s)
 {
 	int i, n;
 	int dest;
 
-	assert(s->kind == Print_kind);
-	n = asdl_seq_LEN(s->v.Print.values);
+	assert(stmt_kind(s) == Print_kind);
+	n = PyList_GET_SIZE(Print_values(s));
 	dest = 0;
-	if (s->v.Print.dest) {
-		VISIT(c, expr, s->v.Print.dest);
+	if (Print_dest(s) != Py_None) {
+		VISIT(c, expr, Print_dest(s));
 		dest = 1;
 	}
 	for (i = 0; i < n; i++) {
-		expr_ty e = (expr_ty)asdl_seq_GET(s->v.Print.values, i);
+		PyObject *e = PyList_GET_ITEM(Print_values(s), i);
 		if (dest) {
 			ADDOP(c, DUP_TOP);
 			VISIT(c, expr, e);
@@ -2065,7 +2064,7 @@
 			ADDOP(c, PRINT_ITEM);
 		}
 	}
-	if (s->v.Print.nl) {
+	if (Print_nl(s) == Py_True) {
 		if (dest)
 			ADDOP(c, PRINT_NEWLINE_TO)
 		else
@@ -2077,32 +2076,32 @@
 }
 
 static int
-compiler_if(struct compiler *c, stmt_ty s)
+compiler_if(struct compiler *c, PyObject *s)
 {
 	basicblock *end, *next;
 
-	assert(s->kind == If_kind);
+	assert(stmt_kind(s) == If_kind);
 	end = compiler_new_block(c);
 	if (end == NULL)
 		return 0;
         next = compiler_new_block(c);
         if (next == NULL)
             return 0;
-        VISIT(c, expr, s->v.If.test);
+        VISIT(c, expr, If_test(s));
         ADDOP_JREL(c, JUMP_IF_FALSE, next);
         ADDOP(c, POP_TOP);
-        VISIT_SEQ(c, stmt, s->v.If.body);
+        VISIT_SEQ(c, stmt, If_body(s));
         ADDOP_JREL(c, JUMP_FORWARD, end);
         compiler_use_next_block(c, next);
         ADDOP(c, POP_TOP);
-        if (s->v.If.orelse)
-            VISIT_SEQ(c, stmt, s->v.If.orelse);
+        /* if (If_orelse(s)) */
+        VISIT_SEQ(c, stmt, If_orelse(s));
 	compiler_use_next_block(c, end);
 	return 1;
 }
 
 static int
-compiler_for(struct compiler *c, stmt_ty s)
+compiler_for(struct compiler *c, PyObject *s)
 {
 	basicblock *start, *cleanup, *end;
 
@@ -2114,26 +2113,26 @@
 	ADDOP_JREL(c, SETUP_LOOP, end);
 	if (!compiler_push_fblock(c, LOOP, start))
 		return 0;
-	VISIT(c, expr, s->v.For.iter);
+	VISIT(c, expr, For_iter(s));
 	ADDOP(c, GET_ITER);
 	compiler_use_next_block(c, start);
 	ADDOP_JREL(c, FOR_ITER, cleanup);
-	VISIT(c, expr, s->v.For.target);
-	VISIT_SEQ(c, stmt, s->v.For.body);
+	VISIT(c, expr, For_target(s));
+	VISIT_SEQ(c, stmt, For_body(s));
 	ADDOP_JABS(c, JUMP_ABSOLUTE, start);
 	compiler_use_next_block(c, cleanup);
 	ADDOP(c, POP_BLOCK);
 	compiler_pop_fblock(c, LOOP, start);
-	VISIT_SEQ(c, stmt, s->v.For.orelse);
+	VISIT_SEQ(c, stmt, For_orelse(s));
 	compiler_use_next_block(c, end);
 	return 1;
 }
 
 static int
-compiler_while(struct compiler *c, stmt_ty s)
+compiler_while(struct compiler *c, PyObject *s)
 {
 	basicblock *loop, *orelse, *end, *anchor = NULL;
-	int constant = expr_constant(s->v.While.test);
+	int constant = expr_constant(While_test(s));
 
 	if (constant == 0)
 		return 1;
@@ -2146,24 +2145,20 @@
 	}
 	if (loop == NULL || end == NULL)
 		return 0;
-	if (s->v.While.orelse) {
-		orelse = compiler_new_block(c);
-		if (orelse == NULL)
-			return 0;
-	}
-	else
-		orelse = NULL;
+	orelse = compiler_new_block(c);
+	if (orelse == NULL)
+		return 0;
 
 	ADDOP_JREL(c, SETUP_LOOP, end);
 	compiler_use_next_block(c, loop);
 	if (!compiler_push_fblock(c, LOOP, loop))
 		return 0;
 	if (constant == -1) {
-		VISIT(c, expr, s->v.While.test);
+		VISIT(c, expr, While_test(s));
 		ADDOP_JREL(c, JUMP_IF_FALSE, anchor);
 		ADDOP(c, POP_TOP);
 	}
-	VISIT_SEQ(c, stmt, s->v.While.body);
+	VISIT_SEQ(c, stmt, While_body(s));
 	ADDOP_JABS(c, JUMP_ABSOLUTE, loop);
 
 	/* XXX should the two POP instructions be in a separate block
@@ -2177,7 +2172,7 @@
 	}
 	compiler_pop_fblock(c, LOOP, loop);
 	if (orelse != NULL)
-		VISIT_SEQ(c, stmt, s->v.While.orelse);
+		VISIT_SEQ(c, stmt, While_orelse(s));
 	compiler_use_next_block(c, end);
 
 	return 1;
@@ -2246,7 +2241,7 @@
 */
 
 static int
-compiler_try_finally(struct compiler *c, stmt_ty s)
+compiler_try_finally(struct compiler *c, PyObject *s)
 {
 	basicblock *body, *end;
 	body = compiler_new_block(c);
@@ -2258,7 +2253,7 @@
 	compiler_use_next_block(c, body);
 	if (!compiler_push_fblock(c, FINALLY_TRY, body))
 		return 0;
-	VISIT_SEQ(c, stmt, s->v.TryFinally.body);
+	VISIT_SEQ(c, stmt, TryFinally_body(s));
 	ADDOP(c, POP_BLOCK);
 	compiler_pop_fblock(c, FINALLY_TRY, body);
 
@@ -2266,7 +2261,7 @@
 	compiler_use_next_block(c, end);
 	if (!compiler_push_fblock(c, FINALLY_END, end))
 		return 0;
-	VISIT_SEQ(c, stmt, s->v.TryFinally.finalbody);
+	VISIT_SEQ(c, stmt, TryFinally_finalbody(s));
 	ADDOP(c, END_FINALLY);
 	compiler_pop_fblock(c, FINALLY_END, end);
 
@@ -2308,7 +2303,7 @@
    Of course, parts are not generated if Vi or Ei is not present.
 */
 static int
-compiler_try_except(struct compiler *c, stmt_ty s)
+compiler_try_except(struct compiler *c, PyObject *s)
 {
         basicblock *body, *orelse, *except, *end;
 	int i, n;
@@ -2323,50 +2318,50 @@
 	compiler_use_next_block(c, body);
 	if (!compiler_push_fblock(c, EXCEPT, body))
 		return 0;
-	VISIT_SEQ(c, stmt, s->v.TryExcept.body);
+	VISIT_SEQ(c, stmt, TryExcept_body(s));
 	ADDOP(c, POP_BLOCK);
 	compiler_pop_fblock(c, EXCEPT, body);
 	ADDOP_JREL(c, JUMP_FORWARD, orelse);
-	n = asdl_seq_LEN(s->v.TryExcept.handlers);
+	n = PyList_GET_SIZE(TryExcept_handlers(s));
 	compiler_use_next_block(c, except);
 	for (i = 0; i < n; i++) {
-		excepthandler_ty handler = asdl_seq_GET(
-						s->v.TryExcept.handlers, i);
-		if (!handler->type && i < n-1)
+		PyObject *handler = PyList_GET_ITEM(
+						TryExcept_handlers(s), i);
+		if (!excepthandler_type(handler)&& i < n-1)
 		    return compiler_error(c, "default 'except:' must be last");
 		except = compiler_new_block(c);
 		if (except == NULL)
 			return 0;
-		if (handler->type) {
+		if (excepthandler_type(handler)) {
 			ADDOP(c, DUP_TOP);
-			VISIT(c, expr, handler->type);
+			VISIT(c, expr, excepthandler_type(handler));
 			ADDOP_I(c, COMPARE_OP, PyCmp_EXC_MATCH);
 			ADDOP_JREL(c, JUMP_IF_FALSE, except);
 			ADDOP(c, POP_TOP);
 		}
 		ADDOP(c, POP_TOP);
-		if (handler->name) {
-			VISIT(c, expr, handler->name);
+		if (excepthandler_name(handler)) {
+			VISIT(c, expr, excepthandler_name(handler));
 		}
 		else {
 			ADDOP(c, POP_TOP);
 		}
 		ADDOP(c, POP_TOP);
-		VISIT_SEQ(c, stmt, handler->body);
+		VISIT_SEQ(c, stmt, excepthandler_body(handler));
 		ADDOP_JREL(c, JUMP_FORWARD, end);
 		compiler_use_next_block(c, except);
-		if (handler->type)
+		if (excepthandler_type(handler))
 			ADDOP(c, POP_TOP);
 	}
 	ADDOP(c, END_FINALLY);
 	compiler_use_next_block(c, orelse);
-	VISIT_SEQ(c, stmt, s->v.TryExcept.orelse);
+	VISIT_SEQ(c, stmt, TryExcept_orelse(s));
 	compiler_use_next_block(c, end);
 	return 1;
 }
 
 static int
-compiler_import_as(struct compiler *c, identifier name, identifier asname)
+compiler_import_as(struct compiler *c, PyObject *name, PyObject *asname)
 {
 	/* The IMPORT_NAME opcode was already generated.  This function
 	   merely needs to bind the result to a name.
@@ -2392,11 +2387,11 @@
 			src = dot + 1;
 		}
 	}
-	return compiler_nameop(c, asname, Store);
+	return compiler_nameop(c, asname, Store());
 }
 
 static int
-compiler_import(struct compiler *c, stmt_ty s)
+compiler_import(struct compiler *c, PyObject *s)
 {
 	/* The Import node stores a module name like a.b.c as a single
 	   string.  This is convenient for all cases except
@@ -2405,27 +2400,27 @@
 	   module names.  
 	   XXX Perhaps change the representation to make this case simpler?
 	 */
-	int i, n = asdl_seq_LEN(s->v.Import.names);
+	int i, n = PyList_GET_SIZE(Import_names(s));
 	for (i = 0; i < n; i++) {
-		alias_ty alias = asdl_seq_GET(s->v.Import.names, i);
+		PyObject *alias = PyList_GET_ITEM(Import_names(s), i);
 		int r;
 
 		ADDOP_O(c, LOAD_CONST, Py_None, consts);
-		ADDOP_NAME(c, IMPORT_NAME, alias->name, names);
+		ADDOP_NAME(c, IMPORT_NAME, alias_name(alias), names);
 
-		if (alias->asname) {
-			r = compiler_import_as(c, alias->name, alias->asname);
+		if (alias_asname(alias) != Py_None) {
+			r = compiler_import_as(c, alias_name(alias), alias_asname(alias));
                         if (!r)
                             return r;
                 }
                 else {
-			identifier tmp = alias->name;
-			const char *base = PyString_AS_STRING(alias->name);
+			PyObject *tmp = alias_name(alias);
+			const char *base = PyString_AS_STRING(alias_name(alias));
 			char *dot = strchr(base, '.');
 			if (dot)
 				tmp = PyString_FromStringAndSize(base, 
 								 dot - base);
-			r = compiler_nameop(c, tmp, Store);
+			r = compiler_nameop(c, tmp, Store());
 			if (dot) {
 				Py_DECREF(tmp);
 			}
@@ -2437,9 +2432,9 @@
 }
 
 static int
-compiler_from_import(struct compiler *c, stmt_ty s)
+compiler_from_import(struct compiler *c, PyObject *s)
 {
-	int i, n = asdl_seq_LEN(s->v.ImportFrom.names);
+	int i, n = PyList_GET_SIZE(ImportFrom_names(s));
 
 	PyObject *names = PyTuple_New(n);
 	if (!names)
@@ -2447,13 +2442,13 @@
 
 	/* build up the names */
 	for (i = 0; i < n; i++) {
-		alias_ty alias = asdl_seq_GET(s->v.ImportFrom.names, i);
-		Py_INCREF(alias->name);
-		PyTuple_SET_ITEM(names, i, alias->name);
+		PyObject *alias = PyList_GET_ITEM(ImportFrom_names(s), i);
+		Py_INCREF(alias_name(alias));
+		PyTuple_SET_ITEM(names, i, alias_name(alias));
 	}
 
-	if (s->lineno > c->c_future->ff_lineno) {
-		if (!strcmp(PyString_AS_STRING(s->v.ImportFrom.module),
+	if (((struct _stmt*)s)->lineno > c->c_future->ff_lineno) {
+		if (!strcmp(PyString_AS_STRING(ImportFrom_module(s)),
 			    "__future__")) {
 			Py_DECREF(names);
 			return compiler_error(c, 
@@ -2465,23 +2460,23 @@
 
 	ADDOP_O(c, LOAD_CONST, names, consts);
 	Py_DECREF(names);
-	ADDOP_NAME(c, IMPORT_NAME, s->v.ImportFrom.module, names);
+	ADDOP_NAME(c, IMPORT_NAME, ImportFrom_module(s), names);
 	for (i = 0; i < n; i++) {
-		alias_ty alias = asdl_seq_GET(s->v.ImportFrom.names, i);
-		identifier store_name;
+		PyObject *alias = PyList_GET_ITEM(ImportFrom_names(s), i);
+		PyObject *store_name;
 
-		if (i == 0 && *PyString_AS_STRING(alias->name) == '*') {
+		if (i == 0 && *PyString_AS_STRING(alias_name(alias)) == '*') {
 			assert(n == 1);
 			ADDOP(c, IMPORT_STAR);
 			return 1;
 		}
 		    
-		ADDOP_NAME(c, IMPORT_FROM, alias->name, names);
-		store_name = alias->name;
-		if (alias->asname)
-			store_name = alias->asname;
+		ADDOP_NAME(c, IMPORT_FROM, alias_name(alias), names);
+		store_name = alias_name(alias);
+		if (alias_asname(alias) != Py_None)
+			store_name = alias_asname(alias);
 
-		if (!compiler_nameop(c, store_name, Store)) {
+		if (!compiler_nameop(c, store_name, Store())) {
 			Py_DECREF(names);
 			return 0;
 		}
@@ -2492,7 +2487,7 @@
 }
 
 static int
-compiler_assert(struct compiler *c, stmt_ty s)
+compiler_assert(struct compiler *c, PyObject *s)
 {
 	static PyObject *assertion_error = NULL;
 	basicblock *end;
@@ -2504,15 +2499,15 @@
 		if (assertion_error == NULL)
 			return 0;
 	}
-	VISIT(c, expr, s->v.Assert.test);
+	VISIT(c, expr, Assert_test(s));
 	end = compiler_new_block(c);
 	if (end == NULL)
 		return 0;
 	ADDOP_JREL(c, JUMP_IF_TRUE, end);
 	ADDOP(c, POP_TOP);
 	ADDOP_O(c, LOAD_GLOBAL, assertion_error, names);
-	if (s->v.Assert.msg) {
-		VISIT(c, expr, s->v.Assert.msg);
+	if (Assert_msg(s) != Py_None) {
+		VISIT(c, expr, Assert_msg(s));
 		ADDOP_I(c, RAISE_VARARGS, 2);
 	}
 	else {
@@ -2524,13 +2519,13 @@
 }
 
 static int
-compiler_visit_stmt(struct compiler *c, stmt_ty s)
+compiler_visit_stmt(struct compiler *c, PyObject *s)
 {
 	int i, n;
 
-	c->u->u_lineno = s->lineno;
+	c->u->u_lineno = ((struct _stmt*)s)->lineno;
 	c->u->u_lineno_set = 0;
-	switch (s->kind) {
+	switch (stmt_kind(s)) {
         case FunctionDef_kind:
 		return compiler_function(c, s);
         case ClassDef_kind:
@@ -2538,28 +2533,28 @@
         case Return_kind:
 		if (c->u->u_ste->ste_type != FunctionBlock)
 			return compiler_error(c, "'return' outside function");
-		if (s->v.Return.value) {
+		if (Return_value(s) != Py_None) {
 			if (c->u->u_ste->ste_generator) {
 				return compiler_error(c,
 				    "'return' with argument inside generator");
 			}
-			VISIT(c, expr, s->v.Return.value);
+			VISIT(c, expr, Return_value(s));
 		}
 		else
 			ADDOP_O(c, LOAD_CONST, Py_None, consts);
 		ADDOP(c, RETURN_VALUE);
 		break;
         case Delete_kind:
-		VISIT_SEQ(c, expr, s->v.Delete.targets)
+		VISIT_SEQ(c, expr, Delete_targets(s))
 		break;
         case Assign_kind:
-		n = asdl_seq_LEN(s->v.Assign.targets);
-		VISIT(c, expr, s->v.Assign.value);
+		n = PyList_GET_SIZE(Assign_targets(s));
+		VISIT(c, expr, Assign_value(s));
 		for (i = 0; i < n; i++) {
 			if (i < n - 1)
 				ADDOP(c, DUP_TOP);
 			VISIT(c, expr,
-			      (expr_ty)asdl_seq_GET(s->v.Assign.targets, i));
+			      PyList_GET_ITEM(Assign_targets(s), i));
 		}
 		break;
         case AugAssign_kind:
@@ -2574,14 +2569,14 @@
 		return compiler_if(c, s);
         case Raise_kind:
 		n = 0;
-		if (s->v.Raise.type) {
-			VISIT(c, expr, s->v.Raise.type);
+		if (Raise_type(s) != Py_None) {
+			VISIT(c, expr, Raise_type(s));
 			n++;
-			if (s->v.Raise.inst) {
-				VISIT(c, expr, s->v.Raise.inst);
+			if (Raise_inst(s) != Py_None) {
+				VISIT(c, expr, Raise_inst(s));
 				n++;
-				if (s->v.Raise.tback) {
-					VISIT(c, expr, s->v.Raise.tback);
+				if (Raise_tback(s) != Py_None) {
+					VISIT(c, expr, Raise_tback(s));
 					n++;
 				}
 			}
@@ -2599,11 +2594,11 @@
         case ImportFrom_kind:
 		return compiler_from_import(c, s);
         case Exec_kind:
-		VISIT(c, expr, s->v.Exec.body);
-		if (s->v.Exec.globals) {
-			VISIT(c, expr, s->v.Exec.globals);
-			if (s->v.Exec.locals) {
-				VISIT(c, expr, s->v.Exec.locals);
+		VISIT(c, expr, Exec_body(s));
+		if (Exec_globals(s) != Py_None) {
+			VISIT(c, expr, Exec_globals(s));
+			if (Exec_locals(s) != Py_None) {
+				VISIT(c, expr, Exec_locals(s));
 			} else {
 				ADDOP(c, DUP_TOP);
 			}
@@ -2616,7 +2611,7 @@
         case Global_kind:
 		break;
         case Expr_kind:
-		VISIT(c, expr, s->v.Expr.value);
+		VISIT(c, expr, Expr_value(s));
 		if (c->c_interactive && c->c_nestlevel <= 1) {
 			ADDOP(c, PRINT_EXPR);
 		}
@@ -2638,124 +2633,124 @@
 }
 
 static int
-unaryop(unaryop_ty op)
+unaryop(PyObject *op)
 {
-	switch (op) {
-	case Invert:
+	switch (unaryop_kind(op)) {
+	case Invert_kind:
 		return UNARY_INVERT;
-	case Not:
+	case Not_kind:
 		return UNARY_NOT;
-	case UAdd:
+	case UAdd_kind:
 		return UNARY_POSITIVE;
-	case USub:
+	case USub_kind:
 		return UNARY_NEGATIVE;
 	}
 	return 0;
 }
 
 static int
-binop(struct compiler *c, operator_ty op)
+binop(struct compiler *c, PyObject *op)
 {
-	switch (op) {
-	case Add:
+	switch (operator_kind(op)) {
+	case Add_kind:
 		return BINARY_ADD;
-	case Sub:
+	case Sub_kind:
 		return BINARY_SUBTRACT;
-	case Mult:
+	case Mult_kind:
 		return BINARY_MULTIPLY;
-	case Div:
+	case Div_kind:
 		if (c->c_flags && c->c_flags->cf_flags & CO_FUTURE_DIVISION)
 			return BINARY_TRUE_DIVIDE;
 		else
 			return BINARY_DIVIDE;
-	case Mod:
+	case Mod_kind:
 		return BINARY_MODULO;
-	case Pow:
+	case Pow_kind:
 		return BINARY_POWER;
-	case LShift:
+	case LShift_kind:
 		return BINARY_LSHIFT;
-	case RShift:
+	case RShift_kind:
 		return BINARY_RSHIFT;
-	case BitOr:
+	case BitOr_kind:
 		return BINARY_OR;
-	case BitXor:
+	case BitXor_kind:
 		return BINARY_XOR;
-	case BitAnd:
+	case BitAnd_kind:
 		return BINARY_AND;
-	case FloorDiv:
+	case FloorDiv_kind:
 		return BINARY_FLOOR_DIVIDE;
 	}
 	return 0;
 }
 
 static int
-cmpop(cmpop_ty op)
+cmpop(PyObject *op)
 {
-	switch (op) {
-	case Eq:
+	switch (cmpop_kind(op)) {
+	case Eq_kind:
 		return PyCmp_EQ;
-	case NotEq:
+	case NotEq_kind:
 		return PyCmp_NE;
-	case Lt:
+	case Lt_kind:
 		return PyCmp_LT;
-	case LtE:
+	case LtE_kind:
 		return PyCmp_LE;
-	case Gt:
+	case Gt_kind:
 		return PyCmp_GT;
-	case GtE:
+	case GtE_kind:
 		return PyCmp_GE;
-	case Is:
+	case Is_kind:
 		return PyCmp_IS;
-	case IsNot:
+	case IsNot_kind:
 		return PyCmp_IS_NOT;
-	case In:
+	case In_kind:
 		return PyCmp_IN;
-	case NotIn:
+	case NotIn_kind:
 		return PyCmp_NOT_IN;
 	}
 	return PyCmp_BAD;
 }
 
 static int
-inplace_binop(struct compiler *c, operator_ty op)
+inplace_binop(struct compiler *c, PyObject *op)
 {
-	switch (op) {
-	case Add:
+	switch (operator_kind(op)) {
+	case Add_kind:
 		return INPLACE_ADD;
-	case Sub:
+	case Sub_kind:
 		return INPLACE_SUBTRACT;
-	case Mult:
+	case Mult_kind:
 		return INPLACE_MULTIPLY;
-	case Div:
+	case Div_kind:
 		if (c->c_flags && c->c_flags->cf_flags & CO_FUTURE_DIVISION)
 			return INPLACE_TRUE_DIVIDE;
 		else
 			return INPLACE_DIVIDE;
-	case Mod:
+	case Mod_kind:
 		return INPLACE_MODULO;
-	case Pow:
+	case Pow_kind:
 		return INPLACE_POWER;
-	case LShift:
+	case LShift_kind:
 		return INPLACE_LSHIFT;
-	case RShift:
+	case RShift_kind:
 		return INPLACE_RSHIFT;
-	case BitOr:
+	case BitOr_kind:
 		return INPLACE_OR;
-	case BitXor:
+	case BitXor_kind:
 		return INPLACE_XOR;
-	case BitAnd:
+	case BitAnd_kind:
 		return INPLACE_AND;
-	case FloorDiv:
+	case FloorDiv_kind:
 		return INPLACE_FLOOR_DIVIDE;
 	}
 	PyErr_Format(PyExc_SystemError,
 		     "inplace binary op %d should not be possible",
-		     op);
+		     operator_kind(op));
 	return 0;
 }
 
 static int
-compiler_nameop(struct compiler *c, identifier name, expr_context_ty ctx)
+compiler_nameop(struct compiler *c, PyObject *name, PyObject *ctx)
 {
 	int op, scope, arg;
 	enum { OP_FAST, OP_GLOBAL, OP_DEREF, OP_NAME } optype;
@@ -2765,7 +2760,9 @@
 	/* XXX AugStore isn't used anywhere! */
 
 	/* First check for assignment to __debug__. Param? */
-	if ((ctx == Store || ctx == AugStore || ctx == Del)
+	if ((expr_context_kind(ctx) == Store_kind
+             || expr_context_kind(ctx) == AugStore_kind 
+             || expr_context_kind(ctx) == Del_kind)
 	    && !strcmp(PyString_AS_STRING(name), "__debug__")) {
 		return compiler_error(c, "can not assign to __debug__");
 	}
@@ -2805,34 +2802,34 @@
 
 	switch (optype) {
 	case OP_DEREF:
-		switch (ctx) {
-		case Load: op = LOAD_DEREF; break;
-		case Store: op = STORE_DEREF; break;
-		case AugLoad:
-		case AugStore:
+		switch (expr_context_kind(ctx)) {
+		case Load_kind: op = LOAD_DEREF; break;
+		case Store_kind: op = STORE_DEREF; break;
+		case AugLoad_kind:
+		case AugStore_kind:
 			break;
-		case Del:
+		case Del_kind:
 			PyErr_Format(PyExc_SyntaxError,
 				     "can not delete variable '%s' referenced "
 				     "in nested scope",
 				     PyString_AS_STRING(name));
 			Py_DECREF(mangled);
 			return 0;
-		case Param:
+		case Param_kind:
 			PyErr_SetString(PyExc_SystemError,
 					"param invalid for deref variable");
 			return 0;
 		}
 		break;
 	case OP_FAST:
-		switch (ctx) {
-		case Load: op = LOAD_FAST; break;
-		case Store: op = STORE_FAST; break;
-		case Del: op = DELETE_FAST; break;
-		case AugLoad:
-		case AugStore:
+		switch (expr_context_kind(ctx)) {
+		case Load_kind: op = LOAD_FAST; break;
+		case Store_kind: op = STORE_FAST; break;
+		case Del_kind: op = DELETE_FAST; break;
+		case AugLoad_kind:
+		case AugStore_kind:
 			break;
-		case Param:
+		case Param_kind:
 			PyErr_SetString(PyExc_SystemError,
 					"param invalid for local variable");
 			return 0;
@@ -2841,28 +2838,28 @@
 		Py_DECREF(mangled);
 		return 1;
 	case OP_GLOBAL:
-		switch (ctx) {
-		case Load: op = LOAD_GLOBAL; break;
-		case Store: op = STORE_GLOBAL; break;
-		case Del: op = DELETE_GLOBAL; break;
-		case AugLoad:
-		case AugStore:
+		switch (expr_context_kind(ctx)) {
+		case Load_kind: op = LOAD_GLOBAL; break;
+		case Store_kind: op = STORE_GLOBAL; break;
+		case Del_kind: op = DELETE_GLOBAL; break;
+		case AugLoad_kind:
+		case AugStore_kind:
 			break;
-		case Param:
+		case Param_kind:
 			PyErr_SetString(PyExc_SystemError,
 					"param invalid for global variable");
 			return 0;
 		}
 		break;
 	case OP_NAME:
-		switch (ctx) {
-		case Load: op = LOAD_NAME; break;
-		case Store: op = STORE_NAME; break;
-		case Del: op = DELETE_NAME; break;
-		case AugLoad:
-		case AugStore:
+		switch (expr_context_kind(ctx)) {
+		case Load_kind: op = LOAD_NAME; break;
+		case Store_kind: op = STORE_NAME; break;
+		case Del_kind: op = DELETE_NAME; break;
+		case AugLoad_kind:
+		case AugStore_kind:
 			break;
-		case Param:
+		case Param_kind:
 			PyErr_SetString(PyExc_SystemError,
 					"param invalid for name variable");
 			return 0;
@@ -2879,92 +2876,92 @@
 }
 
 static int
-compiler_boolop(struct compiler *c, expr_ty e)
+compiler_boolop(struct compiler *c, PyObject *e)
 {
 	basicblock *end;
 	int jumpi, i, n;
-	asdl_seq *s;
+	PyObject *s;
 
-	assert(e->kind == BoolOp_kind);
-	if (e->v.BoolOp.op == And)
+	assert(expr_kind(e) == BoolOp_kind);
+	if (boolop_kind(BoolOp_op(e)) == And_kind)
 		jumpi = JUMP_IF_FALSE;
 	else
 		jumpi = JUMP_IF_TRUE;
 	end = compiler_new_block(c);
 	if (end < 0)
 		return 0;
-	s = e->v.BoolOp.values;
-	n = asdl_seq_LEN(s) - 1;
+	s = BoolOp_values(e);
+	n = PyList_GET_SIZE(s) - 1;
 	for (i = 0; i < n; ++i) {
-		VISIT(c, expr, asdl_seq_GET(s, i));
+		VISIT(c, expr, PyList_GET_ITEM(s, i));
 		ADDOP_JREL(c, jumpi, end);
 		ADDOP(c, POP_TOP)
 	}
-	VISIT(c, expr, asdl_seq_GET(s, n));
+	VISIT(c, expr, PyList_GET_ITEM(s, n));
 	compiler_use_next_block(c, end);
 	return 1;
 }
 
 static int
-compiler_list(struct compiler *c, expr_ty e)
+compiler_list(struct compiler *c, PyObject *e)
 {
-	int n = asdl_seq_LEN(e->v.List.elts);
-	if (e->v.List.ctx == Store) {
+	int n = PyList_GET_SIZE(List_elts(e));
+	if (expr_context_kind(List_ctx(e)) == Store_kind) {
 		ADDOP_I(c, UNPACK_SEQUENCE, n);
 	}
-	VISIT_SEQ(c, expr, e->v.List.elts);
-	if (e->v.List.ctx == Load) {
+	VISIT_SEQ(c, expr, List_elts(e));
+	if (expr_context_kind(List_ctx(e)) == Load_kind) {
 		ADDOP_I(c, BUILD_LIST, n);
 	}
 	return 1;
 }
 
 static int
-compiler_tuple(struct compiler *c, expr_ty e)
+compiler_tuple(struct compiler *c, PyObject *e)
 {
-	int n = asdl_seq_LEN(e->v.Tuple.elts);
-	if (e->v.Tuple.ctx == Store) {
+	int n = PyList_GET_SIZE(Tuple_elts(e));
+	if (expr_context_kind(Tuple_ctx(e)) == Store_kind) {
 		ADDOP_I(c, UNPACK_SEQUENCE, n);
 	}
-	VISIT_SEQ(c, expr, e->v.Tuple.elts);
-	if (e->v.Tuple.ctx == Load) {
+	VISIT_SEQ(c, expr, Tuple_elts(e));
+	if (expr_context_kind(Tuple_ctx(e)) == Load_kind) {
 		ADDOP_I(c, BUILD_TUPLE, n);
 	}
 	return 1;
 }
 
 static int
-compiler_compare(struct compiler *c, expr_ty e)
+compiler_compare(struct compiler *c, PyObject *e)
 {
 	int i, n;
         basicblock *cleanup = NULL;
 
 	/* XXX the logic can be cleaned up for 1 or multiple comparisons */
-	VISIT(c, expr, e->v.Compare.left);
-	n = asdl_seq_LEN(e->v.Compare.ops);
+	VISIT(c, expr, Compare_left(e));
+	n = PyList_GET_SIZE(Compare_ops(e));
 	assert(n > 0);
 	if (n > 1) {
 		cleanup = compiler_new_block(c);
                 if (cleanup == NULL)
                     return 0;
-		VISIT(c, expr, asdl_seq_GET(e->v.Compare.comparators, 0));
+		VISIT(c, expr, PyList_GET_ITEM(Compare_comparators(e), 0));
 	}
 	for (i = 1; i < n; i++) {
 		ADDOP(c, DUP_TOP);
 		ADDOP(c, ROT_THREE);
 		/* XXX We're casting a void* to cmpop_ty in the next stmt. */
 		ADDOP_I(c, COMPARE_OP,
-			cmpop((cmpop_ty)asdl_seq_GET(e->v.Compare.ops, i - 1)));
+			cmpop(PyList_GET_ITEM(Compare_ops(e), i - 1)));
 		ADDOP_JREL(c, JUMP_IF_FALSE, cleanup);
 		NEXT_BLOCK(c);
 		ADDOP(c, POP_TOP);
 		if (i < (n - 1))
-		    VISIT(c, expr, asdl_seq_GET(e->v.Compare.comparators, i));
+		    VISIT(c, expr, PyList_GET_ITEM(Compare_comparators(e), i));
 	}
-	VISIT(c, expr, asdl_seq_GET(e->v.Compare.comparators, n - 1));
+	VISIT(c, expr, PyList_GET_ITEM(Compare_comparators(e), n - 1));
 	ADDOP_I(c, COMPARE_OP,
 		/* XXX We're casting a void* to cmpop_ty in the next stmt. */
-	       cmpop((cmpop_ty)asdl_seq_GET(e->v.Compare.ops, n - 1)));
+	       cmpop(PyList_GET_ITEM(Compare_ops(e), n - 1)));
 	if (n > 1) {
 		basicblock *end = compiler_new_block(c);
                 if (end == NULL)
@@ -2979,23 +2976,21 @@
 }
 
 static int
-compiler_call(struct compiler *c, expr_ty e)
+compiler_call(struct compiler *c, PyObject *e)
 {
 	int n, code = 0;
 
-	VISIT(c, expr, e->v.Call.func);
-	n = asdl_seq_LEN(e->v.Call.args);
-	VISIT_SEQ(c, expr, e->v.Call.args);
-	if (e->v.Call.keywords) {
-		VISIT_SEQ(c, keyword, e->v.Call.keywords);
-		n |= asdl_seq_LEN(e->v.Call.keywords) << 8;
-	}
-	if (e->v.Call.starargs) {
-		VISIT(c, expr, e->v.Call.starargs);
+	VISIT(c, expr, Call_func(e));
+	n = PyList_GET_SIZE(Call_args(e));
+	VISIT_SEQ(c, expr, Call_args(e));
+	VISIT_SEQ(c, keyword, Call_keywords(e));
+	n |= PyList_GET_SIZE(Call_keywords(e)) << 8;
+	if (Call_starargs(e) != Py_None) {
+		VISIT(c, expr, Call_starargs(e));
 		code |= 1;
 	}
-	if (e->v.Call.kwargs) {
-		VISIT(c, expr, e->v.Call.kwargs);
+	if (Call_kwargs(e) != Py_None) {
+		VISIT(c, expr, Call_kwargs(e));
 		code |= 2;
 	}
 	switch (code) {
@@ -3017,13 +3012,13 @@
 
 static int
 compiler_listcomp_generator(struct compiler *c, PyObject *tmpname,
-                            asdl_seq *generators, int gen_index, 
-                            expr_ty elt)
+                            PyObject *generators, int gen_index, 
+                            PyObject *elt)
 {
 	/* generate code for the iterator, then each of the ifs,
 	   and then write to the element */
 
-	comprehension_ty l;
+	PyObject *l;
 	basicblock *start, *anchor, *skip, *if_cleanup;
         int i, n;
 
@@ -3036,32 +3031,32 @@
                 anchor == NULL)
             return 0;
 
-	l = asdl_seq_GET(generators, gen_index);
-	VISIT(c, expr, l->iter);
+	l = PyList_GET_ITEM(generators, gen_index);
+	VISIT(c, expr, comprehension_iter(l));
 	ADDOP(c, GET_ITER);
 	compiler_use_next_block(c, start);
 	ADDOP_JREL(c, FOR_ITER, anchor);
 	NEXT_BLOCK(c);
-	VISIT(c, expr, l->target);
+	VISIT(c, expr, comprehension_target(l));
 
         /* XXX this needs to be cleaned up...a lot! */
-	n = asdl_seq_LEN(l->ifs);
+	n = PyList_GET_SIZE(comprehension_ifs(l));
 	for (i = 0; i < n; i++) {
-		expr_ty e = asdl_seq_GET(l->ifs, i);
+		PyObject *e = PyList_GET_ITEM(comprehension_ifs(l), i);
 		VISIT(c, expr, e);
 		ADDOP_JREL(c, JUMP_IF_FALSE, if_cleanup);
 		NEXT_BLOCK(c);
 		ADDOP(c, POP_TOP);
 	} 
 
-        if (++gen_index < asdl_seq_LEN(generators))
+        if (++gen_index < PyList_GET_SIZE(generators))
             if (!compiler_listcomp_generator(c, tmpname, 
                                              generators, gen_index, elt))
                 return 0;
 
         /* only append after the last for generator */
-        if (gen_index >= asdl_seq_LEN(generators)) {
-            if (!compiler_nameop(c, tmpname, Load))
+        if (gen_index >= PyList_GET_SIZE(generators)) {
+            if (!compiler_nameop(c, tmpname, Load()))
 		return 0;
             VISIT(c, expr, elt);
             ADDOP_I(c, CALL_FUNCTION, 1);
@@ -3079,22 +3074,22 @@
 	compiler_use_next_block(c, anchor);
         /* delete the append method added to locals */
 	if (gen_index == 1)
-            if (!compiler_nameop(c, tmpname, Del))
+            if (!compiler_nameop(c, tmpname, Del()))
 		return 0;
 	
 	return 1;
 }
 
 static int
-compiler_listcomp(struct compiler *c, expr_ty e)
+compiler_listcomp(struct compiler *c, PyObject *e)
 {
 	char tmpname[256];
-	identifier tmp;
+	PyObject *tmp;
         int rc = 0;
-	static identifier append;
-	asdl_seq *generators = e->v.ListComp.generators;
+	static PyObject *append;
+	PyObject *generators = ListComp_generators(e);
 
-	assert(e->kind == ListComp_kind);
+	assert(expr_kind(e) == ListComp_kind);
 	if (!append) {
 		append = PyString_InternFromString("append");
 		if (!append)
@@ -3107,22 +3102,22 @@
 	ADDOP_I(c, BUILD_LIST, 0);
 	ADDOP(c, DUP_TOP);
 	ADDOP_O(c, LOAD_ATTR, append, names);
-	if (compiler_nameop(c, tmp, Store))
+	if (compiler_nameop(c, tmp, Store()))
             rc = compiler_listcomp_generator(c, tmp, generators, 0, 
-                                             e->v.ListComp.elt);
+                                             ListComp_elt(e));
         Py_DECREF(tmp);
 	return rc;
 }
 
 static int
 compiler_genexp_generator(struct compiler *c,
-                          asdl_seq *generators, int gen_index, 
-                          expr_ty elt)
+                          PyObject *generators, int gen_index, 
+                          PyObject *elt)
 {
 	/* generate code for the iterator, then each of the ifs,
 	   and then write to the element */
 
-	comprehension_ty ge;
+	PyObject *ge;
 	basicblock *start, *anchor, *skip, *if_cleanup, *end;
         int i, n;
 
@@ -3136,7 +3131,7 @@
 	    anchor == NULL || end == NULL)
 		return 0;
 
-	ge = asdl_seq_GET(generators, gen_index);
+	ge = PyList_GET_ITEM(generators, gen_index);
 	ADDOP_JREL(c, SETUP_LOOP, end);
 	if (!compiler_push_fblock(c, LOOP, start))
 		return 0;
@@ -3148,30 +3143,30 @@
 	}
 	else {
 		/* Sub-iter - calculate on the fly */
-		VISIT(c, expr, ge->iter);
+		VISIT(c, expr, comprehension_iter(ge));
 		ADDOP(c, GET_ITER);
 	}
 	compiler_use_next_block(c, start);
 	ADDOP_JREL(c, FOR_ITER, anchor);
 	NEXT_BLOCK(c);
-	VISIT(c, expr, ge->target);
+	VISIT(c, expr, comprehension_target(ge));
 
         /* XXX this needs to be cleaned up...a lot! */
-	n = asdl_seq_LEN(ge->ifs);
+	n = PyList_GET_SIZE(comprehension_ifs(ge));
 	for (i = 0; i < n; i++) {
-		expr_ty e = asdl_seq_GET(ge->ifs, i);
+		PyObject *e = PyList_GET_ITEM(comprehension_ifs(ge), i);
 		VISIT(c, expr, e);
 		ADDOP_JREL(c, JUMP_IF_FALSE, if_cleanup);
 		NEXT_BLOCK(c);
 		ADDOP(c, POP_TOP);
 	} 
 
-        if (++gen_index < asdl_seq_LEN(generators))
+        if (++gen_index < PyList_GET_SIZE(generators))
 		if (!compiler_genexp_generator(c, generators, gen_index, elt))
 			return 0;
 
         /* only append after the last 'for' generator */
-        if (gen_index >= asdl_seq_LEN(generators)) {
+        if (gen_index >= PyList_GET_SIZE(generators)) {
 		VISIT(c, expr, elt);
 		ADDOP(c, YIELD_VALUE);
 		ADDOP(c, POP_TOP);
@@ -3195,13 +3190,11 @@
 }
 
 static int
-compiler_genexp(struct compiler *c, expr_ty e)
+compiler_genexp(struct compiler *c, PyObject *e)
 {
-	static identifier name;
+	static PyObject *name;
 	PyCodeObject *co;
-	expr_ty outermost_iter = ((comprehension_ty)
-				 (asdl_seq_GET(e->v.GeneratorExp.generators,
-					       0)))->iter;
+	PyObject *outermost_iter = comprehension_iter(PyList_GET_ITEM(GeneratorExp_generators(e), 0));
 
 	if (!name) {
 		name = PyString_FromString("<genexpr>");
@@ -3209,10 +3202,10 @@
 			return 0;
 	}
 
-	if (!compiler_enter_scope(c, name, (void *)e, e->lineno))
+	if (!compiler_enter_scope(c, name, (void *)e, ((struct _expr*)e)->lineno))
 		return 0;
-	compiler_genexp_generator(c, e->v.GeneratorExp.generators, 0,
-				  e->v.GeneratorExp.elt);
+	compiler_genexp_generator(c, GeneratorExp_generators(e), 0,
+				  GeneratorExp_elt(e));
 	co = assemble(c, 1);
 	compiler_exit_scope(c);
 	if (co == NULL)
@@ -3229,10 +3222,10 @@
 }
 
 static int
-compiler_visit_keyword(struct compiler *c, keyword_ty k)
+compiler_visit_keyword(struct compiler *c, PyObject *k)
 {
-	ADDOP_O(c, LOAD_CONST, k->arg, consts);
-	VISIT(c, expr, k->value);
+	ADDOP_O(c, LOAD_CONST, keyword_arg(k), consts);
+	VISIT(c, expr, keyword_value(k));
 	return 1;
 }
 
@@ -3243,52 +3236,52 @@
  */
 
 static int
-expr_constant(expr_ty e)
+expr_constant(PyObject *e)
 {
-	switch (e->kind) {
+	switch (expr_kind(e)) {
 	case Num_kind:
-		return PyObject_IsTrue(e->v.Num.n);
+		return PyObject_IsTrue(Num_n(e));
 	case Str_kind:
-		return PyObject_IsTrue(e->v.Str.s);
+		return PyObject_IsTrue(Str_s(e));
 	default:
 		return -1;
 	}
 }
 
 static int
-compiler_visit_expr(struct compiler *c, expr_ty e)
+compiler_visit_expr(struct compiler *c, PyObject *e)
 {
 	int i, n;
 
-	if (e->lineno > c->u->u_lineno) {
-		c->u->u_lineno = e->lineno;
+	if (((struct _expr*)e)->lineno > c->u->u_lineno) {
+		c->u->u_lineno = ((struct _expr*)e)->lineno;
 		c->u->u_lineno_set = 0;
 	}
-	switch (e->kind) {
+	switch (expr_kind(e)) {
         case BoolOp_kind:
 		return compiler_boolop(c, e);
         case BinOp_kind:
-		VISIT(c, expr, e->v.BinOp.left);
-		VISIT(c, expr, e->v.BinOp.right);
-		ADDOP(c, binop(c, e->v.BinOp.op));
+		VISIT(c, expr, BinOp_left(e));
+		VISIT(c, expr, BinOp_right(e));
+		ADDOP(c, binop(c, BinOp_op(e)));
 		break;
         case UnaryOp_kind:
-		VISIT(c, expr, e->v.UnaryOp.operand);
-		ADDOP(c, unaryop(e->v.UnaryOp.op));
+		VISIT(c, expr, UnaryOp_operand(e));
+		ADDOP(c, unaryop(UnaryOp_op(e)));
 		break;
         case Lambda_kind:
 		return compiler_lambda(c, e);
         case Dict_kind:
 		/* XXX get rid of arg? */
 		ADDOP_I(c, BUILD_MAP, 0);
-		n = asdl_seq_LEN(e->v.Dict.values);
+		n = PyList_GET_SIZE(Dict_values(e));
 		/* We must arrange things just right for STORE_SUBSCR.
 		   It wants the stack to look like (value) (dict) (key) */
 		for (i = 0; i < n; i++) {
 			ADDOP(c, DUP_TOP);
-			VISIT(c, expr, asdl_seq_GET(e->v.Dict.values, i));
+			VISIT(c, expr, PyList_GET_ITEM(Dict_values(e), i));
 			ADDOP(c, ROT_TWO);
-			VISIT(c, expr, asdl_seq_GET(e->v.Dict.keys, i));
+			VISIT(c, expr, PyList_GET_ITEM(Dict_keys(e), i));
 			ADDOP(c, STORE_SUBSCR);
 		}
 		break;
@@ -3307,8 +3300,8 @@
 					"block with a 'finally' clause");
 		}
 		*/
-		if (e->v.Yield.value) {
-			VISIT(c, expr, e->v.Yield.value);
+		if (Yield_value(e) != Py_None) {
+			VISIT(c, expr, Yield_value(e));
 		}
 		else {
 			ADDOP_O(c, LOAD_CONST, Py_None, consts);
@@ -3320,70 +3313,70 @@
         case Call_kind:
 		return compiler_call(c, e);
         case Repr_kind:
-		VISIT(c, expr, e->v.Repr.value);
+		VISIT(c, expr, Repr_value(e));
 		ADDOP(c, UNARY_CONVERT);
 		break;
         case Num_kind:
-		ADDOP_O(c, LOAD_CONST, e->v.Num.n, consts);
+		ADDOP_O(c, LOAD_CONST, Num_n(e), consts);
 		break;
         case Str_kind:
-		ADDOP_O(c, LOAD_CONST, e->v.Str.s, consts);
+		ADDOP_O(c, LOAD_CONST, Str_s(e), consts);
 		break;
 	/* The following exprs can be assignment targets. */
         case Attribute_kind:
-		if (e->v.Attribute.ctx != AugStore)
-			VISIT(c, expr, e->v.Attribute.value);
-		switch (e->v.Attribute.ctx) {
-		case AugLoad:
+		if (expr_context_kind(Attribute_ctx(e)) != AugStore_kind)
+			VISIT(c, expr, Attribute_value(e));
+		switch (expr_context_kind(Attribute_ctx(e))) {
+		case AugLoad_kind:
 			ADDOP(c, DUP_TOP);
 			/* Fall through to load */
-		case Load:
-			ADDOP_NAME(c, LOAD_ATTR, e->v.Attribute.attr, names);
+		case Load_kind:
+			ADDOP_NAME(c, LOAD_ATTR, Attribute_attr(e), names);
 			break;
-		case AugStore:
+		case AugStore_kind:
 			ADDOP(c, ROT_TWO);
 			/* Fall through to save */
-		case Store:
-			ADDOP_NAME(c, STORE_ATTR, e->v.Attribute.attr, names);
+		case Store_kind:
+			ADDOP_NAME(c, STORE_ATTR, Attribute_attr(e), names);
 			break;
-		case Del:
-			ADDOP_NAME(c, DELETE_ATTR, e->v.Attribute.attr, names);
+		case Del_kind:
+			ADDOP_NAME(c, DELETE_ATTR, Attribute_attr(e), names);
 			break;
-		case Param:
+		case Param_kind:
 			PyErr_SetString(PyExc_SystemError,
 					"param invalid in attribute expression");
 			return 0;
 		}
 		break;
         case Subscript_kind:
-		switch (e->v.Subscript.ctx) {
-		case AugLoad:
-			VISIT(c, expr, e->v.Subscript.value);
-			VISIT_SLICE(c, e->v.Subscript.slice, AugLoad);
-			break;
-		case Load:
-			VISIT(c, expr, e->v.Subscript.value);
-			VISIT_SLICE(c, e->v.Subscript.slice, Load);
-			break;
-		case AugStore:
-			VISIT_SLICE(c, e->v.Subscript.slice, AugStore);
-			break;
-		case Store:
-			VISIT(c, expr, e->v.Subscript.value);
-			VISIT_SLICE(c, e->v.Subscript.slice, Store);
-			break;
-		case Del:
-			VISIT(c, expr, e->v.Subscript.value);
-			VISIT_SLICE(c, e->v.Subscript.slice, Del);
+		switch (expr_context_kind(Subscript_ctx(e))) {
+		case AugLoad_kind:
+			VISIT(c, expr, Subscript_value(e));
+			VISIT_SLICE(c, Subscript_slice(e), AugLoad()); /* make a PyObject ?? */
+			break;
+		case Load_kind:
+			VISIT(c, expr, Subscript_value(e));
+			VISIT_SLICE(c, Subscript_slice(e), Load());
+			break;
+		case AugStore_kind:
+			VISIT_SLICE(c, Subscript_slice(e), AugStore());
+			break;
+		case Store_kind:
+			VISIT(c, expr, Subscript_value(e));
+			VISIT_SLICE(c, Subscript_slice(e), Store());
+			break;
+		case Del_kind:
+			VISIT(c, expr, Subscript_value(e));
+			VISIT_SLICE(c, Subscript_slice(e), Del());
 			break;
-		case Param:
+		case Param_kind:
 			PyErr_SetString(PyExc_SystemError,
 					"param invalid in subscript expression");
 			return 0;
 		}
 		break;
         case Name_kind:
-		return compiler_nameop(c, e->v.Name.id, e->v.Name.ctx);
+		return compiler_nameop(c, Name_id(e), Name_ctx(e));
 	/* child nodes of List and Tuple will have expr_context set */
         case List_kind:
 		return compiler_list(c, e);
@@ -3394,43 +3387,41 @@
 }
 
 static int
-compiler_augassign(struct compiler *c, stmt_ty s)
+compiler_augassign(struct compiler *c, PyObject *s)
 {
-	expr_ty e = s->v.AugAssign.target;
-	expr_ty auge;
+	PyObject *e = AugAssign_target(s);
+	PyObject *auge;
 
-	assert(s->kind == AugAssign_kind);
+	assert(stmt_kind(s) == AugAssign_kind);
 
-	switch (e->kind) {
+	switch (expr_kind(e)) {
                 case Attribute_kind:
-		auge = Attribute(e->v.Attribute.value, e->v.Attribute.attr,
-				 AugLoad, e->lineno);
+		auge = Attribute(Attribute_value(e), Attribute_attr(e),
+				 AugLoad(), ((struct _expr*)e)->lineno);
                 if (auge == NULL)
                     return 0;
 		VISIT(c, expr, auge);
-		VISIT(c, expr, s->v.AugAssign.value);
-		ADDOP(c, inplace_binop(c, s->v.AugAssign.op));
-		auge->v.Attribute.ctx = AugStore;
+		VISIT(c, expr, AugAssign_value(s));
+		ADDOP(c, inplace_binop(c, AugAssign_op(s)));
+		Attribute_ctx (auge)= AugStore();
 		VISIT(c, expr, auge);
-		free(auge);
 		break;
 	case Subscript_kind:
-		auge = Subscript(e->v.Subscript.value, e->v.Subscript.slice,
-				 AugLoad, e->lineno);
+		auge = Subscript(Subscript_value(e), Subscript_slice(e),
+				 AugLoad(), ((struct _expr*)e)->lineno);
                 if (auge == NULL)
                     return 0;
 		VISIT(c, expr, auge);
-		VISIT(c, expr, s->v.AugAssign.value);
-		ADDOP(c, inplace_binop(c, s->v.AugAssign.op));
-                auge->v.Subscript.ctx = AugStore;
+		VISIT(c, expr, AugAssign_value(s));
+		ADDOP(c, inplace_binop(c, AugAssign_op(s)));
+                Subscript_ctx (auge)= AugStore();
 		VISIT(c, expr, auge);
-		free(auge);
                 break;
 	case Name_kind:
-		VISIT(c, expr, s->v.AugAssign.target);
-		VISIT(c, expr, s->v.AugAssign.value);
-		ADDOP(c, inplace_binop(c, s->v.AugAssign.op));
-		return compiler_nameop(c, e->v.Name.id, Store);
+		VISIT(c, expr, AugAssign_target(s));
+		VISIT(c, expr, AugAssign_value(s));
+		ADDOP(c, inplace_binop(c, AugAssign_op(s)));
+		return compiler_nameop(c, Name_id(e), Store());
 	default:
                 fprintf(stderr, 
                         "invalid node type for augmented assignment\n");
@@ -3493,27 +3484,27 @@
 
 static int
 compiler_handle_subscr(struct compiler *c, const char *kind, 
-                       expr_context_ty ctx) 
+                       PyObject *ctx) 
 {
         int op = 0;
 
         /* XXX this code is duplicated */
-        switch (ctx) {
-                case AugLoad: /* fall through to Load */
-                case Load:    op = BINARY_SUBSCR; break;
-                case AugStore:/* fall through to Store */
-                case Store:   op = STORE_SUBSCR; break;
-                case Del:     op = DELETE_SUBSCR; break;
-                case Param:
+        switch (expr_context_kind(ctx)) {
+                case AugLoad_kind: /* fall through to Load */
+                case Load_kind:    op = BINARY_SUBSCR; break;
+                case AugStore_kind:/* fall through to Store */
+                case Store_kind:   op = STORE_SUBSCR; break;
+                case Del_kind:     op = DELETE_SUBSCR; break;
+                case Param_kind:
                         fprintf(stderr, 
                                 "invalid %s kind %d in subscript\n", 
-                                kind, ctx);
+                                kind, expr_context_kind(ctx));
                         return 0;
         }
-        if (ctx == AugLoad) {
+        if (expr_context_kind(ctx) == AugLoad_kind) {
                 ADDOP_I(c, DUP_TOPX, 2);
         }
-        else if (ctx == AugStore) {
+        else if (expr_context_kind(ctx) == AugStore_kind) {
                 ADDOP(c, ROT_THREE);
         }
         ADDOP(c, op);
@@ -3521,61 +3512,61 @@
 }
 
 static int
-compiler_slice(struct compiler *c, slice_ty s, expr_context_ty ctx)
+compiler_slice(struct compiler *c, PyObject *s, PyObject *ctx)
 {
 	int n = 2;
-	assert(s->kind == Slice_kind);
+	assert(slice_kind(s) == Slice_kind);
 
 	/* only handles the cases where BUILD_SLICE is emitted */
-	if (s->v.Slice.lower) {
-                VISIT(c, expr, s->v.Slice.lower);
+	if (Slice_lower(s) != Py_None) {
+                VISIT(c, expr, Slice_lower(s));
 	}
 	else {
                 ADDOP_O(c, LOAD_CONST, Py_None, consts);
 	}
                 
-	if (s->v.Slice.upper) {
-                VISIT(c, expr, s->v.Slice.upper);
+	if (Slice_upper(s) != Py_None) {
+                VISIT(c, expr, Slice_upper(s));
 	}
 	else {
                 ADDOP_O(c, LOAD_CONST, Py_None, consts);
 	}
 
-	if (s->v.Slice.step) {
+	if (Slice_step(s) != Py_None) {
 		n++;
-		VISIT(c, expr, s->v.Slice.step);
+		VISIT(c, expr, Slice_step(s));
 	}
 	ADDOP_I(c, BUILD_SLICE, n);
 	return 1;
 }
 
 static int
-compiler_simple_slice(struct compiler *c, slice_ty s, expr_context_ty ctx)
+compiler_simple_slice(struct compiler *c, PyObject *s, PyObject *ctx)
 {
 	int op = 0, slice_offset = 0, stack_count = 0;
 
-	assert(s->v.Slice.step == NULL);
-	if (s->v.Slice.lower) {
+	assert(Slice_step(s) == NULL);
+	if (Slice_lower(s) != Py_None) {
 		slice_offset++;
 		stack_count++;
-		if (ctx != AugStore) 
-			VISIT(c, expr, s->v.Slice.lower);
+		if (expr_context_kind(ctx) != AugStore_kind) 
+			VISIT(c, expr, Slice_lower(s));
 	}
-	if (s->v.Slice.upper) {
+	if (Slice_upper(s) != Py_None) {
 		slice_offset += 2;
 		stack_count++;
-		if (ctx != AugStore) 
-			VISIT(c, expr, s->v.Slice.upper);
+		if (expr_context_kind(ctx) != AugStore_kind) 
+			VISIT(c, expr, Slice_upper(s));
 	}
 
- 	if (ctx == AugLoad) {
+ 	if (expr_context_kind(ctx) == AugLoad_kind) {
  		switch (stack_count) {
  		case 0: ADDOP(c, DUP_TOP); break;
  		case 1: ADDOP_I(c, DUP_TOPX, 2); break;
  		case 2: ADDOP_I(c, DUP_TOPX, 3); break;
  		}
   	}
- 	else if (ctx == AugStore) {
+ 	else if (expr_context_kind(ctx) == AugStore_kind) {
  		switch (stack_count) {
  		case 0: ADDOP(c, ROT_TWO); break;
  		case 1: ADDOP(c, ROT_THREE); break;
@@ -3583,13 +3574,13 @@
   		}
   	}
 
-	switch (ctx) {
-	case AugLoad: /* fall through to Load */
-	case Load: op = SLICE; break;
-	case AugStore:/* fall through to Store */
-	case Store: op = STORE_SLICE; break;
-	case Del: op = DELETE_SLICE; break;
-	case Param:
+	switch (expr_context_kind(ctx)) {
+	case AugLoad_kind: /* fall through to Load */
+	case Load_kind: op = SLICE; break;
+	case AugStore_kind:/* fall through to Store */
+	case Store_kind: op = STORE_SLICE; break;
+	case Del_kind: op = DELETE_SLICE; break;
+	case Param_kind:
 		PyErr_SetString(PyExc_SystemError,
 				"param invalid in simple slice");
 		return 0;
@@ -3600,10 +3591,10 @@
 }
 
 static int
-compiler_visit_nested_slice(struct compiler *c, slice_ty s, 
-			    expr_context_ty ctx)
+compiler_visit_nested_slice(struct compiler *c, PyObject *s, 
+			    PyObject *ctx)
 {
-	switch (s->kind) {
+	switch (slice_kind(s)) {
 	case Ellipsis_kind:
 		ADDOP_O(c, LOAD_CONST, Py_Ellipsis, consts);
 		break;
@@ -3611,7 +3602,7 @@
 		return compiler_slice(c, s, ctx);
 		break;
 	case Index_kind:
-		VISIT(c, expr, s->v.Index.value);
+		VISIT(c, expr, Index_value(s));
 		break;
 	case ExtSlice_kind:
 		PyErr_SetString(PyExc_SystemError,
@@ -3623,28 +3614,28 @@
 
 
 static int
-compiler_visit_slice(struct compiler *c, slice_ty s, expr_context_ty ctx)
+compiler_visit_slice(struct compiler *c, PyObject *s, PyObject *ctx)
 {
-	switch (s->kind) {
+	switch (slice_kind(s)) {
 	case Ellipsis_kind:
 		ADDOP_O(c, LOAD_CONST, Py_Ellipsis, consts);
 		break;
 	case Slice_kind:
-		if (!s->v.Slice.step) 
+		if (Slice_step(s) == Py_None) 
 			return compiler_simple_slice(c, s, ctx);
                 if (!compiler_slice(c, s, ctx))
 			return 0;
-		if (ctx == AugLoad) {
+		if (expr_context_kind(ctx) == AugLoad_kind) {
 			ADDOP_I(c, DUP_TOPX, 2);
 		}
-		else if (ctx == AugStore) {
+		else if (expr_context_kind(ctx) == AugStore_kind) {
 			ADDOP(c, ROT_THREE);
 		}
 		return compiler_handle_subscr(c, "slice", ctx);
 	case ExtSlice_kind: {
-		int i, n = asdl_seq_LEN(s->v.ExtSlice.dims);
+		int i, n = PyList_GET_SIZE(ExtSlice_dims(s));
 		for (i = 0; i < n; i++) {
-			slice_ty sub = asdl_seq_GET(s->v.ExtSlice.dims, i);
+			PyObject *sub = PyList_GET_ITEM(ExtSlice_dims(s), i);
 			if (!compiler_visit_nested_slice(c, sub, ctx))
 				return 0;
 		}
@@ -3652,8 +3643,8 @@
                 return compiler_handle_subscr(c, "extended slice", ctx);
 	}
 	case Index_kind:
-                if (ctx != AugStore)
-			VISIT(c, expr, s->v.Index.value);
+                if (expr_context_kind(ctx) != AugStore_kind)
+			VISIT(c, expr, Index_value(s));
                 return compiler_handle_subscr(c, "index", ctx);
 	}
 	return 1;

Modified: python/branches/ast-objects/Python/future.c
==============================================================================
--- python/branches/ast-objects/Python/future.c	(original)
+++ python/branches/ast-objects/Python/future.c	Sun Feb  5 02:54:29 2006
@@ -10,17 +10,17 @@
 #define UNDEFINED_FUTURE_FEATURE "future feature %.100s is not defined"
 
 static int
-future_check_features(PyFutureFeatures *ff, stmt_ty s, const char *filename)
+future_check_features(PyFutureFeatures *ff, PyObject *s, const char *filename)
 {
 	int i;
-	asdl_seq *names;
+	PyObject *names;
 
-	assert(s->kind == ImportFrom_kind);
+	assert(stmt_kind(s) == ImportFrom_kind);
 
-	names = s->v.ImportFrom.names;
-	for (i = 0; i < asdl_seq_LEN(names); i++) {
-                alias_ty name = asdl_seq_GET(names, i);
-		const char *feature = PyString_AsString(name->name);
+	names = ImportFrom_names(s);
+	for (i = 0; i < PyList_GET_SIZE(names); i++) {
+                PyObject *name = PyList_GET_ITEM(names, i);
+		const char *feature = PyString_AsString(alias_name(name));
 		if (!feature)
 			return 0;
 		if (strcmp(feature, FUTURE_NESTED_SCOPES) == 0) {
@@ -32,12 +32,12 @@
 		} else if (strcmp(feature, "braces") == 0) {
 			PyErr_SetString(PyExc_SyntaxError,
 					"not a chance");
-			PyErr_SyntaxLocation(filename, s->lineno);
+			PyErr_SyntaxLocation(filename, ((struct _stmt*)s)->lineno);
 			return 0;
 		} else {
 			PyErr_Format(PyExc_SyntaxError,
 				     UNDEFINED_FUTURE_FEATURE, feature);
-			PyErr_SyntaxLocation(filename, s->lineno);
+			PyErr_SyntaxLocation(filename, ((struct _stmt*)s)->lineno);
 			return 0;
 		}
 	}
@@ -45,7 +45,7 @@
 }
 
 static int
-future_parse(PyFutureFeatures *ff, PyTypeObject *mod, const char *filename)
+future_parse(PyFutureFeatures *ff, PyObject *mod, const char *filename)
 {
 	int i, found_docstring = 0, done = 0, prev_line = 0;
 
@@ -56,7 +56,7 @@
 			return 0;
 	}
 
-	if (!(mod->kind == Module_kind || mod->kind == Interactive_kind))
+	if (!(mod_kind(mod) == Module_kind || mod_kind(mod) == Interactive_kind))
 		return 1;
 
 	/* A subsequent pass will detect future imports that don't
@@ -68,12 +68,12 @@
 	*/
 	   
 
-	for (i = 0; i < asdl_seq_LEN(mod->v.Module.body); i++) {
-		stmt_ty s = asdl_seq_GET(mod->v.Module.body, i);
+	for (i = 0; i < PyList_GET_SIZE(Module_body(mod)); i++) {
+		PyObject *s = PyList_GET_ITEM(Module_body(mod), i);
 
-		if (done && s->lineno > prev_line)
+		if (done && ((struct _stmt*)s)->lineno > prev_line)
 			return 1;
-		prev_line = s->lineno;
+		prev_line = ((struct _stmt*)s)->lineno;
 
 		/* The tests below will return from this function unless it is
 		   still possible to find a future statement.  The only things
@@ -81,25 +81,25 @@
 		   statement and a doc string.
 		*/
 
-		if (s->kind == ImportFrom_kind) {
-			if (s->v.ImportFrom.module == future) {
+		if (stmt_kind(s) == ImportFrom_kind) {
+			if (ImportFrom_module (s)== future) {
 				if (done) {
 					PyErr_SetString(PyExc_SyntaxError,
 							ERR_LATE_FUTURE);
 					PyErr_SyntaxLocation(filename, 
-							     s->lineno);
+							     ((struct _stmt*)s)->lineno);
 					return 0;
 				}
 				if (!future_check_features(ff, s, filename))
 					return 0;
-				ff->ff_lineno = s->lineno;
+				ff->ff_lineno = ((struct _stmt*)s)->lineno;
 			}
 			else
 				done = 1;
 		}
-		else if (s->kind == Expr_kind && !found_docstring) {
-			expr_ty e = s->v.Expr.value;
-			if (e->kind != Str_kind)
+		else if (stmt_kind(s) == Expr_kind && !found_docstring) {
+			PyObject *e = Expr_value(s);
+			if (stmt_kind(e) != Str_kind)
 				done = 1;
 			else
 				found_docstring = 1;
@@ -112,7 +112,7 @@
 
 
 PyFutureFeatures *
-PyFuture_FromAST(PyTypeObject *mod, const char *filename)
+PyFuture_FromAST(PyObject *mod, const char *filename)
 {
 	PyFutureFeatures *ff;
 

Modified: python/branches/ast-objects/Python/import.c
==============================================================================
--- python/branches/ast-objects/Python/import.c	(original)
+++ python/branches/ast-objects/Python/import.c	Sun Feb  5 02:54:29 2006
@@ -772,7 +772,7 @@
 parse_source_module(const char *pathname, FILE *fp)
 {
 	PyCodeObject *co = NULL;
-	PyTypeObject *mod;
+	PyObject *mod;
 
 	mod = PyParser_ASTFromFile(fp, pathname, Py_file_input, 0, 0, 0, 
 				   NULL);

Modified: python/branches/ast-objects/Python/pythonrun.c
==============================================================================
--- python/branches/ast-objects/Python/pythonrun.c	(original)
+++ python/branches/ast-objects/Python/pythonrun.c	Sun Feb  5 02:54:29 2006
@@ -35,9 +35,9 @@
 /* Forward */
 static void initmain(void);
 static void initsite(void);
-static PyObject *run_err_mod(PyTypeObject*, const char *, PyObject *, PyObject *,
+static PyObject *run_err_mod(PyObject*, const char *, PyObject *, PyObject *,
 			      PyCompilerFlags *);
-static PyObject *run_mod(PyTypeObject*, const char *, PyObject *, PyObject *,
+static PyObject *run_mod(PyObject*, const char *, PyObject *, PyObject *,
 			  PyCompilerFlags *);
 static PyObject *run_pyc_file(FILE *, const char *, PyObject *, PyObject *,
 			      PyCompilerFlags *);
@@ -213,6 +213,8 @@
 
 	_PyImportHooks_Init();
 
+	init_ast();
+
 	if (install_sigs)
 		initsigs(); /* Signal handling stuff, including initintr() */
 
@@ -225,9 +227,9 @@
 	_PyGILState_Init(interp, tstate);
 #endif /* WITH_THREAD */
 
-	warnings_module = PyImport_ImportModule("warnings");
-	if (!warnings_module)
-		PyErr_Clear();
+	warnings_module = PyImport_ImportModule("warnings"); 
+	if (!warnings_module) 
+		PyErr_Clear(); 
 
 #if defined(Py_USING_UNICODE) && defined(HAVE_LANGINFO_H) && defined(CODESET)
 	/* On Unix, set the file system encoding according to the
@@ -240,7 +242,7 @@
 	setlocale(LC_CTYPE, "");
 	codeset = nl_langinfo(CODESET);
 	if (codeset && *codeset) {
-		PyObject *enc = PyCodec_Encoder(codeset);
+		PyObject *enc = PyCodec_Encoder(codeset); 
 		if (enc) {
 			codeset = strdup(codeset);
 			Py_DECREF(enc);
@@ -696,7 +698,7 @@
 PyRun_InteractiveOneFlags(FILE *fp, const char *filename, PyCompilerFlags *flags)
 {
 	PyObject *m, *d, *v, *w;
-	PyTypeObject *mod;
+	PyObject *mod;
 	char *ps1 = "", *ps2 = "";
 	int errcode = 0;
 
@@ -1155,7 +1157,7 @@
 		  PyObject *locals, PyCompilerFlags *flags)
 {
 	PyObject *ret;
-	PyTypeObject *mod = PyParser_ASTFromString(str, "<string>", start, flags);
+	PyObject *mod = PyParser_ASTFromString(str, "<string>", start, flags);
 	ret = run_err_mod(mod, "<string>", globals, locals, flags);
 	Py_DECREF(mod);
 	return ret;
@@ -1166,7 +1168,7 @@
 		  PyObject *locals, int closeit, PyCompilerFlags *flags)
 {
 	PyObject *ret;
-	PyTypeObject *mod = PyParser_ASTFromFile(fp, filename, start, 0, 0,
+	PyObject *mod = PyParser_ASTFromFile(fp, filename, start, 0, 0,
 					  flags, NULL);
 	if (mod == NULL)
 		return NULL;
@@ -1178,7 +1180,7 @@
 }
 
 static PyObject *
-run_err_mod(PyTypeObject *mod, const char *filename, PyObject *globals, 
+run_err_mod(PyObject *mod, const char *filename, PyObject *globals, 
 	    PyObject *locals, PyCompilerFlags *flags)
 {
 	if (mod == NULL)
@@ -1187,8 +1189,8 @@
 }
 
 static PyObject *
-run_mod(PyTypeObject *mod, const char *filename, PyObject *globals, PyObject *locals,
-	 PyCompilerFlags *flags)
+run_mod(PyObject *mod, const char *filename, PyObject *globals, PyObject *locals,
+	PyCompilerFlags *flags)
 {
 	PyCodeObject *co;
 	PyObject *v;
@@ -1236,7 +1238,7 @@
 Py_CompileStringFlags(const char *str, const char *filename, int start,
 		      PyCompilerFlags *flags)
 {
-	PyTypeObject *mod;
+	PyObject *mod;
 	PyCodeObject *co;
 	mod = PyParser_ASTFromString(str, filename, start, flags);
 	if (mod == NULL)
@@ -1249,7 +1251,7 @@
 struct symtable *
 Py_SymtableString(const char *str, const char *filename, int start)
 {
-	PyTypeObject *mod;
+	PyObject *mod;
 	struct symtable *st;
 
 	mod = PyParser_ASTFromString(str, filename, start, NULL);
@@ -1261,12 +1263,12 @@
 }
 
 /* Preferred access to parser is through AST. */
-PyTypeObject *
+PyObject *
 PyParser_ASTFromString(const char *s, const char *filename, int start, 
 		       PyCompilerFlags *flags)
 {
 	node *n;
-	PyTypeObject *mod;
+	PyObject *mod;
 	perrdetail err;
 	n = PyParser_ParseStringFlagsFilename(s, filename, &_PyParser_Grammar,
 					      start, &err, 
@@ -1282,12 +1284,12 @@
 	}
 }
 
-PyTypeObject *
+PyObject *
 PyParser_ASTFromFile(FILE *fp, const char *filename, int start, char *ps1, 
 		     char *ps2, PyCompilerFlags *flags, int *errcode)
 {
 	node *n;
-	PyTypeObject *mod;
+	PyObject *mod;
 	perrdetail err;
 	n = PyParser_ParseFileFlags(fp, filename, &_PyParser_Grammar, start, 
 				    ps1, ps2, &err, PARSER_FLAGS(flags));

Modified: python/branches/ast-objects/Python/symtable.c
==============================================================================
--- python/branches/ast-objects/Python/symtable.c	(original)
+++ python/branches/ast-objects/Python/symtable.c	Sun Feb  5 02:54:29 2006
@@ -153,24 +153,24 @@
 
 static int symtable_analyze(struct symtable *st);
 static int symtable_warn(struct symtable *st, char *msg);
-static int symtable_enter_block(struct symtable *st, identifier name, 
+static int symtable_enter_block(struct symtable *st, PyObject *name, 
 				_Py_block_ty block, void *ast, int lineno);
 static int symtable_exit_block(struct symtable *st, void *ast);
-static int symtable_visit_stmt(struct symtable *st, stmt_ty s);
-static int symtable_visit_expr(struct symtable *st, expr_ty s);
-static int symtable_visit_genexp(struct symtable *st, expr_ty s);
-static int symtable_visit_arguments(struct symtable *st, arguments_ty);
-static int symtable_visit_excepthandler(struct symtable *st, excepthandler_ty);
-static int symtable_visit_alias(struct symtable *st, alias_ty);
-static int symtable_visit_comprehension(struct symtable *st, comprehension_ty);
-static int symtable_visit_keyword(struct symtable *st, keyword_ty);
-static int symtable_visit_slice(struct symtable *st, slice_ty);
-static int symtable_visit_params(struct symtable *st, asdl_seq *args, int top);
-static int symtable_visit_params_nested(struct symtable *st, asdl_seq *args);
+static int symtable_visit_stmt(struct symtable *st, PyObject *s);
+static int symtable_visit_expr(struct symtable *st, PyObject *s);
+static int symtable_visit_genexp(struct symtable *st, PyObject *s);
+static int symtable_visit_arguments(struct symtable *st, PyObject *);
+static int symtable_visit_excepthandler(struct symtable *st, PyObject *);
+static int symtable_visit_alias(struct symtable *st, PyObject *);
+static int symtable_visit_comprehension(struct symtable *st, PyObject *);
+static int symtable_visit_keyword(struct symtable *st, PyObject *);
+static int symtable_visit_slice(struct symtable *st, PyObject *);
+static int symtable_visit_params(struct symtable *st, PyObject *args, int top);
+static int symtable_visit_params_nested(struct symtable *st, PyObject *args);
 static int symtable_implicit_arg(struct symtable *st, int pos);
 
 
-static identifier top = NULL, lambda = NULL, genexpr = NULL;
+static PyObject *top = NULL, *lambda = NULL, *genexpr = NULL;
 
 #define GET_IDENTIFIER(VAR) \
 	((VAR) ? (VAR) : ((VAR) = PyString_InternFromString(# VAR)))
@@ -204,10 +204,10 @@
 }
 
 struct symtable *
-PySymtable_Build(PyTypeObject *mod, const char *filename, PyFutureFeatures *future)
+PySymtable_Build(PyObject *mod, const char *filename, PyFutureFeatures *future)
 {
 	struct symtable *st = symtable_new();
-	asdl_seq *seq;
+	PyObject *seq;
 	int i;
 
 	if (st == NULL)
@@ -219,21 +219,21 @@
 	st->st_top = st->st_cur;
 	st->st_cur->ste_unoptimized = OPT_TOPLEVEL;
 	/* Any other top-level initialization? */
-	switch (mod->kind) {
+	switch (mod_kind(mod)) {
 	case Module_kind:
-		seq = mod->v.Module.body;
-		for (i = 0; i < asdl_seq_LEN(seq); i++)
-			if (!symtable_visit_stmt(st, asdl_seq_GET(seq, i)))
+		seq = Module_body(mod);
+		for (i = 0; i < PyList_GET_SIZE(seq); i++)
+			if (!symtable_visit_stmt(st, PyList_GET_ITEM(seq, i)))
 				goto error;
 		break;
 	case Expression_kind:
-		if (!symtable_visit_expr(st, mod->v.Expression.body))
+		if (!symtable_visit_expr(st, Expression_body(mod)))
 			goto error;
 		break;
 	case Interactive_kind:
-		seq = mod->v.Interactive.body;
-		for (i = 0; i < asdl_seq_LEN(seq); i++)
-			if (!symtable_visit_stmt(st, asdl_seq_GET(seq, i)))
+		seq = Interactive_body(mod);
+		for (i = 0; i < PyList_GET_SIZE(seq); i++)
+			if (!symtable_visit_stmt(st, PyList_GET_ITEM(seq, i)))
 				goto error;
 		break;
 	case Suite_kind:
@@ -723,7 +723,7 @@
 }
 
 static int
-symtable_enter_block(struct symtable *st, identifier name, _Py_block_ty block, 
+symtable_enter_block(struct symtable *st, PyObject *name, _Py_block_ty block, 
 		     void *ast, int lineno)
 {
 	PySTEntryObject *prev = NULL;
@@ -829,21 +829,23 @@
    useful if the first node in the sequence requires special treatment.
 */
 
-#define VISIT(ST, TYPE, V) \
+#define VISIT(ST, TYPE, V) {\
 	if (!symtable_visit_ ## TYPE((ST), (V))) \
-		return 0; 
+		return 0;\
+}
 
-#define VISIT_IN_BLOCK(ST, TYPE, V, S) \
+#define VISIT_IN_BLOCK(ST, TYPE, V, S) {\
 	if (!symtable_visit_ ## TYPE((ST), (V))) { \
 		symtable_exit_block((ST), (S)); \
 		return 0; \
-	}
+	}\
+}
 
 #define VISIT_SEQ(ST, TYPE, SEQ) { \
 	int i; \
-	asdl_seq *seq = (SEQ); /* avoid variable capture */ \
-	for (i = 0; i < asdl_seq_LEN(seq); i++) { \
-		TYPE ## _ty elt = asdl_seq_GET(seq, i); \
+	PyObject *seq = (SEQ); /* avoid variable capture */ \
+	for (i = 0; i < PyList_GET_SIZE(seq); i++) { \
+		PyObject *elt = PyList_GET_ITEM(seq, i); \
 		if (!symtable_visit_ ## TYPE((ST), elt)) \
 			return 0; \
 	} \
@@ -851,9 +853,9 @@
 
 #define VISIT_SEQ_IN_BLOCK(ST, TYPE, SEQ, S) { \
 	int i; \
-	asdl_seq *seq = (SEQ); /* avoid variable capture */ \
-	for (i = 0; i < asdl_seq_LEN(seq); i++) { \
-		TYPE ## _ty elt = asdl_seq_GET(seq, i); \
+	PyObject *seq = (SEQ); /* avoid variable capture */ \
+	for (i = 0; i < PyList_GET_SIZE(seq); i++) { \
+		PyObject *elt = PyList_GET_ITEM(seq, i); \
 		if (!symtable_visit_ ## TYPE((ST), elt)) { \
 			symtable_exit_block((ST), (S)); \
 			return 0; \
@@ -863,9 +865,9 @@
 
 #define VISIT_SEQ_TAIL(ST, TYPE, SEQ, START) { \
 	int i; \
-	asdl_seq *seq = (SEQ); /* avoid variable capture */ \
-	for (i = (START); i < asdl_seq_LEN(seq); i++) { \
-		TYPE ## _ty elt = asdl_seq_GET(seq, i); \
+	PyObject *seq = (SEQ); /* avoid variable capture */ \
+	for (i = (START); i < PyList_GET_SIZE(seq); i++) { \
+		PyObject *elt = PyList_GET_ITEM(seq, i); \
 		if (!symtable_visit_ ## TYPE((ST), elt)) \
 			return 0; \
 	} \
@@ -873,9 +875,9 @@
 
 #define VISIT_SEQ_TAIL_IN_BLOCK(ST, TYPE, SEQ, START, S) { \
 	int i; \
-	asdl_seq *seq = (SEQ); /* avoid variable capture */ \
-	for (i = (START); i < asdl_seq_LEN(seq); i++) { \
-		TYPE ## _ty elt = asdl_seq_GET(seq, i); \
+	PyObject *seq = (SEQ); /* avoid variable capture */ \
+	for (i = (START); i < PyList_GET_SIZE(seq); i++) { \
+		PyObject *elt = PyList_GET_ITEM(seq, i); \
 		if (!symtable_visit_ ## TYPE((ST), elt)) { \
 			symtable_exit_block((ST), (S)); \
 			return 0; \
@@ -884,136 +886,136 @@
 }
 
 static int
-symtable_visit_stmt(struct symtable *st, stmt_ty s)
+symtable_visit_stmt(struct symtable *st, PyObject *s)
 {
-	switch (s->kind) {
+	switch (stmt_kind(s)) {
         case FunctionDef_kind:
-		if (!symtable_add_def(st, s->v.FunctionDef.name, DEF_LOCAL))
+		if (!symtable_add_def(st, FunctionDef_name(s), DEF_LOCAL))
 			return 0;
-		if (s->v.FunctionDef.args->defaults)
-			VISIT_SEQ(st, expr, s->v.FunctionDef.args->defaults);
-		if (s->v.FunctionDef.decorators)
-			VISIT_SEQ(st, expr, s->v.FunctionDef.decorators);
-		if (!symtable_enter_block(st, s->v.FunctionDef.name, 
-					  FunctionBlock, (void *)s, s->lineno))
+		if (arguments_defaults(FunctionDef_args(s)))
+			VISIT_SEQ(st, expr, arguments_defaults(FunctionDef_args(s)));
+		if (FunctionDef_decorators(s))
+			VISIT_SEQ(st, expr, FunctionDef_decorators(s));
+		if (!symtable_enter_block(st, FunctionDef_name(s), 
+					  FunctionBlock, (void *)s, ((struct _stmt*)s)->lineno))
 			return 0;
-		VISIT_IN_BLOCK(st, arguments, s->v.FunctionDef.args, s);
-		VISIT_SEQ_IN_BLOCK(st, stmt, s->v.FunctionDef.body, s);
+		VISIT_IN_BLOCK(st, arguments, FunctionDef_args(s), s);
+		VISIT_SEQ_IN_BLOCK(st, stmt, FunctionDef_body(s), s);
 		if (!symtable_exit_block(st, s))
 			return 0;
 		break;
         case ClassDef_kind: {
 		PyObject *tmp;
-		if (!symtable_add_def(st, s->v.ClassDef.name, DEF_LOCAL))
+		if (!symtable_add_def(st, ClassDef_name(s), DEF_LOCAL))
 			return 0;
-		VISIT_SEQ(st, expr, s->v.ClassDef.bases);
-		if (!symtable_enter_block(st, s->v.ClassDef.name, ClassBlock, 
-					  (void *)s, s->lineno))
+		VISIT_SEQ(st, expr, ClassDef_bases(s));
+		if (!symtable_enter_block(st, ClassDef_name(s), ClassBlock, 
+					  (void *)s, ((struct _stmt*)s)->lineno))
 			return 0;
 		tmp = st->st_private;
-		st->st_private = s->v.ClassDef.name;
-		VISIT_SEQ_IN_BLOCK(st, stmt, s->v.ClassDef.body, s);
+		st->st_private = ClassDef_name(s);
+		VISIT_SEQ_IN_BLOCK(st, stmt, ClassDef_body(s), s);
 		st->st_private = tmp;
 		if (!symtable_exit_block(st, s))
 			return 0;
 		break;
 	}
         case Return_kind:
-		if (s->v.Return.value)
-			VISIT(st, expr, s->v.Return.value);
+		if (Return_value(s) != Py_None)
+			VISIT(st, expr, Return_value(s));
 		break;
         case Delete_kind:
-		VISIT_SEQ(st, expr, s->v.Delete.targets);
+		VISIT_SEQ(st, expr, Delete_targets(s));
 		break;
         case Assign_kind:
-		VISIT_SEQ(st, expr, s->v.Assign.targets);
-		VISIT(st, expr, s->v.Assign.value);
+		VISIT_SEQ(st, expr, Assign_targets(s));
+		VISIT(st, expr, Assign_value(s));
 		break;
         case AugAssign_kind:
-		VISIT(st, expr, s->v.AugAssign.target);
-		VISIT(st, expr, s->v.AugAssign.value);
+		VISIT(st, expr, AugAssign_target(s));
+		VISIT(st, expr, AugAssign_value(s));
 		break;
         case Print_kind:
-		if (s->v.Print.dest)
-			VISIT(st, expr, s->v.Print.dest);
-		VISIT_SEQ(st, expr, s->v.Print.values);
+		if (Print_dest(s) != Py_None)
+			VISIT(st, expr, Print_dest(s));
+		VISIT_SEQ(st, expr, Print_values(s));
 		break;
         case For_kind:
-		VISIT(st, expr, s->v.For.target);
-		VISIT(st, expr, s->v.For.iter);
-		VISIT_SEQ(st, stmt, s->v.For.body);
-		if (s->v.For.orelse)
-			VISIT_SEQ(st, stmt, s->v.For.orelse);
+		VISIT(st, expr, For_target(s));
+		VISIT(st, expr, For_iter(s));
+		VISIT_SEQ(st, stmt, For_body(s));
+		/* if (For_orelse(s)) */
+		VISIT_SEQ(st, stmt, For_orelse(s));
 		break;
         case While_kind:
-		VISIT(st, expr, s->v.While.test);
-		VISIT_SEQ(st, stmt, s->v.While.body);
-		if (s->v.While.orelse)
-			VISIT_SEQ(st, stmt, s->v.While.orelse);
+		VISIT(st, expr, While_test(s));
+		VISIT_SEQ(st, stmt, While_body(s));
+		/* if (While_orelse(s)) */
+		VISIT_SEQ(st, stmt, While_orelse(s));
 		break;
         case If_kind:
 		/* XXX if 0: and lookup_yield() hacks */
-		VISIT(st, expr, s->v.If.test);
-		VISIT_SEQ(st, stmt, s->v.If.body);
-		if (s->v.If.orelse)
-			VISIT_SEQ(st, stmt, s->v.If.orelse);
+		VISIT(st, expr, If_test(s));
+		VISIT_SEQ(st, stmt, If_body(s));
+		/* if (If_orelse(s)) */
+		VISIT_SEQ(st, stmt, If_orelse(s));
 		break;
         case Raise_kind:
-		if (s->v.Raise.type) {
-			VISIT(st, expr, s->v.Raise.type);
-			if (s->v.Raise.inst) {
-				VISIT(st, expr, s->v.Raise.inst);
-				if (s->v.Raise.tback)
-					VISIT(st, expr, s->v.Raise.tback);
+		if (Raise_type(s) != Py_None) {
+			VISIT(st, expr, Raise_type(s));
+			if (Raise_inst(s) != Py_None) {
+				VISIT(st, expr, Raise_inst(s));
+				if (Raise_tback(s) != Py_None)
+					VISIT(st, expr, Raise_tback(s));
 			}
 		}
 		break;
         case TryExcept_kind:
-		VISIT_SEQ(st, stmt, s->v.TryExcept.body);
-		VISIT_SEQ(st, stmt, s->v.TryExcept.orelse);
-		VISIT_SEQ(st, excepthandler, s->v.TryExcept.handlers);
+		VISIT_SEQ(st, stmt, TryExcept_body(s));
+		VISIT_SEQ(st, stmt, TryExcept_orelse(s));
+		VISIT_SEQ(st, excepthandler, TryExcept_handlers(s));
 		break;
         case TryFinally_kind:
-		VISIT_SEQ(st, stmt, s->v.TryFinally.body);
-		VISIT_SEQ(st, stmt, s->v.TryFinally.finalbody);
+		VISIT_SEQ(st, stmt, TryFinally_body(s));
+		VISIT_SEQ(st, stmt, TryFinally_finalbody(s));
 		break;
         case Assert_kind:
-		VISIT(st, expr, s->v.Assert.test);
-		if (s->v.Assert.msg)
-			VISIT(st, expr, s->v.Assert.msg);
+		VISIT(st, expr, Assert_test(s));
+		if (Assert_msg(s) != Py_None)
+			VISIT(st, expr, Assert_msg(s));
 		break;
         case Import_kind:
-		VISIT_SEQ(st, alias, s->v.Import.names);
+		VISIT_SEQ(st, alias, Import_names(s));
 		/* XXX Don't have the lineno available inside
 		   visit_alias */
 		if (st->st_cur->ste_unoptimized && !st->st_cur->ste_opt_lineno)
-			st->st_cur->ste_opt_lineno = s->lineno;
+			st->st_cur->ste_opt_lineno = ((struct _stmt*)s)->lineno;
 		break;
         case ImportFrom_kind:
-		VISIT_SEQ(st, alias, s->v.ImportFrom.names);
+		VISIT_SEQ(st, alias, ImportFrom_names(s));
 		/* XXX Don't have the lineno available inside
 		   visit_alias */
 		if (st->st_cur->ste_unoptimized && !st->st_cur->ste_opt_lineno)
-			st->st_cur->ste_opt_lineno = s->lineno;
+			st->st_cur->ste_opt_lineno = ((struct _stmt*)s)->lineno;
 		break;
         case Exec_kind:
-		VISIT(st, expr, s->v.Exec.body);
+		VISIT(st, expr, Exec_body(s));
 		if (!st->st_cur->ste_opt_lineno)
-			st->st_cur->ste_opt_lineno = s->lineno;
-		if (s->v.Exec.globals) {
+			st->st_cur->ste_opt_lineno = ((struct _stmt*)s)->lineno;
+		if (Exec_globals(s) != Py_None) {
 			st->st_cur->ste_unoptimized |= OPT_EXEC;
-			VISIT(st, expr, s->v.Exec.globals);
-			if (s->v.Exec.locals) 
-				VISIT(st, expr, s->v.Exec.locals);
+			VISIT(st, expr, Exec_globals(s));
+			if (Exec_locals(s) != Py_None) 
+				VISIT(st, expr, Exec_locals(s));
 		} else {
 			st->st_cur->ste_unoptimized |= OPT_BARE_EXEC;
 		}
 		break;
         case Global_kind: {
 		int i;
-		asdl_seq *seq = s->v.Global.names;
-		for (i = 0; i < asdl_seq_LEN(seq); i++) {
-			identifier name = asdl_seq_GET(seq, i);
+		PyObject *seq = Global_names(s);
+		for (i = 0; i < PyList_GET_SIZE(seq); i++) {
+			PyObject *name = PyList_GET_ITEM(seq, i);
 			char *c_name = PyString_AS_STRING(name);
 			int cur = symtable_lookup(st, name);
 			if (cur < 0)
@@ -1037,7 +1039,7 @@
 		break;
 	}
         case Expr_kind:
-		VISIT(st, expr, s->v.Expr.value);
+		VISIT(st, expr, Expr_value(s));
 		break;
         case Pass_kind:
         case Break_kind:
@@ -1049,41 +1051,41 @@
 }
 
 static int 
-symtable_visit_expr(struct symtable *st, expr_ty e)
+symtable_visit_expr(struct symtable *st, PyObject *e)
 {
-	switch (e->kind) {
+	switch (expr_kind(e)) {
         case BoolOp_kind:
-		VISIT_SEQ(st, expr, e->v.BoolOp.values);
+		VISIT_SEQ(st, expr, BoolOp_values(e));
 		break;
         case BinOp_kind:
-		VISIT(st, expr, e->v.BinOp.left);
-		VISIT(st, expr, e->v.BinOp.right);
+		VISIT(st, expr, BinOp_left(e));
+		VISIT(st, expr, BinOp_right(e));
 		break;
         case UnaryOp_kind:
-		VISIT(st, expr, e->v.UnaryOp.operand);
+		VISIT(st, expr, UnaryOp_operand(e));
 		break;
         case Lambda_kind: {
 		if (!symtable_add_def(st, GET_IDENTIFIER(lambda), DEF_LOCAL))
 			return 0;
-		if (e->v.Lambda.args->defaults)
-			VISIT_SEQ(st, expr, e->v.Lambda.args->defaults);
+		if (arguments_defaults(Lambda_args(e)))
+			VISIT_SEQ(st, expr, arguments_defaults(Lambda_args(e)));
 		/* XXX how to get line numbers for expressions */
 		if (!symtable_enter_block(st, GET_IDENTIFIER(lambda),
                                           FunctionBlock, (void *)e, 0))
 			return 0;
-		VISIT_IN_BLOCK(st, arguments, e->v.Lambda.args, (void*)e);
-		VISIT_IN_BLOCK(st, expr, e->v.Lambda.body, (void*)e);
+		VISIT_IN_BLOCK(st, arguments, Lambda_args(e), (void*)e);
+		VISIT_IN_BLOCK(st, expr, Lambda_body(e), (void*)e);
 		if (!symtable_exit_block(st, (void *)e))
 			return 0;
 		break;
 	}
         case Dict_kind:
-		VISIT_SEQ(st, expr, e->v.Dict.keys);
-		VISIT_SEQ(st, expr, e->v.Dict.values);
+		VISIT_SEQ(st, expr, Dict_keys(e));
+		VISIT_SEQ(st, expr, Dict_values(e));
 		break;
         case ListComp_kind: {
 		char tmpname[256];
-		identifier tmp;
+		PyObject *tmp;
 
 		PyOS_snprintf(tmpname, sizeof(tmpname), "_[%d]",
 			      ++st->st_cur->ste_tmpname);
@@ -1091,8 +1093,8 @@
 		if (!symtable_add_def(st, tmp, DEF_LOCAL))
 			return 0;
 		Py_DECREF(tmp);
-		VISIT(st, expr, e->v.ListComp.elt);
-		VISIT_SEQ(st, comprehension, e->v.ListComp.generators);
+		VISIT(st, expr, ListComp_elt(e));
+		VISIT_SEQ(st, comprehension, ListComp_generators(e));
 		break;
 	}
         case GeneratorExp_kind: {
@@ -1102,25 +1104,25 @@
 		break;
 	}
         case Yield_kind:
-		if (e->v.Yield.value)
-			VISIT(st, expr, e->v.Yield.value);
+		if (Yield_value(e) != Py_None)
+			VISIT(st, expr, Yield_value(e));
                 st->st_cur->ste_generator = 1;
 		break;
         case Compare_kind:
-		VISIT(st, expr, e->v.Compare.left);
-		VISIT_SEQ(st, expr, e->v.Compare.comparators);
+		VISIT(st, expr, Compare_left(e));
+		VISIT_SEQ(st, expr, Compare_comparators(e));
 		break;
         case Call_kind:
-		VISIT(st, expr, e->v.Call.func);
-		VISIT_SEQ(st, expr, e->v.Call.args);
-		VISIT_SEQ(st, keyword, e->v.Call.keywords);
-		if (e->v.Call.starargs)
-			VISIT(st, expr, e->v.Call.starargs);
-		if (e->v.Call.kwargs)
-			VISIT(st, expr, e->v.Call.kwargs);
+		VISIT(st, expr, Call_func(e));
+		VISIT_SEQ(st, expr, Call_args(e));
+		VISIT_SEQ(st, keyword, Call_keywords(e));
+		if (Call_starargs(e) != Py_None)
+			VISIT(st, expr, Call_starargs(e));
+		if (Call_kwargs(e) != Py_None)
+			VISIT(st, expr, Call_kwargs(e));
 		break;
         case Repr_kind:
-		VISIT(st, expr, e->v.Repr.value);
+		VISIT(st, expr, Repr_value(e));
 		break;
         case Num_kind:
         case Str_kind:
@@ -1128,23 +1130,23 @@
 		break;
 	/* The following exprs can be assignment targets. */
         case Attribute_kind:
-		VISIT(st, expr, e->v.Attribute.value);
+		VISIT(st, expr, Attribute_value(e));
 		break;
         case Subscript_kind:
-		VISIT(st, expr, e->v.Subscript.value);
-		VISIT(st, slice, e->v.Subscript.slice);
+		VISIT(st, expr, Subscript_value(e));
+		VISIT(st, slice, Subscript_slice(e));
 		break;
         case Name_kind:
-		if (!symtable_add_def(st, e->v.Name.id, 
-				      e->v.Name.ctx == Load ? USE : DEF_LOCAL))
+		if (!symtable_add_def(st, Name_id(e), 
+				      expr_context_kind(Name_ctx(e)) == Load_kind ? USE : DEF_LOCAL))
 			return 0;
 		break;
 	/* child nodes of List and Tuple will have expr_context set */
         case List_kind:
-		VISIT_SEQ(st, expr, e->v.List.elts);
+		VISIT_SEQ(st, expr, List_elts(e));
 		break;
         case Tuple_kind:
-		VISIT_SEQ(st, expr, e->v.Tuple.elts);
+		VISIT_SEQ(st, expr, Tuple_elts(e));
 		break;
 	}
 	return 1;
@@ -1165,21 +1167,21 @@
 }
 
 static int 
-symtable_visit_params(struct symtable *st, asdl_seq *args, int toplevel)
+symtable_visit_params(struct symtable *st, PyObject *args, int toplevel)
 {
 	int i, complex = 0;
 	
         /* go through all the toplevel arguments first */
-	for (i = 0; i < asdl_seq_LEN(args); i++) {
-		expr_ty arg = asdl_seq_GET(args, i);
-		if (arg->kind == Name_kind) {
-			assert(arg->v.Name.ctx == Param ||
-                               (arg->v.Name.ctx == Store && !toplevel));
-			if (!symtable_add_def(st, arg->v.Name.id, DEF_PARAM))
+	for (i = 0; i < PyList_GET_SIZE(args); i++) {
+		PyObject *arg = PyList_GET_ITEM(args, i);
+		if (expr_kind(arg) == Name_kind) {
+			assert(Name_ctx(arg) == Param ||
+                               (Name_ctx(arg) == Store && !toplevel));
+			if (!symtable_add_def(st, Name_id(arg), DEF_PARAM))
 				return 0;
 		}
-		else if (arg->kind == Tuple_kind) {
-			assert(arg->v.Tuple.ctx == Store);
+		else if (expr_kind(arg) == Tuple_kind) {
+			assert(Tuple_ctx(arg) == Store);
                         complex = 1;
 			if (toplevel) {
 				if (!symtable_implicit_arg(st, i))
@@ -1204,13 +1206,13 @@
 }
 
 static int
-symtable_visit_params_nested(struct symtable *st, asdl_seq *args)
+symtable_visit_params_nested(struct symtable *st, PyObject *args)
 {
 	int i;
-	for (i = 0; i < asdl_seq_LEN(args); i++) {
-		expr_ty arg = asdl_seq_GET(args, i);
-		if (arg->kind == Tuple_kind &&
-		    !symtable_visit_params(st, arg->v.Tuple.elts, 0))
+	for (i = 0; i < PyList_GET_SIZE(args); i++) {
+		PyObject *arg = PyList_GET_ITEM(args, i);
+		if (expr_kind(arg) == Tuple_kind &&
+		    !symtable_visit_params(st, Tuple_elts(arg), 0))
 			return 0;
 	}
 	
@@ -1218,50 +1220,52 @@
 }
 
 static int 
-symtable_visit_arguments(struct symtable *st, arguments_ty a)
+symtable_visit_arguments(struct symtable *st, PyObject *a)
 {
 	/* skip default arguments inside function block
 	   XXX should ast be different?
 	*/
-	if (a->args && !symtable_visit_params(st, a->args, 1))
+	/* if (arguments_args(a) && !symtable_visit_params(st, arguments_args(a), 1)) */
+	if (!symtable_visit_params(st, arguments_args(a), 1))
 		return 0;
-	if (a->vararg) {
-		if (!symtable_add_def(st, a->vararg, DEF_PARAM))
+	if (arguments_vararg(a) != Py_None) {
+		if (!symtable_add_def(st, arguments_vararg(a), DEF_PARAM))
 			return 0;
 		st->st_cur->ste_varargs = 1;
 	}
-	if (a->kwarg) {
-		if (!symtable_add_def(st, a->kwarg, DEF_PARAM))
+	if (arguments_kwarg(a) != Py_None) {
+		if (!symtable_add_def(st, arguments_kwarg(a), DEF_PARAM))
 			return 0;
 		st->st_cur->ste_varkeywords = 1;
 	}
-	if (a->args && !symtable_visit_params_nested(st, a->args))
+	/* if (arguments_args(a) && !symtable_visit_params_nested(st, arguments_args(a))) */
+	if (!symtable_visit_params_nested(st, arguments_args(a)))
 		return 0;
 	return 1;
 }
 
 
 static int 
-symtable_visit_excepthandler(struct symtable *st, excepthandler_ty eh)
+symtable_visit_excepthandler(struct symtable *st, PyObject *eh)
 {
-	if (eh->type)
-		VISIT(st, expr, eh->type);
-	if (eh->name)
-		VISIT(st, expr, eh->name);
-	VISIT_SEQ(st, stmt, eh->body);
+	if (excepthandler_type(eh) != Py_None)
+		VISIT(st, expr, excepthandler_type(eh));
+	if (excepthandler_name(eh) != Py_None)
+		VISIT(st, expr, excepthandler_name(eh));
+	VISIT_SEQ(st, stmt, excepthandler_body(eh));
 	return 1;
 }
 
 
 static int 
-symtable_visit_alias(struct symtable *st, alias_ty a)
+symtable_visit_alias(struct symtable *st, PyObject *a)
 {
 	/* Compute store_name, the name actually bound by the import
-	   operation.  It is diferent than a->name when a->name is a
+	   operation.  It is diferent than alias_name(a) when alias_name(a) is a
 	   dotted package name (e.g. spam.eggs) 
 	*/
 	PyObject *store_name;
-	PyObject *name = (a->asname == NULL) ? a->name : a->asname;
+	PyObject *name = (alias_asname(a) == NULL) ? alias_name(a) : alias_asname(a);
 	const char *base = PyString_AS_STRING(name);
 	char *dot = strchr(base, '.');
 	if (dot)
@@ -1291,40 +1295,40 @@
 
 
 static int 
-symtable_visit_comprehension(struct symtable *st, comprehension_ty lc)
+symtable_visit_comprehension(struct symtable *st, PyObject *lc)
 {
-	VISIT(st, expr, lc->target);
-	VISIT(st, expr, lc->iter);
-	VISIT_SEQ(st, expr, lc->ifs);
+	VISIT(st, expr, comprehension_target(lc));
+	VISIT(st, expr, comprehension_iter(lc));
+	VISIT_SEQ(st, expr, comprehension_ifs(lc));
 	return 1;
 }
 
 
 static int 
-symtable_visit_keyword(struct symtable *st, keyword_ty k)
+symtable_visit_keyword(struct symtable *st, PyObject *k)
 {
-	VISIT(st, expr, k->value);
+	VISIT(st, expr, keyword_value(k));
 	return 1;
 }
 
 
 static int 
-symtable_visit_slice(struct symtable *st, slice_ty s)
+symtable_visit_slice(struct symtable *st, PyObject *s)
 {
-	switch (s->kind) {
+	switch (slice_kind(s)) {
 	case Slice_kind:
-		if (s->v.Slice.lower)
-			VISIT(st, expr, s->v.Slice.lower)
-		if (s->v.Slice.upper)
-			VISIT(st, expr, s->v.Slice.upper)
-		if (s->v.Slice.step)
-			VISIT(st, expr, s->v.Slice.step)
+		if (Slice_lower(s) != Py_None)
+			VISIT(st, expr, Slice_lower(s))
+		if (Slice_upper(s) != Py_None)
+			VISIT(st, expr, Slice_upper(s))
+		if (Slice_step(s) != Py_None)
+			VISIT(st, expr, Slice_step(s))
 		break;
 	case ExtSlice_kind:
-		VISIT_SEQ(st, slice, s->v.ExtSlice.dims)
+		VISIT_SEQ(st, slice, ExtSlice_dims(s))
 		break;
 	case Index_kind:
-		VISIT(st, expr, s->v.Index.value)
+		VISIT(st, expr, Index_value(s))
 		break;
 	case Ellipsis_kind:
 		break;
@@ -1333,12 +1337,12 @@
 }
 
 static int 
-symtable_visit_genexp(struct symtable *st, expr_ty e)
+symtable_visit_genexp(struct symtable *st, PyObject *e)
 {
-	comprehension_ty outermost = ((comprehension_ty)
-			 (asdl_seq_GET(e->v.GeneratorExp.generators, 0)));
+	PyObject *outermost = ((PyObject *)
+			 (PyList_GET_ITEM(GeneratorExp_generators(e), 0)));
 	/* Outermost iterator is evaluated in current scope */
-	VISIT(st, expr, outermost->iter);
+	VISIT(st, expr, comprehension_iter(outermost));
 	/* Create generator scope for the rest */
 	if (!symtable_enter_block(st, GET_IDENTIFIER(genexpr),
 				  FunctionBlock, (void *)e, 0)) {
@@ -1350,11 +1354,11 @@
 		symtable_exit_block(st, (void *)e);
 		return 0;
 	}
-	VISIT_IN_BLOCK(st, expr, outermost->target, (void*)e);
-	VISIT_SEQ_IN_BLOCK(st, expr, outermost->ifs, (void*)e);
+	VISIT_IN_BLOCK(st, expr, comprehension_target(outermost), (void*)e);
+	VISIT_SEQ_IN_BLOCK(st, expr, comprehension_ifs(outermost), (void*)e);
 	VISIT_SEQ_TAIL_IN_BLOCK(st, comprehension,
-				e->v.GeneratorExp.generators, 1, (void*)e);
-	VISIT_IN_BLOCK(st, expr, e->v.GeneratorExp.elt, (void*)e);
+				GeneratorExp_generators(e), 1, (void*)e);
+	VISIT_IN_BLOCK(st, expr, GeneratorExp_elt(e), (void*)e);
 	if (!symtable_exit_block(st, (void *)e))
 		return 0;
 	return 1;


More information about the Python-checkins mailing list