Skip to content
This repository was archived by the owner on Jun 11, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 7 additions & 36 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/uplc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ secp256k1 = "0.30.0"
thiserror = "1.0.63"

[dev-dependencies]
criterion = { version = "0.5.1", features = ["html_reports"] }
criterion = { version = "0.7.0", features = ["html_reports"] }
insta = "1.40.0"
itertools = "0.13.0"
ouroboros = "0.18.4"
Expand Down
45 changes: 33 additions & 12 deletions crates/uplc/src/machine/env.rs
Original file line number Diff line number Diff line change
@@ -1,31 +1,52 @@
use bumpalo::{collections::Vec as BumpVec, Bump};
use bumpalo::Bump;

use crate::binder::Eval;

use super::value::Value;

#[derive(Debug)]
pub struct Env<'a, V>(BumpVec<'a, &'a Value<'a, V>>)
pub enum Env<'a, V>
where
V: Eval<'a>;
V: Eval<'a>,
{
Empty,
Cons {
data: &'a Value<'a, V>,
next: &'a Env<'a, V>,
},
}

impl<'a, V> Env<'a, V>
where
V: Eval<'a>,
{
pub fn new_in(arena: &'a Bump) -> &'a Self {
arena.alloc(Self(BumpVec::new_in(arena)))
arena.alloc(Self::Empty)
}

pub fn push(&'a self, arena: &'a Bump, argument: &'a Value<'a, V>) -> &'a Self {
let mut new_env = self.0.clone();

new_env.push(argument);

arena.alloc(Self(new_env))
pub fn push(&'a self, arena: &'a Bump, arg: &'a Value<'a, V>) -> &'a Self {
arena.alloc(Self::Cons {
data: arg,
next: self,
})
}

pub fn lookup(&'a self, name: usize) -> Option<&'a Value<'a, V>> {
self.0.get(self.0.len() - name).copied()
// De Bruijn indices are 1-based
// So the data at the env[i] is at De Bruijn index i-1
pub fn lookup(&self, index: usize) -> Option<&'a Value<'a, V>> {
if index == 0 {
return None;
}

match self {
Env::Empty => None,
Env::Cons { data, next: parent } => {
if index == 1 {
return Some(data);
}

parent.lookup(index - 1)
Comment thread
yHSJ marked this conversation as resolved.
}
}
}
}
Loading