Gengoscript

gengoscript — an embeddable scripting language for host applications that need user-defined logic without ambient machine access.

Constraints live in the language, bad values fail at construction, and system access exists only when the host exposes it.

Gengoscript gives hosts constrained domain values, explicit imports, and user-defined logic that can reach only the capabilities the host exposes.

std := import("std")

type Port int range 1..65535
type Region string predicate func(s) {
    return s == "eu-west" or s == "us-east"
}
type RolloutPercent int range 0..100
type Decision variant {
    allow,
    deny(reason string),
}

pub func decide_deploy(
    raw_port int,
    raw_region string,
    raw_rollout int,
) Decision {
    port := Port(raw_port)
    region := Region(raw_region)
    rollout := RolloutPercent(raw_rollout)
    if port != Port(443) {
        return Decision.deny("only https is allowed")
    }
    if region != Region("eu-west") {
        return Decision.deny("region not enabled")
    }
    if rollout > RolloutPercent(25) {
        return Decision.deny("rollout exceeds safe limit")
    }
    return Decision.allow
}

Domain Rules

Make invalid values fail where they enter the script instead of leaking further into host-side code.

type Currency string predicate func(s) {
    return s == "USD" or s == "EUR"
}
type Discount int range 0..100

currency := Currency("EUR")
sale := Discount(15)

Policy Logic

Decision logic can carry domain constraints directly instead of relying on the host to validate every input first.

type EventCode int predicate func(x) {
    return x rem 2 == 0
}
type SourceId string predicate func(s) {
    return s == "sensor-a" or s == "sensor-b"
}

pub func accept(code int, source string) bool {
    c := EventCode(code)
    s := SourceId(source)
    return c == EventCode(42) and s == SourceId("sensor-a")
}

Host-Granted Access

Imports are explicit. Filesystem, HTTP, and host modules exist only when the embedding application exposes them.

http := import("cap:http")
cfg := import("host:deploy")

resp, err := http.get(cfg.healthcheck_url())
ok := err == null

Gengoscript is a host-embedded language for running untrusted or user-supplied scripts under explicit host control. Scripts get language utilities through std, but filesystem, network, and host integration exist only if the embedding application grants them.

Each runtime instance is isolated and host-configured. The host decides which capability modules and host modules exist, whether script I/O is enabled, and what instruction, heap, stack, and frame limits apply to execution.

Capabilities

Filesystem, HTTP, and other system access are opt-in. Scripts can import only the capability and host modules the application exposes.

Nominal Types

Domain rules live in the script itself. Range types, predicates, and subtypes let bad values fail at construction instead of later in host-side validation.

Embedding

Embed from Zig through the runtime API or from other hosts through the C-compatible engine surface. Load a script, call exported functions, or drive the engine directly through calls such as engine_run and engine_call.

Bounded Execution

Instruction budgets, heap limits, stack limits, and per-instance isolation let hosts bound script cost and contain failure scope.

Install from the published artifacts on GitHub Releases, or build the CLI from source when you want the latest tree. Gengoscript requires Zig 0.16.0 for source builds.

Use the native CLI for local development and REPL work. Build the WASI target when you want the WebAssembly runtime described in the docs, or when you want to run the CLI through wasmtime.

# Build CLI from source
zig build -Dpreset=1m cli

# Build WASI runtime
zig build -Dpreset=1m wasi

# Execute
./zig-out/bin/gengo script.gengo

# Run the WASI build with wasmtime
wasmtime --dir . ./build/gengo-cli.wasm -- script.gengo

Installation is documented through published artifacts and explicit build steps, not remote shell bootstrap scripts.

Start with the Playground for a quick feel, the docs for the language and embedding model, or GitHub for the source tree and releases.

View on GitHub Open Playground