diff --git a/src/ast.h b/src/ast.h index 243f4d9..7f3edfc 100644 --- a/src/ast.h +++ b/src/ast.h @@ -201,7 +201,9 @@ public: False, }; + Constant() = default; Constant(State state); + Constant(bool state); virtual ~Constant() = default; State state() const { return m_state; } @@ -209,7 +211,7 @@ public: private: virtual bool isConstant() const override { return true; } - const State m_state; + const State m_state { State::Nil }; }; // ----------------------------------------- diff --git a/src/functions.cpp b/src/functions.cpp index 8438c1b..bb06d72 100644 --- a/src/functions.cpp +++ b/src/functions.cpp @@ -238,7 +238,7 @@ ADD_FUNCTION("pr-str", PRINTER_STRING(true, " ")); } \ print("\n"); \ \ - return makePtr(Constant::Nil); \ + return makePtr(); \ } ADD_FUNCTION("prn", PRINTER_PRINT(true)); @@ -478,6 +478,10 @@ ADD_FUNCTION( { CHECK_ARG_COUNT_IS("vec", nodes.size(), 1); + if (is(nodes.front().get())) { + return nodes.front(); + } + VALUE_CAST(collection, Collection, nodes.front()); return makePtr(collection->nodes()); @@ -515,13 +519,13 @@ ADD_FUNCTION( if (is(nodes.front().get()) && std::static_pointer_cast(nodes.front())->state() == Constant::Nil) { - return makePtr(Constant::Nil); + return makePtr(); } VALUE_CAST(collection, Collection, nodes.front()); auto collection_nodes = collection->nodes(); - return (collection_nodes.empty()) ? makePtr(Constant::Nil) : collection_nodes.front(); + return (collection_nodes.empty()) ? makePtr() : collection_nodes.front(); }); // (rest (list 1 2 3)) diff --git a/src/reader.cpp b/src/reader.cpp index 15cfcb7..4242b52 100644 --- a/src/reader.cpp +++ b/src/reader.cpp @@ -191,7 +191,7 @@ ValuePtr Reader::readHashMap() } if (!is(key.get()) && !is(key.get())) { - Error::the().add(format("{} is not a string or keyword", key)); + Error::the().add(format("wrong argument type: string or keyword, {}", key)); return nullptr; }