add aux object field to proc object
This commit is contained in:
parent
72a6e90d83
commit
f5154625ba
|
@ -10,13 +10,17 @@ struct pic_proc {
|
|||
PIC_OBJECT_HEADER
|
||||
bool cfunc_p;
|
||||
union {
|
||||
pic_value (*cfunc)(pic_state *);
|
||||
pic_func_t cfunc;
|
||||
struct pic_irep *irep;
|
||||
} u;
|
||||
pic_value aux;
|
||||
};
|
||||
|
||||
#define pic_proc_ptr(o) ((struct pic_proc *)o.u.data)
|
||||
|
||||
#define pic_proc_cfunc_p(o) (pic_proc_ptr(o)->cfunc_p)
|
||||
|
||||
struct pic_proc *pic_proc_new(pic_state *, struct pic_irep *irep);
|
||||
struct pic_proc *pic_proc_new_cfunc(pic_state *, pic_func_t cfunc, pic_value aux);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -77,9 +77,7 @@ pic_defun(pic_state *pic, const char *name, pic_func_t cfunc)
|
|||
struct pic_proc *proc;
|
||||
int idx;
|
||||
|
||||
proc = (struct pic_proc *)pic_obj_alloc(pic, sizeof(struct pic_proc), PIC_TT_PROC);
|
||||
proc->cfunc_p = true;
|
||||
proc->u.cfunc = cfunc;
|
||||
proc = pic_proc_new_cfunc(pic, cfunc, pic_undef_value());
|
||||
idx = env_global_define(pic, pic_intern_cstr(pic, name));
|
||||
pic->globals[idx] = pic_obj_value(proc);
|
||||
}
|
||||
|
@ -458,9 +456,8 @@ pic_codegen(pic_state *pic, pic_value obj, struct pic_env *env)
|
|||
struct pic_proc *proc;
|
||||
struct pic_irep *irep;
|
||||
|
||||
proc = (struct pic_proc *)pic_obj_alloc(pic, sizeof(struct pic_proc), PIC_TT_PROC);
|
||||
proc->cfunc_p = false;
|
||||
proc->u.irep = irep = new_irep(pic);
|
||||
irep = new_irep(pic);
|
||||
proc = pic_proc_new(pic, irep);
|
||||
|
||||
if (! pic->jmp) {
|
||||
jmp_buf jmp;
|
||||
|
|
1
src/gc.c
1
src/gc.c
|
@ -148,6 +148,7 @@ gc_mark_object(pic_state *pic, struct pic_object *obj)
|
|||
break;
|
||||
}
|
||||
case PIC_TT_PROC: {
|
||||
gc_mark(pic, ((struct pic_proc *)obj)->aux);
|
||||
break;
|
||||
}
|
||||
case PIC_TT_PORT: {
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
#include "picrin.h"
|
||||
#include "picrin/proc.h"
|
||||
#include "picrin/irep.h"
|
||||
|
||||
struct pic_proc *
|
||||
pic_proc_new(pic_state *pic, struct pic_irep *irep)
|
||||
{
|
||||
struct pic_proc *proc;
|
||||
|
||||
proc = (struct pic_proc *)pic_obj_alloc(pic, sizeof(struct pic_proc *), PIC_TT_PROC);
|
||||
proc->cfunc_p = false;
|
||||
proc->u.irep = irep;
|
||||
proc->aux = pic_undef_value();
|
||||
return proc;
|
||||
}
|
||||
|
||||
struct pic_proc *
|
||||
pic_proc_new_cfunc(pic_state *pic, pic_func_t cfunc, pic_value aux)
|
||||
{
|
||||
struct pic_proc *proc;
|
||||
|
||||
proc = (struct pic_proc *)pic_obj_alloc(pic, sizeof(struct pic_proc *), PIC_TT_PROC);
|
||||
proc->cfunc_p = true;
|
||||
proc->u.cfunc = cfunc;
|
||||
proc->aux = aux;
|
||||
return proc;
|
||||
}
|
4
src/vm.c
4
src/vm.c
|
@ -222,9 +222,7 @@ pic_run(pic_state *pic, struct pic_proc *proc, pic_value args)
|
|||
CASE(OP_LAMBDA) {
|
||||
struct pic_proc *proc;
|
||||
|
||||
proc = (struct pic_proc *)pic_obj_alloc(pic, sizeof(struct pic_proc *), PIC_TT_PROC);
|
||||
proc->cfunc_p = false;
|
||||
proc->u.irep = pic->irep[pc->u.i];
|
||||
proc = pic_proc_new(pic, pic->irep[pc->u.i]);
|
||||
PUSH(pic_obj_value(proc));
|
||||
pic_gc_arena_restore(pic, ai);
|
||||
NEXT;
|
||||
|
|
Loading…
Reference in New Issue