Files
nixjit/src/ty/internal/list.rs

80 lines
1.6 KiB
Rust

use std::ops::Deref;
use std::rc::Weak;
use ecow::EcoVec;
use hashbrown::HashSet;
use crate::env::VmEnv;
use crate::ty::public as p;
use crate::engine::Engine;
use super::Value;
#[derive(Clone, PartialEq)]
pub struct List {
data: EcoVec<Value>,
}
impl Default for List {
fn default() -> Self {
Self::new()
}
}
impl<'gc, T: Into<EcoVec<Value>>> From<T> for List {
fn from(value: T) -> Self {
Self { data: value.into() }
}
}
impl Deref for List {
type Target = [Value];
fn deref(&self) -> &Self::Target {
&self.data
}
}
impl List {
pub fn new() -> Self {
List { data: EcoVec::new() }
}
pub fn with_capacity(cap: usize) -> Self {
List {
data: EcoVec::with_capacity(cap),
}
}
pub fn push(&mut self, elem: Value) {
self.data.push(elem);
}
pub fn concat(&mut self, other: &List) {
for elem in other.data.iter() {
self.data.push(elem.clone());
}
}
pub fn capture(&mut self, env: &Weak<VmEnv>) {
self.data.iter().for_each(|v| {
if let Value::Thunk(ref thunk) = v.clone() {
todo!()
// thunk.capture_env_weak(env.clone());
}
})
}
pub fn into_inner(self) -> EcoVec<Value> {
self.data
}
pub fn to_public(&self, engine: &Engine, seen: &mut HashSet<Value>) -> p::Value {
p::Value::List(p::List::new(
self.data
.iter()
.map(|value| value.clone().to_public(engine, seen))
.collect(),
))
}
}