rename PIC_GC_MARK and PIC_GC_UNMARK

This commit is contained in:
Yuichi Nishiwaki 2016-02-20 23:01:12 +09:00
parent 9e5f846787
commit 4751131b4f
2 changed files with 14 additions and 12 deletions

View File

@ -5,6 +5,11 @@
#include "picrin.h" #include "picrin.h"
#include "picrin/object.h" #include "picrin/object.h"
enum {
WHITE = 0,
BLACK = 1
};
union header { union header {
struct { struct {
union header *ptr; union header *ptr;
@ -269,10 +274,10 @@ gc_mark_object(pic_state *pic, struct pic_object *obj)
{ {
loop: loop:
if (obj->u.basic.gc_mark == PIC_GC_MARK) if (obj->u.basic.gc_mark == BLACK)
return; return;
obj->u.basic.gc_mark = PIC_GC_MARK; obj->u.basic.gc_mark = BLACK;
#define LOOP(o) obj = (struct pic_object *)(o); goto loop #define LOOP(o) obj = (struct pic_object *)(o); goto loop
@ -511,8 +516,8 @@ gc_mark_phase(pic_state *pic)
continue; continue;
key = kh_key(h, it); key = kh_key(h, it);
val = kh_val(h, it); val = kh_val(h, it);
if (key->u.basic.gc_mark == PIC_GC_MARK) { if (key->u.basic.gc_mark == BLACK) {
if (pic_obj_p(pic, val) && pic_obj_ptr(val)->u.basic.gc_mark == PIC_GC_UNMARK) { if (pic_obj_p(pic, val) && pic_obj_ptr(val)->u.basic.gc_mark == WHITE) {
gc_mark(pic, val); gc_mark(pic, val);
++j; ++j;
} }
@ -606,8 +611,8 @@ gc_sweep_page(pic_state *pic, struct heap_page *page)
goto escape; goto escape;
} }
obj = (struct pic_object *)(p + 1); obj = (struct pic_object *)(p + 1);
if (obj->u.basic.gc_mark == PIC_GC_MARK) { if (obj->u.basic.gc_mark == BLACK) {
obj->u.basic.gc_mark = PIC_GC_UNMARK; obj->u.basic.gc_mark = WHITE;
alive += p->s.size; alive += p->s.size;
} else { } else {
if (head == NULL) { if (head == NULL) {
@ -652,7 +657,7 @@ gc_sweep_phase(pic_state *pic)
if (! kh_exist(h, it)) if (! kh_exist(h, it))
continue; continue;
obj = kh_key(h, it); obj = kh_key(h, it);
if (obj->u.basic.gc_mark == PIC_GC_UNMARK) { if (obj->u.basic.gc_mark == WHITE) {
kh_del(weak, h, it); kh_del(weak, h, it);
} }
} }
@ -664,7 +669,7 @@ gc_sweep_phase(pic_state *pic)
if (! kh_exist(s, it)) if (! kh_exist(s, it))
continue; continue;
sym = kh_val(s, it); sym = kh_val(s, it);
if (sym->gc_mark == PIC_GC_UNMARK) { if (sym->gc_mark == WHITE) {
kh_del(oblist, s, it); kh_del(oblist, s, it);
} }
} }
@ -721,7 +726,7 @@ pic_obj_alloc_unsafe(pic_state *pic, size_t size, int type)
pic_panic(pic, "GC memory exhausted"); pic_panic(pic, "GC memory exhausted");
} }
} }
obj->u.basic.gc_mark = PIC_GC_UNMARK; obj->u.basic.gc_mark = WHITE;
obj->u.basic.tt = type; obj->u.basic.tt = type;
return obj; return obj;

View File

@ -9,9 +9,6 @@
extern "C" { extern "C" {
#endif #endif
#define PIC_GC_UNMARK 0
#define PIC_GC_MARK 1
struct pic_heap; struct pic_heap;
struct pic_heap *pic_heap_open(pic_state *); struct pic_heap *pic_heap_open(pic_state *);