remove error.h

This commit is contained in:
Yuichi Nishiwaki 2016-02-19 01:34:13 +09:00
parent 3198e77ac1
commit 9ae6f0cbe9
7 changed files with 59 additions and 83 deletions

View File

@ -9,11 +9,7 @@
PIC_NORETURN static void
file_error(pic_state *pic, const char *msg)
{
struct pic_error *e;
e = pic_make_error(pic, pic_intern_lit(pic, "file"), msg, pic_nil_value(pic));
pic_raise(pic, pic_obj_value(e));
pic_error(pic, "file", msg, pic_nil_value(pic));
}
pic_value

View File

@ -44,7 +44,7 @@ pic_errorf(pic_state *pic, const char *fmt, ...)
msg = pic_str(pic, err);
pic_error(pic, msg, pic_nil_value(pic));
pic_error(pic, "", msg, pic_nil_value(pic));
}
pic_value
@ -92,15 +92,16 @@ pic_pop_handler(pic_state *pic)
}
struct pic_error *
pic_make_error(pic_state *pic, pic_sym *type, const char *msg, pic_value irrs)
pic_make_error(pic_state *pic, const char *type, const char *msg, pic_value irrs)
{
struct pic_error *e;
struct pic_string *stack;
pic_sym *ty = pic_intern_cstr(pic, type);
stack = pic_get_backtrace(pic);
e = (struct pic_error *)pic_obj_alloc(pic, sizeof(struct pic_error), PIC_TYPE_ERROR);
e->type = type;
e->type = ty;
e->msg = pic_cstr_value(pic, msg);
e->irrs = irrs;
e->stack = stack;
@ -138,11 +139,11 @@ pic_raise(pic_state *pic, pic_value err)
}
void
pic_error(pic_state *pic, const char *msg, pic_value irrs)
pic_error(pic_state *pic, const char *type, const char *msg, pic_value irrs)
{
struct pic_error *e;
e = pic_make_error(pic, pic_intern_lit(pic, ""), msg, irrs);
e = pic_make_error(pic, type, msg, irrs);
pic_raise(pic, pic_obj_value(e));
}
@ -193,7 +194,7 @@ pic_error_error(pic_state *pic)
pic_get_args(pic, "z*", &str, &argc, &argv);
pic_error(pic, str, pic_list_by_array(pic, argc, argv));
pic_error(pic, "", str, pic_list_by_array(pic, argc, argv));
}
static pic_value

View File

@ -109,6 +109,8 @@ void pic_export(pic_state *, pic_sym *sym);
PIC_NORETURN void pic_panic(pic_state *, const char *msg);
PIC_NORETURN void pic_errorf(pic_state *, const char *fmt, ...);
PIC_NORETURN void pic_error(pic_state *, const char *type, const char *msg, pic_value irrs);
PIC_NORETURN void pic_raise(pic_state *, pic_value v);
struct pic_proc *pic_lambda(pic_state *, pic_func_t f, int n, ...);
struct pic_proc *pic_vlambda(pic_state *, pic_func_t f, int n, va_list);
@ -260,7 +262,6 @@ int pic_str_hash(pic_state *, struct pic_string *);
#include "picrin/state.h"
#include "picrin/cont.h"
#include "picrin/error.h"
#include "picrin/macro.h"
#include "picrin/pair.h"
#include "picrin/port.h"
@ -301,6 +302,35 @@ bool pic_data_type_p(pic_state *, pic_value, const pic_data_type *);
pic_in_library(pic, lib); \
} while (0)
/* do not return from try block! */
#define pic_try \
pic_try_(PIC_GENSYM(cont), PIC_GENSYM(handler))
#define pic_catch \
pic_catch_(PIC_GENSYM(label))
#define pic_try_(cont, handler) \
do { \
extern void pic_push_handler(pic_state *, struct pic_proc *); \
extern struct pic_proc *pic_pop_handler(pic_state *); \
extern pic_value pic_native_exception_handler(pic_state *); \
struct pic_cont cont; \
pic_save_point(pic, &cont); \
if (PIC_SETJMP(pic, cont.jmp) == 0) { \
struct pic_proc *handler; \
handler = pic_lambda(pic, pic_native_exception_handler, 1, pic_obj_value(pic_make_cont(pic, &cont))); \
do { \
pic_push_handler(pic, handler);
#define pic_catch_(label) \
pic_pop_handler(pic); \
} while (0); \
pic->cc = pic->cc->prev; \
} else { \
goto label; \
} \
} while (0); \
if (0) \
label:
void pic_warnf(pic_state *, const char *, ...);
struct pic_string *pic_get_backtrace(pic_state *);
void pic_print_backtrace(pic_state *, xFILE *);

View File

@ -1,63 +0,0 @@
/**
* See Copyright Notice in picrin.h
*/
#ifndef PICRIN_ERROR_H
#define PICRIN_ERROR_H
#if defined(__cplusplus)
extern "C" {
#endif
struct pic_error {
PIC_OBJECT_HEADER
pic_sym *type;
struct pic_string *msg;
pic_value irrs;
struct pic_string *stack;
};
#define pic_error_p(pic, v) (pic_type(pic, v) == PIC_TYPE_ERROR)
#define pic_error_ptr(v) ((struct pic_error *)pic_obj_ptr(v))
struct pic_error *pic_make_error(pic_state *, pic_sym *, const char *, pic_value);
/* do not return from try block! */
#define pic_try \
pic_try_(PIC_GENSYM(cont), PIC_GENSYM(handler))
#define pic_catch \
pic_catch_(PIC_GENSYM(label))
#define pic_try_(cont, handler) \
do { \
struct pic_cont cont; \
pic_save_point(pic, &cont); \
if (PIC_SETJMP(pic, cont.jmp) == 0) { \
extern pic_value pic_native_exception_handler(pic_state *); \
struct pic_proc *handler; \
handler = pic_lambda(pic, pic_native_exception_handler, 1, pic_obj_value(pic_make_cont(pic, &cont))); \
do { \
pic_push_handler(pic, handler);
#define pic_catch_(label) \
pic_pop_handler(pic); \
} while (0); \
pic->cc = pic->cc->prev; \
} else { \
goto label; \
} \
} while (0); \
if (0) \
label:
void pic_push_handler(pic_state *, struct pic_proc *);
struct pic_proc *pic_pop_handler(pic_state *);
pic_value pic_raise_continuable(pic_state *, pic_value);
PIC_NORETURN void pic_raise(pic_state *, pic_value);
PIC_NORETURN void pic_error(pic_state *, const char *, pic_value);
#if defined(__cplusplus)
}
#endif
#endif

View File

@ -163,6 +163,22 @@ struct pic_record {
struct pic_record *pic_make_rec(pic_state *, pic_value, pic_value);
/* error */
struct pic_error {
PIC_OBJECT_HEADER
pic_sym *type;
struct pic_string *msg;
pic_value irrs;
struct pic_string *stack;
};
#define pic_error_p(pic, v) (pic_type(pic, v) == PIC_TYPE_ERROR)
#define pic_error_ptr(v) ((struct pic_error *)pic_obj_ptr(v))
struct pic_error *pic_make_error(pic_state *, const char *, const char *, pic_value);
#if defined(__cplusplus)
}
#endif

View File

@ -94,7 +94,7 @@ file_error(pic_state *pic, const char *msg)
{
struct pic_error *e;
e = pic_make_error(pic, pic_intern_lit(pic, "file"), msg, pic_nil_value(pic));
e = pic_make_error(pic, "file", msg, pic_nil_value(pic));
pic_raise(pic, pic_obj_value(e));
}
@ -257,7 +257,7 @@ string_open(pic_state *pic, const char *data, size_t size)
if (file == NULL) {
string_close(pic, m);
pic_error(pic, "could not open new output string/bytevector port", pic_nil_value(pic));
pic_error(pic, "", "could not open new output string/bytevector port", pic_nil_value(pic));
}
return file;
}

View File

@ -11,13 +11,9 @@ static pic_value read(pic_state *pic, struct pic_port *port, int c);
static pic_value read_nullable(pic_state *pic, struct pic_port *port, int c);
PIC_NORETURN static void
read_error(pic_state *pic, const char *msg, pic_value irritant)
read_error(pic_state *pic, const char *msg, pic_value irritants)
{
struct pic_error *e;
e = pic_make_error(pic, pic_intern_lit(pic, "read"), msg, irritant);
pic_raise(pic, pic_obj_value(e));
pic_error(pic, "read", msg, irritants);
}
static int