diff --git a/extlib/benz/gc.c b/extlib/benz/gc.c index 2e7ae20f..a7096cca 100644 --- a/extlib/benz/gc.c +++ b/extlib/benz/gc.c @@ -35,6 +35,7 @@ union object { struct pic_port port; struct pic_error err; struct pic_lib lib; + struct pic_box box; struct pic_checkpoint cp; }; @@ -405,6 +406,12 @@ gc_mark_object(pic_state *pic, union object *obj) pic->heap->regs = reg; break; } + case PIC_TT_BOX: { + if (pic_obj_p(obj->box.value)) { + LOOP(pic_obj_ptr(obj->box.value)); + } + break; + } case PIC_TT_CP: { if (obj->cp.prev) { gc_mark_object(pic, (union object *)obj->cp.prev); @@ -597,6 +604,7 @@ gc_finalize_object(pic_state *pic, union object *obj) case PIC_TT_LIB: case PIC_TT_RECORD: case PIC_TT_CP: + case PIC_TT_BOX: break; case PIC_TT_NIL: diff --git a/extlib/benz/include/picrin.h b/extlib/benz/include/picrin.h index 30ec8a58..da2a4885 100644 --- a/extlib/benz/include/picrin.h +++ b/extlib/benz/include/picrin.h @@ -268,6 +268,7 @@ pic_value pic_fdisplay(pic_state *, pic_value, xFILE *); #include "picrin/symbol.h" #include "picrin/vector.h" #include "picrin/reg.h" +#include "picrin/box.h" #if defined(__cplusplus) } diff --git a/extlib/benz/include/picrin/box.h b/extlib/benz/include/picrin/box.h new file mode 100644 index 00000000..dcfa676a --- /dev/null +++ b/extlib/benz/include/picrin/box.h @@ -0,0 +1,34 @@ +/** + * See Copyright Notice in picrin.h + */ + +#ifndef PICRIN_BOX_H +#define PICRIN_BOX_H + +#if defined(__cplusplus) +extern "C" { +#endif + +struct pic_box { + PIC_OBJECT_HEADER + pic_value value; +}; + +#define pic_box_p(v) (pic_type(v) == PIC_TT_BOX) +#define pic_box_ptr(v) ((struct pic_box *)pic_ptr(v)) + +PIC_INLINE struct pic_box * +pic_box(pic_state *pic, pic_value value) +{ + struct pic_box *box; + + box = (struct pic_box *)pic_obj_alloc(pic, sizeof(struct pic_box), PIC_TT_BOX); + box->value = value; + return box; +} + +#if defined(__cplusplus) +} +#endif + +#endif diff --git a/extlib/benz/include/picrin/type.h b/extlib/benz/include/picrin/type.h index 0df475a8..4de8d279 100644 --- a/extlib/benz/include/picrin/type.h +++ b/extlib/benz/include/picrin/type.h @@ -156,6 +156,7 @@ enum pic_tt { PIC_TT_DICT, PIC_TT_REG, PIC_TT_RECORD, + PIC_TT_BOX, PIC_TT_CXT, PIC_TT_IREP, PIC_TT_CP @@ -313,6 +314,8 @@ pic_type_repr(enum pic_tt tt) return "dict"; case PIC_TT_REG: return "reg"; + case PIC_TT_BOX: + return "box"; case PIC_TT_RECORD: return "record"; case PIC_TT_CP: