r/ProgrammingLanguages • u/lmntr • 9h ago
Wiret update: my text-first visual language now reads in the order it runs
lemonator32.github.ioI made some changes to my programming languages. There's also a browser version of the editor that you can try out.
The biggest change in this round is how the text is ordered. Until now a function body had three parts: node statements sorted by id, a flow { } block listing exec wires, and a layout { } block of positions and notes. I picked that format because it merges well: each node is one stable chunk and each wire is one line. But to know what a function does, you had to jump between the flow block and the nodes. Here's the loops lesson in the old syntax:
func Main() {
local total: i32
flow {
count.each -> say
count.done -> report
entry -> count
say -> keep
}
node count = Macro std.flow.ForRange(
.first <- 1,
.last <- 5,
)
node entry = Entry()
node keep = SetLocal total(
.value <- Add::<i32>(
.a <- GetLocal total(),
.b <- count.index,
),
)
node report = Call host.Log( ... )
node say = Call host.Log( ... )
layout {
count at (200, 0)
entry at (0, 0)
keep at (1160, 0)
...
}
}Now the body starts at Entry and follows the exec wires. Each exec statement runs after the one before it in its block. A node with several exec outputs (Branch, Switch, Sequence, Try, loop macros) writes each output as a nested block where it runs. Here's the same program but with the new syntax:
func Main() {
local total: i32
exec Entry{pos=(0, 0)}()
exec Macro std.flow.ForRange{pos=(200, 0)}(
.first <- 1
.last <- 5
).each|index| -> {
exec Call host.Log{pos=(820, 0)}(
.message <- Call std.string.Concat{pos=(541, 240)}(
.a <- "Counting: "
.b <- Convert#<i32, string>{pos=(302, 260)}(
.value <- index
)
)
)
@note("Adds index to the running total each time round.")
exec SetLocal total{pos=(1160, 0)}(
.value <- Add#<i32>{pos=(1021, 155)}(
.a <- GetLocal total{pos=(844, 115)}()
.b <- index
)
)
}.done -> {
exec Call host.Log{pos=(1200, 268)}( ... )
}
}It's still a graph, with the same model, the same compiled output and the same bytecode format. But it now reads top to bottom like an imperative program: .each|index| -> { ... } is basically a for-loop, and .then -> { } .else -> { } is basically an if/else. Inline node read backwards from the inputs, data wires form a tree, so a pure node whose output feeds exactly one input is written inside that input. Only shared outputs break the tree. The last exec output can be written as .pin with no block, a consept I call flattening, and the statements after it in the enclosing block continue from it. An if with no else then reads naturally, and so does the .then that runs after a Try. An output's block binds the node's data outputs by name between bars, .each|index, break| -> { ... }. You write just pin by itself, but if a node is declared, you can also write the pin as name.pin. A node is anonymous unless it's used from more than one place. If it is, it gets declared at the top as node name = ..., placed once with exec name, and entered from anywhere else with goto name. A loop is a goto back to an earlier node, and a merge is a goto forward:
node say_hi = Call host.Log(.message <- "Hi!")
exec Entry()
exec say_hi
exec SetLocal count(.value <- Add#<i32>(.a <- GetLocal count(), .b <- 1))
exec Branch(.cond <- Ge#<i32>(.a <- GetLocal count(), .b <- 10)).then -> {
exec Return()
}.else
goto say_hiYes, a visual language ended up with goto. Arbitrary exec wiring is goto, and the text is just honest about it. In practice the structured blocks cover most graphs.
Unreachable code is kept, not dropped. In a graph editor you often have nodes that aren't wired up yet. These go after a ! at the end of the body: !exec ... for an unwired node, !{ ... } for a chain that's wired together but not reached from Entry, and !Kind(...) for a pure node nothing reads. The editor draws them greyed out. This is different from @disabled, which marks a node that is on the path and gets skipped.
Anonymous nodes no longer have ids in the text. Tools refer to them by kind plus execution position, e.g. Main.1.fault.0 is the first statement in the .fault block of statement 1. The debugger, diagnostics and the edit/merge tooling all use these.
The layout block is gone. Positions and display properties go in an attribute block on the node, Kind{pos=(x, y), label="..."}(...), and notes are @note(...) on the line above it. Attribute blocks are excluded from the semantic hash, so moving a node never changes what the program means. A node without one gets auto-placed, so you can write a valid graph with no layout at all.