Browse Source

Eval: Speed up isMacroCall a bit

master
Riyyi 2 years ago
parent
commit
24eab1034e
  1. 1
      src/ast.h
  2. 14
      src/eval.cpp

1
src/ast.h

@ -65,6 +65,7 @@ public:
size_t size() const { return m_nodes.size(); } size_t size() const { return m_nodes.size(); }
bool empty() const { return m_nodes.size() == 0; } bool empty() const { return m_nodes.size() == 0; }
ValuePtr front() const { return m_nodes.front(); }
const std::list<ValuePtr>& nodes() const { return m_nodes; } const std::list<ValuePtr>& nodes() const { return m_nodes; }
protected: protected:

14
src/eval.cpp

@ -202,19 +202,23 @@ ValuePtr Eval::evalAst(ValuePtr ast, EnvironmentPtr env)
// (x y z) // (x y z)
bool Eval::isMacroCall(ValuePtr ast, EnvironmentPtr env) bool Eval::isMacroCall(ValuePtr ast, EnvironmentPtr env)
{ {
if (!is<List>(ast.get())) { auto list = dynamic_cast<List*>(ast.get());
if (list == nullptr || list->empty()) {
return false; return false;
} }
auto nodes = std::static_pointer_cast<List>(ast)->nodes(); auto front = list->front().get();
if (nodes.size() == 0 || !is<Symbol>(nodes.front().get())) { if (!is<Symbol>(front)) {
return false; return false;
} }
auto value = env->get(std::static_pointer_cast<Symbol>(nodes.front())->symbol()); auto symbol = dynamic_cast<Symbol*>(front)->symbol();
auto value = env->get(symbol).get();
auto lambda = dynamic_cast<Lambda*>(value);
if (!is<Lambda>(value.get()) || !std::static_pointer_cast<Lambda>(value)->isMacro()) { if (lambda == nullptr || !lambda->isMacro()) {
return false; return false;
} }

Loading…
Cancel
Save