Browse Source

AST+Env: Add default constructor to Constant

master
Riyyi 2 years ago
parent
commit
f89e73d44a
  1. 4
      src/ast.h
  2. 10
      src/functions.cpp
  3. 2
      src/reader.cpp

4
src/ast.h

@ -201,7 +201,9 @@ public:
False, False,
}; };
Constant() = default;
Constant(State state); Constant(State state);
Constant(bool state);
virtual ~Constant() = default; virtual ~Constant() = default;
State state() const { return m_state; } State state() const { return m_state; }
@ -209,7 +211,7 @@ public:
private: private:
virtual bool isConstant() const override { return true; } virtual bool isConstant() const override { return true; }
const State m_state; const State m_state { State::Nil };
}; };
// ----------------------------------------- // -----------------------------------------

10
src/functions.cpp

@ -238,7 +238,7 @@ ADD_FUNCTION("pr-str", PRINTER_STRING(true, " "));
} \ } \
print("\n"); \ print("\n"); \
\ \
return makePtr<Constant>(Constant::Nil); \ return makePtr<Constant>(); \
} }
ADD_FUNCTION("prn", PRINTER_PRINT(true)); ADD_FUNCTION("prn", PRINTER_PRINT(true));
@ -478,6 +478,10 @@ ADD_FUNCTION(
{ {
CHECK_ARG_COUNT_IS("vec", nodes.size(), 1); CHECK_ARG_COUNT_IS("vec", nodes.size(), 1);
if (is<Vector>(nodes.front().get())) {
return nodes.front();
}
VALUE_CAST(collection, Collection, nodes.front()); VALUE_CAST(collection, Collection, nodes.front());
return makePtr<Vector>(collection->nodes()); return makePtr<Vector>(collection->nodes());
@ -515,13 +519,13 @@ ADD_FUNCTION(
if (is<Constant>(nodes.front().get()) if (is<Constant>(nodes.front().get())
&& std::static_pointer_cast<Constant>(nodes.front())->state() == Constant::Nil) { && std::static_pointer_cast<Constant>(nodes.front())->state() == Constant::Nil) {
return makePtr<Constant>(Constant::Nil); return makePtr<Constant>();
} }
VALUE_CAST(collection, Collection, nodes.front()); VALUE_CAST(collection, Collection, nodes.front());
auto collection_nodes = collection->nodes(); auto collection_nodes = collection->nodes();
return (collection_nodes.empty()) ? makePtr<Constant>(Constant::Nil) : collection_nodes.front(); return (collection_nodes.empty()) ? makePtr<Constant>() : collection_nodes.front();
}); });
// (rest (list 1 2 3)) // (rest (list 1 2 3))

2
src/reader.cpp

@ -191,7 +191,7 @@ ValuePtr Reader::readHashMap()
} }
if (!is<String>(key.get()) && !is<Keyword>(key.get())) { if (!is<String>(key.get()) && !is<Keyword>(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; return nullptr;
} }

Loading…
Cancel
Save