misc: remove unnecessary constants
This is premature optimization.
This commit is contained in:
parent
1d16187846
commit
ad66e839fa
2 changed files with 10 additions and 16 deletions
|
@ -1,6 +1,6 @@
|
||||||
use std::{borrow::Borrow, cell::RefCell, collections::HashMap, rc::Rc};
|
use std::{borrow::Borrow, cell::RefCell, collections::HashMap, rc::Rc};
|
||||||
|
|
||||||
use super::{eval_ast_node, Error, Expression, FALSE, TRUE};
|
use super::{eval_ast_node, Error, Expression};
|
||||||
use crate::parser::Node;
|
use crate::parser::Node;
|
||||||
|
|
||||||
pub type RawEnvironment = HashMap<String, Rc<Expression>>;
|
pub type RawEnvironment = HashMap<String, Rc<Expression>>;
|
||||||
|
@ -135,10 +135,10 @@ pub fn core_environment() -> Rc<Environment> {
|
||||||
}
|
}
|
||||||
|
|
||||||
if args[0] == args[1] {
|
if args[0] == args[1] {
|
||||||
return Ok(TRUE.with(|inner| inner.clone()));
|
return Ok(Expression::Boolean(true).into());
|
||||||
}
|
}
|
||||||
|
|
||||||
return Ok(FALSE.with(|inner| inner.clone()));
|
Ok(Expression::Boolean(false).into())
|
||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
|
@ -148,11 +148,11 @@ pub fn core_environment() -> Rc<Environment> {
|
||||||
Err(Error::MismatchedArgCount(1, args.len()))?
|
Err(Error::MismatchedArgCount(1, args.len()))?
|
||||||
}
|
}
|
||||||
|
|
||||||
if FALSE.with(|inner| &args[0] == inner) {
|
if *args[0] == Expression::Boolean(false) {
|
||||||
return Ok(TRUE.with(|inner| inner.clone()));
|
return Ok(Expression::Boolean(true).into());
|
||||||
}
|
}
|
||||||
|
|
||||||
return Ok(FALSE.with(|inner| inner.clone()));
|
Ok(Expression::Boolean(false).into())
|
||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
// Branching
|
// Branching
|
||||||
|
|
|
@ -8,12 +8,6 @@ use crate::parser::Node;
|
||||||
mod env;
|
mod env;
|
||||||
pub use env::{core_environment, Environment};
|
pub use env::{core_environment, Environment};
|
||||||
|
|
||||||
thread_local! {
|
|
||||||
static TRUE: Rc<Expression> = Rc::new(Expression::Boolean(true));
|
|
||||||
static FALSE: Rc<Expression> = Rc::new(Expression::Boolean(false));
|
|
||||||
static NIL: Rc<Expression> = Rc::new(Expression::Nil);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq)]
|
||||||
pub enum Expression {
|
pub enum Expression {
|
||||||
// Values
|
// Values
|
||||||
|
@ -108,7 +102,7 @@ fn eval_ast_node(env: Rc<Environment>, ast_node: Node) -> Result<Rc<Expression>>
|
||||||
Node::List(list) => {
|
Node::List(list) => {
|
||||||
// Empty lists are nil in scheme
|
// Empty lists are nil in scheme
|
||||||
if list.is_empty() {
|
if list.is_empty() {
|
||||||
return Ok(NIL.with(|v| v.clone()));
|
return Ok(Expression::Nil.into());
|
||||||
}
|
}
|
||||||
|
|
||||||
// We always assume lists evaluate
|
// We always assume lists evaluate
|
||||||
|
@ -163,9 +157,9 @@ fn eval_ast_node(env: Rc<Environment>, ast_node: Node) -> Result<Rc<Expression>>
|
||||||
Node::Keyword(val) => Expression::Keyword(val).into(),
|
Node::Keyword(val) => Expression::Keyword(val).into(),
|
||||||
Node::String(s) => Expression::String(s).into(),
|
Node::String(s) => Expression::String(s).into(),
|
||||||
|
|
||||||
Node::True => TRUE.with(|val| val.clone()),
|
Node::True => Expression::Boolean(true).into(),
|
||||||
Node::False => FALSE.with(|val| val.clone()),
|
Node::False => Expression::Boolean(false).into(),
|
||||||
Node::Nil => NIL.with(|val| val.clone()),
|
Node::Nil => Expression::Nil.into(),
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(expr)
|
Ok(expr)
|
||||||
|
|
Loading…
Reference in a new issue