From 931565d4ce7bdd366ba166de8bce9000c2f82c31 Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Sat, 7 Dec 2013 03:58:18 -0800 Subject: [PATCH] add pic_lib --- include/picrin/lib.h | 10 ++++++++++ include/picrin/value.h | 3 ++- src/codegen.c | 3 ++- src/gc.c | 11 +++++++++++ src/macro.c | 1 + src/port.c | 3 +++ src/value.c | 2 ++ 7 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 include/picrin/lib.h diff --git a/include/picrin/lib.h b/include/picrin/lib.h new file mode 100644 index 00000000..348b6739 --- /dev/null +++ b/include/picrin/lib.h @@ -0,0 +1,10 @@ +#ifndef LIB_H__ +#define LIB_H__ + +struct pic_lib { + PIC_OBJECT_HEADER + struct pic_senv *senv; + struct xhash *exports; +}; + +#endif diff --git a/include/picrin/value.h b/include/picrin/value.h index b64478fb..8e2ce7a6 100644 --- a/include/picrin/value.h +++ b/include/picrin/value.h @@ -92,7 +92,8 @@ enum pic_tt { PIC_TT_CONT, PIC_TT_SENV, PIC_TT_SYNTAX, - PIC_TT_SC + PIC_TT_SC, + PIC_TT_LIB }; #define PIC_OBJECT_HEADER \ diff --git a/src/codegen.c b/src/codegen.c index a368ee60..f79abb42 100644 --- a/src/codegen.c +++ b/src/codegen.c @@ -664,7 +664,8 @@ codegen(codegen_state *state, pic_value obj, bool tailpos) case PIC_TT_ERROR: case PIC_TT_SENV: case PIC_TT_SYNTAX: - case PIC_TT_SC: { + case PIC_TT_SC: + case PIC_TT_LIB: { pic_error(pic, "invalid expression given"); } } diff --git a/src/gc.c b/src/gc.c index 7c03e3fd..b2cd56a0 100644 --- a/src/gc.c +++ b/src/gc.c @@ -9,6 +9,7 @@ #include "picrin/cont.h" #include "picrin/error.h" #include "picrin/macro.h" +#include "picrin/lib.h" #include "xhash/xhash.h" #if GC_DEBUG @@ -396,6 +397,11 @@ gc_mark_object(pic_state *pic, struct pic_object *obj) gc_mark_object(pic, (struct pic_object *)sc->senv); break; } + case PIC_TT_LIB: { + struct pic_lib *lib = (struct pic_lib *)obj; + gc_mark_object(pic, (struct pic_object *)lib->senv); + break; + } case PIC_TT_NIL: case PIC_TT_BOOL: case PIC_TT_FLOAT: @@ -529,6 +535,11 @@ gc_finalize_object(pic_state *pic, struct pic_object *obj) case PIC_TT_SC: { break; } + case PIC_TT_LIB: { + struct pic_lib *lib = (struct pic_lib *)obj; + xh_destory(lib->exports); + break; + } case PIC_TT_NIL: case PIC_TT_BOOL: case PIC_TT_FLOAT: diff --git a/src/macro.c b/src/macro.c index 6648b18a..e750d9a3 100644 --- a/src/macro.c +++ b/src/macro.c @@ -415,6 +415,7 @@ macroexpand(pic_state *pic, pic_value expr, struct pic_senv *senv) case PIC_TT_UNDEF: case PIC_TT_SENV: case PIC_TT_SYNTAX: + case PIC_TT_LIB: pic_error(pic, "unexpected value type"); return pic_undef_value(); /* unreachable */ } diff --git a/src/port.c b/src/port.c index ea8fde9b..fb5abd3c 100644 --- a/src/port.c +++ b/src/port.c @@ -109,6 +109,9 @@ write(pic_state *pic, pic_value obj) write(pic, pic_sc(obj)->expr); printf(">"); break; + case PIC_TT_LIB: + printf("#", pic_ptr(obj)); + break; } } diff --git a/src/value.c b/src/value.c index 9922cd00..ac73907e 100644 --- a/src/value.c +++ b/src/value.c @@ -76,6 +76,8 @@ pic_type_repr(enum pic_tt tt) return "senv"; case PIC_TT_SYNTAX: return "syntax"; + case PIC_TT_LIB: + return "lib"; } /* logic flaw */ abort();