Value method call
Console program125 lines of .st168 lines of generated Cbuilds as C and Rust
module: 5 root: 10, local: 102
On this page
The .st files#
intent.st
structop {
type_app {
exec = {
lang = "C"
}
}
lib_provider {
core = {
source = "StructOp/core"
version = "@latest"
}
}
}main.st
ability "class" "Counter" {
fields = [{ name = "count", type = Int }, { name = "step", type = Int }]
methods = [ability.function.counter_bump]
}
ability "function" "counter_bump" {
body = [ability.set.Bump]
}
ability "set" "Bump" {
target = self.count
value = self.count + self.step
}
ability "value" "c" {
type = Counter
initial = {
count = 0
step = 5
}
}
data "value" "c" {
of = ability.value.c
}
ability "function" "grow" {
body = [ability.call.Inner]
}
ability "call" "Inner" {
function = ability.value.c.bump
}
ability "function" "scratch" {
returns = Int
body = [ability.value.l, ability.call.LocalBump1, ability.call.LocalBump2]
return = data.value.l.current.count
}
ability "value" "l" {
type = Counter
initial = {
count = 100
step = 1
}
}
data "value" "l" {
of = ability.value.l
}
ability "call" "LocalBump1" {
function = ability.value.l.bump
}
ability "call" "LocalBump2" {
function = ability.value.l.bump
}
ability "call" "Grow1" {
function = ability.function.grow
}
ability "call" "Grow2" {
function = ability.function.grow
depends_on = [ability.call.Grow1]
}
module "inner" {
source = "./modules/inner"
depends_on = [ability.call.Grow2]
}
ability "print" "Show" {
message = "root: ${data.value.c.current.count}, local: ${scratch()}"
depends_on = [module.inner]
}modules/inner/main.st
ability "value" "k" {
type = Counter
initial = {
count = 1
step = 2
}
}
data "value" "k" {
of = ability.value.k
}
ability "function" "grow_k" {
body = [ability.call.KBump]
}
ability "call" "KBump" {
function = ability.value.k.bump
}
ability "call" "Run1" {
function = ability.function.grow_k
}
ability "call" "Run2" {
function = ability.function.grow_k
depends_on = [ability.call.Run1]
}
ability "print" "Show" {
message = "module: ${data.value.k.current.count}"
depends_on = [ability.call.Run2]
}Input, plan and generated C#
structop plan
structop plan
# program.app will be created
+ program.app (.structop/build/app)
+ ability.class.Counter
+ ability.function.counter_bump
+ ability.set.Bump
+ ability.value.c
+ ability.function.grow
+ ability.call.Inner
+ ability.function.scratch
+ ability.value.l
+ ability.call.LocalBump1
+ ability.call.LocalBump2
+ ability.call.Grow1
+ ability.call.Grow2
+ module.inner.ability.value.k
+ module.inner.ability.function.grow_k
+ module.inner.ability.call.KBump
+ module.inner.ability.call.Run1
+ module.inner.ability.call.Run2
+ module.inner.ability.print.Show
+ ability.print.Show
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-method-call # a folder holding the .st files above
structop init
structop plan
structop apply