The GT programming language

Introduction

GT is an imperative programming language. It is heavily rooted in the C programming language on top of which it adds some object oriented concepts such as:

However, it still follows the C spirit. A great care has been taken not to ruin C execution performances (by using structures and functions pointers tricks for example).

So GT is a system programming language, like C, C++, D and ObjectiveC.

GT is a language. It doesn't provide any predefined class library nor any "runtime": no garbage collector, no security manager...

Compilation

Compiling a GT program gives a C source code instead of an executable. This choice is motivated by the fact that:

Choosing C (instead of Java, C#...) as a target language aims at producing rapid and light software on many platforms. It also has been influenced by the availability of TCC, a C compiler that proves to be extremely rapid and easy to integrate. Thanks to TCC, the GT compiler can even execute its generated code in memory, bypassing the creation of any file on disk.

Compiler's implementation

GT has been rewritten many times. Its last implementation uses a finite state automata generator based on regular expressions: Ragel. It is quicker and more maintainable than the previous one (a recursive decent parser).

More precisely, GT uses 5 main state machines that stack many sub-machines:

Compared advantages

GT brings to C

GT differs from C++ by

GT isn't another D, Vala, Genie...

GT's compiler has an original architecture. Its code is pretty technical because based on Ragel but small enough to stay maintainable and to allow rapid corrections and evolutions.

GT doesn't reinvent what C does very well by itself; in some cases, it just acts as C: arithmetic expressions and pointers operations are the same in C and in GT for example.

GT follows the spirit of the initial C++, when it was still called "C with Classes".

GT isn't concurrent to Java, C#, VB.NET...

GT, as C and C++, enables to create any kind of software without restriction, without overhead nor any need of a top gun machine to correctly run. It doesn't rely on a runtime and has no need to "finish to compile its code" at class loading. It has no dependency with any library that weights many Mo. GT is as light as C.

Example

GT's syntax will seem pretty classic to C, C++, D, C# and Java developers. Here is a sample showing the main features of the language:

program.gt
#include <stdio.h>
#include <string.h>

class int{
	void autoincrement(){
		*this = *this+1; // this is an int*
	}
}
class Account{
	int number;
	
	void open(){
		puts("Account.open");
		number.autoincrement();
	}
}
class CheckAccount: Account{
	int numCheckBook;
	
	void open(){
		puts("CheckAccount.open");
		super.open();
	}
}
class Account{ // every class is "partial"
	void close(){
		puts("Account.close");
	}
}

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();
		
		Account a;
		a.open();
		
		CheckAccount ca;
		ca.open();
		ca.close();
	}
}

License and download

GT 3.5 is Open Source. Its source code belongs to the Public Domain It can be downloaded at the same place as the executables.

Runtime

gt.exe example.gt example.gt.c analyses example.gt and if no error produces example.gt.c.

gt.exe example.gt -run runs in memory the code that has been compiled from example.gt. This mode requires to have installed TCC in c:\tcc and to have added c:\tcc\tcc.dll (that can be downloaded here for Windows 32 bits)

Bugs, criticisms, suggestions, new features requests, customisation

GT has no dedicated forum. Requests and other reactions can be sent to [email protected].

thomasgil.com is ready to customize, integrate or extend GT for you. Please contact [email protected] to evaluate the workload and cost of the implementation of your needs.