Pointer list change outside
Console program62 lines of .st182 lines of generated Cbuilds as C and Rust
after remove: 20
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 change of a List before the address of one of its elements is taken, or after the pointer's
# last use, builds in Rust as in C. Here remove comes first, then the pointer is taken and read (20), then the List
# changes again once the pointer is no longer used.
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_after_remove" {
locals = [{ name = "lp", type = Pointer, to = Int }]
body = [ability.remove.First, ability.set.AimList, ability.print.AfterRemove, ability.add.Later]
}
ability "set" "AimList" {
target = lp
value = address_of(ability.value.l[0])
}
ability "remove" "First" {
list = ability.value.l
index = 0
}
ability "print" "AfterRemove" {
message = "after remove: ${value_at(lp)}"
}
ability "call" "Show" {
function = ability.function.show_after_remove
depends_on = [ability.add.B]
}
ability "add" "Later" {
list = ability.value.l
value = 30
}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_after_remove
+ ability.remove.First
+ ability.set.AimList
+ ability.print.AfterRemove
+ ability.call.Show
+ ability.add.Later
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-change-outside # a folder holding the .st files above
structop init
structop plan
structop apply