Browse Source

Everywhere: Rename ValueList -> ValueVector

master
Riyyi 2 years ago
parent
commit
4fff2b9aa2
  1. 26
      src/ast.cpp
  2. 26
      src/ast.h
  3. 2
      src/environment.cpp
  4. 2
      src/environment.h
  5. 22
      src/eval-special-form.cpp
  6. 22
      src/eval.h
  7. 6
      src/forward.h
  8. 14
      src/functions.cpp

26
src/ast.cpp

@ -30,18 +30,18 @@ ValuePtr Value::meta() const
// ----------------------------------------- // -----------------------------------------
Collection::Collection(const ValueList& nodes) Collection::Collection(const ValueVector& nodes)
: m_nodes(nodes) : m_nodes(nodes)
{ {
} }
Collection::Collection(ValueListIt begin, ValueListIt end) Collection::Collection(ValueVectorIt begin, ValueVectorIt end)
: m_nodes(ValueList(begin, end)) : m_nodes(ValueVector(begin, end))
{ {
} }
Collection::Collection(ValueListConstIt begin, ValueListConstIt end) Collection::Collection(ValueVectorConstIt begin, ValueVectorConstIt end)
: m_nodes(ValueList(begin, end)) : m_nodes(ValueVector(begin, end))
{ {
} }
@ -60,25 +60,25 @@ void Collection::add(ValuePtr node)
m_nodes.push_back(node); m_nodes.push_back(node);
} }
ValueList Collection::rest() const ValueVector Collection::rest() const
{ {
auto start = (m_nodes.size() > 0) ? m_nodes.begin() + 1 : m_nodes.end(); auto start = (m_nodes.size() > 0) ? m_nodes.begin() + 1 : m_nodes.end();
return ValueList(start, m_nodes.end()); return ValueVector(start, m_nodes.end());
} }
// ----------------------------------------- // -----------------------------------------
List::List(const ValueList& nodes) List::List(const ValueVector& nodes)
: Collection(nodes) : Collection(nodes)
{ {
} }
List::List(ValueListIt begin, ValueListIt end) List::List(ValueVectorIt begin, ValueVectorIt end)
: Collection(begin, end) : Collection(begin, end)
{ {
} }
List::List(ValueListConstIt begin, ValueListConstIt end) List::List(ValueVectorConstIt begin, ValueVectorConstIt end)
: Collection(begin, end) : Collection(begin, end)
{ {
} }
@ -90,17 +90,17 @@ List::List(const List& that, ValuePtr meta)
// ----------------------------------------- // -----------------------------------------
Vector::Vector(const ValueList& nodes) Vector::Vector(const ValueVector& nodes)
: Collection(nodes) : Collection(nodes)
{ {
} }
Vector::Vector(ValueListIt begin, ValueListIt end) Vector::Vector(ValueVectorIt begin, ValueVectorIt end)
: Collection(begin, end) : Collection(begin, end)
{ {
} }
Vector::Vector(ValueListConstIt begin, ValueListConstIt end) Vector::Vector(ValueVectorConstIt begin, ValueVectorConstIt end)
: Collection(begin, end) : Collection(begin, end)
{ {
} }

26
src/ast.h

@ -101,15 +101,15 @@ public:
bool empty() const { return m_nodes.size() == 0; } bool empty() const { return m_nodes.size() == 0; }
ValuePtr front() const { return m_nodes.front(); } ValuePtr front() const { return m_nodes.front(); }
ValueList rest() const; ValueVector rest() const;
const ValueList& nodes() const { return m_nodes; } const ValueVector& nodes() const { return m_nodes; }
protected: protected:
Collection() = default; Collection() = default;
Collection(const ValueList& nodes); Collection(const ValueVector& nodes);
Collection(ValueListIt begin, ValueListIt end); Collection(ValueVectorIt begin, ValueVectorIt end);
Collection(ValueListConstIt begin, ValueListConstIt end); Collection(ValueVectorConstIt begin, ValueVectorConstIt end);
Collection(const Collection& that, ValuePtr meta); Collection(const Collection& that, ValuePtr meta);
template<IsValue... Ts> template<IsValue... Ts>
@ -121,7 +121,7 @@ protected:
private: private:
virtual bool isCollection() const override { return true; } virtual bool isCollection() const override { return true; }
ValueList m_nodes; ValueVector m_nodes;
}; };
// ----------------------------------------- // -----------------------------------------
@ -130,9 +130,9 @@ private:
class List final : public Collection { class List final : public Collection {
public: public:
List() = default; List() = default;
List(const ValueList& nodes); List(const ValueVector& nodes);
List(ValueListIt begin, ValueListIt end); List(ValueVectorIt begin, ValueVectorIt end);
List(ValueListConstIt begin, ValueListConstIt end); List(ValueVectorConstIt begin, ValueVectorConstIt end);
List(const List& that, ValuePtr meta); List(const List& that, ValuePtr meta);
template<IsValue... Ts> template<IsValue... Ts>
@ -155,9 +155,9 @@ private:
class Vector final : public Collection { class Vector final : public Collection {
public: public:
Vector() = default; Vector() = default;
Vector(const ValueList& nodes); Vector(const ValueVector& nodes);
Vector(ValueListIt begin, ValueListIt end); Vector(ValueVectorIt begin, ValueVectorIt end);
Vector(ValueListConstIt begin, ValueListConstIt end); Vector(ValueVectorConstIt begin, ValueVectorConstIt end);
Vector(const Vector& that, ValuePtr meta); Vector(const Vector& that, ValuePtr meta);
template<IsValue... Ts> template<IsValue... Ts>
@ -324,7 +324,7 @@ private:
// ----------------------------------------- // -----------------------------------------
using FunctionType = std::function<ValuePtr(ValueListIt, ValueListIt)>; using FunctionType = std::function<ValuePtr(ValueVectorIt, ValueVectorIt)>;
class Function final : public Callable { class Function final : public Callable {
public: public:

2
src/environment.cpp

@ -29,7 +29,7 @@ EnvironmentPtr Environment::create(EnvironmentPtr outer)
return env; return env;
} }
EnvironmentPtr Environment::create(const ValuePtr lambda, const ValueList& arguments) EnvironmentPtr Environment::create(const ValuePtr lambda, const ValueVector& arguments)
{ {
auto lambda_casted = std::static_pointer_cast<Lambda>(lambda); auto lambda_casted = std::static_pointer_cast<Lambda>(lambda);
auto env = create(lambda_casted->env()); auto env = create(lambda_casted->env());

2
src/environment.h

@ -21,7 +21,7 @@ public:
// Factory functions instead of constructors because it can fail in the bindings/arguments case // Factory functions instead of constructors because it can fail in the bindings/arguments case
static EnvironmentPtr create(); static EnvironmentPtr create();
static EnvironmentPtr create(EnvironmentPtr outer); static EnvironmentPtr create(EnvironmentPtr outer);
static EnvironmentPtr create(const ValuePtr lambda, const ValueList& arguments); static EnvironmentPtr create(const ValuePtr lambda, const ValueVector& arguments);
bool exists(const std::string& symbol); bool exists(const std::string& symbol);
ValuePtr set(const std::string& symbol, ValuePtr value); ValuePtr set(const std::string& symbol, ValuePtr value);

22
src/eval-special-form.cpp

@ -22,7 +22,7 @@ namespace blaze {
static ValuePtr evalQuasiQuoteImpl(ValuePtr ast); static ValuePtr evalQuasiQuoteImpl(ValuePtr ast);
// (def! x 2) // (def! x 2)
ValuePtr Eval::evalDef(const ValueList& nodes, EnvironmentPtr env) ValuePtr Eval::evalDef(const ValueVector& nodes, EnvironmentPtr env)
{ {
CHECK_ARG_COUNT_IS("def!", nodes.size(), 2); CHECK_ARG_COUNT_IS("def!", nodes.size(), 2);
@ -44,7 +44,7 @@ ValuePtr Eval::evalDef(const ValueList& nodes, EnvironmentPtr env)
} }
// (defmacro! x (fn* (x) x)) // (defmacro! x (fn* (x) x))
ValuePtr Eval::evalDefMacro(const ValueList& nodes, EnvironmentPtr env) ValuePtr Eval::evalDefMacro(const ValueVector& nodes, EnvironmentPtr env)
{ {
CHECK_ARG_COUNT_IS("defmacro!", nodes.size(), 2); CHECK_ARG_COUNT_IS("defmacro!", nodes.size(), 2);
@ -67,7 +67,7 @@ ValuePtr Eval::evalDefMacro(const ValueList& nodes, EnvironmentPtr env)
} }
// (fn* (x) x) // (fn* (x) x)
ValuePtr Eval::evalFn(const ValueList& nodes, EnvironmentPtr env) ValuePtr Eval::evalFn(const ValueVector& nodes, EnvironmentPtr env)
{ {
CHECK_ARG_COUNT_IS("fn*", nodes.size(), 2); CHECK_ARG_COUNT_IS("fn*", nodes.size(), 2);
@ -88,7 +88,7 @@ ValuePtr Eval::evalFn(const ValueList& nodes, EnvironmentPtr env)
return makePtr<Lambda>(bindings, *std::next(nodes.begin()), env); return makePtr<Lambda>(bindings, *std::next(nodes.begin()), env);
} }
ValuePtr Eval::evalMacroExpand(const ValueList& nodes, EnvironmentPtr env) ValuePtr Eval::evalMacroExpand(const ValueVector& nodes, EnvironmentPtr env)
{ {
CHECK_ARG_COUNT_IS("macroexpand", nodes.size(), 1); CHECK_ARG_COUNT_IS("macroexpand", nodes.size(), 1);
@ -96,7 +96,7 @@ ValuePtr Eval::evalMacroExpand(const ValueList& nodes, EnvironmentPtr env)
} }
// (quasiquoteexpand x) // (quasiquoteexpand x)
ValuePtr Eval::evalQuasiQuoteExpand(const ValueList& nodes) ValuePtr Eval::evalQuasiQuoteExpand(const ValueVector& nodes)
{ {
CHECK_ARG_COUNT_IS("quasiquoteexpand", nodes.size(), 1); CHECK_ARG_COUNT_IS("quasiquoteexpand", nodes.size(), 1);
@ -104,7 +104,7 @@ ValuePtr Eval::evalQuasiQuoteExpand(const ValueList& nodes)
} }
// (quote x) // (quote x)
ValuePtr Eval::evalQuote(const ValueList& nodes) ValuePtr Eval::evalQuote(const ValueVector& nodes)
{ {
CHECK_ARG_COUNT_IS("quote", nodes.size(), 1); CHECK_ARG_COUNT_IS("quote", nodes.size(), 1);
@ -112,7 +112,7 @@ ValuePtr Eval::evalQuote(const ValueList& nodes)
} }
// (do 1 2 3) // (do 1 2 3)
void Eval::evalDo(const ValueList& nodes, EnvironmentPtr env) void Eval::evalDo(const ValueVector& nodes, EnvironmentPtr env)
{ {
CHECK_ARG_COUNT_AT_LEAST("do", nodes.size(), 1, void()); CHECK_ARG_COUNT_AT_LEAST("do", nodes.size(), 1, void());
@ -130,7 +130,7 @@ void Eval::evalDo(const ValueList& nodes, EnvironmentPtr env)
} }
// (if x true false) // (if x true false)
void Eval::evalIf(const ValueList& nodes, EnvironmentPtr env) void Eval::evalIf(const ValueVector& nodes, EnvironmentPtr env)
{ {
CHECK_ARG_COUNT_BETWEEN("if", nodes.size(), 2, 3, void()); CHECK_ARG_COUNT_BETWEEN("if", nodes.size(), 2, 3, void());
@ -154,7 +154,7 @@ void Eval::evalIf(const ValueList& nodes, EnvironmentPtr env)
} }
// (let* (x 1) x) // (let* (x 1) x)
void Eval::evalLet(const ValueList& nodes, EnvironmentPtr env) void Eval::evalLet(const ValueVector& nodes, EnvironmentPtr env)
{ {
CHECK_ARG_COUNT_IS("let*", nodes.size(), 2, void()); CHECK_ARG_COUNT_IS("let*", nodes.size(), 2, void());
@ -271,7 +271,7 @@ static ValuePtr evalQuasiQuoteImpl(ValuePtr ast)
} }
// (quasiquote x) // (quasiquote x)
void Eval::evalQuasiQuote(const ValueList& nodes, EnvironmentPtr env) void Eval::evalQuasiQuote(const ValueVector& nodes, EnvironmentPtr env)
{ {
CHECK_ARG_COUNT_IS("quasiquote", nodes.size(), 1, void()); CHECK_ARG_COUNT_IS("quasiquote", nodes.size(), 1, void());
@ -283,7 +283,7 @@ void Eval::evalQuasiQuote(const ValueList& nodes, EnvironmentPtr env)
} }
// (try* x (catch* y z)) // (try* x (catch* y z))
void Eval::evalTry(const ValueList& nodes, EnvironmentPtr env) void Eval::evalTry(const ValueVector& nodes, EnvironmentPtr env)
{ {
CHECK_ARG_COUNT_AT_LEAST("try*", nodes.size(), 1, void()); CHECK_ARG_COUNT_AT_LEAST("try*", nodes.size(), 1, void());

22
src/eval.h

@ -32,17 +32,17 @@ private:
bool isMacroCall(ValuePtr ast, EnvironmentPtr env); bool isMacroCall(ValuePtr ast, EnvironmentPtr env);
ValuePtr macroExpand(ValuePtr ast, EnvironmentPtr env); ValuePtr macroExpand(ValuePtr ast, EnvironmentPtr env);
ValuePtr evalDef(const ValueList& nodes, EnvironmentPtr env); ValuePtr evalDef(const ValueVector& nodes, EnvironmentPtr env);
ValuePtr evalDefMacro(const ValueList& nodes, EnvironmentPtr env); ValuePtr evalDefMacro(const ValueVector& nodes, EnvironmentPtr env);
ValuePtr evalFn(const ValueList& nodes, EnvironmentPtr env); ValuePtr evalFn(const ValueVector& nodes, EnvironmentPtr env);
ValuePtr evalMacroExpand(const ValueList& nodes, EnvironmentPtr env); ValuePtr evalMacroExpand(const ValueVector& nodes, EnvironmentPtr env);
ValuePtr evalQuasiQuoteExpand(const ValueList& nodes); ValuePtr evalQuasiQuoteExpand(const ValueVector& nodes);
ValuePtr evalQuote(const ValueList& nodes); ValuePtr evalQuote(const ValueVector& nodes);
void evalDo(const ValueList& nodes, EnvironmentPtr env); void evalDo(const ValueVector& nodes, EnvironmentPtr env);
void evalIf(const ValueList& nodes, EnvironmentPtr env); void evalIf(const ValueVector& nodes, EnvironmentPtr env);
void evalLet(const ValueList& nodes, EnvironmentPtr env); void evalLet(const ValueVector& nodes, EnvironmentPtr env);
void evalQuasiQuote(const ValueList& nodes, EnvironmentPtr env); void evalQuasiQuote(const ValueVector& nodes, EnvironmentPtr env);
void evalTry(const ValueList& nodes, EnvironmentPtr env); void evalTry(const ValueVector& nodes, EnvironmentPtr env);
ValuePtr apply(std::shared_ptr<List> evaluated_list); ValuePtr apply(std::shared_ptr<List> evaluated_list);

6
src/forward.h

@ -16,9 +16,9 @@ namespace blaze {
class Value; class Value;
typedef std::shared_ptr<Value> ValuePtr; typedef std::shared_ptr<Value> ValuePtr;
typedef std::vector<ValuePtr> ValueList; typedef std::vector<ValuePtr> ValueVector;
typedef ValueList::iterator ValueListIt; typedef ValueVector::iterator ValueVectorIt;
typedef ValueList::const_iterator ValueListConstIt; typedef ValueVector::const_iterator ValueVectorConstIt;
class Environment; class Environment;
typedef std::shared_ptr<Environment> EnvironmentPtr; typedef std::shared_ptr<Environment> EnvironmentPtr;

14
src/functions.cpp

@ -39,7 +39,7 @@
static struct FUNCTION_STRUCT_NAME(unique) \ static struct FUNCTION_STRUCT_NAME(unique) \
FUNCTION_STRUCT_NAME(unique)( \ FUNCTION_STRUCT_NAME(unique)( \
symbol, \ symbol, \
[](ValueListIt begin, ValueListIt end) -> ValuePtr lambda); [](ValueVectorIt begin, ValueVectorIt end) -> ValuePtr lambda);
#define ADD_FUNCTION(symbol, lambda) ADD_FUNCTION_IMPL(__LINE__, symbol, lambda); #define ADD_FUNCTION(symbol, lambda) ADD_FUNCTION_IMPL(__LINE__, symbol, lambda);
@ -391,7 +391,7 @@ ADD_FUNCTION(
// Remove atom and function from the argument list, add atom value // Remove atom and function from the argument list, add atom value
begin += 2; begin += 2;
auto arguments = ValueList(end - begin + 1); auto arguments = ValueVector(end - begin + 1);
arguments[0] = atom->deref(); arguments[0] = atom->deref();
std::copy(begin, end, arguments.begin() + 1); std::copy(begin, end, arguments.begin() + 1);
@ -420,7 +420,7 @@ ADD_FUNCTION(
VALUE_CAST(collection, Collection, (*begin)); VALUE_CAST(collection, Collection, (*begin));
const auto& collection_nodes = collection->nodes(); const auto& collection_nodes = collection->nodes();
ValueList* result_nodes = new ValueList(collection_nodes.size() + 1); ValueVector* result_nodes = new ValueVector(collection_nodes.size() + 1);
result_nodes->at(0) = first; result_nodes->at(0) = first;
std::copy(collection_nodes.begin(), collection_nodes.end(), result_nodes->begin() + 1); std::copy(collection_nodes.begin(), collection_nodes.end(), result_nodes->begin() + 1);
@ -437,7 +437,7 @@ ADD_FUNCTION(
count += collection->size(); count += collection->size();
} }
auto result_nodes = new ValueList(count); auto result_nodes = new ValueVector(count);
size_t offset = 0; size_t offset = 0;
for (auto it = begin; it != end; ++it) { for (auto it = begin; it != end; ++it) {
const auto& collection_nodes = std::static_pointer_cast<Collection>(*it)->nodes(); const auto& collection_nodes = std::static_pointer_cast<Collection>(*it)->nodes();
@ -530,7 +530,7 @@ ADD_FUNCTION(
VALUE_CAST(collection, Collection, (*std::prev(end))); VALUE_CAST(collection, Collection, (*std::prev(end)));
ValueList arguments(begin + 1, end - 1); ValueVector arguments(begin + 1, end - 1);
arguments.reserve(arguments.size() + collection->size()); arguments.reserve(arguments.size() + collection->size());
// Append list nodes to the argument leftovers // Append list nodes to the argument leftovers
@ -567,7 +567,7 @@ ADD_FUNCTION(
if (is<Function>(callable.get())) { if (is<Function>(callable.get())) {
auto function = std::static_pointer_cast<Function>(callable)->function(); auto function = std::static_pointer_cast<Function>(callable)->function();
for (const auto& node : collection_nodes) { for (const auto& node : collection_nodes) {
auto arguments = ValueList { node }; auto arguments = ValueVector { node };
result->add(function(arguments.begin(), arguments.end())); result->add(function(arguments.begin(), arguments.end()));
} }
} }
@ -910,7 +910,7 @@ ADD_FUNCTION(
size_t collection_count = collection_nodes.size(); size_t collection_count = collection_nodes.size();
size_t argument_count = SIZE(); size_t argument_count = SIZE();
ValueList* nodes = new ValueList(argument_count + collection_count); ValueVector* nodes = new ValueVector(argument_count + collection_count);
if (is<List>(collection.get())) { if (is<List>(collection.get())) {
std::reverse_copy(begin, end, nodes->begin()); std::reverse_copy(begin, end, nodes->begin());

Loading…
Cancel
Save