Pointer value outside
Console program68 lines of .st142 lines of generated Cbuilds as C and Rust
g 5 q: 6 x 6 g 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 14.1.4: a local pointer to a value of the program borrows it from its set to its last use; a call of a
# function that uses the program's values, or a read of the value, before the set or after the last use builds in
# both targets.
ability "value" "x" {
type = Int
initial = 5
}
data "value" "x" {
of = ability.value.x
}
ability "function" "g" {
body = [ability.print.G]
}
ability "print" "G" {
message = "g ${data.value.x.current}"
}
ability "function" "show" {
locals = [{ name = "lp", type = Pointer, to = Int }]
body = [ability.call.G, ability.set.Aim, ability.store.Up, ability.print.Q, ability.print.X, ability.call.G2]
}
ability "set" "Aim" {
target = lp
value = address_of(ability.value.x)
}
ability "store" "Up" {
pointer = lp
value = value_at(lp) + 1
}
ability "print" "Q" {
message = "q: ${value_at(lp)}"
}
ability "call" "G" {
function = ability.function.g
}
ability "print" "X" {
message = "x ${data.value.x.current}"
}
ability "call" "G2" {
function = ability.function.g
}
ability "call" "Show" {
function = ability.function.show
}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.print.G
+ ability.function.show
+ ability.call.G
+ ability.set.Aim
+ ability.store.Up
+ ability.print.Q
+ ability.print.X
+ ability.call.G2
+ ability.call.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 pointer-value-outside # a folder holding the .st files above
structop init
structop plan
structop apply