diff --git a/contrib/10.callcc/callcc.c b/contrib/10.callcc/callcc.c index 280b8331..cf1c310b 100644 --- a/contrib/10.callcc/callcc.c +++ b/contrib/10.callcc/callcc.c @@ -1,5 +1,6 @@ #include "picrin.h" #include "picrin/object.h" +#include "picrin/state.h" struct pic_fullcont { jmp_buf jmp; diff --git a/etc/mkloader.pl b/etc/mkloader.pl index 527efd7a..088bd962 100755 --- a/etc/mkloader.pl +++ b/etc/mkloader.pl @@ -53,7 +53,7 @@ EOL pic_catch { /* error! */ xfputs(pic, "fatal error: failure in loading $dirname/$basename\\n", xstderr); - pic_raise(pic, pic->err); + pic_raise(pic, pic_err(pic)); } EOL } diff --git a/extlib/benz/cont.c b/extlib/benz/cont.c index 0df3d685..21ffde89 100644 --- a/extlib/benz/cont.c +++ b/extlib/benz/cont.c @@ -4,6 +4,7 @@ #include "picrin.h" #include "picrin/object.h" +#include "picrin/state.h" struct pic_cont { PIC_JMPBUF *jmp; diff --git a/extlib/benz/debug.c b/extlib/benz/debug.c index 21a5211d..bc96a209 100644 --- a/extlib/benz/debug.c +++ b/extlib/benz/debug.c @@ -4,6 +4,7 @@ #include "picrin.h" #include "picrin/object.h" +#include "picrin/state.h" pic_value pic_get_backtrace(pic_state *pic) @@ -36,16 +37,18 @@ pic_get_backtrace(pic_state *pic) void pic_print_backtrace(pic_state *pic, xFILE *file) { - assert(! pic_invalid_p(pic, pic->err)); + pic_value err = pic_err(pic); - if (! pic_error_p(pic, pic->err)) { + assert(! pic_invalid_p(pic, err)); + + if (! pic_error_p(pic, err)) { xfprintf(pic, file, "raise: "); - pic_fwrite(pic, pic->err, file); + pic_fwrite(pic, err, file); } else { struct pic_error *e; pic_value elem, it; - e = pic_error_ptr(pic, pic->err); + e = pic_error_ptr(pic, err); if (! pic_eq_p(pic, pic_obj_value(e->type), pic_intern_lit(pic, ""))) { pic_fwrite(pic, pic_obj_value(e->type), file); xfprintf(pic, file, " "); diff --git a/extlib/benz/error.c b/extlib/benz/error.c index 08b1808e..b750a19a 100644 --- a/extlib/benz/error.c +++ b/extlib/benz/error.c @@ -4,6 +4,7 @@ #include "picrin.h" #include "picrin/object.h" +#include "picrin/state.h" void pic_panic(pic_state PIC_UNUSED(*pic), const char *msg) @@ -98,6 +99,12 @@ pic_pop_handler(pic_state *pic) return pic_obj_value(*--pic->xp); } +pic_value +pic_err(pic_state *pic) +{ + return pic->err; +} + pic_value pic_make_error(pic_state *pic, const char *type, const char *msg, pic_value irrs) { diff --git a/extlib/benz/eval.c b/extlib/benz/eval.c index ace01513..02393339 100644 --- a/extlib/benz/eval.c +++ b/extlib/benz/eval.c @@ -5,6 +5,7 @@ #include "picrin.h" #include "picrin/object.h" #include "picrin/opcode.h" +#include "picrin/state.h" static pic_value optimize_beta(pic_state *pic, pic_value expr) @@ -891,7 +892,7 @@ pic_eval(pic_state *pic, pic_value program, const char *lib) } pic_catch { pic_in_library(pic, prev_lib); - pic_raise(pic, pic->err); + pic_raise(pic, pic_err(pic)); } pic_in_library(pic, prev_lib); diff --git a/extlib/benz/file.c b/extlib/benz/file.c index ac6f231b..bdb2e840 100644 --- a/extlib/benz/file.c +++ b/extlib/benz/file.c @@ -1,4 +1,9 @@ +/** + * See Copyright Notice in picrin.h + */ + #include "picrin.h" +#include "picrin/state.h" #ifndef EOF # define EOF (-1) diff --git a/extlib/benz/gc.c b/extlib/benz/gc.c index d7813799..a7fe6338 100644 --- a/extlib/benz/gc.c +++ b/extlib/benz/gc.c @@ -4,6 +4,7 @@ #include "picrin.h" #include "picrin/object.h" +#include "picrin/state.h" enum { WHITE = 0, diff --git a/extlib/benz/include/picrin.h b/extlib/benz/include/picrin.h index 72c82833..0bfd26e2 100644 --- a/extlib/benz/include/picrin.h +++ b/extlib/benz/include/picrin.h @@ -98,7 +98,6 @@ void pic_export(pic_state *, pic_value 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); pic_value pic_lambda(pic_state *, pic_func_t f, int n, ...); @@ -296,8 +295,6 @@ int xvfprintf(pic_state *, xFILE *fp, const char *fmt, va_list); /* extra stuff */ -#include "picrin/state.h" - void *pic_default_allocf(void *, void *, size_t); #define pic_assert_type(pic, v, type) \ @@ -355,6 +352,8 @@ void pic_exit_point(pic_state *); /* do not return from try block! */ +pic_value pic_err(pic_state *); + #define pic_try \ pic_try_(PIC_GENSYM(cont), PIC_GENSYM(handler)) #define pic_catch \ @@ -376,6 +375,8 @@ void pic_exit_point(pic_state *); if (0) \ label: +PIC_NORETURN void pic_error(pic_state *, const char *type, const char *msg, pic_value irrs); + #define pic_for_each(var, list, it) \ for (it = (list); ! pic_nil_p(pic, it); it = pic_cdr(pic, it)) \ if ((var = pic_car(pic, it)), true) diff --git a/extlib/benz/include/picrin/object.h b/extlib/benz/include/picrin/object.h index 397740d3..761d13f9 100644 --- a/extlib/benz/include/picrin/object.h +++ b/extlib/benz/include/picrin/object.h @@ -9,6 +9,8 @@ extern "C" { #endif +#include "picrin/khash.h" + typedef struct pic_identifier pic_id; typedef pic_id pic_sym; diff --git a/extlib/benz/lib.c b/extlib/benz/lib.c index a7e9336a..63ea7a93 100644 --- a/extlib/benz/lib.c +++ b/extlib/benz/lib.c @@ -4,6 +4,7 @@ #include "picrin.h" #include "picrin/object.h" +#include "picrin/state.h" KHASH_DEFINE(ltable, const char *, struct pic_lib, kh_str_hash_func, kh_str_cmp_func) diff --git a/extlib/benz/load.c b/extlib/benz/load.c index 2ceefa11..7272c000 100644 --- a/extlib/benz/load.c +++ b/extlib/benz/load.c @@ -27,7 +27,7 @@ pic_load_cstr(pic_state *pic, const char *str) } pic_catch { pic_close_port(pic, port); - pic_raise(pic, pic->err); + pic_raise(pic, pic_err(pic)); } pic_close_port(pic, port); diff --git a/extlib/benz/macro.c b/extlib/benz/macro.c index 6825aa62..2f8dc9cd 100644 --- a/extlib/benz/macro.c +++ b/extlib/benz/macro.c @@ -4,6 +4,7 @@ #include "picrin.h" #include "picrin/object.h" +#include "picrin/state.h" KHASH_DEFINE(env, pic_id *, pic_sym *, kh_ptr_hash_func, kh_ptr_hash_equal) diff --git a/extlib/benz/port.c b/extlib/benz/port.c index 6933c07a..af8a1f5b 100644 --- a/extlib/benz/port.c +++ b/extlib/benz/port.c @@ -4,6 +4,7 @@ #include "picrin.h" #include "picrin/object.h" +#include "picrin/file.h" #undef EOF #define EOF (-1) diff --git a/extlib/benz/proc.c b/extlib/benz/proc.c index 3a0c70ae..5182a6b5 100644 --- a/extlib/benz/proc.c +++ b/extlib/benz/proc.c @@ -5,6 +5,7 @@ #include "picrin.h" #include "picrin/object.h" #include "picrin/opcode.h" +#include "picrin/state.h" #define MIN(x,y) ((x) < (y) ? (x) : (y)) diff --git a/extlib/benz/read.c b/extlib/benz/read.c index 86991f82..39404653 100644 --- a/extlib/benz/read.c +++ b/extlib/benz/read.c @@ -4,6 +4,7 @@ #include "picrin.h" #include "picrin/object.h" +#include "picrin/state.h" #undef EOF #define EOF (-1) @@ -852,7 +853,7 @@ pic_read_cstr(pic_state *pic, const char *str) } pic_catch { pic_close_port(pic, port); - pic_raise(pic, pic->err); + pic_raise(pic, pic_err(pic)); } pic_close_port(pic, port); diff --git a/extlib/benz/state.c b/extlib/benz/state.c index 58e35526..afd0c412 100644 --- a/extlib/benz/state.c +++ b/extlib/benz/state.c @@ -4,6 +4,7 @@ #include "picrin.h" #include "picrin/object.h" +#include "picrin/state.h" static void pic_init_features(pic_state *pic) diff --git a/extlib/benz/symbol.c b/extlib/benz/symbol.c index 20941f70..b073421e 100644 --- a/extlib/benz/symbol.c +++ b/extlib/benz/symbol.c @@ -4,6 +4,7 @@ #include "picrin.h" #include "picrin/object.h" +#include "picrin/state.h" #define kh_pic_str_hash(a) (pic_str_hash(pic, pic_obj_value(a))) #define kh_pic_str_cmp(a, b) (pic_str_cmp(pic, pic_obj_value(a), pic_obj_value(b)) == 0) diff --git a/extlib/benz/var.c b/extlib/benz/var.c index 6f59c0c7..df5ee003 100644 --- a/extlib/benz/var.c +++ b/extlib/benz/var.c @@ -4,6 +4,7 @@ #include "picrin.h" #include "picrin/object.h" +#include "picrin/state.h" static pic_value var_get(pic_state *pic, pic_value var) diff --git a/extlib/benz/write.c b/extlib/benz/write.c index 8d2276ed..d9822db3 100644 --- a/extlib/benz/write.c +++ b/extlib/benz/write.c @@ -4,6 +4,7 @@ #include "picrin.h" #include "picrin/object.h" +#include "picrin/state.h" KHASH_DECLARE(l, void *, int) KHASH_DECLARE(v, void *, int)