marCsweep/README.md

1.6 KiB

marCsweep

A mark-and-sweep garbage collector written in C.

Includes a simple virtual machine and a custom malloc implementation for creating, tracing, and freeing garbage.

Building

Compiling the project should be relatively easy, even if you aren't familiar with make.

Dependencies: git, make, and gcc.

git clone https://codeberg.org/andyscott/marCsweep.git

cd marCsweep

make release # or debug

That's it! Make will create the bin directory and place the finished executable there.

Compiling with clang is also supported, just replace "gcc" with "clang" in the first line of the Makefile. Also note that if you don't specify a target for make (i.e. "release" or "debug") both will be built. Debug builds are placed in the debug directory.

Running

Once compiled, the program can be run with the following:

cd bin # or debug

./gc

The results of the test cases will be output to your terminal:

test_int_alloc: PASS
test_pair_alloc: PASS
test_obj_count: PASS
test_pair_alloc: PASS
test_unreachable: PASS
test_auto_gc: PASS

If all six tests pass, then the library compiles correctly on your system and should be ready for experimentation!

Notes

This is a personal project that I am writing in my free time to learn more about garbage collection. Thank you to Robert Nystrom for the idea.

Sadly, it was this author's idea to extend the project by writing a custom malloc. Perhaps I should have been lazy and used the preexisting definitions, but where's the fun in that?