lmcode-go skill
Use lmcode-go to embed the DSLB v6 virtual machine, 226-signature standard library, and REST/CLI controller into dependency-free Go 1.26+ executables.
Purpose
Compile static Go host binaries that expose typed Go structs and functions to lmcode bytecode, validate schemas, serve REST/CLI endpoints, and frame structured results.
When to use it
Use lmcode-go when building a Go command-line tool or service that executes compiled .dslb v6 programs without CGO or third-party Go modules.
Install
Import github.com/lmctl-ai/lmcode-go and github.com/lmctl-ai/lmcode-go/rest with Go 1.26 or newer and CGO_ENABLED=0.
Commands
CGO_ENABLED=0 go build ./...
CGO_ENABLED=0 go test ./...
go run ./cmd/conformance conformance/vectors
go run ./cmd/conformance -std conformance/stdlib-vectors
go run ./cmd/rest-serve app.dslb host.schema.json
Inputs and outputs
- Input: compiled .dslb v6 byte slices, exact embedded schema JSON bytes, and optional LMCODE_INVOCATION_FILE manifest.
- Output: mutated Go pointers in Context, HTTP/1.1 messages on stdout via rest.Controller, or a terminal LMCODE_RETURN envelope.
- Strings: Go string values carry raw bytes without UTF-8 normalization; index by byte or convert to []byte.
Safety rules
- Avoid iterating raw VM strings with Go range loops (which decode UTF-8 runes and replace invalid bytes with U+FFFD); index bytes directly.
- Perform integer math via uint64 conversions when two's-complement wrapping is required on edge values.
- Pass lmcode.Dry(fn) only for read-only preview callbacks so dry runs never mutate external state.
Worked examples
reg := lmcode.NewRegistry()
_ = reg.Function("add_tax", []string{"int"}, "int", func(a []lmcode.Value) (lmcode.Value, error) {
return lmcode.Int(a[0].Int + 15), nil
})
prog, err := lmcode.Load(bytecodeBytes, schemaBytes, reg)
if err != nil {
lmcode.ExitIfError("load", err)
}
Errors and exit codes
| Code | Phase | Exit | Condition |
|---|---|---|---|
| LOAD_BAD_BYTECODE | load | 3 | Malformed DSLB v6 header, bad magic or version, truncated section, invalid opcode, or stack depth violation |
| LOAD_BAD_SCHEMA | load | 3 | Host schema JSON fails dsl.schema 2 validation or declares an invalid result contract |
| LOAD_SCHEMA_MISMATCH | load | 3 | 32-byte SHA-256 schema hash in DSLB v6 header does not match exact host schema bytes |
| LOAD_UNBOUND | load | 3 | Bytecode imports a context, function, or method signature not registered in the host Registry |
| RUN_ERROR | run | 3 | VM division or remainder by zero, or loop-free operand stack underflow |
| RUN_HOST | run | 3 | Host callback failure, invalid encoding, expired collection handle, or REST route validation failure |
| APP_FAIL | app | 4 | Post-run application domain validation failure or output stream write failure |
How to verify
bash scripts/sync-std.sh --verify
bash scripts/sync-rest.sh --verify
CGO_ENABLED=0 go test ./...