aboutsummaryrefslogtreecommitdiff

ngc

This a rough intial implementation of a subset of ideas presented in my blogpost Coming up with a new type system on top of C.

TL;DR

This is largely just an attempt to formalize existing practice for type-generic data structures in C. Essentially, to avoid having to mangle names, generic data structures are typically generated with some constructor macros that take in a user-provided name. See example_vec/old/vec.h for a fairly simple example, and the equivalent example_vec/new/vec.h for what this program deals with instead.

I also have some ideas for ways to extend this idea, including incorporating some kind of trait system. See the blog post more some more details.

Setup

make
export PATH=$PATH:$PWD

No install for now, this is not intended for any serious use.

Usage

./ngc example_vec/new/main.c -o vec

ngc is a wrapper around a gcc-like compiler, so all flags that gcc accepts should work here as well. ngc1 is the 'actual' program that handles type expansion etc. and jumps in between the preprocessing and actual compilation of your C.

Current status

Just enough working that example_vec/new/vec.h generates useful code. I recently got a bit interested in this idea again so I might implement some more features in the near future, probably starting with supertemplates.

Line numbering gets a bit messed up sometimes, I should actually parse the linemarkers that gcc outputs. TODO (although preferably this functionality would be integrated into a compiler directly).