Your first program
Source:
docs/getting-started/first-program.md· revisione9ec458cc39c6da005cd81e959360ec89648b8c7· blob4ae0190c693fb552243c4d693987240f3479c38b· 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.
Hello, world
Section titled “Hello, world”Create a file named hello.aipo:
io.println("Hello from Aipo!")Run it in a terminal:
aipo run hello.aipoExpected output:
Hello from Aipo!Structs, invariants, and methods
Section titled “Structs, invariants, and methods”The following example models an account with a non-negative balance invariant:
struct Account {holderaccount_numbervar balance = 0.0}impl Account {init(holder, account_number = 0, balance = 0.0) {self.holder = holderself.account_number = account_numberself.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}}Inspect bytecode
Section titled “Inspect bytecode”Aipo documentation presents the aipo disasm command to inspect instructions and source coordinates:
aipo disasm account.aipoCompile to JavaScript
Section titled “Compile to JavaScript”The JavaScript backend can be used in the documented local workflow:
aipo build account.aipo -o dist/account.jsnode dist/account.js