Value module copies
Console program70 lines of .st198 lines of generated Cbuilds as C and Rust
0 2 20 20
On this page
The .st files#
intent.st
structop {
type_app {
exec = {
lang = "C"
}
}
lib_provider {
core = {
source = "StructOp/core"
version = "2.2.0"
}
}
}main.st
module "counted" {
source = "./modules/tally"
count = 2
step = count.index
}
module "named" {
source = "./modules/tally"
for_each = ["ann", "bob"]
step = 10
}
ability "print" "Totals" {
message = "${module.counted[0].n} ${module.counted[1].n} ${module.named[\"ann\"].n} ${module.named[\"bob\"].n}"
depends_on = [module.counted, module.named]
}modules/tally/main.st
variable "step" {
type = Int
}
ability "value" "N" {
type = Int
initial = 0
}
data "value" "N" {
of = ability.value.N
}
ability "function" "Inner" {
body = [ability.set.Add]
}
ability "set" "Add" {
target = ability.value.N
value = data.value.N.current + var.step
}
ability "function" "Outer" {
body = [ability.call.Once, ability.call.Again]
}
ability "call" "Once" {
function = ability.function.Inner
}
ability "call" "Again" {
function = ability.function.Inner
}
ability "call" "Run" {
function = ability.function.Outer
}
output "n" {
value = data.value.N.current
}Input, plan and generated C#
structop plan
structop plan
# program.app will be created
+ program.app (.structop/build/app)
+ module.counted[0].ability.value.N
+ module.counted[0].ability.function.Inner
+ module.counted[0].ability.set.Add
+ module.counted[0].ability.function.Outer
+ module.counted[0].ability.call.Once
+ module.counted[0].ability.call.Again
+ module.counted[0].ability.call.Run
+ module.counted[1].ability.value.N
+ module.counted[1].ability.function.Inner
+ module.counted[1].ability.set.Add
+ module.counted[1].ability.function.Outer
+ module.counted[1].ability.call.Once
+ module.counted[1].ability.call.Again
+ module.counted[1].ability.call.Run
+ module.named["ann"].ability.value.N
+ module.named["ann"].ability.function.Inner
+ module.named["ann"].ability.set.Add
+ module.named["ann"].ability.function.Outer
+ module.named["ann"].ability.call.Once
+ module.named["ann"].ability.call.Again
+ module.named["ann"].ability.call.Run
+ module.named["bob"].ability.value.N
+ module.named["bob"].ability.function.Inner
+ module.named["bob"].ability.set.Add
+ module.named["bob"].ability.function.Outer
+ module.named["bob"].ability.call.Once
+ module.named["bob"].ability.call.Again
+ module.named["bob"].ability.call.Run
+ ability.print.Totals
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 value-module-copies # a folder holding the .st files above
structop init
structop plan
structop apply