add box.h

This commit is contained in:
Yuichi Nishiwaki 2015-08-04 08:17:58 +09:00
parent 261580309e
commit 987931bd0f
4 changed files with 46 additions and 0 deletions

View File

@ -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:

View File

@ -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)
}

View File

@ -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

View File

@ -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: