Project restructuring to support the new direction
This commit is contained in:
parent
d109b6f374
commit
330aca002f
@ -1,5 +1,5 @@
|
|||||||
CFLAGS=-g
|
CFLAGS=-g
|
||||||
|
|
||||||
all: scheme
|
all: scheme
|
||||||
|
|
||||||
scheme: gc.o runtime.o
|
scheme: gc.o runtime.o
|
@ -1,64 +1,64 @@
|
|||||||
// Cheney style stop and copy garbage collector
|
// Cheney style stop and copy garbage collector
|
||||||
#include "gc.h"
|
#include "gc.h"
|
||||||
|
|
||||||
cons_t *the_empty_list = NULL;
|
cons_t *the_empty_list = NULL;
|
||||||
|
|
||||||
static cons_t *old, *new, *scanptr, *freeptr, *eom, *root;
|
static cons_t *old, *new, *scanptr, *freeptr, *eom, *root;
|
||||||
size_t tos;
|
size_t tos;
|
||||||
|
|
||||||
void gc_init() {
|
void gc_init() {
|
||||||
old = calloc(sizeof(cons_t), SIZE);
|
old = calloc(sizeof(cons_t), SIZE);
|
||||||
freeptr = old;
|
freeptr = old;
|
||||||
eom = old + (SIZE / 2);
|
eom = old + (SIZE / 2);
|
||||||
new = eom + 1;
|
new = eom + 1;
|
||||||
root = alloc();
|
root = alloc();
|
||||||
}
|
}
|
||||||
|
|
||||||
cons_t *alloc() {
|
cons_t *alloc() {
|
||||||
if (freeptr < eom) {
|
if (freeptr < eom) {
|
||||||
cons_t *retval = freeptr;
|
cons_t *retval = freeptr;
|
||||||
freeptr++;
|
freeptr++;
|
||||||
return retval;
|
return retval;
|
||||||
} else {
|
} else {
|
||||||
gc_run();
|
gc_run();
|
||||||
return alloc();
|
return alloc();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void gc_run() {
|
void gc_run() {
|
||||||
freeptr = new;
|
freeptr = new;
|
||||||
scanptr = new;
|
scanptr = new;
|
||||||
// Relocate root
|
// Relocate root
|
||||||
relocate(root);
|
relocate(root);
|
||||||
// Enter the main GC loop
|
// Enter the main GC loop
|
||||||
gc_loop();
|
gc_loop();
|
||||||
// Flip old and new;
|
// Flip old and new;
|
||||||
cons_t *temp = old;
|
cons_t *temp = old;
|
||||||
old = new;
|
old = new;
|
||||||
new = temp;
|
new = temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
void gc_loop() {
|
void gc_loop() {
|
||||||
while (scanptr < freeptr) {
|
while (scanptr < freeptr) {
|
||||||
relocate(scanptr);
|
relocate(scanptr);
|
||||||
scanptr++;
|
scanptr++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void move(box_t box) {
|
void move(box_t box) {
|
||||||
if (box.type == CONS && box.cons != the_empty_list) {
|
if (box.type == CONS && box.cons != the_empty_list) {
|
||||||
if (box.cons->car.type == BROKEN_HEART) {
|
if (box.cons->car.type == BROKEN_HEART) {
|
||||||
box.cons = box.cons->cdr.cons;
|
box.cons = box.cons->cdr.cons;
|
||||||
} else {
|
} else {
|
||||||
memcpy(freeptr, box.cons, sizeof(cons_t));
|
memcpy(freeptr, box.cons, sizeof(cons_t));
|
||||||
box.cons->car.type = BROKEN_HEART;
|
box.cons->car.type = BROKEN_HEART;
|
||||||
box.cons->cdr.cons = freeptr;
|
box.cons->cdr.cons = freeptr;
|
||||||
freeptr++;
|
freeptr++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void relocate(cons_t* cons) {
|
void relocate(cons_t* cons) {
|
||||||
move(cons->car);
|
move(cons->car);
|
||||||
move(cons->cdr);
|
move(cons->cdr);
|
||||||
}
|
}
|
@ -1,16 +1,16 @@
|
|||||||
#ifndef _GC_H_
|
#ifndef _GC_H_
|
||||||
#define _GC_H_
|
#define _GC_H_
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
|
||||||
void gc_init();
|
void gc_init();
|
||||||
cons_t *alloc();
|
cons_t *alloc();
|
||||||
void gc_run();
|
void gc_run();
|
||||||
void gc_loop();
|
void gc_loop();
|
||||||
void relocate(cons_t*);
|
void relocate(cons_t*);
|
||||||
|
|
||||||
#endif // _GC_H_
|
#endif // _GC_H_
|
@ -1,9 +1,7 @@
|
|||||||
(define-module (scmvm)
|
(define-module (scmvm)
|
||||||
#:use-module (scmvm vm)
|
|
||||||
#:use-module (scmvm assembler)
|
|
||||||
#:use-module (scmvm debugger)
|
|
||||||
#:use-module (ice-9 ports)
|
#:use-module (ice-9 ports)
|
||||||
#:export (read-all-instructions instructions-from-file))
|
#:export (read-all-instructions
|
||||||
|
instructions-from-file))
|
||||||
|
|
||||||
(define (read-all-instructions)
|
(define (read-all-instructions)
|
||||||
(let ([inst (read)])
|
(let ([inst (read)])
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
(define-module (scmvm assembler)
|
(define-module (scmvm language assembler)
|
||||||
#:use-module (srfi srfi-1)
|
#:use-module (srfi srfi-1)
|
||||||
#:use-module (scmvm vm)
|
#:use-module (scmvm vm)
|
||||||
#:use-module (rnrs bytevectors)
|
#:use-module (rnrs bytevectors)
|
@ -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))
|
|
Loading…
Reference in New Issue
Block a user