Compare commits

...

2 commits

Author SHA1 Message Date
26ef0bc3ad
formatting/style 2024-09-06 11:05:16 -04:00
0747e78b15
Makefile: overhaul variables, std=gnu11 for now 2024-09-06 11:03:59 -04:00
7 changed files with 220 additions and 214 deletions

View file

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

View file

@ -43,5 +43,6 @@ void collect(struct virtualMachine *vm)
{
markAll(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;
}

View file

@ -5,7 +5,8 @@
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;
while (curr && !(curr->free && curr->size >= size)) {
@ -16,7 +17,8 @@ struct gcHeader *findFree(struct gcHeader **prev, size_t size) {
return curr;
}
struct gcHeader *requestMem(struct gcHeader *prev, size_t size) {
struct gcHeader *requestMem(struct gcHeader *prev, size_t size)
{
struct gcHeader *block;
void *request;

View file

@ -12,8 +12,8 @@ void test_int_alloc(void)
pushInt(vm, 1000);
pushInt(vm, 10000);
pushInt(vm, -100000);
assert(vm->refCount == 4
&& "test_int_alloc: GARBAGE_INT allocation failure\n");
assert(vm->refCount == 4 &&
"test_int_alloc: GARBAGE_INT allocation failure\n");
printf("test_int_alloc: PASS\n");
deinitVM(vm);
}
@ -27,8 +27,8 @@ void test_pair_alloc(void)
pushInt(vm, -100000);
pushPair(vm);
pushPair(vm);
assert(vm->refCount == 6
&& "test_pair_alloc: FAILED: GARBAGE_PAIR allocation failure\n");
assert(vm->refCount == 6 &&
"test_pair_alloc: FAILED: GARBAGE_PAIR allocation failure\n");
printf("test_pair_alloc: PASS\n");
deinitVM(vm);
}
@ -41,8 +41,8 @@ void test_obj_count(void)
pushInt(vm, 10000);
pushInt(vm, -100000);
collect(vm);
assert(vm->refCount == 4
&& "test_obj_count: FAILED: GC occurred when it shouldn't have\n");
assert(vm->refCount == 4 &&
"test_obj_count: FAILED: GC occurred when it shouldn't have\n");
printf("test_obj_count: PASS\n");
deinitVM(vm);
}
@ -58,8 +58,8 @@ void test_nested_pair(void)
pushPair(vm);
pushPair(vm);
collect(vm);
assert(vm->refCount == 7
&& "test_nested_pair: FAILED: GARBAGE_PAIR allocation failure\n");
assert(vm->refCount == 7 &&
"test_nested_pair: FAILED: GARBAGE_PAIR allocation failure\n");
printf("test_pair_alloc: PASS\n");
deinitVM(vm);
}
@ -72,9 +72,8 @@ void test_unreachable(void)
pop(vm);
pop(vm);
collect(vm);
assert(
vm->refCount == 0
&& "test_unreachable: FAILED: 2 GARBAGE_INT should have been freed\n");
assert(vm->refCount == 0 &&
"test_unreachable: FAILED: 2 GARBAGE_INT should have been freed\n");
printf("test_unreachable: PASS\n");
deinitVM(vm);
}
@ -95,8 +94,8 @@ void test_auto_gc(void)
pushInt(vm, 2);
}
assert(vm->refCount == 550
&& "test_auto_gc: FAILED: 5 references should have been freed\n");
assert(vm->refCount == 550 &&
"test_auto_gc: FAILED: 5 references should have been freed\n");
printf("test_auto_gc: PASS\n");
deinitVM(vm);
}

View file

@ -24,7 +24,8 @@ void deinitVM(struct virtualMachine *vm)
void push(struct virtualMachine *vm, struct garbageObject *value)
{
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;
}
vm->stack[vm->stackSize++] = value;