lmcode-csharp skill
Use lmcode-csharp to embed the DSLB v6 bytecode runtime, 226-signature standard catalog, and REST/CLI controller into .NET 8 and NativeAOT C# hosts.
Purpose
Build reflection-free, NativeAOT-ready C# host applications that verify and execute lmcode DSLB v6 programs and emit LMCODE_RETURN envelopes.
When to use it
Use lmcode-csharp when authoring a .NET 8 application or NativeAOT binary that exposes C# domain objects or REST/CLI routes to compiled lmcode bytecode.
Install
Reference src/LmCode/LmCode.csproj with dotnet add reference or vendor the src/LmCode directory in a .NET 8 SDK project.
Commands
dotnet build -c Release -warnaserror
dotnet test
dotnet run --project conformance/LmCode.Conformance -- conformance/vectors
dotnet run --project conformance/LmCode.Conformance -- conformance/stdlib-vectors
dotnet publish examples/Greeter -r linux-x64 -c Release -p:PublishAot=true
Inputs and outputs
- Input: byte[] DSLB v6 bytecode, byte[] dsl.schema: 2 JSON, and optional LMCODE_INVOCATION_FILE manifest.
- Output: mutated C# objects in Context, HTTP/1.1 responses over stdio via RestController, or a terminal LMCODE_RETURN frame.
- Strings: VmString stores immutable raw bytes accessed via .Span; decode UTF-8 with .ToString() only when text is required.
Safety rules
- Never round-trip arbitrary VmString byte payloads through C# UTF-16 string unless UTF-8 validity is guaranteed.
- Keep object handles (ObjRef) scoped to their owning Context and do not share mutable handles across concurrent runs.
- Use Registry.Dry(callback) to provide safe dry-mode previews while leaving mutating callbacks unslotted.
Worked examples
var registry = new Registry();
registry.Function("greet", ["string"], "void", (_, values) =>
{
Console.Error.WriteLine("Hello, " + values[0].AsStr().ToString());
return Value.None;
});
var program = LmCode.Program.Load(File.ReadAllBytes(path), schemaBytes, registry);
var context = new Context();
program.Run(context, registry);
Errors and exit codes
| Code | Phase | Exit | Condition |
|---|---|---|---|
| LOAD_BAD_BYTECODE | load | 3 | Malformed DSLB v6 header, bad magic or version, truncated section, invalid opcode, or stack depth violation |
| LOAD_BAD_SCHEMA | load | 3 | Host schema JSON fails dsl.schema 2 validation or declares an invalid result contract |
| LOAD_SCHEMA_MISMATCH | load | 3 | 32-byte SHA-256 schema hash in DSLB v6 header does not match exact host schema bytes |
| LOAD_UNBOUND | load | 3 | Bytecode imports a context, function, or method signature not registered in the host Registry |
| RUN_ERROR | run | 3 | VM division or remainder by zero, or loop-free operand stack underflow |
| RUN_HOST | run | 3 | Host callback failure, invalid encoding, expired collection handle, or REST route validation failure |
| APP_FAIL | app | 4 | Post-run application domain validation failure or output stream write failure |
How to verify
bash scripts/sync-std.sh --verify
bash scripts/sync-rest.sh --verify
dotnet test
lmscript test.lms