Skip to main content

Module prelude

Module prelude 

Source
Expand description

The prelude’s implementation: every built-in method, static, constant, and vtable as Rust host fns, registered under submilli:prelude.

Each method is declared (via [declare_method]) as a value symbol whose mangled name is the method’s dispatch key (e.g. submilli:prelude#String#repeat) — the same string is the linker field the host fn registers under, so codegen’s method lookup resolves straight to the Rust impl. codegen::prelude::merged_prelude_declaration folds these value symbols into the single submilli:prelude package next to the type surface; selected top-level bindings (isNaN, NaN, …) are loaded into user scope by the typechecker.

Re-exports§

pub use declaration::MODULE_NAME;
pub use declaration::cached_runtime_package_declarations;
pub use declaration::prelude_package_declaration;

Modules§

array
The submilli array’s operations — the Rust port of the prelude’s Array and ArrayConstructor methods.
bigint
The Rust port of the prelude’s BigInt instance-method surface (toString(radix?), toJson). The arbitrary-precision compute lives in [crate::runtime::prelude::bigint::ops] (num-bigint); this module is the wasmtime boundary that reads the $bigint receiver and marshals the $string result.
boolean
The Rust port of the prelude’s Boolean surface — toString / toJson, both "true" / "false". The receiver is the unboxed i32 (0 = false).
declaration
The prelude’s declaration: the full typed interface/type surface plus the cached package assembly codegen and the typechecker consume.
map
The submilli Map<K, V> — the Rust port of the prelude’s hand-written Wasm hashtable (codegen/prelude/map.rs).
math
The Rust port of the prelude’s built-in Math namespace.
number
The Rust port of the prelude’s Number / NumberConstructor surface.
object
The Rust port of the prelude’s ObjectConstructor statics — Object.keys/values/entries/hasOwn/is — reading the $ObjectShape field-name/field-value arrays directly. Every per-arity object subtype subtypes $ObjectShape, so one matches_ty test covers them all; any other value takes the “no fields” path ([]/false), and a null receiver throws a catchable Error, matching the Wasm bodies in codegen/prelude/object_shape.rs.
regex
The Rust port of the prelude’s hand-written Wasm RegExp / RegExpMatch / RegExpConstructor glue (codegen/prelude/regex.rs).
set
The submilli Set<T> — the Rust port of the prelude’s hand-written Wasm hashset (codegen/prelude/set.rs).
string
The submilli string and its operations — the Rust port of the prelude’s String methods.
temporal
Rust implementations of the prelude’s Temporal surface.
textcodec
Stateless TextEncoder / TextDecoder, ported off the Wasm prelude. The instances carry no state — new TextEncoder() builds an empty $ObjectShape with the host generic object vtable, so JSON.stringify yields {} and toString yields [object Object] (parity with the old dedicated vtable). encode bridges the $string UTF-16 ABI to the $Uint8Array byte ABI; decode does the reverse. UTF-8 only: decode throws a catchable TypeError on invalid UTF-8. All marshalling and registration live in install.
uint8array
The submilli Uint8Array operations — the Rust port of the prelude’s Uint8Array and Uint8ArrayConstructor surface. Bytes live as a Vec<u8>; the higher-order methods box each byte into a $boxed_number before calling back into a guest closure. The $Uint8Array marshalling and host-fn registration live in install; the shared Closure handles callbacks.

Functions§

install
Register every ported host fn. Store-less, so it goes into the reusable base linker; the returned $string/$Array values read the prelude’s vtables at call time, not here. The store-bound vtable globals install separately via [install_vtables].
package_declaration
The codegen-facing declaration: the value symbols that route ported methods to their Rust impls (see the module doc).