伽玛语言
The Gamma Language

原始链接: https://lair.masot.net/gamma/

Gamma是一个极简的、可自托管的C预处理器,旨在创建简单、符合人体工程学的模板化数据结构,*无需*进行完整的C解析。它严格是C的超集,意味着现有的C代码仍然有效。 要使用Gamma,只需在克隆仓库并运行`make`后,将C编译器设置为“gc gcc”。它允许使用模板化代码,例如通用排序和向量实现,如提供的示例所示。 一个关键优势是其易于集成——Gamma足够小,可以直接嵌入到项目中,并与标准的C构建过程(目标文件、静态库、链接)兼容。 对于那些寻求更高级的类型反射能力的人,建议使用相关的项目MaC。Gamma由Matthew和Akshay创建,作为C模板化的一次实验。

## Gamma:一个C泛型实验 RossBencina分享了一个Gamma语言的链接,这是一个个人项目,旨在探索在*不*完全解析语言的情况下,为C添加类似模板/泛型的功能。最初的方法Gamma在模板实例化期间难以正确复制类型定义,尤其是在存在循环依赖时。 作者后来转向了MaC,它*确实*解析头文件以解决这些问题,从而提供更可靠的模板处理。 避免完全解析的一个关键限制是无法执行类型推断,从而阻碍了多重分派等功能。 该项目的驱动力是保持编译器小而易读——这是Gamma(和MaC)可以实现的,而对于C++或D等较大语言来说是不可行的。 虽然它不适用于实际项目(推荐使用D),但它是一个关于最小编译器设计和C中泛型可能性的“有趣”探索。 讨论还涉及语法(质疑是否需要显式类型标注)以及生成C代码固有的调试挑战。
相关文章

原文
The Gamma Language

Gamma is a self-hosting C preprocessor enabling simple, ergonomic templated data structures.

It's primarily an experiment in designing a template engine for C in a minimal way (e.g., without having to parse C).

Gamma is a strict superset of C.


Update 12/25: You might be interested in MaC, a similar experiment in C templates that allows for significantly more reflection on types (e.g., you could write an automated serializer generator).


You merely set CC="gc gcc" to enable support for templates. Here's a quickstart:

    $ git clone https://lair.masot.net/git/gamma.git
    $ cd gamma
    $ make
    $ cat examples/sorting.c
        #include <string.h>
        ...
    $ ./gc gcc examples/sorting.c -o sorting
    $ ./sorting
        1, 10, 50, 75
        apple, hello, world

Gamma can be bootstrapped by normal C compilers, and is small enough to vendor into your own project, so it's remains easy for others to use your code.

Gamma supports creating object files and static archives, and allows linking against normal C object files.

Gamma was written by Matthew and Akshay.

Here's a simple example showing how to define and use generic sort and print routines in Gamma:

And a generic vector data structure:

联系我们 contact @ memedata.com