Value types
Console program110 lines of .st159 lines of generated Cbuilds as C and Rust
Hello, world: 4 25 6 2 bob
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
# Values of every variable type: an Array, a List, a struct and a sized String.
ability "struct" "Pair" {
fields = [{ name = "a", type = Int }, { name = "b", type = Int, default = 5 }]
}
ability "value" "scores" {
type = Array
of = Int
size = 3
initial = [10, 20, 30]
}
data "value" "scores" {
of = ability.value.scores
}
ability "value" "names" {
type = List
of = String
size = 4
initial = ["ann"]
}
data "value" "names" {
of = ability.value.names
}
ability "value" "pair" {
type = Pair
initial = {
a = 1
}
}
data "value" "pair" {
of = ability.value.pair
}
ability "value" "greeting" {
type = String
size = 32
initial = "Hello"
}
data "value" "greeting" {
of = ability.value.greeting
}
ability "function" "Grow" {
body = [ability.value.extra, ability.set.First, ability.set.Second, ability.set.PairA, ability.add.Bob, ability.append.World]
}
# A value listed in a function is its local, declared like the file-level ones.
ability "value" "extra" {
type = Array
of = Int
size = 2
initial = [4]
}
data "value" "extra" {
of = ability.value.extra
}
ability "set" "First" {
target = ability.value.scores[0]
value = data.value.extra.current[0]
}
ability "set" "Second" {
target = ability.value.scores[1]
value = data.value.scores.current[1] + 5
}
ability "set" "PairA" {
target = ability.value.pair.a
value = data.value.pair.current.a + data.value.pair.current.b
}
ability "add" "Bob" {
list = ability.value.names
value = "bob"
}
ability "append" "World" {
target = ability.value.greeting
value = ", world"
}
ability "call" "GrowIt" {
function = ability.function.Grow
}
ability "print" "Show" {
message = "${data.value.greeting.current}: ${data.value.scores.current[0]} ${data.value.scores.current[1]} ${data.value.pair.current.a} ${length(data.value.names.current)} ${data.value.names.current[1]}"
depends_on = [ability.call.GrowIt]
}Input, plan and generated C#
structop plan
structop plan
# program.app will be created
+ program.app (.structop/build/app)
+ ability.struct.Pair
+ ability.value.scores
+ ability.value.names
+ ability.value.pair
+ ability.value.greeting
+ ability.function.Grow
+ ability.value.extra
+ ability.set.First
+ ability.set.Second
+ ability.set.PairA
+ ability.add.Bob
+ ability.append.World
+ ability.call.GrowIt
+ 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-types # a folder holding the .st files above
structop init
structop plan
structop apply