chore: cargo fmt
This commit is contained in:
@@ -2,7 +2,7 @@ use std::cell::RefCell;
|
||||
use std::sync::Arc;
|
||||
|
||||
use crate::ty::common::Symbol;
|
||||
use crate::ty::internal::{Const, PrimOp, RecAttrSet, Thunk, Value, _Thunk};
|
||||
use crate::ty::internal::{_Thunk, Const, PrimOp, RecAttrSet, Thunk, Value};
|
||||
use crate::vm::Env;
|
||||
|
||||
pub fn env() -> Arc<Env> {
|
||||
@@ -50,12 +50,17 @@ pub fn env() -> Arc<Env> {
|
||||
Symbol::from(format!("__{}", primop.name)),
|
||||
Value::PrimOp(primop.clone()),
|
||||
);
|
||||
map.borrow_mut().insert_mut(Symbol::from(primop.name), Value::PrimOp(primop));
|
||||
map.borrow_mut()
|
||||
.insert_mut(Symbol::from(primop.name), Value::PrimOp(primop));
|
||||
}
|
||||
let builtins = Value::RecAttrSet(RecAttrSet::from_inner(map.clone()));
|
||||
let thunk= Thunk { thunk: RefCell::new(_Thunk::Value(Box::new(builtins.clone()))), env: RefCell::default() };
|
||||
let thunk = Thunk {
|
||||
thunk: RefCell::new(_Thunk::Value(Box::new(builtins.clone()))),
|
||||
env: RefCell::default(),
|
||||
};
|
||||
thunk.capture(Arc::new(builtins_env));
|
||||
map.borrow_mut().insert_mut(Symbol::from("builtins"), Value::Thunk(thunk));
|
||||
map.borrow_mut()
|
||||
.insert_mut(Symbol::from("builtins"), Value::Thunk(thunk));
|
||||
|
||||
env.insert(Symbol::from("builtins"), builtins);
|
||||
env
|
||||
|
||||
@@ -6,7 +6,9 @@ mod ir;
|
||||
pub fn compile(expr: &str) -> anyhow::Result<crate::bytecode::Program> {
|
||||
let root = rnix::Root::parse(expr);
|
||||
if !root.errors().is_empty() {
|
||||
return Err(anyhow::anyhow!(root.errors().iter().map(|err| err.to_string()).join(";")))
|
||||
return Err(anyhow::anyhow!(
|
||||
root.errors().iter().map(|err| err.to_string()).join(";")
|
||||
));
|
||||
}
|
||||
assert!(root.errors().is_empty());
|
||||
let expr = root.tree().expr().unwrap();
|
||||
|
||||
@@ -41,7 +41,8 @@ impl Display for Symbol {
|
||||
}
|
||||
}
|
||||
|
||||
static REGEX: LazyLock<Regex> = LazyLock::new(|| Regex::new(r#"^[a-zA-Z\_][a-zA-Z0-9\_\'\-]*$"#).unwrap());
|
||||
static REGEX: LazyLock<Regex> =
|
||||
LazyLock::new(|| Regex::new(r#"^[a-zA-Z\_][a-zA-Z0-9\_\'\-]*$"#).unwrap());
|
||||
impl Symbol {
|
||||
fn normal(&self) -> bool {
|
||||
!REGEX.is_match(self)
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
use std::cell::RefCell;
|
||||
use std::sync::Arc;
|
||||
|
||||
use anyhow::{anyhow, Result};
|
||||
use anyhow::{Result, anyhow};
|
||||
use derive_more::{IsVariant, Unwrap};
|
||||
|
||||
use super::common::Catchable;
|
||||
use super::common as c;
|
||||
use super::common::Catchable;
|
||||
use super::public as p;
|
||||
|
||||
use c::Symbol;
|
||||
|
||||
use crate::vm::{VM, Env};
|
||||
use crate::bytecode::OpCodes;
|
||||
use crate::vm::{Env, VM};
|
||||
|
||||
mod attrset;
|
||||
mod cnst;
|
||||
@@ -187,7 +187,7 @@ impl Value {
|
||||
Catchable(_) => todo!(),
|
||||
PrimOp(_) => "lambda",
|
||||
PartialPrimOp(_) => "lambda",
|
||||
Func(_) => "lambda"
|
||||
Func(_) => "lambda",
|
||||
}
|
||||
}
|
||||
|
||||
@@ -380,7 +380,10 @@ impl Value {
|
||||
)))));
|
||||
*self = val;
|
||||
} else {
|
||||
*self = Value::Catchable(Catchable::new(Some(format!("cannot select from {:?}", self.typename()))))
|
||||
*self = Value::Catchable(Catchable::new(Some(format!(
|
||||
"cannot select from {:?}",
|
||||
self.typename()
|
||||
))))
|
||||
}
|
||||
self
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ impl Debug for AttrSet {
|
||||
match v {
|
||||
List(_) => write!(f, "{k:?} = [ ... ]; ")?,
|
||||
AttrSet(_) => write!(f, "{k:?} = {{ ... }}; ")?,
|
||||
v => write!(f, "{k:?} = {v:?}; ")?
|
||||
v => write!(f, "{k:?} = {v:?}; ")?,
|
||||
}
|
||||
}
|
||||
write!(f, "}}")
|
||||
|
||||
@@ -15,8 +15,13 @@ pub struct Env {
|
||||
impl Clone for Env {
|
||||
fn clone(&self) -> Self {
|
||||
Env {
|
||||
last: RefCell::new(self.last.borrow().clone().map(|e| Arc::new(e.as_ref().clone()))),
|
||||
map: Arc::new(RefCell::new(self.map.borrow().clone()))
|
||||
last: RefCell::new(
|
||||
self.last
|
||||
.borrow()
|
||||
.clone()
|
||||
.map(|e| Arc::new(e.as_ref().clone())),
|
||||
),
|
||||
map: Arc::new(RefCell::new(self.map.borrow().clone())),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,6 @@ mod vm;
|
||||
#[cfg(test)]
|
||||
mod test;
|
||||
|
||||
pub use env::{Env, CapturedEnv};
|
||||
pub use env::{CapturedEnv, Env};
|
||||
pub use vm::VM;
|
||||
pub use vm::run;
|
||||
|
||||
@@ -202,7 +202,10 @@ impl VM {
|
||||
val.force(self)?;
|
||||
val.coerce_to_string();
|
||||
let sym = val.unwrap_const().unwrap_string().into();
|
||||
stack.tos_mut()?.force(self)?.select_with_default(sym, default);
|
||||
stack
|
||||
.tos_mut()?
|
||||
.force(self)?
|
||||
.select_with_default(sym, default);
|
||||
}
|
||||
OpCode::HasAttr { sym } => {
|
||||
stack.tos_mut()?.force(self)?.has_attr(Symbol::new(sym));
|
||||
|
||||
Reference in New Issue
Block a user