Bytes basic
Console program55 lines of .st157 lines of generated Cbuilds as C and Rust
Hi 2 105
On this page
The .st files#
intent.st
structop {
type_app {
exec = {
lang = "C"
}
}
lib_provider {
core = {
source = "StructOp/core"
version = "@latest"
}
}
}main.st
ability "value" "buf" {
type = Bytes
size = 8
}
data "value" "buf" {
of = ability.value.buf
}
ability "set" "Fill" {
target = ability.value.buf
value = bytes(var.text)
}
ability "set" "Upper" {
target = ability.value.buf[0]
value = 72
depends_on = [ability.set.Fill]
}
ability "print" "Show" {
message = "${text(data.value.buf.current)} ${length(data.value.buf.current)} ${data.value.buf.current[1]}"
depends_on = [ability.set.Upper]
}vars.st
variable "text" {
type = String
default = "hi"
}tests/bytes.sttest
run "fits" {
variables = { text = "12345678" }
expect {
output_equals = "H2345678 8 50\n"
}
}
run "overflows" {
variables = { text = "123456789" }
expect {
exit_code = 1
}
}Input, plan and generated C#
structop plan
structop plan
# program.app will be created
+ program.app (.structop/build/app)
+ ability.value.buf
+ ability.set.Fill
+ ability.set.Upper
+ ability.print.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 bytes-basic # a folder holding the .st files above
structop init
structop plan
structop apply