Merge branch 'introduce-undef'
This commit is contained in:
commit
741d771367
|
@ -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
|
||||
|
|
|
@ -35,7 +35,7 @@ pic_load_load(pic_state *pic)
|
|||
|
||||
pic_load(pic, fn);
|
||||
|
||||
return pic_none_value();
|
||||
return pic_undef_value();
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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: ");
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 <setjmp.h>
|
||||
# define PIC_JMPBUF jmp_buf
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
@ -238,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);
|
||||
|
@ -255,6 +258,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 +299,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:
|
||||
|
@ -501,13 +508,12 @@ pic_undef_value()
|
|||
}
|
||||
|
||||
PIC_INLINE pic_value
|
||||
pic_none_value()
|
||||
pic_invalid_value()
|
||||
{
|
||||
#if PIC_NONE_IS_FALSE
|
||||
return pic_false_value();
|
||||
#else
|
||||
# error enable PIC_NONE_IS_FALSE
|
||||
#endif
|
||||
pic_value v;
|
||||
|
||||
pic_init_value(v, PIC_VTYPE_INVALID);
|
||||
return v;
|
||||
}
|
||||
|
||||
#if PIC_NAN_BOXING || PIC_WORD_BOXING
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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()); /* (#<none>) */
|
||||
pic_value skel = pic_list1(pic, pic_invalid_value()); /* (#<invalid>) */
|
||||
|
||||
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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -578,7 +593,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 +603,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;
|
||||
}
|
||||
|
||||
|
@ -618,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);
|
||||
|
||||
|
@ -742,7 +757,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;
|
||||
}
|
||||
|
@ -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 */
|
||||
|
@ -840,7 +855,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;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
@ -223,7 +225,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 +404,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);
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
}
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -220,7 +220,7 @@ write_core(struct writer_control *p, pic_value obj)
|
|||
|
||||
switch (pic_type(obj)) {
|
||||
case PIC_TT_UNDEF:
|
||||
xfprintf(file, "#<undef>");
|
||||
xfprintf(file, "#undefined");
|
||||
break;
|
||||
case PIC_TT_NIL:
|
||||
xfprintf(file, "()");
|
||||
|
@ -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
|
||||
|
|
|
@ -37,6 +37,8 @@
|
|||
eqv?
|
||||
equal?)
|
||||
|
||||
(export undefined?)
|
||||
|
||||
(export boolean?
|
||||
boolean=?
|
||||
not)
|
||||
|
|
Loading…
Reference in New Issue