diff --git a/include/picrin/value.h b/include/picrin/value.h index 42354c78..d14b8a51 100644 --- a/include/picrin/value.h +++ b/include/picrin/value.h @@ -89,7 +89,9 @@ enum pic_tt { PIC_TT_PORT, PIC_TT_ERROR, PIC_TT_ENV, - PIC_TT_CONT + PIC_TT_CONT, + PIC_TT_SENV, + PIC_TT_SYNTAX }; #define PIC_OBJECT_HEADER \ diff --git a/src/codegen.c b/src/codegen.c index 6aac14b5..57340867 100644 --- a/src/codegen.c +++ b/src/codegen.c @@ -658,7 +658,9 @@ codegen(codegen_state *state, pic_value obj, bool tailpos) case PIC_TT_UNDEF: case PIC_TT_EOF: case PIC_TT_PORT: - case PIC_TT_ERROR: { + case PIC_TT_ERROR: + case PIC_TT_SENV: + case PIC_TT_SYNTAX: { pic_error(pic, "invalid expression given"); } } diff --git a/src/gc.c b/src/gc.c index 1c9fddef..23aa1560 100644 --- a/src/gc.c +++ b/src/gc.c @@ -8,6 +8,8 @@ #include "picrin/blob.h" #include "picrin/cont.h" #include "picrin/error.h" +#include "picrin/macro.h" +#include "xhash/xhash.h" #if GC_DEBUG # include @@ -273,6 +275,24 @@ gc_mark_object(pic_state *pic, struct pic_object *obj) gc_mark(pic, cont->result); break; } + case PIC_TT_SYNTAX: { + break; + } + case PIC_TT_SENV: { + struct pic_senv *senv = (struct pic_senv *)obj; + + if (senv->up) { + gc_mark_object(pic, (struct pic_object *)senv->up); + } + if (senv->stx) { + int i; + + for (i = 0; i < 6; ++i) { + gc_mark_object(pic, (struct pic_object *)senv->stx[i]); + } + } + break; + } case PIC_TT_NIL: case PIC_TT_BOOL: case PIC_TT_FLOAT: @@ -397,6 +417,16 @@ gc_finalize_object(pic_state *pic, struct pic_object *obj) PIC_BLK_DECREF(pic, cont->blk); break; } + case PIC_TT_SENV: { + struct pic_senv *senv = (struct pic_senv *)obj; + xh_destory(senv->tbl); + if (senv->stx) + pic_free(pic, senv->stx); + break; + } + case PIC_TT_SYNTAX: { + break; + } case PIC_TT_NIL: case PIC_TT_BOOL: case PIC_TT_FLOAT: diff --git a/src/macro.c b/src/macro.c index 72f4caa1..dca9b8bc 100644 --- a/src/macro.c +++ b/src/macro.c @@ -162,6 +162,8 @@ expand(pic_state *pic, pic_value obj, struct syntactic_env *env) case PIC_TT_ENV: case PIC_TT_CONT: case PIC_TT_UNDEF: + case PIC_TT_SENV: + case PIC_TT_SYNTAX: pic_error(pic, "unexpected value type"); return pic_undef_value(); /* unreachable */ } diff --git a/src/port.c b/src/port.c index 0c3709fd..06a2f5f9 100644 --- a/src/port.c +++ b/src/port.c @@ -97,6 +97,12 @@ write(pic_state *pic, pic_value obj) case PIC_TT_CONT: printf("#", pic_ptr(obj)); break; + case PIC_TT_SENV: + printf("#", pic_ptr(obj)); + break; + case PIC_TT_SYNTAX: + printf("#", pic_ptr(obj)); + break; } }