Merge branch 'error-api'
This commit is contained in:
commit
a7c2933e01
8
blob.c
8
blob.c
|
@ -64,7 +64,7 @@ pic_blob_bytevector(pic_state *pic)
|
|||
pic_assert_type(pic, argv[i], int);
|
||||
|
||||
if (pic_int(argv[i]) < 0 || pic_int(argv[i]) > 255) {
|
||||
pic_error(pic, "byte out of range");
|
||||
pic_errorf(pic, "byte out of range");
|
||||
}
|
||||
|
||||
*data++ = pic_int(argv[i]);
|
||||
|
@ -82,7 +82,7 @@ pic_blob_make_bytevector(pic_state *pic)
|
|||
pic_get_args(pic, "i|i", &k, &b);
|
||||
|
||||
if (b < 0 || b > 255)
|
||||
pic_error(pic, "byte out of range");
|
||||
pic_errorf(pic, "byte out of range");
|
||||
|
||||
blob = pic_make_blob(pic, k);
|
||||
for (i = 0; i < k; ++i) {
|
||||
|
@ -122,7 +122,7 @@ pic_blob_bytevector_u8_set(pic_state *pic)
|
|||
pic_get_args(pic, "bii", &bv, &k, &v);
|
||||
|
||||
if (v < 0 || v > 255)
|
||||
pic_error(pic, "byte out of range");
|
||||
pic_errorf(pic, "byte out of range");
|
||||
|
||||
bv->data[k] = v;
|
||||
return pic_none_value();
|
||||
|
@ -227,7 +227,7 @@ pic_blob_list_to_bytevector(pic_state *pic)
|
|||
pic_assert_type(pic, e, int);
|
||||
|
||||
if (pic_int(e) < 0 || pic_int(e) > 255)
|
||||
pic_error(pic, "byte out of range");
|
||||
pic_errorf(pic, "byte out of range");
|
||||
|
||||
*data++ = pic_int(e);
|
||||
}
|
||||
|
|
2
char.c
2
char.c
|
@ -53,7 +53,7 @@ pic_char_integer_to_char(pic_state *pic)
|
|||
if (pic_char_p(argv[i])) \
|
||||
d = pic_char(argv[i]); \
|
||||
else \
|
||||
pic_error(pic, #op ": char required"); \
|
||||
pic_errorf(pic, #op ": char required"); \
|
||||
\
|
||||
if (! (c op d)) \
|
||||
return pic_false_value(); \
|
||||
|
|
24
codegen.c
24
codegen.c
|
@ -425,7 +425,7 @@ analyze_lambda(analyze_state *state, pic_value obj)
|
|||
pic_value formals, body_exprs;
|
||||
|
||||
if (pic_length(pic, obj) < 2) {
|
||||
pic_error(pic, "syntax error");
|
||||
pic_errorf(pic, "syntax error");
|
||||
}
|
||||
|
||||
formals = pic_list_ref(pic, obj, 1);
|
||||
|
@ -450,12 +450,12 @@ analyze_define(analyze_state *state, pic_value obj)
|
|||
pic_sym sym;
|
||||
|
||||
if (pic_length(pic, obj) != 3) {
|
||||
pic_error(pic, "syntax error");
|
||||
pic_errorf(pic, "syntax error");
|
||||
}
|
||||
|
||||
var = pic_list_ref(pic, obj, 1);
|
||||
if (! pic_sym_p(var)) {
|
||||
pic_error(pic, "syntax error");
|
||||
pic_errorf(pic, "syntax error");
|
||||
} else {
|
||||
sym = pic_sym(var);
|
||||
}
|
||||
|
@ -472,7 +472,7 @@ analyze_define(analyze_state *state, pic_value obj)
|
|||
val = analyze_defer(state, pic_sym_value(sym), formals, body_exprs);
|
||||
} else {
|
||||
if (pic_length(pic, obj) != 3) {
|
||||
pic_error(pic, "syntax error");
|
||||
pic_errorf(pic, "syntax error");
|
||||
}
|
||||
val = analyze(state, pic_list_ref(pic, obj, 2), false);
|
||||
}
|
||||
|
@ -489,7 +489,7 @@ analyze_if(analyze_state *state, pic_value obj, bool tailpos)
|
|||
if_false = pic_none_value();
|
||||
switch (pic_length(pic, obj)) {
|
||||
default:
|
||||
pic_error(pic, "syntax error");
|
||||
pic_errorf(pic, "syntax error");
|
||||
break;
|
||||
case 4:
|
||||
if_false = pic_list_ref(pic, obj, 3);
|
||||
|
@ -539,12 +539,12 @@ analyze_set(analyze_state *state, pic_value obj)
|
|||
pic_value var, val;
|
||||
|
||||
if (pic_length(pic, obj) != 3) {
|
||||
pic_error(pic, "syntax error");
|
||||
pic_errorf(pic, "syntax error");
|
||||
}
|
||||
|
||||
var = pic_list_ref(pic, obj, 1);
|
||||
if (! pic_sym_p(var)) {
|
||||
pic_error(pic, "syntax error");
|
||||
pic_errorf(pic, "syntax error");
|
||||
}
|
||||
|
||||
val = pic_list_ref(pic, obj, 2);
|
||||
|
@ -561,14 +561,14 @@ analyze_quote(analyze_state *state, pic_value obj)
|
|||
pic_state *pic = state->pic;
|
||||
|
||||
if (pic_length(pic, obj) != 2) {
|
||||
pic_error(pic, "syntax error");
|
||||
pic_errorf(pic, "syntax error");
|
||||
}
|
||||
return pic_list2(pic, pic_sym_value(pic->sQUOTE), pic_list_ref(pic, obj, 1));
|
||||
}
|
||||
|
||||
#define ARGC_ASSERT_GE(n) do { \
|
||||
if (pic_length(pic, obj) < (n) + 1) { \
|
||||
pic_error(pic, "wrong number of arguments"); \
|
||||
pic_errorf(pic, "wrong number of arguments"); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
|
@ -699,7 +699,7 @@ analyze_call_with_values(analyze_state *state, pic_value obj, bool tailpos)
|
|||
pic_sym call;
|
||||
|
||||
if (pic_length(pic, obj) != 3) {
|
||||
pic_error(pic, "wrong number of arguments");
|
||||
pic_errorf(pic, "wrong number of arguments");
|
||||
}
|
||||
|
||||
if (! tailpos) {
|
||||
|
@ -714,7 +714,7 @@ analyze_call_with_values(analyze_state *state, pic_value obj, bool tailpos)
|
|||
|
||||
#define ARGC_ASSERT(n) do { \
|
||||
if (pic_length(pic, obj) != (n) + 1) { \
|
||||
pic_error(pic, "wrong number of arguments"); \
|
||||
pic_errorf(pic, "wrong number of arguments"); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
|
@ -1413,7 +1413,7 @@ codegen(codegen_state *state, pic_value obj)
|
|||
cxt->clen++;
|
||||
return;
|
||||
}
|
||||
pic_error(pic, "codegen: unknown AST type");
|
||||
pic_errorf(pic, "codegen: unknown AST type");
|
||||
}
|
||||
|
||||
static struct pic_irep *
|
||||
|
|
41
debug.c
41
debug.c
|
@ -36,37 +36,32 @@ pic_get_backtrace(pic_state *pic)
|
|||
}
|
||||
|
||||
void
|
||||
pic_print_backtrace(pic_state *pic, struct pic_error *e)
|
||||
pic_print_backtrace(pic_state *pic)
|
||||
{
|
||||
size_t ai = pic_gc_arena_preserve(pic);
|
||||
pic_str *trace;
|
||||
|
||||
assert(pic->err != NULL);
|
||||
assert(! pic_undef_p(pic->err));
|
||||
|
||||
trace = pic_make_str(pic, NULL, 0);
|
||||
if (! pic_error_p(pic->err)) {
|
||||
trace = pic_format(pic, "raised: ~s", pic->err);
|
||||
} else {
|
||||
struct pic_error *e;
|
||||
|
||||
switch (e->type) {
|
||||
case PIC_ERROR_OTHER:
|
||||
trace = pic_strcat(pic, trace, pic_make_str_cstr(pic, "error: "));
|
||||
break;
|
||||
case PIC_ERROR_FILE:
|
||||
trace = pic_strcat(pic, trace, pic_make_str_cstr(pic, "file error: "));
|
||||
break;
|
||||
case PIC_ERROR_READ:
|
||||
trace = pic_strcat(pic, trace, pic_make_str_cstr(pic, "read error: "));
|
||||
break;
|
||||
case PIC_ERROR_RAISED:
|
||||
trace = pic_strcat(pic, trace, pic_make_str_cstr(pic, "raised: "));
|
||||
break;
|
||||
e = pic_error_ptr(pic->err);
|
||||
if (e->type != pic_intern_cstr(pic, "")) {
|
||||
trace = pic_format(pic, "~s ", pic_sym_value(e->type));
|
||||
} else {
|
||||
trace = pic_make_str(pic, NULL, 0);
|
||||
}
|
||||
trace = pic_strcat(pic, trace, pic_format(pic, "error: ~s", pic_obj_value(e->msg)));
|
||||
|
||||
/* TODO: print error irritants */
|
||||
|
||||
trace = pic_strcat(pic, trace, pic_make_str(pic, "\n", 1));
|
||||
trace = pic_strcat(pic, trace, e->stack);
|
||||
}
|
||||
|
||||
trace = pic_strcat(pic, trace, e->msg);
|
||||
|
||||
/* TODO: print error irritants */
|
||||
|
||||
trace = pic_strcat(pic, trace, pic_make_str(pic, "\n", 1));
|
||||
trace = pic_strcat(pic, trace, e->stack);
|
||||
|
||||
/* print! */
|
||||
printf("%s", pic_str_cstr(trace));
|
||||
|
||||
|
|
110
error.c
110
error.c
|
@ -71,8 +71,8 @@ pic_pop_try(pic_state *pic)
|
|||
pic->jmp = try_jmp->prev_jmp;
|
||||
}
|
||||
|
||||
static struct pic_error *
|
||||
make_error(pic_state *pic, short type, pic_str *msg, pic_value irrs)
|
||||
struct pic_error *
|
||||
pic_make_error(pic_state *pic, pic_sym type, const char *msg, pic_value irrs)
|
||||
{
|
||||
struct pic_error *e;
|
||||
pic_str *stack;
|
||||
|
@ -81,7 +81,7 @@ make_error(pic_state *pic, short type, pic_str *msg, pic_value irrs)
|
|||
|
||||
e = (struct pic_error *)pic_obj_alloc(pic, sizeof(struct pic_error), PIC_TT_ERROR);
|
||||
e->type = type;
|
||||
e->msg = msg;
|
||||
e->msg = pic_make_str_cstr(pic, msg);
|
||||
e->irrs = irrs;
|
||||
e->stack = stack;
|
||||
|
||||
|
@ -89,37 +89,51 @@ make_error(pic_state *pic, short type, pic_str *msg, pic_value irrs)
|
|||
}
|
||||
|
||||
noreturn void
|
||||
pic_throw_error(pic_state *pic, struct pic_error *e)
|
||||
pic_raise(pic_state *pic, pic_value err)
|
||||
{
|
||||
void pic_vm_tear_off(pic_state *);
|
||||
|
||||
pic_vm_tear_off(pic); /* tear off */
|
||||
|
||||
pic->err = e;
|
||||
pic->err = err;
|
||||
if (! pic->jmp) {
|
||||
puts(pic_errmsg(pic));
|
||||
abort();
|
||||
pic_abort(pic, "no handler found on stack");
|
||||
}
|
||||
|
||||
longjmp(*pic->jmp, 1);
|
||||
}
|
||||
|
||||
noreturn void
|
||||
pic_throw(pic_state *pic, short type, const char *msg, pic_value irrs)
|
||||
pic_throw(pic_state *pic, pic_sym type, const char *msg, pic_value irrs)
|
||||
{
|
||||
struct pic_error *e;
|
||||
|
||||
e = make_error(pic, type, pic_make_str_cstr(pic, msg), irrs);
|
||||
e = pic_make_error(pic, type, msg, irrs);
|
||||
|
||||
pic_throw_error(pic, e);
|
||||
pic_raise(pic, pic_obj_value(e));
|
||||
}
|
||||
|
||||
noreturn void
|
||||
pic_error(pic_state *pic, const char *msg, pic_value irrs)
|
||||
{
|
||||
pic_throw(pic, pic_intern_cstr(pic, ""), msg, irrs);
|
||||
}
|
||||
|
||||
const char *
|
||||
pic_errmsg(pic_state *pic)
|
||||
{
|
||||
assert(pic->err != NULL);
|
||||
pic_str *str;
|
||||
|
||||
return pic_str_cstr(pic->err->msg);
|
||||
assert(! pic_undef_p(pic->err));
|
||||
|
||||
if (! pic_error_p(pic->err)) {
|
||||
str = pic_format(pic, "~s", pic->err);
|
||||
} else {
|
||||
str = pic_error_ptr(pic->err)->msg;
|
||||
}
|
||||
|
||||
return pic_str_cstr(str);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -136,34 +150,30 @@ pic_errorf(pic_state *pic, const char *fmt, ...)
|
|||
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);
|
||||
pic_error(pic, msg, irrs);
|
||||
}
|
||||
|
||||
static pic_value
|
||||
pic_error_with_exception_handler(pic_state *pic)
|
||||
{
|
||||
struct pic_proc *handler, *thunk;
|
||||
pic_value v;
|
||||
pic_value val;
|
||||
|
||||
pic_get_args(pic, "ll", &handler, &thunk);
|
||||
|
||||
pic_try_with_handler(handler) {
|
||||
v = pic_apply0(pic, thunk);
|
||||
val = pic_apply0(pic, thunk);
|
||||
}
|
||||
pic_catch {
|
||||
struct pic_error *e = pic->err;
|
||||
pic_value e = pic->err;
|
||||
|
||||
pic->err = NULL;
|
||||
pic->err = pic_undef_value();
|
||||
|
||||
if (e->type == PIC_ERROR_RAISED) {
|
||||
v = pic_list_ref(pic, e->irrs, 0);
|
||||
} else {
|
||||
v = pic_obj_value(e);
|
||||
}
|
||||
v = pic_apply1(pic, handler, v);
|
||||
pic_errorf(pic, "error handler returned ~s, by error ~s", v, pic_obj_value(e));
|
||||
val = pic_apply1(pic, handler, e);
|
||||
|
||||
pic_errorf(pic, "error handler returned with ~s on error ~s", val, e);
|
||||
}
|
||||
return v;
|
||||
return val;
|
||||
}
|
||||
|
||||
noreturn static pic_value
|
||||
|
@ -173,7 +183,7 @@ pic_error_raise(pic_state *pic)
|
|||
|
||||
pic_get_args(pic, "o", &v);
|
||||
|
||||
pic_throw(pic, PIC_ERROR_RAISED, "object is raised", pic_list1(pic, v));
|
||||
pic_raise(pic, v);
|
||||
}
|
||||
|
||||
static pic_value
|
||||
|
@ -206,7 +216,23 @@ pic_error_error(pic_state *pic)
|
|||
|
||||
pic_get_args(pic, "z*", &str, &argc, &argv);
|
||||
|
||||
pic_throw(pic, PIC_ERROR_OTHER, str, pic_list_by_array(pic, argc, argv));
|
||||
pic_error(pic, str, pic_list_by_array(pic, argc, argv));
|
||||
}
|
||||
|
||||
static pic_value
|
||||
pic_error_make_error_object(pic_state *pic)
|
||||
{
|
||||
struct pic_error *e;
|
||||
pic_sym type;
|
||||
pic_str *msg;
|
||||
size_t argc;
|
||||
pic_value *argv;
|
||||
|
||||
pic_get_args(pic, "ms*", &type, &msg, &argc, &argv);
|
||||
|
||||
e = pic_make_error(pic, type, pic_str_cstr(msg), pic_list_by_array(pic, argc, argv));
|
||||
|
||||
return pic_obj_value(e);
|
||||
}
|
||||
|
||||
static pic_value
|
||||
|
@ -240,35 +266,13 @@ pic_error_error_object_irritants(pic_state *pic)
|
|||
}
|
||||
|
||||
static pic_value
|
||||
pic_error_read_error_p(pic_state *pic)
|
||||
pic_error_error_object_type(pic_state *pic)
|
||||
{
|
||||
pic_value v;
|
||||
struct pic_error *e;
|
||||
|
||||
pic_get_args(pic, "o", &v);
|
||||
pic_get_args(pic, "e", &e);
|
||||
|
||||
if (! pic_error_p(v)) {
|
||||
return pic_false_value();
|
||||
}
|
||||
|
||||
e = pic_error_ptr(v);
|
||||
return pic_bool_value(e->type == PIC_ERROR_READ);
|
||||
}
|
||||
|
||||
static pic_value
|
||||
pic_error_file_error_p(pic_state *pic)
|
||||
{
|
||||
pic_value v;
|
||||
struct pic_error *e;
|
||||
|
||||
pic_get_args(pic, "o", &v);
|
||||
|
||||
if (! pic_error_p(v)) {
|
||||
return pic_false_value();
|
||||
}
|
||||
|
||||
e = pic_error_ptr(v);
|
||||
return pic_bool_value(e->type == PIC_ERROR_FILE);
|
||||
return pic_sym_value(e->type);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -278,9 +282,9 @@ pic_init_error(pic_state *pic)
|
|||
pic_defun(pic, "raise", pic_error_raise);
|
||||
pic_defun(pic, "raise-continuable", pic_error_raise_continuable);
|
||||
pic_defun(pic, "error", pic_error_error);
|
||||
pic_defun(pic, "make-error-object", pic_error_make_error_object);
|
||||
pic_defun(pic, "error-object?", pic_error_error_object_p);
|
||||
pic_defun(pic, "error-object-message", pic_error_error_object_message);
|
||||
pic_defun(pic, "error-object-irritants", pic_error_error_object_irritants);
|
||||
pic_defun(pic, "read-error?", pic_error_read_error_p);
|
||||
pic_defun(pic, "file-error?", pic_error_file_error_p);
|
||||
pic_defun(pic, "error-object-type", pic_error_error_object_type);
|
||||
}
|
||||
|
|
2
file.c
2
file.c
|
@ -9,7 +9,7 @@
|
|||
static noreturn void
|
||||
file_error(pic_state *pic, const char *msg)
|
||||
{
|
||||
pic_throw(pic, PIC_ERROR_FILE, msg, pic_nil_value());
|
||||
pic_throw(pic, pic->sFILE, msg, pic_nil_value());
|
||||
}
|
||||
|
||||
static pic_value
|
||||
|
|
4
gc.c
4
gc.c
|
@ -580,9 +580,7 @@ gc_mark_phase(pic_state *pic)
|
|||
}
|
||||
|
||||
/* error object */
|
||||
if (pic->err) {
|
||||
gc_mark_object(pic, (struct pic_object *)pic->err);
|
||||
}
|
||||
gc_mark(pic, pic->err);
|
||||
|
||||
/* arena */
|
||||
for (j = 0; j < pic->arena_idx; ++j) {
|
||||
|
|
|
@ -81,6 +81,7 @@ typedef struct {
|
|||
pic_sym sCONS, sCAR, sCDR, sNILP;
|
||||
pic_sym sADD, sSUB, sMUL, sDIV, sMINUS;
|
||||
pic_sym sEQ, sLT, sLE, sGT, sGE, sNOT;
|
||||
pic_sym sREAD, sFILE;
|
||||
|
||||
pic_sym rDEFINE, rLAMBDA, rIF, rBEGIN, rQUOTE, rSETBANG;
|
||||
pic_sym rDEFINE_SYNTAX, rIMPORT, rEXPORT;
|
||||
|
@ -104,7 +105,7 @@ typedef struct {
|
|||
struct pic_reader *reader;
|
||||
|
||||
jmp_buf *jmp;
|
||||
struct pic_error *err;
|
||||
pic_value err;
|
||||
struct pic_jmpbuf *try_jmps;
|
||||
size_t try_jmp_size, try_jmp_idx;
|
||||
|
||||
|
@ -206,13 +207,9 @@ noreturn void pic_abort(pic_state *, const char *);
|
|||
noreturn void pic_errorf(pic_state *, const char *, ...);
|
||||
void pic_warnf(pic_state *, const char *, ...);
|
||||
pic_str *pic_get_backtrace(pic_state *);
|
||||
void pic_print_backtrace(pic_state *, struct pic_error *);
|
||||
void pic_print_backtrace(pic_state *);
|
||||
|
||||
/* obsoleted */
|
||||
noreturn static inline void pic_error(pic_state *pic, const char *msg)
|
||||
{
|
||||
pic_errorf(pic, msg);
|
||||
}
|
||||
static inline void pic_warn(pic_state *pic, const char *msg)
|
||||
{
|
||||
pic_warnf(pic, msg);
|
||||
|
|
|
@ -34,18 +34,14 @@ struct pic_jmpbuf {
|
|||
void pic_push_try(pic_state *, struct pic_proc *);
|
||||
void pic_pop_try(pic_state *);
|
||||
|
||||
noreturn void pic_throw(pic_state *, short, const char *, pic_value);
|
||||
noreturn void pic_throw_error(pic_state *, struct pic_error *);
|
||||
noreturn void pic_raise(pic_state *, pic_value);
|
||||
noreturn void pic_throw(pic_state *, pic_sym, const char *, pic_list);
|
||||
noreturn void pic_error(pic_state *, const char *, pic_list);
|
||||
|
||||
struct pic_error {
|
||||
PIC_OBJECT_HEADER
|
||||
enum pic_error_kind {
|
||||
PIC_ERROR_OTHER,
|
||||
PIC_ERROR_FILE,
|
||||
PIC_ERROR_READ,
|
||||
PIC_ERROR_RAISED
|
||||
} type;
|
||||
struct pic_string *msg;
|
||||
pic_sym type;
|
||||
pic_str *msg;
|
||||
pic_value irrs;
|
||||
pic_str *stack;
|
||||
};
|
||||
|
@ -53,6 +49,8 @@ struct pic_error {
|
|||
#define pic_error_p(v) (pic_type(v) == PIC_TT_ERROR)
|
||||
#define pic_error_ptr(v) ((struct pic_error *)pic_ptr(v))
|
||||
|
||||
struct pic_error *pic_make_error(pic_state *, pic_sym, const char *, pic_list);
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -142,6 +142,7 @@ struct pic_blob;
|
|||
|
||||
struct pic_proc;
|
||||
struct pic_port;
|
||||
struct pic_error;
|
||||
|
||||
/* set aliases to basic types */
|
||||
typedef pic_value pic_list;
|
||||
|
|
2
lib.c
2
lib.c
|
@ -318,7 +318,7 @@ pic_lib_define_library(pic_state *pic)
|
|||
}
|
||||
pic_catch {
|
||||
pic_in_library(pic, prev->name); /* restores pic->lib even if an error occurs */
|
||||
pic_throw_error(pic, pic->err);
|
||||
pic_raise(pic, pic->err);
|
||||
}
|
||||
|
||||
return pic_none_value();
|
||||
|
|
14
macro.c
14
macro.c
|
@ -161,7 +161,7 @@ macroexpand_lambda(pic_state *pic, pic_value expr, struct pic_senv *senv)
|
|||
pic_value a;
|
||||
|
||||
if (pic_length(pic, expr) < 2) {
|
||||
pic_error(pic, "syntax error");
|
||||
pic_errorf(pic, "syntax error");
|
||||
}
|
||||
|
||||
in = pic_make_senv(pic, senv);
|
||||
|
@ -170,7 +170,7 @@ macroexpand_lambda(pic_state *pic, pic_value expr, struct pic_senv *senv)
|
|||
pic_value v = pic_car(pic, a);
|
||||
|
||||
if (! pic_sym_p(v)) {
|
||||
pic_error(pic, "syntax error");
|
||||
pic_errorf(pic, "syntax error");
|
||||
}
|
||||
pic_add_rename(pic, in, pic_sym(v));
|
||||
}
|
||||
|
@ -178,7 +178,7 @@ macroexpand_lambda(pic_state *pic, pic_value expr, struct pic_senv *senv)
|
|||
pic_add_rename(pic, in, pic_sym(a));
|
||||
}
|
||||
else if (! pic_nil_p(a)) {
|
||||
pic_error(pic, "syntax error");
|
||||
pic_errorf(pic, "syntax error");
|
||||
}
|
||||
|
||||
formal = macroexpand_list(pic, pic_cadr(pic, expr), in);
|
||||
|
@ -203,12 +203,12 @@ macroexpand_define(pic_state *pic, pic_value expr, struct pic_senv *senv)
|
|||
}
|
||||
|
||||
if (pic_length(pic, expr) != 3) {
|
||||
pic_error(pic, "syntax error");
|
||||
pic_errorf(pic, "syntax error");
|
||||
}
|
||||
|
||||
var = pic_cadr(pic, expr);
|
||||
if (! pic_sym_p(var)) {
|
||||
pic_error(pic, "binding to non-symbol object");
|
||||
pic_errorf(pic, "binding to non-symbol object");
|
||||
}
|
||||
sym = pic_sym(var);
|
||||
if (! pic_find_rename(pic, senv, sym, &rename)) {
|
||||
|
@ -226,12 +226,12 @@ macroexpand_defsyntax(pic_state *pic, pic_value expr, struct pic_senv *senv)
|
|||
pic_sym sym, rename;
|
||||
|
||||
if (pic_length(pic, expr) != 3) {
|
||||
pic_error(pic, "syntax error");
|
||||
pic_errorf(pic, "syntax error");
|
||||
}
|
||||
|
||||
var = pic_cadr(pic, expr);
|
||||
if (! pic_sym_p(var)) {
|
||||
pic_error(pic, "binding to non-symbol object");
|
||||
pic_errorf(pic, "binding to non-symbol object");
|
||||
}
|
||||
sym = pic_sym(var);
|
||||
if (! pic_find_rename(pic, senv, sym, &rename)) {
|
||||
|
|
6
number.c
6
number.c
|
@ -179,7 +179,7 @@ pic_number_nan_p(pic_state *pic)
|
|||
else if (pic_int_p(argv[i])) \
|
||||
g = pic_int(argv[i]); \
|
||||
else \
|
||||
pic_error(pic, #op ": number required"); \
|
||||
pic_errorf(pic, #op ": number required"); \
|
||||
\
|
||||
if (! (f op g)) \
|
||||
return pic_false_value(); \
|
||||
|
@ -216,7 +216,7 @@ DEFINE_ARITH_CMP(>=, ge)
|
|||
f op##= pic_float(argv[i]); \
|
||||
} \
|
||||
else { \
|
||||
pic_error(pic, #op ": number required"); \
|
||||
pic_errorf(pic, #op ": number required"); \
|
||||
} \
|
||||
} \
|
||||
\
|
||||
|
@ -252,7 +252,7 @@ DEFINE_ARITH_OP(*, mul, 1)
|
|||
f op##= pic_float(argv[i]); \
|
||||
} \
|
||||
else { \
|
||||
pic_error(pic, #op ": number required"); \
|
||||
pic_errorf(pic, #op ": number required"); \
|
||||
} \
|
||||
} \
|
||||
\
|
||||
|
|
8
pair.c
8
pair.c
|
@ -51,7 +51,7 @@ pic_set_car(pic_state *pic, pic_value obj, pic_value val)
|
|||
struct pic_pair *pair;
|
||||
|
||||
if (! pic_pair_p(obj)) {
|
||||
pic_error(pic, "pair required");
|
||||
pic_errorf(pic, "pair required");
|
||||
}
|
||||
pair = pic_pair_ptr(obj);
|
||||
|
||||
|
@ -64,7 +64,7 @@ pic_set_cdr(pic_state *pic, pic_value obj, pic_value val)
|
|||
struct pic_pair *pair;
|
||||
|
||||
if (! pic_pair_p(obj)) {
|
||||
pic_error(pic, "pair required");
|
||||
pic_errorf(pic, "pair required");
|
||||
}
|
||||
pair = pic_pair_ptr(obj);
|
||||
|
||||
|
@ -520,7 +520,7 @@ pic_pair_set_car(pic_state *pic)
|
|||
pic_get_args(pic, "oo", &v, &w);
|
||||
|
||||
if (! pic_pair_p(v))
|
||||
pic_error(pic, "pair expected");
|
||||
pic_errorf(pic, "pair expected");
|
||||
|
||||
pic_pair_ptr(v)->car = w;
|
||||
return pic_none_value();
|
||||
|
@ -534,7 +534,7 @@ pic_pair_set_cdr(pic_state *pic)
|
|||
pic_get_args(pic, "oo", &v, &w);
|
||||
|
||||
if (! pic_pair_p(v))
|
||||
pic_error(pic, "pair expected");
|
||||
pic_errorf(pic, "pair expected");
|
||||
|
||||
pic_pair_ptr(v)->cdr = w;
|
||||
return pic_none_value();
|
||||
|
|
18
port.c
18
port.c
|
@ -107,7 +107,7 @@ void
|
|||
pic_close_port(pic_state *pic, struct pic_port *port)
|
||||
{
|
||||
if (xfclose(port->file) == EOF) {
|
||||
pic_error(pic, "close-port: failure");
|
||||
pic_errorf(pic, "close-port: failure");
|
||||
}
|
||||
port->status = PIC_PORT_CLOSE;
|
||||
}
|
||||
|
@ -247,25 +247,25 @@ pic_port_close_port(pic_state *pic)
|
|||
if ((port->flags & (flgs)) != (flgs)) { \
|
||||
switch (flgs) { \
|
||||
case PIC_PORT_IN: \
|
||||
pic_error(pic, caller ": expected output port"); \
|
||||
pic_errorf(pic, caller ": expected output port"); \
|
||||
case PIC_PORT_OUT: \
|
||||
pic_error(pic, caller ": expected input port"); \
|
||||
pic_errorf(pic, caller ": expected input port"); \
|
||||
case PIC_PORT_IN | PIC_PORT_TEXT: \
|
||||
pic_error(pic, caller ": expected input/textual port"); \
|
||||
pic_errorf(pic, caller ": expected input/textual port"); \
|
||||
case PIC_PORT_IN | PIC_PORT_BINARY: \
|
||||
pic_error(pic, caller ": expected input/binary port"); \
|
||||
pic_errorf(pic, caller ": expected input/binary port"); \
|
||||
case PIC_PORT_OUT | PIC_PORT_TEXT: \
|
||||
pic_error(pic, caller ": expected output/textual port"); \
|
||||
pic_errorf(pic, caller ": expected output/textual port"); \
|
||||
case PIC_PORT_OUT | PIC_PORT_BINARY: \
|
||||
pic_error(pic, caller ": expected output/binary port"); \
|
||||
pic_errorf(pic, caller ": expected output/binary port"); \
|
||||
} \
|
||||
} \
|
||||
if (port->status != stat) { \
|
||||
switch (stat) { \
|
||||
case PIC_PORT_OPEN: \
|
||||
pic_error(pic, caller ": expected open port"); \
|
||||
pic_errorf(pic, caller ": expected open port"); \
|
||||
case PIC_PORT_CLOSE: \
|
||||
pic_error(pic, caller ": expected close port"); \
|
||||
pic_errorf(pic, caller ": expected close port"); \
|
||||
} \
|
||||
} \
|
||||
} while (0)
|
||||
|
|
2
proc.c
2
proc.c
|
@ -91,7 +91,7 @@ pic_proc_apply(pic_state *pic)
|
|||
pic_get_args(pic, "l*", &proc, &argc, &args);
|
||||
|
||||
if (argc == 0) {
|
||||
pic_error(pic, "apply: wrong number of arguments");
|
||||
pic_errorf(pic, "apply: wrong number of arguments");
|
||||
}
|
||||
|
||||
arg_list = args[--argc];
|
||||
|
|
2
read.c
2
read.c
|
@ -21,7 +21,7 @@ static pic_value read_nullable(pic_state *pic, struct pic_port *port, int c);
|
|||
static noreturn void
|
||||
read_error(pic_state *pic, const char *msg)
|
||||
{
|
||||
pic_throw(pic, PIC_ERROR_READ, msg, pic_nil_value());
|
||||
pic_throw(pic, pic->sREAD, msg, pic_nil_value());
|
||||
}
|
||||
|
||||
static int
|
||||
|
|
6
state.c
6
state.c
|
@ -72,7 +72,7 @@ pic_open(int argc, char *argv[], char **envp)
|
|||
|
||||
/* error handling */
|
||||
pic->jmp = NULL;
|
||||
pic->err = NULL;
|
||||
pic->err = pic_undef_value();
|
||||
pic->try_jmps = calloc(PIC_RESCUE_SIZE, sizeof(struct pic_jmpbuf));
|
||||
pic->try_jmp_idx = 0;
|
||||
pic->try_jmp_size = PIC_RESCUE_SIZE;
|
||||
|
@ -131,6 +131,8 @@ pic_open(int argc, char *argv[], char **envp)
|
|||
S(sGT, ">");
|
||||
S(sGE, ">=");
|
||||
S(sNOT, "not");
|
||||
S(sREAD, "read");
|
||||
S(sFILE, "file");
|
||||
pic_gc_arena_restore(pic, ai);
|
||||
|
||||
#define R(slot,name) pic->slot = pic_gensym(pic, pic_intern_cstr(pic, name));
|
||||
|
@ -191,7 +193,7 @@ pic_close(pic_state *pic)
|
|||
pic->sp = pic->stbase;
|
||||
pic->ci = pic->cibase;
|
||||
pic->arena_idx = 0;
|
||||
pic->err = NULL;
|
||||
pic->err = pic_undef_value();
|
||||
xh_clear(&pic->macros);
|
||||
pic->features = pic_nil_value();
|
||||
pic->libs = pic_nil_value();
|
||||
|
|
2
string.c
2
string.c
|
@ -404,7 +404,7 @@ pic_str_string_append(pic_state *pic)
|
|||
str = pic_make_str(pic, NULL, 0);
|
||||
for (i = 0; i < argc; ++i) {
|
||||
if (! pic_str_p(argv[i])) {
|
||||
pic_error(pic, "type error");
|
||||
pic_errorf(pic, "type error");
|
||||
}
|
||||
str = pic_strcat(pic, str, pic_str_ptr(argv[i]));
|
||||
}
|
||||
|
|
4
symbol.c
4
symbol.c
|
@ -132,7 +132,7 @@ pic_symbol_symbol_to_string(pic_state *pic)
|
|||
pic_get_args(pic, "o", &v);
|
||||
|
||||
if (! pic_sym_p(v)) {
|
||||
pic_error(pic, "symbol->string: expected symbol");
|
||||
pic_errorf(pic, "symbol->string: expected symbol");
|
||||
}
|
||||
|
||||
return pic_obj_value(pic_make_str_cstr(pic, pic_symbol_name(pic, pic_sym(v))));
|
||||
|
@ -146,7 +146,7 @@ pic_symbol_string_to_symbol(pic_state *pic)
|
|||
pic_get_args(pic, "o", &v);
|
||||
|
||||
if (! pic_str_p(v)) {
|
||||
pic_error(pic, "string->symbol: expected string");
|
||||
pic_errorf(pic, "string->symbol: expected string");
|
||||
}
|
||||
|
||||
return pic_symbol_value(pic_intern_cstr(pic, pic_str_cstr(pic_str_ptr(v))));
|
||||
|
|
4
vector.c
4
vector.c
|
@ -105,7 +105,7 @@ pic_vec_vector_ref(pic_state *pic)
|
|||
pic_get_args(pic, "vi", &v, &k);
|
||||
|
||||
if (k < 0 || v->len <= (size_t)k) {
|
||||
pic_error(pic, "vector-ref: index out of range");
|
||||
pic_errorf(pic, "vector-ref: index out of range");
|
||||
}
|
||||
return v->data[k];
|
||||
}
|
||||
|
@ -120,7 +120,7 @@ pic_vec_vector_set(pic_state *pic)
|
|||
pic_get_args(pic, "vio", &v, &k, &o);
|
||||
|
||||
if (k < 0 || v->len <= (size_t)k) {
|
||||
pic_error(pic, "vector-set!: index out of range");
|
||||
pic_errorf(pic, "vector-set!: index out of range");
|
||||
}
|
||||
v->data[k] = o;
|
||||
return pic_none_value();
|
||||
|
|
24
vm.c
24
vm.c
|
@ -29,7 +29,7 @@ pic_get_proc(pic_state *pic)
|
|||
pic_value v = GET_OPERAND(pic,0);
|
||||
|
||||
if (! pic_proc_p(v)) {
|
||||
pic_error(pic, "fatal error");
|
||||
pic_errorf(pic, "fatal error");
|
||||
}
|
||||
return pic_proc_ptr(v);
|
||||
}
|
||||
|
@ -70,7 +70,7 @@ pic_get_args(pic_state *pic, const char *format, ...)
|
|||
switch (c) {
|
||||
default:
|
||||
if (argc <= i && ! opt) {
|
||||
pic_error(pic, "wrong number of arguments");
|
||||
pic_errorf(pic, "wrong number of arguments");
|
||||
}
|
||||
break;
|
||||
case '|':
|
||||
|
@ -375,7 +375,7 @@ pic_get_args(pic_state *pic, const char *format, ...)
|
|||
*e = pic_error_ptr(v);
|
||||
}
|
||||
else {
|
||||
pic_error(pic, "pic_get_args, expected error");
|
||||
pic_errorf(pic, "pic_get_args, expected error");
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
@ -398,7 +398,7 @@ pic_get_args(pic_state *pic, const char *format, ...)
|
|||
}
|
||||
}
|
||||
else if (argc > i) {
|
||||
pic_error(pic, "wrong number of arguments");
|
||||
pic_errorf(pic, "wrong number of arguments");
|
||||
}
|
||||
va_end(ap);
|
||||
return i - 1;
|
||||
|
@ -675,7 +675,7 @@ pic_apply(pic_state *pic, struct pic_proc *proc, pic_value argv)
|
|||
#endif
|
||||
|
||||
if (! pic_list_p(argv)) {
|
||||
pic_error(pic, "argv must be a proper list");
|
||||
pic_errorf(pic, "argv must be a proper list");
|
||||
}
|
||||
|
||||
argc = pic_length(pic, argv) + 1;
|
||||
|
@ -728,11 +728,11 @@ pic_apply(pic_state *pic, struct pic_proc *proc, pic_value argv)
|
|||
|
||||
self = pic->ci->fp[0];
|
||||
if (! pic_proc_p(self)) {
|
||||
pic_error(pic, "logic flaw");
|
||||
pic_errorf(pic, "logic flaw");
|
||||
}
|
||||
irep = pic_proc_ptr(self)->u.irep;
|
||||
if (! pic_proc_irep_p(pic_proc_ptr(self))) {
|
||||
pic_error(pic, "logic flaw");
|
||||
pic_errorf(pic, "logic flaw");
|
||||
}
|
||||
PUSH(irep->pool[c.u.i]);
|
||||
NEXT;
|
||||
|
@ -950,11 +950,11 @@ pic_apply(pic_state *pic, struct pic_proc *proc, pic_value argv)
|
|||
|
||||
self = pic->ci->fp[0];
|
||||
if (! pic_proc_p(self)) {
|
||||
pic_error(pic, "logic flaw");
|
||||
pic_errorf(pic, "logic flaw");
|
||||
}
|
||||
irep = pic_proc_ptr(self)->u.irep;
|
||||
if (! pic_proc_irep_p(pic_proc_ptr(self))) {
|
||||
pic_error(pic, "logic flaw");
|
||||
pic_errorf(pic, "logic flaw");
|
||||
}
|
||||
|
||||
if (pic->ci->env == NULL) {
|
||||
|
@ -1017,7 +1017,7 @@ pic_apply(pic_state *pic, struct pic_proc *proc, pic_value argv)
|
|||
PUSH(pic_float_value(pic_float(a) op pic_int(b))); \
|
||||
} \
|
||||
else { \
|
||||
pic_error(pic, #op " got non-number operands"); \
|
||||
pic_errorf(pic, #op " got non-number operands"); \
|
||||
} \
|
||||
NEXT; \
|
||||
}
|
||||
|
@ -1037,7 +1037,7 @@ pic_apply(pic_state *pic, struct pic_proc *proc, pic_value argv)
|
|||
PUSH(pic_float_value(-pic_float(n)));
|
||||
}
|
||||
else {
|
||||
pic_error(pic, "unary - got a non-number operand");
|
||||
pic_errorf(pic, "unary - got a non-number operand");
|
||||
}
|
||||
NEXT;
|
||||
}
|
||||
|
@ -1060,7 +1060,7 @@ pic_apply(pic_state *pic, struct pic_proc *proc, pic_value argv)
|
|||
PUSH(pic_bool_value(pic_float(a) op pic_int(b))); \
|
||||
} \
|
||||
else { \
|
||||
pic_error(pic, #op " got non-number operands"); \
|
||||
pic_errorf(pic, #op " got non-number operands"); \
|
||||
} \
|
||||
NEXT; \
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue