Pointer passed other root
Console program61 lines of .st132 lines of generated Cbuilds as C and Rust
in g: 1 2 after: 1
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 14.1.4: the address of a value passed to a function that uses only other values builds in both targets.
ability "value" "x" {
type = Int
initial = 5
}
data "value" "x" {
of = ability.value.x
}
ability "function" "g" {
params = [{ name = "p", type = Pointer, to = Int }]
body = [ability.store.S, ability.set.X, ability.print.In]
}
ability "store" "S" {
pointer = p
value = 1
}
ability "value" "y" {
type = Int
initial = 1
}
data "value" "y" {
of = ability.value.y
}
ability "set" "X" {
target = ability.value.y
value = 2
}
ability "print" "In" {
message = "in g: ${value_at(p)} ${data.value.y.current}"
}
ability "call" "G" {
function = ability.function.g
args = [address_of(ability.value.x)]
}
ability "print" "After" {
message = "after: ${data.value.x.current}"
depends_on = [ability.call.G]
}Input, plan and generated C#
structop plan
structop plan
# program.app will be created
+ program.app (.structop/build/app)
+ ability.value.x
+ ability.function.g
+ ability.store.S
+ ability.value.y
+ ability.set.X
+ ability.print.In
+ ability.call.G
+ ability.print.After
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-passed-other-root # a folder holding the .st files above
structop init
structop plan
structop apply