From 2c9a19acf54fd89c348b6ca66f53e28bf42b368e Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Tue, 9 Jun 2015 16:02:23 +0900 Subject: [PATCH 1/4] 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); From 084d39cd9ec851d6dd8708dfc3b45a5351b00189 Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Tue, 9 Jun 2015 16:19:57 +0900 Subject: [PATCH 2/4] let undefined be public API --- extlib/benz/read.c | 17 ++++++++++++++++- extlib/benz/state.c | 2 ++ extlib/benz/undef.c | 21 +++++++++++++++++++++ extlib/benz/write.c | 2 +- 4 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 extlib/benz/undef.c diff --git a/extlib/benz/read.c b/extlib/benz/read.c index dc7a28a5..a43b28de 100644 --- a/extlib/benz/read.c +++ b/extlib/benz/read.c @@ -560,6 +560,21 @@ read_blob(pic_state *pic, struct pic_port *port, int c) return pic_obj_value(blob); } +static pic_value +read_undef_or_blob(pic_state *pic, struct pic_port *port, int c) +{ + if ((c = peek(port)) == 'n') { + if (! expect(port, "ndefined")) { + read_error(pic, "unexpected character while reading #undefined"); + } + return pic_undef_value(); + } + if (! isdigit(c)) { + read_error(pic, "expect #undefined or #u8(...), but illegal character given"); + } + return read_blob(pic, port, 'u'); +} + static pic_value read_pair(pic_state *pic, struct pic_port *port, int c) { @@ -786,7 +801,7 @@ reader_table_init(struct pic_reader *reader) reader->dispatch['f'] = read_false; reader->dispatch['\\'] = read_char; reader->dispatch['('] = read_vector; - reader->dispatch['u'] = read_blob; + reader->dispatch['u'] = read_undef_or_blob; reader->dispatch['.'] = read_eval; /* read labels */ diff --git a/extlib/benz/state.c b/extlib/benz/state.c index aa60da35..a555dc34 100644 --- a/extlib/benz/state.c +++ b/extlib/benz/state.c @@ -10,6 +10,7 @@ pic_add_feature(pic_state *pic, const char *feature) pic_push(pic, pic_obj_value(pic_intern_cstr(pic, feature)), pic->features); } +void pic_init_undef(pic_state *); void pic_init_bool(pic_state *); void pic_init_pair(pic_state *); void pic_init_port(pic_state *); @@ -107,6 +108,7 @@ pic_init_core(pic_state *pic) pic_define_syntactic_keyword(pic, pic->lib->env, pic->sBEGIN, pic->rBEGIN); pic_define_syntactic_keyword(pic, pic->lib->env, pic->sDEFINE_SYNTAX, pic->rDEFINE_SYNTAX); + pic_init_undef(pic); DONE; pic_init_bool(pic); DONE; pic_init_pair(pic); DONE; pic_init_port(pic); DONE; diff --git a/extlib/benz/undef.c b/extlib/benz/undef.c new file mode 100644 index 00000000..9e709c0e --- /dev/null +++ b/extlib/benz/undef.c @@ -0,0 +1,21 @@ +/** + * See Copyright Notice in picrin.h + */ + +#include "picrin.h" + +static pic_value +pic_undef_undefined_p(pic_state *pic) +{ + pic_value v; + + pic_get_args(pic, "o", &v); + + return pic_undef_p(v) ? pic_true_value() : pic_false_value(); +} + +void +pic_init_undef(pic_state *pic) +{ + pic_defun(pic, "undefined?", pic_undef_undefined_p); +} diff --git a/extlib/benz/write.c b/extlib/benz/write.c index d2c2a807..32aa3e8c 100644 --- a/extlib/benz/write.c +++ b/extlib/benz/write.c @@ -220,7 +220,7 @@ write_core(struct writer_control *p, pic_value obj) switch (pic_type(obj)) { case PIC_TT_UNDEF: - xfprintf(file, "#"); + xfprintf(file, "#undefined"); break; case PIC_TT_NIL: xfprintf(file, "()"); From 0cafbfdb0c6b4798b859097674c53b3d7570f1b7 Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Tue, 9 Jun 2015 16:21:15 +0900 Subject: [PATCH 3/4] update picrin/base.scm --- piclib/picrin/base.scm | 2 ++ 1 file changed, 2 insertions(+) diff --git a/piclib/picrin/base.scm b/piclib/picrin/base.scm index baf00023..2aa6a42b 100644 --- a/piclib/picrin/base.scm +++ b/piclib/picrin/base.scm @@ -37,6 +37,8 @@ eqv? equal?) + (export undefined?) + (export boolean? boolean=? not) From 5185a73cd2fddd99cb9d3dd725d1b43e2d95c28f Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Tue, 9 Jun 2015 16:34:45 +0900 Subject: [PATCH 4/4] replace none with undef --- contrib/05.r7rs/src/file.c | 2 +- contrib/05.r7rs/src/load.c | 2 +- contrib/05.r7rs/src/mutable-string.c | 6 +++--- extlib/benz/blob.c | 6 +++--- extlib/benz/codegen.c | 20 +++++++------------- extlib/benz/cont.c | 4 ++-- extlib/benz/dict.c | 8 ++++---- extlib/benz/include/picrin/config.h | 7 ------- extlib/benz/include/picrin/irep.h | 4 ++++ extlib/benz/include/picrin/value.h | 11 ----------- extlib/benz/lib.c | 10 +++++----- extlib/benz/macro.c | 4 ++-- extlib/benz/pair.c | 10 +++++----- extlib/benz/port.c | 14 +++++++------- extlib/benz/read.c | 2 +- extlib/benz/record.c | 2 +- extlib/benz/string.c | 2 +- extlib/benz/var.c | 2 +- extlib/benz/vector.c | 12 ++++++------ extlib/benz/vm.c | 10 +++++++--- extlib/benz/write.c | 8 ++++---- 21 files changed, 65 insertions(+), 81 deletions(-) diff --git a/contrib/05.r7rs/src/file.c b/contrib/05.r7rs/src/file.c index 4147bd84..ce9cb1b2 100644 --- a/contrib/05.r7rs/src/file.c +++ b/contrib/05.r7rs/src/file.c @@ -104,7 +104,7 @@ pic_file_delete(pic_state *pic) if (remove(fname) != 0) { file_error(pic, "file cannot be deleted"); } - return pic_none_value(); + return pic_undef_value(); } void diff --git a/contrib/05.r7rs/src/load.c b/contrib/05.r7rs/src/load.c index 5efb71c7..c887a1b2 100644 --- a/contrib/05.r7rs/src/load.c +++ b/contrib/05.r7rs/src/load.c @@ -35,7 +35,7 @@ pic_load_load(pic_state *pic) pic_load(pic, fn); - return pic_none_value(); + return pic_undef_value(); } void diff --git a/contrib/05.r7rs/src/mutable-string.c b/contrib/05.r7rs/src/mutable-string.c index 6937b0f6..85db9be0 100644 --- a/contrib/05.r7rs/src/mutable-string.c +++ b/contrib/05.r7rs/src/mutable-string.c @@ -30,7 +30,7 @@ pic_str_string_set(pic_state *pic) pic_get_args(pic, "sic", &str, &k, &c); pic_str_set(pic, str, k, c); - return pic_none_value(); + return pic_undef_value(); } static pic_value @@ -54,7 +54,7 @@ pic_str_string_copy_ip(pic_state *pic) while (start < end) { pic_str_set(pic, to, at++, pic_str_ref(pic, from, start++)); } - return pic_none_value(); + return pic_undef_value(); } static pic_value @@ -76,7 +76,7 @@ pic_str_string_fill_ip(pic_state *pic) while (start < end) { pic_str_set(pic, str, start++, c); } - return pic_none_value(); + return pic_undef_value(); } void diff --git a/extlib/benz/blob.c b/extlib/benz/blob.c index 59791ee9..c2775ea3 100644 --- a/extlib/benz/blob.c +++ b/extlib/benz/blob.c @@ -105,7 +105,7 @@ pic_blob_bytevector_u8_set(pic_state *pic) pic_errorf(pic, "byte out of range"); bv->data[k] = (unsigned char)v; - return pic_none_value(); + return pic_undef_value(); } static pic_value @@ -130,14 +130,14 @@ pic_blob_bytevector_copy_i(pic_state *pic) while (start < end) { to->data[--at] = from->data[--end]; } - return pic_none_value(); + return pic_undef_value(); } while (start < end) { to->data[at++] = from->data[start++]; } - return pic_none_value(); + return pic_undef_value(); } static pic_value diff --git a/extlib/benz/codegen.c b/extlib/benz/codegen.c index ff53f12b..79d4126c 100644 --- a/extlib/benz/codegen.c +++ b/extlib/benz/codegen.c @@ -4,12 +4,6 @@ #include "picrin.h" -#if PIC_NONE_IS_FALSE -# define OP_PUSHNONE OP_PUSHFALSE -#else -# error enable PIC_NONE_IS_FALSE -#endif - typedef xvect_t(pic_sym *) xvect; #define xv_push_sym(v, x) xv_push(pic_sym *, (v), (x)) @@ -428,7 +422,7 @@ analyze_if(analyze_state *state, pic_value obj, bool tailpos) pic_state *pic = state->pic; pic_value cond, if_true, if_false; - if_false = pic_none_value(); + if_false = pic_undef_value(); switch (pic_length(pic, obj)) { default: pic_errorf(pic, "syntax error"); @@ -456,7 +450,7 @@ analyze_begin(analyze_state *state, pic_value obj, bool tailpos) switch (pic_length(pic, obj)) { case 1: - return analyze(state, pic_none_value(), tailpos); + return analyze(state, pic_undef_value(), tailpos); case 2: return analyze(state, pic_list_ref(pic, obj, 1), tailpos); default: @@ -965,7 +959,7 @@ create_activation(codegen_state *state) emit_i(state, OP_LREF, (int)n); } else { /* otherwise, just extend the stack */ - emit_n(state, OP_PUSHNONE); + emit_n(state, OP_PUSHUNDEF); } } @@ -1158,7 +1152,7 @@ codegen(codegen_state *state, pic_value obj) type = pic_sym_ptr(pic_list_ref(pic, var, 0)); if (type == pic->sGREF) { emit_i(state, OP_GSET, index_symbol(state, pic_sym_ptr(pic_list_ref(pic, var, 1)))); - emit_n(state, OP_PUSHNONE); + emit_n(state, OP_PUSHUNDEF); return; } else if (type == pic->sCREF) { @@ -1168,7 +1162,7 @@ codegen(codegen_state *state, pic_value obj) depth = pic_int(pic_list_ref(pic, var, 1)); name = pic_sym_ptr(pic_list_ref(pic, var, 2)); emit_r(state, OP_CSET, depth, index_capture(state, name, depth)); - emit_n(state, OP_PUSHNONE); + emit_n(state, OP_PUSHUNDEF); return; } else if (type == pic->sLREF) { @@ -1178,11 +1172,11 @@ codegen(codegen_state *state, pic_value obj) name = pic_sym_ptr(pic_list_ref(pic, var, 1)); if ((i = index_capture(state, name, 0)) != -1) { emit_i(state, OP_LSET, i + (int)xv_size(cxt->args) + (int)xv_size(cxt->locals) + 1); - emit_n(state, OP_PUSHNONE); + emit_n(state, OP_PUSHUNDEF); return; } emit_i(state, OP_LSET, index_local(state, name)); - emit_n(state, OP_PUSHNONE); + emit_n(state, OP_PUSHUNDEF); return; } } diff --git a/extlib/benz/cont.c b/extlib/benz/cont.c index 72a9b2cb..4b213f52 100644 --- a/extlib/benz/cont.c +++ b/extlib/benz/cont.c @@ -197,7 +197,7 @@ pic_values_by_array(pic_state *pic, size_t argc, pic_value *argv) } pic->ci->retc = (int)argc; - return argc == 0 ? pic_none_value() : pic->sp[0]; + return argc == 0 ? pic_undef_value() : pic->sp[0]; } pic_value @@ -212,7 +212,7 @@ pic_values_by_list(pic_state *pic, pic_value list) } pic->ci->retc = i; - return pic_nil_p(list) ? pic_none_value() : pic->sp[0]; + return pic_nil_p(list) ? pic_undef_value() : pic->sp[0]; } size_t diff --git a/extlib/benz/dict.c b/extlib/benz/dict.c index b802fe06..8a3d0ce7 100644 --- a/extlib/benz/dict.c +++ b/extlib/benz/dict.c @@ -107,7 +107,7 @@ pic_dict_dictionary_ref(pic_state *pic) if (pic_dict_has(pic, dict, key)) { return pic_values2(pic, pic_dict_ref(pic, dict, key), pic_true_value()); } else { - return pic_values2(pic, pic_none_value(), pic_false_value()); + return pic_values2(pic, pic_undef_value(), pic_false_value()); } } @@ -122,7 +122,7 @@ pic_dict_dictionary_set(pic_state *pic) pic_dict_set(pic, dict, key, val); - return pic_none_value(); + return pic_undef_value(); } static pic_value @@ -135,7 +135,7 @@ pic_dict_dictionary_del(pic_state *pic) pic_dict_del(pic, dict, key); - return pic_none_value(); + return pic_undef_value(); } static pic_value @@ -238,7 +238,7 @@ pic_dict_dictionary_for_each(pic_state *pic) pic_free(pic, it); - return pic_none_value(); + return pic_undef_value(); } static pic_value diff --git a/extlib/benz/include/picrin/config.h b/extlib/benz/include/picrin/config.h index 4b98679d..b30bc398 100644 --- a/extlib/benz/include/picrin/config.h +++ b/extlib/benz/include/picrin/config.h @@ -17,9 +17,6 @@ /** no dependency on libc */ /* #define PIC_ENABLE_LIBC 1 */ -/** treat false value as none */ -/* #define PIC_NONE_IS_FALSE 1 */ - /** custom setjmp/longjmp */ /* #define PIC_JMPBUF jmp_buf */ /* #define PIC_SETJMP(pic, buf) setjmp(buf) */ @@ -96,10 +93,6 @@ # error cannot disable float support when nan boxing is on #endif -#ifndef PIC_NONE_IS_FALSE -# define PIC_NONE_IS_FALSE 1 -#endif - #ifndef PIC_JMPBUF # include # define PIC_JMPBUF jmp_buf diff --git a/extlib/benz/include/picrin/irep.h b/extlib/benz/include/picrin/irep.h index 213d0456..319d1b31 100644 --- a/extlib/benz/include/picrin/irep.h +++ b/extlib/benz/include/picrin/irep.h @@ -12,6 +12,7 @@ extern "C" { enum pic_opcode { OP_NOP, OP_POP, + OP_PUSHUNDEF, OP_PUSHNIL, OP_PUSHTRUE, OP_PUSHFALSE, @@ -93,6 +94,9 @@ pic_dump_code(pic_code c) case OP_POP: puts("OP_POP"); break; + case OP_PUSHUNDEF: + puts("OP_PUSHUNDEF"); + break; case OP_PUSHNIL: puts("OP_PUSHNIL"); break; diff --git a/extlib/benz/include/picrin/value.h b/extlib/benz/include/picrin/value.h index 9790926b..c69e09b0 100644 --- a/extlib/benz/include/picrin/value.h +++ b/extlib/benz/include/picrin/value.h @@ -242,7 +242,6 @@ PIC_INLINE pic_value pic_float_value(double); PIC_INLINE pic_value pic_int_value(int); PIC_INLINE pic_value pic_size_value(size_t); PIC_INLINE pic_value pic_char_value(char c); -PIC_INLINE pic_value pic_none_value(); PIC_INLINE bool pic_eq_p(pic_value, pic_value); PIC_INLINE bool pic_eqv_p(pic_value, pic_value); @@ -517,16 +516,6 @@ pic_invalid_value() return v; } -PIC_INLINE pic_value -pic_none_value() -{ -#if PIC_NONE_IS_FALSE - return pic_false_value(); -#else -# error enable PIC_NONE_IS_FALSE -#endif -} - #if PIC_NAN_BOXING || PIC_WORD_BOXING PIC_INLINE bool diff --git a/extlib/benz/lib.c b/extlib/benz/lib.c index 8eff0bb7..6ece6a1f 100644 --- a/extlib/benz/lib.c +++ b/extlib/benz/lib.c @@ -246,7 +246,7 @@ pic_lib_condexpand(pic_state *pic) } } - return pic_none_value(); + return pic_undef_value(); } static pic_value @@ -261,7 +261,7 @@ pic_lib_import(pic_state *pic) import(pic, argv[i]); } - return pic_none_value(); + return pic_undef_value(); } static pic_value @@ -276,7 +276,7 @@ pic_lib_export(pic_state *pic) export(pic, argv[i]); } - return pic_none_value(); + return pic_undef_value(); } static pic_value @@ -306,7 +306,7 @@ pic_lib_define_library(pic_state *pic) pic_raise(pic, pic->err); } - return pic_none_value(); + return pic_undef_value(); } static pic_value @@ -318,7 +318,7 @@ pic_lib_in_library(pic_state *pic) pic_in_library(pic, spec); - return pic_none_value(); + return pic_undef_value(); } void diff --git a/extlib/benz/macro.c b/extlib/benz/macro.c index ed7625fd..fbda5faf 100644 --- a/extlib/benz/macro.c +++ b/extlib/benz/macro.c @@ -105,7 +105,7 @@ macroexpand_list(pic_state *pic, pic_value obj, struct pic_env *env) static pic_value macroexpand_defer(pic_state *pic, pic_value expr, struct pic_env *env) { - pic_value skel = pic_list1(pic, pic_none_value()); /* (#) */ + pic_value skel = pic_list1(pic, pic_invalid_value()); /* (#) */ pic_push(pic, pic_cons(pic, expr, skel), env->defer); @@ -238,7 +238,7 @@ macroexpand_defsyntax(pic_state *pic, pic_value expr, struct pic_env *env) define_macro(pic, rename, pic_proc_ptr(val)); - return pic_none_value(); + return pic_undef_value(); } static pic_value diff --git a/extlib/benz/pair.c b/extlib/benz/pair.c index c0b031af..b3da3b6d 100644 --- a/extlib/benz/pair.c +++ b/extlib/benz/pair.c @@ -492,7 +492,7 @@ pic_pair_set_car(pic_state *pic) pic_set_car(pic, v, w); - return pic_none_value(); + return pic_undef_value(); } static pic_value @@ -504,7 +504,7 @@ pic_pair_set_cdr(pic_state *pic) pic_set_cdr(pic, v, w); - return pic_none_value(); + return pic_undef_value(); } static pic_value @@ -531,7 +531,7 @@ static pic_value pic_pair_make_list(pic_state *pic) { size_t i; - pic_value fill = pic_none_value(); + pic_value fill = pic_undef_value(); pic_get_args(pic, "k|o", &i, &fill); @@ -621,7 +621,7 @@ pic_pair_list_set(pic_state *pic) pic_list_set(pic, list, i, obj); - return pic_none_value(); + return pic_undef_value(); } static pic_value @@ -692,7 +692,7 @@ pic_pair_for_each(pic_state *pic) pic_apply(pic, proc, pic_reverse(pic, arg)); } while (1); - return pic_none_value(); + return pic_undef_value(); } static pic_value diff --git a/extlib/benz/port.c b/extlib/benz/port.c index ab5c39d8..5b04f89b 100644 --- a/extlib/benz/port.c +++ b/extlib/benz/port.c @@ -327,7 +327,7 @@ pic_port_close_port(pic_state *pic) pic_close_port(pic, port); - return pic_none_value(); + return pic_undef_value(); } #define assert_port_profile(port, flgs, stat, caller) do { \ @@ -675,7 +675,7 @@ pic_port_newline(pic_state *pic) assert_port_profile(port, PIC_PORT_OUT | PIC_PORT_TEXT, PIC_PORT_OPEN, "newline"); xfputs("\n", port->file); - return pic_none_value(); + return pic_undef_value(); } static pic_value @@ -689,7 +689,7 @@ pic_port_write_char(pic_state *pic) assert_port_profile(port, PIC_PORT_OUT | PIC_PORT_TEXT, PIC_PORT_OPEN, "write-char"); xfputc(c, port->file); - return pic_none_value(); + return pic_undef_value(); } static pic_value @@ -714,7 +714,7 @@ pic_port_write_string(pic_state *pic) for (i = start; i < end && str[i] != '\0'; ++i) { xfputc(str[i], port->file); } - return pic_none_value(); + return pic_undef_value(); } static pic_value @@ -728,7 +728,7 @@ pic_port_write_byte(pic_state *pic) assert_port_profile(port, PIC_PORT_OUT | PIC_PORT_BINARY, PIC_PORT_OPEN, "write-u8"); xfputc(i, port->file); - return pic_none_value(); + return pic_undef_value(); } static pic_value @@ -754,7 +754,7 @@ pic_port_write_blob(pic_state *pic) for (i = start; i < end; ++i) { xfputc(blob->data[i], port->file); } - return pic_none_value(); + return pic_undef_value(); } static pic_value @@ -767,7 +767,7 @@ pic_port_flush(pic_state *pic) assert_port_profile(port, PIC_PORT_OUT, PIC_PORT_OPEN, "flush-output-port"); xfflush(port->file); - return pic_none_value(); + return pic_undef_value(); } void diff --git a/extlib/benz/read.c b/extlib/benz/read.c index a43b28de..8320af38 100644 --- a/extlib/benz/read.c +++ b/extlib/benz/read.c @@ -633,7 +633,7 @@ read_label_set(pic_state *pic, struct pic_port *port, int i) { pic_value tmp; - val = pic_cons(pic, pic_none_value(), pic_none_value()); + val = pic_cons(pic, pic_undef_value(), pic_undef_value()); xh_put_int(&pic->reader->labels, i, &val); diff --git a/extlib/benz/record.c b/extlib/benz/record.c index dc35e223..55c98f14 100644 --- a/extlib/benz/record.c +++ b/extlib/benz/record.c @@ -96,7 +96,7 @@ pic_record_record_set(pic_state *pic) pic_record_set(pic, rec, slot, val); - return pic_none_value(); + return pic_undef_value(); } void diff --git a/extlib/benz/string.c b/extlib/benz/string.c index ee1f3527..1e1e083c 100644 --- a/extlib/benz/string.c +++ b/extlib/benz/string.c @@ -646,7 +646,7 @@ pic_str_string_for_each(pic_state *pic) pic_apply(pic, proc, vals); } - return pic_none_value(); + return pic_undef_value(); } static pic_value diff --git a/extlib/benz/var.c b/extlib/benz/var.c index 08e1fb89..95da6b16 100644 --- a/extlib/benz/var.c +++ b/extlib/benz/var.c @@ -43,7 +43,7 @@ var_set(pic_state *pic, struct pic_proc *var, pic_value val) pic_dict_set(pic, dict, id, val); - return pic_none_value(); + return pic_undef_value(); } static pic_value diff --git a/extlib/benz/vector.c b/extlib/benz/vector.c index 08d2f72a..c3b914c1 100644 --- a/extlib/benz/vector.c +++ b/extlib/benz/vector.c @@ -14,7 +14,7 @@ pic_make_vec(pic_state *pic, size_t len) vec->len = len; vec->data = (pic_value *)pic_malloc(pic, sizeof(pic_value) * len); for (i = 0; i < len; ++i) { - vec->data[i] = pic_none_value(); + vec->data[i] = pic_undef_value(); } return vec; } @@ -119,7 +119,7 @@ pic_vec_vector_set(pic_state *pic) pic_errorf(pic, "vector-set!: index out of range"); } v->data[k] = o; - return pic_none_value(); + return pic_undef_value(); } static pic_value @@ -144,14 +144,14 @@ pic_vec_vector_copy_i(pic_state *pic) while (start < end) { to->data[--at] = from->data[--end]; } - return pic_none_value(); + return pic_undef_value(); } while (start < end) { to->data[at++] = from->data[start++]; } - return pic_none_value(); + return pic_undef_value(); } static pic_value @@ -231,7 +231,7 @@ pic_vec_vector_fill_i(pic_state *pic) vec->data[start++] = obj; } - return pic_none_value(); + return pic_undef_value(); } static pic_value @@ -292,7 +292,7 @@ pic_vec_vector_for_each(pic_state *pic) pic_apply(pic, proc, vals); } - return pic_none_value(); + return pic_undef_value(); } static pic_value diff --git a/extlib/benz/vm.c b/extlib/benz/vm.c index 17bf655f..825b63fd 100644 --- a/extlib/benz/vm.c +++ b/extlib/benz/vm.c @@ -682,8 +682,8 @@ pic_apply(pic_state *pic, struct pic_proc *proc, pic_value args) #if PIC_DIRECT_THREADED_VM static void *oplabels[] = { - &&L_OP_NOP, &&L_OP_POP, &&L_OP_PUSHNIL, &&L_OP_PUSHTRUE, &&L_OP_PUSHFALSE, - &&L_OP_PUSHINT, &&L_OP_PUSHCHAR, &&L_OP_PUSHCONST, + &&L_OP_NOP, &&L_OP_POP, &&L_OP_PUSHUNDEF, &&L_OP_PUSHNIL, &&L_OP_PUSHTRUE, + &&L_OP_PUSHFALSE, &&L_OP_PUSHINT, &&L_OP_PUSHCHAR, &&L_OP_PUSHCONST, &&L_OP_GREF, &&L_OP_GSET, &&L_OP_LREF, &&L_OP_LSET, &&L_OP_CREF, &&L_OP_CSET, &&L_OP_JMP, &&L_OP_JMPIF, &&L_OP_NOT, &&L_OP_CALL, &&L_OP_TAILCALL, &&L_OP_RET, &&L_OP_LAMBDA, &&L_OP_CONS, &&L_OP_CAR, &&L_OP_CDR, &&L_OP_NILP, @@ -729,6 +729,10 @@ pic_apply(pic_state *pic, struct pic_proc *proc, pic_value args) (void)(POP()); NEXT; } + CASE(OP_PUSHUNDEF) { + PUSH(pic_undef_value()); + NEXT; + } CASE(OP_PUSHNIL) { PUSH(pic_nil_value()); NEXT; @@ -1197,7 +1201,7 @@ pic_apply_trampoline(pic_state *pic, struct pic_proc *proc, pic_value args) ci->retc = (int)pic_length(pic, args); if (ci->retc == 0) { - return pic_none_value(); + return pic_undef_value(); } else { return pic_car(pic, args); } diff --git a/extlib/benz/write.c b/extlib/benz/write.c index 32aa3e8c..73ee11f5 100644 --- a/extlib/benz/write.c +++ b/extlib/benz/write.c @@ -449,7 +449,7 @@ pic_write_write(pic_state *pic) pic_get_args(pic, "o|p", &v, &port); write(pic, v, port->file); - return pic_none_value(); + return pic_undef_value(); } static pic_value @@ -460,7 +460,7 @@ pic_write_write_simple(pic_state *pic) pic_get_args(pic, "o|p", &v, &port); write_simple(pic, v, port->file); - return pic_none_value(); + return pic_undef_value(); } static pic_value @@ -471,7 +471,7 @@ pic_write_write_shared(pic_state *pic) pic_get_args(pic, "o|p", &v, &port); write_shared(pic, v, port->file); - return pic_none_value(); + return pic_undef_value(); } static pic_value @@ -482,7 +482,7 @@ pic_write_display(pic_state *pic) pic_get_args(pic, "o|p", &v, &port); display(pic, v, port->file); - return pic_none_value(); + return pic_undef_value(); } void