lmcode-cpp reference
Reference tables for the lmcode-cpp SDK: the C++ host API in include/dslvm.hpp, the command-line conventions a host built on it follows, exit codes, the lmcode_std_v3 standard catalog (226 canonical signatures, std.lock version 3) and the standard REST and CLI interfaces. Facts come from the repository README, std/lmcode-std.schema.json, the stdlib schema fragments and stdlib/rest.hpp.
C++ host API
| Name | Role |
|---|---|
| dslvm::Registry | Holds the host's context declarations, functions and methods, declared with the schema's type strings. A default Registry also installs the standard catalog. |
| Registry(dslvm::StdMode::Disabled) | Creates a registry without the standard catalog; group binders such as dslvm::stdlib::register_string can then be applied manually. |
| Registry::context(name, type) | Declares a schema context variable and its host type. |
| Registry::method(type, name, params, returns, callback) | Binds a method; the callback receives void* self and dslvm::Args&. Overloads with distinct parameter tuples are allowed; the same tuple twice is refused. |
| Registry::function(name, params, returns, callback) | Binds a host function; the callback receives dslvm::Args&. |
| Registry::signatures() | Returns the sorted canonical signature strings, including the built-in standard, for comparison with lmscript --lmcode-signatures. |
| Registry::set_std_output(stream) | Redirects standard-library output, for example to std::cerr while a REST program owns stdout. |
| dslvm::Program::load(bytecode, schema, registry) | Verifies bytecode version 6 against the exact schema bytes and the registry; refuses the file before anything runs. |
| Program::run(context, registry) | Executes the body of the chunk. |
| Program::entries() | Rule entries in source order; each Program::Entry has name, annotation, iface, returns and params. |
| Program::call(i, context, registry, args) | Runs rule entry i with the given arguments; returns Value::none() for a void interface. |
| dslvm::Context | Live host objects for one run: set(name, pointer); set_dry(true) selects dry execution. |
| dslvm::Value | INT (int64), FLOAT (binary64), STR, BOOL and OBJ (host pointer plus schema type name); constructors include Value::integer, Value::string, Value::boolean and Value::none. |
| dslvm::Error | Thrown by load and run, and by host code to report a run-time failure. |
| dslvm::dry(callback) | Marks a callback for the optional dry slot of a registration. |
| dslvm::read_file(path) | Reads a bytecode or schema file as bytes. |
| dslvm::VERSION | The bytecode format version the SDK reads, currently 6; every other version is refused. |
Host CLI flags
lmcode-cpp is a header, not a program. Hosts built on it follow the same host protocol, which lmscript drives when a block names the host with cli= and is executed with run_lmcode.
| Flag | Effect |
|---|---|
| HOST --lmcode-schema --json | Prints the host schema JSON the compiler binds to. |
| HOST --lmcode-signatures | Prints Registry::signatures(), one sorted canonical signature per line. |
| HOST --lmcode FILE.dslb | Loads and runs a compiled program file. |
| lmscript --lmcode-signatures schema.json | Compiler side of the parity check; diff its output against the host's. |
Exit codes
| Code | Meaning |
|---|---|
| 0 | Success. |
| 2 | Controlled command-line failure. |
| 3 | Bytecode load or run failure. |
| 4 | Application failure. |
Standard groups (lmcode_std_v3)
The canonical std/lmcode-std.schema.json is named lmcode_std_v3 and holds 226 signatures: 88 function signatures and 138 method signatures over 17 types, plus 10 interfaces. The table counts each schema fragment in stdlib; the fragment counts sum to 228 while the merged canonical schema holds 226.
| Group | Function signatures | Method signatures | Names |
|---|---|---|---|
| string | 16 | 0 | str_starts_with, str_ends_with, str_contains, str_lower, str_upper, str_substr, str_len, str_match, str_find, str_replace, str_trim, str_repeat, str_to_int, str_is_int, str_to_float, str_is_float |
| math | 16 | 0 | math_abs, math_ceil, math_floor, math_max, math_min, math_pow, math_round, math_sqrt (overloaded) |
| collections | 5 | 32 | str_list, int_list, float_list, str_map, str_split; types StrList, IntList, FloatList, StrMap |
| containers | 11 | 80 | int_map, float_map, and stack, queue and pq constructors for str, int and float; types IntMap, FloatMap, StrStack, IntStack, FloatStack, StrQueue, IntQueue, FloatQueue, StrPQ, IntPQ, FloatPQ |
| json | 2 | 11 | json_parse, template_render; type Json |
| encoding | 4 | 0 | str_base64_encode, str_base64_decode, str_hex_encode, str_hex_decode |
| file | 5 | 0 | file_read, file_write, file_append, file_exists, file_lines |
| result | 24 | 0 | lmcode_return_set, lmcode_return_put, lmcode_return_null, lmcode_return_put_null (overloaded) |
| testing | 2 | 0 | print, assert_close |
| rest | 5 | 15 | rest_config, rest_route, rest_serve, rest_stop, rest_cli; type RestExchange |
REST and CLI interfaces
The former lmcode_std_rest_v1 module is part of lmcode_std_v3. It serves HTTP/1.1 requests read from an input stream and written to an output stream; there is no network listener. Handlers are annotated rule entries that implement one of ten standard interfaces, each with the shape (RestExchange) -> void, and they run strictly one at a time.
| Interface | Signature | Use |
|---|---|---|
| RestGet | RestGet(RestExchange) -> void | Handler for GET requests. |
| RestPost | RestPost(RestExchange) -> void | Handler for POST requests. |
| RestPut | RestPut(RestExchange) -> void | Handler for PUT requests. |
| RestDelete | RestDelete(RestExchange) -> void | Handler for DELETE requests. |
| RestPatch | RestPatch(RestExchange) -> void | Handler for PATCH requests. |
| RestHead | RestHead(RestExchange) -> void | Handler for HEAD requests. |
| RestOptions | RestOptions(RestExchange) -> void | Handler for OPTIONS requests. |
| RestHandler | RestHandler(RestExchange) -> void | General handler bound to a route with rest_route. |
| CliCommand | CliCommand(RestExchange) -> void | Command dispatched by rest_cli. |
| CliOption | CliOption(RestExchange) -> void | Option handler dispatched by rest_cli. |
Functions
| Signature | Meaning |
|---|---|
| rest_config(string, string) -> void | Stores a configuration key and value. The keys prefix and base_path set the route prefix; max_body_bytes sets the request body limit when given a positive decimal number. Refused once rest_serve has been called. |
| rest_route(string, string, string) -> void | Registers a route. Path templates accept {param} and {rest...} as well as :param and :rest... placeholders. Routes are frozen once rest_serve has been called. |
| rest_serve() -> void | Marks the program as serving: after the body finishes, the host serves the input stream until end of input, rest_stop or a framing error. A second call is an error. |
| rest_stop() -> void | Stops serving. |
| rest_cli(StrList) -> string | Stateless CLI mode: dispatches an argument list to options, commands and REST routes without resetting the outer run state. The method defaults to GET; --method or -X sets it, --body or -d sets the body, positional words form the path, and words after -- are joined with spaces as the body. |
RestExchange methods
| Method | Meaning |
|---|---|
| method() -> string | Request method. |
| path() -> string | Request path. |
| query(string) -> string | Query parameter value, or empty when absent. |
| has_query(string) -> bool | Whether the query parameter is present. |
| param(string) -> string | Route template parameter value, or empty when absent. |
| header(string) -> string | Request header value; repeated headers are joined with a comma and a space. |
| has_header(string) -> bool | Whether the request header is present. |
| body() -> string | Request body. |
| status(int) -> void | Sets the response status; values outside 200..599 are an error. |
| set_header(string, string) -> void | Sets a response header. Content-Length, Connection and Transfer-Encoding are managed by the server and refused. |
| send(string) -> void | Sets the response body. |
| json(string) -> void | Sets the response body and Content-Type application/json. |
| get(string) -> string | Reads a value from the shared server state, or empty when absent. |
| set(string, string) -> void | Writes a value to the shared server state. |
| increment(string) -> int | Increments a counter in the shared server state and returns it. |
See also the quick reference, the guide and the repository.