Merge branch 'boolean-alternative-notation'
This commit is contained in:
commit
10032ea96a
|
@ -32,7 +32,8 @@ struct pic_jmpbuf {
|
||||||
void pic_push_try(pic_state *);
|
void pic_push_try(pic_state *);
|
||||||
void pic_pop_try(pic_state *);
|
void pic_pop_try(pic_state *);
|
||||||
|
|
||||||
noreturn void pic_throw(pic_state *, struct pic_error *);
|
noreturn void pic_throw(pic_state *, short, const char *, pic_value);
|
||||||
|
noreturn void pic_throw_error(pic_state *, struct pic_error *);
|
||||||
|
|
||||||
struct pic_error {
|
struct pic_error {
|
||||||
PIC_OBJECT_HEADER
|
PIC_OBJECT_HEADER
|
||||||
|
|
28
src/error.c
28
src/error.c
|
@ -87,7 +87,7 @@ error_new(pic_state *pic, short type, pic_str *msg, pic_value irrs)
|
||||||
}
|
}
|
||||||
|
|
||||||
noreturn void
|
noreturn void
|
||||||
pic_throw(pic_state *pic, struct pic_error *e)
|
pic_throw_error(pic_state *pic, struct pic_error *e)
|
||||||
{
|
{
|
||||||
pic->err = e;
|
pic->err = e;
|
||||||
if (! pic->jmp) {
|
if (! pic->jmp) {
|
||||||
|
@ -97,6 +97,16 @@ pic_throw(pic_state *pic, struct pic_error *e)
|
||||||
longjmp(*pic->jmp, 1);
|
longjmp(*pic->jmp, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
noreturn void
|
||||||
|
pic_throw(pic_state *pic, short type, const char *msg, pic_value irrs)
|
||||||
|
{
|
||||||
|
struct pic_error *e;
|
||||||
|
|
||||||
|
e = error_new(pic, type, pic_str_new_cstr(pic, msg), irrs);
|
||||||
|
|
||||||
|
pic_throw_error(pic, e);
|
||||||
|
}
|
||||||
|
|
||||||
const char *
|
const char *
|
||||||
pic_errmsg(pic_state *pic)
|
pic_errmsg(pic_state *pic)
|
||||||
{
|
{
|
||||||
|
@ -109,13 +119,17 @@ void
|
||||||
pic_errorf(pic_state *pic, const char *fmt, ...)
|
pic_errorf(pic_state *pic, const char *fmt, ...)
|
||||||
{
|
{
|
||||||
va_list ap;
|
va_list ap;
|
||||||
pic_value err_line;
|
pic_value err_line, irrs;
|
||||||
|
const char *msg;
|
||||||
|
|
||||||
va_start(ap, fmt);
|
va_start(ap, fmt);
|
||||||
err_line = pic_vformat(pic, fmt, ap);
|
err_line = pic_vformat(pic, fmt, ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
|
|
||||||
pic_throw(pic, error_new(pic, PIC_ERROR_OTHER, pic_str_ptr(pic_car(pic, err_line)), pic_cdr(pic, err_line)));
|
msg = pic_str_cstr(pic_str_ptr(pic_car(pic, err_line)));
|
||||||
|
irrs = pic_cdr(pic, err_line);
|
||||||
|
|
||||||
|
pic_throw(pic, PIC_ERROR_OTHER, msg, irrs);
|
||||||
}
|
}
|
||||||
|
|
||||||
static pic_value
|
static pic_value
|
||||||
|
@ -146,19 +160,19 @@ pic_error_raise(pic_state *pic)
|
||||||
|
|
||||||
pic_get_args(pic, "o", &v);
|
pic_get_args(pic, "o", &v);
|
||||||
|
|
||||||
pic_throw(pic, error_new(pic, PIC_ERROR_RAISED, pic_str_new_cstr(pic, "object is raised"), pic_list1(pic, v)));
|
pic_throw(pic, PIC_ERROR_RAISED, "object is raised", pic_list1(pic, v));
|
||||||
}
|
}
|
||||||
|
|
||||||
noreturn static pic_value
|
noreturn static pic_value
|
||||||
pic_error_error(pic_state *pic)
|
pic_error_error(pic_state *pic)
|
||||||
{
|
{
|
||||||
pic_str *str;
|
const char *str;
|
||||||
size_t argc;
|
size_t argc;
|
||||||
pic_value *argv;
|
pic_value *argv;
|
||||||
|
|
||||||
pic_get_args(pic, "s*", &str, &argc, &argv);
|
pic_get_args(pic, "z*", &str, &argc, &argv);
|
||||||
|
|
||||||
pic_throw(pic, error_new(pic, PIC_ERROR_OTHER, str, pic_list_by_array(pic, argc, argv)));
|
pic_throw(pic, PIC_ERROR_OTHER, str, pic_list_by_array(pic, argc, argv));
|
||||||
}
|
}
|
||||||
|
|
||||||
static pic_value
|
static pic_value
|
||||||
|
|
|
@ -246,7 +246,7 @@ macroexpand_deflibrary(pic_state *pic, pic_value expr)
|
||||||
pic_catch {
|
pic_catch {
|
||||||
/* restores pic->lib even if an error occurs */
|
/* restores pic->lib even if an error occurs */
|
||||||
pic_in_library(pic, prev->name);
|
pic_in_library(pic, prev->name);
|
||||||
pic_throw(pic, pic->err);
|
pic_throw_error(pic, pic->err);
|
||||||
}
|
}
|
||||||
|
|
||||||
return pic_none_value();
|
return pic_none_value();
|
||||||
|
|
30
src/read.c
30
src/read.c
|
@ -20,7 +20,7 @@ static pic_value read_nullable(pic_state *pic, struct pic_port *port, char c);
|
||||||
static noreturn void
|
static noreturn void
|
||||||
read_error(pic_state *pic, const char *msg)
|
read_error(pic_state *pic, const char *msg)
|
||||||
{
|
{
|
||||||
pic_error(pic, msg);
|
pic_throw(pic, PIC_ERROR_READ, msg, pic_nil_value());
|
||||||
}
|
}
|
||||||
|
|
||||||
static char
|
static char
|
||||||
|
@ -48,6 +48,19 @@ peek(struct pic_port *port)
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
expect(struct pic_port *port, const char *str)
|
||||||
|
{
|
||||||
|
char c;
|
||||||
|
|
||||||
|
while ((c = *str++) != 0) {
|
||||||
|
if (c != next(port))
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
isdelim(char c)
|
isdelim(char c)
|
||||||
{
|
{
|
||||||
|
@ -250,13 +263,26 @@ read_boolean(pic_state *pic, struct pic_port *port, char c)
|
||||||
UNUSED(pic);
|
UNUSED(pic);
|
||||||
UNUSED(port);
|
UNUSED(port);
|
||||||
|
|
||||||
/* TODO: support #true and #false */
|
if (! isdelim(peek(port))) {
|
||||||
|
if (c == 't') {
|
||||||
|
if (! expect(port, "rue")) {
|
||||||
|
goto fail;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (! expect(port, "alse")) {
|
||||||
|
goto fail;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (c == 't') {
|
if (c == 't') {
|
||||||
return pic_true_value();
|
return pic_true_value();
|
||||||
} else {
|
} else {
|
||||||
return pic_false_value();
|
return pic_false_value();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fail:
|
||||||
|
read_error(pic, "illegal character during reading boolean literal");
|
||||||
}
|
}
|
||||||
|
|
||||||
static pic_value
|
static pic_value
|
||||||
|
|
Loading…
Reference in New Issue