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

NameRole
dslvm::RegistryHolds 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::ContextLive host objects for one run: set(name, pointer); set_dry(true) selects dry execution.
dslvm::ValueINT (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::ErrorThrown 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::VERSIONThe 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.

FlagEffect
HOST --lmcode-schema --jsonPrints the host schema JSON the compiler binds to.
HOST --lmcode-signaturesPrints Registry::signatures(), one sorted canonical signature per line.
HOST --lmcode FILE.dslbLoads and runs a compiled program file.
lmscript --lmcode-signatures schema.jsonCompiler side of the parity check; diff its output against the host's.

Exit codes

CodeMeaning
0Success.
2Controlled command-line failure.
3Bytecode load or run failure.
4Application 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.

GroupFunction signaturesMethod signaturesNames
string160str_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
math160math_abs, math_ceil, math_floor, math_max, math_min, math_pow, math_round, math_sqrt (overloaded)
collections532str_list, int_list, float_list, str_map, str_split; types StrList, IntList, FloatList, StrMap
containers1180int_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
json211json_parse, template_render; type Json
encoding40str_base64_encode, str_base64_decode, str_hex_encode, str_hex_decode
file50file_read, file_write, file_append, file_exists, file_lines
result240lmcode_return_set, lmcode_return_put, lmcode_return_null, lmcode_return_put_null (overloaded)
testing20print, assert_close
rest515rest_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.

InterfaceSignatureUse
RestGetRestGet(RestExchange) -> voidHandler for GET requests.
RestPostRestPost(RestExchange) -> voidHandler for POST requests.
RestPutRestPut(RestExchange) -> voidHandler for PUT requests.
RestDeleteRestDelete(RestExchange) -> voidHandler for DELETE requests.
RestPatchRestPatch(RestExchange) -> voidHandler for PATCH requests.
RestHeadRestHead(RestExchange) -> voidHandler for HEAD requests.
RestOptionsRestOptions(RestExchange) -> voidHandler for OPTIONS requests.
RestHandlerRestHandler(RestExchange) -> voidGeneral handler bound to a route with rest_route.
CliCommandCliCommand(RestExchange) -> voidCommand dispatched by rest_cli.
CliOptionCliOption(RestExchange) -> voidOption handler dispatched by rest_cli.

Functions

SignatureMeaning
rest_config(string, string) -> voidStores 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) -> voidRegisters 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() -> voidMarks 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() -> voidStops serving.
rest_cli(StrList) -> stringStateless 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

MethodMeaning
method() -> stringRequest method.
path() -> stringRequest path.
query(string) -> stringQuery parameter value, or empty when absent.
has_query(string) -> boolWhether the query parameter is present.
param(string) -> stringRoute template parameter value, or empty when absent.
header(string) -> stringRequest header value; repeated headers are joined with a comma and a space.
has_header(string) -> boolWhether the request header is present.
body() -> stringRequest body.
status(int) -> voidSets the response status; values outside 200..599 are an error.
set_header(string, string) -> voidSets a response header. Content-Length, Connection and Transfer-Encoding are managed by the server and refused.
send(string) -> voidSets the response body.
json(string) -> voidSets the response body and Content-Type application/json.
get(string) -> stringReads a value from the shared server state, or empty when absent.
set(string, string) -> voidWrites a value to the shared server state.
increment(string) -> intIncrements a counter in the shared server state and returns it.

See also the quick reference, the guide and the repository.