Skip to content

feature: wasm.ray, Ray writes the kernel's JMP as a wasm module - #45

Open
benjaminshawki wants to merge 28 commits into
mainfrom
core/module-writer
Open

benjaminshawki wants to merge 28 commits into
mainfrom
core/module-writer

Conversation

@benjaminshawki

@benjaminshawki benjaminshawki commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

Selfhosting.md §7, step 5: the kernel's module written by Ray. src/wasm.ray writes the module module_bytes writes, byte for byte, for the whole kernel; with kernel.ray reading kernel.ts it does so from Ray alone, and the kernel it writes runs the library as the one built in TypeScript does.

Carries #47 (its one commit, merged in): without it no run holds the whole kernel. Merge #47 first.

What it adds:

  • src/wasm.ray, on the interface scripts/kernel-wasm.mts gives it (wj_context, wj_begin, wj_label, wj_statement, wj_module): types, imports, functions, exports, code and names, as module_bytes writes them; each body as context and structure do. structure's fix of crossing scopes compares each scope with each (652 in apply); here it is a linear pass that gives the same beginnings (scopes by where they end, a stack of the outermost; the same on all 236 kernel functions, checked in TypeScript). A call names a context by where it is, so bodies are kept until every context is given; when every one is given first (wj_announced), each body is written as its context ends (wj_end) and nothing of it kept.
  • kernel.ray with kjs.writing = true: every function given to the writer in its first reading, each written and ended in its second, so the JMP comes from Ray.
  • The kernel's map: a Byte as a text of one byte (Int32.byte), how many bytes a text is (Int32.bytes_in), --write of a text of bytes as it is; Number.ray's own byte_by_bits (IB25, IB26).
  • RAY_KERNEL_WASM=<file> (language.ts): the kernel module in that file run instead of the one module_bytes makes.
  • kernel-wasm.mts: --check also takes a .wasm; --parts <dir> --module <file> writes the module in runs of their own, about --statements (6000) a run, a context past --slice (7000) in slices (wj_cell, wj_slice_begins, wj_slice_ends, wasm.sized_as). kernel-ray.mts --wasm <file>: the module from kernel.ray and wasm.ray, in ranges of about 250 lines.

Checked (main b12cb48 with #47):

  • The whole kernel from Ray alone: kernel-ray.mts --wasm k.wasm (22 ranges, 33 minutes with 8 at once), then kernel-wasm.mts --check k.wasm --pages 32768: the same 375,834 bytes as module_bytes.
  • The whole kernel from TypeScript's JMP: kernel-wasm.mts --parts <dir> --module k.wasm --check k.wasm (12 runs, 22 minutes): the same 375,830 bytes (16 pages).
  • That module run: the library's tests (-t --threads 1 ../ray/bootstrap/.entrypoint.ray3) with RAY_KERNEL_WASM set to the module Ray wrote answer as on the kernel built in TypeScript, assert for assert (916 pass, 405 errors).
  • A source of 7 functions (loops, else if, continue, natives, cas, fill): the same 882 bytes, in one run, in parts and in slices; the functions run as JavaScript answers.
  • SH6: kernel-ray.mts then kernel-jmp.mts --check, the same, 54,254 lines and 576 contexts.
  • The library's tests: as main's, assert for assert, plus IB25 and IB26.

Not yet: the whole kernel in one run. Its reading is one application (export function kernel, read twice), and what is held and later dropped inside an application still running is not let go of; kernel.ray alone runs out of the 2 GB a run has. The ranges are runs of their own for that.

The failing vscode check fails on main too (Release, b12cb48).

@benjaminshawki benjaminshawki changed the title feature: module.ray, Ray writes the kernel's JMP as a wasm module feature: wasm.ray, Ray writes the kernel's JMP as a wasm module Oct 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant