Switch interpreter Stacks to Ptr (#763)

This also eliminates the ctad wrapper for Stack: I think the leaning is to remove it. It felt worth keeping the constructor because constructing with a single element is a common use-case.

Adds a single-argument constructor for Scope because the `std::list<std::string>()` is common, and eliding it is consistent with what we've done for things like tuples.

I was considering a vector constructor due to the double-Push on line 1139, but thought the Push() semantics may mean that it's better not to provide.
This commit is contained in:
Jon Meow
2021-08-19 11:34:03 -07:00
committed by GitHub
parent 925c60b669
commit 47325be112
7 changed files with 142 additions and 154 deletions
+1 -8
View File
@@ -22,8 +22,6 @@ struct Stack {
Stack() = default;
// Creates an instance containing just `x`.
// TODO: consider removing this. It's somewhat unconventional, and the
// callsite readability is debatable.
explicit Stack(T x) : Stack() { Push(std::move(x)); }
// Pushes `x` onto the top of the stack.
@@ -46,7 +44,7 @@ struct Stack {
CHECK(n >= 0) << "Negative pop count disallowed.";
CHECK(static_cast<size_t>(n) <= elements.size())
<< "Can only pop as many elements as stack has.";
elements.resize(elements.size() - n);
elements.erase(elements.end() - n, elements.end());
}
// Returns the top element of the stack.
@@ -71,11 +69,6 @@ struct Stack {
std::vector<T> elements;
};
// Explicitly enable CTAD to silence warnings.
// TODO: consider removing this (and perhaps the associated constructor).
template <typename T>
Stack(T x) -> Stack<T>;
} // namespace Carbon
#endif // EXECUTABLE_SEMANTICS_INTERPRETER_CONS_LIST_H_