From 1fb9ac5d03df545237973dc84b2ea05204bd7238 Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Sun, 13 Oct 2013 16:16:13 +0900 Subject: [PATCH] let pic_proc be a first class object --- include/picrin.h | 6 ------ include/picrin/value.h | 11 ++++++++++- src/vm.c | 2 +- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/include/picrin.h b/include/picrin.h index 79995f24..ec469abe 100644 --- a/include/picrin.h +++ b/include/picrin.h @@ -11,12 +11,6 @@ struct pic_env { struct pic_env *parent; }; -struct pic_proc { - union { - struct pic_irep *irep; - } u; -}; - #define PIC_HEAP_SIZE 1024 typedef struct { diff --git a/include/picrin/value.h b/include/picrin/value.h index 3666aec1..b2acba8b 100644 --- a/include/picrin/value.h +++ b/include/picrin/value.h @@ -23,7 +23,8 @@ enum pic_tt { PIC_TT_UNDEF, /* heap */ PIC_TT_PAIR, - PIC_TT_SYMBOL + PIC_TT_SYMBOL, + PIC_TT_PROC }; #define PIC_OBJECT_HEADER \ @@ -44,8 +45,16 @@ struct pic_symbol { char *name; }; +struct pic_proc { + PIC_OBJECT_HEADER + union { + struct pic_irep *irep; + } u; +}; + #define pic_pair_ptr(o) ((struct pic_pair *)o.u.data) #define pic_symbol_ptr(o) ((struct pic_symbol *)o.u.data) +#define pic_proc_ptr(o) ((struct pic_proc *)o.u.data) enum pic_tt pic_type(pic_value); diff --git a/src/vm.c b/src/vm.c index 439d9cd8..3d5e8c31 100644 --- a/src/vm.c +++ b/src/vm.c @@ -161,7 +161,7 @@ pic_codegen(pic_state *pic, pic_value obj, struct pic_env *env) struct pic_irep *irep; struct pic_code *code; - proc = (struct pic_proc *)malloc(sizeof(struct pic_proc)); + proc = (struct pic_proc *)pic_gc_alloc(pic, sizeof(struct pic_proc), PIC_TT_PROC); proc->u.irep = irep = (struct pic_irep *)malloc(sizeof(struct pic_irep)); irep->code = code = (struct pic_code *)malloc(sizeof(struct pic_code) * 1024);