Browse Source

Everywhere: Make the project compile again

std::format seems to finally have been implemented in the STL, which is
ambiguous with ruc::format even without ever including <format>.
master
Riyyi 1 year ago
parent
commit
6e6479bd14
  1. 2
      src/ast.cpp
  2. 6
      src/environment.cpp
  3. 4
      src/eval.cpp
  4. 10
      src/functions.cpp
  5. 24
      src/printer.cpp
  6. 2
      src/reader.cpp
  7. 10
      src/util.h

2
src/ast.cpp

@ -182,7 +182,7 @@ ValuePtr HashMap::get(ValuePtr key)
std::string HashMap::getKeyString(ValuePtr key) std::string HashMap::getKeyString(ValuePtr key)
{ {
if (!is<String>(key.get()) && !is<Keyword>(key.get())) { if (!is<String>(key.get()) && !is<Keyword>(key.get())) {
Error::the().add(format("wrong argument type: string or keyword, {}", key)); Error::the().add(::format("wrong argument type: string or keyword, {}", key));
return {}; return {};
} }

6
src/environment.cpp

@ -39,7 +39,7 @@ EnvironmentPtr Environment::create(const ValuePtr lambda, const ValueVector& arg
for (size_t i = 0; i < bindings.size(); ++i, ++it) { for (size_t i = 0; i < bindings.size(); ++i, ++it) {
if (bindings[i] == "&") { if (bindings[i] == "&") {
if (i + 2 != bindings.size()) { if (i + 2 != bindings.size()) {
Error::the().add(format("invalid function: {}", lambda)); Error::the().add(::format("invalid function: {}", lambda));
return nullptr; return nullptr;
} }
@ -53,7 +53,7 @@ EnvironmentPtr Environment::create(const ValuePtr lambda, const ValueVector& arg
} }
if (it == arguments.end()) { if (it == arguments.end()) {
Error::the().add(format("wrong number of arguments: {}, {}", lambda, arguments.size())); Error::the().add(::format("wrong number of arguments: {}, {}", lambda, arguments.size()));
return nullptr; return nullptr;
} }
@ -61,7 +61,7 @@ EnvironmentPtr Environment::create(const ValuePtr lambda, const ValueVector& arg
} }
if (it != arguments.end()) { if (it != arguments.end()) {
Error::the().add(format("wrong number of arguments: {}, {}", lambda, arguments.size())); Error::the().add(::format("wrong number of arguments: {}, {}", lambda, arguments.size()));
return nullptr; return nullptr;
} }

4
src/eval.cpp

@ -153,7 +153,7 @@ ValuePtr Eval::evalAst(ValuePtr ast, EnvironmentPtr env)
if (is<Symbol>(ast_raw_ptr)) { if (is<Symbol>(ast_raw_ptr)) {
auto result = env->get(std::static_pointer_cast<Symbol>(ast)->symbol()); auto result = env->get(std::static_pointer_cast<Symbol>(ast)->symbol());
if (!result) { if (!result) {
Error::the().add(format("'{}' not found", ast)); Error::the().add(::format("'{}' not found", ast));
return nullptr; return nullptr;
} }
return result; return result;
@ -245,7 +245,7 @@ ValuePtr Eval::apply(std::shared_ptr<List> evaluated_list)
auto nodes = evaluated_list->nodes(); auto nodes = evaluated_list->nodes();
if (!is<Function>(nodes.front().get())) { if (!is<Function>(nodes.front().get())) {
Error::the().add(format("invalid function: {}", nodes.front())); Error::the().add(::format("invalid function: {}", nodes.front()));
return nullptr; return nullptr;
} }

10
src/functions.cpp

@ -181,7 +181,7 @@ ADD_FUNCTION(
result = std::static_pointer_cast<Collection>(*begin)->size(); result = std::static_pointer_cast<Collection>(*begin)->size();
} }
else { else {
Error::the().add(format("wrong argument type: Collection, '{}'", *begin)); Error::the().add(::format("wrong argument type: Collection, '{}'", *begin));
return nullptr; return nullptr;
} }
@ -197,7 +197,7 @@ ADD_FUNCTION(
\ \
Printer printer; \ Printer printer; \
for (auto it = begin; it != end; ++it) { \ for (auto it = begin; it != end; ++it) { \
result += format("{}", printer.printNoErrorCheck(*it, print_readably)); \ result += ::format("{}", printer.printNoErrorCheck(*it, print_readably)); \
\ \
if (it != end && std::next(it) != end) { \ if (it != end && std::next(it) != end) { \
result += concatenation; \ result += concatenation; \
@ -869,7 +869,7 @@ ADD_FUNCTION(
if (!is<Collection>(front_raw_ptr) && // List / Vector if (!is<Collection>(front_raw_ptr) && // List / Vector
!is<HashMap>(front_raw_ptr) && // HashMap !is<HashMap>(front_raw_ptr) && // HashMap
!is<Callable>(front_raw_ptr)) { // Function / Lambda !is<Callable>(front_raw_ptr)) { // Function / Lambda
Error::the().add(format("wrong argument type: Collection, HashMap or Callable, {}", front)); Error::the().add(::format("wrong argument type: Collection, HashMap or Callable, {}", front));
return nullptr; return nullptr;
} }
@ -888,7 +888,7 @@ ADD_FUNCTION(
if (!is<Collection>(front_raw_ptr) && // List / Vector if (!is<Collection>(front_raw_ptr) && // List / Vector
!is<HashMap>(front_raw_ptr) && // HashMap !is<HashMap>(front_raw_ptr) && // HashMap
!is<Callable>(front_raw_ptr)) { // Function / Lambda !is<Callable>(front_raw_ptr)) { // Function / Lambda
Error::the().add(format("wrong argument type: Collection, HashMap or Callable, {}", front)); Error::the().add(::format("wrong argument type: Collection, HashMap or Callable, {}", front));
return nullptr; return nullptr;
} }
@ -968,7 +968,7 @@ ADD_FUNCTION(
return result; return result;
} }
Error::the().add(format("wrong argument type: Collection or String, {}", front)); Error::the().add(::format("wrong argument type: Collection or String, {}", front));
return nullptr; return nullptr;
}); });

24
src/printer.cpp

@ -90,7 +90,7 @@ void Printer::printImpl(ValuePtr node, bool print_readably)
m_previous_node_is_list = true; m_previous_node_is_list = true;
auto elements = std::static_pointer_cast<HashMap>(node)->elements(); auto elements = std::static_pointer_cast<HashMap>(node)->elements();
for (auto it = elements.begin(); it != elements.end(); ++it) { for (auto it = elements.begin(); it != elements.end(); ++it) {
m_print += format("{} ", (it->first.front() == 0x7f) ? ":" + it->first.substr(1) : '"' + it->first + '"'); // 127 m_print += ::format("{} ", (it->first.front() == 0x7f) ? ":" + it->first.substr(1) : '"' + it->first + '"'); // 127
printImpl(it->second, print_readably); printImpl(it->second, print_readably);
if (!isLast(it, elements)) { if (!isLast(it, elements)) {
@ -109,15 +109,15 @@ void Printer::printImpl(ValuePtr node, bool print_readably)
text = "\"" + text + "\""; text = "\"" + text + "\"";
} }
printSpacing(); printSpacing();
m_print += format("{}", text); m_print += ::format("{}", text);
} }
else if (is<Keyword>(node_raw_ptr)) { else if (is<Keyword>(node_raw_ptr)) {
printSpacing(); printSpacing();
m_print += format(":{}", std::static_pointer_cast<Keyword>(node)->keyword().substr(1)); m_print += ::format(":{}", std::static_pointer_cast<Keyword>(node)->keyword().substr(1));
} }
else if (is<Number>(node_raw_ptr)) { else if (is<Number>(node_raw_ptr)) {
printSpacing(); printSpacing();
m_print += format("{}", std::static_pointer_cast<Number>(node)->number()); m_print += ::format("{}", std::static_pointer_cast<Number>(node)->number());
} }
else if (is<Constant>(node_raw_ptr)) { else if (is<Constant>(node_raw_ptr)) {
printSpacing(); printSpacing();
@ -127,23 +127,23 @@ void Printer::printImpl(ValuePtr node, bool print_readably)
case Constant::True: value = "true"; break; case Constant::True: value = "true"; break;
case Constant::False: value = "false"; break; case Constant::False: value = "false"; break;
} }
m_print += format("{}", value); m_print += ::format("{}", value);
} }
else if (is<Symbol>(node_raw_ptr)) { else if (is<Symbol>(node_raw_ptr)) {
printSpacing(); printSpacing();
m_print += format("{}", std::static_pointer_cast<Symbol>(node)->symbol()); m_print += ::format("{}", std::static_pointer_cast<Symbol>(node)->symbol());
} }
else if (is<Function>(node_raw_ptr)) { else if (is<Function>(node_raw_ptr)) {
printSpacing(); printSpacing();
m_print += format("#<builtin-function>({})", std::static_pointer_cast<Function>(node)->name()); m_print += ::format("#<builtin-function>({})", std::static_pointer_cast<Function>(node)->name());
} }
else if (is<Lambda>(node_raw_ptr)) { else if (is<Lambda>(node_raw_ptr)) {
printSpacing(); printSpacing();
m_print += format("#<user-function>({:p})", node_raw_ptr); m_print += ::format("#<user-function>({:p})", node_raw_ptr);
} }
else if (is<Macro>(node_raw_ptr)) { else if (is<Macro>(node_raw_ptr)) {
printSpacing(); printSpacing();
m_print += format("#<user-macro>({:p})", node_raw_ptr); m_print += ::format("#<user-macro>({:p})", node_raw_ptr);
} }
else if (is<Atom>(node_raw_ptr)) { else if (is<Atom>(node_raw_ptr)) {
printSpacing(); printSpacing();
@ -158,15 +158,15 @@ void Printer::printError()
m_print = "Error: "; m_print = "Error: ";
if (Error::the().hasTokenError()) { if (Error::the().hasTokenError()) {
Token error = Error::the().tokenError(); Token error = Error::the().tokenError();
m_print += format("{}", error.symbol); m_print += ::format("{}", error.symbol);
} }
else if (Error::the().hasOtherError()) { else if (Error::the().hasOtherError()) {
std::string error = Error::the().otherError(); std::string error = Error::the().otherError();
m_print += format("{}", error); m_print += ::format("{}", error);
} }
else if (Error::the().hasException()) { else if (Error::the().hasException()) {
ValuePtr error = Error::the().exception(); ValuePtr error = Error::the().exception();
m_print += format("{}", error); m_print += ::format("{}", error);
} }
} }

2
src/reader.cpp

@ -188,7 +188,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("wrong argument type: string or keyword, {}", key)); Error::the().add(::format("wrong argument type: string or keyword, {}", key));
return nullptr; return nullptr;
} }

10
src/util.h

@ -36,7 +36,7 @@
#define CHECK_ARG_COUNT_IS_IMPL(name, size, expected, result) \ #define CHECK_ARG_COUNT_IS_IMPL(name, size, expected, result) \
if (size != expected) { \ if (size != expected) { \
Error::the().add(format("wrong number of arguments: {}, {}", name, size)); \ Error::the().add(::format("wrong number of arguments: {}, {}", name, size)); \
return result; \ return result; \
} }
@ -54,7 +54,7 @@
#define CHECK_ARG_COUNT_AT_LEAST_IMPL(name, size, min, result) \ #define CHECK_ARG_COUNT_AT_LEAST_IMPL(name, size, min, result) \
if (size < min) { \ if (size < min) { \
Error::the().add(format("wrong number of arguments: {}, {}", name, size)); \ Error::the().add(::format("wrong number of arguments: {}, {}", name, size)); \
return result; \ return result; \
} }
@ -72,7 +72,7 @@
#define CHECK_ARG_COUNT_BETWEEN_IMPL(name, size, min, max, result) \ #define CHECK_ARG_COUNT_BETWEEN_IMPL(name, size, min, max, result) \
if (size < min || size > max) { \ if (size < min || size > max) { \
Error::the().add(format("wrong number of arguments: {}, {}", name, size)); \ Error::the().add(::format("wrong number of arguments: {}, {}", name, size)); \
return result; \ return result; \
} }
@ -90,7 +90,7 @@
#define CHECK_ARG_COUNT_EVEN_IMPL(name, size, result) \ #define CHECK_ARG_COUNT_EVEN_IMPL(name, size, result) \
if (size % 2 != 0) { \ if (size % 2 != 0) { \
Error::the().add(format("wrong number of arguments: {}, {}", name, size)); \ Error::the().add(::format("wrong number of arguments: {}, {}", name, size)); \
return result; \ return result; \
} }
@ -108,7 +108,7 @@
#define IS_VALUE_IMPL(type, value, result) \ #define IS_VALUE_IMPL(type, value, result) \
if (!is<type>(value.get())) { \ if (!is<type>(value.get())) { \
Error::the().add(format("wrong argument type: {}, {}", #type, value)); \ Error::the().add(::format("wrong argument type: {}, {}", #type, value)); \
return result; \ return result; \
} }

Loading…
Cancel
Save