From: Keith Packard Date: Fri, 11 Nov 2016 08:28:57 +0000 (-0800) Subject: altos/lisp: Share mark function for mark and move X-Git-Tag: 1.7~176 X-Git-Url: https://git.gag.com/?p=fw%2Faltos;a=commitdiff_plain;h=00827a0ffe30938c26be216369fd2d8f8946d2c4 altos/lisp: Share mark function for mark and move These two operations both wanted to walk the referenced objects; sharing is caring. Signed-off-by: Keith Packard --- diff --git a/src/lambdakey-v1.0/Makefile b/src/lambdakey-v1.0/Makefile index ef03527e..1ac04f24 100644 --- a/src/lambdakey-v1.0/Makefile +++ b/src/lambdakey-v1.0/Makefile @@ -56,6 +56,8 @@ IDPRODUCT=0x000a CFLAGS = $(PRODUCT_DEF) $(STMF0_CFLAGS) -Os -g +LDFLAGS=$(CFLAGS) -L$(TOPDIR)/stmf0 -Wl,-Tlambda.ld + PROGNAME=lambdakey-v1.0 PROG=$(PROGNAME)-$(VERSION).elf HEX=$(PROGNAME)-$(VERSION).ihx @@ -65,7 +67,7 @@ OBJ=$(SRC:.c=.o) all: $(PROG) $(HEX) -$(PROG): Makefile $(OBJ) altos.ld +$(PROG): Makefile $(OBJ) lambda.ld altos.ld $(call quiet,CC) $(LDFLAGS) $(CFLAGS) -o $(PROG) $(OBJ) $(LIBS) $(OBJ): $(INC) diff --git a/src/lisp/ao_lisp_mem.c b/src/lisp/ao_lisp_mem.c index b763d78b..1fb1b459 100644 --- a/src/lisp/ao_lisp_mem.c +++ b/src/lisp/ao_lisp_mem.c @@ -79,7 +79,6 @@ uint16_t ao_lisp_top; static inline void mark(uint8_t *tag, int offset) { int byte = offset >> 5; int bit = (offset >> 2) & 7; - tag[byte] |= (1 << bit); } @@ -176,42 +175,32 @@ note_cons(void *addr) } } - -static void *move_old, *move_new; -static int move_size; +/* + * Walk all referenced objects calling functions on each one + */ static void -move_object(void) +walk_all(uint8_t *tag, + int (*visit_addr)(const struct ao_lisp_type *type, void **addr), + int (*visit_poly)(ao_poly *p, uint8_t do_note_cons)) { - int i; + int i; - MDBG_RESET(); - MDBG_MOVE("move %d -> %d\n", MDBG_OFFSET(move_old), MDBG_OFFSET(move_new)); - MDBG_MOVE_IN(); - memset(ao_lisp_moving, '\0', sizeof (ao_lisp_moving)); + memset(tag, '\0', sizeof (ao_lisp_busy)); memset(ao_lisp_cons_note, '\0', sizeof (ao_lisp_cons_note)); ao_lisp_cons_noted = 0; for (i = 0; i < AO_LISP_ROOT; i++) { - if (!ao_lisp_root[i].addr) - continue; if (ao_lisp_root[i].type) { - void *addr = *ao_lisp_root[i].addr; - if (!addr) - continue; - MDBG_MOVE("root %d\n", MDBG_OFFSET(addr)); - if (!ao_lisp_move(ao_lisp_root[i].type, - ao_lisp_root[i].addr)) { - MDBG_MOVE("root moves from %p to %p\n", - addr, - *ao_lisp_root[i].addr); + void **a = ao_lisp_root[i].addr, *v; + if (a && (v = *a)) { + MDBG("root %d\n", MDBG_OFFSET(v)); + visit_addr(ao_lisp_root[i].type, a); } } else { - ao_poly p = *(ao_poly *) ao_lisp_root[i].addr; - if (!p) - continue; - if (!ao_lisp_poly_move((ao_poly *) ao_lisp_root[i].addr, 0)) { - MDBG_MOVE("root poly move from %04x to %04x\n", - p, *(ao_poly *) ao_lisp_root[i].addr); + ao_poly *a = (ao_poly *) ao_lisp_root[i].addr, p; + if (a && (p = *a)) { + MDBG("root 0x%04x\n", p); + visit_poly(a, 0); } } } @@ -221,17 +210,21 @@ move_object(void) ao_lisp_cons_noted = 0; for (i = 0; i < AO_LISP_POOL; i += 4) { if (busy(ao_lisp_cons_last, i)) { - void *addr = ao_lisp_pool + i; - MDBG_MOVE("cons %d\n", MDBG_OFFSET(addr)); - if (!ao_lisp_move(&ao_lisp_cons_type, &addr)) { - MDBG_MOVE("cons moves from %p to %p\n", - ao_lisp_pool + i, addr); - } + void *v = ao_lisp_pool + i; + MDBG("cons %d\n", MDBG_OFFSET(v)); + visit_addr(&ao_lisp_cons_type, &v); } } } - MDBG_MOVE_OUT(); - MDBG_MOVE("move done\n"); +} + +static void *move_old, *move_new; +static int move_size; + +static void +move_object(void) +{ + walk_all(ao_lisp_moving, ao_lisp_move, ao_lisp_poly_move); } #if MDBG_DUMP @@ -268,43 +261,22 @@ static const struct ao_lisp_type const *ao_lisp_types[AO_LISP_NUM_TYPE] = { [AO_LISP_LAMBDA] = &ao_lisp_lambda_type, }; +static int +ao_lisp_mark_ref(const struct ao_lisp_type *type, void **ref) +{ + return ao_lisp_mark(type, *ref); +} + +static int +ao_lisp_poly_mark_ref(ao_poly *p, uint8_t do_note_cons) +{ + return ao_lisp_poly_mark(*p, do_note_cons); +} static void ao_lisp_mark_busy(void) { - int i; - - memset(ao_lisp_busy, '\0', sizeof (ao_lisp_busy)); - memset(ao_lisp_cons_note, '\0', sizeof (ao_lisp_cons_note)); - ao_lisp_cons_noted = 0; - MDBG("mark\n"); - for (i = 0; i < AO_LISP_ROOT; i++) { - if (ao_lisp_root[i].type) { - void **a = ao_lisp_root[i].addr, *v; - if (a && (v = *a)) { - MDBG("root %d\n", MDBG_OFFSET(v)); - ao_lisp_mark(ao_lisp_root[i].type, v); - } - } else { - ao_poly *a = (ao_poly *) ao_lisp_root[i].addr, p; - if (a && (p = *a)) { - MDBG("root 0x%04x\n", p); - ao_lisp_poly_mark(p, 0); - } - } - } - while (ao_lisp_cons_noted) { - memcpy(ao_lisp_cons_last, ao_lisp_cons_note, sizeof (ao_lisp_cons_note)); - memset(ao_lisp_cons_note, '\0', sizeof (ao_lisp_cons_note)); - ao_lisp_cons_noted = 0; - for (i = 0; i < AO_LISP_POOL; i += 4) { - if (busy(ao_lisp_cons_last, i)) { - void *v = ao_lisp_pool + i; - MDBG("cons %d\n", MDBG_OFFSET(v)); - ao_lisp_mark(&ao_lisp_cons_type, v); - } - } - } + walk_all(ao_lisp_busy, ao_lisp_mark_ref, ao_lisp_poly_mark_ref); } void diff --git a/src/test/hanoi.lisp b/src/test/hanoi.lisp index 93594c43..09a3611c 100644 --- a/src/test/hanoi.lisp +++ b/src/test/hanoi.lisp @@ -60,8 +60,8 @@ (defun display () (display-stacks 0 20 stacks) - (move-to 1 1) - (patom "\n") + (move-to 1 21) + (flush) ) (defun length (l) @@ -100,7 +100,7 @@ (setq stacks (replace stacks from from-stack)) (setq stacks (replace stacks to to-stack)) (display) - (delay 500) + (delay 100) ) ) @@ -125,3 +125,5 @@ (clear) (_hanoi len 0 1 2) ) + +(hanoi)