altos/scheme: Add support for hex, octal and binary constants
[fw/altos] / src / scheme / ao_scheme_read.c
1 /*
2  * Copyright © 2016 Keith Packard <keithp@keithp.com>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * General Public License for more details.
13  */
14
15 #include "ao_scheme.h"
16 #include "ao_scheme_read.h"
17 #include <math.h>
18 #include <stdlib.h>
19
20 static const uint16_t   lex_classes[128] = {
21         IGNORE,         /* ^@ */
22         IGNORE,         /* ^A */
23         IGNORE,         /* ^B */
24         IGNORE,         /* ^C */
25         IGNORE,         /* ^D */
26         IGNORE,         /* ^E */
27         IGNORE,         /* ^F */
28         IGNORE,         /* ^G */
29         IGNORE,         /* ^H */
30         WHITE,          /* ^I */
31         WHITE,          /* ^J */
32         WHITE,          /* ^K */
33         WHITE,          /* ^L */
34         WHITE,          /* ^M */
35         IGNORE,         /* ^N */
36         IGNORE,         /* ^O */
37         IGNORE,         /* ^P */
38         IGNORE,         /* ^Q */
39         IGNORE,         /* ^R */
40         IGNORE,         /* ^S */
41         IGNORE,         /* ^T */
42         IGNORE,         /* ^U */
43         IGNORE,         /* ^V */
44         IGNORE,         /* ^W */
45         IGNORE,         /* ^X */
46         IGNORE,         /* ^Y */
47         IGNORE,         /* ^Z */
48         IGNORE,         /* ^[ */
49         IGNORE,         /* ^\ */
50         IGNORE,         /* ^] */
51         IGNORE,         /* ^^ */
52         IGNORE,         /* ^_ */
53         PRINTABLE|WHITE,        /*    */
54         PRINTABLE,              /* ! */
55         PRINTABLE|STRINGC,      /* " */
56         PRINTABLE|POUND,        /* # */
57         PRINTABLE,              /* $ */
58         PRINTABLE,              /* % */
59         PRINTABLE,              /* & */
60         PRINTABLE|SPECIAL,      /* ' */
61         PRINTABLE|SPECIAL,      /* ( */
62         PRINTABLE|SPECIAL,      /* ) */
63         PRINTABLE,              /* * */
64         PRINTABLE|SIGN,         /* + */
65         PRINTABLE|SPECIAL_QUASI,        /* , */
66         PRINTABLE|SIGN,         /* - */
67         PRINTABLE|DOTC|FLOATC,  /* . */
68         PRINTABLE,              /* / */
69         PRINTABLE|DIGIT,        /* 0 */
70         PRINTABLE|DIGIT,        /* 1 */
71         PRINTABLE|DIGIT,        /* 2 */
72         PRINTABLE|DIGIT,        /* 3 */
73         PRINTABLE|DIGIT,        /* 4 */
74         PRINTABLE|DIGIT,        /* 5 */
75         PRINTABLE|DIGIT,        /* 6 */
76         PRINTABLE|DIGIT,        /* 7 */
77         PRINTABLE|DIGIT,        /* 8 */
78         PRINTABLE|DIGIT,        /* 9 */
79         PRINTABLE,              /* : */
80         PRINTABLE|COMMENT,      /* ; */
81         PRINTABLE,              /* < */
82         PRINTABLE,              /* = */
83         PRINTABLE,              /* > */
84         PRINTABLE,              /* ? */
85         PRINTABLE,              /*  @ */
86         PRINTABLE|HEX_LETTER,   /*  A */
87         PRINTABLE|HEX_LETTER,   /*  B */
88         PRINTABLE|HEX_LETTER,   /*  C */
89         PRINTABLE|HEX_LETTER,   /*  D */
90         PRINTABLE|FLOATC|HEX_LETTER,/*  E */
91         PRINTABLE|HEX_LETTER,   /*  F */
92         PRINTABLE,              /*  G */
93         PRINTABLE,              /*  H */
94         PRINTABLE,              /*  I */
95         PRINTABLE,              /*  J */
96         PRINTABLE,              /*  K */
97         PRINTABLE,              /*  L */
98         PRINTABLE,              /*  M */
99         PRINTABLE,              /*  N */
100         PRINTABLE,              /*  O */
101         PRINTABLE,              /*  P */
102         PRINTABLE,              /*  Q */
103         PRINTABLE,              /*  R */
104         PRINTABLE,              /*  S */
105         PRINTABLE,              /*  T */
106         PRINTABLE,              /*  U */
107         PRINTABLE,              /*  V */
108         PRINTABLE,              /*  W */
109         PRINTABLE,              /*  X */
110         PRINTABLE,              /*  Y */
111         PRINTABLE,              /*  Z */
112         PRINTABLE,              /*  [ */
113         PRINTABLE|BACKSLASH,    /*  \ */
114         PRINTABLE,              /*  ] */
115         PRINTABLE,              /*  ^ */
116         PRINTABLE,              /*  _ */
117         PRINTABLE|SPECIAL_QUASI,        /*  ` */
118         PRINTABLE|HEX_LETTER,   /*  a */
119         PRINTABLE|HEX_LETTER,   /*  b */
120         PRINTABLE|HEX_LETTER,   /*  c */
121         PRINTABLE|HEX_LETTER,   /*  d */
122         PRINTABLE|FLOATC|HEX_LETTER,/*  e */
123         PRINTABLE|HEX_LETTER,   /*  f */
124         PRINTABLE,              /*  g */
125         PRINTABLE,              /*  h */
126         PRINTABLE,              /*  i */
127         PRINTABLE,              /*  j */
128         PRINTABLE,              /*  k */
129         PRINTABLE,              /*  l */
130         PRINTABLE,              /*  m */
131         PRINTABLE,              /*  n */
132         PRINTABLE,              /*  o */
133         PRINTABLE,              /*  p */
134         PRINTABLE,              /*  q */
135         PRINTABLE,              /*  r */
136         PRINTABLE,              /*  s */
137         PRINTABLE,              /*  t */
138         PRINTABLE,              /*  u */
139         PRINTABLE,              /*  v */
140         PRINTABLE,              /*  w */
141         PRINTABLE,              /*  x */
142         PRINTABLE,              /*  y */
143         PRINTABLE,              /*  z */
144         PRINTABLE,              /*  { */
145         PRINTABLE,              /*  | */
146         PRINTABLE,              /*  } */
147         PRINTABLE,              /*  ~ */
148         IGNORE,                 /*  ^? */
149 };
150
151 static int lex_unget_c;
152
153 static inline int
154 lex_get(void)
155 {
156         int     c;
157         if (lex_unget_c) {
158                 c = lex_unget_c;
159                 lex_unget_c = 0;
160         } else {
161                 c = ao_scheme_getc();
162         }
163         return c;
164 }
165
166 static inline void
167 lex_unget(int c)
168 {
169         if (c != EOF)
170                 lex_unget_c = c;
171 }
172
173 static uint16_t lex_class;
174
175 static int
176 lexc(void)
177 {
178         int     c;
179         do {
180                 c = lex_get();
181                 if (c == EOF) {
182                         c = 0;
183                         lex_class = ENDOFFILE;
184                 } else {
185                         c &= 0x7f;
186                         lex_class = lex_classes[c];
187                 }
188         } while (lex_class & IGNORE);
189         return c;
190 }
191
192 static int
193 lex_quoted(void)
194 {
195         int     c;
196         int     v;
197         int     count;
198
199         c = lex_get();
200         if (c == EOF) {
201                 lex_class = ENDOFFILE;
202                 return 0;
203         }
204         lex_class = 0;
205         c &= 0x7f;
206         switch (c) {
207         case 'n':
208                 return '\n';
209         case 'f':
210                 return '\f';
211         case 'b':
212                 return '\b';
213         case 'r':
214                 return '\r';
215         case 'v':
216                 return '\v';
217         case 't':
218                 return '\t';
219         case '0':
220         case '1':
221         case '2':
222         case '3':
223         case '4':
224         case '5':
225         case '6':
226         case '7':
227                 v = c - '0';
228                 count = 1;
229                 while (count <= 3) {
230                         c = lex_get();
231                         if (c == EOF)
232                                 return EOF;
233                         c &= 0x7f;
234                         if (c < '0' || '7' < c) {
235                                 lex_unget(c);
236                                 break;
237                         }
238                         v = (v << 3) + c - '0';
239                         ++count;
240                 }
241                 return v;
242         default:
243                 return c;
244         }
245 }
246
247 #ifndef AO_SCHEME_TOKEN_MAX
248 #define AO_SCHEME_TOKEN_MAX     128
249 #endif
250
251 static char     token_string[AO_SCHEME_TOKEN_MAX];
252 static int32_t  token_int;
253 static int      token_len;
254
255 static inline void add_token(int c) {
256         if (c && token_len < AO_SCHEME_TOKEN_MAX - 1)
257                 token_string[token_len++] = c;
258 }
259
260 static inline void del_token(void) {
261         if (token_len > 0)
262                 token_len--;
263 }
264
265 static inline void end_token(void) {
266         token_string[token_len] = '\0';
267 }
268
269 #ifdef AO_SCHEME_FEATURE_FLOAT
270 static float    token_float;
271
272 struct namedfloat {
273         const char      *name;
274         float           value;
275 };
276
277 static const struct namedfloat namedfloats[] = {
278         { .name = "+inf.0", .value = INFINITY },
279         { .name = "-inf.0", .value = -INFINITY },
280         { .name = "+nan.0", .value = NAN },
281         { .name = "-nan.0", .value = NAN },
282 };
283
284 #define NUM_NAMED_FLOATS        (sizeof namedfloats / sizeof namedfloats[0])
285 #endif
286
287 static int
288 parse_int(int base)
289 {
290         int     cval;
291         int     c;
292
293         token_int = 0;
294         for (;;) {
295                 c = lexc();
296                 if ((lex_class & HEX_DIGIT) == 0) {
297                         lex_unget(c);
298                         end_token();
299                         return NUM;
300                 }
301                 add_token(c);
302                 if ('0' <= c && c <= '9')
303                         cval = c - '0';
304                 else
305                         cval = (c | ('a' - 'A')) - 'a' + 10;
306                 token_int = token_int * base + cval;
307         }
308         return NUM;
309 }
310
311 static int
312 _lex(void)
313 {
314         int     c;
315
316         token_len = 0;
317         for (;;) {
318                 c = lexc();
319                 if (lex_class & ENDOFFILE)
320                         return END;
321
322                 if (lex_class & WHITE)
323                         continue;
324
325                 if (lex_class & COMMENT) {
326                         while ((c = lexc()) != '\n') {
327                                 if (lex_class & ENDOFFILE)
328                                         return END;
329                         }
330                         continue;
331                 }
332
333                 if (lex_class & (SPECIAL|DOTC)) {
334                         add_token(c);
335                         end_token();
336                         switch (c) {
337                         case '(':
338                         case '[':
339                                 return OPEN;
340                         case ')':
341                         case ']':
342                                 return CLOSE;
343                         case '\'':
344                                 return QUOTE;
345                         case '.':
346                                 return DOT;
347 #ifdef AO_SCHEME_FEATURE_QUASI
348                         case '`':
349                                 return QUASIQUOTE;
350                         case ',':
351                                 c = lexc();
352                                 if (c == '@') {
353                                         add_token(c);
354                                         end_token();
355                                         return UNQUOTE_SPLICING;
356                                 } else {
357                                         lex_unget(c);
358                                         return UNQUOTE;
359                                 }
360 #endif
361                         }
362                 }
363                 if (lex_class & POUND) {
364                         c = lexc();
365                         switch (c) {
366                         case 't':
367                                 add_token(c);
368                                 end_token();
369                                 return BOOL;
370                         case 'f':
371                                 add_token(c);
372                                 end_token();
373                                 return BOOL;
374 #ifdef AO_SCHEME_FEATURE_VECTOR
375                         case '(':
376                                 return OPEN_VECTOR;
377 #endif
378                         case '\\':
379                                 for (;;) {
380                                         int alphabetic;
381                                         c = lexc();
382                                         alphabetic = (('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z'));
383                                         if (token_len == 0) {
384                                                 add_token(c);
385                                                 if (!alphabetic)
386                                                         break;
387                                         } else {
388                                                 if (alphabetic)
389                                                         add_token(c);
390                                                 else {
391                                                         lex_unget(c);
392                                                         break;
393                                                 }
394                                         }
395                                 }
396                                 end_token();
397                                 if (token_len == 1)
398                                         token_int = token_string[0];
399                                 else if (!strcmp(token_string, "space"))
400                                         token_int = ' ';
401                                 else if (!strcmp(token_string, "newline"))
402                                         token_int = '\n';
403                                 else if (!strcmp(token_string, "tab"))
404                                         token_int = '\t';
405                                 else if (!strcmp(token_string, "return"))
406                                         token_int = '\r';
407                                 else if (!strcmp(token_string, "formfeed"))
408                                         token_int = '\f';
409                                 else {
410                                         ao_scheme_error(AO_SCHEME_INVALID, "invalid character token #\\%s", token_string);
411                                         continue;
412                                 }
413                                 return NUM;
414                         case 'x':
415                                 return parse_int(16);
416                         case 'o':
417                                 return parse_int(8);
418                         case 'b':
419                                 return parse_int(2);
420                         }
421                 }
422                 if (lex_class & STRINGC) {
423                         for (;;) {
424                                 c = lexc();
425                                 if (lex_class & BACKSLASH)
426                                         c = lex_quoted();
427                                 if (lex_class & (STRINGC|ENDOFFILE)) {
428                                         end_token();
429                                         return STRING;
430                                 }
431                                 add_token(c);
432                         }
433                 }
434                 if (lex_class & PRINTABLE) {
435 #ifdef AO_SCHEME_FEATURE_FLOAT
436                         int     isfloat = 1;
437                         int     epos = 0;
438 #endif
439                         int     hasdigit = 0;
440                         int     isneg = 0;
441                         int     isint = 1;
442
443                         token_int = 0;
444                         for (;;) {
445                                 if (!(lex_class & NUMBER)) {
446                                         isint = 0;
447 #ifdef AO_SCHEME_FEATURE_FLOAT
448                                         isfloat = 0;
449 #endif
450                                 } else {
451 #ifdef AO_SCHEME_FEATURE_FLOAT
452                                         if (!(lex_class & INTEGER))
453                                                 isint = 0;
454                                         if (token_len != epos &&
455                                             (lex_class & SIGN))
456                                         {
457                                                 isint = 0;
458                                                 isfloat = 0;
459                                         }
460 #endif
461                                         if (c == '-')
462                                                 isneg = 1;
463 #ifdef AO_SCHEME_FEATURE_FLOAT
464                                         if (c == '.' && epos != 0)
465                                                 isfloat = 0;
466                                         if (c == 'e' || c == 'E') {
467                                                 if (token_len == 0)
468                                                         isfloat = 0;
469                                                 else
470                                                         epos = token_len + 1;
471                                         }
472 #endif
473                                         if (lex_class & DIGIT) {
474                                                 hasdigit = 1;
475                                                 if (isint)
476                                                         token_int = token_int * 10 + c - '0';
477                                         }
478                                 }
479                                 add_token (c);
480                                 c = lexc ();
481                                 if ((lex_class & (NOTNAME))
482 #ifdef AO_SCHEME_FEATURE_FLOAT
483                                     && (c != '.' || !isfloat)
484 #endif
485                                         ) {
486 #ifdef AO_SCHEME_FEATURE_FLOAT
487                                         unsigned int u;
488 #endif
489 //                                      if (lex_class & ENDOFFILE)
490 //                                              clearerr (f);
491                                         lex_unget(c);
492                                         end_token ();
493                                         if (isint && hasdigit) {
494                                                 if (isneg)
495                                                         token_int = -token_int;
496                                                 return NUM;
497                                         }
498 #ifdef AO_SCHEME_FEATURE_FLOAT
499                                         if (isfloat && hasdigit) {
500                                                 token_float = strtof(token_string, NULL);
501                                                 return FLOAT;
502                                         }
503                                         for (u = 0; u < NUM_NAMED_FLOATS; u++)
504                                                 if (!strcmp(namedfloats[u].name, token_string)) {
505                                                         token_float = namedfloats[u].value;
506                                                         return FLOAT;
507                                                 }
508 #endif
509                                         return NAME;
510                                 }
511                         }
512                 }
513         }
514 }
515
516 static inline int lex(void)
517 {
518         int     parse_token = _lex();
519         RDBGI("token %d (%s)\n", parse_token, token_string);
520         return parse_token;
521 }
522
523 static int parse_token;
524
525 int                     ao_scheme_read_list;
526 struct ao_scheme_cons   *ao_scheme_read_cons;
527 struct ao_scheme_cons   *ao_scheme_read_cons_tail;
528 struct ao_scheme_cons   *ao_scheme_read_stack;
529 static int              ao_scheme_read_state;
530
531 #define READ_IN_QUOTE   0x01
532 #define READ_SAW_DOT    0x02
533 #define READ_DONE_DOT   0x04
534 #define READ_SAW_VECTOR 0x08
535
536 static int
537 push_read_stack(int read_state)
538 {
539         RDBGI("push read stack %p 0x%x\n", ao_scheme_read_cons, read_state);
540         RDBG_IN();
541         if (ao_scheme_read_list) {
542                 ao_scheme_read_stack = ao_scheme_cons_cons(ao_scheme_cons_poly(ao_scheme_read_cons),
543                                                        ao_scheme_cons(ao_scheme_int_poly(read_state),
544                                                                      ao_scheme_cons_poly(ao_scheme_read_stack)));
545                 if (!ao_scheme_read_stack)
546                         return 0;
547         } else
548                 ao_scheme_read_state = read_state;
549         ao_scheme_read_cons = NULL;
550         ao_scheme_read_cons_tail = NULL;
551         return 1;
552 }
553
554 static int
555 pop_read_stack(void)
556 {
557         int     read_state = 0;
558         if (ao_scheme_read_list) {
559                 ao_scheme_read_cons = ao_scheme_poly_cons(ao_scheme_read_stack->car);
560                 ao_scheme_read_stack = ao_scheme_poly_cons(ao_scheme_read_stack->cdr);
561                 read_state = ao_scheme_poly_int(ao_scheme_read_stack->car);
562                 ao_scheme_read_stack = ao_scheme_poly_cons(ao_scheme_read_stack->cdr);
563                 for (ao_scheme_read_cons_tail = ao_scheme_read_cons;
564                      ao_scheme_read_cons_tail && ao_scheme_read_cons_tail->cdr;
565                      ao_scheme_read_cons_tail = ao_scheme_poly_cons(ao_scheme_read_cons_tail->cdr))
566                         ;
567         } else {
568                 ao_scheme_read_cons = 0;
569                 ao_scheme_read_cons_tail = 0;
570                 ao_scheme_read_stack = 0;
571                 read_state = ao_scheme_read_state;
572         }
573         RDBG_OUT();
574         RDBGI("pop read stack %p %d\n", ao_scheme_read_cons, read_state);
575         return read_state;
576 }
577
578 #ifdef AO_SCHEME_FEATURE_VECTOR
579 #define is_open(t) ((t) == OPEN || (t) == OPEN_VECTOR)
580 #else
581 #define is_open(t) ((t) == OPEN)
582 #endif
583
584 ao_poly
585 ao_scheme_read(void)
586 {
587         struct ao_scheme_atom   *atom;
588         struct ao_scheme_string *string;
589         int                     read_state;
590         ao_poly                 v = AO_SCHEME_NIL;
591
592         ao_scheme_read_list = 0;
593         read_state = 0;
594         ao_scheme_read_cons = ao_scheme_read_cons_tail = ao_scheme_read_stack = 0;
595         for (;;) {
596                 parse_token = lex();
597                 while (is_open(parse_token)) {
598 #ifdef AO_SCHEME_FEATURE_VECTOR
599                         if (parse_token == OPEN_VECTOR)
600                                 read_state |= READ_SAW_VECTOR;
601 #endif
602                         if (!push_read_stack(read_state))
603                                 return AO_SCHEME_NIL;
604                         ao_scheme_read_list++;
605                         read_state = 0;
606                         parse_token = lex();
607                 }
608
609                 switch (parse_token) {
610                 case END:
611                 default:
612                         if (ao_scheme_read_list)
613                                 ao_scheme_error(AO_SCHEME_EOF, "unexpected end of file");
614                         return _ao_scheme_atom_eof;
615                         break;
616                 case NAME:
617                         atom = ao_scheme_atom_intern(token_string);
618                         if (atom)
619                                 v = ao_scheme_atom_poly(atom);
620                         else
621                                 v = AO_SCHEME_NIL;
622                         break;
623                 case NUM:
624                         v = ao_scheme_integer_poly(token_int);
625                         break;
626 #ifdef AO_SCHEME_FEATURE_FLOAT
627                 case FLOAT:
628                         v = ao_scheme_float_get(token_float);
629                         break;
630 #endif
631                 case BOOL:
632                         if (token_string[0] == 't')
633                                 v = _ao_scheme_bool_true;
634                         else
635                                 v = _ao_scheme_bool_false;
636                         break;
637                 case STRING:
638                         string = ao_scheme_string_make(token_string);
639                         if (string)
640                                 v = ao_scheme_string_poly(string);
641                         else
642                                 v = AO_SCHEME_NIL;
643                         break;
644                 case QUOTE:
645 #ifdef AO_SCHEME_FEATURE_QUASI
646                 case QUASIQUOTE:
647                 case UNQUOTE:
648                 case UNQUOTE_SPLICING:
649 #endif
650                         if (!push_read_stack(read_state))
651                                 return AO_SCHEME_NIL;
652                         ao_scheme_read_list++;
653                         read_state = READ_IN_QUOTE;
654                         switch (parse_token) {
655                         case QUOTE:
656                                 v = _ao_scheme_atom_quote;
657                                 break;
658 #ifdef AO_SCHEME_FEATURE_QUASI
659                         case QUASIQUOTE:
660                                 v = _ao_scheme_atom_quasiquote;
661                                 break;
662                         case UNQUOTE:
663                                 v = _ao_scheme_atom_unquote;
664                                 break;
665                         case UNQUOTE_SPLICING:
666                                 v = _ao_scheme_atom_unquote2dsplicing;
667                                 break;
668 #endif
669                         }
670                         break;
671                 case CLOSE:
672                         if (!ao_scheme_read_list) {
673                                 v = AO_SCHEME_NIL;
674                                 break;
675                         }
676                         v = ao_scheme_cons_poly(ao_scheme_read_cons);
677                         --ao_scheme_read_list;
678                         read_state = pop_read_stack();
679 #ifdef AO_SCHEME_FEATURE_VECTOR
680                         if (read_state & READ_SAW_VECTOR)
681                                 v = ao_scheme_vector_poly(ao_scheme_list_to_vector(ao_scheme_poly_cons(v)));
682 #endif
683                         break;
684                 case DOT:
685                         if (!ao_scheme_read_list) {
686                                 ao_scheme_error(AO_SCHEME_INVALID, ". outside of cons");
687                                 return AO_SCHEME_NIL;
688                         }
689                         if (!ao_scheme_read_cons) {
690                                 ao_scheme_error(AO_SCHEME_INVALID, ". first in cons");
691                                 return AO_SCHEME_NIL;
692                         }
693                         read_state |= READ_SAW_DOT;
694                         continue;
695                 }
696
697                 /* loop over QUOTE ends */
698                 for (;;) {
699                         if (!ao_scheme_read_list)
700                                 return v;
701
702                         if (read_state & READ_DONE_DOT) {
703                                 ao_scheme_error(AO_SCHEME_INVALID, ". not last in cons");
704                                 return AO_SCHEME_NIL;
705                         }
706
707                         if (read_state & READ_SAW_DOT) {
708                                 read_state |= READ_DONE_DOT;
709                                 ao_scheme_read_cons_tail->cdr = v;
710                         } else {
711                                 struct ao_scheme_cons   *read = ao_scheme_cons_cons(v, AO_SCHEME_NIL);
712                                 if (!read)
713                                         return AO_SCHEME_NIL;
714
715                                 if (ao_scheme_read_cons_tail)
716                                         ao_scheme_read_cons_tail->cdr = ao_scheme_cons_poly(read);
717                                 else
718                                         ao_scheme_read_cons = read;
719                                 ao_scheme_read_cons_tail = read;
720                         }
721
722                         if (!(read_state & READ_IN_QUOTE) || !ao_scheme_read_cons->cdr)
723                                 break;
724
725                         v = ao_scheme_cons_poly(ao_scheme_read_cons);
726                         --ao_scheme_read_list;
727                         read_state = pop_read_stack();
728                 }
729         }
730         return v;
731 }