let undefined be public API

This commit is contained in:
Yuichi Nishiwaki 2015-06-09 16:19:57 +09:00
parent 2c9a19acf5
commit 084d39cd9e
4 changed files with 40 additions and 2 deletions

View File

@ -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 */

View File

@ -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;

21
extlib/benz/undef.c Normal file
View File

@ -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);
}

View File

@ -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, "()");