veko-lang.org
Download Free EPUB 3.0

Part III · Concurrency, Dialects, UI & Wasm

Chapter 8

Homoiconic Mini-DSLs, Studio Desktop UI, TUI & Wasm Plugins

Custom quote/compose policy dialects, signed VKP1 packages, 33-widget Studio UIs, and fuel-bounded Wasm

TERMINAL, DESKTOP UI & FFI

Capability-Isolated Terminal UI, RGBA32 Canvas, .ui Window & Opt-In .ffi

Four clean layers keeping CLI binaries tiny while enabling rich TrueColor TUIs, 60 FPS 2D GUIs, and C/Rust interop.

ZERO-CAP PURE-VEKO RENDERING Works on VM, Wasm & Native CAPABILITY-GATED OS & FOREIGN BOUNDARIES .ui and opt-in .ffi mut cv present-canvas RGBA32 pixels Shared telemetry Terminal UIDouble-Buffered TUIlib/tui.vk (TrueColor ANSI) 2D RasterizerRGBA32 Software Canvaslib/ui/canvas.vk (Zero-Copy) Widget ToolkitImmediate-Mode Widgetslib/ui/widgets.vk OS Window (.ui).ui Window Surfacelib/ui.vk + --gui PE switch Foreign Interop (.ffi)Opt-In .ffi C-ABI Bridgelib/ffi.vk (Zero-W^X AOT)
Component & ModuleArchitectural Role
Double-Buffered TUI
lib/tui.vk
Renders flicker-free terminal dashboards by emitting ANSI escapes only for changed cells.
RGBA32 Software Canvas
lib/ui/canvas.vk
Draws alpha-blended shapes, gradients, lines, and crisp 5x7 ASCII glyphs into mut cv.pixels.
Immediate-Mode Widgets
lib/ui/widgets.vk
Composes responsive layouts, themes, hit-tested buttons, lists, and charts over Canvas.
.ui Window Surface
lib/ui.vk + native_pal5.vk
Blits RGBA32 canvases to native Win32 GDI windows or validated headless surfaces.
Opt-In .ffi C-ABI Bridge
lib/ffi.vk + native_pal5.vk
Loads C, C++, Rust, Zig, or Go shared libraries (.dll/.so/.dylib) via static trampolines.

Recipe 8.1: Building a Custom Homoiconic [ ... ] Policy Dialect (quote, compose & parse-block)

Because Veko code and data share the exact same token representation, you can design expressive domain-specific languages in ~20 lines without writing a lexer:

VEKO
eval-acl-rules = fn [rules block, req_role str, req_path str] enum [
    mut i = 0
    while (i + 3) <= (len rules) [
        action = rules[i]       // .allow or .deny
        role   = rules[i + 1]   // 'admin' or '*'
        prefix = rules[i + 2]   // '/admin'
        role_ok = role == '*' or role == req_role
        path_ok = (len req_path) >= (len prefix) and req_path[0..(len prefix)] == prefix
        if role_ok and path_ok [ return action ]
        i = i + 3
    ]
    .deny
]

policy = quote [
    .allow 'superadmin' '/admin'
    .allow '*'          '/stdlib'
    .deny  '*'          '/downloads'
]

decision = eval-acl-rules policy 'guest' '/stdlib/index.html'   // .allow

Recipe 8.2: Official veko-lang.org Ecosystem Packages & Signed VKP1 Bundles

Search, inspect, and install any of the 30 official Ed25519-signed libraries from https://veko-lang.org/packages (cloud_s3, data_formats, openapi, smtp_mail, webauthn, grpc_proto, cluster_raft, mq_streams, db_drivers, resilience, ai_mcp, ai_llm, vec_rag, dataframe_parquet, payments_ledger, graphql, browser_cdp, ldap_saml, oci_k8s, noise_tunnel, iac_fleet, wasm_plugin_sdk, crdt_sync, iot_mqtt, web_live, jobs_cron, doc_media, http_router, veko_ui_kit, sqlite_orm_ext) or pack your own VKP1 archive (lib/pkg/vkp.vk):

POWERSHELL
veko pkg search rag
veko pkg info vec_rag
veko pkg add vec_rag@1.0.0
veko pkg add payments_ledger@1.0.0
veko pkg add graphql@1.0.0
veko pkg verify-lock
VEKO
use [vkp = pkg/vkp, x25 = crypto/x25519, sha = crypto/sha256]

pack-signed-library = fn [] bytes [
    seed = sha/sha256 (bytes/from-str 'publisher-signing-seed-v1')
    pk   = x25/ed25519-pubkey seed
    raw  = vkp/pack-ed25519
        { name = 'veko_ui_kit', version = '1.0.0' }
        { 'mod.vk' = 'pub pill = fn [txt str] str [ `[ {txt} ]` ]' }
        seed
    _ = vkp/verify raw [(vkp/format-trust-key .ed25519 pk)]
    raw
]

Recipe 8.3: Light-Mode Studio UI with Tab Focus Ring, Code Editor & Command Palette (lib/ui/widgets.vk)

Render deterministic RGBA32 Studio surfaces (Win32, zero-libc Linux Wayland/X11, macOS arm64, Wasm <canvas>, or PNG snapshots) with Tab/Shift+Tab keyboard focus traversal, Veko syntax-highlighted code-editor (with 64-step undo/redo), and fuzzy command-palette:

VEKO
use [cv = ui/canvas, w = ui/widgets]

render-studio-frame = fn [mut c cv/Canvas, mut st w/UiState, mut ed w/EditorState, mut pal w/PaletteState] str [
    th = w/light-theme
    cv/clear mut c th.bg
    w/begin-frame mut st

    body = w/panel mut c (w/Rect { x = 16, y = 16, w = 768, h = 448 }) 'Studio Scratchpad' th
    w/code-editor mut c mut st 'main-editor' body mut ed th

    chosen = w/command-palette mut c mut st 'cmd-pal' mut pal [
        w/CommandItem { id = 'run',   label = 'Run Active Module', shortcut = 'Ctrl+Enter' }
        w/CommandItem { id = 'check', label = 'Strict Type Check', shortcut = 'Ctrl+Shift+B' }
    ] th
    w/end-frame mut st
    chosen
]

Recipe 8.4: Fuel-Bounded WebAssembly Sandboxes & Zero-Toolchain Cross-Compilation

Execute untrusted .vk tenant scripts inside vvm with deterministic instruction fuel, or cross-compile standalone native binaries from any host OS:

POWERSHELL
# Run an untrusted plugin in WebAssembly 3.0 with bounded fuel & slab leak verification
veko run --wasm --fuel=500000 --mem-pages=32 --check-slabs plugins/tenant_rule.vk

# Cross-compile standalone native binaries for Windows ARM64, Linux x86_64, Linux ARM64, or Apple Silicon
veko compile --native --target=win-arm64   src/main.vk -o dist/service-win-arm64.exe
veko compile --native --target=linux-x64   src/main.vk -o dist/service-linux-x64
veko compile --native --target=linux-arm64 src/main.vk -o dist/service-linux-arm64
veko compile --native --target=macos-arm64 src/main.vk -o dist/service-macos-arm64