lmcode-cpp user guide

Overview

The SDK is a header-only C++17 loader, structural verifier, registry and VM. lmscript compiles source against a JSON schema; the host implements that schema in C++ and supplies its exact bytes to Program::load. The SDK does not parse or interpret schema JSON.

Install

Copy include/dslvm.hpp into your source tree and include it, or pin a repository revision and verify the header hash. Compile as C++17. No separate library is built and the header has no third-party dependencies. Use the matching published lmscript compiler.

Concepts

Registry
Declares context types, functions and methods with exact argument and return types, and stores the C++ callbacks.
Program::load
Loads a bytecode byte string and exact schema byte string, verifies format, schema binding and imports against a registry, then returns a runnable program.
Context
Maps schema context variable names to live host-owned object pointers.
Value
Carries INT (int64), FLOAT (binary64), STR, BOOL, VOID or OBJ (a host pointer and schema type name).
Ownership
The host owns objects referenced by context and object values. Keep them alive and stable throughout every call that can use them.

Reference

Typical embedding sequence:

dslvm::Registry registry;
registry.context("scene", "Scene");
registry.method("Scene", "render", {"string"}, "void", callback);
auto schema = dslvm::read_file("schema.json");
auto program = dslvm::Program::load(dslvm::read_file("scene.dslb"), schema, registry);
dslvm::Context context;
context.set("scene", &scene);
program.run(context, registry);

Callbacks receive dslvm::Args& and return a dslvm::Value. Void callbacks return Value::none(). Throw dslvm::Error for a host run failure. The standard command-line result helpers print one JSON line: report_ok exits 0, report_error exits 3 for load/run errors, and report_app_failure exits 4. Compiler failures normally exit 2.

Format compatibility is one-version-only. The current loader accepts bytecode v5 and refuses any other version; compiler, SDK and host must move together when the format changes.

The standard function schema and signatures are included by each Registry. Standard functions need no host registration. Declare and bind only functions and methods that belong to your host.

The canonical standard schema is std/lmcode-std.schema.json and is named lmcode_std_v3 and contains 226 signatures, including the standard REST and CLI module: ten interfaces (RestGet, RestPost, RestPut, RestDelete, RestPatch, RestHead, RestOptions, RestHandler, CliCommand, CliOption), the functions rest_config, rest_route, rest_serve, rest_stop and rest_cli, and 15 RestExchange methods, all listed in the reference. Keep host-owned schemas limited to host calls; do not copy standard declarations into them. The compiler input still needs the canonical standard declarations merged into the effective schema, as described by the SDK README, and the host must load the exact schema bytes used for compilation. Every dslvm::Registry includes standard functions by default. Registry(StdMode::Disabled) opts out.

lmcode-cpp is the C++ runtime in a five-language family. Each language uses the standard catalog by default and offers an opt-out registry form:

Language SDKDefault and opt-out registry
lmcode-cppEvery dslvm::Registry includes standard functions. Registry(StdMode::Disabled) opts out.
lmcode-rustRegistry::new() enables the catalog. Registry::without_std() opts out.
lmcode-goNewRegistry() enables the catalog. NewRegistryWithoutStd() opts out.
lmcode-csharpnew Registry() enables the catalog. new Registry(false) creates an empty registry.
lmcode-javaThe default Registry installs the catalog. new Registry(false) creates an empty registry.
FunctionSignatureBehavior
str_starts_withstring, string → boolByte prefix test.
str_ends_withstring, string → boolByte suffix test.
str_containsstring, string → boolByte substring test.
str_lowerstring → stringASCII lowercase.
str_upperstring → stringASCII uppercase.
str_substrstring, int, int → stringClamped byte slice.
str_lenstring → intByte length, including NUL.
str_matchstring, string → boolWhole-string byte glob.
str_findstring, string → intByte offset or −1.
str_replacestring, string, string → stringNon-overlapping replacement.
str_trimstring → stringTrim ASCII whitespace.
str_repeatstring, int → stringRepeat with a 64 MiB catalog bound.
str_to_intstring → intParse signed decimal; invalid input returns 0.
str_is_intstring → boolReports parse validity.
str_to_floatstring → floatParse finite decimal; invalid input returns 0.
str_is_floatstring → boolReports parse validity.

String lengths and indexes are bytes; UTF-8 is not decoded. Case conversion is ASCII-only. The catalog documents bounded replacement/repetition and glob work.

CLI hosts commonly embed one schema and implement --schema (compact summary), --schema --json (exact JSON bytes), and --lmcode-signatures (registry list). A host can accept multiple --lmcode bytecode files and run them in order against that same schema. The SDK itself does not define a CLI.

Tasks

Limits

Bytecode is trusted input. The VM adds no execution budget, recursion limit, stack cap, local cap or string cap; max_stack is only a reservation hint. Hosts should decide whether and where to impose their own input and process limits. Defensive value-kind checks remain in the VM. String catalog helper bounds are library policy, not VM resource limits.

Troubleshooting