lmcode-rust skill
Embed the dslvm Rust crate into a native binary to expose typed Rust domain objects, lmcode_std_v3, and REST/CLI endpoints to compiled lmcode bytecode.
Purpose
Build dependency-free Rust host executables that verify and run DSLB v6 bytecode, dispatch R49 rule entries and REST/CLI routes, and emit LMCODE_RETURN result envelopes.
When to use it
Use lmcode-rust when authoring or maintaining a Rust CLI or service host that executes schema-bound lmcode chunks with zero external crates.
Install
Add the dslvm crate from lmctl-ai/lmcode-rust as a path or git dependency in Cargo.toml using a stable Rust toolchain.
Commands
cargo build --release
cargo test
cargo run --bin dsl-conformance -- conformance/vectors
cargo run --bin dsl-conformance -- --std conformance/stdlib-vectors
cargo run -p dslvm --bin rest-serve -- app.dslb host.schema.json
Inputs and outputs
- Input: compiled DSLB v6 bytecode slice, embedded dsl.schema: 2 JSON bytes, and optional LMCODE_INVOCATION_FILE manifest.
- Output: host mutations on Context arena objects, HTTP/1.1 responses on stdout in rest_serve mode, or a terminal LMCODE_RETURN frame.
- Strings: ByteString values preserve arbitrary raw bytes including interior NUL and invalid UTF-8.
Safety rules
- Embed the exact schema JSON bytes with include_bytes! so Program::load verifies the compile-time SHA-256 hash.
- Use wrapping i64 arithmetic (wrapping_add, wrapping_sub, wrapping_mul, wrapping_neg) in host callbacks to match VM integer semantics.
- Use function_with_dry or method_with_dry so dry-mode invocations skip mutating callbacks unless an explicit preview closure is supplied.
Worked examples
use dslvm::{Context, InvocationResults, Program, Registry, ResultContract, Value};
let mut reg = Registry::new();
reg.function("double_it", &["int"], "int", |_ctx, args| {
Ok(Value::Int(args[0].as_int().wrapping_mul(2)))
})?;
let files = vec!["chunk.dslb".to_string()];
let mut results = InvocationResults::from_command(&files)?;
let mut ctx = Context::new();
ctx.set_dry(results.dry());
let prog = Program::load(&bytecode, schema_bytes, ®)?;
let contract = ResultContract::from_schema(std::str::from_utf8(schema_bytes)?)?;
results.select(0, ®, &mut ctx, contract)?;
prog.run(&mut ctx, ®)?;
results.complete(0)?;
let code = results.write_frame(&mut std::io::stdout().lock());
std::process::exit(code);
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
cargo test
lmscript test.lms