add attribute information to closure objects
This commit is contained in:
parent
82de3cfe2f
commit
56ae4de826
|
@ -31,6 +31,7 @@ struct pic_proc {
|
||||||
struct pic_irep *irep;
|
struct pic_irep *irep;
|
||||||
} u;
|
} u;
|
||||||
struct pic_env *env;
|
struct pic_env *env;
|
||||||
|
struct pic_dict *attr;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define PIC_PROC_KIND_FUNC 1
|
#define PIC_PROC_KIND_FUNC 1
|
||||||
|
@ -50,6 +51,8 @@ struct pic_proc *pic_proc_new_irep(pic_state *, struct pic_irep *, struct pic_en
|
||||||
|
|
||||||
pic_sym pic_proc_name(struct pic_proc *);
|
pic_sym pic_proc_name(struct pic_proc *);
|
||||||
|
|
||||||
|
struct pic_dict *pic_proc_attr(pic_state *, struct pic_proc *);
|
||||||
|
|
||||||
/* closed variables accessor */
|
/* closed variables accessor */
|
||||||
void pic_proc_cv_init(pic_state *, struct pic_proc *, size_t);
|
void pic_proc_cv_init(pic_state *, struct pic_proc *, size_t);
|
||||||
int pic_proc_cv_size(pic_state *, struct pic_proc *);
|
int pic_proc_cv_size(pic_state *, struct pic_proc *);
|
||||||
|
|
3
src/gc.c
3
src/gc.c
|
@ -381,6 +381,9 @@ gc_mark_object(pic_state *pic, struct pic_object *obj)
|
||||||
if (proc->env) {
|
if (proc->env) {
|
||||||
gc_mark_object(pic, (struct pic_object *)proc->env);
|
gc_mark_object(pic, (struct pic_object *)proc->env);
|
||||||
}
|
}
|
||||||
|
if (proc->attr) {
|
||||||
|
gc_mark_object(pic, (struct pic_object *)proc->attr);
|
||||||
|
}
|
||||||
if (pic_proc_irep_p(proc)) {
|
if (pic_proc_irep_p(proc)) {
|
||||||
gc_mark_object(pic, (struct pic_object *)proc->u.irep);
|
gc_mark_object(pic, (struct pic_object *)proc->u.irep);
|
||||||
}
|
}
|
||||||
|
|
12
src/proc.c
12
src/proc.c
|
@ -6,6 +6,7 @@
|
||||||
#include "picrin/pair.h"
|
#include "picrin/pair.h"
|
||||||
#include "picrin/proc.h"
|
#include "picrin/proc.h"
|
||||||
#include "picrin/irep.h"
|
#include "picrin/irep.h"
|
||||||
|
#include "picrin/dict.h"
|
||||||
|
|
||||||
struct pic_proc *
|
struct pic_proc *
|
||||||
pic_proc_new(pic_state *pic, pic_func_t func, const char *name)
|
pic_proc_new(pic_state *pic, pic_func_t func, const char *name)
|
||||||
|
@ -19,6 +20,7 @@ pic_proc_new(pic_state *pic, pic_func_t func, const char *name)
|
||||||
proc->u.func.f = func;
|
proc->u.func.f = func;
|
||||||
proc->u.func.name = pic_intern_cstr(pic, name);
|
proc->u.func.name = pic_intern_cstr(pic, name);
|
||||||
proc->env = NULL;
|
proc->env = NULL;
|
||||||
|
proc->attr = NULL;
|
||||||
return proc;
|
return proc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,6 +33,7 @@ pic_proc_new_irep(pic_state *pic, struct pic_irep *irep, struct pic_env *env)
|
||||||
proc->kind = PIC_PROC_KIND_IREP;
|
proc->kind = PIC_PROC_KIND_IREP;
|
||||||
proc->u.irep = irep;
|
proc->u.irep = irep;
|
||||||
proc->env = env;
|
proc->env = env;
|
||||||
|
proc->attr = NULL;
|
||||||
return proc;
|
return proc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,6 +49,15 @@ pic_proc_name(struct pic_proc *proc)
|
||||||
UNREACHABLE();
|
UNREACHABLE();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct pic_dict *
|
||||||
|
pic_proc_attr(pic_state *pic, struct pic_proc *proc)
|
||||||
|
{
|
||||||
|
if (proc->attr == NULL) {
|
||||||
|
proc->attr = pic_dict_new(pic);
|
||||||
|
}
|
||||||
|
return proc->attr;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
pic_proc_cv_init(pic_state *pic, struct pic_proc *proc, size_t cv_size)
|
pic_proc_cv_init(pic_state *pic, struct pic_proc *proc, size_t cv_size)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue