Pointer list copies
Console program74 lines of .st183 lines of generated Cbuilds as C and Rust
p: 10 q: 10 r: 10
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: copies of a pointer to a List element share its borrow; without a change of the List while any of
# them is used, the program builds in both targets (the remove comes after the last use).
ability "value" "l" {
type = List
of = Int
size = 3
}
ability "add" "A" {
list = ability.value.l
value = 10
}
ability "add" "B" {
list = ability.value.l
value = 20
depends_on = [ability.add.A]
}
ability "function" "show" {
locals = [{ name = "lp", type = Pointer, to = Int }, { name = "lq", type = Pointer, to = Int }, { name = "lr", type = Pointer, to = Int }]
body = [ability.set.Aim, ability.print.P, ability.set.CopyQ, ability.print.Q, ability.set.CopyR, ability.print.R, ability.remove.First]
}
ability "set" "Aim" {
target = lp
value = address_of(ability.value.l[0])
}
ability "print" "P" {
message = "p: ${value_at(lp)}"
}
ability "set" "CopyQ" {
target = lq
value = lp
}
ability "set" "CopyR" {
target = lr
value = lq
}
ability "print" "Q" {
message = "q: ${value_at(lq)}"
}
ability "print" "R" {
message = "r: ${value_at(lr)}"
}
ability "remove" "First" {
list = ability.value.l
index = 0
}
ability "call" "Show" {
function = ability.function.show
depends_on = [ability.add.B]
}Input, plan and generated C#
structop plan
structop plan
# program.app will be created
+ program.app (.structop/build/app)
+ ability.value.l
+ ability.add.A
+ ability.add.B
+ ability.function.show
+ ability.set.Aim
+ ability.print.P
+ ability.set.CopyQ
+ ability.print.Q
+ ability.set.CopyR
+ ability.print.R
+ ability.remove.First
+ 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-list-copies # a folder holding the .st files above
structop init
structop plan
structop apply