Pointer query bind
Console program58 lines of .st162 lines of generated Cbuilds as C and Rust
x=5 x=6
On this page
The .st files#
intent.st
structop {
type_app {
exec = {
lang = "C"
}
}
lib_provider {
core = {
source = "StructOp/core"
version = "@latest"
}
}
}main.st
# Language 7.6.6: a pointer bound by a query's bind is set by the query, so it may be used in the
# query's body (a store, value_at, a field) without a set before it, in a function, in both targets.
ability "component" "Pos" {
fields = [{ name = "x", type = Int }]
}
ability "function" "step" {
body = [ability.query.Move]
}
ability "query" "Move" {
with = [Pos]
bind = {
p = Pos
}
body = [ability.set.Right, ability.print.At]
}
ability "set" "Right" {
target = p.x
value = p.x + 1
}
ability "print" "At" {
message = "x=${p.x}"
}
ability "spawn" "One" {
components = {
Pos = {
x = 4
}
}
}
ability "call" "First" {
function = ability.function.step
depends_on = [ability.spawn.One]
}
ability "call" "Second" {
function = ability.function.step
depends_on = [ability.call.First]
}Input, plan and generated C#
structop plan
structop plan
# program.app will be created
+ program.app (.structop/build/app)
+ ability.component.Pos
+ ability.function.step
+ ability.query.Move
+ ability.set.Right
+ ability.print.At
+ ability.spawn.One
+ ability.call.First
+ ability.call.Second
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 pointer-query-bind # a folder holding the .st files above
structop init
structop plan
structop apply