refactor: function

This commit is contained in:
2025-05-10 20:01:56 +08:00
parent fa3193ea50
commit 046b03c60e
8 changed files with 293 additions and 277 deletions

View File

@@ -60,17 +60,15 @@ impl Thunk {
}
pub fn force(&self, vm: &VM) -> Result<Value> {
{
match &*self.thunk.borrow() {
_Thunk::Value(value) => return Ok(value.as_ref().clone()),
_Thunk::SuspendedFrom(from) => {
return Err(Error::EvalError(format!(
"thunk {:p} already suspended from {from:p} (infinite recursion encountered)",
self as *const Thunk
)));
}
_Thunk::Code(_) => (),
match &*self.thunk.borrow() {
_Thunk::Value(value) => return Ok(value.as_ref().clone()),
_Thunk::SuspendedFrom(from) => {
return Err(Error::EvalError(format!(
"thunk {:p} already suspended from {from:p} (infinite recursion encountered)",
self as *const Thunk
)));
}
_Thunk::Code(_) => (),
}
let opcodes = std::mem::replace(
&mut *self.thunk.borrow_mut(),
@@ -366,14 +364,14 @@ impl Value {
if let Value::AttrSet(attrs) = self {
let val = attrs
.select(sym.clone())
.unwrap_or(Value::Catchable(c::Catchable::new(Some(format!(
.unwrap_or_else(|| Value::Catchable(c::Catchable::new(Some(format!(
"{sym:?} not found"
)))));
*self = val;
} else if let Value::RecAttrSet(attrs) = self {
let val = attrs
.select(sym.clone())
.unwrap_or(Value::Catchable(c::Catchable::new(Some(format!(
.unwrap_or_else(|| Value::Catchable(c::Catchable::new(Some(format!(
"{sym:?} not found"
)))));
*self = val;