Cheat sheet
This page is arche-lang on one page. It lists the declarations every model is written with, one line each. The 1.0 core, with an example of each construct and what edition 1.0 promises to keep, is core.md.
The smallest model that checks is one component and one system:
component Lamp "Lamp" { var level: uint8 = 0 }
system Room "Room" { part lamp: Lamp }
Save it as room.arche, then run:
archec check room.arche
✓ no errors
The ideas behind the declarations are in concepts. Every property is in the language reference. A whole model that uses each line is at the end of this page.
Declarations#
| Write | What it is |
|---|---|
project Pump "Water pump" { version "0.1" } |
The project: its name, its 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. message GO: bool carries 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. It starts in the first state. A transition is 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. |
satisfies REQ-ON |
In a component or a part: it meets the requirement. In a test case, verifies REQ-ON: it checks it. |
trace refines REQ-ON -> REQ-1 |
A trace written on its own, for the other links (derives, refines, allocates…). |
test-plan TP-ON "Turning on" { case TC-1 "…" { … } } |
Tests, run in the simulator. Steps are at 0ms do … and 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. To rewrite a simple one as an
arche body, use the quick fix Convert to arche body in the editor, or run
archec fix --only arche-body.
Commands#
| Run | To |
|---|---|
archec new |
Start a project from a template. |
archec check main.arche |
Check the model. |
archec sim main.arche |
Run the behaviour and print the trace. Nothing to install. --html sim.html writes a page to run it in a 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."
}
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"
}
}Save it as main.arche. archec check main.arche prints ✓ no errors, and
archec test main.arche runs the test plan:
PASS TP-ON/TC-ON-01 A press turns it on
1/1 passed, 0 failing, 0 known failure(s)
Requirements: 1 verified by passing cases, 0 failing