TrustLang

A high-level general-purpose language for trusted development with safe memory management, compile-time error detection and full compatibility with the entire C/C++ ecosystem, including direct embedding of C++ code fragments.

The syntax of every modern programming language keeps getting more complex with each new release (standard). This is an unavoidable price for language evolution and a constantly growing "entry tax" for newcomers.

TrustLang — is a language-«layer» on top of C++ that lets you use all of its rich capabilities, but without its complex syntax, undefined behavior and other pitfalls. Simpler and faster than Python, more familiar and safer than Rust.*

Safe memory without a garbage collector

C++-style memory management using  RAII, strong and weak references. Analysis of errors, data races and cyclic dependencies at compile time. Memory model* →

Stack overflow — as an exception

Program stack overflow is handled as an ordinary program exception, instead of abnormal termination with segfault. Stack protection →

Automatic protection from dangling references

Static analysis of dangling references (analogous to ownership and borrowing in Rust), but for C++ without UB and segfault at runtime. Ownership control* →

Type system

Static and dynamic typing. The type can be specified explicitly or inferred automatically from the context. Ability to use C++ types and templates. Type system →

Integration with C/C++

Embedding of C++ code fragments and direct calls of C++ functions without FFI wrappers. Integration with C++ →

Formal verification

Contract programming (pre/postconditions, assertions). Export of code and contracts to an SMT solver (Z3). Verification* →


*) - The current version is a proof of concept, a test of various approaches to implementing the architecture and prototyping of the syntax

How it looks

An example of a simple TrustLang program with unlimited-precision numbers and automatic type inference.

Running the program as a bash script with automatic compilation of the C++ code on the first run and subsequent execution of the binary file. Automatic recompilation when the source changes.


    #!../_build/trust --run -Wsigil=ignore -Wembed=ignore

    $fact := 1\1;   # Autotyping
    $mult:Int32 := 1; # Fixed type

    while( mult <= 40 ) {
        fact *= mult;   # factorial 40, no precision loss
        {% $mult++ %};  # Increment as a C++ code fragment
    };

    @print('{}', fact);

Output:

    815915283247897734345611269596115894272000000000

More examples and the resulting generated C++ code are in the playground.