Pointer passed other element
Console program66 lines of .st167 lines of generated Cbuilds as C and Rust
l1 99 after: 1 99
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 an element passed to a function that uses only another element, at a different
# constant index, builds in both targets and prints the same.
ability "value" "l" {
type = List
of = Int
size = 4
}
data "value" "l" {
of = ability.value.l
}
ability "add" "First" {
list = ability.value.l
value = 0
}
ability "add" "Second" {
list = ability.value.l
value = 2
depends_on = [ability.add.First]
}
ability "function" "g" {
params = [{ name = "q", type = Pointer, to = Int }]
body = [ability.store.S, ability.set.L1, ability.print.In]
}
ability "store" "S" {
pointer = q
value = 1
}
ability "set" "L1" {
target = ability.value.l[1]
value = 99
}
ability "print" "In" {
message = "l1 ${data.value.l.current[1]}"
}
ability "call" "G" {
function = ability.function.g
args = [address_of(ability.value.l[0])]
depends_on = [ability.add.Second]
}
ability "print" "After" {
message = "after: ${data.value.l.current[0]} ${data.value.l.current[1]}"
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.l
+ ability.add.First
+ ability.add.Second
+ ability.function.g
+ ability.store.S
+ ability.set.L1
+ 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-element # a folder holding the .st files above
structop init
structop plan
structop apply