-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.c
62 lines (53 loc) · 963 Bytes
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include <stdio.h>
#include "gc.h"
#include "object.h"
#include "types.h"
#include "vm.h"
void test1()
{
printf("Test 1: Objects on stack are preserved.\n");
VM *vm = new_vm();
push_int(vm, 1);
push_int(vm, 2);
__gc(vm);
free_vm(vm);
}
void test2()
{
printf("Test 2: Unreached objects are collected.\n");
VM *vm = new_vm();
push_int(vm, 1);
push_int(vm, 2);
Object *o1 = pop(vm);
Object *o2 = pop(vm);
dump(o1);
printf("\n");
dump(o2);
printf("\n");
__gc(vm);
free_vm(vm);
}
void test3()
{
printf("Test 3: Reach nested objects.\n");
VM *vm = new_vm();
push_int(vm, 1);
push_int(vm, 2);
push_pair(vm);
push_int(vm, 3);
push_int(vm, 4);
push_pair(vm);
push_pair(vm);
__gc(vm);
Object *o1 = pop(vm);
dump(o1);
printf("\n");
free_vm(vm);
}
int main(int argc, char *argv[])
{
test1();
test2();
test3();
return 0;
}