Passer en français

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:

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:

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:

  1. File inclusion and scanning for template definitions.
  2. Template instantiation.
  3. Structural analysis (classes, fields, methods, and macros).
  4. Method body parsing.
  5. 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

License and download

GT 3.5 is released into the public domain).