add pic_lib
This commit is contained in:
parent
acbcde3b6a
commit
931565d4ce
|
@ -0,0 +1,10 @@
|
|||
#ifndef LIB_H__
|
||||
#define LIB_H__
|
||||
|
||||
struct pic_lib {
|
||||
PIC_OBJECT_HEADER
|
||||
struct pic_senv *senv;
|
||||
struct xhash *exports;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -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 \
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
}
|
||||
|
|
11
src/gc.c
11
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:
|
||||
|
|
|
@ -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 */
|
||||
}
|
||||
|
|
|
@ -109,6 +109,9 @@ write(pic_state *pic, pic_value obj)
|
|||
write(pic, pic_sc(obj)->expr);
|
||||
printf(">");
|
||||
break;
|
||||
case PIC_TT_LIB:
|
||||
printf("#<library %p>", pic_ptr(obj));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in New Issue