ombre: Remove redundant `Rc`
720a030798bbafebe9b9abebec6dd68a5b9c45e5
1 parent
9236b333
ombre/src/lisp/evaluator.rs
+7 -4
| 248 | 248 | } |
|
| 249 | 249 | } |
|
| 250 | 250 | ||
| 251 | 251 | impl From<Intrinsic> for Expr { |
|
| 252 | 252 | fn from(value: Intrinsic) -> Self { |
|
| 253 | - | Expr::Function(Function::Intrinsic(Rc::new(value))) |
|
| 253 | + | Expr::Function(Function::Intrinsic(value)) |
|
| 254 | 254 | } |
|
| 255 | 255 | } |
|
| 256 | 256 | ||
| 257 | 257 | impl From<Closure> for Expr { |
|
| 258 | 258 | fn from(value: Closure) -> Self { |
| 375 | 375 | #[derive(Debug, Clone)] |
|
| 376 | 376 | pub enum Function { |
|
| 377 | 377 | /// A function that closes over some environment. |
|
| 378 | 378 | Closure(Rc<Closure>), |
|
| 379 | 379 | /// A built-in function implemented natively. |
|
| 380 | - | Intrinsic(Rc<Intrinsic>), |
|
| 380 | + | Intrinsic(Intrinsic), |
|
| 381 | 381 | } |
|
| 382 | 382 | ||
| 383 | 383 | impl Function { |
|
| 384 | 384 | /// Get the pointer to the internal object. |
|
| 385 | 385 | fn as_ptr(&self) -> *const () { |
|
| 386 | 386 | match self { |
|
| 387 | 387 | Self::Closure(f) => Rc::as_ptr(f) as *const (), |
|
| 388 | - | Self::Intrinsic(f) => Rc::as_ptr(f) as *const (), |
|
| 388 | + | Self::Intrinsic(Intrinsic(f)) => Rc::as_ptr(f) as *const (), |
|
| 389 | 389 | } |
|
| 390 | 390 | } |
|
| 391 | 391 | ||
| 392 | 392 | /// Apply the function. |
|
| 393 | 393 | fn apply(&self, args: impl Iterator<Item = Expr>, env: &mut Env<'_>) -> Result<Expr> { |
| 423 | 423 | ||
| 424 | 424 | impl PartialEq for Function { |
|
| 425 | 425 | fn eq(&self, other: &Self) -> bool { |
|
| 426 | 426 | match (self, other) { |
|
| 427 | 427 | (Self::Closure(ref a), Self::Closure(ref b)) => Rc::ptr_eq(a, b), |
|
| 428 | - | (Self::Intrinsic(ref a), Self::Intrinsic(ref b)) => Rc::ptr_eq(a, b), |
|
| 428 | + | (Self::Intrinsic(Intrinsic(ref a)), Self::Intrinsic(Intrinsic(ref b))) => { |
|
| 429 | + | Rc::ptr_eq(a, b) |
|
| 430 | + | } |
|
| 429 | 431 | _ => false, |
|
| 430 | 432 | } |
|
| 431 | 433 | } |
|
| 432 | 434 | } |
|
| 433 | 435 |
| 501 | 503 | ||
| 502 | 504 | /// A natively implemented function. |
|
| 503 | 505 | pub type IntrinsicFn = fn(Vec<Expr>, &Env<'_>) -> Result<Expr>; |
|
| 504 | 506 | ||
| 505 | 507 | /// Built-in function intrinsic to the language. |
|
| 508 | + | #[derive(Clone)] |
|
| 506 | 509 | pub struct Intrinsic(Rc<dyn Fn(Vec<Expr>, &Env<'_>) -> Result<Expr>>); |
|
| 507 | 510 | ||
| 508 | 511 | impl PartialEq for Intrinsic { |
|
| 509 | 512 | fn eq(&self, other: &Self) -> bool { |
|
| 510 | 513 | Rc::ptr_eq(&self.0, &other.0) |