Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Getting Started

Building the Compiler

The Lake native compiler is written in Rust (edition 2024) and uses Cranelift as its code generation backend:

git clone https://github.com/morphqdd/lake-native-compiler.git
cd lake-native-compiler
cargo build

Running an Example

cargo run -- examples/counter.lake -o counter
./counter

First Program

Here is a minimal Lake program:

@rt(rt_write)

main is {
  _ i64.0 -> {
    rt_write(1 "hello, lake!\n" 14)
  }
}

This program:

  1. Declares a runtime function rt_write via the @rt directive
  2. Defines a main machine with a single branch
  3. Calls rt_write with a file descriptor (1 = stdout), a string, and its length

Program Structure

Every Lake program consists of:

  1. Directives — compiler attributes that declare runtime functions (@rt)
  2. Machines — the program logic, defined with is
@rt(rt_write)                # 1. directive

main is {                    # 2. machine
  _ i64.0 -> {
    rt_write(1 "done\n" 5)
  }
}

Machines can be declared in any order — forward references are resolved automatically.