feat(tvix/eval): emit instructions for dynamic var resolution
If an unknown variable is encountered and the with stack is not empty, emit instructions for resolving the variable at runtime. Change-Id: I752f4bd0025335744e4747364abd1bd34130374e Reviewed-on: https://cl.tvl.fyi/c/depot/+/6223 Tested-by: BuildkiteCI Reviewed-by: sterni <sternenseemann@systemli.org> Reviewed-by: grfn <grfn@gws.fyi>
This commit is contained in:
parent
59f50dc81a
commit
89f566ef57
1 changed files with 11 additions and 1 deletions
|
@ -352,7 +352,17 @@ impl Compiler {
|
|||
// features are not yet implemented.
|
||||
match self.resolve_local(name) {
|
||||
Some(idx) => self.chunk.push_op(OpCode::OpGetLocal(idx)),
|
||||
None => return Err(Error::UnknownStaticVariable(node)),
|
||||
None => {
|
||||
if self.scope.with_stack.is_empty() {
|
||||
return Err(Error::UnknownStaticVariable(node));
|
||||
}
|
||||
|
||||
// Variable needs to be dynamically resolved
|
||||
// at runtime.
|
||||
let idx = self.chunk.push_constant(Value::String(name.into()));
|
||||
self.chunk.push_op(OpCode::OpConstant(idx));
|
||||
self.chunk.push_op(OpCode::OpResolveWith)
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue