Skip to content

Feat/real execution runtimes - #1

Open
indexer wants to merge 6 commits into
mainfrom
feat/real-execution-runtimes
Open

Feat/real execution runtimes#1
indexer wants to merge 6 commits into
mainfrom
feat/real-execution-runtimes

Conversation

@indexer

@indexer indexer commented May 31, 2026

Copy link
Copy Markdown
Owner

No description provided.

indexer added 6 commits May 30, 2026 22:34
…ctness fixes

Extend the line interpreter with user-defined function calls and a call
stack, Map/Set/plain-object tracking, and recursion. Fix a class of
silent-wrong bugs that made correct algorithms display wrong results:

- Python `//` floor division was stripped as a comment
- `elif` / `else if` chains ran multiple branches
- `+=` to indexed targets (`freq[c] += 1`) was silently dropped
- `" in "` split inside string literals; scalar->Map double-render;
  Infinity/NaN serialization; object-literal shorthand

Add Kotlin `when` (statement/expression/compound-assign forms; subject &
subjectless; comma/else/in-range conditions; single-line & block bodies),
string templates, `for (x in collection)`, `downTo`, `step`, and a clear
error for invalid `[...]` list literals.
…backends

Run the genuine language and trace it per line into the existing
visualization panels, instead of the regex line-interpreter:

- Python -> Pyodide (real CPython) under sys.settrace
- TypeScript -> the browser JS engine, Babel-instrumented per statement
  (call-stack tracking + a __tick runaway-guard so even `while(true){}`
  terminates instead of freezing the tab)
- shared trace->ExecSnapshot adapter; Kotlin stays on the line interpreter

Heavy deps load from CDN in the browser (never bundled; build ~80KB) and
from the npm packages in Node, so both pipelines are unit-testable
(@vitest-environment node). pyodide/@babel/core are devDependencies.
CodeRunnerPage runs async, routes by language, and sanitizes pasted
zero-width/non-breaking characters.
…ained snippets

The algorithm-detail walkthroughs replayed hand-authored variable values,
often for a different input than the runnable example block. Ground them
in reality:

- genStepValues runs every TS/Python snippet on the real runtimes and
  emits truthful per-step variable values into generatedStepValues.ts
- withGeneratedStepValues overlays them (titles/descriptions/lines kept);
  library values now match the playground ~93% (was ~65%)
- withSelfContainedSnippets prepends ListNode/TrieNode so the linked-list
  and trie snippets actually execute (auto-offsetting authored step lines)
- fix Jump Search `const`->`let` reassignment

libraryExecution.test runs all 210 TS/Python snippets in CI; regenerate
values after editing a snippet via `npm run gen:step-values`.
Document the Content-Security-Policy the playground runtimes need
(unsafe-eval + wasm-unsafe-eval + jsdelivr in script-src/connect-src; set
as a header, not a <meta> which breaks Vite dev), how to self-host the
Pyodide/Babel assets instead of using the CDN, first-load UX, and the
step-value regeneration workflow. Preconnect to the CDN in index.html.
Behavior-preserving complexity fixes from a hot-path audit:

- CodeRunnerPage: memoize `codeLines` so `escapedCodeLines` actually caches
  (it was re-escaping every source line on every render); replace the
  O(S^2) executed-line-set rebuild with an O(S) first-execution-step map
  (O(1) per line at render time).
- jsRuntime: serialize call-frame args once at `__enter` instead of on every
  recorded step (was O(steps * depth * arg-size)).
- interpreter: precompute a brace-match table so `matchBraceClose` is O(1)
  instead of re-scanning the block on every loop iteration / branch re-entry
  (helps Kotlin if-chains / `when` inside nested loops).
…p config

`tsc -b` checks src/ under the browser-only app tsconfig (no node / @babel
types), which broke on the runtime loaders' Node fallback paths:

- reference `process` via a `globalThis` cast instead of the bare global
  (no @types/node needed in the app build)
- type the Node-only `@babel/core` dynamic import with a minimal local shape
  instead of `typeof import("@babel/core")` (no declaration in the app build)

Behavior unchanged; the Node branches still run only under @vitest-environment
node, where the real types are available.
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