Cheat sheet
The core of arche-lang on one page: the declarations every model is written
with (the core set of the language), one line each. The ideas behind them
are in concepts; every property is in
the language reference.
Declarations#
| Write | What it is |
|---|---|
project Pump "Water pump" { version "0.1" } |
The project: its name, version, the libraries it uses. One per model. |
include "parts/motor.arche" |
Another file of the model. |
type Flow = float32 unit l/min range 0..120 |
A data type: a base type, a unit, a range. |
enum Mode { Off, On } |
A choice of named values. |
struct Point { x: float32; y: float32 } |
A record of fields. |
const MAX_FLOW = 100 unit l/min |
A named value. |
message PRESS "Press" { count: uint8 } |
What travels between parts (or message GO: bool, one value). |
component Lamp "Lamp" { … } |
A definition: its ports, variables, functions, states. |
in cmd: can receives PRESS |
A port that receives. out click: can sends PRESS sends; inout does both. |
var level: uint8 = 0 |
A variable of the component, with its first value. |
fn dim "Dim" ```arche … ``` |
A function and what it does, in the action language. main runs from the start. |
states { state Off; state On; Off -> On on PRESS [level > 0] } |
The state machine: the first state is where it starts; A -> B on trigger [guard] / action. |
system Room "Room" { … } |
What Arche shows and runs: parts and the links between them. |
part lamp: Lamp |
An instance of a component, in a system. |
button.click -> lamp.cmd { latency 1ms } |
A link from a port to a port. |
requirement REQ-ON "Turn on" { text "The lamp shall …" } |
What must hold. verified-by TP-ON names its test. |
trace satisfies Room.lamp -> REQ-ON |
A trace written apart (or satisfies REQ-ON in the component). |
test-plan TP-ON "Turning on" { case TC-1 "…" { … } } |
Tests, run in the simulator: at 0ms do …, within 50ms expect …. |
In a ```arche body#
| Write | What it does |
|---|---|
var d = speed * 2.0 |
A local variable. |
level = 0, level += 1 |
Sets a variable of the part. |
if level > 0 { … } else { … } |
A choice. while c { … }, for i in 0..4 { … } loop. |
send click PRESS { count: 1 } |
Sends a message on a port. |
goto On, state == On |
Changes the state; tests it. |
wait 10ms |
Waits. |
dim(), return x |
Calls a function of the part; returns. |
log "pressed", level |
Writes to the simulator's log. |
A body written in ```python still works: the quick fix Convert to
arche body (or archec fix --only arche-body) rewrites a simple one.
Commands#
| Run | To |
|---|---|
archec new |
Start a project from a template. |
archec check main.arche |
Check the model. |
archec sim main.arche |
See it run in the browser. |
archec test main.arche |
Run its test plans in the simulator. |
archec gen main.arche --target c |
Generate code (embassy, go, ros2…). |
archec build main.arche |
Write the Arche project, to open in Arche. |
All of it at once#
project Room "Room" {
version "0.1"
}
message PRESS "Press" { count: uint8 }
const MAX_LEVEL = 10
requirement REQ-ON "Turn on" {
text "The lamp shall turn on within 50 ms of a press."
verified-by TP-ON
}
component Button "Button" {
out click: can sends PRESS
}
component Lamp "Lamp" {
satisfies REQ-ON
in cmd: can receives PRESS
var level: uint8 = 0
states {
state Off
state On
Off -> On on PRESS
On -> Off on PRESS
}
fn main "Brighten" ```arche
while true {
wait 100ms
if state == On and level < MAX_LEVEL {
level += 1
}
}
}
system Home "Home" { part button: Button part lamp: Lamp button.click -> lamp.cmd }
test-plan TP-ON "Turning on" { case TC-ON-01 "A press turns it on" { verifies REQ-ON at 0ms do send(button.click, PRESS(count=1)) within 50ms expect lamp.state == "On" } }