refactor(tvix/eval): rename Value::NotFound & OpAttrOrNotFound
grfn suggested clearer naming for these in cl/6166. Change-Id: I83164bf1d1902ebd42272e9d5d63819a0f6a72c5 Reviewed-on: https://cl.tvl.fyi/c/depot/+/6277 Reviewed-by: grfn <grfn@gws.fyi> Tested-by: BuildkiteCI
This commit is contained in:
parent
903b57be04
commit
7da5076191
4 changed files with 10 additions and 10 deletions
|
@ -429,7 +429,7 @@ impl Compiler {
|
||||||
// next nested element, for all fragments except the last one.
|
// next nested element, for all fragments except the last one.
|
||||||
for (count, fragment) in node.attrpath().unwrap().attrs().enumerate() {
|
for (count, fragment) in node.attrpath().unwrap().attrs().enumerate() {
|
||||||
if count > 0 {
|
if count > 0 {
|
||||||
self.chunk().push_op(OpCode::OpAttrOrNotFound);
|
self.chunk().push_op(OpCode::OpAttrsTrySelect);
|
||||||
}
|
}
|
||||||
|
|
||||||
self.compile_attr(fragment);
|
self.compile_attr(fragment);
|
||||||
|
@ -616,7 +616,7 @@ impl Compiler {
|
||||||
|
|
||||||
for fragment in path.attrs() {
|
for fragment in path.attrs() {
|
||||||
self.compile_attr(fragment);
|
self.compile_attr(fragment);
|
||||||
self.chunk().push_op(OpCode::OpAttrOrNotFound);
|
self.chunk().push_op(OpCode::OpAttrsTrySelect);
|
||||||
jumps.push(self.chunk().push_op(OpCode::OpJumpIfNotFound(0)));
|
jumps.push(self.chunk().push_op(OpCode::OpJumpIfNotFound(0)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -50,7 +50,7 @@ pub enum OpCode {
|
||||||
OpAttrPath(usize),
|
OpAttrPath(usize),
|
||||||
OpAttrsUpdate,
|
OpAttrsUpdate,
|
||||||
OpAttrsSelect,
|
OpAttrsSelect,
|
||||||
OpAttrOrNotFound,
|
OpAttrsTrySelect,
|
||||||
OpAttrsIsSet,
|
OpAttrsIsSet,
|
||||||
|
|
||||||
// `with`-handling
|
// `with`-handling
|
||||||
|
|
|
@ -33,7 +33,7 @@ pub enum Value {
|
||||||
// Internal values that, while they technically exist at runtime,
|
// Internal values that, while they technically exist at runtime,
|
||||||
// are never returned to or created directly by users.
|
// are never returned to or created directly by users.
|
||||||
AttrPath(Vec<NixString>),
|
AttrPath(Vec<NixString>),
|
||||||
NotFound,
|
AttrNotFound,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Value {
|
impl Value {
|
||||||
|
@ -54,7 +54,7 @@ impl Value {
|
||||||
Value::Closure(_) | Value::Builtin(_) => "lambda",
|
Value::Closure(_) | Value::Builtin(_) => "lambda",
|
||||||
|
|
||||||
// Internal types
|
// Internal types
|
||||||
Value::AttrPath(_) | Value::NotFound => "internal",
|
Value::AttrPath(_) | Value::AttrNotFound => "internal",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -140,7 +140,7 @@ impl Display for Value {
|
||||||
|
|
||||||
// internal types
|
// internal types
|
||||||
Value::AttrPath(path) => write!(f, "internal[attrpath({})]", path.len()),
|
Value::AttrPath(path) => write!(f, "internal[attrpath({})]", path.len()),
|
||||||
Value::NotFound => f.write_str("internal[not found]"),
|
Value::AttrNotFound => f.write_str("internal[not found]"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -225,15 +225,15 @@ impl VM {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
OpCode::OpAttrOrNotFound => {
|
OpCode::OpAttrsTrySelect => {
|
||||||
let key = self.pop().to_string()?;
|
let key = self.pop().to_string()?;
|
||||||
let value = match self.pop() {
|
let value = match self.pop() {
|
||||||
Value::Attrs(attrs) => match attrs.select(key.as_str()) {
|
Value::Attrs(attrs) => match attrs.select(key.as_str()) {
|
||||||
Some(value) => value.clone(),
|
Some(value) => value.clone(),
|
||||||
None => Value::NotFound,
|
None => Value::AttrNotFound,
|
||||||
},
|
},
|
||||||
|
|
||||||
_ => Value::NotFound,
|
_ => Value::AttrNotFound,
|
||||||
};
|
};
|
||||||
|
|
||||||
self.push(value);
|
self.push(value);
|
||||||
|
@ -283,7 +283,7 @@ impl VM {
|
||||||
}
|
}
|
||||||
|
|
||||||
OpCode::OpJumpIfNotFound(offset) => {
|
OpCode::OpJumpIfNotFound(offset) => {
|
||||||
if matches!(self.peek(0), Value::NotFound) {
|
if matches!(self.peek(0), Value::AttrNotFound) {
|
||||||
self.pop();
|
self.pop();
|
||||||
self.frame_mut().ip += offset;
|
self.frame_mut().ip += offset;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue