mirror of
https://codeberg.org/andyscott/marCsweep.git
synced 2024-12-22 09:43:12 -05:00
formatting/style
This commit is contained in:
parent
0747e78b15
commit
26ef0bc3ad
6 changed files with 205 additions and 202 deletions
3
src/gc.c
3
src/gc.c
|
@ -43,5 +43,6 @@ void collect(struct virtualMachine *vm)
|
||||||
{
|
{
|
||||||
markAll(vm);
|
markAll(vm);
|
||||||
sweep(vm);
|
sweep(vm);
|
||||||
vm->refMax = vm->refCount * 2 <= STACK_MAX ? vm->refCount * 2 : STACK_MAX;
|
vm->refMax = vm->refCount * 2 <= STACK_MAX ? vm->refCount * 2 :
|
||||||
|
STACK_MAX;
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,8 @@
|
||||||
|
|
||||||
static void *allocHead = NULL;
|
static void *allocHead = NULL;
|
||||||
|
|
||||||
struct gcHeader *findFree(struct gcHeader **prev, size_t size) {
|
struct gcHeader *findFree(struct gcHeader **prev, size_t size)
|
||||||
|
{
|
||||||
struct gcHeader *curr = allocHead;
|
struct gcHeader *curr = allocHead;
|
||||||
|
|
||||||
while (curr && !(curr->free && curr->size >= size)) {
|
while (curr && !(curr->free && curr->size >= size)) {
|
||||||
|
@ -16,7 +17,8 @@ struct gcHeader *findFree(struct gcHeader **prev, size_t size) {
|
||||||
return curr;
|
return curr;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct gcHeader *requestMem(struct gcHeader *prev, size_t size) {
|
struct gcHeader *requestMem(struct gcHeader *prev, size_t size)
|
||||||
|
{
|
||||||
struct gcHeader *block;
|
struct gcHeader *block;
|
||||||
void *request;
|
void *request;
|
||||||
|
|
||||||
|
|
25
src/main.c
25
src/main.c
|
@ -12,8 +12,8 @@ void test_int_alloc(void)
|
||||||
pushInt(vm, 1000);
|
pushInt(vm, 1000);
|
||||||
pushInt(vm, 10000);
|
pushInt(vm, 10000);
|
||||||
pushInt(vm, -100000);
|
pushInt(vm, -100000);
|
||||||
assert(vm->refCount == 4
|
assert(vm->refCount == 4 &&
|
||||||
&& "test_int_alloc: GARBAGE_INT allocation failure\n");
|
"test_int_alloc: GARBAGE_INT allocation failure\n");
|
||||||
printf("test_int_alloc: PASS\n");
|
printf("test_int_alloc: PASS\n");
|
||||||
deinitVM(vm);
|
deinitVM(vm);
|
||||||
}
|
}
|
||||||
|
@ -27,8 +27,8 @@ void test_pair_alloc(void)
|
||||||
pushInt(vm, -100000);
|
pushInt(vm, -100000);
|
||||||
pushPair(vm);
|
pushPair(vm);
|
||||||
pushPair(vm);
|
pushPair(vm);
|
||||||
assert(vm->refCount == 6
|
assert(vm->refCount == 6 &&
|
||||||
&& "test_pair_alloc: FAILED: GARBAGE_PAIR allocation failure\n");
|
"test_pair_alloc: FAILED: GARBAGE_PAIR allocation failure\n");
|
||||||
printf("test_pair_alloc: PASS\n");
|
printf("test_pair_alloc: PASS\n");
|
||||||
deinitVM(vm);
|
deinitVM(vm);
|
||||||
}
|
}
|
||||||
|
@ -41,8 +41,8 @@ void test_obj_count(void)
|
||||||
pushInt(vm, 10000);
|
pushInt(vm, 10000);
|
||||||
pushInt(vm, -100000);
|
pushInt(vm, -100000);
|
||||||
collect(vm);
|
collect(vm);
|
||||||
assert(vm->refCount == 4
|
assert(vm->refCount == 4 &&
|
||||||
&& "test_obj_count: FAILED: GC occurred when it shouldn't have\n");
|
"test_obj_count: FAILED: GC occurred when it shouldn't have\n");
|
||||||
printf("test_obj_count: PASS\n");
|
printf("test_obj_count: PASS\n");
|
||||||
deinitVM(vm);
|
deinitVM(vm);
|
||||||
}
|
}
|
||||||
|
@ -58,8 +58,8 @@ void test_nested_pair(void)
|
||||||
pushPair(vm);
|
pushPair(vm);
|
||||||
pushPair(vm);
|
pushPair(vm);
|
||||||
collect(vm);
|
collect(vm);
|
||||||
assert(vm->refCount == 7
|
assert(vm->refCount == 7 &&
|
||||||
&& "test_nested_pair: FAILED: GARBAGE_PAIR allocation failure\n");
|
"test_nested_pair: FAILED: GARBAGE_PAIR allocation failure\n");
|
||||||
printf("test_pair_alloc: PASS\n");
|
printf("test_pair_alloc: PASS\n");
|
||||||
deinitVM(vm);
|
deinitVM(vm);
|
||||||
}
|
}
|
||||||
|
@ -72,9 +72,8 @@ void test_unreachable(void)
|
||||||
pop(vm);
|
pop(vm);
|
||||||
pop(vm);
|
pop(vm);
|
||||||
collect(vm);
|
collect(vm);
|
||||||
assert(
|
assert(vm->refCount == 0 &&
|
||||||
vm->refCount == 0
|
"test_unreachable: FAILED: 2 GARBAGE_INT should have been freed\n");
|
||||||
&& "test_unreachable: FAILED: 2 GARBAGE_INT should have been freed\n");
|
|
||||||
printf("test_unreachable: PASS\n");
|
printf("test_unreachable: PASS\n");
|
||||||
deinitVM(vm);
|
deinitVM(vm);
|
||||||
}
|
}
|
||||||
|
@ -95,8 +94,8 @@ void test_auto_gc(void)
|
||||||
pushInt(vm, 2);
|
pushInt(vm, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(vm->refCount == 550
|
assert(vm->refCount == 550 &&
|
||||||
&& "test_auto_gc: FAILED: 5 references should have been freed\n");
|
"test_auto_gc: FAILED: 5 references should have been freed\n");
|
||||||
printf("test_auto_gc: PASS\n");
|
printf("test_auto_gc: PASS\n");
|
||||||
deinitVM(vm);
|
deinitVM(vm);
|
||||||
}
|
}
|
||||||
|
|
3
src/vm.c
3
src/vm.c
|
@ -24,7 +24,8 @@ void deinitVM(struct virtualMachine *vm)
|
||||||
void push(struct virtualMachine *vm, struct garbageObject *value)
|
void push(struct virtualMachine *vm, struct garbageObject *value)
|
||||||
{
|
{
|
||||||
if (vm->stackSize >= STACK_MAX) {
|
if (vm->stackSize >= STACK_MAX) {
|
||||||
fprintf(stderr, "ERROR: push(): refusing to overflow the stack!\n");
|
fprintf(stderr,
|
||||||
|
"ERROR: push(): refusing to overflow the stack!\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
vm->stack[vm->stackSize++] = value;
|
vm->stack[vm->stackSize++] = value;
|
||||||
|
|
Loading…
Reference in a new issue