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