Value local types
Console program199 lines of .st201 lines of generated Cbuilds as C and Rust
abc 1/20 101,2,3 2:bob 1 x 42 abc 1/20 101,2,3 2:bob 1 x 42
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 "enum" "Mood" {
values = [Happy, Sleepy]
}
ability "struct" "Pair" {
fields = [
{ name = "a", type = Int },
{ name = "b", type = Int },
]
}
ability "class" "Counter" {
fields = [{ name = "n", type = Int }]
methods = [ability.function.counter_bump]
}
ability "function" "counter_bump" {
body = [ability.set.Bump]
}
ability "set" "Bump" {
target = self.n
value = self.n + 1
}
ability "function" "Work" {
body = [
ability.value.Name,
ability.value.P,
ability.value.Nums,
ability.value.Names,
ability.value.M,
ability.value.Fp,
ability.value.Ch,
ability.value.C,
ability.append.More,
ability.set.PB,
ability.set.N0,
ability.add.Bob,
ability.set.Sleep,
ability.open.In,
ability.call.BumpC,
ability.call.BumpAgain,
ability.print.All,
]
}
ability "value" "Name" {
type = String
size = 16
initial = "ab"
}
data "value" "Name" {
of = ability.value.Name
}
ability "value" "P" {
type = Pair
initial = {
a = 1
b = 2
}
}
data "value" "P" {
of = ability.value.P
}
ability "value" "Nums" {
type = Array
of = Int
size = 3
initial = [1, 2, 3]
}
data "value" "Nums" {
of = ability.value.Nums
}
ability "value" "Names" {
type = List
of = String
size = 4
initial = ["ann"]
}
data "value" "Names" {
of = ability.value.Names
}
ability "value" "M" {
type = Mood
initial = Mood.Happy
}
data "value" "M" {
of = ability.value.M
}
ability "value" "Fp" {
type = File
}
data "value" "Fp" {
of = ability.value.Fp
}
ability "value" "Ch" {
type = Char
initial = "-"
}
data "value" "Ch" {
of = ability.value.Ch
}
ability "value" "C" {
type = Counter
initial = {
n = 40
}
}
data "value" "C" {
of = ability.value.C
}
ability "call" "BumpC" {
function = ability.value.C.bump
}
ability "call" "BumpAgain" {
function = ability.value.C.bump
}
ability "append" "More" {
target = ability.value.Name
value = "c"
}
ability "set" "PB" {
target = ability.value.P.b
value = data.value.P.current.b * 10
}
ability "set" "N0" {
target = ability.value.Nums[0]
value = data.value.Nums.current[0] + 100
}
ability "add" "Bob" {
list = ability.value.Names
value = "bob"
}
ability "set" "Sleep" {
target = ability.value.M
value = Mood.Sleepy
}
ability "open" "In" {
path = "input.txt"
mode = read
file = ability.value.Fp
body = [ability.read.First]
}
ability "read" "First" {
file = ability.value.Fp
target = ability.value.Ch
}
ability "print" "All" {
message = "${data.value.Name.current} ${data.value.P.current.a}/${data.value.P.current.b} ${data.value.Nums.current[0]},${data.value.Nums.current[1]},${data.value.Nums.current[2]} ${length(data.value.Names.current)}:${data.value.Names.current[1]} ${int(data.value.M.current == Mood.Sleepy)} ${data.value.Ch.current} ${data.value.C.current.n}"
}
ability "call" "Once" {
function = ability.function.Work
}
ability "call" "Twice" {
function = ability.function.Work
depends_on = [ability.call.Once]
}Input, plan and generated C#
structop plan
structop plan
# program.app will be created
+ program.app (.structop/build/app)
+ ability.enum.Mood
+ ability.struct.Pair
+ ability.class.Counter
+ ability.function.counter_bump
+ ability.set.Bump
+ ability.function.Work
+ ability.value.Name
+ ability.value.P
+ ability.value.Nums
+ ability.value.Names
+ ability.value.M
+ ability.value.Fp
+ ability.value.Ch
+ ability.value.C
+ ability.append.More
+ ability.set.PB
+ ability.set.N0
+ ability.add.Bob
+ ability.set.Sleep
+ ability.open.In
+ ability.call.BumpC
+ ability.call.BumpAgain
+ ability.read.First
+ ability.print.All
+ ability.call.Once
+ ability.call.Twice
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-local-types # a folder holding the .st files above
structop init
structop plan
structop apply