tvix/eval: more granular evaluation (for repl purposes)

#371
Opened by flokli at 2024-01-18T10·20+00

The nix repl behaves different than the tvix repl.

The Tvix repl currently expects the passed Nix code to be a somewhat self-contained Nix program.

The Nix repl allows you to do some more "back and forth" with the evaluator, essentially mutating variables in a per-session scope.

We currently have no infrastructure to run some code with the evaluator, and then run some more code.

This would however be helpful for this usecase, as well as enabling tab completion.

Evaluation::evaluate() currently consumes self, and returns an Evaluation result.

I propose to change this to take &mut self, and having some notion of a toplevel scope accessible as attributes, allowing more dialogues to happen with the evaluator and something interactive driving it.

  1. evaluate doesn't need to and should not know about this. All the nix repl has is extra syntax (that wouldn't parse as a Nix expression) to bind something in the global scope. All that's necessary is to add the returned Value to the globals of the evaluator struct after some special command.

    sterni at 2024-01-18T10·59+00