Skip to content

Your first program

Source: docs/getting-started/first-program.md · revision e9ec458cc39c6da005cd81e959360ec89648b8c7 · blob 4ae0190c693fb552243c4d693987240f3479c38b · MIT license.

Static reading copy. Full, canonical documentation remains in Aipo’s repository.

Português: Seu primeiro programa

This guide walks through writing, checking, compiling, and running a first program in an environment with Aipo installed. Commands below are documentation examples; this page does not execute code.

Create a file named hello.aipo:

hello.aipo
io.println("Hello from Aipo!")

Run it in a terminal:

Janela do terminal
aipo run hello.aipo

Expected output:

Hello from Aipo!

The following example models an account with a non-negative balance invariant:

struct Account {
holder
account_number
var balance = 0.0
}
impl Account {
init(holder, account_number = 0, balance = 0.0) {
self.holder = holder
self.account_number = account_number
self.balance = balance
}
invariant {
self.balance >= 0.0
}
fn deposit(var self, amount: Float) {
if amount <= 0.0 {
return fail("Deposit amount must be positive")
}
self.balance += amount
}
}

Aipo documentation presents the aipo disasm command to inspect instructions and source coordinates:

Janela do terminal
aipo disasm account.aipo

The JavaScript backend can be used in the documented local workflow:

Janela do terminal
aipo build account.aipo -o dist/account.js
node dist/account.js