diff --git a/include/picrin/value.h b/include/picrin/value.h index fc627138..e752f36a 100644 --- a/include/picrin/value.h +++ b/include/picrin/value.h @@ -69,5 +69,6 @@ pic_value pic_float_value(double); #define pic_nil_p(v) ((v).type == PIC_VTYPE_NIL) #define pic_true_p(v) ((v).type == PIC_VTYPE_TRUE) #define pic_false_p(v) ((v).type == PIC_VTYPE_FALSE) +#define pic_undef_p(v) ((v).type == PIC_VTYPE_UNDEF) #endif diff --git a/src/main.c b/src/main.c index 36e14f4e..1e24ed3f 100644 --- a/src/main.c +++ b/src/main.c @@ -3,6 +3,8 @@ #include "picrin.h" #if PIC_ENABLE_READLINE +# include +# include # include # include #endif @@ -84,6 +86,11 @@ main() printf("]\n"); #endif + if (pic_undef_p(v)) { + pic_gc_arena_restore(pic, ai); + continue; + } + /* eval */ proc = pic_codegen(pic, v, pic->global_env); v = pic_run(pic, proc, pic_nil_value()); diff --git a/src/parse.y b/src/parse.y index 5582c769..b730ee12 100644 --- a/src/parse.y +++ b/src/parse.y @@ -4,6 +4,8 @@ #include "picrin.h" +#define YYERROR_VERBOSE 1 + struct parser_control { pic_state *pic; pic_value value; @@ -29,7 +31,7 @@ struct parser_control { program : { - p->value = pic_nil_value(p->pic); + p->value = pic_undef_value(p->pic); } | datum { @@ -95,7 +97,6 @@ int yyerror(struct parser_control *p, const char *msg) { puts(msg); - abort(); } pic_value @@ -109,5 +110,9 @@ pic_parse(pic_state *pic, const char *str) yyparse(&p); yylex_destroy(); + if (yynerrs > 0) { + p.value = pic_undef_value(); + } + return p.value; }