// Example 04: Homoiconic blocks, quote, compose/deep, parse-block, and compile-time macros
// Track A (ORO VM) : veko run examples/04_macros_and_dialects.vk
// Track A (.vko) : veko compile --vko examples/04_macros_and_dialects.vk -o dist/04.vko ; veko run dist/04.vko
// Track B (Wasm 3) : veko run --wasm examples/04_macros_and_dialects.vk
// Track C (Native) : veko compile --native examples/04_macros_and_dialects.vk -o dist/04.exe ; ./dist/04.exe
// 1. Inspecting unevaluated homoiconic blocks with quote
spec = quote [route .tcp '10.0.0.0/8' 8443 30s]
println spec.len
println (type-of spec[1])
println spec[4]
// 2. Templating blocks without backtick/comma soup
port = 9000
tls-mode = .strict
server-cfg = compose/deep [
bind '127.0.0.1' (port)
policy [mode (tls-mode) timeout 15s]
]
println (mold server-cfg)
// 3. Declarative DSL parsing via parse-block
mut endpoints = []
parsed-ok = parse-block (quote [allow .tcp '10.1.0.0/16' 443 allow .udp '10.2.0.0/16' 51820]) [
any [
['allow' proto = enum! cidr = str! p = int!] [
push mut endpoints (compose [(proto) (cidr) (p)])
]
]
]
println parsed-ok
println (mold endpoints)
// 4. Compile-time macro expansion
triple = macro [x] [
compose [(x) + (x) + (x)]
]
println (triple 14)