Pointer method other value
Console program66 lines of .st158 lines of generated Cbuilds as C and Rust
side 2.000000
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: while a local pointer into one value lives, a method called on another value builds in both targets.
ability "class" "Square" {
fields = [{ name = "side", type = Float }, { name = "n", type = Int }]
methods = [ability.function.Square_grow]
}
ability "function" "Square_grow" {
body = [ability.set.Grow]
}
ability "set" "Grow" {
target = self.n
value = self.n + 1
}
ability "value" "sq" {
type = Square
initial = {
side = 2.0
n = 0
}
}
ability "value" "other" {
type = Square
initial = {
side = 5.0
n = 0
}
}
ability "function" "work" {
locals = [{ name = "lp", type = Pointer, to = Float }]
body = [ability.set.Aim, ability.call.GrowIt, ability.print.Side]
}
ability "set" "Aim" {
target = lp
value = address_of(ability.value.sq.side)
}
ability "call" "GrowIt" {
function = ability.value.other.grow
}
ability "print" "Side" {
message = "side ${value_at(lp)}"
}
ability "call" "Work" {
function = ability.function.work
}Input, plan and generated C#
structop plan
structop plan
# program.app will be created
+ program.app (.structop/build/app)
+ ability.class.Square
+ ability.function.Square_grow
+ ability.set.Grow
+ ability.value.sq
+ ability.value.other
+ ability.function.work
+ ability.set.Aim
+ ability.call.GrowIt
+ ability.print.Side
+ ability.call.Work
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-method-other-value # a folder holding the .st files above
structop init
structop plan
structop apply