diff --git a/src/functions.cpp b/src/functions.cpp index d670f43..73ba45f 100644 --- a/src/functions.cpp +++ b/src/functions.cpp @@ -129,36 +129,36 @@ ADD_FUNCTION( // // ----------------------------------------- -#define NUMBER_COMPARE(operator) \ - { \ - bool result = true; \ - \ - if (nodes.size() < 2) { \ - Error::the().add(format("wrong number of arguments: {}, {}", #operator, nodes.size() - 1)); \ - return nullptr; \ - } \ - \ - for (auto node : nodes) { \ - if (!is(node.get())) { \ - Error::the().add(format("wrong argument type: number, '{}'", node)); \ - return nullptr; \ - } \ - } \ - \ - /* Start with the first number */ \ - int64_t number = std::static_pointer_cast(nodes.front())->number(); \ - \ - /* Skip the first node */ \ - for (auto it = std::next(nodes.begin()); it != nodes.end(); ++it) { \ - int64_t current_number = std::static_pointer_cast(*it)->number(); \ - if (!(number operator current_number)) { \ - result = false; \ - break; \ - } \ - number = current_number; \ - } \ - \ - return makePtr((result) ? Value::True : Value::False); \ +#define NUMBER_COMPARE(operator) \ + { \ + bool result = true; \ + \ + if (nodes.size() < 2) { \ + Error::the().add(format("wrong number of arguments: {}, {}", #operator, nodes.size())); \ + return nullptr; \ + } \ + \ + for (auto node : nodes) { \ + if (!is(node.get())) { \ + Error::the().add(format("wrong argument type: number, '{}'", node)); \ + return nullptr; \ + } \ + } \ + \ + /* Start with the first number */ \ + int64_t number = std::static_pointer_cast(nodes.front())->number(); \ + \ + /* Skip the first node */ \ + for (auto it = std::next(nodes.begin()); it != nodes.end(); ++it) { \ + int64_t current_number = std::static_pointer_cast(*it)->number(); \ + if (!(number operator current_number)) { \ + result = false; \ + break; \ + } \ + number = current_number; \ + } \ + \ + return makePtr((result) ? Value::True : Value::False); \ } ADD_FUNCTION("<", NUMBER_COMPARE(<)); @@ -185,6 +185,10 @@ ADD_FUNCTION( { bool result = true; + if (nodes.size() == 0) { + result = false; + } + for (auto node : nodes) { if (!is(node.get())) { result = false; @@ -219,7 +223,7 @@ ADD_FUNCTION( "count", { if (nodes.size() != 1) { - Error::the().add(format("wrong number of arguments: count, {}", nodes.size() - 1)); + Error::the().add(format("wrong number of arguments: count, {}", nodes.size())); return nullptr; } @@ -286,7 +290,7 @@ ADD_FUNCTION( "=", { if (nodes.size() < 2) { - Error::the().add(format("wrong number of arguments: =, {}", nodes.size() - 1)); + Error::the().add(format("wrong number of arguments: =, {}", nodes.size())); return nullptr; }