lmcode-java skill
Use lmcode-java to embed the DSLB v6 verifier and virtual machine into Java 21 or GraalVM Native Image host applications.
Purpose
Provide a JDK-only bytecode loader, stack VM, 226-signature standard library, stdio REST/CLI controller, and invocation result framer for JVM and native executables.
When to use it
Use lmcode-java when building a Java, Kotlin, or Scala host application or GraalVM native binary that executes schema-bound lmcode programs.
Install
Build with JDK 21 and Maven 3.6.3+ (mvn -q verify), or vendor src/main/java/io/lmctl/lmcode directly into your project.
Commands
mvn -q verify
./scripts/build-native.sh
lmctl autorun examples/byte_strings.lms
Inputs and outputs
- Input: byte[] bytecode (DSLB v6), byte[] schema (dsl.schema: 2), and optional LMCODE_INVOCATION_FILE manifest.
- Output: mutated Java objects in Context, HTTP/1.1 responses on stdout via RestController, or a terminal LMCODE_RETURN frame.
- Strings: VmString wraps an immutable byte[] so arbitrary bytes and interior NULs never corrupt through UTF-16 String decoding.
Safety rules
- Use VmString.bytes() for raw byte payloads rather than converting arbitrary binary strings through java.lang.String.
- Use Java long arithmetic (+, -, *, unary -) for two's-complement int64 wrapping and Formatting.formatG15 for VM float text.
- Supply Registry.dry(callback) only for side-effect-free preview logic when dry mode is active.
Worked examples
Registry registry = new Registry();
registry.function("greet", List.of("string"), "string", (ctx, self, args) ->
Value.ofString(VmString.fromString("hello " + args[0].asString().toString()))
);
Program program = Program.load(bytecodeBytes, schemaBytes, registry);
Context 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
mvn -q verify
lmscript test.lms