Commit graph

1185 commits

Author SHA1 Message Date
Vincent Ambo
56caaf70ca fix(tvix/errors): display a useful intermediate error representation
Change-Id: If979a2aa21444320427f54e6530a55cab873856b
Reviewed-on: https://cl.tvl.fyi/c/depot/+/6099
Tested-by: BuildkiteCI
Reviewed-by: grfn <grfn@gws.fyi>
2022-08-13 18:28:36 +00:00
Vincent Ambo
a93933b487 feat(tvix): implement string interpolation
This adds a new instruction which assembles an interpolated string
from a specified number of fragments, which are already going to be
located on the stack in the right position.

This will raise a type error if any of the fragments do not evaluate
to a string.

Change-Id: I5756248fa3e9fcc3d063c14db40b332f7e20a588
Reviewed-on: https://cl.tvl.fyi/c/depot/+/6098
Tested-by: BuildkiteCI
Reviewed-by: grfn <grfn@gws.fyi>
2022-08-13 18:28:36 +00:00
Vincent Ambo
3577841bde feat(tvix/compiler): compile non-interpolated string literals
This sets up the scaffolding for compiling interpolation, but those
instructions do not yet exist.

Change-Id: Ife41bbbf432d9661abe566c92437409dd0da44e7
Reviewed-on: https://cl.tvl.fyi/c/depot/+/6097
Tested-by: BuildkiteCI
Reviewed-by: grfn <grfn@gws.fyi>
2022-08-13 18:28:36 +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
910336c68c feat(tvix/compiler): compile list literals
Change-Id: I2c6fedc3dbb7d449d700f3972c3fbd4a7d147f6c
Reviewed-on: https://cl.tvl.fyi/c/depot/+/6095
Tested-by: BuildkiteCI
Reviewed-by: grfn <grfn@gws.fyi>
Autosubmit: tazjin <tazjin@tvl.su>
2022-08-13 15:39:26 +00:00
Vincent Ambo
5763b62172 feat(tvix/vm): implement list construction
Change-Id: Iec2b4910800ab29daae6d71b58a8acd14ccb1cc1
Reviewed-on: https://cl.tvl.fyi/c/depot/+/6094
Tested-by: BuildkiteCI
Reviewed-by: grfn <grfn@gws.fyi>
Autosubmit: tazjin <tazjin@tvl.su>
2022-08-13 15:35:24 +00:00
Vincent Ambo
c67747cbe1 feat(tvix/value): add runtime representation of simple lists
There might be more logic in the future to encapsulate different
backing implementations of lists as well.

Change-Id: Ib7064fab48bf88b0c8913b0ecfa2108177c7c9fd
Reviewed-on: https://cl.tvl.fyi/c/depot/+/6093
Tested-by: BuildkiteCI
Reviewed-by: grfn <grfn@gws.fyi>
Autosubmit: tazjin <tazjin@tvl.su>
2022-08-13 15:35:24 +00:00
Vincent Ambo
6f13c16f28 docs(tvix/eval): add design documentation for attrset opcodes
Change-Id: I303b57e035543f4597c6247983d1d533e4014638
Reviewed-on: https://cl.tvl.fyi/c/depot/+/6092
Tested-by: BuildkiteCI
Reviewed-by: grfn <grfn@gws.fyi>
2022-08-13 15:31:50 +00:00
Vincent Ambo
57a723aaa9 feat(tvix/eval): implement trivial attribute set literals
Implements attribute set literals without nesting. Technically this
already supports dynamic key fragments (evaluating to strings), though
the only way to create these (interpolation) is not yet implemented.

However, creating simple attribute sets like `{ }`, or `{ a = 15; }`
or `{ a = 10 * 2; }` works.

Recursive attribute sets are not yet implemented as we do not have any
kind of scope access yet anyways.

This is implemented using a new instruction that creates an attribute
set with a given number of elements by popping key/value pairs off the
stack.

Change-Id: I0f9aac7a131a112d3f66b131297686b38aaeddf2
Reviewed-on: https://cl.tvl.fyi/c/depot/+/6091
Tested-by: BuildkiteCI
Reviewed-by: grfn <grfn@gws.fyi>
2022-08-13 15:31:50 +00:00
Vincent Ambo
e24248df3b feat(tvix/value): add some necessary helpers for strings
Deriving Ord/Eq is required for the ordered BTreeMaps. Once interning
is implemented this will require some extra magic for the sort order,
but that's fine.

Change-Id: I0c654648eb3609a4a01d84868c25f43a4d35bc2e
Reviewed-on: https://cl.tvl.fyi/c/depot/+/6089
Tested-by: BuildkiteCI
Reviewed-by: grfn <grfn@gws.fyi>
2022-08-13 11:50:37 +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
2ed38a7cdb feat(tvix/eval): add Value variants for strings & attrsets
Change-Id: Idebf663ab7fde3955aae50f635320f7eb6c353e8
Reviewed-on: https://cl.tvl.fyi/c/depot/+/6087
Tested-by: BuildkiteCI
Reviewed-by: grfn <grfn@gws.fyi>
2022-08-13 11:50:37 +00:00
Vincent Ambo
ba03226e51 feat(tvix/eval): add module for attribute set implementations
Change-Id: I6002bd5e5596b93325dea6c862370ba5235c0f08
Reviewed-on: https://cl.tvl.fyi/c/depot/+/6086
Tested-by: BuildkiteCI
Reviewed-by: grfn <grfn@gws.fyi>
2022-08-13 11:50:37 +00:00
Vincent Ambo
d26c097d1b feat(tvix/eval): add module for string type implementation
Change-Id: I5e4465acc4a676c10d7374b14f7a09240202b466
Reviewed-on: https://cl.tvl.fyi/c/depot/+/6085
Tested-by: BuildkiteCI
Reviewed-by: grfn <grfn@gws.fyi>
2022-08-13 11:50:37 +00:00
Vincent Ambo
3ed45caad1 feat(tvix/eval): implement Display trait for Value enum
This representation should match what the Nix REPL shows for result
values.

Change-Id: If3143d969fcdc123a6029e2aeb7bbd6ae51aeb71
Reviewed-on: https://cl.tvl.fyi/c/depot/+/6082
Tested-by: BuildkiteCI
Autosubmit: tazjin <tazjin@tvl.su>
Reviewed-by: grfn <grfn@gws.fyi>
2022-08-12 14:12:07 +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
9c5a249b30 feat(tvix/compiler): incompletely handle true/false/null literals
These are a bit tricky to implement because Nix technically treats
them as identifiers, and only if the identifier is not explicitly
overridden within the scope does it yield the expected literal values.

Note that weirdness even occurs with scopedImport.

Change-Id: Ie55723405ccfcc25da37c5a08fa3332f37cf9ae5
Reviewed-on: https://cl.tvl.fyi/c/depot/+/6080
Tested-by: BuildkiteCI
Autosubmit: tazjin <tazjin@tvl.su>
Reviewed-by: grfn <grfn@gws.fyi>
2022-08-12 14:09:27 +00:00
Vincent Ambo
d431f43f5f feat(tvix/eval): implement boolean inversion operator
Change-Id: Icb1d449fdee4d67b5f1eefdbc01baa1584ea0a67
Reviewed-on: https://cl.tvl.fyi/c/depot/+/6079
Tested-by: BuildkiteCI
Autosubmit: tazjin <tazjin@tvl.su>
Reviewed-by: grfn <grfn@gws.fyi>
2022-08-12 14:09:27 +00:00
Vincent Ambo
ded0fb9e21 feat(tvix/eval): implement equality operator
Change-Id: I9dd54aed72cd7e67593dc76f5a046ebbda40c26f
Reviewed-on: https://cl.tvl.fyi/c/depot/+/6078
Tested-by: BuildkiteCI
Autosubmit: tazjin <tazjin@tvl.su>
Reviewed-by: grfn <grfn@gws.fyi>
2022-08-12 14:09:27 +00:00
Vincent Ambo
28f57abac1 refactor(tvix/compiler): use rnix's typed AST for literal values
Change-Id: Ic56ab64ad82343c7cdf8168ef41ee0a97f7e1dd9
Reviewed-on: https://cl.tvl.fyi/c/depot/+/6077
Tested-by: BuildkiteCI
Reviewed-by: grfn <grfn@gws.fyi>
2022-08-12 13:24:10 +00:00
Vincent Ambo
18fe188c3e feat(tvix/compiler): implement parens precedence
Change-Id: I8944354b3690d7504e4fe4254f14be5b849b9bcf
Reviewed-on: https://cl.tvl.fyi/c/depot/+/6076
Tested-by: BuildkiteCI
Reviewed-by: grfn <grfn@gws.fyi>
2022-08-12 13:24:10 +00:00
Vincent Ambo
72be759e1e feat(tvix/eval): implement unary negation operator
Change-Id: I5d012cc073e55d79d7b34b88283aab3164864293
Reviewed-on: https://cl.tvl.fyi/c/depot/+/6075
Tested-by: BuildkiteCI
Reviewed-by: grfn <grfn@gws.fyi>
2022-08-12 13:24:10 +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
e96a2934ad feat(tvix/eval): add error variant for runtime type errors
Change-Id: I74155cf01766b7a991a69522945bff67fbca5a16
Reviewed-on: https://cl.tvl.fyi/c/depot/+/6073
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
d59968649e feat(tvix/eval): add initial stack-based VM
This can't do anything other than compute a single literal, for now

Change-Id: Ia28f9da51c906b590a198e77a4ca5d45a871106b
Reviewed-on: https://cl.tvl.fyi/c/depot/+/6071
Tested-by: BuildkiteCI
Reviewed-by: grfn <grfn@gws.fyi>
2022-08-12 13:05:16 +00:00
Vincent Ambo
34df2c8473 feat(tvix/eval): add initial barebones compiler
This compiler can only take care of very trivial literals so far.

Change-Id: I9dfac75a801b7235f868061a979ae24159fe1425
Reviewed-on: https://cl.tvl.fyi/c/depot/+/6070
Tested-by: BuildkiteCI
Reviewed-by: grfn <grfn@gws.fyi>
2022-08-12 13:05:16 +00:00
Vincent Ambo
3aaefc3000 feat(tvix/eval): add initial chunk representation
Change-Id: I53202e93938bede421c8f1c98901e4c67544e257
Reviewed-on: https://cl.tvl.fyi/c/depot/+/6069
Tested-by: BuildkiteCI
Reviewed-by: grfn <grfn@gws.fyi>
2022-08-12 13:05:16 +00:00
Vincent Ambo
48a7449834 feat(tvix/eval): add initial opcode representation
Change-Id: Ibc7685a6b0b92e08f0b6c82cf7d9b04fbb593a4e
Reviewed-on: https://cl.tvl.fyi/c/depot/+/6068
Tested-by: BuildkiteCI
Reviewed-by: grfn <grfn@gws.fyi>
2022-08-12 13:05:16 +00:00
Vincent Ambo
8b7d2fd59e feat(tvix/eval): add initial value representation
Change-Id: I427a04e89994662df2750dffe21991bad48aab15
Reviewed-on: https://cl.tvl.fyi/c/depot/+/6066
Tested-by: BuildkiteCI
Reviewed-by: grfn <grfn@gws.fyi>
2022-08-12 12:39:19 +00:00
Vincent Ambo
bef8d67b6c chore(tvix/eval): add rnix-parser dependency
Change-Id: I81bd8416b3837a728ecd7911fe1ca06e89b9e90e
Reviewed-on: https://cl.tvl.fyi/c/depot/+/6065
Tested-by: BuildkiteCI
Reviewed-by: grfn <grfn@gws.fyi>
2022-08-12 12:39:19 +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
Vincent Ambo
a9b2157fba chore(tvix/eval): check in naersk-based default.nix
Change-Id: I9ff0c4a196747361a3e421863beaff07a4972b0f
Reviewed-on: https://cl.tvl.fyi/c/depot/+/6067
Tested-by: BuildkiteCI
Reviewed-by: grfn <grfn@gws.fyi>
2022-08-12 12:39:19 +00:00
Vincent Ambo
7be4581876 docs(tvix/eval): Add initial evaluator README
Change-Id: I85df002dc13c91a184d064586244f6a7440320fb
Reviewed-on: https://cl.tvl.fyi/c/depot/+/6063
Tested-by: BuildkiteCI
Reviewed-by: grfn <grfn@gws.fyi>
2022-08-12 12:34:29 +00:00
Vincent Ambo
d1bf3d3577 feat(tvix/eval): check in generated project skeleton
Change-Id: Iecc8283abb289de71f22076fd88892f6ded99cb3
Reviewed-on: https://cl.tvl.fyi/c/depot/+/6062
Tested-by: BuildkiteCI
Reviewed-by: grfn <grfn@gws.fyi>
2022-08-12 12:34:29 +00:00