John Mastro
2016-03-15 18:39:48 UTC
Hello,
I suspect this question is quite basic, but I haven't been able to
figure it out on my own.
I'm implementing a small programming language and would like to use
BDWGC for garbage collection. I'm using tagged pointers, where the 3
least-significant bits can carry a type tag. The tagged value may be
either an immediate (e.g. an integer) or a pointer. In other words, I
have something like this:
typedef intptr_t object;
#define TAG_BITS 3
#define VAL_MASK -(1 << TAG_BITS)
enum obj_tag { TAG_INT = 1, TAG_LIST };
typedef struct {
object head, tail;
} obj_list;
#define make_integer(i) (((i) << TAG_BITS) + TAG_INT)
#define extract_integer(o) ((o) >> TAG_BITS)
object make_list(object head, object tail)
{
obj_list *list = /* allocate it */;
list->head = head;
list->tail = tail;
return ((intptr_t)list) + TAG_LIST;
}
#define extract_list(o) ((void *)((o) & VAL_MASK))
... which I think is pretty standard/boring. However, I believe I need
to teach BDWGC about this tagging, so it knows these `object` values may
(or may not) represent pointers, and I'm not sure how to do that.
Are there any documents, examples, or other help on how to accomplish
this?
Thanks,
John Mastro
I suspect this question is quite basic, but I haven't been able to
figure it out on my own.
I'm implementing a small programming language and would like to use
BDWGC for garbage collection. I'm using tagged pointers, where the 3
least-significant bits can carry a type tag. The tagged value may be
either an immediate (e.g. an integer) or a pointer. In other words, I
have something like this:
typedef intptr_t object;
#define TAG_BITS 3
#define VAL_MASK -(1 << TAG_BITS)
enum obj_tag { TAG_INT = 1, TAG_LIST };
typedef struct {
object head, tail;
} obj_list;
#define make_integer(i) (((i) << TAG_BITS) + TAG_INT)
#define extract_integer(o) ((o) >> TAG_BITS)
object make_list(object head, object tail)
{
obj_list *list = /* allocate it */;
list->head = head;
list->tail = tail;
return ((intptr_t)list) + TAG_LIST;
}
#define extract_list(o) ((void *)((o) & VAL_MASK))
... which I think is pretty standard/boring. However, I believe I need
to teach BDWGC about this tagging, so it knows these `object` values may
(or may not) represent pointers, and I'm not sure how to do that.
Are there any documents, examples, or other help on how to accomplish
this?
Thanks,
John Mastro