Pointer passed other field
Console program57 lines of .st136 lines of generated Cbuilds as C and Rust
b 9 after: 1 9
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 field passed to a function that uses only another field of the same value builds
# in both targets and prints the same (the copy Rust writes back after the call holds only that field).
ability "struct" "P" {
fields = [{ name = "a", type = Int }, { name = "b", type = Int }]
}
ability "value" "p" {
type = P
initial = { a = 0, b = 2 }
}
data "value" "p" {
of = ability.value.p
}
ability "function" "g" {
params = [{ name = "q", type = Pointer, to = Int }]
body = [ability.store.S, ability.set.B, ability.print.In]
}
ability "store" "S" {
pointer = q
value = 1
}
ability "set" "B" {
target = ability.value.p.b
value = 9
}
ability "print" "In" {
message = "b ${data.value.p.current.b}"
}
ability "call" "G" {
function = ability.function.g
args = [address_of(ability.value.p.a)]
}
ability "print" "After" {
message = "after: ${data.value.p.current.a} ${data.value.p.current.b}"
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.struct.P
+ ability.value.p
+ ability.function.g
+ ability.store.S
+ ability.set.B
+ 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-field # a folder holding the .st files above
structop init
structop plan
structop apply