?
Unknown Status unknown.
Code
// Test: Interpreter identity branch constructor (result s) and discard (_)
~import std/runtime
~import std/interpreter
~import std/io
const std = @import("std");
// Event with identity branch payload
~pub tor add { a: i64, b: i64 }
| sum i64
~add => sum a + b
~std/runtime:register(scope: "test") {
add
}
const TEST_SOURCE_IDENTITY =
\\add(a: 3, b: 4)
\\| sum s |> result s
;
const TEST_SOURCE_BRANCH =
\\add(a: 3, b: 4)
\\| sum s |> result s.Branch
;
const TEST_SOURCE_DISCARD =
\\add(a: 3, b: 4)
\\| sum s |> _
;
~std/runtime:get-scope(name: "test")
| scope s |> std/interpreter:run(source: TEST_SOURCE_IDENTITY, s.dispatcher)
| result r |> std/interpreter:value.stringify(r.value)
| json j |> std/io:print.ln("IDENTITY {{ j:s }}")
| exhausted e |> std/io:print.ln("EXHAUSTED: {{ e.last_event:s }}")
| parse-error e |> std/io:print.ln("PARSE ERROR: {{ e.message:s }}")
| validation-error e |> std/io:print.ln("VALIDATION ERROR: {{ e:s }}")
| dispatch-error e |> std/io:print.ln("DISPATCH ERROR: {{ e.message:s }}")
| not-found |> std/io:print.ln("SCOPE NOT FOUND")
~std/runtime:get-scope(name: "test")
| scope s |> std/interpreter:run(source: TEST_SOURCE_BRANCH, s.dispatcher)
| result r |> std/interpreter:value.stringify(r.value)
| json j |> std/io:print.ln("BRANCH {{ j:s }}")
| exhausted e |> std/io:print.ln("EXHAUSTED: {{ e.last_event:s }}")
| parse-error e |> std/io:print.ln("PARSE ERROR: {{ e.message:s }}")
| validation-error e |> std/io:print.ln("VALIDATION ERROR: {{ e:s }}")
| dispatch-error e |> std/io:print.ln("DISPATCH ERROR: {{ e.message:s }}")
| not-found |> std/io:print.ln("SCOPE NOT FOUND")
~std/runtime:get-scope(name: "test")
| scope s |> std/interpreter:run(source: TEST_SOURCE_DISCARD, s.dispatcher)
| result r |> std/io:print.ln("DISCARD {{ r.value.branch:s }}")
| exhausted e |> std/io:print.ln("EXHAUSTED: {{ e.last_event:s }}")
| parse-error e |> std/io:print.ln("PARSE ERROR: {{ e.message:s }}")
| validation-error e |> std/io:print.ln("VALIDATION ERROR: {{ e:s }}")
| dispatch-error e |> std/io:print.ln("DISPATCH ERROR: {{ e.message:s }}")
| not-found |> std/io:print.ln("SCOPE NOT FOUND")
Expected output
IDENTITY {"branch":"result","value":7}
BRANCH {"branch":"result","value":"sum"}
DISCARD discard
Flows
flow ~register click a branch to expand · @labels scroll to their anchor
register (scope: "test", source: add)
flow ~get-scope click a branch to expand · @labels scroll to their anchor
get-scope (name: "test")
flow ~get-scope click a branch to expand · @labels scroll to their anchor
get-scope (name: "test")
flow ~get-scope click a branch to expand · @labels scroll to their anchor
get-scope (name: "test")
Test Configuration
MUST_RUN