refactor(tvix/eval): extract recursive scope logic into a helper
This needs to be reused between let & `rec` attrs. Change-Id: I4a3bb90af4be32771b0f9e405c19370e105c0fef Reviewed-on: https://cl.tvl.fyi/c/depot/+/6608 Reviewed-by: sterni <sternenseemann@systemli.org> Tested-by: BuildkiteCI
This commit is contained in:
parent
01a239c955
commit
1cf07051cb
1 changed files with 14 additions and 7 deletions
|
@ -520,12 +520,10 @@ impl Compiler<'_, '_> {
|
|||
self.patch_jump(else_idx); // patch jump *over* else body
|
||||
}
|
||||
|
||||
/// Compile a standard `let ...; in ...` statement.
|
||||
///
|
||||
/// Unless in a non-standard scope, the encountered values are
|
||||
/// simply pushed on the stack and their indices noted in the
|
||||
/// entries vector.
|
||||
fn compile_let_in(&mut self, slot: LocalIdx, node: ast::LetIn) {
|
||||
fn compile_recursive_scope<N>(&mut self, slot: LocalIdx, node: &N)
|
||||
where
|
||||
N: AstNode + ast::HasEntry,
|
||||
{
|
||||
self.scope_mut().begin_scope();
|
||||
|
||||
// First pass to find all plain inherits (if they are not useless).
|
||||
|
@ -638,9 +636,18 @@ impl Compiler<'_, '_> {
|
|||
for idx in indices {
|
||||
if self.scope()[idx].needs_finaliser {
|
||||
let stack_idx = self.scope().stack_index(idx);
|
||||
self.push_op(OpCode::OpFinalise(stack_idx), &node);
|
||||
self.push_op(OpCode::OpFinalise(stack_idx), node);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Compile a standard `let ...; in ...` statement.
|
||||
///
|
||||
/// Unless in a non-standard scope, the encountered values are
|
||||
/// simply pushed on the stack and their indices noted in the
|
||||
/// entries vector.
|
||||
fn compile_let_in(&mut self, slot: LocalIdx, node: ast::LetIn) {
|
||||
self.compile_recursive_scope(slot, &node);
|
||||
|
||||
// Deal with the body, then clean up the locals afterwards.
|
||||
self.compile(slot, node.body().unwrap());
|
||||
|
|
Loading…
Reference in a new issue