diff options
Diffstat (limited to 'tvix/eval/src')
-rw-r--r-- | tvix/eval/src/opcode.rs | 2 | ||||
-rw-r--r-- | tvix/eval/src/value/mod.rs | 8 | ||||
-rw-r--r-- | tvix/eval/src/vm.rs | 17 |
3 files changed, 24 insertions, 3 deletions
diff --git a/tvix/eval/src/opcode.rs b/tvix/eval/src/opcode.rs index 73cf2098fe21..b072febd42fb 100644 --- a/tvix/eval/src/opcode.rs +++ b/tvix/eval/src/opcode.rs @@ -41,12 +41,14 @@ pub enum OpCode { OpJump(usize), OpJumpIfTrue(usize), OpJumpIfFalse(usize), + OpJumpIfNotFound(usize), // Attribute sets OpAttrs(usize), OpAttrPath(usize), OpAttrsUpdate, OpAttrsSelect, + OpAttrOrNotFound, OpAttrsIsSet, // Lists diff --git a/tvix/eval/src/value/mod.rs b/tvix/eval/src/value/mod.rs index 355678fb7496..e9fdc40ac5c6 100644 --- a/tvix/eval/src/value/mod.rs +++ b/tvix/eval/src/value/mod.rs @@ -26,6 +26,7 @@ pub enum Value { // are never returned to or created directly by users. AttrPath(Vec<NixString>), Blackhole, + NotFound, } impl Value { @@ -48,7 +49,7 @@ impl Value { Value::List(_) => "list", // Internal types - Value::AttrPath(_) | Value::Blackhole => "internal", + Value::AttrPath(_) | Value::Blackhole | Value::NotFound => "internal", } } @@ -116,8 +117,9 @@ impl Display for Value { )), // internal types - Value::AttrPath(_) => f.write_str("internal<attrpath>"), - Value::Blackhole => f.write_str("internal<blackhole>"), + Value::AttrPath(_) => f.write_str("internal[attrpath]"), + Value::Blackhole => f.write_str("internal[blackhole]"), + Value::NotFound => f.write_str("internal[not found]"), } } } diff --git a/tvix/eval/src/vm.rs b/tvix/eval/src/vm.rs index 332398d7b9ff..232e27aabbd3 100644 --- a/tvix/eval/src/vm.rs +++ b/tvix/eval/src/vm.rs @@ -173,6 +173,16 @@ impl VM { } } + OpCode::OpAttrOrNotFound => { + let key = self.pop().as_string()?; + let attrs = self.pop().as_attrs()?; + + match attrs.select(key.as_str()) { + Some(value) => self.push(value.clone()), + None => self.push(Value::NotFound), + } + } + OpCode::OpAttrsIsSet => { let key = self.pop().as_string()?; let attrs = self.pop().as_attrs()?; @@ -210,6 +220,13 @@ impl VM { } } + OpCode::OpJumpIfNotFound(offset) => { + if matches!(self.peek(0), Value::NotFound) { + self.pop(); + self.ip += offset; + } + } + // These assertion operations error out if the stack // top is not of the expected type. This is necessary // to implement some specific behaviours of Nix |