feat(tvix/repl): Allow binding variables at the top-level

Allow binding variables at the REPL's toplevel in the same way the Nix
REPL does, using the syntax <ident> = <expr>. This fully, strictly
evaluates the value and sets it in the repl's "env", which gets passed
in at the toplevel when evaluating expressions.

The laziness behavior differs from Nix's, but I think this is good:

    ❯ nix repl
    Welcome to Nix version 2.3.18. Type :? for help.

    nix-repl> x = builtins.trace "x" 1

    nix-repl> x
    trace: x
    1

    nix-repl> x
    1

vs tvix:

    tvix-repl> x = builtins.trace "x" 1
    trace: "x" :: string
    tvix-repl> x
    => 1 :: int
    tvix-repl> x
    => 1 :: int

Bug: https://b.tvl.fyi/issues/371
Change-Id: Ieb2d626b7195fa87be638c9a4dae2eee45eb9ab1
Reviewed-on: https://cl.tvl.fyi/c/depot/+/11954
Reviewed-by: flokli <flokli@flokli.de>
Tested-by: BuildkiteCI
Autosubmit: aspen <root@gws.fyi>
This commit is contained in:
Aspen Smith 2024-07-04 23:46:20 -04:00 committed by clbot
parent ac3d717944
commit fc63594631
6 changed files with 157 additions and 16 deletions

View file

@ -13845,10 +13845,18 @@ rec {
name = "rnix";
packageId = "rnix";
}
{
name = "rowan";
packageId = "rowan";
}
{
name = "rustyline";
packageId = "rustyline";
}
{
name = "smol_str";
packageId = "smol_str";
}
{
name = "thiserror";
packageId = "thiserror";