diff options
author | Vincent Ambo <mail@tazj.in> | 2022-08-13T14·34+0300 |
---|---|---|
committer | tazjin <tazjin@tvl.su> | 2022-08-28T17·50+0000 |
commit | 691a596aac0381d7794c6969cb9793131aa998f3 (patch) | |
tree | 24c0f446f54986b9da070d9f7305d62b97dcdd4c /tvix/eval/src/vm.rs | |
parent | bbad338017c94efbf3fa966528b8e9c751449328 (diff) |
feat(tvix/eval): compile simple `let ... in ...` expressions r/4522
These expressions now leave the binding values on the stack, and clean up the scope after the body of the expression. While variable access is not yet implemented (as the identifier node remains unhandled), this already gives us the correct stack behaviour. Change-Id: I138c20ace9c64502c94b2c0f99a6077cd912c00d Reviewed-on: https://cl.tvl.fyi/c/depot/+/6188 Tested-by: BuildkiteCI Reviewed-by: grfn <grfn@gws.fyi>
Diffstat (limited to 'tvix/eval/src/vm.rs')
-rw-r--r-- | tvix/eval/src/vm.rs | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/tvix/eval/src/vm.rs b/tvix/eval/src/vm.rs index 232e27aabbd3..eb860eae007e 100644 --- a/tvix/eval/src/vm.rs +++ b/tvix/eval/src/vm.rs @@ -240,6 +240,20 @@ impl VM { }); } } + + // Remove the given number of elements from the stack, + // but retain the top value. + OpCode::OpCloseScope(count) => { + // Immediately move the top value into the right + // position. + let target_idx = self.stack.len() - 1 - count; + self.stack[target_idx] = self.pop(); + + // Then drop the remaining values. + for _ in 0..(count - 1) { + self.pop(); + } + } } if self.ip == self.chunk.code.len() { |