pic_catch binds current error object to a variable
This commit is contained in:
parent
73e38657ff
commit
8a9a1200d8
|
@ -39,6 +39,8 @@ print <<EOL;
|
||||||
void
|
void
|
||||||
pic_load_piclib(pic_state *pic)
|
pic_load_piclib(pic_state *pic)
|
||||||
{
|
{
|
||||||
|
pic_value e;
|
||||||
|
|
||||||
EOL
|
EOL
|
||||||
|
|
||||||
foreach my $file (@ARGV) {
|
foreach my $file (@ARGV) {
|
||||||
|
@ -51,10 +53,10 @@ EOL
|
||||||
print " pic_load_cstr(pic, &${var}[0][0]);\n";
|
print " pic_load_cstr(pic, &${var}[0][0]);\n";
|
||||||
print<<EOL
|
print<<EOL
|
||||||
}
|
}
|
||||||
pic_catch {
|
pic_catch(e) {
|
||||||
/* error! */
|
/* error! */
|
||||||
xfputs(pic, "fatal error: failure in loading $dirname/$basename\\n", xstderr);
|
xfputs(pic, "fatal error: failure in loading $dirname/$basename\\n", xstderr);
|
||||||
pic_raise(pic, pic_err(pic));
|
pic_raise(pic, e);
|
||||||
}
|
}
|
||||||
EOL
|
EOL
|
||||||
}
|
}
|
||||||
|
|
|
@ -1083,7 +1083,7 @@ pic_value
|
||||||
pic_eval(pic_state *pic, pic_value program, const char *lib)
|
pic_eval(pic_state *pic, pic_value program, const char *lib)
|
||||||
{
|
{
|
||||||
const char *prev_lib = pic_current_library(pic);
|
const char *prev_lib = pic_current_library(pic);
|
||||||
pic_value env, r;
|
pic_value env, r, e;
|
||||||
|
|
||||||
env = pic_library_environment(pic, lib);
|
env = pic_library_environment(pic, lib);
|
||||||
|
|
||||||
|
@ -1091,9 +1091,9 @@ pic_eval(pic_state *pic, pic_value program, const char *lib)
|
||||||
pic_try {
|
pic_try {
|
||||||
r = pic_call(pic, pic_compile(pic, pic_expand(pic, program, env)), 0);
|
r = pic_call(pic, pic_compile(pic, pic_expand(pic, program, env)), 0);
|
||||||
}
|
}
|
||||||
pic_catch {
|
pic_catch(e) {
|
||||||
pic_in_library(pic, prev_lib);
|
pic_in_library(pic, prev_lib);
|
||||||
pic_raise(pic, pic_err(pic));
|
pic_raise(pic, e);
|
||||||
}
|
}
|
||||||
pic_in_library(pic, prev_lib);
|
pic_in_library(pic, prev_lib);
|
||||||
|
|
||||||
|
|
|
@ -78,21 +78,21 @@ xFILE *xfopen_null(pic_state *, const char *mode);
|
||||||
do { \
|
do { \
|
||||||
extern pic_value pic_start_try(pic_state *, PIC_JMPBUF *); \
|
extern pic_value pic_start_try(pic_state *, PIC_JMPBUF *); \
|
||||||
extern void pic_end_try(pic_state *, pic_value); \
|
extern void pic_end_try(pic_state *, pic_value); \
|
||||||
|
extern pic_value pic_err(pic_state *); \
|
||||||
PIC_JMPBUF jmp; \
|
PIC_JMPBUF jmp; \
|
||||||
if (PIC_SETJMP(pic, jmp) == 0) { \
|
if (PIC_SETJMP(pic, jmp) == 0) { \
|
||||||
pic_value pic_try_cookie_ = pic_start_try(pic, &jmp);
|
pic_value pic_try_cookie_ = pic_start_try(pic, &jmp);
|
||||||
#define pic_catch pic_catch_(PIC_GENSYM(label))
|
#define pic_catch(e) pic_catch_(e, PIC_GENSYM(label))
|
||||||
#define pic_catch_(label) \
|
#define pic_catch_(e, label) \
|
||||||
pic_end_try(pic, pic_try_cookie_); \
|
pic_end_try(pic, pic_try_cookie_); \
|
||||||
} else { \
|
} else { \
|
||||||
|
e = pic_err(pic); \
|
||||||
goto label; \
|
goto label; \
|
||||||
} \
|
} \
|
||||||
} while (0); \
|
} while (0); \
|
||||||
if (0) \
|
if (0) \
|
||||||
label:
|
label:
|
||||||
|
|
||||||
pic_value pic_err(pic_state *);
|
|
||||||
|
|
||||||
/* for debug */
|
/* for debug */
|
||||||
|
|
||||||
void pic_warnf(pic_state *, const char *, ...);
|
void pic_warnf(pic_state *, const char *, ...);
|
||||||
|
|
|
@ -21,14 +21,14 @@ pic_load(pic_state *pic, pic_value port)
|
||||||
void
|
void
|
||||||
pic_load_cstr(pic_state *pic, const char *str)
|
pic_load_cstr(pic_state *pic, const char *str)
|
||||||
{
|
{
|
||||||
pic_value port = pic_open_port(pic, xfopen_buf(pic, str, strlen(str), "r"));
|
pic_value e, port = pic_open_port(pic, xfopen_buf(pic, str, strlen(str), "r"));
|
||||||
|
|
||||||
pic_try {
|
pic_try {
|
||||||
pic_load(pic, port);
|
pic_load(pic, port);
|
||||||
}
|
}
|
||||||
pic_catch {
|
pic_catch(e) {
|
||||||
pic_close_port(pic, port);
|
pic_close_port(pic, port);
|
||||||
pic_raise(pic, pic_err(pic));
|
pic_raise(pic, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
pic_close_port(pic, port);
|
pic_close_port(pic, port);
|
||||||
|
|
|
@ -255,7 +255,7 @@ pic_number_string_to_number(pic_state *pic)
|
||||||
int radix = 10;
|
int radix = 10;
|
||||||
long num;
|
long num;
|
||||||
char *eptr;
|
char *eptr;
|
||||||
pic_value flo;
|
pic_value flo, e;
|
||||||
|
|
||||||
pic_get_args(pic, "z|i", &str, &radix);
|
pic_get_args(pic, "z|i", &str, &radix);
|
||||||
|
|
||||||
|
@ -269,7 +269,7 @@ pic_number_string_to_number(pic_state *pic)
|
||||||
pic_try {
|
pic_try {
|
||||||
flo = pic_read_cstr(pic, str);
|
flo = pic_read_cstr(pic, str);
|
||||||
}
|
}
|
||||||
pic_catch {
|
pic_catch(e) {
|
||||||
/* swallow error */
|
/* swallow error */
|
||||||
flo = pic_false_value(pic);
|
flo = pic_false_value(pic);
|
||||||
}
|
}
|
||||||
|
|
|
@ -836,6 +836,7 @@ pic_read(pic_state *pic, pic_value port)
|
||||||
pic_value val;
|
pic_value val;
|
||||||
xFILE *file = pic_fileno(pic, port);
|
xFILE *file = pic_fileno(pic, port);
|
||||||
int c;
|
int c;
|
||||||
|
pic_value e;
|
||||||
|
|
||||||
reader_init(pic, &p);
|
reader_init(pic, &p);
|
||||||
|
|
||||||
|
@ -852,9 +853,9 @@ pic_read(pic_state *pic, pic_value port)
|
||||||
val = pic_eof_object(pic);
|
val = pic_eof_object(pic);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pic_catch {
|
pic_catch(e) {
|
||||||
reader_destroy(pic, &p);
|
reader_destroy(pic, &p);
|
||||||
pic_raise(pic, pic_err(pic));
|
pic_raise(pic, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
pic_leave(pic, ai);
|
pic_leave(pic, ai);
|
||||||
|
@ -865,14 +866,14 @@ pic_value
|
||||||
pic_read_cstr(pic_state *pic, const char *str)
|
pic_read_cstr(pic_state *pic, const char *str)
|
||||||
{
|
{
|
||||||
pic_value port = pic_open_port(pic, xfopen_buf(pic, str, strlen(str), "r"));
|
pic_value port = pic_open_port(pic, xfopen_buf(pic, str, strlen(str), "r"));
|
||||||
pic_value form;
|
pic_value form, e;
|
||||||
|
|
||||||
pic_try {
|
pic_try {
|
||||||
form = pic_read(pic, port);
|
form = pic_read(pic, port);
|
||||||
}
|
}
|
||||||
pic_catch {
|
pic_catch(e) {
|
||||||
pic_close_port(pic, port);
|
pic_close_port(pic, port);
|
||||||
pic_raise(pic, pic_err(pic));
|
pic_raise(pic, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
pic_close_port(pic, port);
|
pic_close_port(pic, port);
|
||||||
|
|
|
@ -26,6 +26,7 @@ main(int argc, char *argv[], char **envp)
|
||||||
{
|
{
|
||||||
char t;
|
char t;
|
||||||
pic_state *pic;
|
pic_state *pic;
|
||||||
|
pic_value e;
|
||||||
int status;
|
int status;
|
||||||
|
|
||||||
pic = pic_open(pic_default_allocf, NULL);
|
pic = pic_open(pic_default_allocf, NULL);
|
||||||
|
@ -43,7 +44,7 @@ main(int argc, char *argv[], char **envp)
|
||||||
|
|
||||||
status = 0;
|
status = 0;
|
||||||
}
|
}
|
||||||
pic_catch {
|
pic_catch(e) {
|
||||||
pic_print_error(pic, xstderr);
|
pic_print_error(pic, xstderr);
|
||||||
status = 1;
|
status = 1;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue