Skip to content

CSE Machine (Conductor) : Move language-specific value conversion out of CseSnapshotAdapter into the runner #4005

Description

@Akshay-2007-1

Refactor: remove language-specific type coercion from CseSnapshotAdapter — move to runner side

CseSnapshotAdapter.ts contains a toJsValue function that maps serialized snapshot value labels to JS runtime values:

if (label === 'int' || label === 'number') { ... }
if (label === 'float' || label === 'complex') { return { toReplString: () => v.displayValue }; }
if (label === 'bool' || label === 'boolean') { return v.displayValue === 'True' || ...; }
if (label === 'str' || label === 'string') { ... }
if (label === 'nonetype' || label === 'none' || label === 'null') { ... }

This is entirely Python-specific knowledge baked into the frontend. It happens to work for Python and JavaScript but breaks for any other language:

  • Go uses nil not null/none
  • Racket uses #t/#f not true/false
  • Any language with non-standard numeric tower (e.g. rationals, bignums) has no representation here

@AaravMalani has pointed this out yet again in the review of #4000.

Proposed direction:
The snapshot protocol should carry values in a frontend-agnostic form. Two options to discuss:

  1. Standardised kind enum: runner serializes each value with a kind field from a fixed set (number, boolean, string, null, closure, list, raw) plus a displayValue string. Frontend renders purely from kind + displayValue with no language knowledge.
  2. Pre-rendered display string only: runner is solely responsible for producing the display string; frontend treats all primitives as opaque strings and only structures (closures, lists, pairs) need structural metadata.

Steps:

  1. Agree on snapshot protocol value format (needs discussion — see above)
  2. Update py-slang's CSE runner to serialize values in the agreed format
  3. Simplify CseSnapshotAdapter.toJsValue to consume the standardised format with no language-specific branching
  4. Document the value format as part of the conductor snapshot protocol spec so future language runners know what to emit

Needs design agreement between frontend and runner maintainers before implementation.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions