lmcode-rust-sample skill

Use lmcode-rust-sample as a verified blueprint for embedding lmcode-rust (vendor/lmcode-rust/dslvm) in a Rust (stable, zero crates.io dependencies) host application with schema discovery, R49 rule entries, dry mode, and LMCODE_RETURN framing.

Purpose

Demonstrate a complete, byte-pinned Rust (stable, zero crates.io dependencies) host application that exposes a 45-signature Shop/Ledger domain to DSLB v6 bytecode and passes the shared sample suite.

When to use it

Use lmcode-rust-sample when learning how to bind Rust (stable, zero crates.io dependencies) domain objects, overloaded methods, operators, R49 rule entries, and LMCODE_RETURN result envelopes with lmcode-rust (vendor/lmcode-rust/dslvm).

Install

Clone lmctl-ai/lmcode-rust-sample and run ./test.sh with Rust (stable, zero crates.io dependencies), Python 3, Node 24, and a current lmscript from @lmctl-ai/lmctl.

Commands

git clone https://github.com/lmctl-ai/lmcode-rust-sample.git
cd lmcode-rust-sample
python3 scripts/sync.py check
cargo build --release
./test.sh
./target/release/lmcode-rust-sample --version
./target/release/lmcode-rust-sample --lmcode-schema --json
./target/release/lmcode-rust-sample --lmcode-signatures
./target/release/lmcode-rust-sample --lmcode sample-suite/bytecode/001-literals.dslb

Inputs and outputs

Safety rules

Worked examples

program = _lmcode_ schema="sample-suite/sample.dsl.json";
  ledger.record(shop.total());
  $return.balance = ledger.balance();
end _lmcode_
r = run_lmcode(program, {command:[ARGV[0], "--lmcode", "$DSLFILE"]});
require(r.ok, "sample host execution failed");

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
RUN_HOSTrun3Host callback failure, invalid encoding, or expired collection handle
APP_FAILapp4Post-run application domain validation failure

How to verify

./test.sh