Getting Started

This guide compiles and runs a complete SLang program.

Prerequisites

SLangCC currently emits x86-64 Linux assembly and invokes gcc first, or clang if GCC is unavailable. Keep codegen/runtime.o beside the compiler in the source-tree layout.

Write a program

Create hello.sl:

void main()
{
    string audience = "SLangCC";
    print("Hello, ", audience, "!");
}

SLang files use typed declarations, # comments, and a void main() entry point.

Compile

From the repository root:

./slangcc hello.sl

The compiler parses and type-checks the source, lowers it to SLangIR, generates x86-64 assembly, and links a native executable. Without -o, the output is named hello beside the source.

Compiled "hello.sl" to "hello".

Run

./hello

Expected output:

Hello, SLangCC!

Choose another output path with:

./slangcc hello.sl -o build/hello

The destination directory must already exist.

Inspect compiler stages

./slangcc hello.sl --ast-dump --ast-semantic-dump --ir-dump --asm-dump

This additionally writes hello.ast.json, hello.semantic.json, hello.ir, and hello.s in the current working directory.

Next, explore the examples, language guide, or compiler options.