Commit graph

14 commits

Author SHA1 Message Date
Vincent Ambo
813fb98470 refactor(tvix/eval): Upgrade to latest rnix-parser
Since the latest published version of rnix-parser on crates.io, the
crate has undergone major changes which are only available in the git
repository at the moment. This commit updates the compiler to this
newer version of rnix.

Most notably, the entire AST provided by rnix is now wrapped in the
AST type system. As a result of this traversal is much nicer in many
places, especially for things like nested attribute selection.

There are a handful of smaller features missing for full feature
parity with the previous version, especially handling of path
literals, but PRs for these already exist in rnix-parser.

Change-Id: Icde6d393067976549492b7d89c4cc49e5e575fc7
Reviewed-on: https://cl.tvl.fyi/c/depot/+/6231
Reviewed-by: sterni <sternenseemann@systemli.org>
Tested-by: BuildkiteCI
2022-09-01 17:41:22 +00:00
Vincent Ambo
0257f89917 chore(tvix/eval): return parse errors out of eval::interpret
Change-Id: I14f25b9c85260c68be38abf07ed80121ead60c7b
Reviewed-on: https://cl.tvl.fyi/c/depot/+/6224
Tested-by: BuildkiteCI
Reviewed-by: sterni <sternenseemann@systemli.org>
Reviewed-by: grfn <grfn@gws.fyi>
2022-08-31 22:42:48 +00:00
Vincent Ambo
ab9407bded fix(tvix/eval): address various clippy lints
Change-Id: I3ea0f51475e80948adfeb5d1620c1f2665cc39bc
Reviewed-on: https://cl.tvl.fyi/c/depot/+/6201
Tested-by: BuildkiteCI
Reviewed-by: sterni <sternenseemann@systemli.org>
2022-08-30 16:53:40 +00:00
Vincent Ambo
e041851581 feat(tvix/eval): implement chunk disassembler output
This makes for a much nicer view of an execution if `--feature
disassembler` is set, for example:

  tvix-repl> let value = [ 1 2 { a = 1; } ]; in value ++ [ 1 ]
  === compiled bytecode (11 operations) ===
  02   OpConstant(1)
  02   OpConstant(2)
  02   OpConstant("a")
  02   OpConstant(1)
  02   OpAttrs(1)
  02   OpList(3)
  02   OpGetLocal(0)
  02   OpConstant(1)
  02   OpList(1)
  02   OpConcat
  02   OpCloseScope(1)
  === runtime trace ===
  0001 OpConstant(ConstantIdx(0))  [ 1 ]
  0002 OpConstant(ConstantIdx(1))  [ 1 2 ]
  0003 OpConstant(ConstantIdx(2))  [ 1 2 "a" ]
  0004 OpConstant(ConstantIdx(3))  [ 1 2 "a" 1 ]
  0005 OpAttrs(1)                  [ 1 2 { a = 1; } ]
  0006 OpList(3)                   [ [ 1 2 { a = 1; } ] ]
  0007 OpGetLocal(0)               [ [ 1 2 { a = 1; } ] [ 1 2 { a = 1; } ] ]
  0008 OpConstant(ConstantIdx(4))  [ [ 1 2 { a = 1; } ] [ 1 2 { a = 1; } ] 1 ]
  0009 OpList(1)                   [ [ 1 2 { a = 1; } ] [ 1 2 { a = 1; } ] [ 1 ] ]
  0010 OpConcat                    [ [ 1 2 { a = 1; } ] [ 1 2 { a = 1; } 1 ] ]
  0011 OpCloseScope(1)             [ [ 1 2 { a = 1; } 1 ] ]
  => [ 1 2 { a = 1; } 1 ] :: list

Change-Id: If79c7fd1f0f18255ddb3763c1ba585fda8041b1b
Reviewed-on: https://cl.tvl.fyi/c/depot/+/6195
Tested-by: BuildkiteCI
Reviewed-by: sterni <sternenseemann@systemli.org>
2022-08-30 16:53:40 +00:00
Vincent Ambo
6fe5e2d752 feat(tvix/eval): resolve relative path literals
Resolves relative paths (e.g. `./foo`) either relative to the location
of the Nix file, or relative to the working directory if none is
supplied.

Change-Id: I70ec574657b221b458015117a004b6e4a9c25a30
Reviewed-on: https://cl.tvl.fyi/c/depot/+/6185
Tested-by: BuildkiteCI
Reviewed-by: sterni <sternenseemann@systemli.org>
2022-08-28 11:02:15 +00:00
Vincent Ambo
7e77972d71 feat(tvix/eval): add mechanism for emitting warnings from compiler
These can be used predominantly to emit warnings about things that the
compiler can infer, such as deprecated language features.

Change-Id: I3649c625459d7f3f95cdf42d5c651d23d66569ec
Reviewed-on: https://cl.tvl.fyi/c/depot/+/6174
Reviewed-by: grfn <grfn@gws.fyi>
Tested-by: BuildkiteCI
2022-08-26 17:19:51 +00:00
Vincent Ambo
8235384d2d chore(tvix/eval): only print AST if requested
Change-Id: If32c7fd03458a27aecb8c473f2c48b12f8cb5175
Reviewed-on: https://cl.tvl.fyi/c/depot/+/6128
Tested-by: BuildkiteCI
Reviewed-by: grfn <grfn@gws.fyi>
Autosubmit: tazjin <tazjin@tvl.su>
2022-08-24 21:25:41 +00:00
Vincent Ambo
92c53fe982 feat(tvix/tests): check in Nix' language test suite
This adds scaffolding code for running the Nix language test suite.

The majority of eval-okay-* tests should eventually be runnable as-is
by Tvix, however the eval-fail-* tests might not as we intend to have
more useful error messages than upstream Nix.

Change-Id: I4f3227f0889c55e4274b804a3072850fb78dd1bd
Reviewed-on: https://cl.tvl.fyi/c/depot/+/6126
Tested-by: BuildkiteCI
Autosubmit: tazjin <tazjin@tvl.su>
Reviewed-by: grfn <grfn@gws.fyi>
2022-08-24 21:25:41 +00:00
Vincent Ambo
72863d81fc style(tvix/eval): display Display representation of runtime values
Change-Id: Ifbe05c2da9493c9e132a2d2e94a451d6091542a5
Reviewed-on: https://cl.tvl.fyi/c/depot/+/6096
Tested-by: BuildkiteCI
Reviewed-by: grfn <grfn@gws.fyi>
2022-08-13 18:28:36 +00:00
Vincent Ambo
865717a8db fix(tvix/eval): print code even if runtime fails
Change-Id: I357c9adf939cb6001afa73ad02282d94ee22d0ba
Reviewed-on: https://cl.tvl.fyi/c/depot/+/6088
Tested-by: BuildkiteCI
Reviewed-by: grfn <grfn@gws.fyi>
2022-08-13 11:50:37 +00:00
Vincent Ambo
0d2896519c refactor(tvix/eval): move NumberPair struct definition to vm module
This isn't relevant to the value type itself.

Change-Id: I678bc92a8a530b1081ed498bf3ff7925217bcc01
Reviewed-on: https://cl.tvl.fyi/c/depot/+/6081
Tested-by: BuildkiteCI
Autosubmit: tazjin <tazjin@tvl.su>
Reviewed-by: grfn <grfn@gws.fyi>
2022-08-12 14:09:27 +00:00
Vincent Ambo
d35ecc0caf feat(tvix/eval): implement simple arithmetic binary operations
Implements simple arithmetic operations (+, -, *, /).

There is some scaffolding included to pop and coerce pairs of numbers,
as the Nix language will let arithmetic operators apply to arbitrary
pairs of number types (always resulting in floats if the types are
mixed).

Change-Id: I5f62c363bdea8baa6ef812cc64c5406759d257cf
Reviewed-on: https://cl.tvl.fyi/c/depot/+/6074
Tested-by: BuildkiteCI
Reviewed-by: grfn <grfn@gws.fyi>
2022-08-12 13:24:10 +00:00
Vincent Ambo
e8253c7044 chore(tvix/eval): wire things up for development flow
This creates a REPL which outputs compiled bytecode, constants, and VM
results for code snippets.

Change-Id: If63f79a961456afd6a4cdf59b994107ff7ab8b47
Reviewed-on: https://cl.tvl.fyi/c/depot/+/6072
Tested-by: BuildkiteCI
Reviewed-by: grfn <grfn@gws.fyi>
Autosubmit: tazjin <tazjin@tvl.su>
2022-08-12 13:05:28 +00:00
Vincent Ambo
8921688334 chore(tvix/eval): bootstrap some evaluator boilerplate
Change-Id: I7770a20948d18a8506c2418dea21202aa21a6ddc
Reviewed-on: https://cl.tvl.fyi/c/depot/+/6064
Tested-by: BuildkiteCI
Reviewed-by: grfn <grfn@gws.fyi>
2022-08-12 12:39:19 +00:00