introduce pic_invalid_value

This commit is contained in:
Yuichi Nishiwaki 2015-06-09 16:02:23 +09:00
parent df56a8c154
commit 2c9a19acf5
6 changed files with 34 additions and 15 deletions

View File

@ -35,7 +35,7 @@ pic_get_backtrace(pic_state *pic)
void void
pic_print_backtrace(pic_state *pic, xFILE *file) 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)) { if (! pic_error_p(pic->err)) {
xfprintf(file, "raise: "); xfprintf(file, "raise: ");

View File

@ -52,7 +52,7 @@ pic_errmsg(pic_state *pic)
{ {
pic_str *str; pic_str *str;
assert(! pic_undef_p(pic->err)); assert(! pic_invalid_p(pic->err));
if (! pic_error_p(pic->err)) { if (! pic_error_p(pic->err)) {
str = pic_format(pic, "~s", pic->err); str = pic_format(pic, "~s", pic->err);

View File

@ -482,6 +482,7 @@ gc_mark_object(pic_state *pic, struct pic_object *obj)
case PIC_TT_CHAR: case PIC_TT_CHAR:
case PIC_TT_EOF: case PIC_TT_EOF:
case PIC_TT_UNDEF: case PIC_TT_UNDEF:
case PIC_TT_INVALID:
pic_panic(pic, "logic flaw"); 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_CHAR:
case PIC_TT_EOF: case PIC_TT_EOF:
case PIC_TT_UNDEF: case PIC_TT_UNDEF:
case PIC_TT_INVALID:
pic_panic(pic, "logic flaw"); pic_panic(pic, "logic flaw");
} }
} }

View File

@ -10,8 +10,8 @@ extern "C" {
#endif #endif
/** /**
* `undef` values never seen from user-end: that is, * `invalid` value will never be seen from user-end:
* it's used only for repsenting internal special state * it is only used for repsenting internal special state
*/ */
enum pic_vtype { enum pic_vtype {
@ -19,6 +19,7 @@ enum pic_vtype {
PIC_VTYPE_TRUE, PIC_VTYPE_TRUE,
PIC_VTYPE_FALSE, PIC_VTYPE_FALSE,
PIC_VTYPE_UNDEF, PIC_VTYPE_UNDEF,
PIC_VTYPE_INVALID,
#if PIC_ENABLE_FLOAT #if PIC_ENABLE_FLOAT
PIC_VTYPE_FLOAT, PIC_VTYPE_FLOAT,
#endif #endif
@ -146,6 +147,7 @@ enum pic_tt {
PIC_TT_CHAR, PIC_TT_CHAR,
PIC_TT_EOF, PIC_TT_EOF,
PIC_TT_UNDEF, PIC_TT_UNDEF,
PIC_TT_INVALID,
/* heap */ /* heap */
PIC_TT_SYMBOL, PIC_TT_SYMBOL,
PIC_TT_PAIR, 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_true_p(v) (pic_vtype(v) == PIC_VTYPE_TRUE)
#define pic_false_p(v) (pic_vtype(v) == PIC_VTYPE_FALSE) #define pic_false_p(v) (pic_vtype(v) == PIC_VTYPE_FALSE)
#define pic_undef_p(v) (pic_vtype(v) == PIC_VTYPE_UNDEF) #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_float_p(v) (pic_vtype(v) == PIC_VTYPE_FLOAT)
#define pic_int_p(v) (pic_vtype(v) == PIC_VTYPE_INT) #define pic_int_p(v) (pic_vtype(v) == PIC_VTYPE_INT)
#define pic_char_p(v) (pic_vtype(v) == PIC_VTYPE_CHAR) #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_false_value();
PIC_INLINE pic_value pic_bool_value(bool); PIC_INLINE pic_value pic_bool_value(bool);
PIC_INLINE pic_value pic_undef_value(); PIC_INLINE pic_value pic_undef_value();
PIC_INLINE pic_value pic_invalid_value();
PIC_INLINE pic_value pic_obj_value(void *); PIC_INLINE pic_value pic_obj_value(void *);
#if PIC_ENABLE_FLOAT #if PIC_ENABLE_FLOAT
PIC_INLINE pic_value pic_float_value(double); PIC_INLINE pic_value pic_float_value(double);
@ -255,6 +259,8 @@ pic_type(pic_value v)
return PIC_TT_BOOL; return PIC_TT_BOOL;
case PIC_VTYPE_UNDEF: case PIC_VTYPE_UNDEF:
return PIC_TT_UNDEF; return PIC_TT_UNDEF;
case PIC_VTYPE_INVALID:
return PIC_TT_INVALID;
#if PIC_ENABLE_FLOAT #if PIC_ENABLE_FLOAT
case PIC_VTYPE_FLOAT: case PIC_VTYPE_FLOAT:
return PIC_TT_FLOAT; return PIC_TT_FLOAT;
@ -294,6 +300,8 @@ pic_type_repr(enum pic_tt tt)
return "eof"; return "eof";
case PIC_TT_UNDEF: case PIC_TT_UNDEF:
return "undef"; return "undef";
case PIC_TT_INVALID:
return "invalid";
case PIC_TT_PAIR: case PIC_TT_PAIR:
return "pair"; return "pair";
case PIC_TT_STRING: case PIC_TT_STRING:
@ -500,6 +508,15 @@ pic_undef_value()
return v; 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_INLINE pic_value
pic_none_value() pic_none_value()
{ {

View File

@ -92,7 +92,7 @@ read_comment(pic_state PIC_UNUSED(*pic), struct pic_port *port, int c)
c = next(port); c = next(port);
} while (! (c == EOF || c == '\n')); } while (! (c == EOF || c == '\n'));
return pic_undef_value(); return pic_invalid_value();
} }
static pic_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 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)); read(pic, port, next(port));
return pic_undef_value(); return pic_invalid_value();
} }
static pic_value static pic_value
@ -132,13 +132,13 @@ read_directive(pic_state *pic, struct pic_port *port, int c)
case 'n': case 'n':
if (expect(port, "no-fold-case")) { if (expect(port, "no-fold-case")) {
pic->reader->typecase = PIC_CASE_DEFAULT; pic->reader->typecase = PIC_CASE_DEFAULT;
return pic_undef_value(); return pic_invalid_value();
} }
break; break;
case 'f': case 'f':
if (expect(port, "fold-case")) { if (expect(port, "fold-case")) {
pic->reader->typecase = PIC_CASE_FOLD; pic->reader->typecase = PIC_CASE_FOLD;
return pic_undef_value(); return pic_invalid_value();
} }
break; break;
} }
@ -578,7 +578,7 @@ read_pair(pic_state *pic, struct pic_port *port, int c)
closing: closing:
if ((c = skip(port, ' ')) != tCLOSE) { 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; goto closing;
} }
read_error(pic, "unmatched parenthesis"); read_error(pic, "unmatched parenthesis");
@ -588,7 +588,7 @@ read_pair(pic_state *pic, struct pic_port *port, int c)
else { else {
car = read_nullable(pic, port, c); car = read_nullable(pic, port, c);
if (pic_undef_p(car)) { if (pic_invalid_p(car)) {
goto retry; goto retry;
} }
@ -742,7 +742,7 @@ read(pic_state *pic, struct pic_port *port, int c)
retry: retry:
val = read_nullable(pic, port, c); val = read_nullable(pic, port, c);
if (pic_undef_p(val)) { if (pic_invalid_p(val)) {
c = next(port); c = next(port);
goto retry; goto retry;
} }
@ -840,7 +840,7 @@ pic_read(pic_state *pic, struct pic_port *port)
val = read_nullable(pic, port, c); val = read_nullable(pic, port, c);
if (pic_undef_p(val)) { if (pic_invalid_p(val)) {
c = next(port); c = next(port);
goto retry; goto retry;
} }

View File

@ -223,7 +223,7 @@ pic_open(int argc, char *argv[], char **envp, pic_allocf allocf)
pic->lib = NULL; pic->lib = NULL;
/* raised error object */ /* raised error object */
pic->err = pic_undef_value(); pic->err = pic_invalid_value();
/* standard ports */ /* standard ports */
pic->xSTDIN = NULL; pic->xSTDIN = NULL;
@ -402,7 +402,7 @@ pic_close(pic_state *pic)
pic->ci = pic->cibase; pic->ci = pic->cibase;
pic->xp = pic->xpbase; pic->xp = pic->xpbase;
pic->arena_idx = 0; pic->arena_idx = 0;
pic->err = pic_undef_value(); pic->err = pic_invalid_value();
pic->globals = NULL; pic->globals = NULL;
pic->macros = NULL; pic->macros = NULL;
xh_clear(&pic->syms); xh_clear(&pic->syms);