From 4905aab41640b73a1aee1c37788f68049b229051 Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Thu, 2 Jul 2015 08:50:10 +0900 Subject: [PATCH] remove pic->file and pic->read --- contrib/20.r7rs/src/file.c | 2 +- extlib/benz/gc.c | 7 ++----- extlib/benz/include/picrin.h | 1 - extlib/benz/port.c | 13 +++++++++++-- extlib/benz/read.c | 2 +- extlib/benz/state.c | 2 -- 6 files changed, 15 insertions(+), 12 deletions(-) diff --git a/contrib/20.r7rs/src/file.c b/contrib/20.r7rs/src/file.c index 340a5e6d..dd94803c 100644 --- a/contrib/20.r7rs/src/file.c +++ b/contrib/20.r7rs/src/file.c @@ -11,7 +11,7 @@ file_error(pic_state *pic, const char *msg) { struct pic_error *e; - e = pic_make_error(pic, pic->sFILE, msg, pic_nil_value()); + e = pic_make_error(pic, pic_intern_cstr(pic, "file"), msg, pic_nil_value()); pic_raise(pic, pic_obj_value(e)); } diff --git a/extlib/benz/gc.c b/extlib/benz/gc.c index d9bda339..d2849dc0 100644 --- a/extlib/benz/gc.c +++ b/extlib/benz/gc.c @@ -524,15 +524,12 @@ gc_mark_global_symbols(pic_state *pic) M(sQUOTE); M(sQUASIQUOTE); M(sUNQUOTE); M(sUNQUOTE_SPLICING); M(sSYNTAX_QUOTE); M(sSYNTAX_QUASIQUOTE); M(sSYNTAX_UNQUOTE); M(sSYNTAX_UNQUOTE_SPLICING); M(sDEFINE_LIBRARY); M(sIMPORT); M(sEXPORT); M(sCOND_EXPAND); - M(sREAD); M(sFILE); M(sCALL); M(sGREF); M(sLREF); M(sCREF); M(uDEFINE); M(uLAMBDA); M(uIF); M(uBEGIN); M(uQUOTE); M(uSETBANG); M(uDEFINE_MACRO); M(uDEFINE_LIBRARY); M(uIMPORT); M(uEXPORT); M(uCOND_EXPAND); - M(uCONS); M(uCAR); M(uCDR); M(uNILP); - M(uSYMBOLP); M(uPAIRP); - M(uADD); M(uSUB); M(uMUL); M(uDIV); - M(uEQ); M(uLT); M(uLE); M(uGT); M(uGE); M(uNOT); + M(uCONS); M(uCAR); M(uCDR); M(uNILP); M(uSYMBOLP); M(uPAIRP); + M(uADD); M(uSUB); M(uMUL); M(uDIV); M(uEQ); M(uLT); M(uLE); M(uGT); M(uGE); M(uNOT); M(uVALUES); M(uCALL_WITH_VALUES); } diff --git a/extlib/benz/include/picrin.h b/extlib/benz/include/picrin.h index a52fad61..45b8a22d 100644 --- a/extlib/benz/include/picrin.h +++ b/extlib/benz/include/picrin.h @@ -99,7 +99,6 @@ struct pic_state { pic_sym *sSYNTAX_QUOTE, *sSYNTAX_QUASIQUOTE, *sSYNTAX_UNQUOTE, *sSYNTAX_UNQUOTE_SPLICING; pic_sym *sDEFINE_LIBRARY, *sIMPORT, *sEXPORT, *sCOND_EXPAND; pic_sym *sGREF, *sCREF, *sLREF, *sCALL; - pic_sym *sREAD, *sFILE; pic_sym *uDEFINE, *uLAMBDA, *uIF, *uBEGIN, *uQUOTE, *uSETBANG, *uDEFINE_MACRO; pic_sym *uDEFINE_LIBRARY, *uIMPORT, *uEXPORT, *uCOND_EXPAND; diff --git a/extlib/benz/port.c b/extlib/benz/port.c index bc5ab406..337d0ecd 100644 --- a/extlib/benz/port.c +++ b/extlib/benz/port.c @@ -98,6 +98,16 @@ file_open(pic_state *pic, const char *name, const char *mode) { } } +PIC_NORETURN static void +file_error(pic_state *pic, const char *msg) +{ + struct pic_error *e; + + e = pic_make_error(pic, pic_intern_cstr(pic, "file"), msg, pic_nil_value()); + + pic_raise(pic, pic_obj_value(e)); +} + struct pic_port * pic_open_file(pic_state *pic, const char *name, int flags) { struct pic_port *port; @@ -108,8 +118,7 @@ pic_open_file(pic_state *pic, const char *name, int flags) { mode = 'w'; } if ((file = file_open(pic, name, &mode)) == NULL) { - pic_str *msg = pic_format(pic, "could not open file '%s'", name); - pic_raise(pic, pic_obj_value(pic_make_error(pic, pic->sFILE, pic_str_cstr(pic, msg), pic_nil_value()))); + file_error(pic, pic_str_cstr(pic, pic_format(pic, "could not open file '%s'", name))); } port = (struct pic_port *)pic_obj_alloc(pic, sizeof(struct pic_port), PIC_TT_PORT); diff --git a/extlib/benz/read.c b/extlib/benz/read.c index c7abf434..537437d0 100644 --- a/extlib/benz/read.c +++ b/extlib/benz/read.c @@ -14,7 +14,7 @@ read_error(pic_state *pic, const char *msg) { struct pic_error *e; - e = pic_make_error(pic, pic->sREAD, msg, pic_nil_value()); + e = pic_make_error(pic, pic_intern_cstr(pic, "read"), msg, pic_nil_value()); pic_raise(pic, pic_obj_value(e)); } diff --git a/extlib/benz/state.c b/extlib/benz/state.c index ed2751bf..c06474f1 100644 --- a/extlib/benz/state.c +++ b/extlib/benz/state.c @@ -314,8 +314,6 @@ pic_open(pic_allocf allocf, void *userdata) S(sEXPORT, "export"); S(sDEFINE_LIBRARY, "define-library"); S(sCOND_EXPAND, "cond-expand"); - S(sREAD, "read"); - S(sFILE, "file"); S(sCALL, "call"); S(sGREF, "gref"); S(sLREF, "lref");