Get started Browse docs
On this page 5 sections

Get started

Your first program

Build and run the smallest Orbit program, then read its exit code. A 0 means success, and a 3 is a result you can check.

You will write a four-line program, build it into a binary, run it, and read its result from the shell. You need a built compiler first: see install the compiler.

The entry point

Every Orbit program starts at fn main() -> int. The number main returns is the process exit code: the number the shell reports when the program ends. By convention 0 means success and any other number means something else happened.

That gives you a test with nothing to install. A program that returns 0 passed. A program that returns 3 reports 3, and you check that it is the 3 you expected. The compiler’s own test suite checks programs the same way.

Create hello.orb:

hello.orb
fn main() -> int {
  return 0
}

That is a complete program. It does nothing, and it reports success by exiting 0.

Build it

orbit build compiles one file into one native binary. Name the output with -o:

PowerShell
.\orbit.exe build hello.orb -o hello.exe

Unless the compiler folder is on your PATH, run orbit by its local path, as shown. Every example in these docs does this.

Run it, read the answer

Run the binary, then ask the shell what it returned:

PowerShell
.\hello.exe
echo $LASTEXITCODE   # 0

Now change the program to return 3, rebuild, and run again. The shell reports 3. That is a complete test: you expected 3 and observed 3.

The exit-code loop

From here on, every snippet in these docs follows the same loop: write, build, run, read the number. Four examples to build the habit, each one verified against the 0.1.0 fixed-point compiler:

20 seconds — Call a function from main. The sum is the exit code.

Program
fn add(left: int, right: int) -> int {
    return left + right
}

fn main() -> int {
    return add(20, 22)
}
Run
./orbit build tour1.orb -o tour1
./tour1
echo $?   # 42

Exit 42

Statements and comments

Indentation is up to you. The compiler ignores it, and orbit fmt can normalize it later. Write one statement per line.

What next

A program that listens for requests is the other half of the language. Your first service builds one and calls it with curl.

Type to search commands, errors, modules and concepts.