home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 2 / 2791 < prev    next >
Encoding:
Internet Message Format  |  1991-02-20  |  60.7 KB

  1. From: guido@cwi.nl (Guido van Rossum)
  2. Newsgroups: alt.sources
  3. Subject: Python 0.9.1 part 03/21
  4. Message-ID: <2965@charon.cwi.nl>
  5. Date: 19 Feb 91 17:41:21 GMT
  6.  
  7. : This is a shell archive.
  8. : Extract with 'sh this_file'.
  9. :
  10. : Extract part 01 first since it makes all directories
  11. echo 'Start of pack.out, part 03 out of 21:'
  12. if test -s 'src/compile.c'
  13. then echo '*** I will not over-write existing file src/compile.c'
  14. else
  15. echo 'x - src/compile.c'
  16. sed 's/^X//' > 'src/compile.c' << 'EOF'
  17. X/***********************************************************
  18. XCopyright 1991 by Stichting Mathematisch Centrum, Amsterdam, The
  19. XNetherlands.
  20. X
  21. X                        All Rights Reserved
  22. X
  23. XPermission to use, copy, modify, and distribute this software and its 
  24. Xdocumentation for any purpose and without fee is hereby granted, 
  25. Xprovided that the above copyright notice appear in all copies and that
  26. Xboth that copyright notice and this permission notice appear in 
  27. Xsupporting documentation, and that the names of Stichting Mathematisch
  28. XCentrum or CWI not be used in advertising or publicity pertaining to
  29. Xdistribution of the software without specific, written prior permission.
  30. X
  31. XSTICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
  32. XTHIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
  33. XFITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
  34. XFOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  35. XWHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  36. XACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
  37. XOF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  38. X
  39. X******************************************************************/
  40. X
  41. X/* Compile an expression node to intermediate code */
  42. X
  43. X/* XXX TO DO:
  44. X   XXX Compute maximum needed stack sizes while compiling
  45. X   XXX Generate simple jump for break/return outside 'try...finally'
  46. X   XXX Include function name in code (and module names?)
  47. X*/
  48. X
  49. X#include "allobjects.h"
  50. X
  51. X#include "node.h"
  52. X#include "token.h"
  53. X#include "graminit.h"
  54. X#include "compile.h"
  55. X#include "opcode.h"
  56. X#include "structmember.h"
  57. X
  58. X#include <ctype.h>
  59. X
  60. X#define OFF(x) offsetof(codeobject, x)
  61. X
  62. Xstatic struct memberlist code_memberlist[] = {
  63. X    {"co_code",    T_OBJECT,    OFF(co_code)},
  64. X    {"co_consts",    T_OBJECT,    OFF(co_consts)},
  65. X    {"co_names",    T_OBJECT,    OFF(co_names)},
  66. X    {"co_filename",    T_OBJECT,    OFF(co_filename)},
  67. X    {NULL}    /* Sentinel */
  68. X};
  69. X
  70. Xstatic object *
  71. Xcode_getattr(co, name)
  72. X    codeobject *co;
  73. X    char *name;
  74. X{
  75. X    return getmember((char *)co, code_memberlist, name);
  76. X}
  77. X
  78. Xstatic void
  79. Xcode_dealloc(co)
  80. X    codeobject *co;
  81. X{
  82. X    XDECREF(co->co_code);
  83. X    XDECREF(co->co_consts);
  84. X    XDECREF(co->co_names);
  85. X    XDECREF(co->co_filename);
  86. X    DEL(co);
  87. X}
  88. X
  89. Xtypeobject Codetype = {
  90. X    OB_HEAD_INIT(&Typetype)
  91. X    0,
  92. X    "code",
  93. X    sizeof(codeobject),
  94. X    0,
  95. X    code_dealloc,    /*tp_dealloc*/
  96. X    0,        /*tp_print*/
  97. X    code_getattr,    /*tp_getattr*/
  98. X    0,        /*tp_setattr*/
  99. X    0,        /*tp_compare*/
  100. X    0,        /*tp_repr*/
  101. X    0,        /*tp_as_number*/
  102. X    0,        /*tp_as_sequence*/
  103. X    0,        /*tp_as_mapping*/
  104. X};
  105. X
  106. Xstatic codeobject *newcodeobject PROTO((object *, object *, object *, char *));
  107. X
  108. Xstatic codeobject *
  109. Xnewcodeobject(code, consts, names, filename)
  110. X    object *code;
  111. X    object *consts;
  112. X    object *names;
  113. X    char *filename;
  114. X{
  115. X    codeobject *co;
  116. X    int i;
  117. X    /* Check argument types */
  118. X    if (code == NULL || !is_stringobject(code) ||
  119. X        consts == NULL || !is_listobject(consts) ||
  120. X        names == NULL || !is_listobject(names)) {
  121. X        err_badcall();
  122. X        return NULL;
  123. X    }
  124. X    /* Make sure the list of names contains only strings */
  125. X    for (i = getlistsize(names); --i >= 0; ) {
  126. X        object *v = getlistitem(names, i);
  127. X        if (v == NULL || !is_stringobject(v)) {
  128. X            err_badcall();
  129. X            return NULL;
  130. X        }
  131. X    }
  132. X    co = NEWOBJ(codeobject, &Codetype);
  133. X    if (co != NULL) {
  134. X        INCREF(code);
  135. X        co->co_code = (stringobject *)code;
  136. X        INCREF(consts);
  137. X        co->co_consts = consts;
  138. X        INCREF(names);
  139. X        co->co_names = names;
  140. X        if ((co->co_filename = newstringobject(filename)) == NULL) {
  141. X            DECREF(co);
  142. X            co = NULL;
  143. X        }
  144. X    }
  145. X    return co;
  146. X}
  147. X
  148. X
  149. X/* Data structure used internally */
  150. Xstruct compiling {
  151. X    object *c_code;        /* string */
  152. X    object *c_consts;    /* list of objects */
  153. X    object *c_names;    /* list of strings (names) */
  154. X    int c_nexti;        /* index into c_code */
  155. X    int c_errors;        /* counts errors occurred */
  156. X    int c_infunction;    /* set when compiling a function */
  157. X    int c_loops;        /* counts nested loops */
  158. X    char *c_filename;    /* filename of current node */
  159. X};
  160. X
  161. X/* Prototypes */
  162. Xstatic int com_init PROTO((struct compiling *, char *));
  163. Xstatic void com_free PROTO((struct compiling *));
  164. Xstatic void com_done PROTO((struct compiling *));
  165. Xstatic void com_node PROTO((struct compiling *, struct _node *));
  166. Xstatic void com_addbyte PROTO((struct compiling *, int));
  167. Xstatic void com_addint PROTO((struct compiling *, int));
  168. Xstatic void com_addoparg PROTO((struct compiling *, int, int));
  169. Xstatic void com_addfwref PROTO((struct compiling *, int, int *));
  170. Xstatic void com_backpatch PROTO((struct compiling *, int));
  171. Xstatic int com_add PROTO((struct compiling *, object *, object *));
  172. Xstatic int com_addconst PROTO((struct compiling *, object *));
  173. Xstatic int com_addname PROTO((struct compiling *, object *));
  174. Xstatic void com_addopname PROTO((struct compiling *, int, node *));
  175. X
  176. Xstatic int
  177. Xcom_init(c, filename)
  178. X    struct compiling *c;
  179. X    char *filename;
  180. X{
  181. X    if ((c->c_code = newsizedstringobject((char *)NULL, 0)) == NULL)
  182. X        goto fail_3;
  183. X    if ((c->c_consts = newlistobject(0)) == NULL)
  184. X        goto fail_2;
  185. X    if ((c->c_names = newlistobject(0)) == NULL)
  186. X        goto fail_1;
  187. X    c->c_nexti = 0;
  188. X    c->c_errors = 0;
  189. X    c->c_infunction = 0;
  190. X    c->c_loops = 0;
  191. X    c->c_filename = filename;
  192. X    return 1;
  193. X    
  194. X  fail_1:
  195. X    DECREF(c->c_consts);
  196. X  fail_2:
  197. X    DECREF(c->c_code);
  198. X  fail_3:
  199. X     return 0;
  200. X}
  201. X
  202. Xstatic void
  203. Xcom_free(c)
  204. X    struct compiling *c;
  205. X{
  206. X    XDECREF(c->c_code);
  207. X    XDECREF(c->c_consts);
  208. X    XDECREF(c->c_names);
  209. X}
  210. X
  211. Xstatic void
  212. Xcom_done(c)
  213. X    struct compiling *c;
  214. X{
  215. X    if (c->c_code != NULL)
  216. X        resizestring(&c->c_code, c->c_nexti);
  217. X}
  218. X
  219. Xstatic void
  220. Xcom_addbyte(c, byte)
  221. X    struct compiling *c;
  222. X    int byte;
  223. X{
  224. X    int len;
  225. X    if (byte < 0 || byte > 255) {
  226. X        fprintf(stderr, "XXX compiling bad byte: %d\n", byte);
  227. X        abort();
  228. X        err_setstr(SystemError, "com_addbyte: byte out of range");
  229. X        c->c_errors++;
  230. X    }
  231. X    if (c->c_code == NULL)
  232. X        return;
  233. X    len = getstringsize(c->c_code);
  234. X    if (c->c_nexti >= len) {
  235. X        if (resizestring(&c->c_code, len+1000) != 0) {
  236. X            c->c_errors++;
  237. X            return;
  238. X        }
  239. X    }
  240. X    getstringvalue(c->c_code)[c->c_nexti++] = byte;
  241. X}
  242. X
  243. Xstatic void
  244. Xcom_addint(c, x)
  245. X    struct compiling *c;
  246. X    int x;
  247. X{
  248. X    com_addbyte(c, x & 0xff);
  249. X    com_addbyte(c, x >> 8); /* XXX x should be positive */
  250. X}
  251. X
  252. Xstatic void
  253. Xcom_addoparg(c, op, arg)
  254. X    struct compiling *c;
  255. X    int op;
  256. X    int arg;
  257. X{
  258. X    com_addbyte(c, op);
  259. X    com_addint(c, arg);
  260. X}
  261. X
  262. Xstatic void
  263. Xcom_addfwref(c, op, p_anchor)
  264. X    struct compiling *c;
  265. X    int op;
  266. X    int *p_anchor;
  267. X{
  268. X    /* Compile a forward reference for backpatching */
  269. X    int here;
  270. X    int anchor;
  271. X    com_addbyte(c, op);
  272. X    here = c->c_nexti;
  273. X    anchor = *p_anchor;
  274. X    *p_anchor = here;
  275. X    com_addint(c, anchor == 0 ? 0 : here - anchor);
  276. X}
  277. X
  278. Xstatic void
  279. Xcom_backpatch(c, anchor)
  280. X    struct compiling *c;
  281. X    int anchor; /* Must be nonzero */
  282. X{
  283. X    unsigned char *code = (unsigned char *) getstringvalue(c->c_code);
  284. X    int target = c->c_nexti;
  285. X    int lastanchor = 0;
  286. X    int dist;
  287. X    int prev;
  288. X    for (;;) {
  289. X        /* Make the JUMP instruction at anchor point to target */
  290. X        prev = code[anchor] + (code[anchor+1] << 8);
  291. X        dist = target - (anchor+2);
  292. X        code[anchor] = dist & 0xff;
  293. X        code[anchor+1] = dist >> 8;
  294. X        if (!prev)
  295. X            break;
  296. X        lastanchor = anchor;
  297. X        anchor -= prev;
  298. X    }
  299. X}
  300. X
  301. X/* Handle constants and names uniformly */
  302. X
  303. Xstatic int
  304. Xcom_add(c, list, v)
  305. X    struct compiling *c;
  306. X    object *list;
  307. X    object *v;
  308. X{
  309. X    int n = getlistsize(list);
  310. X    int i;
  311. X    for (i = n; --i >= 0; ) {
  312. X        object *w = getlistitem(list, i);
  313. X        if (cmpobject(v, w) == 0)
  314. X            return i;
  315. X    }
  316. X    if (addlistitem(list, v) != 0)
  317. X        c->c_errors++;
  318. X    return n;
  319. X}
  320. X
  321. Xstatic int
  322. Xcom_addconst(c, v)
  323. X    struct compiling *c;
  324. X    object *v;
  325. X{
  326. X    return com_add(c, c->c_consts, v);
  327. X}
  328. X
  329. Xstatic int
  330. Xcom_addname(c, v)
  331. X    struct compiling *c;
  332. X    object *v;
  333. X{
  334. X    return com_add(c, c->c_names, v);
  335. X}
  336. X
  337. Xstatic void
  338. Xcom_addopname(c, op, n)
  339. X    struct compiling *c;
  340. X    int op;
  341. X    node *n;
  342. X{
  343. X    object *v;
  344. X    int i;
  345. X    char *name;
  346. X    if (TYPE(n) == STAR)
  347. X        name = "*";
  348. X    else {
  349. X        REQ(n, NAME);
  350. X        name = STR(n);
  351. X    }
  352. X    if ((v = newstringobject(name)) == NULL) {
  353. X        c->c_errors++;
  354. X        i = 255;
  355. X    }
  356. X    else {
  357. X        i = com_addname(c, v);
  358. X        DECREF(v);
  359. X    }
  360. X    com_addoparg(c, op, i);
  361. X}
  362. X
  363. Xstatic object *
  364. Xparsenumber(s)
  365. X    char *s;
  366. X{
  367. X    extern long strtol();
  368. X    extern double atof();
  369. X    char *end = s;
  370. X    long x;
  371. X    x = strtol(s, &end, 0);
  372. X    if (*end == '\0')
  373. X        return newintobject(x);
  374. X    if (*end == '.' || *end == 'e' || *end == 'E')
  375. X        return newfloatobject(atof(s));
  376. X    err_setstr(RuntimeError, "bad number syntax");
  377. X    return NULL;
  378. X}
  379. X
  380. Xstatic object *
  381. Xparsestr(s)
  382. X    char *s;
  383. X{
  384. X    object *v;
  385. X    int len;
  386. X    char *buf;
  387. X    char *p;
  388. X    int c;
  389. X    if (*s != '\'') {
  390. X        err_badcall();
  391. X        return NULL;
  392. X    }
  393. X    s++;
  394. X    len = strlen(s);
  395. X    if (s[--len] != '\'') {
  396. X        err_badcall();
  397. X        return NULL;
  398. X    }
  399. X    if (strchr(s, '\\') == NULL)
  400. X        return newsizedstringobject(s, len);
  401. X    v = newsizedstringobject((char *)NULL, len);
  402. X    p = buf = getstringvalue(v);
  403. X    while (*s != '\0' && *s != '\'') {
  404. X        if (*s != '\\') {
  405. X            *p++ = *s++;
  406. X            continue;
  407. X        }
  408. X        s++;
  409. X        switch (*s++) {
  410. X        /* XXX This assumes ASCII! */
  411. X        case '\\': *p++ = '\\'; break;
  412. X        case '\'': *p++ = '\''; break;
  413. X        case 'b': *p++ = '\b'; break;
  414. X        case 'f': *p++ = '\014'; break; /* FF */
  415. X        case 't': *p++ = '\t'; break;
  416. X        case 'n': *p++ = '\n'; break;
  417. X        case 'r': *p++ = '\r'; break;
  418. X        case 'v': *p++ = '\013'; break; /* VT */
  419. X        case 'E': *p++ = '\033'; break; /* ESC, not C */
  420. X        case 'a': *p++ = '\007'; break; /* BEL, not classic C */
  421. X        case '0': case '1': case '2': case '3':
  422. X        case '4': case '5': case '6': case '7':
  423. X            c = s[-1] - '0';
  424. X            if ('0' <= *s && *s <= '7') {
  425. X                c = (c<<3) + *s++ - '0';
  426. X                if ('0' <= *s && *s <= '7')
  427. X                    c = (c<<3) + *s++ - '0';
  428. X            }
  429. X            *p++ = c;
  430. X            break;
  431. X        case 'x':
  432. X            if (isxdigit(*s)) {
  433. X                sscanf(s, "%x", &c);
  434. X                *p++ = c;
  435. X                do {
  436. X                    s++;
  437. X                } while (isxdigit(*s));
  438. X                break;
  439. X            }
  440. X        /* FALLTHROUGH */
  441. X        default: *p++ = '\\'; *p++ = s[-1]; break;
  442. X        }
  443. X    }
  444. X    resizestring(&v, (int)(p - buf));
  445. X    return v;
  446. X}
  447. X
  448. Xstatic void
  449. Xcom_list_constructor(c, n)
  450. X    struct compiling *c;
  451. X    node *n;
  452. X{
  453. X    int len;
  454. X    int i;
  455. X    object *v, *w;
  456. X    if (TYPE(n) != testlist)
  457. X        REQ(n, exprlist);
  458. X    /* exprlist: expr (',' expr)* [',']; likewise for testlist */
  459. X    len = (NCH(n) + 1) / 2;
  460. X    for (i = 0; i < NCH(n); i += 2)
  461. X        com_node(c, CHILD(n, i));
  462. X    com_addoparg(c, BUILD_LIST, len);
  463. X}
  464. X
  465. Xstatic void
  466. Xcom_atom(c, n)
  467. X    struct compiling *c;
  468. X    node *n;
  469. X{
  470. X    node *ch;
  471. X    object *v;
  472. X    int i;
  473. X    REQ(n, atom);
  474. X    ch = CHILD(n, 0);
  475. X    switch (TYPE(ch)) {
  476. X    case LPAR:
  477. X        if (TYPE(CHILD(n, 1)) == RPAR)
  478. X            com_addoparg(c, BUILD_TUPLE, 0);
  479. X        else
  480. X            com_node(c, CHILD(n, 1));
  481. X        break;
  482. X    case LSQB:
  483. X        if (TYPE(CHILD(n, 1)) == RSQB)
  484. X            com_addoparg(c, BUILD_LIST, 0);
  485. X        else
  486. X            com_list_constructor(c, CHILD(n, 1));
  487. X        break;
  488. X    case LBRACE:
  489. X        com_addoparg(c, BUILD_MAP, 0);
  490. X        break;
  491. X    case BACKQUOTE:
  492. X        com_node(c, CHILD(n, 1));
  493. X        com_addbyte(c, UNARY_CONVERT);
  494. X        break;
  495. X    case NUMBER:
  496. X        if ((v = parsenumber(STR(ch))) == NULL) {
  497. X            c->c_errors++;
  498. X            i = 255;
  499. X        }
  500. X        else {
  501. X            i = com_addconst(c, v);
  502. X            DECREF(v);
  503. X        }
  504. X        com_addoparg(c, LOAD_CONST, i);
  505. X        break;
  506. X    case STRING:
  507. X        if ((v = parsestr(STR(ch))) == NULL) {
  508. X            c->c_errors++;
  509. X            i = 255;
  510. X        }
  511. X        else {
  512. X            i = com_addconst(c, v);
  513. X            DECREF(v);
  514. X        }
  515. X        com_addoparg(c, LOAD_CONST, i);
  516. X        break;
  517. X    case NAME:
  518. X        com_addopname(c, LOAD_NAME, ch);
  519. X        break;
  520. X    default:
  521. X        fprintf(stderr, "node type %d\n", TYPE(ch));
  522. X        err_setstr(SystemError, "com_atom: unexpected node type");
  523. X        c->c_errors++;
  524. X    }
  525. X}
  526. X
  527. Xstatic void
  528. Xcom_slice(c, n, op)
  529. X    struct compiling *c;
  530. X    node *n;
  531. X    int op;
  532. X{
  533. X    if (NCH(n) == 1) {
  534. X        com_addbyte(c, op);
  535. X    }
  536. X    else if (NCH(n) == 2) {
  537. X        if (TYPE(CHILD(n, 0)) != COLON) {
  538. X            com_node(c, CHILD(n, 0));
  539. X            com_addbyte(c, op+1);
  540. X        }
  541. X        else {
  542. X            com_node(c, CHILD(n, 1));
  543. X            com_addbyte(c, op+2);
  544. X        }
  545. X    }
  546. X    else {
  547. X        com_node(c, CHILD(n, 0));
  548. X        com_node(c, CHILD(n, 2));
  549. X        com_addbyte(c, op+3);
  550. X    }
  551. X}
  552. X
  553. Xstatic void
  554. Xcom_apply_subscript(c, n)
  555. X    struct compiling *c;
  556. X    node *n;
  557. X{
  558. X    REQ(n, subscript);
  559. X    if (NCH(n) == 1 && TYPE(CHILD(n, 0)) != COLON) {
  560. X        /* It's a single subscript */
  561. X        com_node(c, CHILD(n, 0));
  562. X        com_addbyte(c, BINARY_SUBSCR);
  563. X    }
  564. X    else {
  565. X        /* It's a slice: [expr] ':' [expr] */
  566. X        com_slice(c, n, SLICE);
  567. X    }
  568. X}
  569. X
  570. Xstatic void
  571. Xcom_call_function(c, n)
  572. X    struct compiling *c;
  573. X    node *n; /* EITHER testlist OR ')' */
  574. X{
  575. X    if (TYPE(n) == RPAR) {
  576. X        com_addbyte(c, UNARY_CALL);
  577. X    }
  578. X    else {
  579. X        com_node(c, n);
  580. X        com_addbyte(c, BINARY_CALL);
  581. X    }
  582. X}
  583. X
  584. Xstatic void
  585. Xcom_select_member(c, n)
  586. X    struct compiling *c;
  587. X    node *n;
  588. X{
  589. X    com_addopname(c, LOAD_ATTR, n);
  590. X}
  591. X
  592. Xstatic void
  593. Xcom_apply_trailer(c, n)
  594. X    struct compiling *c;
  595. X    node *n;
  596. X{
  597. X    REQ(n, trailer);
  598. X    switch (TYPE(CHILD(n, 0))) {
  599. X    case LPAR:
  600. X        com_call_function(c, CHILD(n, 1));
  601. X        break;
  602. X    case DOT:
  603. X        com_select_member(c, CHILD(n, 1));
  604. X        break;
  605. X    case LSQB:
  606. X        com_apply_subscript(c, CHILD(n, 1));
  607. X        break;
  608. X    default:
  609. X        err_setstr(SystemError,
  610. X            "com_apply_trailer: unknown trailer type");
  611. X        c->c_errors++;
  612. X    }
  613. X}
  614. X
  615. Xstatic void
  616. Xcom_factor(c, n)
  617. X    struct compiling *c;
  618. X    node *n;
  619. X{
  620. X    int i;
  621. X    REQ(n, factor);
  622. X    if (TYPE(CHILD(n, 0)) == PLUS) {
  623. X        com_factor(c, CHILD(n, 1));
  624. X        com_addbyte(c, UNARY_POSITIVE);
  625. X    }
  626. X    else if (TYPE(CHILD(n, 0)) == MINUS) {
  627. X        com_factor(c, CHILD(n, 1));
  628. X        com_addbyte(c, UNARY_NEGATIVE);
  629. X    }
  630. X    else {
  631. X        com_atom(c, CHILD(n, 0));
  632. X        for (i = 1; i < NCH(n); i++)
  633. X            com_apply_trailer(c, CHILD(n, i));
  634. X    }
  635. X}
  636. X
  637. Xstatic void
  638. Xcom_term(c, n)
  639. X    struct compiling *c;
  640. X    node *n;
  641. X{
  642. X    int i;
  643. X    int op;
  644. X    REQ(n, term);
  645. X    com_factor(c, CHILD(n, 0));
  646. X    for (i = 2; i < NCH(n); i += 2) {
  647. X        com_factor(c, CHILD(n, i));
  648. X        switch (TYPE(CHILD(n, i-1))) {
  649. X        case STAR:
  650. X            op = BINARY_MULTIPLY;
  651. X            break;
  652. X        case SLASH:
  653. X            op = BINARY_DIVIDE;
  654. X            break;
  655. X        case PERCENT:
  656. X            op = BINARY_MODULO;
  657. X            break;
  658. X        default:
  659. X            err_setstr(SystemError,
  660. X                "com_term: term operator not *, / or %");
  661. X            c->c_errors++;
  662. X            op = 255;
  663. X        }
  664. X        com_addbyte(c, op);
  665. X    }
  666. X}
  667. X
  668. Xstatic void
  669. Xcom_expr(c, n)
  670. X    struct compiling *c;
  671. X    node *n;
  672. X{
  673. X    int i;
  674. X    int op;
  675. X    REQ(n, expr);
  676. X    com_term(c, CHILD(n, 0));
  677. X    for (i = 2; i < NCH(n); i += 2) {
  678. X        com_term(c, CHILD(n, i));
  679. X        switch (TYPE(CHILD(n, i-1))) {
  680. X        case PLUS:
  681. X            op = BINARY_ADD;
  682. X            break;
  683. X        case MINUS:
  684. X            op = BINARY_SUBTRACT;
  685. X            break;
  686. X        default:
  687. X            err_setstr(SystemError,
  688. X                "com_expr: expr operator not + or -");
  689. X            c->c_errors++;
  690. X            op = 255;
  691. X        }
  692. X        com_addbyte(c, op);
  693. X    }
  694. X}
  695. X
  696. Xstatic enum cmp_op
  697. Xcmp_type(n)
  698. X    node *n;
  699. X{
  700. X    REQ(n, comp_op);
  701. X    /* comp_op: '<' | '>' | '=' | '>' '=' | '<' '=' | '<' '>'
  702. X              | 'in' | 'not' 'in' | 'is' | 'is' not' */
  703. X    if (NCH(n) == 1) {
  704. X        n = CHILD(n, 0);
  705. X        switch (TYPE(n)) {
  706. X        case LESS:    return LT;
  707. X        case GREATER:    return GT;
  708. X        case EQUAL:    return EQ;
  709. X        case NAME:    if (strcmp(STR(n), "in") == 0) return IN;
  710. X                if (strcmp(STR(n), "is") == 0) return IS;
  711. X        }
  712. X    }
  713. X    else if (NCH(n) == 2) {
  714. X        int t2 = TYPE(CHILD(n, 1));
  715. X        switch (TYPE(CHILD(n, 0))) {
  716. X        case LESS:    if (t2 == EQUAL)    return LE;
  717. X                if (t2 == GREATER)    return NE;
  718. X                break;
  719. X        case GREATER:    if (t2 == EQUAL)    return GE;
  720. X                break;
  721. X        case NAME:    if (strcmp(STR(CHILD(n, 1)), "in") == 0)
  722. X                    return NOT_IN;
  723. X                if (strcmp(STR(CHILD(n, 0)), "is") == 0)
  724. X                    return IS_NOT;
  725. X        }
  726. X    }
  727. X    return BAD;
  728. X}
  729. X
  730. Xstatic void
  731. Xcom_comparison(c, n)
  732. X    struct compiling *c;
  733. X    node *n;
  734. X{
  735. X    int i;
  736. X    enum cmp_op op;
  737. X    int anchor;
  738. X    REQ(n, comparison); /* comparison: expr (comp_op expr)* */
  739. X    com_expr(c, CHILD(n, 0));
  740. X    if (NCH(n) == 1)
  741. X        return;
  742. X    
  743. X    /****************************************************************
  744. X       The following code is generated for all but the last
  745. X       comparison in a chain:
  746. X       
  747. X       label:    on stack:    opcode:        jump to:
  748. X       
  749. X            a        <code to load b>
  750. X            a, b        DUP_TOP
  751. X            a, b, b        ROT_THREE
  752. X            b, a, b        COMPARE_OP
  753. X            b, 0-or-1    JUMP_IF_FALSE    L1
  754. X            b, 1        POP_TOP
  755. X            b        
  756. X    
  757. X       We are now ready to repeat this sequence for the next
  758. X       comparison in the chain.
  759. X       
  760. X       For the last we generate:
  761. X       
  762. X               b        <code to load c>
  763. X               b, c        COMPARE_OP
  764. X               0-or-1        
  765. X       
  766. X       If there were any jumps to L1 (i.e., there was more than one
  767. X       comparison), we generate:
  768. X       
  769. X               0-or-1        JUMP_FORWARD    L2
  770. X       L1:        b, 0        ROT_TWO
  771. X               0, b        POP_TOP
  772. X               0
  773. X       L2:
  774. X    ****************************************************************/
  775. X    
  776. X    anchor = 0;
  777. X    
  778. X    for (i = 2; i < NCH(n); i += 2) {
  779. X        com_expr(c, CHILD(n, i));
  780. X        if (i+2 < NCH(n)) {
  781. X            com_addbyte(c, DUP_TOP);
  782. X            com_addbyte(c, ROT_THREE);
  783. X        }
  784. X        op = cmp_type(CHILD(n, i-1));
  785. X        if (op == BAD) {
  786. X            err_setstr(SystemError,
  787. X                "com_comparison: unknown comparison op");
  788. X            c->c_errors++;
  789. X        }
  790. X        com_addoparg(c, COMPARE_OP, op);
  791. X        if (i+2 < NCH(n)) {
  792. X            com_addfwref(c, JUMP_IF_FALSE, &anchor);
  793. X            com_addbyte(c, POP_TOP);
  794. X        }
  795. X    }
  796. X    
  797. X    if (anchor) {
  798. X        int anchor2 = 0;
  799. X        com_addfwref(c, JUMP_FORWARD, &anchor2);
  800. X        com_backpatch(c, anchor);
  801. X        com_addbyte(c, ROT_TWO);
  802. X        com_addbyte(c, POP_TOP);
  803. X        com_backpatch(c, anchor2);
  804. X    }
  805. X}
  806. X
  807. Xstatic void
  808. Xcom_not_test(c, n)
  809. X    struct compiling *c;
  810. X    node *n;
  811. X{
  812. X    REQ(n, not_test); /* 'not' not_test | comparison */
  813. X    if (NCH(n) == 1) {
  814. X        com_comparison(c, CHILD(n, 0));
  815. X    }
  816. X    else {
  817. X        com_not_test(c, CHILD(n, 1));
  818. X        com_addbyte(c, UNARY_NOT);
  819. X    }
  820. X}
  821. X
  822. Xstatic void
  823. Xcom_and_test(c, n)
  824. X    struct compiling *c;
  825. X    node *n;
  826. X{
  827. X    int i;
  828. X    int anchor;
  829. X    REQ(n, and_test); /* not_test ('and' not_test)* */
  830. X    anchor = 0;
  831. X    i = 0;
  832. X    for (;;) {
  833. X        com_not_test(c, CHILD(n, i));
  834. X        if ((i += 2) >= NCH(n))
  835. X            break;
  836. X        com_addfwref(c, JUMP_IF_FALSE, &anchor);
  837. X        com_addbyte(c, POP_TOP);
  838. X    }
  839. X    if (anchor)
  840. X        com_backpatch(c, anchor);
  841. X}
  842. X
  843. Xstatic void
  844. Xcom_test(c, n)
  845. X    struct compiling *c;
  846. X    node *n;
  847. X{
  848. X    int i;
  849. X    int anchor;
  850. X    REQ(n, test); /* and_test ('and' and_test)* */
  851. X    anchor = 0;
  852. X    i = 0;
  853. X    for (;;) {
  854. X        com_and_test(c, CHILD(n, i));
  855. X        if ((i += 2) >= NCH(n))
  856. X            break;
  857. X        com_addfwref(c, JUMP_IF_TRUE, &anchor);
  858. X        com_addbyte(c, POP_TOP);
  859. X    }
  860. X    if (anchor)
  861. X        com_backpatch(c, anchor);
  862. X}
  863. X
  864. Xstatic void
  865. Xcom_list(c, n)
  866. X    struct compiling *c;
  867. X    node *n;
  868. X{
  869. X    /* exprlist: expr (',' expr)* [',']; likewise for testlist */
  870. X    if (NCH(n) == 1) {
  871. X        com_node(c, CHILD(n, 0));
  872. X    }
  873. X    else {
  874. X        int i;
  875. X        int len;
  876. X        len = (NCH(n) + 1) / 2;
  877. X        for (i = 0; i < NCH(n); i += 2)
  878. X            com_node(c, CHILD(n, i));
  879. X        com_addoparg(c, BUILD_TUPLE, len);
  880. X    }
  881. X}
  882. X
  883. X
  884. X/* Begin of assignment compilation */
  885. X
  886. Xstatic void com_assign_name PROTO((struct compiling *, node *, int));
  887. Xstatic void com_assign PROTO((struct compiling *, node *, int));
  888. X
  889. Xstatic void
  890. Xcom_assign_attr(c, n, assigning)
  891. X    struct compiling *c;
  892. X    node *n;
  893. X    int assigning;
  894. X{
  895. X    com_addopname(c, assigning ? STORE_ATTR : DELETE_ATTR, n);
  896. X}
  897. X
  898. Xstatic void
  899. Xcom_assign_slice(c, n, assigning)
  900. X    struct compiling *c;
  901. X    node *n;
  902. X    int assigning;
  903. X{
  904. X    com_slice(c, n, assigning ? STORE_SLICE : DELETE_SLICE);
  905. X}
  906. X
  907. Xstatic void
  908. Xcom_assign_subscript(c, n, assigning)
  909. X    struct compiling *c;
  910. X    node *n;
  911. X    int assigning;
  912. X{
  913. X    com_node(c, n);
  914. X    com_addbyte(c, assigning ? STORE_SUBSCR : DELETE_SUBSCR);
  915. X}
  916. X
  917. Xstatic void
  918. Xcom_assign_trailer(c, n, assigning)
  919. X    struct compiling *c;
  920. X    node *n;
  921. X    int assigning;
  922. X{
  923. X    char *name;
  924. X    REQ(n, trailer);
  925. X    switch (TYPE(CHILD(n, 0))) {
  926. X    case LPAR: /* '(' [exprlist] ')' */
  927. X        err_setstr(TypeError, "can't assign to function call");
  928. X        c->c_errors++;
  929. X        break;
  930. X    case DOT: /* '.' NAME */
  931. X        com_assign_attr(c, CHILD(n, 1), assigning);
  932. X        break;
  933. X    case LSQB: /* '[' subscript ']' */
  934. X        n = CHILD(n, 1);
  935. X        REQ(n, subscript); /* subscript: expr | [expr] ':' [expr] */
  936. X        if (NCH(n) > 1 || TYPE(CHILD(n, 0)) == COLON)
  937. X            com_assign_slice(c, n, assigning);
  938. X        else
  939. X            com_assign_subscript(c, CHILD(n, 0), assigning);
  940. X        break;
  941. X    default:
  942. X        err_setstr(TypeError, "unknown trailer type");
  943. X        c->c_errors++;
  944. X    }
  945. X}
  946. X
  947. Xstatic void
  948. Xcom_assign_tuple(c, n, assigning)
  949. X    struct compiling *c;
  950. X    node *n;
  951. X    int assigning;
  952. X{
  953. X    int i;
  954. X    if (TYPE(n) != testlist)
  955. X        REQ(n, exprlist);
  956. X    if (assigning)
  957. X        com_addoparg(c, UNPACK_TUPLE, (NCH(n)+1)/2);
  958. X    for (i = 0; i < NCH(n); i += 2)
  959. X        com_assign(c, CHILD(n, i), assigning);
  960. X}
  961. X
  962. Xstatic void
  963. Xcom_assign_list(c, n, assigning)
  964. X    struct compiling *c;
  965. X    node *n;
  966. X    int assigning;
  967. X{
  968. X    int i;
  969. X    if (assigning)
  970. X        com_addoparg(c, UNPACK_LIST, (NCH(n)+1)/2);
  971. X    for (i = 0; i < NCH(n); i += 2)
  972. X        com_assign(c, CHILD(n, i), assigning);
  973. X}
  974. X
  975. Xstatic void
  976. Xcom_assign_name(c, n, assigning)
  977. X    struct compiling *c;
  978. X    node *n;
  979. X    int assigning;
  980. X{
  981. X    REQ(n, NAME);
  982. X    com_addopname(c, assigning ? STORE_NAME : DELETE_NAME, n);
  983. X}
  984. X
  985. Xstatic void
  986. Xcom_assign(c, n, assigning)
  987. X    struct compiling *c;
  988. X    node *n;
  989. X    int assigning;
  990. X{
  991. X    /* Loop to avoid trivial recursion */
  992. X    for (;;) {
  993. X        switch (TYPE(n)) {
  994. X        
  995. X        case exprlist:
  996. X        case testlist:
  997. X            if (NCH(n) > 1) {
  998. X                com_assign_tuple(c, n, assigning);
  999. X                return;
  1000. X            }
  1001. X            n = CHILD(n, 0);
  1002. X            break;
  1003. X        
  1004. X        case test:
  1005. X        case and_test:
  1006. X        case not_test:
  1007. X            if (NCH(n) > 1) {
  1008. X                err_setstr(TypeError,
  1009. X                    "can't assign to operator");
  1010. X                c->c_errors++;
  1011. X                return;
  1012. X            }
  1013. X            n = CHILD(n, 0);
  1014. X            break;
  1015. X        
  1016. X        case comparison:
  1017. X            if (NCH(n) > 1) {
  1018. X                err_setstr(TypeError,
  1019. X                    "can't assign to operator");
  1020. X                c->c_errors++;
  1021. X                return;
  1022. X            }
  1023. X            n = CHILD(n, 0);
  1024. X            break;
  1025. X        
  1026. X        case expr:
  1027. X            if (NCH(n) > 1) {
  1028. X                err_setstr(TypeError,
  1029. X                    "can't assign to operator");
  1030. X                c->c_errors++;
  1031. X                return;
  1032. X            }
  1033. X            n = CHILD(n, 0);
  1034. X            break;
  1035. X        
  1036. X        case term:
  1037. X            if (NCH(n) > 1) {
  1038. X                err_setstr(TypeError,
  1039. X                    "can't assign to operator");
  1040. X                c->c_errors++;
  1041. X                return;
  1042. X            }
  1043. X            n = CHILD(n, 0);
  1044. X            break;
  1045. X        
  1046. X        case factor: /* ('+'|'-') factor | atom trailer* */
  1047. X            if (TYPE(CHILD(n, 0)) != atom) { /* '+' | '-' */
  1048. X                err_setstr(TypeError,
  1049. X                    "can't assign to operator");
  1050. X                c->c_errors++;
  1051. X                return;
  1052. X            }
  1053. X            if (NCH(n) > 1) { /* trailer present */
  1054. X                int i;
  1055. X                com_node(c, CHILD(n, 0));
  1056. X                for (i = 1; i+1 < NCH(n); i++) {
  1057. X                    com_apply_trailer(c, CHILD(n, i));
  1058. X                } /* NB i is still alive */
  1059. X                com_assign_trailer(c,
  1060. X                        CHILD(n, i), assigning);
  1061. X                return;
  1062. X            }
  1063. X            n = CHILD(n, 0);
  1064. X            break;
  1065. X        
  1066. X        case atom:
  1067. X            switch (TYPE(CHILD(n, 0))) {
  1068. X            case LPAR:
  1069. X                n = CHILD(n, 1);
  1070. X                if (TYPE(n) == RPAR) {
  1071. X                    /* XXX Should allow () = () ??? */
  1072. X                    err_setstr(TypeError,
  1073. X                        "can't assign to ()");
  1074. X                    c->c_errors++;
  1075. X                    return;
  1076. X                }
  1077. X                break;
  1078. X            case LSQB:
  1079. X                n = CHILD(n, 1);
  1080. X                if (TYPE(n) == RSQB) {
  1081. X                    err_setstr(TypeError,
  1082. X                        "can't assign to []");
  1083. X                    c->c_errors++;
  1084. X                    return;
  1085. X                }
  1086. X                com_assign_list(c, n, assigning);
  1087. X                return;
  1088. X            case NAME:
  1089. X                com_assign_name(c, CHILD(n, 0), assigning);
  1090. X                return;
  1091. X            default:
  1092. X                err_setstr(TypeError,
  1093. X                        "can't assign to constant");
  1094. X                c->c_errors++;
  1095. X                return;
  1096. X            }
  1097. X            break;
  1098. X        
  1099. X        default:
  1100. X            fprintf(stderr, "node type %d\n", TYPE(n));
  1101. X            err_setstr(SystemError, "com_assign: bad node");
  1102. X            c->c_errors++;
  1103. X            return;
  1104. X        
  1105. X        }
  1106. X    }
  1107. X}
  1108. X
  1109. Xstatic void
  1110. Xcom_expr_stmt(c, n)
  1111. X    struct compiling *c;
  1112. X    node *n;
  1113. X{
  1114. X    REQ(n, expr_stmt); /* exprlist ('=' exprlist)* NEWLINE */
  1115. X    com_node(c, CHILD(n, NCH(n)-2));
  1116. X    if (NCH(n) == 2) {
  1117. X        com_addbyte(c, PRINT_EXPR);
  1118. X    }
  1119. X    else {
  1120. X        int i;
  1121. X        for (i = 0; i < NCH(n)-3; i+=2) {
  1122. X            if (i+2 < NCH(n)-3)
  1123. X                com_addbyte(c, DUP_TOP);
  1124. X            com_assign(c, CHILD(n, i), 1/*assign*/);
  1125. X        }
  1126. X    }
  1127. X}
  1128. X
  1129. Xstatic void
  1130. Xcom_print_stmt(c, n)
  1131. X    struct compiling *c;
  1132. X    node *n;
  1133. X{
  1134. X    int i;
  1135. X    REQ(n, print_stmt); /* 'print' (test ',')* [test] NEWLINE */
  1136. X    for (i = 1; i+1 < NCH(n); i += 2) {
  1137. X        com_node(c, CHILD(n, i));
  1138. X        com_addbyte(c, PRINT_ITEM);
  1139. X    }
  1140. X    if (TYPE(CHILD(n, NCH(n)-2)) != COMMA)
  1141. X        com_addbyte(c, PRINT_NEWLINE);
  1142. X        /* XXX Alternatively, LOAD_CONST '\n' and then PRINT_ITEM */
  1143. X}
  1144. X
  1145. Xstatic void
  1146. Xcom_return_stmt(c, n)
  1147. X    struct compiling *c;
  1148. X    node *n;
  1149. X{
  1150. X    REQ(n, return_stmt); /* 'return' [testlist] NEWLINE */
  1151. X    if (!c->c_infunction) {
  1152. X        err_setstr(TypeError, "'return' outside function");
  1153. X        c->c_errors++;
  1154. X    }
  1155. X    if (NCH(n) == 2)
  1156. X        com_addoparg(c, LOAD_CONST, com_addconst(c, None));
  1157. X    else
  1158. X        com_node(c, CHILD(n, 1));
  1159. X    com_addbyte(c, RETURN_VALUE);
  1160. X}
  1161. X
  1162. Xstatic void
  1163. Xcom_raise_stmt(c, n)
  1164. X    struct compiling *c;
  1165. X    node *n;
  1166. X{
  1167. X    REQ(n, raise_stmt); /* 'raise' expr [',' expr] NEWLINE */
  1168. X    com_node(c, CHILD(n, 1));
  1169. X    if (NCH(n) > 3)
  1170. X        com_node(c, CHILD(n, 3));
  1171. X    else
  1172. X        com_addoparg(c, LOAD_CONST, com_addconst(c, None));
  1173. X    com_addbyte(c, RAISE_EXCEPTION);
  1174. X}
  1175. X
  1176. Xstatic void
  1177. Xcom_import_stmt(c, n)
  1178. X    struct compiling *c;
  1179. X    node *n;
  1180. X{
  1181. X    int i;
  1182. X    REQ(n, import_stmt);
  1183. X    /* 'import' NAME (',' NAME)* NEWLINE |
  1184. X       'from' NAME 'import' ('*' | NAME (',' NAME)*) NEWLINE */
  1185. X    if (STR(CHILD(n, 0))[0] == 'f') {
  1186. X        /* 'from' NAME 'import' ... */
  1187. X        REQ(CHILD(n, 1), NAME);
  1188. X        com_addopname(c, IMPORT_NAME, CHILD(n, 1));
  1189. X        for (i = 3; i < NCH(n); i += 2)
  1190. X            com_addopname(c, IMPORT_FROM, CHILD(n, i));
  1191. X        com_addbyte(c, POP_TOP);
  1192. X    }
  1193. X    else {
  1194. X        /* 'import' ... */
  1195. X        for (i = 1; i < NCH(n); i += 2) {
  1196. X            com_addopname(c, IMPORT_NAME, CHILD(n, i));
  1197. X            com_addopname(c, STORE_NAME, CHILD(n, i));
  1198. X        }
  1199. X    }
  1200. X}
  1201. X
  1202. Xstatic void
  1203. Xcom_if_stmt(c, n)
  1204. X    struct compiling *c;
  1205. X    node *n;
  1206. X{
  1207. X    int i;
  1208. X    int anchor = 0;
  1209. X    REQ(n, if_stmt);
  1210. X    /*'if' test ':' suite ('elif' test ':' suite)* ['else' ':' suite] */
  1211. X    for (i = 0; i+3 < NCH(n); i+=4) {
  1212. X        int a = 0;
  1213. X        node *ch = CHILD(n, i+1);
  1214. X        if (i > 0)
  1215. X            com_addoparg(c, SET_LINENO, ch->n_lineno);
  1216. X        com_node(c, CHILD(n, i+1));
  1217. X        com_addfwref(c, JUMP_IF_FALSE, &a);
  1218. X        com_addbyte(c, POP_TOP);
  1219. X        com_node(c, CHILD(n, i+3));
  1220. X        com_addfwref(c, JUMP_FORWARD, &anchor);
  1221. X        com_backpatch(c, a);
  1222. X        com_addbyte(c, POP_TOP);
  1223. X    }
  1224. X    if (i+2 < NCH(n))
  1225. X        com_node(c, CHILD(n, i+2));
  1226. X    com_backpatch(c, anchor);
  1227. X}
  1228. X
  1229. Xstatic void
  1230. Xcom_while_stmt(c, n)
  1231. X    struct compiling *c;
  1232. X    node *n;
  1233. X{
  1234. X    int break_anchor = 0;
  1235. X    int anchor = 0;
  1236. X    int begin;
  1237. X    REQ(n, while_stmt); /* 'while' test ':' suite ['else' ':' suite] */
  1238. X    com_addfwref(c, SETUP_LOOP, &break_anchor);
  1239. X    begin = c->c_nexti;
  1240. X    com_addoparg(c, SET_LINENO, n->n_lineno);
  1241. X    com_node(c, CHILD(n, 1));
  1242. X    com_addfwref(c, JUMP_IF_FALSE, &anchor);
  1243. X    com_addbyte(c, POP_TOP);
  1244. X    c->c_loops++;
  1245. X    com_node(c, CHILD(n, 3));
  1246. X    c->c_loops--;
  1247. X    com_addoparg(c, JUMP_ABSOLUTE, begin);
  1248. X    com_backpatch(c, anchor);
  1249. X    com_addbyte(c, POP_TOP);
  1250. X    com_addbyte(c, POP_BLOCK);
  1251. X    if (NCH(n) > 4)
  1252. X        com_node(c, CHILD(n, 6));
  1253. X    com_backpatch(c, break_anchor);
  1254. X}
  1255. X
  1256. Xstatic void
  1257. Xcom_for_stmt(c, n)
  1258. X    struct compiling *c;
  1259. X    node *n;
  1260. X{
  1261. X    object *v;
  1262. X    int break_anchor = 0;
  1263. X    int anchor = 0;
  1264. X    int begin;
  1265. X    REQ(n, for_stmt);
  1266. X    /* 'for' exprlist 'in' exprlist ':' suite ['else' ':' suite] */
  1267. X    com_addfwref(c, SETUP_LOOP, &break_anchor);
  1268. X    com_node(c, CHILD(n, 3));
  1269. X    v = newintobject(0L);
  1270. X    if (v == NULL)
  1271. X        c->c_errors++;
  1272. X    com_addoparg(c, LOAD_CONST, com_addconst(c, v));
  1273. X    XDECREF(v);
  1274. X    begin = c->c_nexti;
  1275. X    com_addoparg(c, SET_LINENO, n->n_lineno);
  1276. X    com_addfwref(c, FOR_LOOP, &anchor);
  1277. X    com_assign(c, CHILD(n, 1), 1/*assigning*/);
  1278. X    c->c_loops++;
  1279. X    com_node(c, CHILD(n, 5));
  1280. X    c->c_loops--;
  1281. X    com_addoparg(c, JUMP_ABSOLUTE, begin);
  1282. X    com_backpatch(c, anchor);
  1283. X    com_addbyte(c, POP_BLOCK);
  1284. X    if (NCH(n) > 8)
  1285. X        com_node(c, CHILD(n, 8));
  1286. X    com_backpatch(c, break_anchor);
  1287. X}
  1288. X
  1289. X/* Although 'execpt' and 'finally' clauses can be combined
  1290. X   syntactically, they are compiled separately.  In fact,
  1291. X    try: S
  1292. X    except E1: S1
  1293. X    except E2: S2
  1294. X    ...
  1295. X    finally: Sf
  1296. X   is equivalent to
  1297. X    try:
  1298. X        try: S
  1299. X        except E1: S1
  1300. X        except E2: S2
  1301. X        ...
  1302. X    finally: Sf
  1303. X   meaning that the 'finally' clause is entered even if things
  1304. X   go wrong again in an exception handler.  Note that this is
  1305. X   not the case for exception handlers: at most one is entered.
  1306. X   
  1307. X   Code generated for "try: S finally: Sf" is as follows:
  1308. X   
  1309. X        SETUP_FINALLY    L
  1310. X        <code for S>
  1311. X        POP_BLOCK
  1312. X        LOAD_CONST    <nil>
  1313. X    L:    <code for Sf>
  1314. X        END_FINALLY
  1315. X   
  1316. X   The special instructions use the block stack.  Each block
  1317. X   stack entry contains the instruction that created it (here
  1318. X   SETUP_FINALLY), the level of the value stack at the time the
  1319. X   block stack entry was created, and a label (here L).
  1320. X   
  1321. X   SETUP_FINALLY:
  1322. X    Pushes the current value stack level and the label
  1323. X    onto the block stack.
  1324. X   POP_BLOCK:
  1325. X    Pops en entry from the block stack, and pops the value
  1326. X    stack until its level is the same as indicated on the
  1327. X    block stack.  (The label is ignored.)
  1328. X   END_FINALLY:
  1329. X    Pops a variable number of entries from the *value* stack
  1330. X    and re-raises the exception they specify.  The number of
  1331. X    entries popped depends on the (pseudo) exception type.
  1332. X   
  1333. X   The block stack is unwound when an exception is raised:
  1334. X   when a SETUP_FINALLY entry is found, the exception is pushed
  1335. X   onto the value stack (and the exception condition is cleared),
  1336. X   and the interpreter jumps to the label gotten from the block
  1337. X   stack.
  1338. X   
  1339. X   Code generated for "try: S except E1, V1: S1 except E2, V2: S2 ...":
  1340. X   (The contents of the value stack is shown in [], with the top
  1341. X   at the right; 'tb' is trace-back info, 'val' the exception's
  1342. X   associated value, and 'exc' the exception.)
  1343. X   
  1344. X   Value stack        Label    Instruction    Argument
  1345. X   []                SETUP_EXCEPT    L1
  1346. X   []                <code for S>
  1347. X   []                POP_BLOCK
  1348. X   []                JUMP_FORWARD    L0
  1349. X   
  1350. X   [tb, val, exc]    L1:    DUP                )
  1351. X   [tb, val, exc, exc]        <evaluate E1>            )
  1352. X   [tb, val, exc, exc, E1]    COMPARE_OP    EXC_MATCH    ) only if E1
  1353. X   [tb, val, exc, 1-or-0]    JUMP_IF_FALSE    L2        )
  1354. X   [tb, val, exc, 1]        POP                )
  1355. X   [tb, val, exc]        POP
  1356. X   [tb, val]            <assign to V1>    (or POP if no V1)
  1357. X   [tb]                POP
  1358. X   []                <code for S1>
  1359. X                   JUMP_FORWARD    L0
  1360. X   
  1361. X   [tb, val, exc, 0]    L2:    POP
  1362. X   [tb, val, exc]        DUP
  1363. X   .............................etc.......................
  1364. X
  1365. X   [tb, val, exc, 0]    Ln+1:    POP
  1366. X   [tb, val, exc]           END_FINALLY    # re-raise exception
  1367. X   
  1368. X   []            L0:    <next statement>
  1369. X   
  1370. X   Of course, parts are not generated if Vi or Ei is not present.
  1371. X*/
  1372. X
  1373. Xstatic void
  1374. Xcom_try_stmt(c, n)
  1375. X    struct compiling *c;
  1376. X    node *n;
  1377. X{
  1378. X    int finally_anchor = 0;
  1379. X    int except_anchor = 0;
  1380. X    REQ(n, try_stmt);
  1381. X    /* 'try' ':' suite (except_clause ':' suite)* ['finally' ':' suite] */
  1382. X    
  1383. X    if (NCH(n) > 3 && TYPE(CHILD(n, NCH(n)-3)) != except_clause) {
  1384. X        /* Have a 'finally' clause */
  1385. X        com_addfwref(c, SETUP_FINALLY, &finally_anchor);
  1386. X    }
  1387. X    if (NCH(n) > 3 && TYPE(CHILD(n, 3)) == except_clause) {
  1388. X        /* Have an 'except' clause */
  1389. X        com_addfwref(c, SETUP_EXCEPT, &except_anchor);
  1390. X    }
  1391. X    com_node(c, CHILD(n, 2));
  1392. X    if (except_anchor) {
  1393. X        int end_anchor = 0;
  1394. X        int i;
  1395. X        node *ch;
  1396. X        com_addbyte(c, POP_BLOCK);
  1397. X        com_addfwref(c, JUMP_FORWARD, &end_anchor);
  1398. X        com_backpatch(c, except_anchor);
  1399. X        for (i = 3;
  1400. X            i < NCH(n) && TYPE(ch = CHILD(n, i)) == except_clause;
  1401. X                                i += 3) {
  1402. X            /* except_clause: 'except' [expr [',' expr]] */
  1403. X            if (except_anchor == 0) {
  1404. X                err_setstr(TypeError,
  1405. X                    "default 'except:' must be last");
  1406. X                c->c_errors++;
  1407. X                break;
  1408. X            }
  1409. X            except_anchor = 0;
  1410. X            com_addoparg(c, SET_LINENO, ch->n_lineno);
  1411. X            if (NCH(ch) > 1) {
  1412. X                com_addbyte(c, DUP_TOP);
  1413. X                com_node(c, CHILD(ch, 1));
  1414. X                com_addoparg(c, COMPARE_OP, EXC_MATCH);
  1415. X                com_addfwref(c, JUMP_IF_FALSE, &except_anchor);
  1416. X                com_addbyte(c, POP_TOP);
  1417. X            }
  1418. X            com_addbyte(c, POP_TOP);
  1419. X            if (NCH(ch) > 3)
  1420. X                com_assign(c, CHILD(ch, 3), 1/*assigning*/);
  1421. X            else
  1422. X                com_addbyte(c, POP_TOP);
  1423. X            com_addbyte(c, POP_TOP);
  1424. X            com_node(c, CHILD(n, i+2));
  1425. X            com_addfwref(c, JUMP_FORWARD, &end_anchor);
  1426. X            if (except_anchor) {
  1427. X                com_backpatch(c, except_anchor);
  1428. X                com_addbyte(c, POP_TOP);
  1429. X            }
  1430. X        }
  1431. X        com_addbyte(c, END_FINALLY);
  1432. X        com_backpatch(c, end_anchor);
  1433. X    }
  1434. X    if (finally_anchor) {
  1435. X        node *ch;
  1436. X        com_addbyte(c, POP_BLOCK);
  1437. X        com_addoparg(c, LOAD_CONST, com_addconst(c, None));
  1438. X        com_backpatch(c, finally_anchor);
  1439. X        ch = CHILD(n, NCH(n)-1);
  1440. X        com_addoparg(c, SET_LINENO, ch->n_lineno);
  1441. X        com_node(c, ch);
  1442. X        com_addbyte(c, END_FINALLY);
  1443. X    }
  1444. X}
  1445. X
  1446. Xstatic void
  1447. Xcom_suite(c, n)
  1448. X    struct compiling *c;
  1449. X    node *n;
  1450. X{
  1451. X    REQ(n, suite);
  1452. X    /* simple_stmt | NEWLINE INDENT NEWLINE* (stmt NEWLINE*)+ DEDENT */
  1453. X    if (NCH(n) == 1) {
  1454. X        com_node(c, CHILD(n, 0));
  1455. X    }
  1456. X    else {
  1457. X        int i;
  1458. X        for (i = 0; i < NCH(n); i++) {
  1459. X            node *ch = CHILD(n, i);
  1460. X            if (TYPE(ch) == stmt)
  1461. X                com_node(c, ch);
  1462. X        }
  1463. X    }
  1464. X}
  1465. X
  1466. Xstatic void
  1467. Xcom_funcdef(c, n)
  1468. X    struct compiling *c;
  1469. X    node *n;
  1470. X{
  1471. X    object *v;
  1472. X    REQ(n, funcdef); /* funcdef: 'def' NAME parameters ':' suite */
  1473. X    v = (object *)compile(n, c->c_filename);
  1474. X    if (v == NULL)
  1475. X        c->c_errors++;
  1476. X    else {
  1477. X        int i = com_addconst(c, v);
  1478. X        com_addoparg(c, LOAD_CONST, i);
  1479. X        com_addbyte(c, BUILD_FUNCTION);
  1480. X        com_addopname(c, STORE_NAME, CHILD(n, 1));
  1481. X        DECREF(v);
  1482. X    }
  1483. X}
  1484. X
  1485. Xstatic void
  1486. Xcom_bases(c, n)
  1487. X    struct compiling *c;
  1488. X    node *n;
  1489. X{
  1490. X    int i, nbases;
  1491. X    REQ(n, baselist);
  1492. X    /*
  1493. X    baselist: atom arguments (',' atom arguments)*
  1494. X    arguments: '(' [testlist] ')'
  1495. X    */
  1496. X    for (i = 0; i < NCH(n); i += 3)
  1497. X        com_node(c, CHILD(n, i));
  1498. X    com_addoparg(c, BUILD_TUPLE, (NCH(n)+1) / 3);
  1499. X}
  1500. X
  1501. Xstatic void
  1502. Xcom_classdef(c, n)
  1503. X    struct compiling *c;
  1504. X    node *n;
  1505. X{
  1506. X    object *v;
  1507. X    REQ(n, classdef);
  1508. X    /*
  1509. X    classdef: 'class' NAME parameters ['=' baselist] ':' suite
  1510. X    baselist: atom arguments (',' atom arguments)*
  1511. X    arguments: '(' [testlist] ')'
  1512. X    */
  1513. X    if (NCH(n) == 7)
  1514. X        com_bases(c, CHILD(n, 4));
  1515. X    else
  1516. X        com_addoparg(c, LOAD_CONST, com_addconst(c, None));
  1517. X    v = (object *)compile(n, c->c_filename);
  1518. X    if (v == NULL)
  1519. X        c->c_errors++;
  1520. X    else {
  1521. X        int i = com_addconst(c, v);
  1522. X        com_addoparg(c, LOAD_CONST, i);
  1523. X        com_addbyte(c, BUILD_FUNCTION);
  1524. X        com_addbyte(c, UNARY_CALL);
  1525. X        com_addbyte(c, BUILD_CLASS);
  1526. X        com_addopname(c, STORE_NAME, CHILD(n, 1));
  1527. X        DECREF(v);
  1528. X    }
  1529. X}
  1530. X
  1531. Xstatic void
  1532. Xcom_node(c, n)
  1533. X    struct compiling *c;
  1534. X    node *n;
  1535. X{
  1536. X    switch (TYPE(n)) {
  1537. X    
  1538. X    /* Definition nodes */
  1539. X    
  1540. X    case funcdef:
  1541. X        com_funcdef(c, n);
  1542. X        break;
  1543. X    case classdef:
  1544. X        com_classdef(c, n);
  1545. X        break;
  1546. X    
  1547. X    /* Trivial parse tree nodes */
  1548. X    
  1549. X    case stmt:
  1550. X    case flow_stmt:
  1551. X        com_node(c, CHILD(n, 0));
  1552. X        break;
  1553. X
  1554. X    case simple_stmt:
  1555. X    case compound_stmt:
  1556. X        com_addoparg(c, SET_LINENO, n->n_lineno);
  1557. X        com_node(c, CHILD(n, 0));
  1558. X        break;
  1559. X
  1560. X    /* Statement nodes */
  1561. X    
  1562. X    case expr_stmt:
  1563. X        com_expr_stmt(c, n);
  1564. X        break;
  1565. X    case print_stmt:
  1566. X        com_print_stmt(c, n);
  1567. X        break;
  1568. X    case del_stmt: /* 'del' exprlist NEWLINE */
  1569. X        com_assign(c, CHILD(n, 1), 0/*delete*/);
  1570. X        break;
  1571. X    case pass_stmt:
  1572. X        break;
  1573. X    case break_stmt:
  1574. X        if (c->c_loops == 0) {
  1575. X            err_setstr(TypeError, "'break' outside loop");
  1576. X            c->c_errors++;
  1577. X        }
  1578. X        com_addbyte(c, BREAK_LOOP);
  1579. X        break;
  1580. X    case return_stmt:
  1581. X        com_return_stmt(c, n);
  1582. X        break;
  1583. X    case raise_stmt:
  1584. X        com_raise_stmt(c, n);
  1585. X        break;
  1586. X    case import_stmt:
  1587. X        com_import_stmt(c, n);
  1588. X        break;
  1589. X    case if_stmt:
  1590. X        com_if_stmt(c, n);
  1591. X        break;
  1592. X    case while_stmt:
  1593. X        com_while_stmt(c, n);
  1594. X        break;
  1595. X    case for_stmt:
  1596. X        com_for_stmt(c, n);
  1597. X        break;
  1598. X    case try_stmt:
  1599. X        com_try_stmt(c, n);
  1600. X        break;
  1601. X    case suite:
  1602. X        com_suite(c, n);
  1603. X        break;
  1604. X    
  1605. X    /* Expression nodes */
  1606. X    
  1607. X    case testlist:
  1608. X        com_list(c, n);
  1609. X        break;
  1610. X    case test:
  1611. X        com_test(c, n);
  1612. X        break;
  1613. X    case and_test:
  1614. X        com_and_test(c, n);
  1615. X        break;
  1616. X    case not_test:
  1617. X        com_not_test(c, n);
  1618. X        break;
  1619. X    case comparison:
  1620. X        com_comparison(c, n);
  1621. X        break;
  1622. X    case exprlist:
  1623. X        com_list(c, n);
  1624. X        break;
  1625. X    case expr:
  1626. X        com_expr(c, n);
  1627. X        break;
  1628. X    case term:
  1629. X        com_term(c, n);
  1630. X        break;
  1631. X    case factor:
  1632. X        com_factor(c, n);
  1633. X        break;
  1634. X    case atom:
  1635. X        com_atom(c, n);
  1636. X        break;
  1637. X    
  1638. X    default:
  1639. X        fprintf(stderr, "node type %d\n", TYPE(n));
  1640. X        err_setstr(SystemError, "com_node: unexpected node type");
  1641. X        c->c_errors++;
  1642. X    }
  1643. X}
  1644. X
  1645. Xstatic void com_fplist PROTO((struct compiling *, node *));
  1646. X
  1647. Xstatic void
  1648. Xcom_fpdef(c, n)
  1649. X    struct compiling *c;
  1650. X    node *n;
  1651. X{
  1652. X    REQ(n, fpdef); /* fpdef: NAME | '(' fplist ')' */
  1653. X    if (TYPE(CHILD(n, 0)) == LPAR)
  1654. X        com_fplist(c, CHILD(n, 1));
  1655. X    else
  1656. X        com_addopname(c, STORE_NAME, CHILD(n, 0));
  1657. X}
  1658. X
  1659. Xstatic void
  1660. Xcom_fplist(c, n)
  1661. X    struct compiling *c;
  1662. X    node *n;
  1663. X{
  1664. X    REQ(n, fplist); /* fplist: fpdef (',' fpdef)* */
  1665. X    if (NCH(n) == 1) {
  1666. X        com_fpdef(c, CHILD(n, 0));
  1667. X    }
  1668. X    else {
  1669. X        int i;
  1670. X        com_addoparg(c, UNPACK_TUPLE, (NCH(n)+1)/2);
  1671. X        for (i = 0; i < NCH(n); i += 2)
  1672. X            com_fpdef(c, CHILD(n, i));
  1673. X    }
  1674. X}
  1675. X
  1676. Xstatic void
  1677. Xcom_file_input(c, n)
  1678. X    struct compiling *c;
  1679. X    node *n;
  1680. X{
  1681. X    int i;
  1682. X    REQ(n, file_input); /* (NEWLINE | stmt)* ENDMARKER */
  1683. X    for (i = 0; i < NCH(n); i++) {
  1684. X        node *ch = CHILD(n, i);
  1685. X        if (TYPE(ch) != ENDMARKER && TYPE(ch) != NEWLINE)
  1686. X            com_node(c, ch);
  1687. X    }
  1688. X}
  1689. X
  1690. X/* Top-level compile-node interface */
  1691. X
  1692. Xstatic void
  1693. Xcompile_funcdef(c, n)
  1694. X    struct compiling *c;
  1695. X    node *n;
  1696. X{
  1697. X    node *ch;
  1698. X    REQ(n, funcdef); /* funcdef: 'def' NAME parameters ':' suite */
  1699. X    ch = CHILD(n, 2); /* parameters: '(' [fplist] ')' */
  1700. X    ch = CHILD(ch, 1); /* ')' | fplist */
  1701. X    if (TYPE(ch) == RPAR)
  1702. X        com_addbyte(c, REFUSE_ARGS);
  1703. X    else {
  1704. X        com_addbyte(c, REQUIRE_ARGS);
  1705. X        com_fplist(c, ch);
  1706. X    }
  1707. X    c->c_infunction = 1;
  1708. X    com_node(c, CHILD(n, 4));
  1709. X    c->c_infunction = 0;
  1710. X    com_addoparg(c, LOAD_CONST, com_addconst(c, None));
  1711. X    com_addbyte(c, RETURN_VALUE);
  1712. X}
  1713. X
  1714. Xstatic void
  1715. Xcompile_node(c, n)
  1716. X    struct compiling *c;
  1717. X    node *n;
  1718. X{
  1719. X    com_addoparg(c, SET_LINENO, n->n_lineno);
  1720. X    
  1721. X    switch (TYPE(n)) {
  1722. X    
  1723. X    case single_input: /* One interactive command */
  1724. X        /* NEWLINE | simple_stmt | compound_stmt NEWLINE */
  1725. X        com_addbyte(c, REFUSE_ARGS);
  1726. X        n = CHILD(n, 0);
  1727. X        if (TYPE(n) != NEWLINE)
  1728. X            com_node(c, n);
  1729. X        com_addoparg(c, LOAD_CONST, com_addconst(c, None));
  1730. X        com_addbyte(c, RETURN_VALUE);
  1731. X        break;
  1732. X    
  1733. X    case file_input: /* A whole file, or built-in function exec() */
  1734. X        com_addbyte(c, REFUSE_ARGS);
  1735. X        com_file_input(c, n);
  1736. X        com_addoparg(c, LOAD_CONST, com_addconst(c, None));
  1737. X        com_addbyte(c, RETURN_VALUE);
  1738. X        break;
  1739. X    
  1740. X    case expr_input: /* Built-in function eval() */
  1741. X        com_addbyte(c, REFUSE_ARGS);
  1742. X        com_node(c, CHILD(n, 0));
  1743. X        com_addbyte(c, RETURN_VALUE);
  1744. X        break;
  1745. X    
  1746. X    case eval_input: /* Built-in function input() */
  1747. X        com_addbyte(c, REFUSE_ARGS);
  1748. X        com_node(c, CHILD(n, 0));
  1749. X        com_addbyte(c, RETURN_VALUE);
  1750. X        break;
  1751. X    
  1752. X    case funcdef: /* A function definition */
  1753. X        compile_funcdef(c, n);
  1754. X        break;
  1755. X    
  1756. X    case classdef: /* A class definition */
  1757. X        /* 'class' NAME parameters ['=' baselist] ':' suite */
  1758. X        com_addbyte(c, REFUSE_ARGS);
  1759. X        com_node(c, CHILD(n, NCH(n)-1));
  1760. X        com_addbyte(c, LOAD_LOCALS);
  1761. X        com_addbyte(c, RETURN_VALUE);
  1762. X        break;
  1763. X    
  1764. X    default:
  1765. X        fprintf(stderr, "node type %d\n", TYPE(n));
  1766. X        err_setstr(SystemError, "compile_node: unexpected node type");
  1767. X        c->c_errors++;
  1768. X    }
  1769. X}
  1770. X
  1771. Xcodeobject *
  1772. Xcompile(n, filename)
  1773. X    node *n;
  1774. X    char *filename;
  1775. X{
  1776. X    struct compiling sc;
  1777. X    codeobject *co;
  1778. X    if (!com_init(&sc, filename))
  1779. X        return NULL;
  1780. X    compile_node(&sc, n);
  1781. X    com_done(&sc);
  1782. X    if (sc.c_errors == 0)
  1783. X        co = newcodeobject(sc.c_code, sc.c_consts, sc.c_names, filename);
  1784. X    else
  1785. X        co = NULL;
  1786. X    com_free(&sc);
  1787. X    return co;
  1788. X}
  1789. EOF
  1790. fi
  1791. if test -s 'src/graminit.c'
  1792. then echo '*** I will not over-write existing file src/graminit.c'
  1793. else
  1794. echo 'x - src/graminit.c'
  1795. sed 's/^X//' > 'src/graminit.c' << 'EOF'
  1796. X/***********************************************************
  1797. XCopyright 1991 by Stichting Mathematisch Centrum, Amsterdam, The
  1798. XNetherlands.
  1799. X
  1800. X                        All Rights Reserved
  1801. X
  1802. XPermission to use, copy, modify, and distribute this software and its 
  1803. Xdocumentation for any purpose and without fee is hereby granted, 
  1804. Xprovided that the above copyright notice appear in all copies and that
  1805. Xboth that copyright notice and this permission notice appear in 
  1806. Xsupporting documentation, and that the names of Stichting Mathematisch
  1807. XCentrum or CWI not be used in advertising or publicity pertaining to
  1808. Xdistribution of the software without specific, written prior permission.
  1809. X
  1810. XSTICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
  1811. XTHIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
  1812. XFITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
  1813. XFOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  1814. XWHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  1815. XACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
  1816. XOF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  1817. X
  1818. X******************************************************************/
  1819. X
  1820. X#include "pgenheaders.h"
  1821. X#include "grammar.h"
  1822. Xstatic arc arcs_0_0[3] = {
  1823. X    {2, 1},
  1824. X    {3, 1},
  1825. X    {4, 2},
  1826. X};
  1827. Xstatic arc arcs_0_1[1] = {
  1828. X    {0, 1},
  1829. X};
  1830. Xstatic arc arcs_0_2[1] = {
  1831. X    {2, 1},
  1832. X};
  1833. Xstatic state states_0[3] = {
  1834. X    {3, arcs_0_0},
  1835. X    {1, arcs_0_1},
  1836. X    {1, arcs_0_2},
  1837. X};
  1838. Xstatic arc arcs_1_0[3] = {
  1839. X    {2, 0},
  1840. X    {6, 0},
  1841. X    {7, 1},
  1842. X};
  1843. Xstatic arc arcs_1_1[1] = {
  1844. X    {0, 1},
  1845. X};
  1846. Xstatic state states_1[2] = {
  1847. X    {3, arcs_1_0},
  1848. X    {1, arcs_1_1},
  1849. X};
  1850. Xstatic arc arcs_2_0[1] = {
  1851. X    {9, 1},
  1852. X};
  1853. Xstatic arc arcs_2_1[1] = {
  1854. X    {2, 2},
  1855. X};
  1856. Xstatic arc arcs_2_2[1] = {
  1857. X    {0, 2},
  1858. X};
  1859. Xstatic state states_2[3] = {
  1860. X    {1, arcs_2_0},
  1861. X    {1, arcs_2_1},
  1862. X    {1, arcs_2_2},
  1863. X};
  1864. Xstatic arc arcs_3_0[1] = {
  1865. X    {9, 1},
  1866. X};
  1867. Xstatic arc arcs_3_1[1] = {
  1868. X    {7, 2},
  1869. X};
  1870. Xstatic arc arcs_3_2[1] = {
  1871. X    {0, 2},
  1872. X};
  1873. Xstatic state states_3[3] = {
  1874. X    {1, arcs_3_0},
  1875. X    {1, arcs_3_1},
  1876. X    {1, arcs_3_2},
  1877. X};
  1878. Xstatic arc arcs_4_0[1] = {
  1879. X    {12, 1},
  1880. X};
  1881. Xstatic arc arcs_4_1[1] = {
  1882. X    {13, 2},
  1883. X};
  1884. Xstatic arc arcs_4_2[1] = {
  1885. X    {14, 3},
  1886. X};
  1887. Xstatic arc arcs_4_3[1] = {
  1888. X    {15, 4},
  1889. X};
  1890. Xstatic arc arcs_4_4[1] = {
  1891. X    {16, 5},
  1892. X};
  1893. Xstatic arc arcs_4_5[1] = {
  1894. X    {0, 5},
  1895. X};
  1896. Xstatic state states_4[6] = {
  1897. X    {1, arcs_4_0},
  1898. X    {1, arcs_4_1},
  1899. X    {1, arcs_4_2},
  1900. X    {1, arcs_4_3},
  1901. X    {1, arcs_4_4},
  1902. X    {1, arcs_4_5},
  1903. X};
  1904. Xstatic arc arcs_5_0[1] = {
  1905. X    {17, 1},
  1906. X};
  1907. Xstatic arc arcs_5_1[2] = {
  1908. X    {18, 2},
  1909. X    {19, 3},
  1910. X};
  1911. Xstatic arc arcs_5_2[1] = {
  1912. X    {19, 3},
  1913. X};
  1914. Xstatic arc arcs_5_3[1] = {
  1915. X    {0, 3},
  1916. X};
  1917. Xstatic state states_5[4] = {
  1918. X    {1, arcs_5_0},
  1919. X    {2, arcs_5_1},
  1920. X    {1, arcs_5_2},
  1921. X    {1, arcs_5_3},
  1922. X};
  1923. Xstatic arc arcs_6_0[1] = {
  1924. X    {20, 1},
  1925. X};
  1926. Xstatic arc arcs_6_1[2] = {
  1927. X    {21, 0},
  1928. X    {0, 1},
  1929. X};
  1930. Xstatic state states_6[2] = {
  1931. X    {1, arcs_6_0},
  1932. X    {2, arcs_6_1},
  1933. X};
  1934. Xstatic arc arcs_7_0[2] = {
  1935. X    {13, 1},
  1936. X    {17, 2},
  1937. X};
  1938. Xstatic arc arcs_7_1[1] = {
  1939. X    {0, 1},
  1940. X};
  1941. Xstatic arc arcs_7_2[1] = {
  1942. X    {18, 3},
  1943. X};
  1944. Xstatic arc arcs_7_3[1] = {
  1945. X    {19, 1},
  1946. X};
  1947. Xstatic state states_7[4] = {
  1948. X    {2, arcs_7_0},
  1949. X    {1, arcs_7_1},
  1950. X    {1, arcs_7_2},
  1951. X    {1, arcs_7_3},
  1952. X};
  1953. Xstatic arc arcs_8_0[2] = {
  1954. X    {3, 1},
  1955. X    {4, 1},
  1956. X};
  1957. Xstatic arc arcs_8_1[1] = {
  1958. X    {0, 1},
  1959. X};
  1960. Xstatic state states_8[2] = {
  1961. X    {2, arcs_8_0},
  1962. X    {1, arcs_8_1},
  1963. X};
  1964. Xstatic arc arcs_9_0[6] = {
  1965. X    {22, 1},
  1966. X    {23, 1},
  1967. X    {24, 1},
  1968. X    {25, 1},
  1969. X    {26, 1},
  1970. X    {27, 1},
  1971. X};
  1972. Xstatic arc arcs_9_1[1] = {
  1973. X    {0, 1},
  1974. X};
  1975. Xstatic state states_9[2] = {
  1976. X    {6, arcs_9_0},
  1977. X    {1, arcs_9_1},
  1978. X};
  1979. Xstatic arc arcs_10_0[1] = {
  1980. X    {28, 1},
  1981. X};
  1982. Xstatic arc arcs_10_1[2] = {
  1983. X    {29, 0},
  1984. X    {2, 2},
  1985. X};
  1986. Xstatic arc arcs_10_2[1] = {
  1987. X    {0, 2},
  1988. X};
  1989. Xstatic state states_10[3] = {
  1990. X    {1, arcs_10_0},
  1991. X    {2, arcs_10_1},
  1992. X    {1, arcs_10_2},
  1993. X};
  1994. Xstatic arc arcs_11_0[1] = {
  1995. X    {30, 1},
  1996. X};
  1997. Xstatic arc arcs_11_1[2] = {
  1998. X    {31, 2},
  1999. X    {2, 3},
  2000. X};
  2001. Xstatic arc arcs_11_2[2] = {
  2002. X    {21, 1},
  2003. X    {2, 3},
  2004. X};
  2005. Xstatic arc arcs_11_3[1] = {
  2006. X    {0, 3},
  2007. X};
  2008. Xstatic state states_11[4] = {
  2009. X    {1, arcs_11_0},
  2010. X    {2, arcs_11_1},
  2011. X    {2, arcs_11_2},
  2012. X    {1, arcs_11_3},
  2013. X};
  2014. Xstatic arc arcs_12_0[1] = {
  2015. X    {32, 1},
  2016. X};
  2017. Xstatic arc arcs_12_1[1] = {
  2018. X    {28, 2},
  2019. X};
  2020. Xstatic arc arcs_12_2[1] = {
  2021. X    {2, 3},
  2022. X};
  2023. Xstatic arc arcs_12_3[1] = {
  2024. X    {0, 3},
  2025. X};
  2026. Xstatic state states_12[4] = {
  2027. X    {1, arcs_12_0},
  2028. X    {1, arcs_12_1},
  2029. X    {1, arcs_12_2},
  2030. X    {1, arcs_12_3},
  2031. X};
  2032. Xstatic arc arcs_13_0[1] = {
  2033. X    {33, 1},
  2034. X};
  2035. Xstatic arc arcs_13_1[1] = {
  2036. X    {2, 2},
  2037. X};
  2038. Xstatic arc arcs_13_2[1] = {
  2039. X    {0, 2},
  2040. X};
  2041. Xstatic state states_13[3] = {
  2042. X    {1, arcs_13_0},
  2043. X    {1, arcs_13_1},
  2044. X    {1, arcs_13_2},
  2045. X};
  2046. Xstatic arc arcs_14_0[3] = {
  2047. X    {34, 1},
  2048. X    {35, 1},
  2049. X    {36, 1},
  2050. X};
  2051. Xstatic arc arcs_14_1[1] = {
  2052. X    {0, 1},
  2053. X};
  2054. Xstatic state states_14[2] = {
  2055. X    {3, arcs_14_0},
  2056. X    {1, arcs_14_1},
  2057. X};
  2058. Xstatic arc arcs_15_0[1] = {
  2059. X    {37, 1},
  2060. X};
  2061. Xstatic arc arcs_15_1[1] = {
  2062. X    {2, 2},
  2063. X};
  2064. Xstatic arc arcs_15_2[1] = {
  2065. X    {0, 2},
  2066. X};
  2067. Xstatic state states_15[3] = {
  2068. X    {1, arcs_15_0},
  2069. X    {1, arcs_15_1},
  2070. X    {1, arcs_15_2},
  2071. X};
  2072. Xstatic arc arcs_16_0[1] = {
  2073. X    {38, 1},
  2074. X};
  2075. Xstatic arc arcs_16_1[2] = {
  2076. X    {9, 2},
  2077. X    {2, 3},
  2078. X};
  2079. Xstatic arc arcs_16_2[1] = {
  2080. X    {2, 3},
  2081. X};
  2082. Xstatic arc arcs_16_3[1] = {
  2083. X    {0, 3},
  2084. X};
  2085. Xstatic state states_16[4] = {
  2086. X    {1, arcs_16_0},
  2087. X    {2, arcs_16_1},
  2088. X    {1, arcs_16_2},
  2089. X    {1, arcs_16_3},
  2090. X};
  2091. Xstatic arc arcs_17_0[1] = {
  2092. X    {39, 1},
  2093. X};
  2094. Xstatic arc arcs_17_1[1] = {
  2095. X    {40, 2},
  2096. X};
  2097. Xstatic arc arcs_17_2[2] = {
  2098. X    {21, 3},
  2099. X    {2, 4},
  2100. X};
  2101. Xstatic arc arcs_17_3[1] = {
  2102. X    {40, 5},
  2103. X};
  2104. Xstatic arc arcs_17_4[1] = {
  2105. X    {0, 4},
  2106. X};
  2107. Xstatic arc arcs_17_5[1] = {
  2108. X    {2, 4},
  2109. X};
  2110. Xstatic state states_17[6] = {
  2111. X    {1, arcs_17_0},
  2112. X    {1, arcs_17_1},
  2113. X    {2, arcs_17_2},
  2114. X    {1, arcs_17_3},
  2115. X    {1, arcs_17_4},
  2116. X    {1, arcs_17_5},
  2117. X};
  2118. Xstatic arc arcs_18_0[2] = {
  2119. X    {41, 1},
  2120. X    {42, 2},
  2121. X};
  2122. Xstatic arc arcs_18_1[1] = {
  2123. X    {13, 3},
  2124. X};
  2125. Xstatic arc arcs_18_2[1] = {
  2126. X    {13, 4},
  2127. X};
  2128. Xstatic arc arcs_18_3[2] = {
  2129. X    {21, 1},
  2130. X    {2, 5},
  2131. X};
  2132. Xstatic arc arcs_18_4[1] = {
  2133. X    {41, 6},
  2134. X};
  2135. Xstatic arc arcs_18_5[1] = {
  2136. X    {0, 5},
  2137. X};
  2138. Xstatic arc arcs_18_6[2] = {
  2139. X    {43, 7},
  2140. X    {13, 8},
  2141. X};
  2142. Xstatic arc arcs_18_7[1] = {
  2143. X    {2, 5},
  2144. X};
  2145. Xstatic arc arcs_18_8[2] = {
  2146. X    {21, 9},
  2147. X    {2, 5},
  2148. X};
  2149. Xstatic arc arcs_18_9[1] = {
  2150. X    {13, 8},
  2151. X};
  2152. Xstatic state states_18[10] = {
  2153. X    {2, arcs_18_0},
  2154. X    {1, arcs_18_1},
  2155. X    {1, arcs_18_2},
  2156. X    {2, arcs_18_3},
  2157. X    {1, arcs_18_4},
  2158. X    {1, arcs_18_5},
  2159. X    {2, arcs_18_6},
  2160. X    {1, arcs_18_7},
  2161. X    {2, arcs_18_8},
  2162. X    {1, arcs_18_9},
  2163. X};
  2164. Xstatic arc arcs_19_0[6] = {
  2165. X    {44, 1},
  2166. X    {45, 1},
  2167. X    {46, 1},
  2168. X    {47, 1},
  2169. X    {11, 1},
  2170. X    {48, 1},
  2171. X};
  2172. Xstatic arc arcs_19_1[1] = {
  2173. X    {0, 1},
  2174. X};
  2175. Xstatic state states_19[2] = {
  2176. X    {6, arcs_19_0},
  2177. X    {1, arcs_19_1},
  2178. X};
  2179. Xstatic arc arcs_20_0[1] = {
  2180. X    {49, 1},
  2181. X};
  2182. Xstatic arc arcs_20_1[1] = {
  2183. X    {31, 2},
  2184. X};
  2185. Xstatic arc arcs_20_2[1] = {
  2186. X    {15, 3},
  2187. X};
  2188. Xstatic arc arcs_20_3[1] = {
  2189. X    {16, 4},
  2190. X};
  2191. Xstatic arc arcs_20_4[3] = {
  2192. X    {50, 1},
  2193. X    {51, 5},
  2194. X    {0, 4},
  2195. X};
  2196. Xstatic arc arcs_20_5[1] = {
  2197. X    {15, 6},
  2198. X};
  2199. Xstatic arc arcs_20_6[1] = {
  2200. X    {16, 7},
  2201. X};
  2202. Xstatic arc arcs_20_7[1] = {
  2203. X    {0, 7},
  2204. X};
  2205. Xstatic state states_20[8] = {
  2206. X    {1, arcs_20_0},
  2207. X    {1, arcs_20_1},
  2208. X    {1, arcs_20_2},
  2209. X    {1, arcs_20_3},
  2210. X    {3, arcs_20_4},
  2211. X    {1, arcs_20_5},
  2212. X    {1, arcs_20_6},
  2213. X    {1, arcs_20_7},
  2214. X};
  2215. Xstatic arc arcs_21_0[1] = {
  2216. X    {52, 1},
  2217. X};
  2218. Xstatic arc arcs_21_1[1] = {
  2219. X    {31, 2},
  2220. X};
  2221. Xstatic arc arcs_21_2[1] = {
  2222. X    {15, 3},
  2223. X};
  2224. Xstatic arc arcs_21_3[1] = {
  2225. X    {16, 4},
  2226. X};
  2227. Xstatic arc arcs_21_4[2] = {
  2228. X    {51, 5},
  2229. X    {0, 4},
  2230. X};
  2231. Xstatic arc arcs_21_5[1] = {
  2232. X    {15, 6},
  2233. X};
  2234. Xstatic arc arcs_21_6[1] = {
  2235. X    {16, 7},
  2236. X};
  2237. Xstatic arc arcs_21_7[1] = {
  2238. X    {0, 7},
  2239. X};
  2240. Xstatic state states_21[8] = {
  2241. X    {1, arcs_21_0},
  2242. X    {1, arcs_21_1},
  2243. X    {1, arcs_21_2},
  2244. X    {1, arcs_21_3},
  2245. X    {2, arcs_21_4},
  2246. X    {1, arcs_21_5},
  2247. X    {1, arcs_21_6},
  2248. X    {1, arcs_21_7},
  2249. X};
  2250. Xstatic arc arcs_22_0[1] = {
  2251. X    {53, 1},
  2252. X};
  2253. Xstatic arc arcs_22_1[1] = {
  2254. X    {28, 2},
  2255. X};
  2256. Xstatic arc arcs_22_2[1] = {
  2257. X    {54, 3},
  2258. X};
  2259. Xstatic arc arcs_22_3[1] = {
  2260. X    {28, 4},
  2261. X};
  2262. Xstatic arc arcs_22_4[1] = {
  2263. X    {15, 5},
  2264. X};
  2265. Xstatic arc arcs_22_5[1] = {
  2266. X    {16, 6},
  2267. X};
  2268. Xstatic arc arcs_22_6[2] = {
  2269. X    {51, 7},
  2270. X    {0, 6},
  2271. X};
  2272. Xstatic arc arcs_22_7[1] = {
  2273. X    {15, 8},
  2274. X};
  2275. Xstatic arc arcs_22_8[1] = {
  2276. X    {16, 9},
  2277. X};
  2278. Xstatic arc arcs_22_9[1] = {
  2279. X    {0, 9},
  2280. X};
  2281. Xstatic state states_22[10] = {
  2282. X    {1, arcs_22_0},
  2283. X    {1, arcs_22_1},
  2284. X    {1, arcs_22_2},
  2285. X    {1, arcs_22_3},
  2286. X    {1, arcs_22_4},
  2287. X    {1, arcs_22_5},
  2288. X    {2, arcs_22_6},
  2289. X    {1, arcs_22_7},
  2290. X    {1, arcs_22_8},
  2291. X    {1, arcs_22_9},
  2292. X};
  2293. Xstatic arc arcs_23_0[1] = {
  2294. X    {55, 1},
  2295. X};
  2296. Xstatic arc arcs_23_1[1] = {
  2297. X    {15, 2},
  2298. X};
  2299. Xstatic arc arcs_23_2[1] = {
  2300. X    {16, 3},
  2301. X};
  2302. Xstatic arc arcs_23_3[3] = {
  2303. X    {56, 1},
  2304. X    {57, 4},
  2305. X    {0, 3},
  2306. X};
  2307. Xstatic arc arcs_23_4[1] = {
  2308. X    {15, 5},
  2309. X};
  2310. Xstatic arc arcs_23_5[1] = {
  2311. X    {16, 6},
  2312. X};
  2313. Xstatic arc arcs_23_6[1] = {
  2314. X    {0, 6},
  2315. X};
  2316. Xstatic state states_23[7] = {
  2317. X    {1, arcs_23_0},
  2318. X    {1, arcs_23_1},
  2319. X    {1, arcs_23_2},
  2320. X    {3, arcs_23_3},
  2321. X    {1, arcs_23_4},
  2322. X    {1, arcs_23_5},
  2323. X    {1, arcs_23_6},
  2324. X};
  2325. Xstatic arc arcs_24_0[1] = {
  2326. X    {58, 1},
  2327. X};
  2328. Xstatic arc arcs_24_1[2] = {
  2329. X    {40, 2},
  2330. X    {0, 1},
  2331. X};
  2332. Xstatic arc arcs_24_2[2] = {
  2333. X    {21, 3},
  2334. X    {0, 2},
  2335. X};
  2336. Xstatic arc arcs_24_3[1] = {
  2337. X    {40, 4},
  2338. X};
  2339. Xstatic arc arcs_24_4[1] = {
  2340. X    {0, 4},
  2341. X};
  2342. Xstatic state states_24[5] = {
  2343. X    {1, arcs_24_0},
  2344. X    {2, arcs_24_1},
  2345. X    {2, arcs_24_2},
  2346. X    {1, arcs_24_3},
  2347. X    {1, arcs_24_4},
  2348. X};
  2349. Xstatic arc arcs_25_0[2] = {
  2350. X    {3, 1},
  2351. X    {2, 2},
  2352. X};
  2353. Xstatic arc arcs_25_1[1] = {
  2354. X    {0, 1},
  2355. X};
  2356. Xstatic arc arcs_25_2[1] = {
  2357. X    {59, 3},
  2358. X};
  2359. Xstatic arc arcs_25_3[2] = {
  2360. X    {2, 3},
  2361. X    {6, 4},
  2362. X};
  2363. Xstatic arc arcs_25_4[3] = {
  2364. X    {6, 4},
  2365. X    {2, 4},
  2366. X    {60, 1},
  2367. X};
  2368. Xstatic state states_25[5] = {
  2369. X    {2, arcs_25_0},
  2370. X    {1, arcs_25_1},
  2371. X    {1, arcs_25_2},
  2372. X    {2, arcs_25_3},
  2373. X    {3, arcs_25_4},
  2374. X};
  2375. Xstatic arc arcs_26_0[1] = {
  2376. X    {61, 1},
  2377. X};
  2378. Xstatic arc arcs_26_1[2] = {
  2379. X    {62, 0},
  2380. X    {0, 1},
  2381. X};
  2382. Xstatic state states_26[2] = {
  2383. X    {1, arcs_26_0},
  2384. X    {2, arcs_26_1},
  2385. X};
  2386. Xstatic arc arcs_27_0[1] = {
  2387. X    {63, 1},
  2388. X};
  2389. Xstatic arc arcs_27_1[2] = {
  2390. X    {64, 0},
  2391. X    {0, 1},
  2392. X};
  2393. Xstatic state states_27[2] = {
  2394. X    {1, arcs_27_0},
  2395. X    {2, arcs_27_1},
  2396. X};
  2397. Xstatic arc arcs_28_0[2] = {
  2398. X    {65, 1},
  2399. X    {66, 2},
  2400. X};
  2401. Xstatic arc arcs_28_1[1] = {
  2402. X    {63, 2},
  2403. X};
  2404. Xstatic arc arcs_28_2[1] = {
  2405. X    {0, 2},
  2406. X};
  2407. Xstatic state states_28[3] = {
  2408. X    {2, arcs_28_0},
  2409. X    {1, arcs_28_1},
  2410. X    {1, arcs_28_2},
  2411. X};
  2412. Xstatic arc arcs_29_0[1] = {
  2413. X    {40, 1},
  2414. X};
  2415. Xstatic arc arcs_29_1[2] = {
  2416. X    {67, 0},
  2417. X    {0, 1},
  2418. X};
  2419. Xstatic state states_29[2] = {
  2420. X    {1, arcs_29_0},
  2421. X    {2, arcs_29_1},
  2422. X};
  2423. Xstatic arc arcs_30_0[6] = {
  2424. X    {68, 1},
  2425. X    {69, 2},
  2426. X    {29, 3},
  2427. X    {54, 3},
  2428. X    {65, 4},
  2429. X    {70, 5},
  2430. X};
  2431. Xstatic arc arcs_30_1[3] = {
  2432. X    {29, 3},
  2433. X    {69, 3},
  2434. X    {0, 1},
  2435. X};
  2436. Xstatic arc arcs_30_2[2] = {
  2437. X    {29, 3},
  2438. X    {0, 2},
  2439. X};
  2440. Xstatic arc arcs_30_3[1] = {
  2441. X    {0, 3},
  2442. X};
  2443. Xstatic arc arcs_30_4[1] = {
  2444. X    {54, 3},
  2445. X};
  2446. Xstatic arc arcs_30_5[2] = {
  2447. X    {65, 3},
  2448. X    {0, 5},
  2449. X};
  2450. Xstatic state states_30[6] = {
  2451. X    {6, arcs_30_0},
  2452. X    {3, arcs_30_1},
  2453. X    {2, arcs_30_2},
  2454. X    {1, arcs_30_3},
  2455. X    {1, arcs_30_4},
  2456. X    {2, arcs_30_5},
  2457. X};
  2458. Xstatic arc arcs_31_0[1] = {
  2459. X    {71, 1},
  2460. X};
  2461. Xstatic arc arcs_31_1[3] = {
  2462. X    {72, 0},
  2463. X    {73, 0},
  2464. X    {0, 1},
  2465. X};
  2466. Xstatic state states_31[2] = {
  2467. X    {1, arcs_31_0},
  2468. X    {3, arcs_31_1},
  2469. X};
  2470. Xstatic arc arcs_32_0[1] = {
  2471. X    {74, 1},
  2472. X};
  2473. Xstatic arc arcs_32_1[4] = {
  2474. X    {43, 0},
  2475. X    {75, 0},
  2476. X    {76, 0},
  2477. X    {0, 1},
  2478. X};
  2479. Xstatic state states_32[2] = {
  2480. X    {1, arcs_32_0},
  2481. X    {4, arcs_32_1},
  2482. X};
  2483. Xstatic arc arcs_33_0[3] = {
  2484. X    {72, 1},
  2485. X    {73, 1},
  2486. X    {77, 2},
  2487. X};
  2488. Xstatic arc arcs_33_1[1] = {
  2489. X    {74, 3},
  2490. X};
  2491. Xstatic arc arcs_33_2[2] = {
  2492. X    {78, 2},
  2493. X    {0, 2},
  2494. X};
  2495. Xstatic arc arcs_33_3[1] = {
  2496. X    {0, 3},
  2497. X};
  2498. Xstatic state states_33[4] = {
  2499. X    {3, arcs_33_0},
  2500. X    {1, arcs_33_1},
  2501. X    {2, arcs_33_2},
  2502. X    {1, arcs_33_3},
  2503. X};
  2504. Xstatic arc arcs_34_0[7] = {
  2505. X    {17, 1},
  2506. X    {79, 2},
  2507. X    {81, 3},
  2508. X    {83, 4},
  2509. X    {13, 5},
  2510. X    {84, 5},
  2511. X    {85, 5},
  2512. X};
  2513. Xstatic arc arcs_34_1[2] = {
  2514. X    {9, 6},
  2515. X    {19, 5},
  2516. X};
  2517. Xstatic arc arcs_34_2[2] = {
  2518. X    {9, 7},
  2519. X    {80, 5},
  2520. X};
  2521. Xstatic arc arcs_34_3[1] = {
  2522. X    {82, 5},
  2523. X};
  2524. Xstatic arc arcs_34_4[1] = {
  2525. X    {9, 8},
  2526. X};
  2527. Xstatic arc arcs_34_5[1] = {
  2528. X    {0, 5},
  2529. X};
  2530. Xstatic arc arcs_34_6[1] = {
  2531. X    {19, 5},
  2532. X};
  2533. Xstatic arc arcs_34_7[1] = {
  2534. X    {80, 5},
  2535. X};
  2536. Xstatic arc arcs_34_8[1] = {
  2537. X    {83, 5},
  2538. X};
  2539. Xstatic state states_34[9] = {
  2540. X    {7, arcs_34_0},
  2541. X    {2, arcs_34_1},
  2542. X    {2, arcs_34_2},
  2543. X    {1, arcs_34_3},
  2544. X    {1, arcs_34_4},
  2545. X    {1, arcs_34_5},
  2546. X    {1, arcs_34_6},
  2547. X    {1, arcs_34_7},
  2548. X    {1, arcs_34_8},
  2549. X};
  2550. Xstatic arc arcs_35_0[3] = {
  2551. X    {17, 1},
  2552. X    {79, 2},
  2553. X    {87, 3},
  2554. X};
  2555. Xstatic arc arcs_35_1[2] = {
  2556. X    {9, 4},
  2557. X    {19, 5},
  2558. X};
  2559. Xstatic arc arcs_35_2[1] = {
  2560. X    {86, 6},
  2561. X};
  2562. Xstatic arc arcs_35_3[1] = {
  2563. X    {13, 5},
  2564. X};
  2565. Xstatic arc arcs_35_4[1] = {
  2566. X    {19, 5},
  2567. X};
  2568. Xstatic arc arcs_35_5[1] = {
  2569. X    {0, 5},
  2570. X};
  2571. Xstatic arc arcs_35_6[1] = {
  2572. X    {80, 5},
  2573. X};
  2574. Xstatic state states_35[7] = {
  2575. X    {3, arcs_35_0},
  2576. X    {2, arcs_35_1},
  2577. X    {1, arcs_35_2},
  2578. X    {1, arcs_35_3},
  2579. X    {1, arcs_35_4},
  2580. X    {1, arcs_35_5},
  2581. X    {1, arcs_35_6},
  2582. X};
  2583. Xstatic arc arcs_36_0[2] = {
  2584. X    {40, 1},
  2585. X    {15, 2},
  2586. X};
  2587. Xstatic arc arcs_36_1[2] = {
  2588. X    {15, 2},
  2589. X    {0, 1},
  2590. X};
  2591. Xstatic arc arcs_36_2[2] = {
  2592. X    {40, 3},
  2593. X    {0, 2},
  2594. X};
  2595. Xstatic arc arcs_36_3[1] = {
  2596. X    {0, 3},
  2597. X};
  2598. Xstatic state states_36[4] = {
  2599. X    {2, arcs_36_0},
  2600. X    {2, arcs_36_1},
  2601. X    {2, arcs_36_2},
  2602. X    {1, arcs_36_3},
  2603. X};
  2604. Xstatic arc arcs_37_0[1] = {
  2605. X    {40, 1},
  2606. X};
  2607. Xstatic arc arcs_37_1[2] = {
  2608. X    {21, 2},
  2609. X    {0, 1},
  2610. X};
  2611. Xstatic arc arcs_37_2[2] = {
  2612. X    {40, 1},
  2613. X    {0, 2},
  2614. X};
  2615. Xstatic state states_37[3] = {
  2616. X    {1, arcs_37_0},
  2617. X    {2, arcs_37_1},
  2618. X    {2, arcs_37_2},
  2619. X};
  2620. Xstatic arc arcs_38_0[1] = {
  2621. X    {31, 1},
  2622. X};
  2623. Xstatic arc arcs_38_1[2] = {
  2624. X    {21, 2},
  2625. X    {0, 1},
  2626. X};
  2627. Xstatic arc arcs_38_2[2] = {
  2628. X    {31, 1},
  2629. X    {0, 2},
  2630. X};
  2631. Xstatic state states_38[3] = {
  2632. X    {1, arcs_38_0},
  2633. X    {2, arcs_38_1},
  2634. X    {2, arcs_38_2},
  2635. X};
  2636. Xstatic arc arcs_39_0[1] = {
  2637. X    {88, 1},
  2638. X};
  2639. Xstatic arc arcs_39_1[1] = {
  2640. X    {13, 2},
  2641. X};
  2642. Xstatic arc arcs_39_2[1] = {
  2643. X    {14, 3},
  2644. X};
  2645. Xstatic arc arcs_39_3[2] = {
  2646. X    {29, 4},
  2647. X    {15, 5},
  2648. X};
  2649. Xstatic arc arcs_39_4[1] = {
  2650. X    {89, 6},
  2651. X};
  2652. Xstatic arc arcs_39_5[1] = {
  2653. X    {16, 7},
  2654. X};
  2655. Xstatic arc arcs_39_6[1] = {
  2656. X    {15, 5},
  2657. X};
  2658. Xstatic arc arcs_39_7[1] = {
  2659. X    {0, 7},
  2660. X};
  2661. Xstatic state states_39[8] = {
  2662. X    {1, arcs_39_0},
  2663. X    {1, arcs_39_1},
  2664. X    {1, arcs_39_2},
  2665. X    {2, arcs_39_3},
  2666. X    {1, arcs_39_4},
  2667. X    {1, arcs_39_5},
  2668. X    {1, arcs_39_6},
  2669. X    {1, arcs_39_7},
  2670. X};
  2671. Xstatic arc arcs_40_0[1] = {
  2672. X    {77, 1},
  2673. X};
  2674. Xstatic arc arcs_40_1[1] = {
  2675. X    {90, 2},
  2676. X};
  2677. Xstatic arc arcs_40_2[2] = {
  2678. X    {21, 0},
  2679. X    {0, 2},
  2680. X};
  2681. Xstatic state states_40[3] = {
  2682. X    {1, arcs_40_0},
  2683. X    {1, arcs_40_1},
  2684. X    {2, arcs_40_2},
  2685. X};
  2686. Xstatic arc arcs_41_0[1] = {
  2687. X    {17, 1},
  2688. X};
  2689. Xstatic arc arcs_41_1[2] = {
  2690. X    {9, 2},
  2691. X    {19, 3},
  2692. X};
  2693. Xstatic arc arcs_41_2[1] = {
  2694. X    {19, 3},
  2695. X};
  2696. Xstatic arc arcs_41_3[1] = {
  2697. X    {0, 3},
  2698. X};
  2699. Xstatic state states_41[4] = {
  2700. X    {1, arcs_41_0},
  2701. X    {2, arcs_41_1},
  2702. X    {1, arcs_41_2},
  2703. X    {1, arcs_41_3},
  2704. X};
  2705. Xstatic dfa dfas[42] = {
  2706. X    {256, "single_input", 0, 3, states_0,
  2707. X     "\004\060\002\100\343\006\262\000\000\203\072\001"},
  2708. X    {257, "file_input", 0, 2, states_1,
  2709. X     "\204\060\002\100\343\006\262\000\000\203\072\001"},
  2710. X    {258, "expr_input", 0, 3, states_2,
  2711. X     "\000\040\002\000\000\000\000\000\002\203\072\000"},
  2712. X    {259, "eval_input", 0, 3, states_3,
  2713. X     "\000\040\002\000\000\000\000\000\002\203\072\000"},
  2714. X    {260, "funcdef", 0, 6, states_4,
  2715. X     "\000\020\000\000\000\000\000\000\000\000\000\000"},
  2716. X    {261, "parameters", 0, 4, states_5,
  2717. X     "\000\000\002\000\000\000\000\000\000\000\000\000"},
  2718. X    {262, "fplist", 0, 2, states_6,
  2719. X     "\000\040\002\000\000\000\000\000\000\000\000\000"},
  2720. X    {263, "fpdef", 0, 4, states_7,
  2721. X     "\000\040\002\000\000\000\000\000\000\000\000\000"},
  2722. X    {264, "stmt", 0, 2, states_8,
  2723. X     "\000\060\002\100\343\006\262\000\000\203\072\001"},
  2724. X    {265, "simple_stmt", 0, 2, states_9,
  2725. X     "\000\040\002\100\343\006\000\000\000\203\072\000"},
  2726. X    {266, "expr_stmt", 0, 3, states_10,
  2727. X     "\000\040\002\000\000\000\000\000\000\203\072\000"},
  2728. X    {267, "print_stmt", 0, 4, states_11,
  2729. X     "\000\000\000\100\000\000\000\000\000\000\000\000"},
  2730. X    {268, "del_stmt", 0, 4, states_12,
  2731. X     "\000\000\000\000\001\000\000\000\000\000\000\000"},
  2732. X    {269, "pass_stmt", 0, 3, states_13,
  2733. X     "\000\000\000\000\002\000\000\000\000\000\000\000"},
  2734. X    {270, "flow_stmt", 0, 2, states_14,
  2735. X     "\000\000\000\000\340\000\000\000\000\000\000\000"},
  2736. X    {271, "break_stmt", 0, 3, states_15,
  2737. X     "\000\000\000\000\040\000\000\000\000\000\000\000"},
  2738. X    {272, "return_stmt", 0, 4, states_16,
  2739. X     "\000\000\000\000\100\000\000\000\000\000\000\000"},
  2740. X    {273, "raise_stmt", 0, 6, states_17,
  2741. X     "\000\000\000\000\200\000\000\000\000\000\000\000"},
  2742. X    {274, "import_stmt", 0, 10, states_18,
  2743. X     "\000\000\000\000\000\006\000\000\000\000\000\000"},
  2744. X    {275, "compound_stmt", 0, 2, states_19,
  2745. X     "\000\020\000\000\000\000\262\000\000\000\000\001"},
  2746. X    {276, "if_stmt", 0, 8, states_20,
  2747. X     "\000\000\000\000\000\000\002\000\000\000\000\000"},
  2748. X    {277, "while_stmt", 0, 8, states_21,
  2749. X     "\000\000\000\000\000\000\020\000\000\000\000\000"},
  2750. X    {278, "for_stmt", 0, 10, states_22,
  2751. X     "\000\000\000\000\000\000\040\000\000\000\000\000"},
  2752. X    {279, "try_stmt", 0, 7, states_23,
  2753. X     "\000\000\000\000\000\000\200\000\000\000\000\000"},
  2754. X    {280, "except_clause", 0, 5, states_24,
  2755. X     "\000\000\000\000\000\000\000\004\000\000\000\000"},
  2756. X    {281, "suite", 0, 5, states_25,
  2757. X     "\004\040\002\100\343\006\000\000\000\203\072\000"},
  2758. X    {282, "test", 0, 2, states_26,
  2759. X     "\000\040\002\000\000\000\000\000\002\203\072\000"},
  2760. X    {283, "and_test", 0, 2, states_27,
  2761. X     "\000\040\002\000\000\000\000\000\002\203\072\000"},
  2762. X    {284, "not_test", 0, 3, states_28,
  2763. X     "\000\040\002\000\000\000\000\000\002\203\072\000"},
  2764. X    {285, "comparison", 0, 2, states_29,
  2765. X     "\000\040\002\000\000\000\000\000\000\203\072\000"},
  2766. X    {286, "comp_op", 0, 6, states_30,
  2767. X     "\000\000\000\040\000\000\100\000\162\000\000\000"},
  2768. X    {287, "expr", 0, 2, states_31,
  2769. X     "\000\040\002\000\000\000\000\000\000\203\072\000"},
  2770. X    {288, "term", 0, 2, states_32,
  2771. X     "\000\040\002\000\000\000\000\000\000\203\072\000"},
  2772. X    {289, "factor", 0, 4, states_33,
  2773. X     "\000\040\002\000\000\000\000\000\000\203\072\000"},
  2774. X    {290, "atom", 0, 9, states_34,
  2775. X     "\000\040\002\000\000\000\000\000\000\200\072\000"},
  2776. X    {291, "trailer", 0, 7, states_35,
  2777. X     "\000\000\002\000\000\000\000\000\000\200\200\000"},
  2778. X    {292, "subscript", 0, 4, states_36,
  2779. X     "\000\240\002\000\000\000\000\000\000\203\072\000"},
  2780. X    {293, "exprlist", 0, 3, states_37,
  2781. X     "\000\040\002\000\000\000\000\000\000\203\072\000"},
  2782. X    {294, "testlist", 0, 3, states_38,
  2783. X     "\000\040\002\000\000\000\000\000\002\203\072\000"},
  2784. X    {295, "classdef", 0, 8, states_39,
  2785. X     "\000\000\000\000\000\000\000\000\000\000\000\001"},
  2786. X    {296, "baselist", 0, 3, states_40,
  2787. X     "\000\040\002\000\000\000\000\000\000\200\072\000"},
  2788. X    {297, "arguments", 0, 4, states_41,
  2789. X     "\000\000\002\000\000\000\000\000\000\000\000\000"},
  2790. X};
  2791. Xstatic label labels[91] = {
  2792. X    {0, "EMPTY"},
  2793. X    {256, 0},
  2794. X    {4, 0},
  2795. X    {265, 0},
  2796. X    {275, 0},
  2797. X    {257, 0},
  2798. X    {264, 0},
  2799. X    {0, 0},
  2800. X    {258, 0},
  2801. X    {294, 0},
  2802. X    {259, 0},
  2803. X    {260, 0},
  2804. X    {1, "def"},
  2805. X    {1, 0},
  2806. X    {261, 0},
  2807. X    {11, 0},
  2808. X    {281, 0},
  2809. X    {7, 0},
  2810. X    {262, 0},
  2811. X    {8, 0},
  2812. X    {263, 0},
  2813. X    {12, 0},
  2814. X    {266, 0},
  2815. X    {267, 0},
  2816. X    {269, 0},
  2817. X    {268, 0},
  2818. X    {270, 0},
  2819. X    {274, 0},
  2820. X    {293, 0},
  2821. X    {22, 0},
  2822. X    {1, "print"},
  2823. X    {282, 0},
  2824. X    {1, "del"},
  2825. X    {1, "pass"},
  2826. X    {271, 0},
  2827. X    {272, 0},
  2828. X    {273, 0},
  2829. X    {1, "break"},
  2830. X    {1, "return"},
  2831. X    {1, "raise"},
  2832. X    {287, 0},
  2833. X    {1, "import"},
  2834. X    {1, "from"},
  2835. X    {16, 0},
  2836. X    {276, 0},
  2837. X    {277, 0},
  2838. X    {278, 0},
  2839. X    {279, 0},
  2840. X    {295, 0},
  2841. X    {1, "if"},
  2842. X    {1, "elif"},
  2843. X    {1, "else"},
  2844. X    {1, "while"},
  2845. X    {1, "for"},
  2846. X    {1, "in"},
  2847. X    {1, "try"},
  2848. X    {280, 0},
  2849. X    {1, "finally"},
  2850. X    {1, "except"},
  2851. X    {5, 0},
  2852. X    {6, 0},
  2853. X    {283, 0},
  2854. X    {1, "or"},
  2855. X    {284, 0},
  2856. X    {1, "and"},
  2857. X    {1, "not"},
  2858. X    {285, 0},
  2859. X    {286, 0},
  2860. X    {20, 0},
  2861. X    {21, 0},
  2862. X    {1, "is"},
  2863. X    {288, 0},
  2864. X    {14, 0},
  2865. X    {15, 0},
  2866. X    {289, 0},
  2867. X    {17, 0},
  2868. X    {24, 0},
  2869. X    {290, 0},
  2870. X    {291, 0},
  2871. X    {9, 0},
  2872. X    {10, 0},
  2873. X    {26, 0},
  2874. X    {27, 0},
  2875. X    {25, 0},
  2876. X    {2, 0},
  2877. X    {3, 0},
  2878. X    {292, 0},
  2879. X    {23, 0},
  2880. X    {1, "class"},
  2881. X    {296, 0},
  2882. X    {297, 0},
  2883. X};
  2884. Xgrammar gram = {
  2885. X    42,
  2886. X    dfas,
  2887. X    {91, labels},
  2888. X    256
  2889. X};
  2890. EOF
  2891. fi
  2892. if test -s 'src/objimpl.h'
  2893. then echo '*** I will not over-write existing file src/objimpl.h'
  2894. else
  2895. echo 'x - src/objimpl.h'
  2896. sed 's/^X//' > 'src/objimpl.h' << 'EOF'
  2897. X/***********************************************************
  2898. XCopyright 1991 by Stichting Mathematisch Centrum, Amsterdam, The
  2899. XNetherlands.
  2900. X
  2901. X                        All Rights Reserved
  2902. X
  2903. XPermission to use, copy, modify, and distribute this software and its 
  2904. Xdocumentation for any purpose and without fee is hereby granted, 
  2905. Xprovided that the above copyright notice appear in all copies and that
  2906. Xboth that copyright notice and this permission notice appear in 
  2907. Xsupporting documentation, and that the names of Stichting Mathematisch
  2908. XCentrum or CWI not be used in advertising or publicity pertaining to
  2909. Xdistribution of the software without specific, written prior permission.
  2910. X
  2911. XSTICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
  2912. XTHIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
  2913. XFITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
  2914. XFOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  2915. XWHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  2916. XACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
  2917. XOF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  2918. X
  2919. X******************************************************************/
  2920. X
  2921. X/*
  2922. X123456789-123456789-123456789-123456789-123456789-123456789-123456789-12
  2923. X
  2924. XAdditional macros for modules that implement new object types.
  2925. XYou must first include "object.h".
  2926. X
  2927. XNEWOBJ(type, typeobj) allocates memory for a new object of the given
  2928. Xtype; here 'type' must be the C structure type used to represent the
  2929. Xobject and 'typeobj' the address of the corresponding type object.
  2930. XReference count and type pointer are filled in; the rest of the bytes of
  2931. Xthe object are *undefined*!  The resulting expression type is 'type *'.
  2932. XThe size of the object is actually determined by the tp_basicsize field
  2933. Xof the type object.
  2934. X
  2935. XNEWVAROBJ(type, typeobj, n) is similar but allocates a variable-size
  2936. Xobject with n extra items.  The size is computer as tp_basicsize plus
  2937. Xn * tp_itemsize.  This fills in the ob_size field as well.
  2938. X*/
  2939. X
  2940. Xextern object *newobject PROTO((typeobject *));
  2941. Xextern varobject *newvarobject PROTO((typeobject *, unsigned int));
  2942. X
  2943. X#define NEWOBJ(type, typeobj) ((type *) newobject(typeobj))
  2944. X#define NEWVAROBJ(type, typeobj, n) ((type *) newvarobject(typeobj, n))
  2945. X
  2946. Xextern int StopPrint; /* Set when printing is interrupted */
  2947. EOF
  2948. fi
  2949. echo 'Part 03 out of 21 of pack.out complete.'
  2950. exit 0
  2951.