- Integers
- Booleans
- Chars
- Floats
- Strings
- Enums (integer or string based)
- Pointers
- Typedefs
- Functions
- Conditions (if, else, else if)
- Switches
- Loops (for, for-in, while)
- Records
- Arrays
- Generics
fn collatz(x: s64) -> s64 {
steps := 0
while x != 1 {
steps += 1
if !(x % 2) {
x /= 2
}
else {
x = 3 * x + 1
}
print("step {}: {}\n", steps, x)
}
return steps
}
return collatz(42) as s32
- Diagnostics with location and line printing
- SSA conversion
- Constant folding
- Dead code elimination
- Inlining
Only Linux builds are supported. Parts of the code are working on Windows, but it currently does not build with cl.exe. clang-cl might work.
The project should build with C++23-capable versions of clang and gcc, although clang is preferred. If both are installed, xmake will ask which one to use.
- Download xmake (on Arch Linux, run
sudo pacman -S xmake) git clone https://github.com/lstrsrt/compilercd compilerxmake
This builds in Release mode.
To switch to a Debug build, run xmake config -m debug before xmake.
To run: ./build/{debug,release}/compiler [args...].
Pass --help for help.
The --exe flag and tests require nasm and gcc to be installed.