diff --git a/asm/fib.scm b/example/asm/fib.scm similarity index 100% rename from asm/fib.scm rename to example/asm/fib.scm diff --git a/asm/runtime.scm b/example/asm/runtime.scm similarity index 100% rename from asm/runtime.scm rename to example/asm/runtime.scm diff --git a/reference/.gitignore b/example/c/.gitignore similarity index 100% rename from reference/.gitignore rename to example/c/.gitignore diff --git a/reference/Makefile b/example/c/Makefile similarity index 90% rename from reference/Makefile rename to example/c/Makefile index 58dc73f..8a07571 100644 --- a/reference/Makefile +++ b/example/c/Makefile @@ -1,5 +1,5 @@ -CFLAGS=-g - -all: scheme - -scheme: gc.o runtime.o +CFLAGS=-g + +all: scheme + +scheme: gc.o runtime.o diff --git a/reference/common.h b/example/c/common.h similarity index 100% rename from reference/common.h rename to example/c/common.h diff --git a/reference/gc.c b/example/c/gc.c similarity index 94% rename from reference/gc.c rename to example/c/gc.c index b811cdc..d5406f0 100644 --- a/reference/gc.c +++ b/example/c/gc.c @@ -1,64 +1,64 @@ -// Cheney style stop and copy garbage collector -#include "gc.h" - -cons_t *the_empty_list = NULL; - -static cons_t *old, *new, *scanptr, *freeptr, *eom, *root; -size_t tos; - -void gc_init() { - old = calloc(sizeof(cons_t), SIZE); - freeptr = old; - eom = old + (SIZE / 2); - new = eom + 1; - root = alloc(); -} - -cons_t *alloc() { - if (freeptr < eom) { - cons_t *retval = freeptr; - freeptr++; - return retval; - } else { - gc_run(); - return alloc(); - } -} - -void gc_run() { - freeptr = new; - scanptr = new; - // Relocate root - relocate(root); - // Enter the main GC loop - gc_loop(); - // Flip old and new; - cons_t *temp = old; - old = new; - new = temp; -} - -void gc_loop() { - while (scanptr < freeptr) { - relocate(scanptr); - scanptr++; - } -} - -void move(box_t box) { - if (box.type == CONS && box.cons != the_empty_list) { - if (box.cons->car.type == BROKEN_HEART) { - box.cons = box.cons->cdr.cons; - } else { - memcpy(freeptr, box.cons, sizeof(cons_t)); - box.cons->car.type = BROKEN_HEART; - box.cons->cdr.cons = freeptr; - freeptr++; - } - } -} - -void relocate(cons_t* cons) { - move(cons->car); - move(cons->cdr); -} +// Cheney style stop and copy garbage collector +#include "gc.h" + +cons_t *the_empty_list = NULL; + +static cons_t *old, *new, *scanptr, *freeptr, *eom, *root; +size_t tos; + +void gc_init() { + old = calloc(sizeof(cons_t), SIZE); + freeptr = old; + eom = old + (SIZE / 2); + new = eom + 1; + root = alloc(); +} + +cons_t *alloc() { + if (freeptr < eom) { + cons_t *retval = freeptr; + freeptr++; + return retval; + } else { + gc_run(); + return alloc(); + } +} + +void gc_run() { + freeptr = new; + scanptr = new; + // Relocate root + relocate(root); + // Enter the main GC loop + gc_loop(); + // Flip old and new; + cons_t *temp = old; + old = new; + new = temp; +} + +void gc_loop() { + while (scanptr < freeptr) { + relocate(scanptr); + scanptr++; + } +} + +void move(box_t box) { + if (box.type == CONS && box.cons != the_empty_list) { + if (box.cons->car.type == BROKEN_HEART) { + box.cons = box.cons->cdr.cons; + } else { + memcpy(freeptr, box.cons, sizeof(cons_t)); + box.cons->car.type = BROKEN_HEART; + box.cons->cdr.cons = freeptr; + freeptr++; + } + } +} + +void relocate(cons_t* cons) { + move(cons->car); + move(cons->cdr); +} diff --git a/reference/gc.h b/example/c/gc.h similarity index 93% rename from reference/gc.h rename to example/c/gc.h index 969f95b..a109bc8 100644 --- a/reference/gc.h +++ b/example/c/gc.h @@ -1,16 +1,16 @@ -#ifndef _GC_H_ -#define _GC_H_ - -#include -#include -#include -#include -#include "common.h" - -void gc_init(); -cons_t *alloc(); -void gc_run(); -void gc_loop(); -void relocate(cons_t*); - -#endif // _GC_H_ +#ifndef _GC_H_ +#define _GC_H_ + +#include +#include +#include +#include +#include "common.h" + +void gc_init(); +cons_t *alloc(); +void gc_run(); +void gc_loop(); +void relocate(cons_t*); + +#endif // _GC_H_ diff --git a/scmvm.scm b/scmvm.scm index cb69e95..4a8269e 100644 --- a/scmvm.scm +++ b/scmvm.scm @@ -1,9 +1,7 @@ (define-module (scmvm) - #:use-module (scmvm vm) - #:use-module (scmvm assembler) - #:use-module (scmvm debugger) #:use-module (ice-9 ports) - #:export (read-all-instructions instructions-from-file)) + #:export (read-all-instructions + instructions-from-file)) (define (read-all-instructions) (let ([inst (read)]) diff --git a/scmvm/assembler.scm b/scmvm/language/assembler.scm similarity index 98% rename from scmvm/assembler.scm rename to scmvm/language/assembler.scm index 501f6f7..c6d59f7 100644 --- a/scmvm/assembler.scm +++ b/scmvm/language/assembler.scm @@ -1,4 +1,4 @@ -(define-module (scmvm assembler) +(define-module (scmvm language assembler) #:use-module (srfi srfi-1) #:use-module (scmvm vm) #:use-module (rnrs bytevectors) diff --git a/scratch.scm b/scratch.scm deleted file mode 100644 index 7048f18..0000000 --- a/scratch.scm +++ /dev/null @@ -1,8 +0,0 @@ -(use-modules (scmvm) - (scmvm vm) - (scmvm assembler) - (scmvm debugger)) - -(define my-instructions (instructions-from-file "./asm/runtime.scm")) -(define my-debugger (make-debugger my-instructions)) -(define my-vm (debugger-vm my-debugger)) diff --git a/tests.scm b/tests.scm index 34844f6..43ac735 100644 --- a/tests.scm +++ b/tests.scm @@ -1,5 +1,5 @@ (use-modules (d- test) - (scmvm assembler) + (scmvm language assembler) (scmvm vm) (scmvm debugger) (rnrs bytevectors)