Go → C11
An exploratory compiler from Go to portable C11: readable output that any C11 compiler can build, and that sits next to C without cgo.
1983 / 2018upstream Go tests passing (
$GOROOT/test, excluding skips)generics, reflecttype parameters, range-over-func,
reflect.Call, MakeFunc, Selectstdlib from source
fmt, time, sync, os, errors, log, …What it does
- Each
.gofile becomes a matching.cfile; each package gets a private and a public.h. - A small
<go.h>header holds the runtime and the representation of builtin types, so you can swap it out. - The standard library is compiled from Go's own source, with a few C11 hooks (
os, parts ofreflect) where Go would reach into its runtime. - Errors are reported exactly as
gcreports them, using its parser.
Why C
- Fil-C: memory-safe C. Unsafe code is checked, and data races can't corrupt runtime structures.
- Cosmopolitan Libc: one binary that runs on Linux, macOS, Windows and the BSDs.
- Calling C is just calling C, with no cgo trampolines.
Try it
go install github.com/quaadgras/gd-compiler@latest
cd your/go/package
gd-compiler build
gd-compiler test
The output needs a garbage collector: link with Boehm GC, or build with a C compiler that has one, such as Fil-C. Set the compiler with GD_CC.
Status
Experimental. Conformance is measured against Go's own test suite on every change; the remaining failures are mostly runtime internals and gc-specific behaviour.