Skip to content

The great frame refactor#2

Open
masak wants to merge 34 commits into
mainfrom
masak/frame
Open

The great frame refactor#2
masak wants to merge 34 commits into
mainfrom
masak/frame

Conversation

@masak

@masak masak commented Apr 25, 2026

Copy link
Copy Markdown
Owner

Old evaluator: Uses a Kont hierarchy to represent internal continuations. Evaluation always starts at a syntax node (and in some mode), but recursive evaluation is managed by delegating to a Kont object, in zero or more steps.

New evaluator: Uses a single Frame class to unify the cases of "handling a node for the first time" and "continuing the node after a subtask finishes".

Advantages:

  • Half the evaluator code. (1.4 kLoC, down from 3.0 kLoC.)
    • Specific evaluator code for infix and prefix ops has been separated out into infix.ts (~300 LoC) and preifx.ts (~100 LoC); these have their own handler maps.
  • The code for evaluating each syntax node type is localized to a single handler, instead of spread over initial code for the syntax node and code for each Kont type.

The properties of Frame are divided into immutable and mutable. Here are the immutable ones:

  • mode: Mode — either GetValue, GetCell, or Ignore
  • node: SyntaxNode — the node we're currently evaluation
  • state: number — the current state in the state machine
  • env: Env — current lexical environment
  • staticEnvs: Map<SyntaxNode, Env> — static environments
  • value: Value — latest value returned from recursive evaluation
  • cell: Cell | null — latest cell returned from recursive evaluation
  • jumpMap: JumpMap — jump map for last, next, and return
  • tail: Frame — which frame to return to next

Here are the mutable properties:

  • datum1: number
  • datum2: number | Value
  • datum3: Array<SyntaxNode>
  • datum4: Array<Value>

The resulting structure of the evaluator makes more structure stand out for the individual syntax node types. But such improvements have to come in later PRs.

They will be added back, gradually.
masak added 28 commits May 22, 2026 23:20
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