GT Programming Language
GT is an experiment in an imperative programming language built as a lightweight layer on top of C (in the spirit of the original C with Classes), complete with a transpiler to C. Now an archived project, it remains available for download.
Overview
GT extends the C language with a targeted subset of abstractions:
- classes, single inheritance, fields, and methods;
- open (partial) classes and extension of primitive types;
- parameterized templates.
Particular care was taken to preserve C’s native performance (using struct and function pointers, with zero hidden overhead). GT intentionally has no standard library or runtime: no garbage collector, no exceptions, no RTTI, and no vtables (static dispatch only).
Compilation and in-memory execution
Rather than emitting machine code directly, the GT compiler generates standard C source code. This design offers several benefits:
- immediate portability across any C compiler and operating system;
- seamless integration with existing C, C++, or Objective-C code;
- the ability to execute a GT program on the fly via TCC (Tiny C Compiler), which compiles and runs the generated code directly in memory without touching the disk.
Compiler architecture
The GT transpiler went through several iterations. After an initial version built around a recursive descent parser, it was rewritten using Ragel, a regular-expression-based finite state machine compiler, to improve speed and conciseness.
The compilation pipeline relies on 5 main state machines triggering stacked sub-machines:
- File inclusion and scanning for template definitions.
- Template instantiation.
- Structural analysis (classes, fields, methods, and macros).
- Method body parsing.
- C code generation.
GT does not try to reinvent what C already does well: for arithmetic expressions or pointer manipulation, the compiler acts almost as a straight pass-through.
Example
The syntax remains familiar to C, C++, C#, or Java developers:
programme.gt
#include <stdio.h>
#include <string.h>
class int {
void autoincrement() {
*this = *this + 1; // this est un int*
}
}
class Compte {
int numero;
void ouvrir() {
puts("Compte.ouvrir");
numero.autoincrement();
}
}
class CompteCheque : Compte {
int numChequier;
void ouvrir() {
puts("CompteCheque.ouvrir");
super.ouvrir();
}
}
class Compte { // toutes les classes sont "partielles"
void fermer() {
puts("Compte.fermer");
}
}
template Vector<T, size, format> {
${T}* start;
${Vector}* add(${T} t) {
printf("${T}.add.${size}(${format})\n", t);
return this;
}
}<>
using VectorInt4 = Vector<int, 4, %d>
class VectorTest {
static void test() {
VectorInt4 ints;
ints.add(3);
}
}
class Test {
void main(int argc, char** argv) {
VectorTest.test();
Compte cpt;
cpt.ouvrir();
CompteCheque cc;
cc.ouvrir();
cc.fermer();
}
}
Usage
gt.exe exemple.gt exemple.gt.cparsesexemple.gtand generates the corresponding C file.gt.exe exemple.gt -runcompiles and runs the program directly in memory via TCC (requires TCC installed inc:\tccalong with the shared library tcc.dll (Windows 32-bit)).
License and download
GT 3.5 is released into the public domain).