SWAG

SWAG Programming Language

A Modern Playground

Swag is a systems programming language crafted for fun, offering a fresh alternative to the increasingly cumbersome C++.

This is my third compiler project (the previous ones powered AAA game engines), but Swag represents a significant leap forward in terms of capability and design.

Flexible and Powerful

The Swag compiler can generate high-performance native code using a custom x64 backend or LLVM, and it can also function as an interpreter for scripting purposes.

Think of it as C++, but with the ability to make everything constexpr.

Cutting-Edge Features

Swag offers advanced features like full compile-time evaluation, type reflection at both runtime and compile time, meta-programming, generics, a powerful macro system, and much more.

It's designed to be both fun and highly productive.

Explore a detailed, single-script implementation of the Flappy Bird game.

Warning

Swag is still under active development! Everything, including this website, is a work in progress. Features and details are subject to change until we officially reach version 1.0.0. Stay tuned and enjoy the ride!

// The 'IsSet' generic struct mirrors the user-defined struct, // with each field converted to a 'bool' type. // After command-line parsing, it indicates whether each argument // was provided by the user. struct(T) IsSet { #ast { var str = StrConv.StringBuilder{} let typeof = #typeof(T) foreach f in typeof.fields str.appendFormat("%: bool\n", f.name) return str.toString() } }
#test { const N = 4 const PowerOfTwo: [N] s32 = #run { var arr: [N] s32 for i in arr arr[i] = 1 << cast(u32) i return arr } #assert PowerOfTwo[0] == 1 #assert PowerOfTwo[1] == 2 #assert PowerOfTwo[2] == 4 #assert PowerOfTwo[3] == 8 }

Swag is open source and released under the MIT license. The compiler source code is available on GitHub. Check out our YouTube channel for coding sessions.

Warning

As the language evolves, some videos might show outdated syntax. However, the corresponding scripts on GitHub are always up-to-date and functional.

Note

This website and all related documentation were generated using Swag. The compiler can also produce HTML from markdown files and source code.

Generated on 08-09-2024 with swag 0.40.0