• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

source-academy / py-slang / 30410611527

29 Jul 2026 12:15AM UTC coverage: 86.205% (+0.05%) from 86.159%
30410611527

push

github

web-flow
Add draw_data to the py2js engine (#366)

Wires draw_data up for the py2js engine, alongside the existing CSE
machine support. Available from chapter 2 onward, bridged natively as
part of the LINKED_LISTS group (the same group pair/llist/head/tail
belong to) rather than the generic CSE-Value round-trip bridge every
other stdlib builtin goes through.

That's a deliberate choice, not a shortcut: the generic bridge's
toTagged/toTaggedList walk a pair/list's spine with no cycle guard,
which is fine for every other bridged builtin (none is ever handed a
genuinely self-referential structure in practice) but wrong for
draw_data specifically, since chapter 3+'s set_head/set_tail can build
exactly that, and visualizing such a structure gracefully (a "ref"
arrow, not a hang) is the whole point of the feature. draw_data instead
walks native PyValues directly via a new toDataVisualizerNodePy2Js
adapter, with its own refs-based cycle guard — proven by a test that
draws a genuinely self-referential pair without hanging.

- src/conductor/dataVisualizer/toDataVisualizerNodePy2Js.ts — the py2js
  native-value counterpart of toDataVisualizerNode.ts, dispatching on
  py2js's own unboxed value shapes instead of CSE's tagged Value.
- src/conductor/dataVisualizer/Py2JsDataVisualizerRunnerPlugin.ts —
  thin BaseDataVisualizerRunnerPlugin<PyValue> binding, mirroring
  PythonDataVisualizerRunnerPlugin's shape.
- src/engines/py2js/stdlibBridge.ts — nativeDrawData, registered when
  bridging the LINKED_LISTS group.
- src/engines/py2js/index.ts / src/conductor/Py2JsEvaluator.ts —
  thread a registered Py2JsDataVisualizerRunnerPlugin down into the
  session (variant >= 2 only, mirroring PyCseEvaluatorBase's identical
  gate), with resetRun() called per chunk.


Claude-Session: https://claude.ai/code/session_014SWoqgBNWe8oP21aL2qejk

Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>

4443 of 5546 branches covered (80.11%)

Branch coverage included in aggregate %.

41 of 42 new or added lines in 5 files covered. (97.62%)

9630 of 10779 relevant lines covered (89.34%)

179273.54 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

75.0
/src/conductor/dataVisualizer/Py2JsDataVisualizerRunnerPlugin.ts
1
import {
2✔
2
  BaseDataVisualizerRunnerPlugin,
3
  type RefIdAllocator,
4
} from "@sourceacademy/runner-data-visualizer";
5
import type { SerializedDataVisualizerNode } from "@sourceacademy/common-data-visualizer";
6

7
import type { PyValue } from "../../engines/py2js/runtime";
8
import { toDataVisualizerNodePy2Js } from "./toDataVisualizerNodePy2Js";
2✔
9

10
/**
11
 * The py2js engine's binding of the language-agnostic data visualizer runner — the native-value
12
 * counterpart of `PythonDataVisualizerRunnerPlugin` (the CSE machine's binding).
13
 *
14
 * All py2js-specific knowledge lives in {@link toDataVisualizerNodePy2Js}; this class is the thin
15
 * adapter `BaseDataVisualizerRunnerPlugin` expects — no cycle-detection or classification here, that
16
 * stays host-side, shared across every language and every engine.
17
 */
18
export class Py2JsDataVisualizerRunnerPlugin extends BaseDataVisualizerRunnerPlugin<PyValue> {
2✔
19
  protected toNode(value: PyValue, refs: RefIdAllocator): SerializedDataVisualizerNode {
NEW
20
    return toDataVisualizerNodePy2Js(value, refs);
×
21
  }
22
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc