blob: eeecaad8d280f2631cc2335600d6d232bccf9b10 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# `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](https://metanimi.dy.fi/blog/cng/).
# 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
```sh
make
export PATH=$PATH:$PWD
```
No install for now, this is not intended for any serious use.
# Usage
```sh
./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).
|