diff --git a/Grammar/Grammar b/Grammar/Grammar index 8464cf2b8a0..cb4bc2718e8 100644 --- a/Grammar/Grammar +++ b/Grammar/Grammar @@ -2,6 +2,12 @@ # Change log: +# 19-May-93: +# Add access statement + +# 18-May-93: +# Abolish old class header syntax + # 06-Apr-92: # Use only '*' for varargs list @@ -81,7 +87,7 @@ fplist: fpdef (',' fpdef)* [','] stmt: simple_stmt | compound_stmt simple_stmt: small_stmt (';' small_stmt)* [';'] NEWLINE -small_stmt: expr_stmt | print_stmt | del_stmt | pass_stmt | flow_stmt | import_stmt | global_stmt +small_stmt: expr_stmt | print_stmt | del_stmt | pass_stmt | flow_stmt | import_stmt | global_stmt | access_stmt expr_stmt: (exprlist '=')* exprlist # For assignments, additional restrictions enforced by the interpreter print_stmt: 'print' (test ',')* [test] @@ -94,6 +100,11 @@ return_stmt: 'return' [testlist] raise_stmt: 'raise' test [',' test] import_stmt: 'import' NAME (',' NAME)* | 'from' NAME 'import' ('*' | NAME (',' NAME)*) global_stmt: 'global' NAME (',' NAME)* +access_stmt: 'access' NAME (',' NAME)* ':' accesstype (',' accesstype)* +accesstype: NAME+ +# accesstype should be ('public' | 'protected' | 'private') ['read'] ['write'] +# but can't be because that would create undesirable reserved words! + compound_stmt: if_stmt | while_stmt | for_stmt | try_stmt | funcdef | classdef if_stmt: 'if' test ':' suite ('elif' test ':' suite)* ['else' ':' suite] while_stmt: 'while' test ':' suite ['else' ':' suite] @@ -122,9 +133,4 @@ exprlist: expr (',' expr)* [','] testlist: test (',' test)* [','] dictmaker: test ':' test (',' test ':' test)* [','] -# New class syntax should be: -# classdef: class NAME ['(' testlist ')'] ':' suite -# but merged with old syntax for compatibility it becomes: -classdef: 'class' NAME ['(' testlist ')' |'(' ')' ['=' baselist]] ':' suite -baselist: atom arguments (',' atom arguments)* -arguments: '(' ')' +classdef: class NAME ['(' testlist ')'] ':' suite diff --git a/Include/allobjects.h b/Include/allobjects.h index d7a03331fc7..859f0b3ca76 100644 --- a/Include/allobjects.h +++ b/Include/allobjects.h @@ -36,6 +36,7 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include "object.h" #include "objimpl.h" +#include "accessobject.h" #include "intobject.h" #include "longobject.h" #include "floatobject.h" diff --git a/Include/classobject.h b/Include/classobject.h index 88b955a4159..b9bbc9b6a7a 100644 --- a/Include/classobject.h +++ b/Include/classobject.h @@ -37,7 +37,7 @@ extern typeobject Classtype, Instancetype, Instancemethodtype; #define is_instancemethodobject(op) ((op)->ob_type == &Instancemethodtype) extern object *newclassobject PROTO((object *, object *, object *)); -extern object *newinstanceobject PROTO((object *)); +extern object *newinstanceobject PROTO((object *, object *)); extern object *newinstancemethodobject PROTO((object *, object *)); extern object *instancemethodgetfunc PROTO((object *)); diff --git a/Include/dictobject.h b/Include/dictobject.h index ce71570ab44..1475f103f33 100644 --- a/Include/dictobject.h +++ b/Include/dictobject.h @@ -33,12 +33,9 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. extern object *dictlookup PROTO((object *dp, char *key)); extern int dictinsert PROTO((object *dp, char *key, object *item)); extern int dictremove PROTO((object *dp, char *key)); -extern char *getdictkey PROTO((object *dp, int i)); -#define getdictsize getmappingsize #define getdictkeys getmappingkeys -#define getdict2key getmappingkey #define dict2lookup mappinglookup #define dict2insert mappinginsert #define dict2remove mappingremove diff --git a/Include/errors.h b/Include/errors.h index f2d7b1acb49..0e5ae9f0af6 100755 --- a/Include/errors.h +++ b/Include/errors.h @@ -33,7 +33,9 @@ void err_clear PROTO((void)); /* Predefined exceptions */ +extern object *AccessError; extern object *AttributeError; +extern object *ConflictError; extern object *EOFError; extern object *IOError; extern object *ImportError; @@ -59,3 +61,5 @@ extern object *err_errno PROTO((object *)); extern void err_input PROTO((int)); extern void err_badcall PROTO((void)); + +extern object *err_getexc PROTO((void)); diff --git a/Include/funcobject.h b/Include/funcobject.h index d24600d8200..e4ed26991fd 100644 --- a/Include/funcobject.h +++ b/Include/funcobject.h @@ -24,6 +24,13 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. /* Function object interface */ +typedef struct { + OB_HEAD + object *func_code; + object *func_globals; + object *func_name; +} funcobject; + extern typeobject Functype; #define is_funcobject(op) ((op)->ob_type == &Functype) diff --git a/Include/graminit.h b/Include/graminit.h index 5aba47d5ee7..0ba02a6da94 100644 --- a/Include/graminit.h +++ b/Include/graminit.h @@ -21,31 +21,31 @@ #define raise_stmt 276 #define import_stmt 277 #define global_stmt 278 -#define compound_stmt 279 -#define if_stmt 280 -#define while_stmt 281 -#define for_stmt 282 -#define try_stmt 283 -#define except_clause 284 -#define suite 285 -#define test 286 -#define and_test 287 -#define not_test 288 -#define comparison 289 -#define comp_op 290 -#define expr 291 -#define xor_expr 292 -#define and_expr 293 -#define shift_expr 294 -#define arith_expr 295 -#define term 296 -#define factor 297 -#define atom 298 -#define trailer 299 -#define subscript 300 -#define exprlist 301 -#define testlist 302 -#define dictmaker 303 -#define classdef 304 -#define baselist 305 -#define arguments 306 +#define access_stmt 279 +#define accesstype 280 +#define compound_stmt 281 +#define if_stmt 282 +#define while_stmt 283 +#define for_stmt 284 +#define try_stmt 285 +#define except_clause 286 +#define suite 287 +#define test 288 +#define and_test 289 +#define not_test 290 +#define comparison 291 +#define comp_op 292 +#define expr 293 +#define xor_expr 294 +#define and_expr 295 +#define shift_expr 296 +#define arith_expr 297 +#define term 298 +#define factor 299 +#define atom 300 +#define trailer 301 +#define subscript 302 +#define exprlist 303 +#define testlist 304 +#define dictmaker 305 +#define classdef 306 diff --git a/Include/mappingobject.h b/Include/mappingobject.h index 83c338078a8..fa7402d563c 100644 --- a/Include/mappingobject.h +++ b/Include/mappingobject.h @@ -22,22 +22,19 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ******************************************************************/ -/* -Mapping object type -- mapping from object to object. -These functions set errno for errors. Functions mappingremove() and -mappinginsert() return nonzero for errors, getmappingsize() returns -1, -the others NULL. A successful call to mappinginsert() calls INCREF() -for the inserted item. -*/ +/* Mapping object type -- mapping from hashable object to object */ extern typeobject Mappingtype; #define is_mappingobject(op) ((op)->ob_type == &Mappingtype) extern object *newmappingobject PROTO((void)); -extern object *mappinglookup PROTO((object *dp, object *key)); -extern int mappinginsert PROTO((object *dp, object *key, object *item)); -extern int mappingremove PROTO((object *dp, object *key)); -extern int getmappingsize PROTO((object *dp)); -extern object *getmappingkey PROTO((object *dp, int i)); -extern object *getmappingkeys PROTO((object *dp)); +extern object *mappinglookup PROTO((object *mp, object *key)); +extern int mappinginsert PROTO((object *mp, object *key, object *item)); +extern int mappingremove PROTO((object *mp, object *key)); +extern void mappingclear PROTO((object *mp)); +extern int mappinggetnext + PROTO((object *mp, int *pos, object **key, object **value)); +extern object *getmappingkeys PROTO((object *mp)); +extern object *getmappingvalues PROTO((object *mp)); +extern object *getmappingitems PROTO((object *mp)); diff --git a/Include/opcode.h b/Include/opcode.h index 0f087605b20..5f5826fd4c0 100644 --- a/Include/opcode.h +++ b/Include/opcode.h @@ -100,6 +100,7 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #define COMPARE_OP 106 /* Comparison operator */ #define IMPORT_NAME 107 /* Index in name list */ #define IMPORT_FROM 108 /* Index in name list */ +#define ACCESS_MODE 109 /* Name (mode is int on top of stack) */ #define JUMP_FORWARD 110 /* Number of bytes to skip */ #define JUMP_IF_FALSE 111 /* "" */ diff --git a/Include/pyerrors.h b/Include/pyerrors.h index f2d7b1acb49..0e5ae9f0af6 100644 --- a/Include/pyerrors.h +++ b/Include/pyerrors.h @@ -33,7 +33,9 @@ void err_clear PROTO((void)); /* Predefined exceptions */ +extern object *AccessError; extern object *AttributeError; +extern object *ConflictError; extern object *EOFError; extern object *IOError; extern object *ImportError; @@ -59,3 +61,5 @@ extern object *err_errno PROTO((object *)); extern void err_input PROTO((int)); extern void err_badcall PROTO((void)); + +extern object *err_getexc PROTO((void)); diff --git a/Objects/classobject.c b/Objects/classobject.c index 587d122aeed..bc61b649c14 100644 --- a/Objects/classobject.c +++ b/Objects/classobject.c @@ -29,9 +29,6 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include "structmember.h" #include "ceval.h" -extern typeobject MappingInstancetype; -extern typeobject SequenceInstancetype; - typedef struct { OB_HEAD object *cl_bases; /* A tuple */ @@ -102,7 +99,10 @@ class_getattr(op, name) } v = dictlookup(op->cl_methods, name); if (v != NULL) { - INCREF(v); + if (is_accessobject(v)) + v = getaccessvalue(v, (object *)NULL); + else + INCREF(v); return v; } { @@ -126,6 +126,7 @@ class_setattr(op, name, v) char *name; object *v; { + object *ac; if (name[0] == '_' && name[1] == '_') { int n = strlen(name); if (name[n-1] == '_' && name[n-2] == '_') { @@ -133,6 +134,9 @@ class_setattr(op, name, v) return -1; } } + ac = dictlookup(op->cl_methods, name); + if (ac != NULL && is_accessobject(ac)) + return setaccessvalue(ac, (object *)NULL, v); if (v == NULL) { int rv = dictremove(op->cl_methods, name); if (rv < 0) @@ -144,6 +148,20 @@ class_setattr(op, name, v) return dictinsert(op->cl_methods, name, v); } +static object * +class_repr(op) + classobject *op; +{ + char buf[140]; + char *name; + if (op->cl_name == NULL || !is_stringobject(op->cl_name)) + name = "?"; + else + name = getstringvalue(op->cl_name); + sprintf(buf, "", name, (long)op); + return newstringobject(buf); +} + typeobject Classtype = { OB_HEAD_INIT(&Typetype) 0, @@ -155,7 +173,7 @@ typeobject Classtype = { class_getattr, /*tp_getattr*/ class_setattr, /*tp_setattr*/ 0, /*tp_compare*/ - 0, /*tp_repr*/ + class_repr, /*tp_repr*/ 0, /*tp_as_number*/ 0, /*tp_as_sequence*/ 0, /*tp_as_mapping*/ @@ -170,12 +188,18 @@ typedef struct { object *in_attr; /* A dictionary */ } instanceobject; +static object *instance_getattr PROTO((instanceobject *, char *)); + object * -newinstanceobject(class) - register object *class; +newinstanceobject(class, arg) + object *class; + object *arg; { register instanceobject *inst; object *v; + object *init; + int pos; + object *key, *value; if (!is_classobject(class)) { err_badcall(); return NULL; @@ -187,9 +211,52 @@ newinstanceobject(class) inst->in_class = (classobject *)class; inst->in_attr = newdictobject(); if (inst->in_attr == NULL) { + error: DECREF(inst); return NULL; } + pos = 0; + while (mappinggetnext(((classobject *)class)->cl_methods, + &pos, &key, &value)) { + if (is_accessobject(value)) { + object *ac = cloneaccessobject(value); + int err; + if (ac == NULL) + goto error; + err = dict2insert(inst->in_attr, key, ac); + DECREF(ac); + if (err) + goto error; + } + } + init = instance_getattr(inst, "__init__"); + if (init == NULL) { + err_clear(); + if (arg != NULL && !(is_tupleobject(arg) && + gettuplesize(arg) == 0)) { + err_setstr(TypeError, + "this classobject() takes no arguments"); + DECREF(inst); + inst = NULL; + } + } + else { + object *res = call_object(init, arg); + DECREF(init); + if (res == NULL) { + DECREF(inst); + inst = NULL; + } + else { + if (res != None) { + err_setstr(TypeError, + "__init__() should return None"); + DECREF(inst); + inst = NULL; + } + DECREF(res); + } + } return (object *)inst; } @@ -199,9 +266,29 @@ static void instance_dealloc(inst) register instanceobject *inst; { + object *error_type, *error_value; + object *del; + /* Call the __del__ method if it exists. First temporarily + revive the object and save the current exception, if any. */ + INCREF(inst); + err_get(&error_type, &error_value); + if ((del = instance_getattr(inst, "__del__")) != NULL) { + object *args = newtupleobject(0); + object *res = args; + if (res != NULL) + res = call_object(del, args); + XDECREF(args); + DECREF(del); + XDECREF(res); + /* XXX If __del__ raised an exception, it is ignored! */ + } + /* Restore the saved exception and undo the temporary revival */ + err_setval(error_type, error_value); + /* Can't use DECREF here, it would cause a recursive call */ + if (--inst->ob_refcnt > 0) + return; /* __del__ added a reference; don't delete now */ DECREF(inst->in_class); - if (inst->in_attr != NULL) - DECREF(inst->in_attr); + XDECREF(inst->in_attr); free((ANY *)inst); } @@ -221,7 +308,10 @@ instance_getattr(inst, name) } v = dictlookup(inst->in_attr, name); if (v != NULL) { - INCREF(v); + if (is_accessobject(v)) + v = getaccessvalue(v, (object *)NULL); + else + INCREF(v); return v; } v = class_getattr(inst->in_class, name); @@ -243,6 +333,7 @@ instance_setattr(inst, name, v) char *name; object *v; { + object *ac; if (name[0] == '_' && name[1] == '_') { int n = strlen(name); if (name[n-1] == '_' && name[n-2] == '_') { @@ -250,6 +341,9 @@ instance_setattr(inst, name, v) return -1; } } + ac = dictlookup(inst->in_attr, name); + if (ac != NULL && is_accessobject(ac)) + return setaccessvalue(ac, (object *)NULL, v); if (v == NULL) { int rv = dictremove(inst->in_attr, name); if (rv < 0) @@ -270,9 +364,15 @@ instance_repr(inst) func = instance_getattr(inst, "__repr__"); if (func == NULL) { - char buf[80]; + char buf[140]; + object *classname = inst->in_class->cl_name; + char *cname; + if (classname != NULL && is_stringobject(classname)) + cname = getstringvalue(classname); + else + cname = "?"; err_clear(); - sprintf(buf, "", (long)inst); + sprintf(buf, "<%.100s instance at %lx>", cname, (long)inst); return newstringobject(buf); } res = call_object(func, (object *)NULL); @@ -773,6 +873,7 @@ typeobject Instancetype = { 0, instance_dealloc, /*tp_dealloc*/ 0, /*tp_print*/ + (object * (*) FPROTO((object *, char *))) instance_getattr, /*tp_getattr*/ instance_setattr, /*tp_setattr*/ instance_compare, /*tp_compare*/ @@ -879,6 +980,28 @@ instancemethod_compare(a, b) return cmp; } +static object * +instancemethod_repr(a) + instancemethodobject *a; +{ + char buf[240]; + object *classname = + ((instanceobject *)(a->im_self))->in_class->cl_name; + object *funcname = ((funcobject *)(a->im_func))->func_name; + char *cname, *fname; + if (classname != NULL && is_stringobject(classname)) + cname = getstringvalue(classname); + else + cname = "?"; + if (funcname != NULL && is_stringobject(funcname)) + fname = getstringvalue(funcname); + else + fname = "?"; + sprintf(buf, "", + fname, cname, (long)a->im_func); + return newstringobject(buf); +} + static long instancemethod_hash(a) instancemethodobject *a; @@ -904,7 +1027,7 @@ typeobject Instancemethodtype = { instancemethod_getattr, /*tp_getattr*/ 0, /*tp_setattr*/ instancemethod_compare, /*tp_compare*/ - 0, /*tp_repr*/ + instancemethod_repr, /*tp_repr*/ 0, /*tp_as_number*/ 0, /*tp_as_sequence*/ 0, /*tp_as_mapping*/ diff --git a/Objects/dictobject.c b/Objects/dictobject.c index fa66a9d73fc..c50b35a335e 100644 --- a/Objects/dictobject.c +++ b/Objects/dictobject.c @@ -307,39 +307,49 @@ mappingremove(op, key) return 0; } -int -getmappingsize(op) - register object *op; +void +mappingclear(op) + object *op; { - if (!is_mappingobject(op)) { - err_badcall(); - return -1; + int i; + register mappingobject *mp; + if (!is_mappingobject(op)) + return; + mp = (mappingobject *)op; + for (i = 0; i < mp->ma_size; i++) { + XDECREF(mp->ma_table[i].me_key); + XDECREF(mp->ma_table[i].me_value); + mp->ma_table[i].me_key = NULL; + mp->ma_table[i].me_value = NULL; } - return ((mappingobject *)op) -> ma_size; + mp->ma_used = 0; } -object * -getmappingkey(op, i) +int +mappinggetnext(op, ppos, pkey, pvalue) object *op; - register int i; + int *ppos; + object **pkey; + object **pvalue; { - /* XXX This can't return errors since its callers assume - that NULL means there was no key at that point */ + int i; register mappingobject *mp; - if (!is_mappingobject(op)) { - /* err_badcall(); */ - return NULL; - } + if (!is_dictobject(op)) + return 0; mp = (mappingobject *)op; - if (i < 0 || i >= mp->ma_size) { - /* err_badarg(); */ - return NULL; - } - if (mp->ma_table[i].me_value == NULL) { - /* Not an error! */ - return NULL; - } - return (object *) mp->ma_table[i].me_key; + i = *ppos; + if (i < 0) + return 0; + while (i < mp->ma_size && mp->ma_table[i].me_value == NULL) + i++; + *ppos = i+1; + if (i >= mp->ma_size) + return 0; + if (pkey) + *pkey = mp->ma_table[i].me_key; + if (pvalue) + *pvalue = mp->ma_table[i].me_value; + return 1; } /* Methods */ @@ -488,6 +498,61 @@ mapping_keys(mp, args) return v; } +static object * +mapping_values(mp, args) + register mappingobject *mp; + object *args; +{ + register object *v; + register int i, j; + if (!getnoarg(args)) + return NULL; + v = newlistobject(mp->ma_used); + if (v == NULL) + return NULL; + for (i = 0, j = 0; i < mp->ma_size; i++) { + if (mp->ma_table[i].me_value != NULL) { + object *value = mp->ma_table[i].me_value; + INCREF(value); + setlistitem(v, j, value); + j++; + } + } + return v; +} + +static object * +mapping_items(mp, args) + register mappingobject *mp; + object *args; +{ + register object *v; + register int i, j; + if (!getnoarg(args)) + return NULL; + v = newlistobject(mp->ma_used); + if (v == NULL) + return NULL; + for (i = 0, j = 0; i < mp->ma_size; i++) { + if (mp->ma_table[i].me_value != NULL) { + object *key = mp->ma_table[i].me_key; + object *value = mp->ma_table[i].me_value; + object *item = newtupleobject(2); + if (item == NULL) { + DECREF(v); + return NULL; + } + INCREF(key); + settupleitem(item, 0, key); + INCREF(value); + settupleitem(item, 1, value); + setlistitem(v, j, item); + j++; + } + } + return v; +} + object * getmappingkeys(mp) object *mp; @@ -499,6 +564,28 @@ getmappingkeys(mp) return mapping_keys((mappingobject *)mp, (object *)NULL); } +object * +getmappingvalues(mp) + object *mp; +{ + if (mp == NULL || !is_mappingobject(mp)) { + err_badcall(); + return NULL; + } + return mapping_values((mappingobject *)mp, (object *)NULL); +} + +object * +getmappingitems(mp) + object *mp; +{ + if (mp == NULL || !is_mappingobject(mp)) { + err_badcall(); + return NULL; + } + return mapping_values((mappingobject *)mp, (object *)NULL); +} + static int mapping_compare(a, b) mappingobject *a, *b; @@ -582,8 +669,10 @@ mapping_has_key(mp, args) } static struct methodlist mapp_methods[] = { - {"keys", mapping_keys}, {"has_key", mapping_has_key}, + {"items", mapping_items}, + {"keys", mapping_keys}, + {"values", mapping_values}, {NULL, NULL} /* sentinel */ }; @@ -697,14 +786,3 @@ dictremove(v, key) } return mappingremove(v, last_name_object); } - -char * -getdictkey(v, i) - object *v; - int i; -{ - object *key = getmappingkey(v, i); - if (key == NULL) - return NULL; - return getstringvalue(key); -} diff --git a/Objects/funcobject.c b/Objects/funcobject.c index ccf1b29fda6..cf08af738d2 100644 --- a/Objects/funcobject.c +++ b/Objects/funcobject.c @@ -28,12 +28,6 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include "compile.h" #include "structmember.h" -typedef struct { - OB_HEAD - object *func_code; - object *func_globals; -} funcobject; - object * newfuncobject(code, globals) object *code; @@ -45,6 +39,8 @@ newfuncobject(code, globals) op->func_code = code; INCREF(globals); op->func_globals = globals; + op->func_name = ((codeobject*)(op->func_code))->co_name; + INCREF(op->func_name); } return (object *)op; } @@ -78,6 +74,7 @@ getfuncglobals(op) static struct memberlist func_memberlist[] = { {"func_code", T_OBJECT, OFF(func_code), READONLY}, {"func_globals",T_OBJECT, OFF(func_globals), READONLY}, + {"func_name", T_OBJECT, OFF(func_name), READONLY}, {NULL} /* Sentinel */ }; @@ -104,7 +101,7 @@ func_repr(op) { char buf[140]; sprintf(buf, "", - getstringvalue(((codeobject*)(op->func_code))->co_name), + getstringvalue(op->func_name), (long)op); return newstringobject(buf); } diff --git a/Objects/mappingobject.c b/Objects/mappingobject.c index fa66a9d73fc..c50b35a335e 100644 --- a/Objects/mappingobject.c +++ b/Objects/mappingobject.c @@ -307,39 +307,49 @@ mappingremove(op, key) return 0; } -int -getmappingsize(op) - register object *op; +void +mappingclear(op) + object *op; { - if (!is_mappingobject(op)) { - err_badcall(); - return -1; + int i; + register mappingobject *mp; + if (!is_mappingobject(op)) + return; + mp = (mappingobject *)op; + for (i = 0; i < mp->ma_size; i++) { + XDECREF(mp->ma_table[i].me_key); + XDECREF(mp->ma_table[i].me_value); + mp->ma_table[i].me_key = NULL; + mp->ma_table[i].me_value = NULL; } - return ((mappingobject *)op) -> ma_size; + mp->ma_used = 0; } -object * -getmappingkey(op, i) +int +mappinggetnext(op, ppos, pkey, pvalue) object *op; - register int i; + int *ppos; + object **pkey; + object **pvalue; { - /* XXX This can't return errors since its callers assume - that NULL means there was no key at that point */ + int i; register mappingobject *mp; - if (!is_mappingobject(op)) { - /* err_badcall(); */ - return NULL; - } + if (!is_dictobject(op)) + return 0; mp = (mappingobject *)op; - if (i < 0 || i >= mp->ma_size) { - /* err_badarg(); */ - return NULL; - } - if (mp->ma_table[i].me_value == NULL) { - /* Not an error! */ - return NULL; - } - return (object *) mp->ma_table[i].me_key; + i = *ppos; + if (i < 0) + return 0; + while (i < mp->ma_size && mp->ma_table[i].me_value == NULL) + i++; + *ppos = i+1; + if (i >= mp->ma_size) + return 0; + if (pkey) + *pkey = mp->ma_table[i].me_key; + if (pvalue) + *pvalue = mp->ma_table[i].me_value; + return 1; } /* Methods */ @@ -488,6 +498,61 @@ mapping_keys(mp, args) return v; } +static object * +mapping_values(mp, args) + register mappingobject *mp; + object *args; +{ + register object *v; + register int i, j; + if (!getnoarg(args)) + return NULL; + v = newlistobject(mp->ma_used); + if (v == NULL) + return NULL; + for (i = 0, j = 0; i < mp->ma_size; i++) { + if (mp->ma_table[i].me_value != NULL) { + object *value = mp->ma_table[i].me_value; + INCREF(value); + setlistitem(v, j, value); + j++; + } + } + return v; +} + +static object * +mapping_items(mp, args) + register mappingobject *mp; + object *args; +{ + register object *v; + register int i, j; + if (!getnoarg(args)) + return NULL; + v = newlistobject(mp->ma_used); + if (v == NULL) + return NULL; + for (i = 0, j = 0; i < mp->ma_size; i++) { + if (mp->ma_table[i].me_value != NULL) { + object *key = mp->ma_table[i].me_key; + object *value = mp->ma_table[i].me_value; + object *item = newtupleobject(2); + if (item == NULL) { + DECREF(v); + return NULL; + } + INCREF(key); + settupleitem(item, 0, key); + INCREF(value); + settupleitem(item, 1, value); + setlistitem(v, j, item); + j++; + } + } + return v; +} + object * getmappingkeys(mp) object *mp; @@ -499,6 +564,28 @@ getmappingkeys(mp) return mapping_keys((mappingobject *)mp, (object *)NULL); } +object * +getmappingvalues(mp) + object *mp; +{ + if (mp == NULL || !is_mappingobject(mp)) { + err_badcall(); + return NULL; + } + return mapping_values((mappingobject *)mp, (object *)NULL); +} + +object * +getmappingitems(mp) + object *mp; +{ + if (mp == NULL || !is_mappingobject(mp)) { + err_badcall(); + return NULL; + } + return mapping_values((mappingobject *)mp, (object *)NULL); +} + static int mapping_compare(a, b) mappingobject *a, *b; @@ -582,8 +669,10 @@ mapping_has_key(mp, args) } static struct methodlist mapp_methods[] = { - {"keys", mapping_keys}, {"has_key", mapping_has_key}, + {"items", mapping_items}, + {"keys", mapping_keys}, + {"values", mapping_values}, {NULL, NULL} /* sentinel */ }; @@ -697,14 +786,3 @@ dictremove(v, key) } return mappingremove(v, last_name_object); } - -char * -getdictkey(v, i) - object *v; - int i; -{ - object *key = getmappingkey(v, i); - if (key == NULL) - return NULL; - return getstringvalue(key); -} diff --git a/Objects/moduleobject.c b/Objects/moduleobject.c index 749d872b259..8949c7d44b8 100644 --- a/Objects/moduleobject.c +++ b/Objects/moduleobject.c @@ -109,8 +109,12 @@ module_getattr(m, name) res = dictlookup(m->md_dict, name); if (res == NULL) err_setstr(AttributeError, name); - else - INCREF(res); + else { + if (is_accessobject(res)) + res = getaccessvalue(res, (object *)NULL); + else + INCREF(res); + } return res; } @@ -120,10 +124,17 @@ module_setattr(m, name, v) char *name; object *v; { - if (strcmp(name, "__dict__") == 0 || strcmp(name, "__name__") == 0) { - err_setstr(TypeError, "read-only special attribute"); - return -1; + object *ac; + if (name[0] == '_' && name[1] == '_') { + int n = strlen(name); + if (name[n-1] == '_' && name[n-2] == '_') { + err_setstr(TypeError, "read-only special attribute"); + return -1; + } } + ac = dictlookup(m->md_dict, name); + if (ac != NULL && is_accessobject(ac)) + return setaccessvalue(ac, (object *)NULL, v); if (v == NULL) { int rv = dictremove(m->md_dict, name); if (rv < 0) diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c index b74b9cc0282..3d9504bedcd 100644 --- a/Python/bltinmodule.c +++ b/Python/bltinmodule.c @@ -796,7 +796,9 @@ getbuiltin(name) /* Predefined exceptions */ +object *AccessError; object *AttributeError; +object *ConflictError; object *EOFError; object *IOError; object *ImportError; @@ -827,7 +829,9 @@ newstdexception(name) static void initerrors() { + AccessError = newstdexception("AccessError"); AttributeError = newstdexception("AttributeError"); + ConflictError = newstdexception("ConflictError"); EOFError = newstdexception("EOFError"); IOError = newstdexception("IOError"); ImportError = newstdexception("ImportError"); diff --git a/Python/ceval.c b/Python/ceval.c index 44239e6c6fc..57abda606a0 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -84,9 +84,10 @@ static int cmp_exception PROTO((object *, object *)); static int cmp_member PROTO((object *, object *)); static object *cmp_outcome PROTO((int, object *, object *)); static int import_from PROTO((object *, object *, object *)); -static object *build_class PROTO((object *, object *)); +static object *build_class PROTO((object *, object *, object *)); static void locals_2_fast PROTO((frameobject *, int)); static void fast_2_locals PROTO((frameobject *)); +static int access_statement PROTO((object *, int, frameobject *)); /* Pointer to current frame, used to link new frames to */ @@ -743,10 +744,12 @@ eval_code(co, globals, locals, arg) break; case BUILD_CLASS: - w = POP(); + u = POP(); v = POP(); - x = build_class(v, w); + w = POP(); + x = build_class(u, v, w); PUSH(x); + DECREF(u); DECREF(v); DECREF(w); break; @@ -754,12 +757,24 @@ eval_code(co, globals, locals, arg) case STORE_NAME: w = GETNAMEV(oparg); v = POP(); + u = dict2lookup(f->f_locals, w); + if (u != NULL && is_accessobject(u)) { + err = setaccessvalue(u, (object *)NULL, v); + DECREF(v); + break; + } err = dict2insert(f->f_locals, w, v); DECREF(v); break; case DELETE_NAME: w = GETNAMEV(oparg); + u = dict2lookup(f->f_locals, w); + if (u != NULL && is_accessobject(u)) { + err = setaccessvalue(u, (object *)NULL, + (object *)NULL); + break; + } if ((err = dict2remove(f->f_locals, w)) != 0) err_setstr(NameError, getstringvalue(w)); break; @@ -952,12 +967,24 @@ eval_code(co, globals, locals, arg) case STORE_GLOBAL: w = GETNAMEV(oparg); v = POP(); + u = dict2lookup(f->f_locals, w); + if (u != NULL && is_accessobject(u)) { + err = setaccessvalue(u, (object *)NULL, v); + DECREF(v); + break; + } err = dict2insert(f->f_globals, w, v); DECREF(v); break; case DELETE_GLOBAL: w = GETNAMEV(oparg); + u = dict2lookup(f->f_locals, w); + if (u != NULL && is_accessobject(u)) { + err = setaccessvalue(u, (object *)NULL, + (object *)NULL); + break; + } if ((err = dict2remove(f->f_globals, w)) != 0) err_setstr(NameError, getstringvalue(w)); break; @@ -984,6 +1011,11 @@ eval_code(co, globals, locals, arg) } } } + if (is_accessobject(x)) { + x = getaccessvalue(x, (object *)NULL); + if (x == NULL) + break; + } INCREF(x); PUSH(x); break; @@ -1000,6 +1032,11 @@ eval_code(co, globals, locals, arg) break; } } + if (is_accessobject(x)) { + x = getaccessvalue(x, (object *)NULL); + if (x == NULL) + break; + } INCREF(x); PUSH(x); break; @@ -1011,6 +1048,11 @@ eval_code(co, globals, locals, arg) err_setstr(NameError, getstringvalue(w)); break; } + if (is_accessobject(x)) { + x = getaccessvalue(x, (object *)NULL); + if (x == NULL) + break; + } INCREF(x); PUSH(x); break; @@ -1041,15 +1083,25 @@ eval_code(co, globals, locals, arg) "undefined local variable"); break; } + if (is_accessobject(x)) { + x = getaccessvalue(x, (object *)NULL); + if (x == NULL) + break; + } INCREF(x); PUSH(x); break; case STORE_FAST: + v = POP(); w = GETLISTITEM(fastlocals, oparg); + if (w != NULL && is_accessobject(w)) { + err = setaccessvalue(w, (object *)NULL, v); + DECREF(v); + break; + } XDECREF(w); - w = POP(); - GETLISTITEM(fastlocals, oparg) = w; + GETLISTITEM(fastlocals, oparg) = v; break; case DELETE_FAST: @@ -1059,6 +1111,11 @@ eval_code(co, globals, locals, arg) "undefined local variable"); break; } + if (w != NULL && is_accessobject(w)) { + err = setaccessvalue(w, (object *)NULL, + (object *)NULL); + break; + } DECREF(x); GETLISTITEM(fastlocals, oparg) = NULL; break; @@ -1124,6 +1181,13 @@ eval_code(co, globals, locals, arg) err = import_from(f->f_locals, v, w); locals_2_fast(f, 0); break; + + case ACCESS_MODE: + v = POP(); + w = GETNAMEV(oparg); + err = access_statement(w, (int)getintvalue(v), f); + DECREF(v); + break; case JUMP_FORWARD: JUMPBY(oparg); @@ -1483,7 +1547,8 @@ fast_2_locals(f) /* Merge f->f_fastlocals into f->f_locals */ object *locals, *fast, *map; object *error_type, *error_value; - int i; + int pos; + object *key, *value; if (f == NULL) return; locals = f->f_locals; @@ -1495,16 +1560,10 @@ fast_2_locals(f) !is_dictobject(map)) return; err_get(&error_type, &error_value); - i = getdictsize(map); - while (--i >= 0) { - object *key; - object *value; + pos = 0; + while (mappinggetnext(map, &pos, &key, &value)) { int j; - key = getdict2key(map, i); - if (key == NULL) - continue; - value = dict2lookup(map, key); - if (value == NULL || !is_intobject(value)) + if (!is_intobject(value)) continue; j = getintvalue(value); value = getlistitem(fast, j); @@ -1529,7 +1588,8 @@ locals_2_fast(f, clear) /* Merge f->f_locals into f->f_fastlocals */ object *locals, *fast, *map; object *error_type, *error_value; - int i; + int pos; + object *key, *value; if (f == NULL) return; locals = f->f_locals; @@ -1541,16 +1601,10 @@ locals_2_fast(f, clear) !is_dictobject(map)) return; err_get(&error_type, &error_value); - i = getdictsize(map); - while (--i >= 0) { - object *key; - object *value; + pos = 0; + while (mappinggetnext(map, &pos, &key, &value)) { int j; - key = getdict2key(map, i); - if (key == NULL) - continue; - value = dict2lookup(map, key); - if (value == NULL || !is_intobject(value)) + if (!is_intobject(value)) continue; j = getintvalue(value); value = dict2lookup(locals, key); @@ -1907,14 +1961,7 @@ call_builtin(func, arg) return (*meth)(self, arg); } if (is_classobject(func)) { - if (arg != NULL && - !(is_tupleobject(arg) && - gettuplesize(arg) == 0)) { - err_setstr(TypeError, - "classobject() allows no arguments"); - return NULL; - } - return newinstanceobject(func); + return newinstanceobject(func, arg); } err_setstr(TypeError, "call of non-function"); return NULL; @@ -2258,19 +2305,14 @@ import_from(locals, v, name) object *w, *x; w = getmoduledict(v); if (getstringvalue(name)[0] == '*') { - int i; - int n = getdictsize(w); - for (i = 0; i < n; i++) { - name = getdict2key(w, i); - if (name == NULL || getstringvalue(name)[0] == '_') + int pos; + object *name, *value; + pos = 0; + while (mappinggetnext(w, &pos, &name, &value)) { + if (!is_stringobject(name) || + getstringvalue(name)[0] == '_') continue; - x = dict2lookup(w, name); - if (x == NULL) { - /* XXX can't happen? */ - err_setstr(SystemError, getstringvalue(name)); - return -1; - } - if (dict2insert(locals, name, x) != 0) + if (dict2insert(locals, name, value) != 0) return -1; } return 0; @@ -2290,27 +2332,74 @@ import_from(locals, v, name) } static object * -build_class(v, w) - object *v; /* None or tuple containing base classes */ - object *w; /* dictionary */ +build_class(methods, bases, name) + object *methods; /* dictionary */ + object *bases; /* tuple containing classes */ + object *name; /* string */ { - if (is_tupleobject(v)) { - int i; - for (i = gettuplesize(v); --i >= 0; ) { - object *x = gettupleitem(v, i); - if (!is_classobject(x)) { - err_setstr(TypeError, - "base is not a class object"); - return NULL; - } - } + int i; + if (!is_tupleobject(bases)) { + err_setstr(SystemError, "build_class with non-tuple bases"); + return NULL; } - else { - v = NULL; - } - if (!is_dictobject(w)) { + if (!is_dictobject(methods)) { err_setstr(SystemError, "build_class with non-dictionary"); return NULL; } - return newclassobject(v, w, (object *) NULL); + if (!is_stringobject(name)) { + err_setstr(SystemError, "build_class witn non-string name"); + return NULL; + } + for (i = gettuplesize(bases); --i >= 0; ) { + object *base = gettupleitem(bases, i); + if (!is_classobject(base)) { + err_setstr(TypeError, + "base is not a class object"); + return NULL; + } + } + return newclassobject(bases, methods, name); +} + +static int +access_statement(name, mode, f) + object *name; + int mode; + frameobject *f; +{ + object *value; + int i = -1; + object *ac; + int ret; + if (f->f_localmap == NULL) + value = dict2lookup(f->f_locals, name); + else { + value = dict2lookup(f->f_localmap, name); + if (value == NULL || !is_intobject(value)) + value = NULL; + else { + i = getintvalue(value); + if (0 <= i && i < getlistsize(f->f_fastlocals)) + value = getlistitem(f->f_fastlocals, i); + else { + value = NULL; + i = -1; + } + } + } + if (value && is_accessobject(value)) { + err_setstr(AccessError, "can't override access"); + return -1; + } + err_clear(); + ac = newaccessobject(value, (object*)NULL, (typeobject*)NULL, mode); + if (ac == NULL) + return -1; + if (i >= 0) + ret = setlistitem(f->f_fastlocals, i, ac); + else { + ret = dict2insert(f->f_locals, name, ac); + DECREF(ac); + } + return ret; } diff --git a/Python/compile.c b/Python/compile.c index dd7993707e1..d9d661cbac6 100644 --- a/Python/compile.c +++ b/Python/compile.c @@ -1408,6 +1408,65 @@ com_global_stmt(c, n) } } +#define strequ(a, b) (strcmp((a), (b)) == 0) + +static void +com_access_stmt(c, n) + struct compiling *c; + node *n; +{ + int i, j, k, mode, imode; + object *vmode; + REQ(n, access_stmt); + /* 'access' NAME (',' NAME)* ':' accesstype (',' accesstype)* + accesstype: NAME+ */ + + /* Find where the colon is */ + i = 1; + while (TYPE(CHILD(n,i-1)) != COLON) + i += 1; + + /* Calculate the mode mask */ + mode = 0; + for (j = i; j < NCH(n); j += 2) { + int r=0,w=0,p=0; + for (k=0; kc_errors++; + return; + } + /* Push the class name on the stack */ + i = com_addconst(c, v); + com_addoparg(c, LOAD_CONST, i); + DECREF(v); + /* Push the tuple of base classes on the stack */ + if (TYPE(CHILD(n, 2)) != LPAR) com_addoparg(c, BUILD_TUPLE, 0); - } - else { - if (TYPE(CHILD(n, 3)) == RPAR) { - /* Old syntax with or without base classes: - class NAME '(' ')' ['=' baselist] ':' suite - _______________^....^...^ - */ - if (TYPE(CHILD(n, 4)) == EQUAL) - com_oldbases(c, CHILD(n, 5)); - else - com_addoparg(c, BUILD_TUPLE, 0); - } - else { - /* New syntax with base classes: - class NAME '(' testlist ')' ':' suite - _______________^ - */ - com_newbases(c, CHILD(n, 3)); - } - } + else + com_bases(c, CHILD(n, 3)); v = (object *)compile(n, c->c_filename); if (v == NULL) c->c_errors++; else { - int i = com_addconst(c, v); + i = com_addconst(c, v); com_addoparg(c, LOAD_CONST, i); com_addbyte(c, BUILD_FUNCTION); com_addbyte(c, UNARY_CALL); @@ -1882,6 +1907,9 @@ com_node(c, n) case global_stmt: com_global_stmt(c, n); break; + case access_stmt: + com_access_stmt(c, n); + break; case if_stmt: com_if_stmt(c, n); break; @@ -2084,9 +2112,8 @@ compile_node(c, n) break; case classdef: /* A class definition */ - /* classdef: 'class' NAME - ['(' testlist ')' |'(' ')' ['=' baselist]] - ':' suite */ + /* classdef: 'class' NAME ['(' testlist ')'] ':' suite */ + c->c_name = STR(CHILD(n, 1)); com_node(c, CHILD(n, NCH(n)-1)); /* The suite */ com_addbyte(c, LOAD_LOCALS); com_addbyte(c, RETURN_VALUE); @@ -2114,8 +2141,8 @@ compile_node(c, n) There is one problem: 'from foo import *' introduces local variables that we can't know while compiling. If this is the case, wo don't - optimize at all (this rarely happens, since import is mostly used - at the module level). + optimize at all (this rarely happens, since this form of import + statement is mostly used at the module level). Note that, because of this optimization, code like the following won't work: diff --git a/Python/graminit.c b/Python/graminit.c index 571a835a4f8..530ddf3f09a 100644 --- a/Python/graminit.c +++ b/Python/graminit.c @@ -194,7 +194,7 @@ static state states_10[4] = { {2, arcs_10_2}, {1, arcs_10_3}, }; -static arc arcs_11_0[7] = { +static arc arcs_11_0[8] = { {26, 1}, {27, 1}, {28, 1}, @@ -202,19 +202,20 @@ static arc arcs_11_0[7] = { {30, 1}, {31, 1}, {32, 1}, + {33, 1}, }; static arc arcs_11_1[1] = { {0, 1}, }; static state states_11[2] = { - {7, arcs_11_0}, + {8, arcs_11_0}, {1, arcs_11_1}, }; static arc arcs_12_0[1] = { - {33, 1}, + {34, 1}, }; static arc arcs_12_1[2] = { - {34, 0}, + {35, 0}, {0, 1}, }; static state states_12[2] = { @@ -222,10 +223,10 @@ static state states_12[2] = { {2, arcs_12_1}, }; static arc arcs_13_0[1] = { - {35, 1}, + {36, 1}, }; static arc arcs_13_1[2] = { - {36, 2}, + {37, 2}, {0, 1}, }; static arc arcs_13_2[2] = { @@ -238,10 +239,10 @@ static state states_13[3] = { {2, arcs_13_2}, }; static arc arcs_14_0[1] = { - {37, 1}, + {38, 1}, }; static arc arcs_14_1[1] = { - {33, 2}, + {34, 2}, }; static arc arcs_14_2[1] = { {0, 2}, @@ -252,7 +253,7 @@ static state states_14[3] = { {1, arcs_14_2}, }; static arc arcs_15_0[1] = { - {38, 1}, + {39, 1}, }; static arc arcs_15_1[1] = { {0, 1}, @@ -262,10 +263,10 @@ static state states_15[2] = { {1, arcs_15_1}, }; static arc arcs_16_0[4] = { - {39, 1}, {40, 1}, {41, 1}, {42, 1}, + {43, 1}, }; static arc arcs_16_1[1] = { {0, 1}, @@ -275,7 +276,7 @@ static state states_16[2] = { {1, arcs_16_1}, }; static arc arcs_17_0[1] = { - {43, 1}, + {44, 1}, }; static arc arcs_17_1[1] = { {0, 1}, @@ -285,7 +286,7 @@ static state states_17[2] = { {1, arcs_17_1}, }; static arc arcs_18_0[1] = { - {44, 1}, + {45, 1}, }; static arc arcs_18_1[1] = { {0, 1}, @@ -295,7 +296,7 @@ static state states_18[2] = { {1, arcs_18_1}, }; static arc arcs_19_0[1] = { - {45, 1}, + {46, 1}, }; static arc arcs_19_1[2] = { {9, 2}, @@ -310,17 +311,17 @@ static state states_19[3] = { {1, arcs_19_2}, }; static arc arcs_20_0[1] = { - {46, 1}, + {47, 1}, }; static arc arcs_20_1[1] = { - {36, 2}, + {37, 2}, }; static arc arcs_20_2[2] = { {21, 3}, {0, 2}, }; static arc arcs_20_3[1] = { - {36, 4}, + {37, 4}, }; static arc arcs_20_4[1] = { {0, 4}, @@ -333,8 +334,8 @@ static state states_20[5] = { {1, arcs_20_4}, }; static arc arcs_21_0[2] = { - {47, 1}, - {48, 2}, + {48, 1}, + {49, 2}, }; static arc arcs_21_1[1] = { {13, 3}, @@ -347,7 +348,7 @@ static arc arcs_21_3[2] = { {0, 3}, }; static arc arcs_21_4[1] = { - {47, 5}, + {48, 5}, }; static arc arcs_21_5[2] = { {22, 6}, @@ -375,7 +376,7 @@ static state states_21[9] = { {1, arcs_21_8}, }; static arc arcs_22_0[1] = { - {49, 1}, + {50, 1}, }; static arc arcs_22_1[1] = { {13, 2}, @@ -389,330 +390,343 @@ static state states_22[3] = { {1, arcs_22_1}, {2, arcs_22_2}, }; -static arc arcs_23_0[6] = { - {50, 1}, +static arc arcs_23_0[1] = { {51, 1}, - {52, 1}, - {53, 1}, - {11, 1}, - {54, 1}, }; static arc arcs_23_1[1] = { - {0, 1}, + {13, 2}, }; -static state states_23[2] = { - {6, arcs_23_0}, +static arc arcs_23_2[2] = { + {21, 1}, + {15, 3}, +}; +static arc arcs_23_3[1] = { + {52, 4}, +}; +static arc arcs_23_4[2] = { + {21, 3}, + {0, 4}, +}; +static state states_23[5] = { + {1, arcs_23_0}, {1, arcs_23_1}, + {2, arcs_23_2}, + {1, arcs_23_3}, + {2, arcs_23_4}, }; static arc arcs_24_0[1] = { - {55, 1}, + {13, 1}, }; -static arc arcs_24_1[1] = { - {36, 2}, +static arc arcs_24_1[2] = { + {13, 1}, + {0, 1}, }; -static arc arcs_24_2[1] = { - {15, 3}, -}; -static arc arcs_24_3[1] = { - {16, 4}, -}; -static arc arcs_24_4[3] = { - {56, 1}, - {57, 5}, - {0, 4}, -}; -static arc arcs_24_5[1] = { - {15, 6}, -}; -static arc arcs_24_6[1] = { - {16, 7}, -}; -static arc arcs_24_7[1] = { - {0, 7}, -}; -static state states_24[8] = { +static state states_24[2] = { {1, arcs_24_0}, - {1, arcs_24_1}, - {1, arcs_24_2}, - {1, arcs_24_3}, - {3, arcs_24_4}, - {1, arcs_24_5}, - {1, arcs_24_6}, - {1, arcs_24_7}, + {2, arcs_24_1}, }; -static arc arcs_25_0[1] = { - {58, 1}, +static arc arcs_25_0[6] = { + {53, 1}, + {54, 1}, + {55, 1}, + {56, 1}, + {11, 1}, + {57, 1}, }; static arc arcs_25_1[1] = { - {36, 2}, + {0, 1}, }; -static arc arcs_25_2[1] = { - {15, 3}, -}; -static arc arcs_25_3[1] = { - {16, 4}, -}; -static arc arcs_25_4[2] = { - {57, 5}, - {0, 4}, -}; -static arc arcs_25_5[1] = { - {15, 6}, -}; -static arc arcs_25_6[1] = { - {16, 7}, -}; -static arc arcs_25_7[1] = { - {0, 7}, -}; -static state states_25[8] = { - {1, arcs_25_0}, +static state states_25[2] = { + {6, arcs_25_0}, {1, arcs_25_1}, - {1, arcs_25_2}, - {1, arcs_25_3}, - {2, arcs_25_4}, - {1, arcs_25_5}, - {1, arcs_25_6}, - {1, arcs_25_7}, }; static arc arcs_26_0[1] = { - {59, 1}, + {58, 1}, }; static arc arcs_26_1[1] = { - {33, 2}, + {37, 2}, }; static arc arcs_26_2[1] = { - {60, 3}, + {15, 3}, }; static arc arcs_26_3[1] = { - {9, 4}, + {16, 4}, }; -static arc arcs_26_4[1] = { - {15, 5}, +static arc arcs_26_4[3] = { + {59, 1}, + {60, 5}, + {0, 4}, }; static arc arcs_26_5[1] = { - {16, 6}, + {15, 6}, }; -static arc arcs_26_6[2] = { - {57, 7}, - {0, 6}, +static arc arcs_26_6[1] = { + {16, 7}, }; static arc arcs_26_7[1] = { - {15, 8}, + {0, 7}, }; -static arc arcs_26_8[1] = { - {16, 9}, -}; -static arc arcs_26_9[1] = { - {0, 9}, -}; -static state states_26[10] = { +static state states_26[8] = { {1, arcs_26_0}, {1, arcs_26_1}, {1, arcs_26_2}, {1, arcs_26_3}, - {1, arcs_26_4}, + {3, arcs_26_4}, {1, arcs_26_5}, - {2, arcs_26_6}, + {1, arcs_26_6}, {1, arcs_26_7}, - {1, arcs_26_8}, - {1, arcs_26_9}, }; static arc arcs_27_0[1] = { {61, 1}, }; static arc arcs_27_1[1] = { - {15, 2}, + {37, 2}, }; static arc arcs_27_2[1] = { - {16, 3}, + {15, 3}, }; -static arc arcs_27_3[2] = { - {62, 4}, - {63, 5}, +static arc arcs_27_3[1] = { + {16, 4}, }; -static arc arcs_27_4[1] = { - {15, 6}, +static arc arcs_27_4[2] = { + {60, 5}, + {0, 4}, }; static arc arcs_27_5[1] = { - {15, 7}, + {15, 6}, }; static arc arcs_27_6[1] = { - {16, 8}, + {16, 7}, }; static arc arcs_27_7[1] = { - {16, 9}, + {0, 7}, }; -static arc arcs_27_8[2] = { - {62, 4}, - {0, 8}, -}; -static arc arcs_27_9[1] = { - {0, 9}, -}; -static state states_27[10] = { +static state states_27[8] = { {1, arcs_27_0}, {1, arcs_27_1}, {1, arcs_27_2}, - {2, arcs_27_3}, - {1, arcs_27_4}, + {1, arcs_27_3}, + {2, arcs_27_4}, {1, arcs_27_5}, {1, arcs_27_6}, {1, arcs_27_7}, - {2, arcs_27_8}, - {1, arcs_27_9}, }; static arc arcs_28_0[1] = { - {64, 1}, + {62, 1}, }; -static arc arcs_28_1[2] = { - {36, 2}, - {0, 1}, +static arc arcs_28_1[1] = { + {34, 2}, }; -static arc arcs_28_2[2] = { - {21, 3}, - {0, 2}, +static arc arcs_28_2[1] = { + {63, 3}, }; static arc arcs_28_3[1] = { - {36, 4}, + {9, 4}, }; static arc arcs_28_4[1] = { - {0, 4}, + {15, 5}, }; -static state states_28[5] = { +static arc arcs_28_5[1] = { + {16, 6}, +}; +static arc arcs_28_6[2] = { + {60, 7}, + {0, 6}, +}; +static arc arcs_28_7[1] = { + {15, 8}, +}; +static arc arcs_28_8[1] = { + {16, 9}, +}; +static arc arcs_28_9[1] = { + {0, 9}, +}; +static state states_28[10] = { {1, arcs_28_0}, - {2, arcs_28_1}, - {2, arcs_28_2}, + {1, arcs_28_1}, + {1, arcs_28_2}, {1, arcs_28_3}, {1, arcs_28_4}, + {1, arcs_28_5}, + {2, arcs_28_6}, + {1, arcs_28_7}, + {1, arcs_28_8}, + {1, arcs_28_9}, }; -static arc arcs_29_0[2] = { - {3, 1}, - {2, 2}, +static arc arcs_29_0[1] = { + {64, 1}, }; static arc arcs_29_1[1] = { - {0, 1}, + {15, 2}, }; static arc arcs_29_2[1] = { - {65, 3}, + {16, 3}, }; -static arc arcs_29_3[1] = { - {6, 4}, +static arc arcs_29_3[2] = { + {65, 4}, + {66, 5}, }; -static arc arcs_29_4[2] = { - {6, 4}, - {66, 1}, +static arc arcs_29_4[1] = { + {15, 6}, }; -static state states_29[5] = { - {2, arcs_29_0}, +static arc arcs_29_5[1] = { + {15, 7}, +}; +static arc arcs_29_6[1] = { + {16, 8}, +}; +static arc arcs_29_7[1] = { + {16, 9}, +}; +static arc arcs_29_8[2] = { + {65, 4}, + {0, 8}, +}; +static arc arcs_29_9[1] = { + {0, 9}, +}; +static state states_29[10] = { + {1, arcs_29_0}, {1, arcs_29_1}, {1, arcs_29_2}, - {1, arcs_29_3}, - {2, arcs_29_4}, + {2, arcs_29_3}, + {1, arcs_29_4}, + {1, arcs_29_5}, + {1, arcs_29_6}, + {1, arcs_29_7}, + {2, arcs_29_8}, + {1, arcs_29_9}, }; static arc arcs_30_0[1] = { {67, 1}, }; static arc arcs_30_1[2] = { - {68, 0}, + {37, 2}, {0, 1}, }; -static state states_30[2] = { - {1, arcs_30_0}, - {2, arcs_30_1}, -}; -static arc arcs_31_0[1] = { - {69, 1}, -}; -static arc arcs_31_1[2] = { - {70, 0}, - {0, 1}, -}; -static state states_31[2] = { - {1, arcs_31_0}, - {2, arcs_31_1}, -}; -static arc arcs_32_0[2] = { - {71, 1}, - {72, 2}, -}; -static arc arcs_32_1[1] = { - {69, 2}, -}; -static arc arcs_32_2[1] = { +static arc arcs_30_2[2] = { + {21, 3}, {0, 2}, }; -static state states_32[3] = { - {2, arcs_32_0}, - {1, arcs_32_1}, - {1, arcs_32_2}, +static arc arcs_30_3[1] = { + {37, 4}, +}; +static arc arcs_30_4[1] = { + {0, 4}, +}; +static state states_30[5] = { + {1, arcs_30_0}, + {2, arcs_30_1}, + {2, arcs_30_2}, + {1, arcs_30_3}, + {1, arcs_30_4}, +}; +static arc arcs_31_0[2] = { + {3, 1}, + {2, 2}, +}; +static arc arcs_31_1[1] = { + {0, 1}, +}; +static arc arcs_31_2[1] = { + {68, 3}, +}; +static arc arcs_31_3[1] = { + {6, 4}, +}; +static arc arcs_31_4[2] = { + {6, 4}, + {69, 1}, +}; +static state states_31[5] = { + {2, arcs_31_0}, + {1, arcs_31_1}, + {1, arcs_31_2}, + {1, arcs_31_3}, + {2, arcs_31_4}, +}; +static arc arcs_32_0[1] = { + {70, 1}, +}; +static arc arcs_32_1[2] = { + {71, 0}, + {0, 1}, +}; +static state states_32[2] = { + {1, arcs_32_0}, + {2, arcs_32_1}, }; static arc arcs_33_0[1] = { - {73, 1}, + {72, 1}, }; static arc arcs_33_1[2] = { - {74, 0}, + {73, 0}, {0, 1}, }; static state states_33[2] = { {1, arcs_33_0}, {2, arcs_33_1}, }; -static arc arcs_34_0[10] = { - {75, 1}, - {76, 1}, - {77, 1}, - {78, 1}, - {79, 1}, - {80, 1}, - {81, 1}, - {60, 1}, - {71, 2}, - {82, 3}, +static arc arcs_34_0[2] = { + {74, 1}, + {75, 2}, }; static arc arcs_34_1[1] = { - {0, 1}, + {72, 2}, }; static arc arcs_34_2[1] = { - {60, 1}, + {0, 2}, }; -static arc arcs_34_3[2] = { - {71, 1}, - {0, 3}, -}; -static state states_34[4] = { - {10, arcs_34_0}, +static state states_34[3] = { + {2, arcs_34_0}, {1, arcs_34_1}, {1, arcs_34_2}, - {2, arcs_34_3}, }; static arc arcs_35_0[1] = { - {83, 1}, + {76, 1}, }; static arc arcs_35_1[2] = { - {84, 0}, + {77, 0}, {0, 1}, }; static state states_35[2] = { {1, arcs_35_0}, {2, arcs_35_1}, }; -static arc arcs_36_0[1] = { - {85, 1}, +static arc arcs_36_0[10] = { + {78, 1}, + {79, 1}, + {80, 1}, + {81, 1}, + {82, 1}, + {83, 1}, + {84, 1}, + {63, 1}, + {74, 2}, + {85, 3}, }; -static arc arcs_36_1[2] = { - {86, 0}, +static arc arcs_36_1[1] = { {0, 1}, }; -static state states_36[2] = { - {1, arcs_36_0}, - {2, arcs_36_1}, +static arc arcs_36_2[1] = { + {63, 1}, +}; +static arc arcs_36_3[2] = { + {74, 1}, + {0, 3}, +}; +static state states_36[4] = { + {10, arcs_36_0}, + {1, arcs_36_1}, + {1, arcs_36_2}, + {2, arcs_36_3}, }; static arc arcs_37_0[1] = { - {87, 1}, + {86, 1}, }; static arc arcs_37_1[2] = { - {88, 0}, + {87, 0}, {0, 1}, }; static state states_37[2] = { @@ -720,308 +734,291 @@ static state states_37[2] = { {2, arcs_37_1}, }; static arc arcs_38_0[1] = { - {89, 1}, + {88, 1}, }; -static arc arcs_38_1[3] = { - {90, 0}, - {91, 0}, +static arc arcs_38_1[2] = { + {89, 0}, {0, 1}, }; static state states_38[2] = { {1, arcs_38_0}, - {3, arcs_38_1}, + {2, arcs_38_1}, }; static arc arcs_39_0[1] = { - {92, 1}, + {90, 1}, }; -static arc arcs_39_1[3] = { - {93, 0}, - {94, 0}, +static arc arcs_39_1[2] = { + {91, 0}, {0, 1}, }; static state states_39[2] = { {1, arcs_39_0}, - {3, arcs_39_1}, + {2, arcs_39_1}, }; static arc arcs_40_0[1] = { - {95, 1}, + {92, 1}, }; -static arc arcs_40_1[4] = { - {22, 0}, - {96, 0}, - {97, 0}, +static arc arcs_40_1[3] = { + {93, 0}, + {94, 0}, {0, 1}, }; static state states_40[2] = { {1, arcs_40_0}, - {4, arcs_40_1}, + {3, arcs_40_1}, }; -static arc arcs_41_0[4] = { - {93, 1}, - {94, 1}, +static arc arcs_41_0[1] = { + {95, 1}, +}; +static arc arcs_41_1[3] = { + {96, 0}, + {97, 0}, + {0, 1}, +}; +static state states_41[2] = { + {1, arcs_41_0}, + {3, arcs_41_1}, +}; +static arc arcs_42_0[1] = { {98, 1}, - {99, 2}, }; -static arc arcs_41_1[1] = { - {95, 3}, +static arc arcs_42_1[4] = { + {22, 0}, + {99, 0}, + {100, 0}, + {0, 1}, }; -static arc arcs_41_2[2] = { - {100, 2}, +static state states_42[2] = { + {1, arcs_42_0}, + {4, arcs_42_1}, +}; +static arc arcs_43_0[4] = { + {96, 1}, + {97, 1}, + {101, 1}, + {102, 2}, +}; +static arc arcs_43_1[1] = { + {98, 3}, +}; +static arc arcs_43_2[2] = { + {103, 2}, {0, 2}, }; -static arc arcs_41_3[1] = { +static arc arcs_43_3[1] = { {0, 3}, }; -static state states_41[4] = { - {4, arcs_41_0}, - {1, arcs_41_1}, - {2, arcs_41_2}, - {1, arcs_41_3}, +static state states_43[4] = { + {4, arcs_43_0}, + {1, arcs_43_1}, + {2, arcs_43_2}, + {1, arcs_43_3}, }; -static arc arcs_42_0[7] = { +static arc arcs_44_0[7] = { {17, 1}, - {101, 2}, - {103, 3}, - {106, 4}, + {104, 2}, + {106, 3}, + {109, 4}, {13, 5}, - {107, 5}, - {108, 5}, + {110, 5}, + {111, 5}, }; -static arc arcs_42_1[2] = { +static arc arcs_44_1[2] = { {9, 6}, {19, 5}, }; -static arc arcs_42_2[2] = { +static arc arcs_44_2[2] = { {9, 7}, - {102, 5}, -}; -static arc arcs_42_3[2] = { - {104, 8}, {105, 5}, }; -static arc arcs_42_4[1] = { +static arc arcs_44_3[2] = { + {107, 8}, + {108, 5}, +}; +static arc arcs_44_4[1] = { {9, 9}, }; -static arc arcs_42_5[1] = { +static arc arcs_44_5[1] = { {0, 5}, }; -static arc arcs_42_6[1] = { +static arc arcs_44_6[1] = { {19, 5}, }; -static arc arcs_42_7[1] = { - {102, 5}, -}; -static arc arcs_42_8[1] = { +static arc arcs_44_7[1] = { {105, 5}, }; -static arc arcs_42_9[1] = { - {106, 5}, +static arc arcs_44_8[1] = { + {108, 5}, }; -static state states_42[10] = { - {7, arcs_42_0}, - {2, arcs_42_1}, - {2, arcs_42_2}, - {2, arcs_42_3}, - {1, arcs_42_4}, - {1, arcs_42_5}, - {1, arcs_42_6}, - {1, arcs_42_7}, - {1, arcs_42_8}, - {1, arcs_42_9}, +static arc arcs_44_9[1] = { + {109, 5}, }; -static arc arcs_43_0[3] = { +static state states_44[10] = { + {7, arcs_44_0}, + {2, arcs_44_1}, + {2, arcs_44_2}, + {2, arcs_44_3}, + {1, arcs_44_4}, + {1, arcs_44_5}, + {1, arcs_44_6}, + {1, arcs_44_7}, + {1, arcs_44_8}, + {1, arcs_44_9}, +}; +static arc arcs_45_0[3] = { {17, 1}, - {101, 2}, - {110, 3}, + {104, 2}, + {113, 3}, }; -static arc arcs_43_1[2] = { +static arc arcs_45_1[2] = { {9, 4}, {19, 5}, }; -static arc arcs_43_2[1] = { - {109, 6}, +static arc arcs_45_2[1] = { + {112, 6}, }; -static arc arcs_43_3[1] = { +static arc arcs_45_3[1] = { {13, 5}, }; -static arc arcs_43_4[1] = { +static arc arcs_45_4[1] = { {19, 5}, }; -static arc arcs_43_5[1] = { +static arc arcs_45_5[1] = { {0, 5}, }; -static arc arcs_43_6[1] = { - {102, 5}, +static arc arcs_45_6[1] = { + {105, 5}, }; -static state states_43[7] = { - {3, arcs_43_0}, - {2, arcs_43_1}, - {1, arcs_43_2}, - {1, arcs_43_3}, - {1, arcs_43_4}, - {1, arcs_43_5}, - {1, arcs_43_6}, -}; -static arc arcs_44_0[2] = { - {36, 1}, - {15, 2}, -}; -static arc arcs_44_1[2] = { - {15, 2}, - {0, 1}, -}; -static arc arcs_44_2[2] = { - {36, 3}, - {0, 2}, -}; -static arc arcs_44_3[1] = { - {0, 3}, -}; -static state states_44[4] = { - {2, arcs_44_0}, - {2, arcs_44_1}, - {2, arcs_44_2}, - {1, arcs_44_3}, -}; -static arc arcs_45_0[1] = { - {73, 1}, -}; -static arc arcs_45_1[2] = { - {21, 2}, - {0, 1}, -}; -static arc arcs_45_2[2] = { - {73, 1}, - {0, 2}, -}; -static state states_45[3] = { - {1, arcs_45_0}, +static state states_45[7] = { + {3, arcs_45_0}, {2, arcs_45_1}, - {2, arcs_45_2}, + {1, arcs_45_2}, + {1, arcs_45_3}, + {1, arcs_45_4}, + {1, arcs_45_5}, + {1, arcs_45_6}, }; -static arc arcs_46_0[1] = { - {36, 1}, +static arc arcs_46_0[2] = { + {37, 1}, + {15, 2}, }; static arc arcs_46_1[2] = { - {21, 2}, + {15, 2}, {0, 1}, }; static arc arcs_46_2[2] = { - {36, 1}, + {37, 3}, {0, 2}, }; -static state states_46[3] = { - {1, arcs_46_0}, +static arc arcs_46_3[1] = { + {0, 3}, +}; +static state states_46[4] = { + {2, arcs_46_0}, {2, arcs_46_1}, {2, arcs_46_2}, + {1, arcs_46_3}, }; static arc arcs_47_0[1] = { - {36, 1}, + {76, 1}, }; -static arc arcs_47_1[1] = { +static arc arcs_47_1[2] = { + {21, 2}, + {0, 1}, +}; +static arc arcs_47_2[2] = { + {76, 1}, + {0, 2}, +}; +static state states_47[3] = { + {1, arcs_47_0}, + {2, arcs_47_1}, + {2, arcs_47_2}, +}; +static arc arcs_48_0[1] = { + {37, 1}, +}; +static arc arcs_48_1[2] = { + {21, 2}, + {0, 1}, +}; +static arc arcs_48_2[2] = { + {37, 1}, + {0, 2}, +}; +static state states_48[3] = { + {1, arcs_48_0}, + {2, arcs_48_1}, + {2, arcs_48_2}, +}; +static arc arcs_49_0[1] = { + {37, 1}, +}; +static arc arcs_49_1[1] = { {15, 2}, }; -static arc arcs_47_2[1] = { - {36, 3}, +static arc arcs_49_2[1] = { + {37, 3}, }; -static arc arcs_47_3[2] = { +static arc arcs_49_3[2] = { {21, 4}, {0, 3}, }; -static arc arcs_47_4[2] = { - {36, 1}, +static arc arcs_49_4[2] = { + {37, 1}, {0, 4}, }; -static state states_47[5] = { - {1, arcs_47_0}, - {1, arcs_47_1}, - {1, arcs_47_2}, - {2, arcs_47_3}, - {2, arcs_47_4}, +static state states_49[5] = { + {1, arcs_49_0}, + {1, arcs_49_1}, + {1, arcs_49_2}, + {2, arcs_49_3}, + {2, arcs_49_4}, }; -static arc arcs_48_0[1] = { - {111, 1}, +static arc arcs_50_0[1] = { + {114, 1}, }; -static arc arcs_48_1[1] = { +static arc arcs_50_1[1] = { {13, 2}, }; -static arc arcs_48_2[2] = { +static arc arcs_50_2[2] = { {17, 3}, {15, 4}, }; -static arc arcs_48_3[2] = { +static arc arcs_50_3[1] = { {9, 5}, - {19, 6}, }; -static arc arcs_48_4[1] = { - {16, 7}, +static arc arcs_50_4[1] = { + {16, 6}, }; -static arc arcs_48_5[1] = { - {19, 8}, +static arc arcs_50_5[1] = { + {19, 7}, }; -static arc arcs_48_6[2] = { - {34, 9}, +static arc arcs_50_6[1] = { + {0, 6}, +}; +static arc arcs_50_7[1] = { {15, 4}, }; -static arc arcs_48_7[1] = { - {0, 7}, -}; -static arc arcs_48_8[1] = { - {15, 4}, -}; -static arc arcs_48_9[1] = { - {112, 8}, -}; -static state states_48[10] = { - {1, arcs_48_0}, - {1, arcs_48_1}, - {2, arcs_48_2}, - {2, arcs_48_3}, - {1, arcs_48_4}, - {1, arcs_48_5}, - {2, arcs_48_6}, - {1, arcs_48_7}, - {1, arcs_48_8}, - {1, arcs_48_9}, -}; -static arc arcs_49_0[1] = { - {99, 1}, -}; -static arc arcs_49_1[1] = { - {113, 2}, -}; -static arc arcs_49_2[2] = { - {21, 0}, - {0, 2}, -}; -static state states_49[3] = { - {1, arcs_49_0}, - {1, arcs_49_1}, - {2, arcs_49_2}, -}; -static arc arcs_50_0[1] = { - {17, 1}, -}; -static arc arcs_50_1[1] = { - {19, 2}, -}; -static arc arcs_50_2[1] = { - {0, 2}, -}; -static state states_50[3] = { +static state states_50[8] = { {1, arcs_50_0}, {1, arcs_50_1}, - {1, arcs_50_2}, + {2, arcs_50_2}, + {1, arcs_50_3}, + {1, arcs_50_4}, + {1, arcs_50_5}, + {1, arcs_50_6}, + {1, arcs_50_7}, }; static dfa dfas[51] = { {256, "single_input", 0, 3, states_0, - "\004\060\002\000\150\370\203\054\000\000\000\140\244\234\000"}, + "\004\060\002\000\320\360\017\144\001\000\000\000\043\345\004"}, {257, "file_input", 0, 2, states_1, - "\204\060\002\000\150\370\203\054\000\000\000\140\244\234\000"}, + "\204\060\002\000\320\360\017\144\001\000\000\000\043\345\004"}, {258, "expr_input", 0, 3, states_2, - "\000\040\002\000\000\000\000\000\200\000\000\140\244\034\000"}, + "\000\040\002\000\000\000\000\000\000\004\000\000\043\345\000"}, {259, "eval_input", 0, 3, states_3, - "\000\040\002\000\000\000\000\000\200\000\000\140\244\034\000"}, + "\000\040\002\000\000\000\000\000\000\004\000\000\043\345\000"}, {260, "funcdef", 0, 6, states_4, "\000\020\000\000\000\000\000\000\000\000\000\000\000\000\000"}, {261, "parameters", 0, 4, states_5, @@ -1033,108 +1030,108 @@ static dfa dfas[51] = { {264, "fplist", 0, 3, states_8, "\000\040\002\000\000\000\000\000\000\000\000\000\000\000\000"}, {265, "stmt", 0, 2, states_9, - "\000\060\002\000\150\370\203\054\000\000\000\140\244\234\000"}, + "\000\060\002\000\320\360\017\144\001\000\000\000\043\345\004"}, {266, "simple_stmt", 0, 4, states_10, - "\000\040\002\000\150\370\003\000\000\000\000\140\244\034\000"}, + "\000\040\002\000\320\360\017\000\000\000\000\000\043\345\000"}, {267, "small_stmt", 0, 2, states_11, - "\000\040\002\000\150\370\003\000\000\000\000\140\244\034\000"}, + "\000\040\002\000\320\360\017\000\000\000\000\000\043\345\000"}, {268, "expr_stmt", 0, 2, states_12, - "\000\040\002\000\000\000\000\000\000\000\000\140\244\034\000"}, + "\000\040\002\000\000\000\000\000\000\000\000\000\043\345\000"}, {269, "print_stmt", 0, 3, states_13, - "\000\000\000\000\010\000\000\000\000\000\000\000\000\000\000"}, + "\000\000\000\000\020\000\000\000\000\000\000\000\000\000\000"}, {270, "del_stmt", 0, 3, states_14, - "\000\000\000\000\040\000\000\000\000\000\000\000\000\000\000"}, - {271, "pass_stmt", 0, 2, states_15, "\000\000\000\000\100\000\000\000\000\000\000\000\000\000\000"}, + {271, "pass_stmt", 0, 2, states_15, + "\000\000\000\000\200\000\000\000\000\000\000\000\000\000\000"}, {272, "flow_stmt", 0, 2, states_16, - "\000\000\000\000\000\170\000\000\000\000\000\000\000\000\000"}, + "\000\000\000\000\000\360\000\000\000\000\000\000\000\000\000"}, {273, "break_stmt", 0, 2, states_17, - "\000\000\000\000\000\010\000\000\000\000\000\000\000\000\000"}, - {274, "continue_stmt", 0, 2, states_18, "\000\000\000\000\000\020\000\000\000\000\000\000\000\000\000"}, - {275, "return_stmt", 0, 3, states_19, + {274, "continue_stmt", 0, 2, states_18, "\000\000\000\000\000\040\000\000\000\000\000\000\000\000\000"}, - {276, "raise_stmt", 0, 5, states_20, + {275, "return_stmt", 0, 3, states_19, "\000\000\000\000\000\100\000\000\000\000\000\000\000\000\000"}, + {276, "raise_stmt", 0, 5, states_20, + "\000\000\000\000\000\200\000\000\000\000\000\000\000\000\000"}, {277, "import_stmt", 0, 9, states_21, - "\000\000\000\000\000\200\001\000\000\000\000\000\000\000\000"}, + "\000\000\000\000\000\000\003\000\000\000\000\000\000\000\000"}, {278, "global_stmt", 0, 3, states_22, - "\000\000\000\000\000\000\002\000\000\000\000\000\000\000\000"}, - {279, "compound_stmt", 0, 2, states_23, - "\000\020\000\000\000\000\200\054\000\000\000\000\000\200\000"}, - {280, "if_stmt", 0, 8, states_24, - "\000\000\000\000\000\000\200\000\000\000\000\000\000\000\000"}, - {281, "while_stmt", 0, 8, states_25, + "\000\000\000\000\000\000\004\000\000\000\000\000\000\000\000"}, + {279, "access_stmt", 0, 5, states_23, + "\000\000\000\000\000\000\010\000\000\000\000\000\000\000\000"}, + {280, "accesstype", 0, 2, states_24, + "\000\040\000\000\000\000\000\000\000\000\000\000\000\000\000"}, + {281, "compound_stmt", 0, 2, states_25, + "\000\020\000\000\000\000\000\144\001\000\000\000\000\000\004"}, + {282, "if_stmt", 0, 8, states_26, "\000\000\000\000\000\000\000\004\000\000\000\000\000\000\000"}, - {282, "for_stmt", 0, 10, states_26, - "\000\000\000\000\000\000\000\010\000\000\000\000\000\000\000"}, - {283, "try_stmt", 0, 10, states_27, + {283, "while_stmt", 0, 8, states_27, "\000\000\000\000\000\000\000\040\000\000\000\000\000\000\000"}, - {284, "except_clause", 0, 5, states_28, + {284, "for_stmt", 0, 10, states_28, + "\000\000\000\000\000\000\000\100\000\000\000\000\000\000\000"}, + {285, "try_stmt", 0, 10, states_29, "\000\000\000\000\000\000\000\000\001\000\000\000\000\000\000"}, - {285, "suite", 0, 5, states_29, - "\004\040\002\000\150\370\003\000\000\000\000\140\244\034\000"}, - {286, "test", 0, 2, states_30, - "\000\040\002\000\000\000\000\000\200\000\000\140\244\034\000"}, - {287, "and_test", 0, 2, states_31, - "\000\040\002\000\000\000\000\000\200\000\000\140\244\034\000"}, - {288, "not_test", 0, 3, states_32, - "\000\040\002\000\000\000\000\000\200\000\000\140\244\034\000"}, - {289, "comparison", 0, 2, states_33, - "\000\040\002\000\000\000\000\000\000\000\000\140\244\034\000"}, - {290, "comp_op", 0, 4, states_34, - "\000\000\000\000\000\000\000\020\200\370\007\000\000\000\000"}, - {291, "expr", 0, 2, states_35, - "\000\040\002\000\000\000\000\000\000\000\000\140\244\034\000"}, - {292, "xor_expr", 0, 2, states_36, - "\000\040\002\000\000\000\000\000\000\000\000\140\244\034\000"}, - {293, "and_expr", 0, 2, states_37, - "\000\040\002\000\000\000\000\000\000\000\000\140\244\034\000"}, - {294, "shift_expr", 0, 2, states_38, - "\000\040\002\000\000\000\000\000\000\000\000\140\244\034\000"}, - {295, "arith_expr", 0, 2, states_39, - "\000\040\002\000\000\000\000\000\000\000\000\140\244\034\000"}, - {296, "term", 0, 2, states_40, - "\000\040\002\000\000\000\000\000\000\000\000\140\244\034\000"}, - {297, "factor", 0, 4, states_41, - "\000\040\002\000\000\000\000\000\000\000\000\140\244\034\000"}, - {298, "atom", 0, 10, states_42, - "\000\040\002\000\000\000\000\000\000\000\000\000\240\034\000"}, - {299, "trailer", 0, 7, states_43, - "\000\000\002\000\000\000\000\000\000\000\000\000\040\100\000"}, - {300, "subscript", 0, 4, states_44, - "\000\240\002\000\000\000\000\000\200\000\000\140\244\034\000"}, - {301, "exprlist", 0, 3, states_45, - "\000\040\002\000\000\000\000\000\000\000\000\140\244\034\000"}, - {302, "testlist", 0, 3, states_46, - "\000\040\002\000\000\000\000\000\200\000\000\140\244\034\000"}, - {303, "dictmaker", 0, 5, states_47, - "\000\040\002\000\000\000\000\000\200\000\000\140\244\034\000"}, - {304, "classdef", 0, 10, states_48, - "\000\000\000\000\000\000\000\000\000\000\000\000\000\200\000"}, - {305, "baselist", 0, 3, states_49, - "\000\040\002\000\000\000\000\000\000\000\000\000\240\034\000"}, - {306, "arguments", 0, 3, states_50, - "\000\000\002\000\000\000\000\000\000\000\000\000\000\000\000"}, + {286, "except_clause", 0, 5, states_30, + "\000\000\000\000\000\000\000\000\010\000\000\000\000\000\000"}, + {287, "suite", 0, 5, states_31, + "\004\040\002\000\320\360\017\000\000\000\000\000\043\345\000"}, + {288, "test", 0, 2, states_32, + "\000\040\002\000\000\000\000\000\000\004\000\000\043\345\000"}, + {289, "and_test", 0, 2, states_33, + "\000\040\002\000\000\000\000\000\000\004\000\000\043\345\000"}, + {290, "not_test", 0, 3, states_34, + "\000\040\002\000\000\000\000\000\000\004\000\000\043\345\000"}, + {291, "comparison", 0, 2, states_35, + "\000\040\002\000\000\000\000\000\000\000\000\000\043\345\000"}, + {292, "comp_op", 0, 4, states_36, + "\000\000\000\000\000\000\000\200\000\304\077\000\000\000\000"}, + {293, "expr", 0, 2, states_37, + "\000\040\002\000\000\000\000\000\000\000\000\000\043\345\000"}, + {294, "xor_expr", 0, 2, states_38, + "\000\040\002\000\000\000\000\000\000\000\000\000\043\345\000"}, + {295, "and_expr", 0, 2, states_39, + "\000\040\002\000\000\000\000\000\000\000\000\000\043\345\000"}, + {296, "shift_expr", 0, 2, states_40, + "\000\040\002\000\000\000\000\000\000\000\000\000\043\345\000"}, + {297, "arith_expr", 0, 2, states_41, + "\000\040\002\000\000\000\000\000\000\000\000\000\043\345\000"}, + {298, "term", 0, 2, states_42, + "\000\040\002\000\000\000\000\000\000\000\000\000\043\345\000"}, + {299, "factor", 0, 4, states_43, + "\000\040\002\000\000\000\000\000\000\000\000\000\043\345\000"}, + {300, "atom", 0, 10, states_44, + "\000\040\002\000\000\000\000\000\000\000\000\000\000\345\000"}, + {301, "trailer", 0, 7, states_45, + "\000\000\002\000\000\000\000\000\000\000\000\000\000\001\002"}, + {302, "subscript", 0, 4, states_46, + "\000\240\002\000\000\000\000\000\000\004\000\000\043\345\000"}, + {303, "exprlist", 0, 3, states_47, + "\000\040\002\000\000\000\000\000\000\000\000\000\043\345\000"}, + {304, "testlist", 0, 3, states_48, + "\000\040\002\000\000\000\000\000\000\004\000\000\043\345\000"}, + {305, "dictmaker", 0, 5, states_49, + "\000\040\002\000\000\000\000\000\000\004\000\000\043\345\000"}, + {306, "classdef", 0, 8, states_50, + "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\004"}, }; -static label labels[114] = { +static label labels[115] = { {0, "EMPTY"}, {256, 0}, {4, 0}, {266, 0}, - {279, 0}, + {281, 0}, {257, 0}, {265, 0}, {0, 0}, {258, 0}, - {302, 0}, + {304, 0}, {259, 0}, {260, 0}, {1, "def"}, {1, 0}, {261, 0}, {11, 0}, - {285, 0}, + {287, 0}, {7, 0}, {262, 0}, {8, 0}, @@ -1151,10 +1148,11 @@ static label labels[114] = { {272, 0}, {277, 0}, {278, 0}, - {301, 0}, + {279, 0}, + {303, 0}, {22, 0}, {1, "print"}, - {286, 0}, + {288, 0}, {1, "del"}, {1, "pass"}, {273, 0}, @@ -1168,11 +1166,13 @@ static label labels[114] = { {1, "import"}, {1, "from"}, {1, "global"}, + {1, "access"}, {280, 0}, - {281, 0}, {282, 0}, {283, 0}, - {304, 0}, + {284, 0}, + {285, 0}, + {306, 0}, {1, "if"}, {1, "elif"}, {1, "else"}, @@ -1180,19 +1180,19 @@ static label labels[114] = { {1, "for"}, {1, "in"}, {1, "try"}, - {284, 0}, + {286, 0}, {1, "finally"}, {1, "except"}, {5, 0}, {6, 0}, - {287, 0}, + {289, 0}, {1, "or"}, - {288, 0}, + {290, 0}, {1, "and"}, {1, "not"}, - {289, 0}, {291, 0}, - {290, 0}, + {293, 0}, + {292, 0}, {20, 0}, {21, 0}, {28, 0}, @@ -1201,41 +1201,39 @@ static label labels[114] = { {29, 0}, {29, 0}, {1, "is"}, - {292, 0}, - {18, 0}, - {293, 0}, - {33, 0}, {294, 0}, - {19, 0}, + {18, 0}, {295, 0}, + {33, 0}, + {296, 0}, + {19, 0}, + {297, 0}, {34, 0}, {35, 0}, - {296, 0}, + {298, 0}, {14, 0}, {15, 0}, - {297, 0}, + {299, 0}, {17, 0}, {24, 0}, {32, 0}, - {298, 0}, - {299, 0}, + {300, 0}, + {301, 0}, {9, 0}, {10, 0}, {26, 0}, - {303, 0}, + {305, 0}, {27, 0}, {25, 0}, {2, 0}, {3, 0}, - {300, 0}, + {302, 0}, {23, 0}, {1, "class"}, - {305, 0}, - {306, 0}, }; grammar gram = { 51, dfas, - {114, labels}, + {115, labels}, 256 }; diff --git a/Python/import.c b/Python/import.c index 4310afa1f8c..ec21b4c85e8 100644 --- a/Python/import.c +++ b/Python/import.c @@ -54,7 +54,7 @@ extern char *argv0; /* Magic word to reject .pyc files generated by other Python versions */ -#define MAGIC 0x99BE3AL +#define MAGIC 0x999901L /* Increment by one for each incompatible change */ static object *modules; @@ -353,46 +353,27 @@ reload_module(m) return get_module(m, getmodulename(m), (object **)NULL); } -static void -cleardict(d) - object *d; -{ - int i; - for (i = getdictsize(d); --i >= 0; ) { - char *k; - k = getdictkey(d, i); - if (k != NULL) - (void) dictremove(d, k); - } -} - void doneimport() { if (modules != NULL) { - int i; + int pos; + object *modname, *module; /* Explicitly erase all modules; this is the safest way to get rid of at least *some* circular dependencies */ - for (i = getdictsize(modules); --i >= 0; ) { - object *k; - k = getdict2key(modules, i); - if (k != NULL) { - object *m; - m = dict2lookup(modules, k); - if (m == NULL) - err_clear(); - else if (is_moduleobject(m)) { - object *d; - d = getmoduledict(m); - if (d != NULL && is_dictobject(d)) { - cleardict(d); - } - } + pos = 0; + while (mappinggetnext(modules, &pos, &modname, &module)) { + if (is_moduleobject(module)) { + object *dict; + dict = getmoduledict(module); + if (dict != NULL && is_dictobject(dict)) + mappingclear(dict); } } - cleardict(modules); + mappingclear(modules); } DECREF(modules); + modules = NULL; } diff --git a/Python/marshal.c b/Python/marshal.c index 3853ff9fb3d..93503d13ee2 100644 --- a/Python/marshal.c +++ b/Python/marshal.c @@ -174,17 +174,14 @@ w_object(v, p) } } else if (is_dictobject(v)) { + int pos; + object *key, *value; w_byte(TYPE_DICT, p); /* This one is NULL object terminated! */ - n = getdictsize(v); - for (i = 0; i < n; i++) { - object *key, *val; - key = getdict2key(v, (int)i); - if (key != NULL) { - val = dict2lookup(v, key); /* Can't be NULL */ - w_object(key, p); - w_object(val, p); - } + pos = 0; + while (mappinggetnext(v, &pos, &key, &value)) { + w_object(key, p); + w_object(value, p); } w_object((object *)NULL, p); }