Class basic
Console program85 lines of .st147 lines of generated Cbuilds as C and Rust
Total: 15
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_total, ability.function.counter_twice]
}
ability "function" "counter_bump" {
body = [ability.set.Bump]
}
ability "set" "Bump" {
target = self.count
value = self.count + self.step
}
ability "function" "counter_twice" {
body = [ability.call.Again1, ability.call.Again2]
}
ability "call" "Again1" {
function = self.bump
}
ability "call" "Again2" {
function = self.bump
}
ability "function" "counter_total" {
returns = Int
return = self.count
}
ability "value" "c" {
type = Counter
initial = {
count = 0
step = 5
}
}
data "value" "c" {
of = ability.value.c
}
ability "value" "total" {
type = Int
initial = 0
}
data "value" "total" {
of = ability.value.total
}
ability "call" "First" {
function = ability.value.c.twice
}
ability "call" "Second" {
function = ability.value.c.bump
depends_on = [ability.call.First]
}
ability "call" "Read" {
function = ability.value.c.total
result = ability.value.total
depends_on = [ability.call.Second]
}
ability "print" "Show" {
message = "Total: ${data.value.total.current}"
depends_on = [ability.call.Read]
}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.function.counter_twice
+ ability.call.Again1
+ ability.call.Again2
+ ability.function.counter_total
+ ability.value.c
+ ability.value.total
+ ability.call.First
+ ability.call.Second
+ ability.call.Read
+ 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 class-basic # a folder holding the .st files above
structop init
structop plan
structop apply