lmcode-cpp

lmcode-cpp is the experimental C++17 header-only runtime for lmscript _lmcode_ bytecode: loader, verifier, VM and host registry in include/dslvm.hpp. Every default Registry provides the 226 signatures of the lmcode_std_v3 standard catalog, including the standard REST and CLI interfaces.
Install and build
git clone https://github.com/lmctl-ai/lmcode-cpp
g++ -std=c++17 -Ilmcode-cpp/include host.cpp -o host
make test
make conformance
There is no compiled library and no third-party dependency. The runtime reads bytecode version 6 only; use a matching lmscript compiler from the published @lmctl-ai/lmctl npm package.
Host protocol
| Command | Effect |
|---|---|
| HOST --lmcode-schema --json | Prints the host schema JSON that lmscript compiles against. |
| HOST --lmcode-signatures | Prints the registry's sorted canonical signatures, host and standard. |
| HOST --lmcode FILE.dslb | Loads and runs a compiled program file. |
| lmscript --lmcode-signatures schema.json | Compiler-side signatures to diff against the host. |
| Exit codes | 0 success, 2 command-line failure, 3 load or run failure, 4 application failure. |
In lmscript a block is written prog = _lmcode_ cli="HOST" install="github:lmctl-ai/HOST@latest"; ... end _lmcode_ and executed with r = run_lmcode(prog), which returns ok and result.
C++ API quick reference
| Name | Role |
|---|---|
| dslvm::Registry | Declares context, function and method bindings with schema type strings; includes the standard catalog unless built with StdMode::Disabled. |
| Registry::context, method, function | Bind host context variables, methods and functions. |
| Registry::signatures() | Sorted canonical signatures for the parity check. |
| dslvm::Program::load(bytecode, schema, registry) | Verifies the file against the exact schema bytes; refuses before anything runs. |
| Program::run(context, registry) | Runs the body. |
| Program::entries(), Program::call(i, context, registry, args) | Lists and invokes annotated rule entries, the mechanism behind REST and CLI handlers. |
| dslvm::Context | Maps context names to live host objects; set_dry(true) selects dry execution. |
| dslvm::Value | INT, FLOAT, STR, BOOL or OBJ; Value::none() for void. |
| dslvm::Error | Load, run and host failures. |
Minimal host
#include "dslvm.hpp"
struct Greeter { std::string last; };
int main(int argc, char** argv) {
dslvm::Registry reg;
reg.context("g", "Greeter");
reg.method("Greeter", "say", {"string"}, "void", [](void* self, dslvm::Args& a) {
static_cast<Greeter*>(self)->last = a[0].s; return dslvm::Value::none(); });
dslvm::Program program;
try { program = dslvm::Program::load(dslvm::read_file(argv[1]), dslvm::read_file(argv[2]), reg); }
catch (const dslvm::Error& e) { std::cerr << "refused: " << e.what() << "\n"; return 3; }
Greeter greeter;
dslvm::Context ctx; ctx.set("g", &greeter);
try { program.run(ctx, reg); } catch (const dslvm::Error& e) { std::cerr << "dsl error: " << e.what() << "\n"; return 3; }
std::cout << greeter.last << "\n";
}
Standard catalog and REST/CLI interfaces
The canonical std/lmcode-std.schema.json (lmcode_std_v3, std.lock version 3) holds 226 signatures in ten groups: string, math, collections, containers, json, encoding, file, result, testing and rest. Hosts do not register these; keep host schemas limited to host calls.
| Item | Names |
|---|---|
| Interfaces, each (RestExchange) -> void | RestGet, RestPost, RestPut, RestDelete, RestPatch, RestHead, RestOptions, RestHandler, CliCommand, CliOption |
| Functions | rest_config(string, string) -> void, rest_route(string, string, string) -> void, rest_serve() -> void, rest_stop() -> void, rest_cli(StrList) -> string |
| RestExchange request methods | method, path, query, has_query, param, header, has_header, body |
| RestExchange response methods | status, set_header, send, json |
| RestExchange shared state methods | get, set, increment |
| Route templates | {param} and {rest...}, or :param and :rest... |
Requests are HTTP/1.1 read from an input stream and answered on an output stream; there is no network listener. rest_cli is a stateless CLI mode that dispatches an argument list to options, commands and REST routes.
More
- Reference: C++ API, flags, exit codes, standard groups, REST and CLI interfaces
- Skill page for assistants writing host bindings
- User guide
- Tutorial
- Source repository, with sibling SDKs lmcode-rust, lmcode-go, lmcode-csharp and lmcode-java