refactor: type

This commit is contained in:
2025-05-03 20:33:59 +08:00
parent 3f0cb2c2fa
commit 4a310ff317
23 changed files with 475 additions and 309 deletions

42
src/ty/internal/list.rs Normal file
View File

@@ -0,0 +1,42 @@
use derive_more::Constructor;
use rpds::VectorSync;
use crate::ty::public as p;
use crate::vm::VM;
use super::{ToPublic, Value};
#[derive(Debug, Constructor, Clone, PartialEq)]
pub struct List {
data: VectorSync<Value>,
}
impl List {
pub fn empty() -> List {
List {
data: VectorSync::new_sync()
}
}
pub fn push(&mut self, elem: Value) {
self.data.push_back_mut(elem);
}
pub fn concat(mut self, other: List) -> List {
for elem in other.data.iter() {
self.data.push_back_mut(elem.clone());
}
self
}
}
impl ToPublic for List {
fn to_public(self, vm: &VM) -> p::Value {
p::Value::List(p::List::new(
self.data
.iter()
.map(|value| value.clone().to_public(vm))
.collect(),
))
}
}