Compare commits

..

No commits in common. "26ef0bc3ad3a5bef00f2d2d36eb2e543dea4bf70" and "c73dfc2c0060991de10addf27c79b5e0dfd44b41" have entirely different histories.

7 changed files with 214 additions and 220 deletions

View file

@ -1,22 +1,21 @@
CC = gcc CC = gcc
CFLAGS = -std=gnu11 CFLAGS =
CPPFLAGS = -Iinclude -MMD -MP CPPFLAGS = -Iinclude -MMD -MP
SRCDIR = src SRCDIR = src
SRCS := $(wildcard $(SRCDIR)/*.c) SRCS = $(wildcard $(SRCDIR)/*.c)
OBJS := $(patsubst $(SRCDIR)/%.c,%.o,$(SRCS)) OBJS = $(patsubst $(SRCDIR)/%.c,%.o,$(SRCS))
EXE = gc EXE = gc
DBDIR = debug DBDIR = debug
DBEXE := $(DBDIR)/$(EXE) DBEXE = $(DBDIR)/$(EXE)
DBOBJS := $(addprefix $(DBDIR)/, $(OBJS)) DBOBJS = $(addprefix $(DBDIR)/, $(OBJS))
DBCFLAGS = -g -O0 -DDEBUG DBCFLAGS = -g -O0 -DDEBUG
REDIR = bin REDIR = bin
REEXE := $(REDIR)/$(EXE) REEXE = $(REDIR)/$(EXE)
REOBJS := $(addprefix $(REDIR)/, $(OBJS)) REOBJS = $(addprefix $(REDIR)/, $(OBJS))
RECFLAGS = -O3 -Wall -Wextra -Wpedantic -Werror RECFLAGS = -O3 -Wall -Wextra -Wpedantic -Werror
.PHONY: all clean debug prep release .PHONY: all clean debug prep release
@ -44,5 +43,3 @@ prep:
clean: clean:
rm -rf $(DBDIR) $(REDIR) rm -rf $(DBDIR) $(REDIR)
-include $(OBJ:.o=.d)

View file

@ -43,6 +43,5 @@ void collect(struct virtualMachine *vm)
{ {
markAll(vm); markAll(vm);
sweep(vm); sweep(vm);
vm->refMax = vm->refCount * 2 <= STACK_MAX ? vm->refCount * 2 : vm->refMax = vm->refCount * 2 <= STACK_MAX ? vm->refCount * 2 : STACK_MAX;
STACK_MAX;
} }

View file

@ -5,8 +5,7 @@
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)) {
@ -17,8 +16,7 @@ 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;

View file

@ -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,8 +72,9 @@ void test_unreachable(void)
pop(vm); pop(vm);
pop(vm); pop(vm);
collect(vm); collect(vm);
assert(vm->refCount == 0 && assert(
"test_unreachable: FAILED: 2 GARBAGE_INT should have been freed\n"); vm->refCount == 0
&& "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);
} }
@ -94,8 +95,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);
} }

View file

@ -24,8 +24,7 @@ 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, fprintf(stderr, "ERROR: push(): refusing to overflow the stack!\n");
"ERROR: push(): refusing to overflow the stack!\n");
return; return;
} }
vm->stack[vm->stackSize++] = value; vm->stack[vm->stackSize++] = value;