Browse Source

Env: Fix function argument size error message

master
Riyyi 1 year ago
parent
commit
f35fea9fa4
  1. 68
      src/functions.cpp

68
src/functions.cpp

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

Loading…
Cancel
Save