A self-hosting compiler and bare-metal OS, written entirely in JavaScript A developer released a self-hosting JavaScript compiler and bare-metal operating system written entirely in JavaScript, comprising 55,700 lines of code and passing 1,214 tests across x86-64 and AArch64. The compiler emits native x86-64 and AArch64 machine code with no interpreter, VM, or libc, compiles itself, and produces byte-for-byte identical ELF output to the Bun-hosted compiler, while the kernel boots on QEMU and VMware via GRUB with a GUI window manager, ext2 filesystem, TCP/IP networking, TLS 1.3, a Bourne shell, fork/exec, and a built-in Claude AI assistant with 10 agentic tools. The project omits async/await, generators, and regular expressions. A self-hosting JavaScript compiler and bare-metal OS, written entirely in JavaScript. Compiles JS to native x86-64 and AArch64 machine code — no interpreter, no VM, no libc. The compiler compiles itself. The OS boots on real hardware. js import { compileToLinuxExe } from './src/compiler/pipeline.js'; import { writeFileSync } from 'fs'; writeFileSync 'hello', compileToLinuxExe function fib n { if n < 2 return n; return fib n - 1 + fib n - 2 ; } console.log fib 30 ; ; // chmod +x hello && ./hello → 832040 55,700 lines of JS. 1,214 tests. The natively-compiled compiler produces byte-for-byte identical ELF output to the Bun-hosted compiler. The kernel boots on QEMU and VMware via GRUB, with a GUI window manager, ext2 filesystem, full TCP/IP networking, TLS 1.3 encryption, a Bourne shell, fork/exec, and a built-in Claude AI assistant with 10 agentic tools. bun install bun test 1,214 tests, both architectures js x86-64 runs natively on Linux x86-64 bun -e ' import { compileToLinuxExe } from "./src/compiler/pipeline.js"; import { writeFileSync } from "fs"; writeFileSync "out", compileToLinuxExe "console.log 6 7 ;" ; ' chmod +x out && ./out 42 AArch64 requires qemu-aarch64-static on x86 hosts bun -e ' import { compileToLinuxExeAArch64 } from "./src/compiler/pipeline.js"; import { writeFileSync } from "fs"; writeFileSync "out", compileToLinuxExeAArch64 "console.log 6 7 ;" ; ' chmod +x out && qemu-aarch64-static ./out 42 bun run tools/build-kernel.js build kernel image bash tools/make-iso.sh create GRUB bootable ISO QEMU serial I/O on stdio qemu-system-x86 64 -kernel build/ungodly.bin \ -vga std -serial stdio -m 256 -no-reboot With disk + networking qemu-system-x86 64 -cdrom build/ungodly.iso \ -vga std -serial stdio -m 256 -no-reboot \ -drive file=disk.img,format=raw,if=none,id=disk0 \ -device ahci,id=ahci -device ide-hd,drive=disk0,bus=ahci.0 \ -netdev user,id=net0 -device e1000,netdev=net0 | Feature | Example | Status | |---|---|---| | Integer + float arithmetic | 10.5 + 5 2 - 7 | done | | Variables, scoping | let x = 42; const y = x + 1; | done | | All operators | a b ? a : b , x ?? y , a?.b | done | | Bitwise ops | 0xFF & 0x0F , x << 3 , n 0 | done | | All loop types | while , for , for-in , for-of , do-while | done | | Functions + recursion | function fib n { ... } | done | | Arrow functions | const f = x = x 2; | done | | Closures + mutable captures | let x = 0; function inc { x++; } | done | | Objects + prototypes | let o = { x: 1 }; o.x = 2; | done | | Arrays + methods | push , map , filter , reduce , sort , find , ... | done | | Strings + methods | concat, slice , indexOf , charCodeAt , template literals | done | | Classes + inheritance | class Foo extends Bar { ... } | done | | new + constructors | new Point 1, 2 | done | | this binding | methods, constructors, arrow this capture | done | | Destructuring | let { a, b } = obj; let x, y = arr; | done | | Switch + break | switch x { case 1: ... } | done | | Throw / try-catch | throw new Error "msg" , try { ... } catch e { ... } | done | | typeof , instanceof | typeof x === "string" | done | | console.log | multi-arg, all value types | done | | Garbage collection | Cheney semi-space, conservative stack scanning | done | | String interning | "hello" === "hello" → pointer compare | done | | NaN-boxing | int32 fast path, f64 fallback, pointer-biased | done | | AArch64 cross-compile | same JS → ARM64 binary | done | | Optimization passes | DCE, constant folding, GVN, type specialization | done | | Self-hosting | compiler compiles itself, byte-for-byte identical | done | | Promises + microtasks | new Promise ... , .then , microtask queue | done | - No async/await , generators - No regular expressions - No modules import / export — worked around by file concatenation - No Proxy , Reflect , Symbol , WeakMap / WeakSet - No getters/setters - No private class fields JS source │ ▼ ┌──────────────────┐ │ Parser │ Recursive-descent, ES2023 subset, ESTree AST │ parser.js │ 1,510 lines └────────┬─────────┘ │ AST ▼ ┌──────────────────┐ │ Lowering │ AST → SSA IR with basic blocks, phi nodes │ lower.js │ NaN-boxing, closure capture analysis, │ │ mutable capture box cells, 30+ builtin interceptions │ │ 3,831 lines └────────┬─────────┘ │ IRFunction SSA, 196 opcodes ▼ ┌──────────────────┐ │ Optimization │ constFold → DCE → typeSpec → constFold → GVN → DCE │ optimize/ │ 914 lines └────────┬─────────┘ │ optimized IR ▼ ┌──────────────────┐ │ Register Alloc │ Linear scan on SSA live intervals │ regalloc.js │ Dataflow liveness, call-aware spilling │ │ 397 lines └────────┬─────────┘ │ allocation map ▼ ┌──────────────────┐ │ Instruction Sel │ IR → native machine code + runtime helpers │ x86 64/isel.js │ 6,296 lines — System V ABI, 30+ rt helpers │ aarch64/isel.js │ 4,746 lines — AAPCS64, full feature parity └────────┬─────────┘ │ machine code bytes ▼ ┌──────────────────┐ │ ELF Linker │ ELF64 builder, single LOAD segment │ elf.js │ x86 64 + aarch64 + flat binary output └────────┬─────────┘ │ ▼ Linux ELF binary — or — Bare-metal kernel image Pointers: 0x0000 PPPP PPPP PPPP raw, zero-cost dereference Int32: 0xFFFF 0000 IIII IIII tagged, extract with mask Double: raw IEEE754 + 0x0002 0000 0000 0000 bias Boolean: false = 0x06, true = 0x07 Null: 0x02 Undefined: 0x0A Flat inline storage, no hash table. Up to 128 properties per object. GC header: u64 num props: u64 key0: u64 val0: u64 key1: u64 val1: u64 ... Property names are hashed at compile time djb2 with high bit set . Lookup is linear scan. Cheney semi-space collector. Two 256MB semispaces allocated via mmap 14MB on bare metal . Bump allocation into the from-space; when full, copy reachable objects to the to-space and swap. Conservative stack scanning for roots. GC control block pinned in R13 x86-64 / X25 AArch64 . Bump pointer in R15 / X28. Header format: totalSize << 17 | numScannable << 5 | tag << 1 | 1 Tags: CLOSURE=0, OBJECT=1, STRING=2, ARRAY=3, BOX=4. GC header: 8 code ptr: 8 bytes capture0: 8 capture1: 8 ... Closure pointer passed in pinned register R14 on x86-64, X26 on AArch64 . Captures accessed as closure reg + 8 1 + slot . Mutable captures use heap-allocated box cells GC TAG BOX . A box is a 24-byte GC object: GC header: 8 value: 8 pad: 8 . Both the outer scope and all capturing closures share the same box, reading and writing through it. The lowerer's pre-analysis pass preAnalyzeMutableCaptures identifies which variables need boxing. Two representations: - Data-segment strings : length: u64 bytes... — embedded in code section, interned - Heap strings : GC header: u64 length: u64 bytes... — allocated by concat/slice src/ compiler/ parser/ parser.js Recursive-descent ES2023 subset parser 1,510 lines token.js Token types ir/ opcodes.js 196 IR opcodes with metadata flags types.js IR type system i32, i64, f64, ptr, jsval, bool builder.js IRFunction, BasicBlock, instruction pool lowering/ lower.js AST → IR, scope analysis, closure capture 3,831 lines codegen/ regalloc.js Linear scan register allocator 397 lines i64.js 64-bit integer arithmetic no BigInt x86 64/ regs.js x86-64 register definitions, System V ABI assembler.js x86-64 instruction encoder 904 lines isel.js IR → x86-64 instruction selection 6,296 lines aarch64/ regs.js AArch64 register definitions, AAPCS64 assembler.js AArch64 instruction encoder 716 lines isel.js IR → AArch64 instruction selection 4,746 lines optimize/ dce.js Dead code elimination constfold.js Constant folding + branch simplification gvn.js Global value numbering CSE typespec.js Type specialization int32 inference utils.js Shared optimization utilities linker/ elf.js ELF64 builder + flat binary output pipeline.js Main entry: source → ELF 601 lines kernel/ 67 files, 33,200 lines main.js Kernel entry, event loop, window manager 1,472 lines drivers/ serial.js COM1 serial I/O vga.js VGA text mode + framebuffer 800x600x32, PSF font keyboard.js PS/2 keyboard ISR mouse.js PS/2 mouse driver pci.js PCI bus enumeration pty.js Pseudo-terminal PTY for terminal emulator e1000.js Intel e1000 NIC driver ahci.js AHCI SATA disk driver vmware.js VMware Tools guest agent usb scan.js USB device enumeration xhci core.js xHCI host controller xhci keyboard.js USB keyboard via xHCI fs/ ext2.js ext2 filesystem read/write, inode/block alloc, symlinks ramdisk.js Embedded ramdisk archive vfs.js Virtual filesystem layer 10 FD types pipe.js Pipe IPC fork/exec stdin piping net/ net.js Ethernet/IPv4/ARP/ICMP stack tcp.js TCP 3-way handshake, sliding window, retransmit udp.js UDP dhcp.js DHCP client auto-configure IP/gateway/DNS dns.js DNS resolver http.js HTTP/1.1 client + HTTPS TLS 1.3 claude api.js Claude API client SSE streaming, agentic tool loop oauth.js OAuth 2.0 device code flow crypto/ chacha.js ChaCha20-Poly1305 AEAD + X25519 key exchange sha256.js SHA-256 + HMAC-SHA256 + HKDF tls.js TLS 1.3 handshake + record layer ChaCha20-Poly1305-SHA256 lib/ json.js JSON parser arena-based sse.js Server-Sent Events parser microtask.js Microtask queue Promise resolution promise.js Promise implementation tools/ tools.js 10 Claude tools read/write/list/edit/search/exec/glob/fetch/search web syscall/ dispatch.js Linux syscall trampoline 60+ syscalls dir ops.js Directory syscalls mkdir, rmdir, rename, getdents64 file ops.js File syscalls open, read, write, stat, symlinks socket ops.js Socket syscalls shell/ eval.js JIT eval compile JS → native → execute at runtime commands.js Shell command dispatch sub-dispatcher pattern dispatch.js Shell dispatch router claude cmd.js Claude AI shell integration agentic loop oauth cmd.js OAuth authentication commands eval expr.js Expression evaluator arithmetic, precedence exec.js Process execution fork, exec, wait fs cmds.js Filesystem shell commands net cmds.js Network shell commands proc cmds.js Process shell commands misc cmds.js Miscellaneous commands vfs cmds.js VFS shell commands fd, open, close, pipe vga helpers.js VGA output helpers sh lexer.js Bourne shell lexer sh parser.js Bourne shell parser sh exec.js Bourne shell execution sh runner.js Bourne shell runner sh shell.js Bourne shell main loop sh control.js Bourne shell control flow if/while/for proc/ pmm.js Physical memory manager bitmap allocator vmm.js Virtual memory page tables, 4-level paging process.js Process table + context switching elf.js ELF loader static-PIE binaries, ring 3 exec runtime/ value.js NaN-boxing encode/decode/type checks tools/ build-kernel.js Boot image builder Multiboot, ISRs, page tables, 4,439 lines make-iso.sh GRUB bootable ISO creator tests/ 1,214 tests across 23 test files The kernel boots via Multiboot1 GRUB or QEMU -kernel , sets up 4-level paging, SSE, PIT timer at 100 Hz, PS/2 keyboard + mouse ISRs, and enters a GUI window manager with terminal emulator. The embedded compiler 19 files, ~18K lines enables JIT evaluation of arbitrary JS at the shell prompt. Compositing window manager with mouse-driven drag/resize, terminal emulator with PTY backend, VGA framebuffer at 800x600x32. 55+ commands including: | Command | Description | |---|---| | help | List available commands | | eval