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

Safety rules

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, &reg)?;
let contract = ResultContract::from_schema(std::str::from_utf8(schema_bytes)?)?;
results.select(0, &reg, &mut ctx, contract)?;
prog.run(&mut ctx, &reg)?;
results.complete(0)?;
let code = results.write_frame(&mut std::io::stdout().lock());
std::process::exit(code);

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
bash scripts/sync-rest.sh --verify
cargo test
lmscript test.lms