parser returns multiple expressions in a call

This commit is contained in:
Yuichi Nishiwaki
2013-10-30 17:06:01 +09:00
parent 6fcce1cd23
commit 98a41314fe
4 changed files with 66 additions and 59 deletions
+29 -23
View File
@@ -2,6 +2,7 @@
#include <unistd.h>
#include "picrin.h"
#include "picrin/pair.h"
#if PIC_ENABLE_READLINE
# include <string.h>
@@ -58,10 +59,9 @@ repl(pic_state *pic)
{
char code[CODE_MAX_LENGTH] = "", line[LINE_MAX_LENGTH];
char *read_line, *prompt;
pic_value v;
pic_value v, vs;
struct pic_proc *proc;
int ai;
bool r;
int ai, n, i;
#if ! PIC_ENABLE_READLINE
char last_char;
@@ -102,39 +102,45 @@ repl(pic_state *pic)
strcat(code, line);
/* read */
r = pic_parse_cstr(pic, code, &v);
if (! r) { /* wait for more input */
n = pic_parse_cstr(pic, code, &vs);
if (n == 0) { /* wait for more input */
goto next;
}
code[0] = '\0';
if (pic_undef_p(v)) { /* parse error */
if (n == -1) { /* parse error */
goto next;
}
for (i = 0; i < n; ++i) {
v = pic_car(pic, vs);
#if DEBUG
printf("[read: ");
pic_debug(pic, v);
printf("]\n");
#endif
/* eval */
proc = pic_codegen(pic, v);
if (proc == NULL) {
printf("compilation error: %s\n", pic->errmsg);
pic->errmsg = NULL;
goto next;
}
v = pic_apply(pic, proc, pic_nil_value());
if (pic_undef_p(v)) {
printf("runtime error: %s\n", pic->errmsg);
pic->errmsg = NULL;
goto next;
}
/* eval */
proc = pic_codegen(pic, v);
if (proc == NULL) {
printf("compilation error: %s\n", pic->errmsg);
pic->errmsg = NULL;
goto next;
}
v = pic_apply(pic, proc, pic_nil_value());
if (pic_undef_p(v)) {
printf("runtime error: %s\n", pic->errmsg);
pic->errmsg = NULL;
goto next;
}
/* print */
printf("=> ");
pic_debug(pic, v);
printf("\n");
/* print */
printf("=> ");
pic_debug(pic, v);
printf("\n");
vs = pic_cdr(pic, vs);
}
next:
pic_gc_arena_restore(pic, ai);