From 1f3f7c99a2890fde5febffe81bf47d51f6f929f8 Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Tue, 26 Nov 2013 08:42:13 -0800 Subject: [PATCH] save macro procesures in each syntax object --- include/picrin/macro.h | 3 +++ src/gc.c | 5 +++++ src/macro.c | 13 +++++++++++++ 3 files changed, 21 insertions(+) diff --git a/include/picrin/macro.h b/include/picrin/macro.h index 1dd6cd81..672feb73 100644 --- a/include/picrin/macro.h +++ b/include/picrin/macro.h @@ -18,14 +18,17 @@ struct pic_syntax { PIC_STX_LAMBDA, PIC_STX_IF, PIC_STX_BEGIN, + PIC_STX_MACRO, PIC_STX_DEFMACRO } kind; pic_sym sym; + struct pic_proc *macro; }; #define pic_syntax(v) ((struct pic_syntax *)pic_ptr(v)) #define pic_syntax_p(v) (pic_type(v) == PIC_TT_SYNTAX) struct pic_syntax *pic_syntax_new(pic_state *, int kind, pic_sym sym); +struct pic_syntax *pic_syntax_new_macro(pic_state *, pic_sym, struct pic_proc *); #endif diff --git a/src/gc.c b/src/gc.c index 2264d5bc..c12a1633 100644 --- a/src/gc.c +++ b/src/gc.c @@ -276,6 +276,11 @@ gc_mark_object(pic_state *pic, struct pic_object *obj) break; } case PIC_TT_SYNTAX: { + struct pic_syntax *stx = (struct pic_syntax *)obj; + + if (stx->macro) { + gc_mark_object(pic, (struct pic_object *)stx->macro); + } break; } case PIC_TT_SENV: { diff --git a/src/macro.c b/src/macro.c index b379aed0..e4825e39 100644 --- a/src/macro.c +++ b/src/macro.c @@ -385,6 +385,19 @@ pic_syntax_new(pic_state *pic, int kind, pic_sym sym) stx = (struct pic_syntax *)pic_obj_alloc(pic, sizeof(struct pic_syntax), PIC_TT_SYNTAX); stx->kind = kind; stx->sym = sym; + stx->macro = NULL; + return stx; +} + +struct pic_syntax * +pic_syntax_new_macro(pic_state *pic, pic_sym sym, struct pic_proc *macro) +{ + struct pic_syntax *stx; + + stx = (struct pic_syntax *)pic_obj_alloc(pic, sizeof(struct pic_syntax), PIC_TT_SYNTAX); + stx->kind = PIC_STX_MACRO; + stx->sym = sym; + stx->macro = macro; return stx; }