lmcode-python skill

Use lmcode-python to embed the DSLB v6 bytecode verifier, 206-signature standard catalog, and opt-in REST controller into Python 3.9+ applications.

Purpose

Execute schema-bound lmcode DSLB v6 bytecode in pure Python with zero third-party runtime dependencies, opt-in REST dispatch, and LMCODE_RETURN framing.

When to use it

Use lmcode-python when authoring a Python CLI, service, or test harness that exposes Python objects or REST endpoints to compiled lmcode chunks.

Install

Install with python -m pip install lmcode-python (or pip install -e . from a checkout) on Python 3.9 or newer.

Commands

python3 -m unittest discover -s tests
python3 scripts/check-verifier-mutations.py
python3 -m lmcode.conformance conformance/vectors
python3 scripts/run-rest-suite.py
python3 -m lmcode.rest app.dslb host.schema.json

Inputs and outputs

Safety rules

Worked examples

from pathlib import Path
from lmcode import Context, Registry, dry, load

registry = Registry()
registry.function(
    "double_it", ["int"], "int",
    lambda ctx, args: (args[0] * 2) & 0xFFFFFFFFFFFFFFFF,
    dry_callback=dry(lambda ctx, args: 0),
)
program = load(Path("chunk.dslb").read_bytes(), Path("host.schema.json").read_bytes(), registry)
program.run(Context(), registry)

Errors and exit codes

CodePhaseExitCondition
LOAD_BAD_BYTECODEload3Malformed DSLB v6 header, bad magic or version, truncated section, invalid opcode, or stack depth violation
LOAD_BAD_SCHEMAload3Host schema JSON fails dsl.schema 2 validation or declares an invalid result contract
LOAD_SCHEMA_MISMATCHload332-byte SHA-256 schema hash in DSLB v6 header does not match exact host schema bytes
LOAD_UNBOUNDload3Bytecode imports a context, function, or method signature not registered in the host Registry
RUN_ERRORrun3VM division or remainder by zero, or loop-free operand stack underflow
RUN_HOSTrun3Host callback failure, invalid encoding, expired collection handle, or REST route validation failure
APP_FAILapp4Post-run application domain validation failure or output stream write failure

How to verify

bash scripts/sync-std.sh --verify
python3 scripts/sync-rest.py --verify
python3 -m unittest discover -s tests
python3 scripts/run-rest-suite.py