mirror of
https://codeberg.org/andyscott/marCsweep.git
synced 2024-12-21 09:23:09 -05:00
VM: added deinitVM() and replaced calls to free()
This commit is contained in:
parent
ba08dd966c
commit
d0865a644c
3 changed files with 14 additions and 6 deletions
12
main.c
12
main.c
|
@ -15,7 +15,7 @@ void test_int_alloc(void) {
|
|||
assert(vm->refCount == 4 &&
|
||||
"test_int_alloc: GARBAGE_INT allocation failure\n");
|
||||
printf("test_int_alloc: PASS\n");
|
||||
free(vm);
|
||||
deinitVM(vm);
|
||||
}
|
||||
|
||||
void test_pair_alloc(void) {
|
||||
|
@ -29,7 +29,7 @@ void test_pair_alloc(void) {
|
|||
assert(vm->refCount == 6 &&
|
||||
"test_pair_alloc: FAILED: GARBAGE_PAIR allocation failure\n");
|
||||
printf("test_pair_alloc: PASS\n");
|
||||
free(vm);
|
||||
deinitVM(vm);
|
||||
}
|
||||
|
||||
void test_obj_count(void) {
|
||||
|
@ -42,7 +42,7 @@ void test_obj_count(void) {
|
|||
assert(vm->refCount == 4 &&
|
||||
"test_obj_count: FAILED: GC occurred when it shouldn't have\n");
|
||||
printf("test_obj_count: PASS\n");
|
||||
free(vm);
|
||||
deinitVM(vm);
|
||||
}
|
||||
|
||||
void test_nested_pair(void) {
|
||||
|
@ -58,7 +58,7 @@ void test_nested_pair(void) {
|
|||
assert(vm->refCount == 7 &&
|
||||
"test_nested_pair: FAILED: GARBAGE_PAIR allocation failure\n");
|
||||
printf("test_pair_alloc: PASS\n");
|
||||
free(vm);
|
||||
deinitVM(vm);
|
||||
}
|
||||
|
||||
void test_unreachable(void) {
|
||||
|
@ -71,7 +71,7 @@ void test_unreachable(void) {
|
|||
assert(vm->refCount == 0 &&
|
||||
"test_unreachable: FAILED: 2 GARBAGE_INT should have been freed\n");
|
||||
printf("test_unreachable: PASS\n");
|
||||
free(vm);
|
||||
deinitVM(vm);
|
||||
}
|
||||
|
||||
void test_auto_gc(void) {
|
||||
|
@ -92,7 +92,7 @@ void test_auto_gc(void) {
|
|||
assert(vm->refCount == 550 &&
|
||||
"test_auto_gc: FAILED: 5 references should have been freed\n");
|
||||
printf("test_auto_gc: PASS\n");
|
||||
free(vm);
|
||||
deinitVM(vm);
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
|
|
6
vm.c
6
vm.c
|
@ -13,6 +13,12 @@ struct virtualMachine *initVM() {
|
|||
return vm;
|
||||
}
|
||||
|
||||
void deinitVM(struct virtualMachine *vm) {
|
||||
vm->stackSize = 0;
|
||||
collect(vm);
|
||||
free(vm);
|
||||
}
|
||||
|
||||
void push(struct virtualMachine *vm, struct garbageObject *value) {
|
||||
if (vm->stackSize >= STACK_MAX) {
|
||||
fprintf(stderr, "ERROR: push(): refusing to overflow the stack!\n");
|
||||
|
|
2
vm.h
2
vm.h
|
@ -42,6 +42,8 @@ struct garbageObject *initGarbage(struct virtualMachine *vm,
|
|||
// Create a new VM
|
||||
struct virtualMachine *initVM(void);
|
||||
|
||||
void deinitVM(struct virtualMachine *vm);
|
||||
|
||||
// Generic function to push data onto the VM stack
|
||||
void push(struct virtualMachine *vm, struct garbageObject *value);
|
||||
|
||||
|
|
Loading…
Reference in a new issue