Skip to content

Native software

Zap compiles to native executables while keeping application code organized around ordinary modules and types. Start with a Thor project, then grow the source tree by responsibility.

Put a focused unit behind a module file:

src/greeting.zp
pub fun message(name: String) String {
return "Hello, " + name + "!";
}

Import it from the entry point:

import "./greeting.zp" as greeting;
fun main() Int {
println(greeting.message("Ada"));
return 0;
}

The entry point remains src/main.zp unless thor.toml selects another file.

Classes are reference types with automatic lifetime management:

class Counter {
priv value: Int;
fun init() {
self.value = 0;
}
pub fun next() Int {
self.value = self.value + 1;
return self.value;
}
}

Zap manages strong references automatically. Use ownership and ARC to understand deterministic release and cycle collection, and weak references for links that must not keep an object alive.

Put the default optimization level in thor.toml:

optimization = "O2"

Then build and run normally:

thor build
thor run

See Thor build tool for outputs, dependencies, and native linker flags.