safer names for utility macros

This commit is contained in:
Yuichi Nishiwaki 2015-01-07 13:11:48 -08:00
parent 569b1ace02
commit c611258760
17 changed files with 76 additions and 75 deletions

View File

@ -492,7 +492,7 @@ analyze_if(analyze_state *state, pic_value obj, bool tailpos)
pic_errorf(pic, "syntax error");
case 4:
if_false = pic_list_ref(pic, obj, 3);
FALLTHROUGH;
PIC_FALLTHROUGH;
case 3:
if_true = pic_list_ref(pic, obj, 2);
}

2
cont.c
View File

@ -93,7 +93,7 @@ pic_load_point(pic_state *pic, struct pic_escape *escape)
escape->valid = false;
}
noreturn static pic_value
static pic_value
escape_call(pic_state *pic)
{
size_t argc;

8
dict.c
View File

@ -14,7 +14,7 @@ xh_value_hash(const void *key, void *data)
pic_value val = *(pic_value *)key;
int hash, vtype;
UNUSED(data);
PIC_UNUSED(data);
vtype = pic_vtype(val);
@ -96,7 +96,7 @@ pic_dict_ref(pic_state *pic, struct pic_dict *dict, pic_value key)
void
pic_dict_set(pic_state *pic, struct pic_dict *dict, pic_value key, pic_value val)
{
UNUSED(pic);
PIC_UNUSED(pic);
xh_put_value(&dict->hash, key, &val);
}
@ -104,7 +104,7 @@ pic_dict_set(pic_state *pic, struct pic_dict *dict, pic_value key, pic_value val
size_t
pic_dict_size(pic_state *pic, struct pic_dict *dict)
{
UNUSED(pic);
PIC_UNUSED(pic);
return dict->hash.count;
}
@ -112,7 +112,7 @@ pic_dict_size(pic_state *pic, struct pic_dict *dict)
bool
pic_dict_has(pic_state *pic, struct pic_dict *dict, pic_value key)
{
UNUSED(pic);
PIC_UNUSED(pic);
return xh_get_value(&dict->hash, key) != NULL;
}

16
error.c
View File

@ -17,7 +17,7 @@
void
pic_panic(pic_state *pic, const char *msg)
{
UNUSED(pic);
PIC_UNUSED(pic);
fprintf(stderr, "abort: %s\n", msg);
abort();
@ -69,7 +69,7 @@ pic_errmsg(pic_state *pic)
return pic_str_cstr(str);
}
noreturn static pic_value
static pic_value
native_exception_handler(pic_state *pic)
{
pic_value err;
@ -83,7 +83,7 @@ native_exception_handler(pic_state *pic)
pic_apply1(pic, cont, pic_false_value());
UNREACHABLE();
PIC_UNREACHABLE();
}
void
@ -166,7 +166,7 @@ pic_raise_continuable(pic_state *pic, pic_value err)
return v;
}
noreturn void
void
pic_raise(pic_state *pic, pic_value err)
{
pic_value val;
@ -178,7 +178,7 @@ pic_raise(pic_state *pic, pic_value err)
pic_errorf(pic, "error handler returned with ~s on error ~s", val, err);
}
noreturn void
void
pic_throw(pic_state *pic, pic_sym type, const char *msg, pic_value irrs)
{
struct pic_error *e;
@ -188,7 +188,7 @@ pic_throw(pic_state *pic, pic_sym type, const char *msg, pic_value irrs)
pic_raise(pic, pic_obj_value(e));
}
noreturn void
void
pic_error(pic_state *pic, const char *msg, pic_value irrs)
{
pic_throw(pic, pic_intern_cstr(pic, ""), msg, irrs);
@ -221,7 +221,7 @@ pic_error_with_exception_handler(pic_state *pic)
return val;
}
noreturn static pic_value
static pic_value
pic_error_raise(pic_state *pic)
{
pic_value v;
@ -241,7 +241,7 @@ pic_error_raise_continuable(pic_state *pic)
return pic_raise_continuable(pic, v);
}
noreturn static pic_value
static pic_value
pic_error_error(pic_state *pic)
{
const char *str;

2
file.c
View File

@ -6,7 +6,7 @@
#include "picrin/port.h"
#include "picrin/error.h"
static noreturn void
pic_noreturn static void
file_error(pic_state *pic, const char *msg)
{
pic_throw(pic, pic->sFILE, msg, pic_nil_value());

2
gc.c
View File

@ -170,7 +170,7 @@ pic_calloc(pic_state *pic, size_t count, size_t size)
void
pic_free(pic_state *pic, void *ptr)
{
UNUSED(pic);
PIC_UNUSED(pic);
free(ptr);
}

View File

@ -141,7 +141,7 @@ pic_value pic_gc_protect(pic_state *, pic_value);
size_t pic_gc_arena_preserve(pic_state *);
void pic_gc_arena_restore(pic_state *, size_t);
#define pic_void(exec) \
pic_void_(GENSYM(ai), exec)
pic_void_(PIC_GENSYM(ai), exec)
#define pic_void_(ai,exec) do { \
size_t ai = pic_gc_arena_preserve(pic); \
exec; \
@ -202,7 +202,7 @@ struct pic_lib *pic_open_library(pic_state *, pic_value);
struct pic_lib *pic_find_library(pic_state *, pic_value);
#define pic_deflibrary(pic, spec) \
pic_deflibrary_helper_(pic, GENSYM(i), GENSYM(prev_lib), spec)
pic_deflibrary_helper_(pic, PIC_GENSYM(i), PIC_GENSYM(prev_lib), spec)
#define pic_deflibrary_helper_(pic, i, prev_lib, spec) \
for (int i = 0; ! i; ) \
for (struct pic_lib *prev_lib; ! i; ) \
@ -212,8 +212,8 @@ void pic_import(pic_state *, pic_value);
void pic_import_library(pic_state *, struct pic_lib *);
void pic_export(pic_state *, pic_sym);
noreturn void pic_panic(pic_state *, const char *);
noreturn void pic_errorf(pic_state *, const char *, ...);
pic_noreturn void pic_panic(pic_state *, const char *);
pic_noreturn void pic_errorf(pic_state *, const char *, ...);
void pic_warnf(pic_state *, const char *, ...);
const char *pic_errmsg(pic_state *);
pic_str *pic_get_backtrace(pic_state *);

View File

@ -27,7 +27,7 @@ struct pic_error *pic_make_error(pic_state *, pic_sym, const char *, pic_list);
/* do not return from try block! */
#define pic_try \
pic_try_(GENSYM(escape))
pic_try_(PIC_GENSYM(escape))
#define pic_try_(escape) \
struct pic_escape *escape = pic_alloc(pic, sizeof(struct pic_escape)); \
pic_save_point(pic, escape); \
@ -43,9 +43,9 @@ void pic_push_try(pic_state *, struct pic_escape *);
void pic_pop_try(pic_state *);
pic_value pic_raise_continuable(pic_state *, pic_value);
noreturn void pic_raise(pic_state *, pic_value);
noreturn void pic_throw(pic_state *, pic_sym, const char *, pic_list);
noreturn void pic_error(pic_state *, const char *, pic_list);
pic_noreturn void pic_raise(pic_state *, pic_value);
pic_noreturn void pic_throw(pic_state *, pic_sym, const char *, pic_list);
pic_noreturn void pic_error(pic_state *, const char *, pic_list);
#if defined(__cplusplus)
}

View File

@ -59,9 +59,9 @@ pic_value pic_list7(pic_state *, pic_value, pic_value, pic_value, pic_value, pic
pic_value pic_list_by_array(pic_state *, size_t, pic_value *);
pic_value pic_make_list(pic_state *, size_t, pic_value);
#define pic_for_each(var, list) \
pic_for_each_helper_(var, GENSYM(tmp), list)
#define pic_for_each_helper_(var, tmp, list) \
#define pic_for_each(var, list) \
pic_for_each_helper_(var, PIC_GENSYM(tmp), list)
#define pic_for_each_helper_(var, tmp, list) \
for (pic_value tmp = (list); \
pic_nil_p(tmp) ? false : ((var = pic_car(pic, tmp)), true); \
tmp = pic_cdr(pic, tmp))

View File

@ -11,33 +11,34 @@ extern "C" {
#if __STDC_VERSION__ >= 201112L
# include <stdnoreturn.h>
# define pic_noreturn noreturn
#elif __GNUC__ || __clang__
# define noreturn __attribute__((noreturn))
# define pic_noreturn __attribute__((noreturn))
#else
# define noreturn
# define pic_noreturn
#endif
#define FALLTHROUGH ((void)0)
#define UNUSED(v) ((void)(v))
#define PIC_FALLTHROUGH ((void)0)
#define PIC_UNUSED(v) ((void)(v))
#define GENSYM2_(x,y) G##x##_##y##__
#define GENSYM1_(x,y) GENSYM2_(x,y)
#define PIC_GENSYM2_(x,y) PIC_G##x##_##y##_
#define PIC_GENSYM1_(x,y) PIC_GENSYM2_(x,y)
#if defined(__COUNTER__)
# define GENSYM(x) GENSYM1_(__COUNTER__,x)
# define PIC_GENSYM(x) PIC_GENSYM1_(__COUNTER__,x)
#else
# define GENSYM(x) GENSYM1_(__LINE__,x)
# define PIC_GENSYM(x) PIC_GENSYM1_(__LINE__,x)
#endif
#if GCC_VERSION >= 40500 || __clang__
# define UNREACHABLE() (__builtin_unreachable())
# define PIC_UNREACHABLE() (__builtin_unreachable())
#else
# include <assert.h>
# define UNREACHABLE() (assert(false))
# define PIC_UNREACHABLE() (assert(false))
#endif
#define SWAP(type,a,b) \
SWAP_HELPER_(type,GENSYM(tmp),a,b)
#define SWAP_HELPER_(type,tmp,a,b) \
#define PIC_SWAP(type,a,b) \
PIC_SWAP_HELPER_(type, PIC_GENSYM(tmp), a, b)
#define PIC_SWAP_HELPER_(type,tmp,a,b) \
do { \
type tmp = (a); \
(a) = (b); \

View File

@ -225,7 +225,7 @@ pic_type(pic_value v)
return ((struct pic_object *)pic_ptr(v))->tt;
}
UNREACHABLE();
PIC_UNREACHABLE();
}
static inline const char *
@ -279,7 +279,7 @@ pic_type_repr(enum pic_tt tt)
case PIC_TT_RECORD:
return "record";
}
UNREACHABLE();
PIC_UNREACHABLE();
}
static inline bool

View File

@ -25,7 +25,7 @@ pic_add_rename(pic_state *pic, struct pic_senv *senv, pic_sym sym)
void
pic_put_rename(pic_state *pic, struct pic_senv *senv, pic_sym sym, pic_sym rename)
{
UNUSED(pic);
PIC_UNUSED(pic);
xh_put_int(&senv->map, sym, &rename);
}
@ -35,7 +35,7 @@ pic_find_rename(pic_state *pic, struct pic_senv *senv, pic_sym sym, pic_sym *ren
{
xh_entry *e;
UNUSED(pic);
PIC_UNUSED(pic);
if ((e = xh_get_int(&senv->map, sym)) == NULL) {
return false;

2
proc.c
View File

@ -43,7 +43,7 @@ pic_proc_name(struct pic_proc *proc)
case PIC_PROC_KIND_IREP:
return proc->u.irep->name;
}
UNREACHABLE();
PIC_UNREACHABLE();
}
static pic_value

54
read.c
View File

@ -18,7 +18,7 @@
static pic_value read(pic_state *pic, struct pic_port *port, int c);
static pic_value read_nullable(pic_state *pic, struct pic_port *port, int c);
static noreturn void
pic_noreturn static void
read_error(pic_state *pic, const char *msg)
{
pic_throw(pic, pic->sREAD, msg, pic_nil_value());
@ -86,8 +86,8 @@ read_comment(pic_state *pic, struct pic_port *port, const char *str)
{
int c;
UNUSED(pic);
UNUSED(str);
PIC_UNUSED(pic);
PIC_UNUSED(str);
do {
c = next(port);
@ -102,8 +102,8 @@ read_block_comment(pic_state *pic, struct pic_port *port, const char *str)
int x, y;
int i = 1;
UNUSED(pic);
UNUSED(str);
PIC_UNUSED(pic);
PIC_UNUSED(str);
y = next(port);
@ -124,7 +124,7 @@ read_block_comment(pic_state *pic, struct pic_port *port, const char *str)
static pic_value
read_datum_comment(pic_state *pic, struct pic_port *port, const char *str)
{
UNUSED(str);
PIC_UNUSED(str);
read(pic, port, next(port));
@ -157,7 +157,7 @@ read_eval(pic_state *pic, struct pic_port *port, const char *str)
{
pic_value form;
UNUSED(str);
PIC_UNUSED(str);
form = read(pic, port, next(port));
@ -167,7 +167,7 @@ read_eval(pic_state *pic, struct pic_port *port, const char *str)
static pic_value
read_quote(pic_state *pic, struct pic_port *port, const char *str)
{
UNUSED(str);
PIC_UNUSED(str);
return pic_list2(pic, pic_sym_value(pic->sQUOTE), read(pic, port, next(port)));
}
@ -175,7 +175,7 @@ read_quote(pic_state *pic, struct pic_port *port, const char *str)
static pic_value
read_quasiquote(pic_state *pic, struct pic_port *port, const char *str)
{
UNUSED(str);
PIC_UNUSED(str);
return pic_list2(pic, pic_sym_value(pic->sQUASIQUOTE), read(pic, port, next(port)));
}
@ -183,7 +183,7 @@ read_quasiquote(pic_state *pic, struct pic_port *port, const char *str)
static pic_value
read_unquote(pic_state *pic, struct pic_port *port, const char *str)
{
UNUSED(str);
PIC_UNUSED(str);
return pic_list2(pic, pic_sym_value(pic->sUNQUOTE), read(pic, port, next(port)));
}
@ -191,7 +191,7 @@ read_unquote(pic_state *pic, struct pic_port *port, const char *str)
static pic_value
read_unquote_splicing(pic_state *pic, struct pic_port *port, const char *str)
{
UNUSED(str);
PIC_UNUSED(str);
return pic_list2(pic, pic_sym_value(pic->sUNQUOTE_SPLICING), read(pic, port, next(port)));
}
@ -354,9 +354,9 @@ read_plus(pic_state *pic, struct pic_port *port, const char *str)
static pic_value
read_true(pic_state *pic, struct pic_port *port, const char *str)
{
UNUSED(pic);
UNUSED(port);
UNUSED(str);
PIC_UNUSED(pic);
PIC_UNUSED(port);
PIC_UNUSED(str);
return pic_true_value();
}
@ -364,9 +364,9 @@ read_true(pic_state *pic, struct pic_port *port, const char *str)
static pic_value
read_false(pic_state *pic, struct pic_port *port, const char *str)
{
UNUSED(pic);
UNUSED(port);
UNUSED(str);
PIC_UNUSED(pic);
PIC_UNUSED(port);
PIC_UNUSED(str);
return pic_false_value();
}
@ -376,7 +376,7 @@ read_char(pic_state *pic, struct pic_port *port, const char *str)
{
int c;
UNUSED(str);
PIC_UNUSED(str);
c = next(port);
@ -418,7 +418,7 @@ read_string(pic_state *pic, struct pic_port *port, const char *name)
size_t size, cnt;
pic_str *str;
UNUSED(name);
PIC_UNUSED(name);
size = 256;
buf = pic_alloc(pic, size);
@ -459,7 +459,7 @@ read_pipe(pic_state *pic, struct pic_port *port, const char *str)
size_t i = 0;
int c;
UNUSED(str);
PIC_UNUSED(str);
size = 256;
buf = pic_alloc(pic, size);
@ -504,7 +504,7 @@ read_blob(pic_state *pic, struct pic_port *port, const char *str)
unsigned char *dat;
pic_blob *blob;
UNUSED(str);
PIC_UNUSED(str);
nbits = 0;
@ -631,13 +631,13 @@ read_label_set(pic_state *pic, struct pic_port *port, int i)
xh_put_int(&pic->reader->labels, i, &val);
tmp = pic_vec_ptr(read(pic, port, c));
SWAP(pic_value *, tmp->data, pic_vec_ptr(val)->data);
SWAP(size_t, tmp->len, pic_vec_ptr(val)->len);
PIC_SWAP(pic_value *, tmp->data, pic_vec_ptr(val)->data);
PIC_SWAP(size_t, tmp->len, pic_vec_ptr(val)->len);
return val;
}
FALLTHROUGH;
PIC_FALLTHROUGH;
}
default:
{
@ -655,7 +655,7 @@ read_label_ref(pic_state *pic, struct pic_port *port, int i)
{
xh_entry *e;
UNUSED(port);
PIC_UNUSED(port);
e = xh_get_int(&pic->reader->labels, i);
if (! e) {
@ -687,8 +687,8 @@ read_label(pic_state *pic, struct pic_port *port, const char *str)
static pic_value
read_unmatch(pic_state *pic, struct pic_port *port, const char *str)
{
UNUSED(port);
UNUSED(str);
PIC_UNUSED(port);
PIC_UNUSED(str);
read_error(pic, "unmatched parenthesis");
}

View File

@ -39,7 +39,7 @@ pic_record_ref(pic_state *pic, struct pic_record *rec, pic_sym slot)
void
pic_record_set(pic_state *pic, struct pic_record *rec, pic_sym slot, pic_value val)
{
UNUSED(pic);
PIC_UNUSED(pic);
xh_put_int(&rec->hash, slot, &val);
}

2
var.c
View File

@ -73,7 +73,7 @@ var_call(pic_state *pic)
return val;
}
}
UNREACHABLE();
PIC_UNREACHABLE();
}
struct pic_proc *

View File

@ -164,7 +164,7 @@ write_str(pic_state *pic, struct pic_string *str, xFILE *file)
size_t i;
const char *cstr = pic_str_cstr(str);
UNUSED(pic);
PIC_UNUSED(pic);
for (i = 0; i < pic_strlen(str); ++i) {
if (cstr[i] == '"' || cstr[i] == '\\') {