save macro procesures in each syntax object

This commit is contained in:
Yuichi Nishiwaki 2013-11-26 08:42:13 -08:00
parent 3d1f74d8f5
commit 1f3f7c99a2
3 changed files with 21 additions and 0 deletions

View File

@ -18,14 +18,17 @@ struct pic_syntax {
PIC_STX_LAMBDA, PIC_STX_LAMBDA,
PIC_STX_IF, PIC_STX_IF,
PIC_STX_BEGIN, PIC_STX_BEGIN,
PIC_STX_MACRO,
PIC_STX_DEFMACRO PIC_STX_DEFMACRO
} kind; } kind;
pic_sym sym; pic_sym sym;
struct pic_proc *macro;
}; };
#define pic_syntax(v) ((struct pic_syntax *)pic_ptr(v)) #define pic_syntax(v) ((struct pic_syntax *)pic_ptr(v))
#define pic_syntax_p(v) (pic_type(v) == PIC_TT_SYNTAX) #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(pic_state *, int kind, pic_sym sym);
struct pic_syntax *pic_syntax_new_macro(pic_state *, pic_sym, struct pic_proc *);
#endif #endif

View File

@ -276,6 +276,11 @@ gc_mark_object(pic_state *pic, struct pic_object *obj)
break; break;
} }
case PIC_TT_SYNTAX: { 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; break;
} }
case PIC_TT_SENV: { case PIC_TT_SENV: {

View File

@ -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 = (struct pic_syntax *)pic_obj_alloc(pic, sizeof(struct pic_syntax), PIC_TT_SYNTAX);
stx->kind = kind; stx->kind = kind;
stx->sym = sym; 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; return stx;
} }