From 2c9a19acf54fd89c348b6ca66f53e28bf42b368e Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Tue, 9 Jun 2015 16:02:23 +0900 Subject: [PATCH] introduce pic_invalid_value --- extlib/benz/debug.c | 2 +- extlib/benz/error.c | 2 +- extlib/benz/gc.c | 2 ++ extlib/benz/include/picrin/value.h | 21 +++++++++++++++++++-- extlib/benz/read.c | 18 +++++++++--------- extlib/benz/state.c | 4 ++-- 6 files changed, 34 insertions(+), 15 deletions(-) diff --git a/extlib/benz/debug.c b/extlib/benz/debug.c index 2525a656..d61e9380 100644 --- a/extlib/benz/debug.c +++ b/extlib/benz/debug.c @@ -35,7 +35,7 @@ pic_get_backtrace(pic_state *pic) void pic_print_backtrace(pic_state *pic, xFILE *file) { - assert(! pic_undef_p(pic->err)); + assert(! pic_invalid_p(pic->err)); if (! pic_error_p(pic->err)) { xfprintf(file, "raise: "); diff --git a/extlib/benz/error.c b/extlib/benz/error.c index 15e34087..6fa5309d 100644 --- a/extlib/benz/error.c +++ b/extlib/benz/error.c @@ -52,7 +52,7 @@ pic_errmsg(pic_state *pic) { pic_str *str; - assert(! pic_undef_p(pic->err)); + assert(! pic_invalid_p(pic->err)); if (! pic_error_p(pic->err)) { str = pic_format(pic, "~s", pic->err); diff --git a/extlib/benz/gc.c b/extlib/benz/gc.c index f7056d94..65bf219d 100644 --- a/extlib/benz/gc.c +++ b/extlib/benz/gc.c @@ -482,6 +482,7 @@ gc_mark_object(pic_state *pic, struct pic_object *obj) case PIC_TT_CHAR: case PIC_TT_EOF: case PIC_TT_UNDEF: + case PIC_TT_INVALID: pic_panic(pic, "logic flaw"); } } @@ -694,6 +695,7 @@ gc_finalize_object(pic_state *pic, struct pic_object *obj) case PIC_TT_CHAR: case PIC_TT_EOF: case PIC_TT_UNDEF: + case PIC_TT_INVALID: pic_panic(pic, "logic flaw"); } } diff --git a/extlib/benz/include/picrin/value.h b/extlib/benz/include/picrin/value.h index 02b06293..9790926b 100644 --- a/extlib/benz/include/picrin/value.h +++ b/extlib/benz/include/picrin/value.h @@ -10,8 +10,8 @@ extern "C" { #endif /** - * `undef` values never seen from user-end: that is, - * it's used only for repsenting internal special state + * `invalid` value will never be seen from user-end: + * it is only used for repsenting internal special state */ enum pic_vtype { @@ -19,6 +19,7 @@ enum pic_vtype { PIC_VTYPE_TRUE, PIC_VTYPE_FALSE, PIC_VTYPE_UNDEF, + PIC_VTYPE_INVALID, #if PIC_ENABLE_FLOAT PIC_VTYPE_FLOAT, #endif @@ -146,6 +147,7 @@ enum pic_tt { PIC_TT_CHAR, PIC_TT_EOF, PIC_TT_UNDEF, + PIC_TT_INVALID, /* heap */ PIC_TT_SYMBOL, PIC_TT_PAIR, @@ -196,6 +198,7 @@ typedef struct pic_blob pic_blob; #define pic_true_p(v) (pic_vtype(v) == PIC_VTYPE_TRUE) #define pic_false_p(v) (pic_vtype(v) == PIC_VTYPE_FALSE) #define pic_undef_p(v) (pic_vtype(v) == PIC_VTYPE_UNDEF) +#define pic_invalid_p(v) (pic_vtype(v) == PIC_VTYPE_INVALID) #define pic_float_p(v) (pic_vtype(v) == PIC_VTYPE_FLOAT) #define pic_int_p(v) (pic_vtype(v) == PIC_VTYPE_INT) #define pic_char_p(v) (pic_vtype(v) == PIC_VTYPE_CHAR) @@ -231,6 +234,7 @@ PIC_INLINE pic_value pic_true_value(); PIC_INLINE pic_value pic_false_value(); PIC_INLINE pic_value pic_bool_value(bool); PIC_INLINE pic_value pic_undef_value(); +PIC_INLINE pic_value pic_invalid_value(); PIC_INLINE pic_value pic_obj_value(void *); #if PIC_ENABLE_FLOAT PIC_INLINE pic_value pic_float_value(double); @@ -255,6 +259,8 @@ pic_type(pic_value v) return PIC_TT_BOOL; case PIC_VTYPE_UNDEF: return PIC_TT_UNDEF; + case PIC_VTYPE_INVALID: + return PIC_TT_INVALID; #if PIC_ENABLE_FLOAT case PIC_VTYPE_FLOAT: return PIC_TT_FLOAT; @@ -294,6 +300,8 @@ pic_type_repr(enum pic_tt tt) return "eof"; case PIC_TT_UNDEF: return "undef"; + case PIC_TT_INVALID: + return "invalid"; case PIC_TT_PAIR: return "pair"; case PIC_TT_STRING: @@ -500,6 +508,15 @@ pic_undef_value() return v; } +PIC_INLINE pic_value +pic_invalid_value() +{ + pic_value v; + + pic_init_value(v, PIC_VTYPE_INVALID); + return v; +} + PIC_INLINE pic_value pic_none_value() { diff --git a/extlib/benz/read.c b/extlib/benz/read.c index 50498ac2..dc7a28a5 100644 --- a/extlib/benz/read.c +++ b/extlib/benz/read.c @@ -92,7 +92,7 @@ read_comment(pic_state PIC_UNUSED(*pic), struct pic_port *port, int c) c = next(port); } while (! (c == EOF || c == '\n')); - return pic_undef_value(); + return pic_invalid_value(); } static pic_value @@ -114,7 +114,7 @@ read_block_comment(pic_state PIC_UNUSED(*pic), struct pic_port *port, int PIC_UN } } - return pic_undef_value(); + return pic_invalid_value(); } static pic_value @@ -122,7 +122,7 @@ read_datum_comment(pic_state *pic, struct pic_port *port, int PIC_UNUSED(c)) { read(pic, port, next(port)); - return pic_undef_value(); + return pic_invalid_value(); } static pic_value @@ -132,13 +132,13 @@ read_directive(pic_state *pic, struct pic_port *port, int c) case 'n': if (expect(port, "no-fold-case")) { pic->reader->typecase = PIC_CASE_DEFAULT; - return pic_undef_value(); + return pic_invalid_value(); } break; case 'f': if (expect(port, "fold-case")) { pic->reader->typecase = PIC_CASE_FOLD; - return pic_undef_value(); + return pic_invalid_value(); } break; } @@ -578,7 +578,7 @@ read_pair(pic_state *pic, struct pic_port *port, int c) closing: if ((c = skip(port, ' ')) != tCLOSE) { - if (pic_undef_p(read_nullable(pic, port, c))) { + if (pic_invalid_p(read_nullable(pic, port, c))) { goto closing; } read_error(pic, "unmatched parenthesis"); @@ -588,7 +588,7 @@ read_pair(pic_state *pic, struct pic_port *port, int c) else { car = read_nullable(pic, port, c); - if (pic_undef_p(car)) { + if (pic_invalid_p(car)) { goto retry; } @@ -742,7 +742,7 @@ read(pic_state *pic, struct pic_port *port, int c) retry: val = read_nullable(pic, port, c); - if (pic_undef_p(val)) { + if (pic_invalid_p(val)) { c = next(port); goto retry; } @@ -840,7 +840,7 @@ pic_read(pic_state *pic, struct pic_port *port) val = read_nullable(pic, port, c); - if (pic_undef_p(val)) { + if (pic_invalid_p(val)) { c = next(port); goto retry; } diff --git a/extlib/benz/state.c b/extlib/benz/state.c index 75b2df9b..aa60da35 100644 --- a/extlib/benz/state.c +++ b/extlib/benz/state.c @@ -223,7 +223,7 @@ pic_open(int argc, char *argv[], char **envp, pic_allocf allocf) pic->lib = NULL; /* raised error object */ - pic->err = pic_undef_value(); + pic->err = pic_invalid_value(); /* standard ports */ pic->xSTDIN = NULL; @@ -402,7 +402,7 @@ pic_close(pic_state *pic) pic->ci = pic->cibase; pic->xp = pic->xpbase; pic->arena_idx = 0; - pic->err = pic_undef_value(); + pic->err = pic_invalid_value(); pic->globals = NULL; pic->macros = NULL; xh_clear(&pic->syms);