The Thrust Programming Language
TheThrust Programming Language. A general-purpose, statically typed systems programming language for writing verbose, accurate, and fast code.
- Syntactically it is based on Rust.
- Is C based.
Thrust is a very promising tool for bare-metal and embedded system development thanks to its innovative low-level instruction concepts, particularly its integrated Low-Level Instructions (LLIs) for powerful IR manipulation using GCC and LLVM intrinsics. Thrust offers more granular control over system languages by manipulating low-level instructions for extreme manual optimizations that compiler backends cannot decipher.
- Thrust enables embedding of linear assembler within the compilation process, offering direct control over architecture-specific code generation.
asmfn invoke_x86_64_exit_syscall() void@asmSyntax("AT&T") @convention("C"){"mov $$60, %rax","mov $$1, %rdi","syscall"}{"~{rax}~{rdi}"}fn main() s32 @public{ invoke_x86_64_exit_syscall();return0;}
- Full standalone Ahead Of Time (AOT) compilation.
- Full Just In Time (JIT) compilation via
-jit. - Control over deeper C compiler code optimizations.
- Deeper code generation control.
- Robust static type checking.
- Standalone x86_64 assembler interoperability.
- Automatically generated types for C headers (CBindgen) through the Clang frontend C & C++ compiler.
- Quantum code generation, through QIR.
- Support for quantum behavior emulation with embedded QCOR, or a bytecode runner.
- The Thrust compiler
thrustc: The Thrust compiler is in a near-BETA phase (final bug hunts), and the first edition of the language will soon be available. Torio (the package manager) won’t be ready, so a temporary installer will be created until Torio development is complete or advanced enough for a beta. The documentation is on its way.
The documentation is on its way.New, dedicated documentation is on its way for the web; however, you can view the outdated version at:https://github.com/thrustlang/syntax
./thrustc -opt=O3 fibonacci.thrust -start -o fibonacci -end && ./fibonacci.\thrustc.exe -opt=O3 fibonacci.thrust -start -o fibonacci.exe -end && .\fibonacci.exeIn the future, there will be a package manager that works exactly like RustCargo. Once it is installed in the system path at the root of the project, wherever theProject.toml file is located, it will automate the program's build process.
torio run// ******************************************************************************************//// Hello World!//// ******************************************************************************************// Thrust Programming Language - File extensions//// - '.🐦'// - '.Thrust'//// External declaration for the C printf functionfn print(fmt:const array[char]) s32 @public @arbitraryArgs @extern("printf") @convention("C");fn main() s32 @public{ print("Hello World!");return0;}
// ******************************************************************************************//// Fibonacci - O(2^n)//// ******************************************************************************************// Thrust Programming Language - File extensions// // - '.🐦'// - '.thrust'//// External declaration for the C printf functionfn print(fmt:const array[char]) s32 @public @arbitraryArgs @extern("printf") @convention("C");// Computes the nth Fibonacci number recursively//// Parameters:// n: The index of the Fibonacci number to compute (unsigned 32-bit integer)//// Returns: The nth Fibonacci number (unsigned 32-bit integer)//// Attributes:// @hot: Marks the function as frequently executed, encouraging aggressive optimizations.// @inline:// Maps to LLVM's 'inlinehint', suggesting the compiler inline this function// at call sites to reduce call overhead. May increase code size, and may be// limited for deep recursion.// @nounwind:// Maps to LLVM's 'nounwind', guaranteeing the function will not unwind the stack// (i.e., it will not throw an exception or cause an abnormal termination// that requires stack unwinding). This enables significant optimizations.//fn fibonacci(n:u32) u32@hot@inline@nounwind{ if n <=1{ return n; } return fibonacci(n -1) + fibonacci(n -2);}// Prints the first n Fibonacci numbers// Parameters:// n: The number of Fibonacci numbers to print (unsigned 32-bit integer)fnprintFibonacci(n:u32) void{ for localmuti:u32 =0; i <n; ++i;{ print("%d\n",fibonacci(i)); }}fnmain(argc:u32,argv: ptr[array[char]]) s32 @public{ print("Fibonacci sequence: "); printFibonacci(25); return0;}
// ******************************************************************************************//// 100 MILLIONS ARRAY UPDATES//// ******************************************************************************************fn atoi(str:const array[char]) s32 @public @vaArgs @extern("atoi") @convention("C");fn srand(seed:u32) void @public @extern("srand") @convention("C");fntime(timer:ptr) u32 @public @extern("time") @convention("C");fn rand() s32 @public @extern("rand") @convention("C");fnprint(fmt:const array[char]) s32 @public @arbitraryArgs @extern("printf") @convention("C");fn main(argc:s32,argv: ptr[array[char]]) s32 @public{ local mut u: s32 =atoi((deref(argv[1]asptr[ptr[char]]))asconstarray[char]);srand(time(nullptr)); local mut r: s32 =rand() %10000; local mut a: array[s32;10000];for localmut i: s32 =0; i <10000;i++;{for localmut j: s32 =0; j <100000;j++;{ a[i] =(deref a[i]) +((j % u));} a[i] =(deref a[i]) + r;}print("%ld\n", deref a[r]);return0;}
#include"stdio.h"#include"stdlib.h"#include"stdint.h"#include"time.h"intmain(intargc,char**argv) {intu=atoi(argv[1]);srand(time(NULL));intr=rand() %10000;int32_ta[10000]= {0};for (inti=0;i<10000;i++) {for (intj=0;j<100000;j++) {a[i]=a[i]+j%u; }a[i]+=r; }printf("%d\n",a[r]); }
- Thrust: AVG
1.76s - C: AVG
1.79s
Note
Actually, it can be a margin of error and is the same as C, although with-jit it even outperforms C, even though the Just-In-Time Compiler always has a heavy overhead at startup.
Commands:
thrustc -opt=O3 loop.thrust -start -o loop -end && ./loop 1clang -O3 loop.c -o loop && ./loop 1Note
Obviously, if you have a little knowledge of CS, you know that this isn't the ideal way to test which programming language is faster, but anyway, it's just to point out that Thrust is trying to be a C equivalent in the speed field.
TheThrust Programming Language is involved with a research project or is part of a census at the University of Porto (U.Porto) and the Institute for Systems and Computer Engineering, Technology and Science (INESC TEC), related to a former PhD student.
DISCLAIMER:THIS DOES NOT MEAN THAT Thrust PROGRAMMING LANGUAGE IS OFFICIALLY AFFILIATED WITH THESE INSTITUTIONS.
In fact, the programming language was originally intended for learning purposes in the compiler fields, for the "team" behind the project. However, this doesn't mean it will betaken as seriously as possible.
The responsible team (practically asolo developer) considers it a side, not main, project. We focus on improving both ourselves and our side projects in parallel.
We're looking for contributors for our project! If you're a Spanish speaker and would like to contribute, contact us through our official social media channels.Already knowRust but notLLVM orGCC? Don't worry! We're happy to teach you.
~"It takes a long time to make a tool that is simple and beautiful." ~ Bjarne Stroustrup (C++ Programming Language creator)
PinnedLoading
Repositories
- llvm-project Public Forked fromllvm/llvm-project
The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
Uh oh!
There was an error while loading.Please reload this page.
thrustlang/llvm-project’s past year of commit activity Uh oh!
There was an error while loading.Please reload this page.
thrustlang/.github’s past year of commit activity - thrustc Public
A general-purpose, statically typed systems programming language for writing verbose, accurate, and fast code.
Uh oh!
There was an error while loading.Please reload this page.
thrustlang/thrustc’s past year of commit activity Uh oh!
There was an error while loading.Please reload this page.
thrustlang/quantum’s past year of commit activity Uh oh!
There was an error while loading.Please reload this page.
thrustlang/roadmap’s past year of commit activity - toolchains Public
x86_64 (libc, musl, glibc, msvcrt, libcmt) Windows & Linux precompiled LLVM and Clang infrastructure.
Uh oh!
There was an error while loading.Please reload this page.
thrustlang/toolchains’s past year of commit activity - compiler-builder Public
The Thrust Compiler main dependency constructor builds LLVM and GCC infrastructure for the compiler. (Operating system agnostic)
Uh oh!
There was an error while loading.Please reload this page.
thrustlang/compiler-builder’s past year of commit activity Uh oh!
There was an error while loading.Please reload this page.
thrustlang/lld-wrapper’s past year of commit activity - thrustqc Public
Quantum-based Compiler for the Thrust Programming Language (reassembles Microsoft 'qsc' Qsharp Compiler functionality via the QIR backend using LLVM Infrastructure) (2028 expected).
Uh oh!
There was an error while loading.Please reload this page.
thrustlang/thrustqc’s past year of commit activity Uh oh!
There was an error while loading.Please reload this page.
thrustlang/torio’s past year of commit activity
Top languages
Loading…
Uh oh!
There was an error while loading.Please reload this page.
Most used topics
Loading…
Uh oh!
There was an error while loading.Please reload this page.

