diff --git a/include/picrin/value.h b/include/picrin/value.h index c2029fb2..56aa9453 100644 --- a/include/picrin/value.h +++ b/include/picrin/value.h @@ -93,7 +93,8 @@ enum pic_tt { PIC_TT_SENV, PIC_TT_SYNTAX, PIC_TT_SC, - PIC_TT_LIB + PIC_TT_LIB, + PIC_TT_VAR }; #define PIC_OBJECT_HEADER \ diff --git a/src/codegen.c b/src/codegen.c index 05ab6246..464daa8e 100644 --- a/src/codegen.c +++ b/src/codegen.c @@ -673,7 +673,8 @@ codegen(codegen_state *state, pic_value obj, bool tailpos) case PIC_TT_SENV: case PIC_TT_SYNTAX: case PIC_TT_SC: - case PIC_TT_LIB: { + case PIC_TT_LIB: + case PIC_TT_VAR: { pic_error(pic, "invalid expression given"); } } diff --git a/src/gc.c b/src/gc.c index 422c527d..925ca161 100644 --- a/src/gc.c +++ b/src/gc.c @@ -10,6 +10,7 @@ #include "picrin/error.h" #include "picrin/macro.h" #include "picrin/lib.h" +#include "picrin/var.h" #include "xhash/xhash.h" #if GC_DEBUG @@ -403,6 +404,14 @@ gc_mark_object(pic_state *pic, struct pic_object *obj) gc_mark_object(pic, (struct pic_object *)lib->senv); break; } + case PIC_TT_VAR: { + struct pic_var *var = (struct pic_var *)obj; + gc_mark(pic, var->value); + if (var->conv) { + gc_mark_object(pic, (struct pic_object *)var->conv); + } + break; + } case PIC_TT_NIL: case PIC_TT_BOOL: case PIC_TT_FLOAT: @@ -539,6 +548,9 @@ gc_finalize_object(pic_state *pic, struct pic_object *obj) xh_destory(lib->exports); break; } + case PIC_TT_VAR: { + break; + } case PIC_TT_NIL: case PIC_TT_BOOL: case PIC_TT_FLOAT: diff --git a/src/init.c b/src/init.c index b1ef3b08..cf9d7ab0 100644 --- a/src/init.c +++ b/src/init.c @@ -22,6 +22,7 @@ void pic_init_char(pic_state *); void pic_init_error(pic_state *); void pic_init_str(pic_state *); void pic_init_macro(pic_state *); +void pic_init_var(pic_state *); void pic_load_stdlib(pic_state *pic) @@ -124,6 +125,7 @@ pic_init_core(pic_state *pic) pic_init_error(pic); DONE; pic_init_str(pic); DONE; pic_init_macro(pic); DONE; + pic_init_var(pic); DONE; pic_load_stdlib(pic); DONE; diff --git a/src/macro.c b/src/macro.c index 56288401..0cd38949 100644 --- a/src/macro.c +++ b/src/macro.c @@ -560,6 +560,7 @@ macroexpand(pic_state *pic, pic_value expr, struct pic_senv *senv) case PIC_TT_SENV: case PIC_TT_SYNTAX: case PIC_TT_LIB: + case PIC_TT_VAR: pic_error(pic, "unexpected value type"); return pic_undef_value(); /* unreachable */ } diff --git a/src/port.c b/src/port.c index a106350e..a1e84e3e 100644 --- a/src/port.c +++ b/src/port.c @@ -112,6 +112,9 @@ write(pic_state *pic, pic_value obj) case PIC_TT_LIB: printf("#", pic_ptr(obj)); break; + case PIC_TT_VAR: + printf("#", pic_ptr(obj)); + break; } } diff --git a/src/value.c b/src/value.c index b33c6fe4..2b73c53e 100644 --- a/src/value.c +++ b/src/value.c @@ -78,6 +78,8 @@ pic_type_repr(enum pic_tt tt) return "syntax"; case PIC_TT_LIB: return "lib"; + case PIC_TT_VAR: + return "var"; } /* logic flaw */ abort();