From 208abaae43586d4bcafa6a5b0e1fea1dd74f0a00 Mon Sep 17 00:00:00 2001 From: Stephen Thirlwall Date: Sat, 28 Mar 2015 16:22:26 +1100 Subject: [PATCH] Fix bugs introduced in reader hash-map/{} change Only apparent in double-self-hosting mode. eg. ../cpp/stepA_mal ./stepA_mal.mal ./stepA_mal.mal Throws an error that MACROEXPAND is not defined. TODO: figure out why modifying he hash in-place doesn't work. --- cpp/Types.cpp | 14 ++++++++------ cpp/Types.h | 4 ++-- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/cpp/Types.cpp b/cpp/Types.cpp index d9027719..36d9254b 100644 --- a/cpp/Types.cpp +++ b/cpp/Types.cpp @@ -193,13 +193,15 @@ malHash::dissoc(malValueIter argsBegin, malValueIter argsEnd) const malValuePtr malHash::eval(malEnvPtr env) { - if (!m_isEvaluated) { - for (auto it = m_map.begin(), end = m_map.end(); it != end; ++it) { - it->second = EVAL(it->second, env); - } - m_isEvaluated = true; + if (m_isEvaluated) { + return malValuePtr(this); } - return malValuePtr(this); + + malHash::Map map; + for (auto it = m_map.begin(), end = m_map.end(); it != end; ++it) { + map[it->first] = EVAL(it->second, env); + } + return mal::hash(map); } malValuePtr malHash::get(malValuePtr key) const diff --git a/cpp/Types.h b/cpp/Types.h index fb4b8245..bc76d82d 100644 --- a/cpp/Types.h +++ b/cpp/Types.h @@ -254,8 +254,8 @@ public: WITH_META(malHash); private: - Map m_map; - bool m_isEvaluated; + const Map m_map; + const bool m_isEvaluated; }; class malBuiltIn : public malApplicable { -- 2.20.1