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. 36
      src/functions.cpp
  5. 24
      src/printer.cpp
  6. 2
      src/reader.cpp
  7. 40
      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;
} }

36
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;
} }
@ -191,20 +191,20 @@ ADD_FUNCTION(
// ----------------------------------------- // -----------------------------------------
#define PRINTER_STRING(print_readably, concatenation) \ #define PRINTER_STRING(print_readably, concatenation) \
{ \ { \
std::string result; \ std::string result; \
\ \
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; \
} \ } \
} \ } \
\ \
return makePtr<String>(result); \ return makePtr<String>(result); \
} }
ADD_FUNCTION("str", PRINTER_STRING(false, "")); ADD_FUNCTION("str", PRINTER_STRING(false, ""));
@ -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;
} }

40
src/util.h

@ -34,10 +34,10 @@
// ----------------------------------------- // -----------------------------------------
#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; \
} }
#define CHECK_ARG_COUNT_IS_3(name, size, expected) \ #define CHECK_ARG_COUNT_IS_3(name, size, expected) \
@ -52,10 +52,10 @@
// ----------------------------------------- // -----------------------------------------
#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; \
} }
#define CHECK_ARG_COUNT_AT_LEAST_3(name, size, min) \ #define CHECK_ARG_COUNT_AT_LEAST_3(name, size, min) \
@ -70,10 +70,10 @@
// ----------------------------------------- // -----------------------------------------
#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; \
} }
#define CHECK_ARG_COUNT_BETWEEN_4(name, size, min, max) \ #define CHECK_ARG_COUNT_BETWEEN_4(name, size, min, max) \
@ -88,10 +88,10 @@
// ----------------------------------------- // -----------------------------------------
#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; \
} }
#define CHECK_ARG_COUNT_EVEN_2(name, size) \ #define CHECK_ARG_COUNT_EVEN_2(name, size) \
@ -106,10 +106,10 @@
// ----------------------------------------- // -----------------------------------------
#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; \
} }
#define IS_VALUE_2(type, value) \ #define IS_VALUE_2(type, value) \

Loading…
Cancel
Save