struct pic_dict * -> pic_value

This commit is contained in:
Yuichi Nishiwaki 2016-02-19 19:08:45 +09:00
parent 03fed95b32
commit 3e4a4755dc
7 changed files with 112 additions and 189 deletions

View File

@ -7,21 +7,20 @@
KHASH_DEFINE(dict, pic_sym *, pic_value, kh_ptr_hash_func, kh_ptr_hash_equal) KHASH_DEFINE(dict, pic_sym *, pic_value, kh_ptr_hash_func, kh_ptr_hash_equal)
struct pic_dict * pic_value
pic_make_dict(pic_state *pic) pic_make_dict(pic_state *pic)
{ {
struct pic_dict *dict; struct pic_dict *dict;
dict = (struct pic_dict *)pic_obj_alloc(pic, sizeof(struct pic_dict), PIC_TYPE_DICT); dict = (struct pic_dict *)pic_obj_alloc(pic, sizeof(struct pic_dict), PIC_TYPE_DICT);
kh_init(dict, &dict->hash); kh_init(dict, &dict->hash);
return pic_obj_value(dict);
return dict;
} }
pic_value pic_value
pic_dict_ref(pic_state *pic, struct pic_dict *dict, pic_sym *key) pic_dict_ref(pic_state *pic, pic_value dict, pic_sym *key)
{ {
khash_t(dict) *h = &dict->hash; khash_t(dict) *h = &pic_dict_ptr(pic, dict)->hash;
khiter_t it; khiter_t it;
it = kh_get(dict, h, key); it = kh_get(dict, h, key);
@ -32,9 +31,9 @@ pic_dict_ref(pic_state *pic, struct pic_dict *dict, pic_sym *key)
} }
void void
pic_dict_set(pic_state PIC_UNUSED(*pic), struct pic_dict *dict, pic_sym *key, pic_value val) pic_dict_set(pic_state *pic, pic_value dict, pic_sym *key, pic_value val)
{ {
khash_t(dict) *h = &dict->hash; khash_t(dict) *h = &pic_dict_ptr(pic, dict)->hash;
int ret; int ret;
khiter_t it; khiter_t it;
@ -43,21 +42,23 @@ pic_dict_set(pic_state PIC_UNUSED(*pic), struct pic_dict *dict, pic_sym *key, pi
} }
int int
pic_dict_size(pic_state PIC_UNUSED(*pic), struct pic_dict *dict) pic_dict_size(pic_state PIC_UNUSED(*pic), pic_value dict)
{ {
return kh_size(&dict->hash); return kh_size(&pic_dict_ptr(pic, dict)->hash);
} }
bool bool
pic_dict_has(pic_state PIC_UNUSED(*pic), struct pic_dict *dict, pic_sym *key) pic_dict_has(pic_state *pic, pic_value dict, pic_sym *key)
{ {
return kh_get(dict, &dict->hash, key) != kh_end(&dict->hash); khash_t(dict) *h = &pic_dict_ptr(pic, dict)->hash;
return kh_get(dict, h, key) != kh_end(h);
} }
void void
pic_dict_del(pic_state *pic, struct pic_dict *dict, pic_sym *key) pic_dict_del(pic_state *pic, pic_value dict, pic_sym *key)
{ {
khash_t(dict) *h = &dict->hash; khash_t(dict) *h = &pic_dict_ptr(pic, dict)->hash;
khiter_t it; khiter_t it;
it = kh_get(dict, h, key); it = kh_get(dict, h, key);
@ -68,9 +69,9 @@ pic_dict_del(pic_state *pic, struct pic_dict *dict, pic_sym *key)
} }
bool bool
pic_dict_next(pic_state PIC_UNUSED(*pic), struct pic_dict *dict, int *iter, pic_sym **key, pic_value *val) pic_dict_next(pic_state PIC_UNUSED(*pic), pic_value dict, int *iter, pic_sym **key, pic_value *val)
{ {
khash_t(dict) *h = &dict->hash; khash_t(dict) *h = &pic_dict_ptr(pic, dict)->hash;
int it = *iter; int it = *iter;
for (it = *iter; it != kh_end(h); ++it) { for (it = *iter; it != kh_end(h); ++it) {
@ -87,20 +88,15 @@ pic_dict_next(pic_state PIC_UNUSED(*pic), struct pic_dict *dict, int *iter, pic_
static pic_value static pic_value
pic_dict_make_dictionary(pic_state *pic) pic_dict_make_dictionary(pic_state *pic)
{ {
struct pic_dict *dict;
pic_get_args(pic, ""); pic_get_args(pic, "");
dict = pic_make_dict(pic); return pic_make_dict(pic);
return pic_obj_value(dict);
} }
static pic_value static pic_value
pic_dict_dictionary(pic_state *pic) pic_dict_dictionary(pic_state *pic)
{ {
struct pic_dict *dict; pic_value dict, *argv;
pic_value *argv;
int argc, i; int argc, i;
pic_get_args(pic, "*", &argc, &argv); pic_get_args(pic, "*", &argc, &argv);
@ -112,7 +108,7 @@ pic_dict_dictionary(pic_state *pic)
pic_dict_set(pic, dict, pic_sym_ptr(argv[i]), argv[i+1]); pic_dict_set(pic, dict, pic_sym_ptr(argv[i]), argv[i+1]);
} }
return pic_obj_value(dict); return dict;
} }
static pic_value static pic_value
@ -128,7 +124,7 @@ pic_dict_dictionary_p(pic_state *pic)
static pic_value static pic_value
pic_dict_dictionary_ref(pic_state *pic) pic_dict_dictionary_ref(pic_state *pic)
{ {
struct pic_dict *dict; pic_value dict;
pic_sym *key; pic_sym *key;
pic_get_args(pic, "dm", &dict, &key); pic_get_args(pic, "dm", &dict, &key);
@ -142,7 +138,7 @@ pic_dict_dictionary_ref(pic_state *pic)
static pic_value static pic_value
pic_dict_dictionary_set(pic_state *pic) pic_dict_dictionary_set(pic_state *pic)
{ {
struct pic_dict *dict; pic_value dict;
pic_sym *key; pic_sym *key;
pic_value val; pic_value val;
@ -162,7 +158,7 @@ pic_dict_dictionary_set(pic_state *pic)
static pic_value static pic_value
pic_dict_dictionary_size(pic_state *pic) pic_dict_dictionary_size(pic_state *pic)
{ {
struct pic_dict *dict; pic_value dict;
pic_get_args(pic, "d", &dict); pic_get_args(pic, "d", &dict);
@ -173,21 +169,15 @@ static pic_value
pic_dict_dictionary_map(pic_state *pic) pic_dict_dictionary_map(pic_state *pic)
{ {
struct pic_proc *proc; struct pic_proc *proc;
struct pic_dict *dict; pic_value dict, ret = pic_nil_value(pic);
khiter_t it; pic_sym *key;
khash_t(dict) *kh; int it = 0;
pic_value ret = pic_nil_value(pic);
pic_get_args(pic, "ld", &proc, &dict); pic_get_args(pic, "ld", &proc, &dict);
kh = &dict->hash; while (pic_dict_next(pic, dict, &it, &key, NULL)) {
pic_push(pic, pic_call(pic, proc, 1, pic_obj_value(key)), ret);
for (it = kh_begin(kh); it != kh_end(kh); ++it) {
if (kh_exist(kh, it)) {
pic_push(pic, pic_call(pic, proc, 1, pic_obj_value(kh_key(kh, it))), ret);
}
} }
return pic_reverse(pic, ret); return pic_reverse(pic, ret);
} }
@ -195,18 +185,14 @@ static pic_value
pic_dict_dictionary_for_each(pic_state *pic) pic_dict_dictionary_for_each(pic_state *pic)
{ {
struct pic_proc *proc; struct pic_proc *proc;
struct pic_dict *dict; pic_value dict;
khiter_t it; pic_sym *key;
khash_t(dict) *kh; int it;
pic_get_args(pic, "ld", &proc, &dict); pic_get_args(pic, "ld", &proc, &dict);
kh = &dict->hash; while (pic_dict_next(pic, dict, &it, &key, NULL)) {
pic_call(pic, proc, 1, pic_obj_value(key));
for (it = kh_begin(kh); it != kh_end(kh); ++it) {
if (kh_exist(kh, it)) {
pic_call(pic, proc, 1, pic_obj_value(kh_key(kh, it)));
}
} }
return pic_undef_value(pic); return pic_undef_value(pic);
@ -215,8 +201,7 @@ pic_dict_dictionary_for_each(pic_state *pic)
static pic_value static pic_value
pic_dict_dictionary_to_alist(pic_state *pic) pic_dict_dictionary_to_alist(pic_state *pic)
{ {
struct pic_dict *dict; pic_value dict, val, alist = pic_nil_value(pic);
pic_value val, alist = pic_nil_value(pic);
pic_sym *sym; pic_sym *sym;
int it = 0; int it = 0;
@ -232,8 +217,7 @@ pic_dict_dictionary_to_alist(pic_state *pic)
static pic_value static pic_value
pic_dict_alist_to_dictionary(pic_state *pic) pic_dict_alist_to_dictionary(pic_state *pic)
{ {
struct pic_dict *dict; pic_value dict, alist, e, it;
pic_value alist, e, it;
pic_get_args(pic, "o", &alist); pic_get_args(pic, "o", &alist);
@ -244,14 +228,13 @@ pic_dict_alist_to_dictionary(pic_state *pic)
pic_dict_set(pic, dict, pic_sym_ptr(pic_car(pic, e)), pic_cdr(pic, e)); pic_dict_set(pic, dict, pic_sym_ptr(pic_car(pic, e)), pic_cdr(pic, e));
} }
return pic_obj_value(dict); return dict;
} }
static pic_value static pic_value
pic_dict_dictionary_to_plist(pic_state *pic) pic_dict_dictionary_to_plist(pic_state *pic)
{ {
struct pic_dict *dict; pic_value dict, val, plist = pic_nil_value(pic);
pic_value val, plist = pic_nil_value(pic);
pic_sym *sym; pic_sym *sym;
int it = 0; int it = 0;
@ -268,8 +251,7 @@ pic_dict_dictionary_to_plist(pic_state *pic)
static pic_value static pic_value
pic_dict_plist_to_dictionary(pic_state *pic) pic_dict_plist_to_dictionary(pic_state *pic)
{ {
struct pic_dict *dict; pic_value dict, plist, e;
pic_value plist, e;
pic_get_args(pic, "o", &plist); pic_get_args(pic, "o", &plist);
@ -280,7 +262,7 @@ pic_dict_plist_to_dictionary(pic_state *pic)
pic_dict_set(pic, dict, pic_sym_ptr(pic_cadr(pic, e)), pic_car(pic, e)); pic_dict_set(pic, dict, pic_sym_ptr(pic_cadr(pic, e)), pic_car(pic, e));
} }
return pic_obj_value(dict); return dict;
} }
void void

View File

@ -363,7 +363,7 @@ gc_mark_object(pic_state *pic, struct pic_object *obj)
pic_value val; pic_value val;
int it = 0; int it = 0;
while (pic_dict_next(pic, &obj->u.dict, &it, &sym, &val)) { while (pic_dict_next(pic, pic_obj_value(&obj->u.dict), &it, &sym, &val)) {
gc_mark_object(pic, (struct pic_object *)sym); gc_mark_object(pic, (struct pic_object *)sym);
gc_mark(pic, val); gc_mark(pic, val);
} }

View File

@ -241,13 +241,13 @@ void pic_vec_set(pic_state *, pic_vec *, int, pic_value);
int pic_vec_len(pic_state *, pic_vec *); int pic_vec_len(pic_state *, pic_vec *);
/* dictionary */ /* dictionary */
struct pic_dict *pic_make_dict(pic_state *); pic_value pic_make_dict(pic_state *);
pic_value pic_dict_ref(pic_state *, struct pic_dict *, pic_sym *); pic_value pic_dict_ref(pic_state *, pic_value dict, pic_sym *);
void pic_dict_set(pic_state *, struct pic_dict *, pic_sym *, pic_value); void pic_dict_set(pic_state *, pic_value dict, pic_sym *, pic_value);
void pic_dict_del(pic_state *, struct pic_dict *, pic_sym *); void pic_dict_del(pic_state *, pic_value dict, pic_sym *);
bool pic_dict_has(pic_state *, struct pic_dict *, pic_sym *); bool pic_dict_has(pic_state *, pic_value dict, pic_sym *);
int pic_dict_size(pic_state *, struct pic_dict *); int pic_dict_size(pic_state *, pic_value dict);
bool pic_dict_next(pic_state *, struct pic_dict *, int *iter, pic_sym **key, pic_value *val); bool pic_dict_next(pic_state *, pic_value dict, int *iter, pic_sym **key, pic_value *val);
/* ephemeron */ /* ephemeron */
struct pic_weak *pic_make_weak(pic_state *); struct pic_weak *pic_make_weak(pic_state *);

View File

@ -9,11 +9,9 @@
extern "C" { extern "C" {
#endif #endif
KHASH_DECLARE(env, pic_id *, pic_sym *)
struct pic_object *pic_obj_alloc(pic_state *, size_t, int type); KHASH_DECLARE(dict, pic_sym *, pic_value)
KHASH_DECLARE(weak, void *, pic_value)
/* symbol & identifier */
struct pic_id { struct pic_id {
union { union {
@ -29,21 +27,12 @@ struct pic_id {
} u; } u;
}; };
#define pic_sym_ptr(v) ((pic_sym *)pic_obj_ptr(v)) struct pic_env {
PIC_OBJECT_HEADER
#define pic_id_p(pic, v) (pic_type(pic, v) == PIC_TYPE_ID || pic_type(pic, v) == PIC_TYPE_SYMBOL) khash_t(env) map;
#define pic_id_ptr(v) ((pic_id *)pic_obj_ptr(v)) struct pic_env *up;
struct pic_string *lib;
pic_id *pic_make_identifier(pic_state *, pic_id *, struct pic_env *); };
pic_sym *pic_add_identifier(pic_state *, pic_id *, struct pic_env *);
pic_sym *pic_put_identifier(pic_state *, pic_id *, pic_sym *, struct pic_env *);
pic_sym *pic_find_identifier(pic_state *, pic_id *, struct pic_env *);
struct pic_string *pic_id_name(pic_state *, pic_id *);
/* pair */
struct pic_pair { struct pic_pair {
PIC_OBJECT_HEADER PIC_OBJECT_HEADER
@ -51,69 +40,33 @@ struct pic_pair {
pic_value cdr; pic_value cdr;
}; };
#define pic_pair_ptr(o) ((struct pic_pair *)pic_obj_ptr(o))
/* blob */
struct pic_blob { struct pic_blob {
PIC_OBJECT_HEADER PIC_OBJECT_HEADER
unsigned char *data; unsigned char *data;
int len; int len;
}; };
#define pic_blob_ptr(v) ((struct pic_blob *)pic_obj_ptr(v))
/* string */
struct pic_string { struct pic_string {
PIC_OBJECT_HEADER PIC_OBJECT_HEADER
struct pic_rope *rope; struct pic_rope *rope;
}; };
void pic_rope_incref(pic_state *, struct pic_rope *);
void pic_rope_decref(pic_state *, struct pic_rope *);
#define pic_str_ptr(o) ((struct pic_string *)pic_obj_ptr(o))
/* vector */
struct pic_vector {
PIC_OBJECT_HEADER
pic_value *data;
int len;
};
#define pic_vec_ptr(o) ((struct pic_vector *)pic_obj_ptr(o))
/* dictionary */
KHASH_DECLARE(dict, pic_sym *, pic_value)
struct pic_dict { struct pic_dict {
PIC_OBJECT_HEADER PIC_OBJECT_HEADER
khash_t(dict) hash; khash_t(dict) hash;
}; };
#define pic_dict_ptr(v) ((struct pic_dict *)pic_obj_ptr(v))
/* weak */
KHASH_DECLARE(weak, void *, pic_value)
struct pic_weak { struct pic_weak {
PIC_OBJECT_HEADER PIC_OBJECT_HEADER
khash_t(weak) hash; khash_t(weak) hash;
struct pic_weak *prev; /* for GC */ struct pic_weak *prev; /* for GC */
}; };
#define pic_weak_ptr(v) ((struct pic_weak *)pic_obj_ptr(v)) struct pic_vector {
PIC_OBJECT_HEADER
pic_value *data;
/* data */ int len;
};
struct pic_data { struct pic_data {
PIC_OBJECT_HEADER PIC_OBJECT_HEADER
@ -121,11 +74,6 @@ struct pic_data {
void *data; void *data;
}; };
#define pic_data_ptr(o) ((struct pic_data *)pic_obj_ptr(o))
/* context */
struct pic_context { struct pic_context {
PIC_OBJECT_HEADER PIC_OBJECT_HEADER
pic_value *regs; pic_value *regs;
@ -134,11 +82,6 @@ struct pic_context {
pic_value storage[1]; pic_value storage[1];
}; };
#define pic_context_ptr(o) ((struct pic_context *)pic_obj_ptr(o))
/* procedure */
struct pic_proc { struct pic_proc {
PIC_OBJECT_HEADER PIC_OBJECT_HEADER
enum { enum {
@ -158,31 +101,12 @@ struct pic_proc {
pic_value locals[1]; pic_value locals[1];
}; };
#define pic_proc_ptr(o) ((struct pic_proc *)pic_obj_ptr(o))
#define pic_proc_func_p(proc) ((proc)->tag == PIC_PROC_TAG_FUNC)
#define pic_proc_irep_p(proc) ((proc)->tag == PIC_PROC_TAG_IREP)
struct pic_proc *pic_make_proc(pic_state *, pic_func_t, int, pic_value *);
struct pic_proc *pic_make_proc_irep(pic_state *, struct pic_irep *, struct pic_context *);
/* record */
struct pic_record { struct pic_record {
PIC_OBJECT_HEADER PIC_OBJECT_HEADER
pic_value type; pic_value type;
pic_value datum; pic_value datum;
}; };
#define pic_rec_p(pic, v) (pic_type(pic, v) == PIC_TYPE_RECORD)
#define pic_rec_ptr(v) ((struct pic_record *)pic_obj_ptr(v))
struct pic_record *pic_make_rec(pic_state *, pic_value, pic_value);
/* error */
struct pic_error { struct pic_error {
PIC_OBJECT_HEADER PIC_OBJECT_HEADER
pic_sym *type; pic_sym *type;
@ -191,38 +115,52 @@ struct pic_error {
struct pic_string *stack; struct pic_string *stack;
}; };
#define pic_error_p(pic, v) (pic_type(pic, v) == PIC_TYPE_ERROR)
#define pic_error_ptr(v) ((struct pic_error *)pic_obj_ptr(v))
struct pic_error *pic_make_error(pic_state *, const char *, const char *, pic_value);
/* port */
struct pic_port { struct pic_port {
PIC_OBJECT_HEADER PIC_OBJECT_HEADER
xFILE *file; xFILE *file;
}; };
#define pic_dict_ptr(pic, v) ((struct pic_dict *)pic_obj_ptr(v))
#define pic_sym_ptr(v) ((pic_sym *)pic_obj_ptr(v))
#define pic_id_ptr(v) ((pic_id *)pic_obj_ptr(v))
#define pic_pair_ptr(o) ((struct pic_pair *)pic_obj_ptr(o))
#define pic_blob_ptr(v) ((struct pic_blob *)pic_obj_ptr(v))
#define pic_str_ptr(o) ((struct pic_string *)pic_obj_ptr(o))
#define pic_vec_ptr(o) ((struct pic_vector *)pic_obj_ptr(o))
#define pic_weak_ptr(v) ((struct pic_weak *)pic_obj_ptr(v))
#define pic_data_ptr(o) ((struct pic_data *)pic_obj_ptr(o))
#define pic_context_ptr(o) ((struct pic_context *)pic_obj_ptr(o))
#define pic_proc_ptr(o) ((struct pic_proc *)pic_obj_ptr(o))
#define pic_rec_ptr(v) ((struct pic_record *)pic_obj_ptr(v))
#define pic_error_ptr(v) ((struct pic_error *)pic_obj_ptr(v))
#define pic_port_ptr(v) ((struct pic_port *)pic_obj_ptr(v)) #define pic_port_ptr(v) ((struct pic_port *)pic_obj_ptr(v))
/* environment */
KHASH_DECLARE(env, pic_id *, pic_sym *)
struct pic_env {
PIC_OBJECT_HEADER
khash_t(env) map;
struct pic_env *up;
struct pic_string *lib;
};
#define pic_env_p(pic, v) (pic_type(pic, v) == PIC_TYPE_ENV)
#define pic_env_ptr(v) ((struct pic_env *)pic_obj_ptr(v)) #define pic_env_ptr(v) ((struct pic_env *)pic_obj_ptr(v))
#define pic_env_p(pic, v) (pic_type(pic, v) == PIC_TYPE_ENV)
#define pic_error_p(pic, v) (pic_type(pic, v) == PIC_TYPE_ERROR)
#define pic_rec_p(pic, v) (pic_type(pic, v) == PIC_TYPE_RECORD)
#define pic_id_p(pic, v) (pic_type(pic, v) == PIC_TYPE_ID || pic_type(pic, v) == PIC_TYPE_SYMBOL)
struct pic_object *pic_obj_alloc(pic_state *, size_t, int type);
pic_id *pic_make_identifier(pic_state *, pic_id *, struct pic_env *);
struct pic_proc *pic_make_proc(pic_state *, pic_func_t, int, pic_value *);
struct pic_proc *pic_make_proc_irep(pic_state *, struct pic_irep *, struct pic_context *);
struct pic_record *pic_make_rec(pic_state *, pic_value, pic_value);
struct pic_error *pic_make_error(pic_state *, const char *, const char *, pic_value);
struct pic_env *pic_make_env(pic_state *, struct pic_env *); struct pic_env *pic_make_env(pic_state *, struct pic_env *);
pic_sym *pic_add_identifier(pic_state *, pic_id *, struct pic_env *);
pic_sym *pic_put_identifier(pic_state *, pic_id *, pic_sym *, struct pic_env *);
pic_sym *pic_find_identifier(pic_state *, pic_id *, struct pic_env *);
struct pic_string *pic_id_name(pic_state *, pic_id *);
void pic_rope_incref(pic_state *, struct pic_rope *);
void pic_rope_decref(pic_state *, struct pic_rope *);
#define pic_proc_func_p(proc) ((proc)->tag == PIC_PROC_TAG_FUNC)
#define pic_proc_irep_p(proc) ((proc)->tag == PIC_PROC_TAG_IREP)
#if defined(__cplusplus) #if defined(__cplusplus)
} }

View File

@ -57,7 +57,7 @@ pic_make_library(pic_state *pic, const char *lib)
const char *old_lib; const char *old_lib;
struct pic_string *name; struct pic_string *name;
struct pic_env *env; struct pic_env *env;
struct pic_dict *exports; pic_value exports;
khiter_t it; khiter_t it;
int ret; int ret;
@ -76,7 +76,7 @@ pic_make_library(pic_state *pic, const char *lib)
kh_val(h, it).name = name; kh_val(h, it).name = name;
kh_val(h, it).env = env; kh_val(h, it).env = env;
kh_val(h, it).exports = exports; kh_val(h, it).exports = pic_dict_ptr(pic, exports);
if (pic->lib) { if (pic->lib) {
pic->lib = get_library(pic, old_lib); /* ltable might be rehashed */ pic->lib = get_library(pic, old_lib); /* ltable might be rehashed */
@ -117,7 +117,7 @@ pic_import(pic_state *pic, const char *lib)
libp = get_library(pic, lib); libp = get_library(pic, lib);
while (pic_dict_next(pic, libp->exports, &it, &name, &val)) { while (pic_dict_next(pic, pic_obj_value(libp->exports), &it, &name, &val)) {
realname = pic_sym_ptr(val); realname = pic_sym_ptr(val);
if ((uid = pic_find_identifier(pic, (pic_id *)realname, libp->env)) == NULL) { if ((uid = pic_find_identifier(pic, (pic_id *)realname, libp->env)) == NULL) {
@ -130,7 +130,7 @@ pic_import(pic_state *pic, const char *lib)
void void
pic_export(pic_state *pic, pic_sym *name) pic_export(pic_state *pic, pic_sym *name)
{ {
pic_dict_set(pic, pic->lib->exports, name, pic_obj_value(name)); pic_dict_set(pic, pic_obj_value(pic->lib->exports), name, pic_obj_value(name));
} }
static pic_value static pic_value
@ -188,10 +188,10 @@ pic_lib_library_import(pic_state *pic)
libp = get_library(pic, lib); libp = get_library(pic, lib);
if (! pic_dict_has(pic, libp->exports, name)) { if (! pic_dict_has(pic, pic_obj_value(libp->exports), name)) {
pic_errorf(pic, "attempted to import undefined variable '~s'", pic_obj_value(name)); pic_errorf(pic, "attempted to import undefined variable '~s'", pic_obj_value(name));
} else { } else {
realname = pic_sym_ptr(pic_dict_ref(pic, libp->exports, name)); realname = pic_sym_ptr(pic_dict_ref(pic, pic_obj_value(libp->exports), name));
} }
if ((uid = pic_find_identifier(pic, (pic_id *)realname, libp->env)) == NULL) { if ((uid = pic_find_identifier(pic, (pic_id *)realname, libp->env)) == NULL) {
@ -214,7 +214,7 @@ pic_lib_library_export(pic_state *pic)
alias = name; alias = name;
} }
pic_dict_set(pic, pic->lib->exports, alias, pic_obj_value(name)); pic_dict_set(pic, pic_obj_value(pic->lib->exports), alias, pic_obj_value(name));
return pic_undef_value(pic); return pic_undef_value(pic);
} }
@ -232,7 +232,7 @@ pic_lib_library_exports(pic_state *pic)
libp = get_library(pic, lib); libp = get_library(pic, lib);
while (pic_dict_next(pic, libp->exports, &it, &sym, NULL)) { while (pic_dict_next(pic, pic_obj_value(libp->exports), &it, &sym, NULL)) {
pic_push(pic, pic_obj_value(sym), exports); pic_push(pic, pic_obj_value(sym), exports);
} }

View File

@ -26,7 +26,7 @@
* b struct pic_blob ** bytevector object * b struct pic_blob ** bytevector object
* l struct pic_proc ** lambda object * l struct pic_proc ** lambda object
* p struct pic_port ** port object * p struct pic_port ** port object
* d struct pic_dict ** dictionary object * d pic_value * dictionary object
* e struct pic_error ** error object * e struct pic_error ** error object
* r struct pic_record ** record object * r struct pic_record ** record object
* *
@ -153,10 +153,13 @@ pic_get_args(pic_state *pic, const char *format, ...)
PTR_CASE('b', blob, struct pic_blob *) PTR_CASE('b', blob, struct pic_blob *)
PTR_CASE('l', proc, struct pic_proc *) PTR_CASE('l', proc, struct pic_proc *)
PTR_CASE('p', port, struct pic_port *) PTR_CASE('p', port, struct pic_port *)
PTR_CASE('d', dict, struct pic_dict *)
PTR_CASE('e', error, struct pic_error *) PTR_CASE('e', error, struct pic_error *)
PTR_CASE('r', rec, struct pic_record *) PTR_CASE('r', rec, struct pic_record *)
#define OBJ_CASE(c, type) VAL_CASE(c, type, pic_value, v)
OBJ_CASE('d', dict)
default: default:
pic_errorf(pic, "pic_get_args: invalid argument specifier '%c' given", c); pic_errorf(pic, "pic_get_args: invalid argument specifier '%c' given", c);
} }

View File

@ -238,7 +238,7 @@ write_vec(struct writer_control *p, pic_vec *vec)
} }
static void static void
write_dict(struct writer_control *p, struct pic_dict *dict) write_dict(struct writer_control *p, pic_value dict)
{ {
pic_state *pic = p->pic; pic_state *pic = p->pic;
xFILE *file = p->file; xFILE *file = p->file;
@ -318,7 +318,7 @@ write_core(struct writer_control *p, pic_value obj)
write_vec(p, pic_vec_ptr(obj)); write_vec(p, pic_vec_ptr(obj));
break; break;
case PIC_TYPE_DICT: case PIC_TYPE_DICT:
write_dict(p, pic_dict_ptr(obj)); write_dict(p, obj);
break; break;
default: default:
xfprintf(pic, file, "#<%s %p>", pic_typename(pic, pic_type(pic, obj)), pic_obj_ptr(obj)); xfprintf(pic, file, "#<%s %p>", pic_typename(pic, pic_type(pic, obj)), pic_obj_ptr(obj));
@ -369,7 +369,7 @@ traverse(struct writer_control *p, pic_value obj)
/* dictionary */ /* dictionary */
int it = 0; int it = 0;
pic_value val; pic_value val;
while (pic_dict_next(pic, pic_dict_ptr(obj), &it, NULL, &val)) { while (pic_dict_next(pic, obj, &it, NULL, &val)) {
traverse(p, val); traverse(p, val);
} }
} }