cpp-dsl-sdk 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.

String helpers are ordinary host functions, not VM built-ins. To add them, copy the functions object from stdlib/string.schema-fragment.json into the host schema, include stdlib/string.hpp, and call dslvm::stdlib::register_string(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 --dsl-signatures (registry list). A host can accept multiple --dsl 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