From 4f8aa03b24894b2241a691b78aca73e5fc3f992d Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Sun, 20 Oct 2013 17:41:48 +0900 Subject: [PATCH] clarify the meanings of error functions --- include/picrin.h | 4 +++- src/codegen.c | 6 +++--- src/error.c | 4 ++-- src/gc.c | 12 ++++++------ 4 files changed, 14 insertions(+), 12 deletions(-) diff --git a/include/picrin.h b/include/picrin.h index 3c5c0c84..0af29e40 100644 --- a/include/picrin.h +++ b/include/picrin.h @@ -66,7 +66,9 @@ pic_value pic_eval(pic_state *, pic_value, struct pic_env *); pic_value pic_run(pic_state *, struct pic_proc *, pic_value); struct pic_proc *pic_codegen(pic_state *, pic_value, struct pic_env *); -void pic_raise(pic_state *, const char *); +void pic_abort(pic_state *, const char *); +void pic_raise(pic_state *, pic_value); +void pic_error(pic_state *, const char *, ...); void pic_debug(pic_state *, pic_value); diff --git a/src/codegen.c b/src/codegen.c index 38993077..5ec0c652 100644 --- a/src/codegen.c +++ b/src/codegen.c @@ -204,7 +204,7 @@ pic_gen(pic_state *pic, struct pic_irep *irep, pic_value obj, struct pic_env *en b = env_lookup(pic, obj, env, &depth, &idx); if (! b) { - pic_raise(pic, "unbound variable"); + pic_abort(pic, "unbound variable"); } if (depth == -1) { /* global */ @@ -218,7 +218,7 @@ pic_gen(pic_state *pic, struct pic_irep *irep, pic_value obj, struct pic_env *en irep->clen++; } else { /* nonlocal */ - pic_raise(pic, "reference to closed variable not supported"); + pic_abort(pic, "reference to closed variable not supported"); } break; } @@ -362,7 +362,7 @@ pic_gen(pic_state *pic, struct pic_irep *irep, pic_value obj, struct pic_env *en case PIC_TT_PROC: case PIC_TT_UNDEF: case PIC_TT_PORT: { - pic_raise(pic, "invalid expression given"); + pic_abort(pic, "invalid expression given"); } } } diff --git a/src/error.c b/src/error.c index 9efcea1d..5ac13860 100644 --- a/src/error.c +++ b/src/error.c @@ -4,8 +4,8 @@ #include "picrin.h" void -pic_raise(pic_state *pic, const char *str) +pic_abort(pic_state *pic, const char *msg) { - puts(str); + puts(msg); abort(); } diff --git a/src/gc.c b/src/gc.c index dc9fa2da..4884c3b3 100644 --- a/src/gc.c +++ b/src/gc.c @@ -40,7 +40,7 @@ pic_alloc(pic_state *pic, size_t size) ptr = malloc(size); if (ptr == NULL) { - pic_raise(pic, "memory exhausted"); + pic_abort(pic, "memory exhausted"); } return ptr; } @@ -50,7 +50,7 @@ pic_realloc(pic_state *pic, void *ptr, size_t size) { ptr = realloc(ptr, size); if (ptr == NULL) { - pic_raise(pic, "memory exhausted"); + pic_abort(pic, "memory exhausted"); } return ptr; } @@ -65,7 +65,7 @@ static void gc_protect(pic_state *pic, struct pic_object *obj) { if (pic->arena_idx >= PIC_ARENA_SIZE) { - pic_raise(pic, "arena overflow"); + pic_abort(pic, "arena overflow"); } pic->arena[pic->arena_idx++] = obj; } @@ -149,7 +149,7 @@ gc_mark_object(pic_state *pic, struct pic_object *obj) break; } default: - pic_raise(pic, "logic flaw"); + pic_abort(pic, "logic flaw"); } } @@ -243,7 +243,7 @@ gc_finalize_object(pic_state *pic, struct pic_object *obj) break; } default: - pic_raise(pic, "logic flaw"); + pic_abort(pic, "logic flaw"); } } @@ -349,7 +349,7 @@ pic_obj_alloc(pic_state *pic, size_t size, enum pic_tt tt) pic_gc_run(pic); obj = (struct pic_object *)gc_alloc(pic, size); if (obj == NULL) - pic_raise(pic, "GC memory exhausted"); + pic_abort(pic, "GC memory exhausted"); } obj->tt = tt;