Runtime
Source: detlef.mjs:520
An interpreter instance and the host callbacks and packages installed in it.
Create with new Runtime() after createAPI(). No stdlib is installed initially. Must be disposed explicitly; JavaScript garbage collection does not replace disposal or break every host-callback reference cycle.
Alias: Runtime
Constructor
new Runtime(): RuntimeInstance Methods
loadPackage(
bytes: ArrayBuffer | Uint8Array,
): Promise.<PackageInfo>
Load a separately compiled Wasm artifact from a package archive.
Downloads and file access belong to the host. A failed initializer may have registered definitions; its instance is retained and cannot be loaded again under the same package name. Loading must finish before another load or disposal.
Parameters
bytes(ArrayBuffer | Uint8Array) — Complete .dtfpkg archive.
Returns
Promise.<PackageInfo>— Package name and version after initialization.
Throws
Error— Malformed archive, duplicate package, incompatible protocol/imports, or initialization failure.
withAccess(callback: SetupCallback): *
Invoke a synchronous setup callback with borrowed Access.
Values created here are host-owned and must be disposed, even though access expires on callback return. A Promise result is rejected. Reentry through this method is rejected; inside a Control use the supplied Access instead.
Parameters
callback(SetupCallback) — Synchronous setup operation.
Returns
*— The callback result.
Throws
Error— Callback failure, Promise result, or busy/disposed runtime.
execute(source: string): Value
Evaluate source and return the last evaluation. The result must be disposed. Calling this through a captured runtime inside an eager Function is rejected.
Parameters
source(string) — DETLEF source.
Returns
Value— Host-owned result wrapper; callback use follows the active callback scope.
Throws
Error— Parsing/evaluation failure or unavailable context.
installStdlib(options?: IOOptions): undefined
Install stdlib operations with synchronous I/O. Equivalent to Access.installStdlib() in a context access.
Parameters
options(IOOptions, optional) — Synchronous input and output callbacks.
Returns
undefined— No value.
Throws
Error— Installation failure or invalid callback use.
registerFunction(
name: string,
types: Array.<TypeSpec>,
callback: FunctionCallback,
options?: Object,
): undefined
Register an eager Function. Equivalent to Access.registerFunction().
Parameters
name(string) — Callable name.types(Array.<TypeSpec>) — Fixed parameter types in declaration order.callback(FunctionCallback) — Synchronous host implementation.options(Object, optional) — Signature options.options.variadic(TypeSpec, optional) — Type accepted by each additional argument.
Returns
undefined— No value.
Throws
Error— Invalid types, signature conflicts, expired access, or an unavailable runtime.
registerRecord(
name: string,
fields: Array.<RecordField>,
): undefined
Define a record type. Equivalent to Access.registerRecord().
Parameters
name(string) — Record type name.fields(Array.<RecordField>) — Fields in declaration order; field types are named types.
Returns
undefined— No value.
Throws
Error— Invalid fields, unknown field types, or an already defined record.
registerControl(
name: string,
callback: ControlCallback,
): undefined
Register a lazy Control. Equivalent to Access.registerControl().
Parameters
name(string) — Callable name.callback(ControlCallback) — Synchronous host implementation.
Returns
undefined— No value.
Throws
Error— Invalid registration, expired access, or an unavailable runtime.
dispose(): undefined
Release package-retained values, runtime handles, callbacks, and package instances.
Must be called explicitly. Repeated calls after successful disposal have no effect. Disposal while a callback or package load is active is rejected. All remaining Value and access wrappers become unusable.
Returns
undefined— No value.
Throws
Error— Active runtime/package load or package cleanup failure.