introduce pic_invalid_value
This commit is contained in:
parent
df56a8c154
commit
2c9a19acf5
|
@ -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: ");
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
{
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue