summaryrefslogtreecommitdiff
path: root/src/lisp/ao_lisp_frame.c
diff options
context:
space:
mode:
authorKeith Packard <keithp@keithp.com>2016-11-05 14:51:58 -0700
committerKeith Packard <keithp@keithp.com>2017-02-20 11:16:50 -0800
commit3366efb139653939f053c1fe4aba352ba3b66c94 (patch)
tree57c01798cfaef078e4e8ca11680a9bb748ed3334 /src/lisp/ao_lisp_frame.c
parent6fc1ee0f7adc6fcb3e850bcbaabc1db705314234 (diff)
altos/lisp: Change GC move API
Pass reference to move API so it can change the values in-place, then let it return '1' when the underlying object has already been moved to shorten GC times. Signed-off-by: Keith Packard <keithp@keithp.com>
Diffstat (limited to 'src/lisp/ao_lisp_frame.c')
-rw-r--r--src/lisp/ao_lisp_frame.c48
1 files changed, 22 insertions, 26 deletions
diff --git a/src/lisp/ao_lisp_frame.c b/src/lisp/ao_lisp_frame.c
index 1853f6d7..8bf98571 100644
--- a/src/lisp/ao_lisp_frame.c
+++ b/src/lisp/ao_lisp_frame.c
@@ -33,7 +33,7 @@ frame_size(void *addr)
return frame_num_size(frame->num);
}
-#define OFFSET(a) ((uint8_t *) (ao_lisp_ref(a)) - ao_lisp_const)
+#define OFFSET(a) ((int) ((uint8_t *) (ao_lisp_ref(a)) - ao_lisp_const))
static void
frame_mark(void *addr)
@@ -42,16 +42,19 @@ frame_mark(void *addr)
int f;
for (;;) {
- if (frame->readonly)
+ DBG("frame mark %p\n", frame);
+ if (!AO_LISP_IS_POOL(frame))
break;
for (f = 0; f < frame->num; f++) {
struct ao_lisp_val *v = &frame->vals[f];
- ao_lisp_poly_mark(v->atom);
ao_lisp_poly_mark(v->val);
- DBG ("\tframe mark atom %s %d val %d at %d\n", ao_lisp_poly_atom(v->atom)->name, OFFSET(v->atom), OFFSET(v->val), f);
+ DBG ("\tframe mark atom %s %d val %d at %d\n",
+ ao_lisp_poly_atom(v->atom)->name,
+ OFFSET(v->atom), OFFSET(v->val), f);
}
frame = ao_lisp_poly_frame(frame->next);
+ DBG("frame next %p\n", frame);
if (!frame)
break;
if (ao_lisp_mark_memory(frame, frame_size(frame)))
@@ -66,26 +69,19 @@ frame_move(void *addr)
int f;
for (;;) {
- struct ao_lisp_frame *next;
- if (frame->readonly)
+ DBG("frame move %p\n", frame);
+ if (!AO_LISP_IS_POOL(frame))
break;
for (f = 0; f < frame->num; f++) {
struct ao_lisp_val *v = &frame->vals[f];
- ao_poly t;
-
- t = ao_lisp_poly_move(v->atom);
- DBG("\t\tatom %s %d -> %d\n", ao_lisp_poly_atom(t)->name, OFFSET(v->atom), OFFSET(t));
- v->atom = t;
- t = ao_lisp_poly_move(v->val);
- DBG("\t\tval %d -> %d\n", OFFSET(v->val), OFFSET(t));
- v->val = t;
+
+ ao_lisp_poly_move(&v->atom);
+ DBG("moved atom %s\n", ao_lisp_poly_atom(v->atom)->name);
+ ao_lisp_poly_move(&v->val);
}
- next = ao_lisp_poly_frame(frame->next);
- if (!next)
+ if (ao_lisp_poly_move(&frame->next))
break;
- next = ao_lisp_move_memory(next, frame_size(next));
- frame->next = ao_lisp_frame_poly(next);
- frame = next;
+ frame = ao_lisp_poly_frame(frame->next);
}
}
@@ -109,7 +105,7 @@ int
ao_lisp_frame_set(struct ao_lisp_frame *frame, ao_poly atom, ao_poly val)
{
while (frame) {
- if (!frame->readonly) {
+ if (!AO_LISP_IS_CONST(frame)) {
ao_poly *ref = ao_lisp_frame_ref(frame, atom);
if (ref) {
*ref = val;
@@ -134,28 +130,28 @@ ao_lisp_frame_get(struct ao_lisp_frame *frame, ao_poly atom)
}
struct ao_lisp_frame *
-ao_lisp_frame_new(int num, int readonly)
+ao_lisp_frame_new(int num)
{
struct ao_lisp_frame *frame = ao_lisp_alloc(frame_num_size(num));
if (!frame)
return NULL;
+ frame->type = AO_LISP_FRAME;
frame->num = num;
- frame->readonly = readonly;
frame->next = AO_LISP_NIL;
memset(frame->vals, '\0', num * sizeof (struct ao_lisp_val));
return frame;
}
static struct ao_lisp_frame *
-ao_lisp_frame_realloc(struct ao_lisp_frame *frame, int new_num, int readonly)
+ao_lisp_frame_realloc(struct ao_lisp_frame *frame, int new_num)
{
struct ao_lisp_frame *new;
int copy;
if (new_num == frame->num)
return frame;
- new = ao_lisp_frame_new(new_num, readonly);
+ new = ao_lisp_frame_new(new_num);
if (!new)
return NULL;
copy = new_num;
@@ -175,10 +171,10 @@ ao_lisp_frame_add(struct ao_lisp_frame *frame, ao_poly atom, ao_poly val)
int f;
if (frame) {
f = frame->num;
- frame = ao_lisp_frame_realloc(frame, f + 1, frame->readonly);
+ frame = ao_lisp_frame_realloc(frame, f + 1);
} else {
f = 0;
- frame = ao_lisp_frame_new(1, 0);
+ frame = ao_lisp_frame_new(1);
}
if (!frame)
return NULL;