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
- Input: compiled .dslb v6 bytecode files from sample-suite/bytecode/, embedded sample.dsl.json schema, and optional LMCODE_INVOCATION_FILE manifest.
- Output: print trace lines, entry NAME = VALUE lines, tagged host_summary JSON diagnostic, and terminal LMCODE_RETURN_BEGIN / END frame.
- Locks: sdk.lock and suite.lock pinning every vendored SDK and corpus byte by commit SHA and SHA-256.
Safety rules
- Verify sdk.lock and suite.lock before building so vendored SDK and corpus files never drift silently.
- Preserve raw byte strings across Ledger.note and JSON diagnostics without lossy UTF-8 replacement.
- Check LMCODE_INVOCATION_FILE dry mode before seeding or mutating external state so dry runs remain side-effect-free.
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
| 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 |
| RUN_HOST | run | 3 | Host callback failure, invalid encoding, or expired collection handle |
| APP_FAIL | app | 4 | Post-run application domain validation failure |
How to verify
./test.sh