heyq02/moonjs/src/util does not have a README file

    Interner

    pub struct Interner {
    // private fields
    }

    Deduplicating string pool.

    Interners are created per owner (each Chunk, each Shape, the compiler itself) rather than as a single global. Keeping them local avoids synchronisation, matches the isolation contract described in design.md §1, and lets strip_debug() drop an entire pool at once when M6 pushes size-sensitive release builds.

    The returned ids are small non-negative integers assigned in the order the strings were first interned. Ids from one Interner are meaningless in another instance.

    Interner::intern

    fn Interner::intern(self : Interner, s : String) -> Int

    Return the id assigned to s, allocating a fresh id the first time the string is seen. Two subsequent intern calls with equal Strings always return the same Int.

    Interner::length

    fn Interner::length(self : Interner) -> Int

    Number of distinct strings currently held. Used mostly by tests; also handy when serialising a pool for debug output.

    Interner::new

    fn Interner::new() -> Interner

    Create an empty interner. HashMap([]) starts at the stdlib default capacity, which is fine for the volumes we handle in M1; larger owners (test262 driver in M6) can wrap this with a pre-sized backing map later.

    Interner::resolve

    fn Interner::resolve(self : Interner, id : Int) -> String

    Look up the string associated with an id. id must have been produced by a prior intern call on the same interner; passing anything else aborts because a bad id is a compiler bug (this API is internal — end-user JS can never reach it, so we prefer a hard abort over a Result on every access).

    SourceLoc

    pub struct SourceLoc {
    line : UInt16
    col : UInt16
    } derive(Eq, Hash,
    Debug
    )

    Source-code location expressed as (line, col), both 1-based.

    M1 uses UInt16 fields because the parallel Array[SourceLoc] attached to every Chunk easily reaches millions of entries in real workloads: two bytes per field is enough for essentially all JS files, and it halves the debug-info footprint compared to Int. Sources exceeding 65535 lines / cols clamp to 0 by convention (documented in the parent design).

    SourceLoc::new

    fn SourceLoc::new(line : Int, col : Int) -> SourceLoc

    Build a SourceLoc from plain integers. Callers usually get them from the lexer as Int, so this constructor centralizes the narrowing conversion and avoids scattering .to_uint16() calls around the codebase.

    SourceSpan

    pub struct SourceSpan {
    start : SourceLoc
    end : SourceLoc
    } derive(Eq,
    Debug
    )

    Range of source code between two SourceLocs. Every AST node carries one so that later passes (compiler, error reporter) can attribute bytecode and diagnostics back to the exact original span.

    SourceSpan::new

    fn SourceSpan::new(start : SourceLoc, end : SourceLoc) -> SourceSpan

    Build a span from two locations. Provided as a stable constructor even though the struct is fully public so callers do not need to know the field order; if we later add optional metadata to spans (e.g. a source index), callers won't have to change.

    Source Files