List capacity
Console program68 lines of .st184 lines of generated Cbuilds as C and Rust
2 added
On this page
The .st files#
intent.st
structop {
type_app {
exec = {
lang = "C"
}
}
lib_provider {
core = {
source = "StructOp/core"
version = "@latest"
}
}
}main.st
parameter "n" {
type = Int
default = 2
}
ability "value" "names" {
type = List
of = Int
size = 3
}
data "value" "names" {
of = ability.value.names
}
ability "value" "i" {
type = Int
initial = 0
}
data "value" "i" {
of = ability.value.i
}
ability "for" "Fill" {
counter = ability.value.i
from = 0
while = data.value.i.current < param.n
next = data.value.i.current + 1
body = [ability.add.One]
}
ability "add" "One" {
list = ability.value.names
value = data.value.i.current
}
ability "print" "Count" {
message = "${length(data.value.names.current)} added"
depends_on = [ability.for.Fill]
}tests/capacity.sttest
run "fits" {
args = ["--n", "3"]
expect {
output_equals = "3 added\n"
}
}
run "overflows" {
args = ["--n", "4"]
expect {
exit_code = 1
}
}Input, plan and generated C#
structop plan
structop plan
# program.app will be created
+ program.app (.structop/build/app)
+ ability.value.names
+ ability.value.i
+ ability.for.Fill
+ ability.add.One
+ ability.print.Count
Plan: 1 to add, 0 to change, 0 to destroy.Generated main.c
To inspect this generated file, select C in intent.st, initialize the project and export its source.
Export locally
structop init
structop apply -source -no-runGenerated main.rs (the same .st built as Rust)
To inspect this generated file, select Rust in intent.st, initialize the project and export its source.
Export locally
structop init
structop apply -source -no-runTry it
cd list-capacity # a folder holding the .st files above
structop init
structop plan
structop apply