From a2b2bf18caede8abd761654d996919d655aae465 Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Wed, 29 Mar 2017 07:12:13 +0900 Subject: [PATCH] pic_obj_value -> obj_value --- contrib/10.callcc/callcc.c | 8 +++--- lib/blob.c | 2 +- lib/bool.c | 4 +-- lib/cont.c | 4 +-- lib/data.c | 2 +- lib/debug.c | 8 +++--- lib/dict.c | 4 +-- lib/error.c | 8 +++--- lib/ext/lib.c | 40 +++++++++++++------------- lib/gc.c | 4 +-- lib/pair.c | 2 +- lib/port.c | 2 +- lib/proc.c | 10 +++---- lib/record.c | 2 +- lib/string.c | 2 +- lib/symbol.c | 20 ++++++------- lib/value.h | 58 ++++++++++++++++++++++++++++++++------ lib/vector.c | 2 +- lib/weak.c | 2 +- 19 files changed, 113 insertions(+), 71 deletions(-) diff --git a/contrib/10.callcc/callcc.c b/contrib/10.callcc/callcc.c index 6821efe9..50513b38 100644 --- a/contrib/10.callcc/callcc.c +++ b/contrib/10.callcc/callcc.c @@ -56,10 +56,10 @@ cont_mark(pic_state *pic, void *data, void (*mark)(pic_state *, pic_value)) /* checkpoint */ for (cp = cont->cp; cp != NULL; cp = cp->prev) { if (cp->in) { - mark(pic, pic_obj_value(cp->in)); + mark(pic, obj_value(cp->in)); } if (cp->out) { - mark(pic, pic_obj_value(cp->out)); + mark(pic, obj_value(cp->out)); } } @@ -71,13 +71,13 @@ cont_mark(pic_state *pic, void *data, void (*mark)(pic_state *, pic_value)) /* callinfo */ for (ci = cont->ci_ptr + cont->ci_offset; ci != cont->ci_ptr; --ci) { if (ci->cxt) { - mark(pic, pic_obj_value(ci->cxt)); + mark(pic, obj_value(ci->cxt)); } } /* arena */ for (i = 0; i < cont->arena_idx; ++i) { - mark(pic, pic_obj_value(cont->arena[i])); + mark(pic, obj_value(cont->arena[i])); } } diff --git a/lib/blob.c b/lib/blob.c index 06420357..f70ae92c 100644 --- a/lib/blob.c +++ b/lib/blob.c @@ -17,7 +17,7 @@ pic_blob_value(pic_state *pic, const unsigned char *buf, int len) if (buf) { memcpy(bv->data, buf, len); } - return pic_obj_value(bv); + return obj_value(bv); } unsigned char * diff --git a/lib/bool.c b/lib/bool.c index ce9ecd29..73c94b67 100644 --- a/lib/bool.c +++ b/lib/bool.c @@ -101,8 +101,8 @@ internal_equal_p(pic_state *pic, pic_value x, pic_value y, int depth, khash_t(m) id1 = pic_id_ptr(pic, x); id2 = pic_id_ptr(pic, y); - s1 = pic_find_identifier(pic, pic_obj_value(id1->u.id), pic_obj_value(id1->env)); - s2 = pic_find_identifier(pic, pic_obj_value(id2->u.id), pic_obj_value(id2->env)); + s1 = pic_find_identifier(pic, obj_value(id1->u.id), obj_value(id1->env)); + s2 = pic_find_identifier(pic, obj_value(id2->u.id), obj_value(id2->env)); return pic_eq_p(pic, s1, s2); } diff --git a/lib/cont.c b/lib/cont.c index 61ab7696..e488d464 100644 --- a/lib/cont.c +++ b/lib/cont.c @@ -70,10 +70,10 @@ pic_wind(pic_state *pic, struct checkpoint *here, struct checkpoint *there) if (here->depth < there->depth) { pic_wind(pic, here, there->prev); - pic_call(pic, pic_obj_value(there->in), 0); + pic_call(pic, obj_value(there->in), 0); } else { - pic_call(pic, pic_obj_value(here->out), 0); + pic_call(pic, obj_value(here->out), 0); pic_wind(pic, here->prev, there); } } diff --git a/lib/data.c b/lib/data.c index 05c9a4f3..6e063da1 100644 --- a/lib/data.c +++ b/lib/data.c @@ -30,5 +30,5 @@ pic_data_value(pic_state *pic, void *userdata, const pic_data_type *type) data->type = type; data->data = userdata; - return pic_obj_value(data); + return obj_value(data); } diff --git a/lib/debug.c b/lib/debug.c index f5dd3601..7ba559fd 100644 --- a/lib/debug.c +++ b/lib/debug.c @@ -47,15 +47,15 @@ pic_print_error(pic_state *pic, pic_value port, pic_value err) pic_value elem, it; e = pic_error_ptr(pic, err); - if (! pic_eq_p(pic, pic_obj_value(e->type), pic_intern_lit(pic, ""))) { - pic_fprintf(pic, port, "~s-", pic_obj_value(e->type)); + if (! pic_eq_p(pic, obj_value(e->type), pic_intern_lit(pic, ""))) { + pic_fprintf(pic, port, "~s-", obj_value(e->type)); } - pic_fprintf(pic, port, "error: ~s", pic_obj_value(e->msg)); + pic_fprintf(pic, port, "error: ~s", obj_value(e->msg)); pic_for_each (elem, e->irrs, it) { /* print error irritants */ pic_fprintf(pic, port, " ~s", elem); } - pic_fprintf(pic, port, "\n%s", pic_str(pic, pic_obj_value(e->stack), NULL)); + pic_fprintf(pic, port, "\n%s", pic_str(pic, obj_value(e->stack), NULL)); } } diff --git a/lib/dict.c b/lib/dict.c index d2c4abdf..d579cf2b 100644 --- a/lib/dict.c +++ b/lib/dict.c @@ -15,7 +15,7 @@ pic_make_dict(pic_state *pic) dict = (struct dict *)pic_obj_alloc(pic, sizeof(struct dict), PIC_TYPE_DICT); kh_init(dict, &dict->hash); - return pic_obj_value(dict); + return obj_value(dict); } pic_value @@ -77,7 +77,7 @@ pic_dict_next(pic_state *PIC_UNUSED(pic), pic_value dict, int *iter, pic_value * for (it = *iter; it != kh_end(h); ++it) { if (kh_exist(h, it)) { - if (key) *key = pic_obj_value(kh_key(h, it)); + if (key) *key = obj_value(kh_key(h, it)); if (val) *val = kh_val(h, it); *iter = ++it; return true; diff --git a/lib/error.c b/lib/error.c index a4a7fa9a..4347578f 100644 --- a/lib/error.c +++ b/lib/error.c @@ -96,7 +96,7 @@ pic_start_try(pic_state *pic, PIC_JMPBUF *jmp) pic->cp->in = pic_proc_ptr(pic, in); pic->cp->out = pic_proc_ptr(pic, out); - return pic_cons(pic, pic_obj_value(here), out); + return pic_cons(pic, obj_value(here), out); } void @@ -132,7 +132,7 @@ pic_make_error(pic_state *pic, const char *type, const char *msg, pic_value irrs e->irrs = irrs; e->stack = pic_str_ptr(pic, stack); - return pic_obj_value(e); + return obj_value(e); } pic_value pic_raise_continuable(pic_state *, pic_value err); @@ -262,7 +262,7 @@ pic_error_error_object_message(pic_state *pic) TYPE_CHECK(pic, e, error); - return pic_obj_value(pic_error_ptr(pic, e)->msg); + return obj_value(pic_error_ptr(pic, e)->msg); } static pic_value @@ -286,7 +286,7 @@ pic_error_error_object_type(pic_state *pic) TYPE_CHECK(pic, e, error); - return pic_obj_value(pic_error_ptr(pic, e)->type); + return obj_value(pic_error_ptr(pic, e)->type); } void diff --git a/lib/ext/lib.c b/lib/ext/lib.c index a07b8a26..f569748e 100644 --- a/lib/ext/lib.c +++ b/lib/ext/lib.c @@ -21,7 +21,7 @@ pic_make_env(pic_state *pic, pic_value up) env->lib = NULL; kh_init(env, &env->map); - return pic_obj_value(env); + return obj_value(env); } static bool @@ -33,7 +33,7 @@ search_scope(pic_state *pic, pic_value id, pic_value env, pic_value *uid) if (it == kh_end(&pic_env_ptr(pic, env)->map)) { return false; } - *uid = pic_obj_value(kh_val(&pic_env_ptr(pic, env)->map, it)); + *uid = obj_value(kh_val(&pic_env_ptr(pic, env)->map, it)); return true; } @@ -48,7 +48,7 @@ search(pic_state *pic, pic_value id, pic_value env, pic_value *uid) e = pic_env_ptr(pic, env)->up; if (e == NULL) break; - env = pic_obj_value(e); + env = obj_value(e); } return false; } @@ -65,12 +65,12 @@ pic_find_identifier(pic_state *pic, pic_value id, pic_value env) e = pic_env_ptr(pic, env); if (e->up == NULL) break; - env = pic_obj_value(e->up); + env = obj_value(e->up); } return pic_add_identifier(pic, id, env); } - env = pic_obj_value(pic_id_ptr(pic, id)->env); /* do not overwrite id first */ - id = pic_obj_value(pic_id_ptr(pic, id)->u.id); + env = obj_value(pic_id_ptr(pic, id)->env); /* do not overwrite id first */ + id = obj_value(pic_id_ptr(pic, id)->u.id); } return uid; } @@ -88,7 +88,7 @@ pic_add_identifier(pic_state *pic, pic_value id, pic_value env) name = pic_str(pic, pic_id_name(pic, id), NULL); if (pic_env_ptr(pic, env)->up == NULL && pic_sym_p(pic, id)) { /* toplevel & public */ - lib = pic_str(pic, pic_obj_value(pic_env_ptr(pic, env)->lib), NULL); + lib = pic_str(pic, obj_value(pic_env_ptr(pic, env)->lib), NULL); str = pic_strf_value(pic, "%s/%s", lib, name); } else { str = pic_strf_value(pic, ".%s.%d", name, pic->ucnt++); @@ -144,7 +144,7 @@ make_library_env(pic_state *pic, pic_value name) env->lib = pic_str_ptr(pic, name); kh_init(env, &env->map); - e = pic_obj_value(env); + e = obj_value(env); #define REGISTER(name) pic_put_identifier(pic, pic_intern_lit(pic, name), pic_intern_lit(pic, name), e) @@ -201,7 +201,7 @@ pic_current_library(pic_state *pic) pic_value pic_library_environment(pic_state *pic, const char *lib) { - return pic_obj_value(get_library(pic, lib)->env); + return obj_value(get_library(pic, lib)->env); } void @@ -214,19 +214,19 @@ pic_import(pic_state *pic, const char *lib) our = get_library(pic, pic->lib); their = get_library(pic, lib); - while (pic_dict_next(pic, pic_obj_value(their->exports), &it, &name, &realname)) { - uid = pic_find_identifier(pic, realname, pic_obj_value(their->env)); + while (pic_dict_next(pic, obj_value(their->exports), &it, &name, &realname)) { + uid = pic_find_identifier(pic, realname, obj_value(their->env)); if (! pic_weak_has(pic, pic->globals, uid) && ! pic_weak_has(pic, pic->macros, uid)) { pic_error(pic, "attempted to export undefined variable", 1, realname); } - pic_put_identifier(pic, name, uid, pic_obj_value(our->env)); + pic_put_identifier(pic, name, uid, obj_value(our->env)); } } void pic_export(pic_state *pic, pic_value name) { - pic_dict_set(pic, pic_obj_value(get_library(pic, pic->lib)->exports), name, name); + pic_dict_set(pic, obj_value(get_library(pic, pic->lib)->exports), name, name); } static pic_value @@ -285,18 +285,18 @@ pic_lib_library_import(pic_state *pic) libp = get_library(pic, lib); - if (! pic_dict_has(pic, pic_obj_value(libp->exports), name)) { + if (! pic_dict_has(pic, obj_value(libp->exports), name)) { pic_error(pic, "library-import: variable is not exported", 1, name); } else { - realname = pic_dict_ref(pic, pic_obj_value(libp->exports), name); + realname = pic_dict_ref(pic, obj_value(libp->exports), name); } - uid = pic_find_identifier(pic, realname, pic_obj_value(libp->env)); + uid = pic_find_identifier(pic, realname, obj_value(libp->env)); if (! pic_weak_has(pic, pic->globals, uid) && ! pic_weak_has(pic, pic->macros, uid)) { pic_error(pic, "attempted to export undefined variable", 1, realname); } - pic_put_identifier(pic, alias, uid, pic_obj_value(get_library(pic, pic->lib)->env)); + pic_put_identifier(pic, alias, uid, obj_value(get_library(pic, pic->lib)->env)); return pic_undef_value(pic); } @@ -313,7 +313,7 @@ pic_lib_library_export(pic_state *pic) alias = name; } - pic_dict_set(pic, pic_obj_value(get_library(pic, pic->lib)->exports), alias, name); + pic_dict_set(pic, obj_value(get_library(pic, pic->lib)->exports), alias, name); return pic_undef_value(pic); } @@ -330,7 +330,7 @@ pic_lib_library_exports(pic_state *pic) libp = get_library(pic, lib); - while (pic_dict_next(pic, pic_obj_value(libp->exports), &it, &sym, NULL)) { + while (pic_dict_next(pic, obj_value(libp->exports), &it, &sym, NULL)) { pic_push(pic, sym, exports); } @@ -344,7 +344,7 @@ pic_lib_library_environment(pic_state *pic) pic_get_args(pic, "z", &lib); - return pic_obj_value(get_library(pic, lib)->env); + return obj_value(get_library(pic, lib)->env); } void diff --git a/lib/gc.c b/lib/gc.c index fe0b997f..b8745cba 100644 --- a/lib/gc.c +++ b/lib/gc.c @@ -409,7 +409,7 @@ gc_mark_object(pic_state *pic, struct object *obj) pic_value key, val; int it = 0; - while (pic_dict_next(pic, pic_obj_value(&obj->u.dict), &it, &key, &val)) { + while (pic_dict_next(pic, obj_value(&obj->u.dict), &it, &key, &val)) { gc_mark(pic, key); gc_mark(pic, val); } @@ -588,7 +588,7 @@ gc_finalize_object(pic_state *pic, struct object *obj) break; } case PIC_TYPE_PORT: { - pic_fclose(pic, pic_obj_value(obj)); /* FIXME */ + pic_fclose(pic, obj_value(obj)); /* FIXME */ break; } diff --git a/lib/pair.c b/lib/pair.c index 4307c0e3..9d288b4c 100644 --- a/lib/pair.c +++ b/lib/pair.c @@ -15,7 +15,7 @@ pic_cons(pic_state *pic, pic_value car, pic_value cdr) pair->car = car; pair->cdr = cdr; - return pic_obj_value(pair); + return obj_value(pair); } pic_value diff --git a/lib/port.c b/lib/port.c index 9f629e83..49b0f24e 100644 --- a/lib/port.c +++ b/lib/port.c @@ -32,7 +32,7 @@ pic_funopen(pic_state *pic, void *cookie, const pic_port_type *type) port->file.cookie = cookie; port->file.vtable = type; - return pic_obj_value(port); + return obj_value(port); } int diff --git a/lib/proc.c b/lib/proc.c index dc1180fc..b591140b 100644 --- a/lib/proc.c +++ b/lib/proc.c @@ -438,15 +438,15 @@ pic_apply(pic_state *pic, pic_value proc, int argc, pic_value *argv) NEXT; } CASE(OP_PUSHCONST) { - PUSH(pic_obj_value(pic->ci->irep->pool[c.a])); + PUSH(obj_value(pic->ci->irep->pool[c.a])); NEXT; } CASE(OP_GREF) { - PUSH(pic_global_ref(pic, pic_obj_value(pic->ci->irep->pool[c.a]))); + PUSH(pic_global_ref(pic, obj_value(pic->ci->irep->pool[c.a]))); NEXT; } CASE(OP_GSET) { - pic_global_set(pic, pic_obj_value(pic->ci->irep->pool[c.a]), POP()); + pic_global_set(pic, obj_value(pic->ci->irep->pool[c.a]), POP()); PUSH(pic_undef_value(pic)); NEXT; } @@ -865,7 +865,7 @@ pic_make_proc(pic_state *pic, pic_func_t func, int n, pic_value *env) for (i = 0; i < n; ++i) { proc->locals[i] = env[i]; } - return pic_obj_value(proc); + return obj_value(proc); } pic_value @@ -877,7 +877,7 @@ pic_make_proc_irep(pic_state *pic, struct irep *irep, struct context *cxt) proc->u.i.irep = irep; proc->u.i.cxt = cxt; pic_irep_incref(pic, irep); - return pic_obj_value(proc); + return obj_value(proc); } static pic_value diff --git a/lib/record.c b/lib/record.c index 6e3f5c59..299eca16 100644 --- a/lib/record.c +++ b/lib/record.c @@ -15,7 +15,7 @@ pic_make_record(pic_state *pic, pic_value type, pic_value datum) rec->type = type; rec->datum = datum; - return pic_obj_value(rec); + return obj_value(rec); } static pic_value diff --git a/lib/string.c b/lib/string.c index b25c7074..7e81fbf2 100644 --- a/lib/string.c +++ b/lib/string.c @@ -121,7 +121,7 @@ make_str(pic_state *pic, struct rope *rope) str = (struct string *)pic_obj_alloc(pic, sizeof(struct string), PIC_TYPE_STRING); str->rope = rope; /* delegate ownership */ - return pic_obj_value(str); + return obj_value(str); } static struct rope * diff --git a/lib/symbol.c b/lib/symbol.c index 67ed748d..8f37e41b 100644 --- a/lib/symbol.c +++ b/lib/symbol.c @@ -7,8 +7,8 @@ #include "object.h" #include "state.h" -#define kh_pic_str_hash(a) (pic_str_hash(pic, pic_obj_value(a))) -#define kh_pic_str_cmp(a, b) (pic_str_cmp(pic, pic_obj_value(a), pic_obj_value(b)) == 0) +#define kh_pic_str_hash(a) (pic_str_hash(pic, obj_value(a))) +#define kh_pic_str_cmp(a, b) (pic_str_cmp(pic, obj_value(a), obj_value(b)) == 0) KHASH_DEFINE(oblist, struct string *, symbol *, kh_pic_str_hash, kh_pic_str_cmp) @@ -23,8 +23,8 @@ pic_intern(pic_state *pic, pic_value str) it = kh_put(oblist, h, pic_str_ptr(pic, str), &ret); if (ret == 0) { /* if exists */ sym = kh_val(h, it); - pic_protect(pic, pic_obj_value(sym)); - return pic_obj_value(sym); + pic_protect(pic, obj_value(sym)); + return obj_value(sym); } kh_val(h, it) = NULL; /* dummy */ @@ -33,7 +33,7 @@ pic_intern(pic_state *pic, pic_value str) sym->u.str = pic_str_ptr(pic, str); kh_val(h, it) = sym; - return pic_obj_value(sym); + return obj_value(sym); } pic_value @@ -45,20 +45,20 @@ pic_make_identifier(pic_state *pic, pic_value base, pic_value env) id->u.id = pic_id_ptr(pic, base); id->env = pic_env_ptr(pic, env); - return pic_obj_value(id); + return obj_value(id); } pic_value pic_sym_name(pic_state *PIC_UNUSED(pic), pic_value sym) { - return pic_obj_value(pic_sym_ptr(pic, sym)->u.str); + return obj_value(pic_sym_ptr(pic, sym)->u.str); } pic_value pic_id_name(pic_state *pic, pic_value id) { while (! pic_sym_p(pic, id)) { - id = pic_obj_value(pic_id_ptr(pic, id)->u.id); + id = obj_value(pic_id_ptr(pic, id)->u.id); } return pic_sym_name(pic, id); @@ -149,7 +149,7 @@ pic_symbol_identifier_base(pic_state *pic) pic_error(pic, "non-symbol identifier required", 1, id); } - return pic_obj_value(pic_id_ptr(pic, id)->u.id); + return obj_value(pic_id_ptr(pic, id)->u.id); } static pic_value @@ -165,7 +165,7 @@ pic_symbol_identifier_environment(pic_state *pic) pic_error(pic, "non-symbol identifier required", 1, id); } - return pic_obj_value(pic_id_ptr(pic, id)->env); + return obj_value(pic_id_ptr(pic, id)->env); } static pic_value diff --git a/lib/value.h b/lib/value.h index acb41478..80f8da55 100644 --- a/lib/value.h +++ b/lib/value.h @@ -9,14 +9,56 @@ extern "C" { #endif -#ifndef INLINE -# if GENERATE_EXTERNAL_DEFINITION -# define INLINE -# else -# define INLINE -# endif +#if 0 +#define pic_int pic_int_inline +#define pic_float pic_float_inline +#define pic_char pic_char_inline +#define pic_int_value pic_int_value_inline +#define pic_float_value pic_float_value_inline +#define pic_char_value pic_char_value_inline +#define obj_value obj_value_inline /* TODO */ +#define pic_nil_value pic_nil_value_inline +#define pic_eof_object pic_eof_object_inline +#define pic_true_value pic_true_value_inline +#define pic_false_value pic_false_value_inline +#define pic_undef_value pic_undef_value_inline +#define pic_invalid_value pic_invalid_value_inline +#define pic_bool_value pic_bool_value_inline +#define pic_invalid_p pic_invalid_p_inline +#define pic_float_p pic_float_p_inline +#define pic_int_p pic_int_p_inline +#define pic_char_p pic_char_p_inline +#define pic_eof_p pic_eof_p_inline +#define pic_undef_p pic_undef_p_inline +#define pic_true_p pic_true_p_inline +#define pic_nil_p pic_nil_p_inline +#define pic_false_p pic_false_p_inline +#define pic_bool_p pic_bool_p_inline +#define pic_str_p pic_str_p_inline +#define pic_vec_p pic_vec_p_inline +#define pic_blob_p pic_blob_p_inline +#define pic_error_p pic_error_p_inline +#define pic_id_p pic_id_p_inline +#define pic_dict_p pic_dict_p_inline +#define pic_weak_p pic_weak_p_inline +#define pic_env_p pic_env_p_inline +#define pic_rec_p pic_rec_p_inline +#define pic_sym_p pic_sym_p_inline +#define pic_pair_p pic_pair_p_inline +#define pic_cp_p pic_cp_p_inline +#define pic_func_p pic_func_p_inline +#define pic_irep_p pic_irep_p_inline +#define pic_proc_p pic_proc_p_inline #endif +/* #ifndef INLINE */ +/* # if GENERATE_EXTERNAL_DEFINITION */ +/* # define INLINE PIC_EXTERN_INLINE */ +/* # else */ +/* # define INLINE PIC_INLINE */ +/* # endif */ +/* #endif */ + #define INLINE PIC_STATIC_INLINE enum { @@ -76,7 +118,7 @@ obj_p(pic_state *PIC_UNUSED(pic), pic_value v) } PIC_STATIC_INLINE pic_value -pic_obj_value(void *ptr) +obj_value(void *ptr) { pic_value v = make_value(obj_tt(ptr)); v.u.data = ptr; @@ -162,7 +204,7 @@ obj_p(pic_state *PIC_UNUSED(pic), pic_value v) } PIC_STATIC_INLINE pic_value -pic_obj_value(void *ptr) +obj_value(void *ptr) { pic_value v = make_value(PIC_IVAL_END); v.v |= 0xfffffffffffful & (uint64_t)ptr; diff --git a/lib/vector.c b/lib/vector.c index 9bc02d5d..2c42d673 100644 --- a/lib/vector.c +++ b/lib/vector.c @@ -22,7 +22,7 @@ pic_make_vec(pic_state *pic, int len, pic_value *argv) } else { memcpy(vec->data, argv, sizeof(pic_value) * len); } - return pic_obj_value(vec); + return obj_value(vec); } pic_value diff --git a/lib/weak.c b/lib/weak.c index 18dac8eb..cfdfd739 100644 --- a/lib/weak.c +++ b/lib/weak.c @@ -17,7 +17,7 @@ pic_make_weak(pic_state *pic) weak->prev = NULL; kh_init(weak, &weak->hash); - return pic_obj_value(weak); + return obj_value(weak); } pic_value