axw/llgo — pull request #108 by antongulenko (2013-10-20 03:42:36+00:00)
Title: Added a garbage collector to the llgo runtime

This implements issue #106.
I found a way to avoid cloning the entire GC source tree into the llgo repo, so I'll just go ahead and open this pull request.
The Böhm garbage collector is added to the llgo runtime in the following way:
- llgo-dist has an additional step that clones the repositories for the collector into llgo/pkg/runtime/gc
- There is the file llgo/pkg/runtime/gc.c that includes the entire collector code. Since the file is in this folder, it will be compiled into the runtime.bc file by llgo-dist.
- To make it compile, I had to add a pseudo-generic rule to llgo-build - if C-files are compiled, it recursively looks for folders called 'include' and adds them to the header lookup path of the compiler. This is the most portable way to compile the collector directly into the runtime.
- I added the switch -gc (bool) to llgo-build, that switches the gc on/off for every invocation of llgo-build. This works by defining symbols called llgo_malloc and llgo_free at link-time using --defsym.

Check it out! Here you can find a program to test this:
https://github.com/antongulenko/test-gc

Cheers,
Anton