// The static data at the bottom of the engine's linear memory, below the frame stack (which starts at // DATA_END). It starts at 1KiB because scripts/build.sh tells wasm-opt the low 1KiB is unused. // Each table is an active data segment in a small WAT module that scripts/build.sh merges into // the zena output (zena has no way to declare one), so the bytes cost exactly their own size instead // of the ~1.3x of i64 constants in code. export const KW_BASE = 1024; // keyword and punctuator tables: keywords.mjs export const TEXT_BASE = 2304; // downlevel's text templates (build/downlevel.wasm only): downlevel-text.mjs export const TEXT_END = 3072; export const CLASS_BASE = TEXT_END; // lex.zena's 256-byte byte-class table: chartable.mjs // The lexer's token replay cache (engine/lex.zena): LEXC_SIZE 16-byte entries, direct-mapped by stream offset. export const LEXC_BASE = CLASS_BASE + 256 + 16; // dataModule keeps 16 bytes of slack after each table export const LEXC_SIZE = 256; export const ENT_BASE = LEXC_BASE + LEXC_SIZE * 16; // JSX's HTML entity table (build/downlevel.wasm only): jsx-entities.mjs export const ENT_END = ENT_BASE + 3072; export const DATA_END = ENT_END; // Writes a WAT module holding `bytes` as one active segment at `base` of the imported memory. export function dataModule(comment, base, bytes, limit) { if (base + bytes.length + 16 > limit) throw new Error(`${comment}: ${bytes.length} bytes at ${base} overrun ${limit}`); let s = ""; for (const b of bytes) { s += b >= 0x20 && b < 0x7f && b !== 0x22 && b !== 0x5c ? String.fromCharCode(b) : "\\" + b.toString(16).padStart(2, "0"); } const lines = s.match(/(\\..|.){1,96}/g) ?? []; return `;; GENERATED by scripts/gen/${comment}. Do not edit by hand. (module (import "engine" "memory" (memory 1)) (data (i32.const ${base}) ${lines.map((l) => ` "${l}"`).join("\n")}) ) `; }