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