|
|
@ -24,17 +24,17 @@ |
|
|
|
|
|
|
|
|
|
|
|
#define FUNCTION_STRUCT_NAME(unique) __functionStruct##unique |
|
|
|
#define FUNCTION_STRUCT_NAME(unique) __functionStruct##unique |
|
|
|
|
|
|
|
|
|
|
|
#define ADD_FUNCTION_IMPL(unique, symbol, lambda) \ |
|
|
|
#define ADD_FUNCTION_IMPL(unique, symbol, lambda) \ |
|
|
|
struct FUNCTION_STRUCT_NAME(unique) { \
|
|
|
|
struct FUNCTION_STRUCT_NAME(unique) { \
|
|
|
|
FUNCTION_STRUCT_NAME(unique) \
|
|
|
|
FUNCTION_STRUCT_NAME(unique) \
|
|
|
|
(std::string __symbol, FunctionType __lambda) \
|
|
|
|
(const std::string& __symbol, FunctionType __lambda) \
|
|
|
|
{ \
|
|
|
|
{ \
|
|
|
|
s_functions.emplace(__symbol, __lambda); \
|
|
|
|
s_functions.emplace(__symbol, __lambda); \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
}; \
|
|
|
|
}; \
|
|
|
|
static struct FUNCTION_STRUCT_NAME(unique) \
|
|
|
|
static struct FUNCTION_STRUCT_NAME(unique) \
|
|
|
|
FUNCTION_STRUCT_NAME(unique)( \
|
|
|
|
FUNCTION_STRUCT_NAME(unique)( \
|
|
|
|
symbol, \
|
|
|
|
symbol, \
|
|
|
|
[](std::list<ValuePtr> nodes) -> ValuePtr lambda); |
|
|
|
[](std::list<ValuePtr> nodes) -> ValuePtr lambda); |
|
|
|
|
|
|
|
|
|
|
|
#define ADD_FUNCTION(symbol, lambda) ADD_FUNCTION_IMPL(__LINE__, symbol, lambda); |
|
|
|
#define ADD_FUNCTION(symbol, lambda) ADD_FUNCTION_IMPL(__LINE__, symbol, lambda); |
|
|
@ -49,12 +49,8 @@ ADD_FUNCTION( |
|
|
|
int64_t result = 0; |
|
|
|
int64_t result = 0; |
|
|
|
|
|
|
|
|
|
|
|
for (auto node : nodes) { |
|
|
|
for (auto node : nodes) { |
|
|
|
if (!is<Number>(node.get())) { |
|
|
|
VALUE_CAST(number, Number, node); |
|
|
|
Error::the().add(format("wrong argument type: number, '{}'", node)); |
|
|
|
result += number->number(); |
|
|
|
return nullptr; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
result += std::static_pointer_cast<Number>(node)->number(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return makePtr<Number>(result); |
|
|
|
return makePtr<Number>(result); |
|
|
@ -67,19 +63,14 @@ ADD_FUNCTION( |
|
|
|
return makePtr<Number>(0); |
|
|
|
return makePtr<Number>(0); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
for (auto node : nodes) { |
|
|
|
|
|
|
|
if (!is<Number>(node.get())) { |
|
|
|
|
|
|
|
Error::the().add(format("wrong argument type: number, '{}'", node)); |
|
|
|
|
|
|
|
return nullptr; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Start with the first number
|
|
|
|
// Start with the first number
|
|
|
|
int64_t result = std::static_pointer_cast<Number>(nodes.front())->number(); |
|
|
|
VALUE_CAST(number, Number, nodes.front()); |
|
|
|
|
|
|
|
int64_t result = number->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) { |
|
|
|
result -= std::static_pointer_cast<Number>(*it)->number(); |
|
|
|
VALUE_CAST(number, Number, (*it)); |
|
|
|
|
|
|
|
result -= number->number(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return makePtr<Number>(result); |
|
|
|
return makePtr<Number>(result); |
|
|
@ -91,12 +82,8 @@ ADD_FUNCTION( |
|
|
|
int64_t result = 1; |
|
|
|
int64_t result = 1; |
|
|
|
|
|
|
|
|
|
|
|
for (auto node : nodes) { |
|
|
|
for (auto node : nodes) { |
|
|
|
if (!is<Number>(node.get())) { |
|
|
|
VALUE_CAST(number, Number, node); |
|
|
|
Error::the().add(format("wrong argument type: number, '{}'", node)); |
|
|
|
result *= number->number(); |
|
|
|
return nullptr; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
result *= std::static_pointer_cast<Number>(node)->number(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return makePtr<Number>(result); |
|
|
|
return makePtr<Number>(result); |
|
|
@ -105,24 +92,16 @@ ADD_FUNCTION( |
|
|
|
ADD_FUNCTION( |
|
|
|
ADD_FUNCTION( |
|
|
|
"/", |
|
|
|
"/", |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (nodes.size() == 0) { |
|
|
|
CHECK_ARG_COUNT_AT_LEAST("/", nodes.size(), 1); |
|
|
|
Error::the().add(format("wrong number of arguments: /, 0")); |
|
|
|
|
|
|
|
return nullptr; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (auto node : nodes) { |
|
|
|
|
|
|
|
if (!is<Number>(node.get())) { |
|
|
|
|
|
|
|
Error::the().add(format("wrong argument type: number, '{}'", node)); |
|
|
|
|
|
|
|
return nullptr; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Start with the first number
|
|
|
|
// Start with the first number
|
|
|
|
double result = std::static_pointer_cast<Number>(nodes.front())->number(); |
|
|
|
VALUE_CAST(number, Number, nodes.front()); |
|
|
|
|
|
|
|
double result = number->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) { |
|
|
|
result /= std::static_pointer_cast<Number>(*it)->number(); |
|
|
|
VALUE_CAST(number, Number, (*it)); |
|
|
|
|
|
|
|
result /= number->number(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return makePtr<Number>((int64_t)result); |
|
|
|
return makePtr<Number>((int64_t)result); |
|
|
@ -130,36 +109,28 @@ ADD_FUNCTION( |
|
|
|
|
|
|
|
|
|
|
|
// // -----------------------------------------
|
|
|
|
// // -----------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
#define NUMBER_COMPARE(operator) \ |
|
|
|
#define NUMBER_COMPARE(operator) \ |
|
|
|
{ \
|
|
|
|
{ \
|
|
|
|
bool result = true; \
|
|
|
|
bool result = true; \
|
|
|
|
\
|
|
|
|
\
|
|
|
|
if (nodes.size() < 2) { \
|
|
|
|
CHECK_ARG_COUNT_AT_LEAST(#operator, nodes.size(), 2); \
|
|
|
|
Error::the().add(format("wrong number of arguments: {}, {}", #operator, nodes.size())); \
|
|
|
|
\
|
|
|
|
return nullptr; \
|
|
|
|
/* Start with the first number */ \
|
|
|
|
} \
|
|
|
|
VALUE_CAST(number_node, Number, nodes.front()); \
|
|
|
|
\
|
|
|
|
int64_t number = number_node->number(); \
|
|
|
|
for (auto node : nodes) { \
|
|
|
|
\
|
|
|
|
if (!is<Number>(node.get())) { \
|
|
|
|
/* Skip the first node */ \
|
|
|
|
Error::the().add(format("wrong argument type: number, '{}'", node)); \
|
|
|
|
for (auto it = std::next(nodes.begin()); it != nodes.end(); ++it) { \
|
|
|
|
return nullptr; \
|
|
|
|
VALUE_CAST(current_number_node, Number, (*it)); \
|
|
|
|
} \
|
|
|
|
int64_t current_number = current_number_node->number(); \
|
|
|
|
} \
|
|
|
|
if (!(number operator current_number)) { \
|
|
|
|
\
|
|
|
|
result = false; \
|
|
|
|
/* Start with the first number */ \
|
|
|
|
break; \
|
|
|
|
int64_t number = std::static_pointer_cast<Number>(nodes.front())->number(); \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
number = current_number; \
|
|
|
|
/* Skip the first node */ \
|
|
|
|
} \
|
|
|
|
for (auto it = std::next(nodes.begin()); it != nodes.end(); ++it) { \
|
|
|
|
\
|
|
|
|
int64_t current_number = std::static_pointer_cast<Number>(*it)->number(); \
|
|
|
|
return makePtr<Constant>((result) ? Constant::True : Constant::False); \
|
|
|
|
if (!(number operator current_number)) { \
|
|
|
|
|
|
|
|
result = false; \
|
|
|
|
|
|
|
|
break; \
|
|
|
|
|
|
|
|
} \
|
|
|
|
|
|
|
|
number = current_number; \
|
|
|
|
|
|
|
|
} \
|
|
|
|
|
|
|
|
\
|
|
|
|
|
|
|
|
return makePtr<Constant>((result) ? Constant::True : Constant::False); \
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
ADD_FUNCTION("<", NUMBER_COMPARE(<)); |
|
|
|
ADD_FUNCTION("<", NUMBER_COMPARE(<)); |
|
|
@ -200,12 +171,8 @@ ADD_FUNCTION( |
|
|
|
bool result = true; |
|
|
|
bool result = true; |
|
|
|
|
|
|
|
|
|
|
|
for (auto node : nodes) { |
|
|
|
for (auto node : nodes) { |
|
|
|
if (!is<Collection>(node.get())) { |
|
|
|
VALUE_CAST(collection, Collection, node); |
|
|
|
Error::the().add(format("wrong argument type: collection, '{}'", node)); |
|
|
|
if (!collection->empty()) { |
|
|
|
return nullptr; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!std::static_pointer_cast<Collection>(node)->empty()) { |
|
|
|
|
|
|
|
result = false; |
|
|
|
result = false; |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
@ -214,13 +181,11 @@ ADD_FUNCTION( |
|
|
|
return makePtr<Constant>((result) ? Constant::True : Constant::False); |
|
|
|
return makePtr<Constant>((result) ? Constant::True : Constant::False); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// FIXME: (count {1}) infinite loop
|
|
|
|
ADD_FUNCTION( |
|
|
|
ADD_FUNCTION( |
|
|
|
"count", |
|
|
|
"count", |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (nodes.size() != 1) { |
|
|
|
CHECK_ARG_COUNT_IS("count", nodes.size(), 1); |
|
|
|
Error::the().add(format("wrong number of arguments: count, {}", nodes.size())); |
|
|
|
|
|
|
|
return nullptr; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
auto first_argument = nodes.front(); |
|
|
|
auto first_argument = nodes.front(); |
|
|
|
|
|
|
|
|
|
|
@ -284,10 +249,7 @@ ADD_FUNCTION("println", PRINTER_PRINT(false)); |
|
|
|
ADD_FUNCTION( |
|
|
|
ADD_FUNCTION( |
|
|
|
"=", |
|
|
|
"=", |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (nodes.size() < 2) { |
|
|
|
CHECK_ARG_COUNT_AT_LEAST("=", nodes.size(), 2); |
|
|
|
Error::the().add(format("wrong number of arguments: =, {}", nodes.size())); |
|
|
|
|
|
|
|
return nullptr; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::function<bool(ValuePtr, ValuePtr)> equal = |
|
|
|
std::function<bool(ValuePtr, ValuePtr)> equal = |
|
|
|
[&equal](ValuePtr lhs, ValuePtr rhs) -> bool { |
|
|
|
[&equal](ValuePtr lhs, ValuePtr rhs) -> bool { |
|
|
@ -369,17 +331,10 @@ ADD_FUNCTION( |
|
|
|
ADD_FUNCTION( |
|
|
|
ADD_FUNCTION( |
|
|
|
"read-string", |
|
|
|
"read-string", |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (nodes.size() != 1) { |
|
|
|
CHECK_ARG_COUNT_IS("read-string", nodes.size(), 1); |
|
|
|
Error::the().add(format("wrong number of arguments: read-string, {}", nodes.size())); |
|
|
|
|
|
|
|
return nullptr; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!is<String>(nodes.front().get())) { |
|
|
|
|
|
|
|
Error::the().add(format("wrong argument type: string, '{}'", nodes.front())); |
|
|
|
|
|
|
|
return nullptr; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::string input = std::static_pointer_cast<String>(nodes.front())->data(); |
|
|
|
VALUE_CAST(node, String, nodes.front()); |
|
|
|
|
|
|
|
std::string input = node->data(); |
|
|
|
|
|
|
|
|
|
|
|
return read(input); |
|
|
|
return read(input); |
|
|
|
}); |
|
|
|
}); |
|
|
@ -387,17 +342,10 @@ ADD_FUNCTION( |
|
|
|
ADD_FUNCTION( |
|
|
|
ADD_FUNCTION( |
|
|
|
"slurp", |
|
|
|
"slurp", |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (nodes.size() != 1) { |
|
|
|
CHECK_ARG_COUNT_IS("slurp", nodes.size(), 1); |
|
|
|
Error::the().add(format("wrong number of arguments: slurp, {}", nodes.size())); |
|
|
|
|
|
|
|
return nullptr; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!is<String>(nodes.front().get())) { |
|
|
|
|
|
|
|
Error::the().add(format("wrong argument type: string, '{}'", nodes.front())); |
|
|
|
|
|
|
|
return nullptr; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::string path = std::static_pointer_cast<String>(nodes.front())->data(); |
|
|
|
VALUE_CAST(node, String, nodes.front()); |
|
|
|
|
|
|
|
std::string path = node->data(); |
|
|
|
|
|
|
|
|
|
|
|
auto file = ruc::File(path); |
|
|
|
auto file = ruc::File(path); |
|
|
|
|
|
|
|
|
|
|
@ -407,10 +355,7 @@ ADD_FUNCTION( |
|
|
|
ADD_FUNCTION( |
|
|
|
ADD_FUNCTION( |
|
|
|
"eval", |
|
|
|
"eval", |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (nodes.size() != 1) { |
|
|
|
CHECK_ARG_COUNT_IS("eval", nodes.size(), 1); |
|
|
|
Error::the().add(format("wrong number of arguments: eval, {}", nodes.size())); |
|
|
|
|
|
|
|
return nullptr; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return eval(nodes.front(), nullptr); |
|
|
|
return eval(nodes.front(), nullptr); |
|
|
|
}); |
|
|
|
}); |
|
|
@ -419,10 +364,7 @@ ADD_FUNCTION( |
|
|
|
ADD_FUNCTION( |
|
|
|
ADD_FUNCTION( |
|
|
|
"atom", |
|
|
|
"atom", |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (nodes.size() != 1) { |
|
|
|
CHECK_ARG_COUNT_IS("atom", nodes.size(), 1); |
|
|
|
Error::the().add(format("wrong number of arguments: atom, {}", nodes.size())); |
|
|
|
|
|
|
|
return nullptr; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return makePtr<Atom>(nodes.front()); |
|
|
|
return makePtr<Atom>(nodes.front()); |
|
|
|
}); |
|
|
|
}); |
|
|
@ -451,34 +393,20 @@ ADD_FUNCTION( |
|
|
|
ADD_FUNCTION( |
|
|
|
ADD_FUNCTION( |
|
|
|
"deref", |
|
|
|
"deref", |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (nodes.size() != 1) { |
|
|
|
CHECK_ARG_COUNT_IS("deref", nodes.size(), 1); |
|
|
|
Error::the().add(format("wrong number of arguments: deref, {}", nodes.size())); |
|
|
|
|
|
|
|
return nullptr; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!is<Atom>(nodes.front().get())) { |
|
|
|
VALUE_CAST(atom, Atom, nodes.front()); |
|
|
|
Error::the().add(format("wrong argument type: atom, '{}'", nodes.front())); |
|
|
|
|
|
|
|
return nullptr; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return std::static_pointer_cast<Atom>(nodes.front())->deref(); |
|
|
|
return atom->deref(); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
// (reset! myatom 2)
|
|
|
|
// (reset! myatom 2)
|
|
|
|
ADD_FUNCTION( |
|
|
|
ADD_FUNCTION( |
|
|
|
"reset!", |
|
|
|
"reset!", |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (nodes.size() != 2) { |
|
|
|
CHECK_ARG_COUNT_IS("reset!", nodes.size(), 2); |
|
|
|
Error::the().add(format("wrong number of arguments: reset!, {}", nodes.size())); |
|
|
|
|
|
|
|
return nullptr; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!is<Atom>(nodes.front().get())) { |
|
|
|
VALUE_CAST(atom, Atom, nodes.front()); |
|
|
|
Error::the().add(format("wrong argument type: atom, '{}'", nodes.front())); |
|
|
|
|
|
|
|
return nullptr; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
auto atom = std::static_pointer_cast<Atom>(*nodes.begin()); |
|
|
|
|
|
|
|
auto value = *std::next(nodes.begin()); |
|
|
|
auto value = *std::next(nodes.begin()); |
|
|
|
|
|
|
|
|
|
|
|
atom->reset(value); |
|
|
|
atom->reset(value); |
|
|
@ -490,25 +418,12 @@ ADD_FUNCTION( |
|
|
|
ADD_FUNCTION( |
|
|
|
ADD_FUNCTION( |
|
|
|
"swap!", |
|
|
|
"swap!", |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (nodes.size() < 2) { |
|
|
|
CHECK_ARG_COUNT_AT_LEAST("swap!", nodes.size(), 2); |
|
|
|
Error::the().add(format("wrong number of arguments: swap!, {}", nodes.size())); |
|
|
|
|
|
|
|
return nullptr; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
auto first_argument = *nodes.begin(); |
|
|
|
|
|
|
|
auto second_argument = *std::next(nodes.begin()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!is<Atom>(first_argument.get())) { |
|
|
|
VALUE_CAST(atom, Atom, nodes.front()); |
|
|
|
Error::the().add(format("wrong argument type: atom, '{}'", first_argument)); |
|
|
|
|
|
|
|
return nullptr; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!is<Callable>(second_argument.get())) { |
|
|
|
auto second_argument = *std::next(nodes.begin()); |
|
|
|
Error::the().add(format("wrong argument type: function, '{}'", second_argument)); |
|
|
|
IS_VALUE(Callable, second_argument); |
|
|
|
return nullptr; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
auto atom = std::static_pointer_cast<Atom>(first_argument); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Remove atom and function from the argument list, add atom value
|
|
|
|
// Remove atom and function from the argument list, add atom value
|
|
|
|
nodes.pop_front(); |
|
|
|
nodes.pop_front(); |
|
|
@ -532,21 +447,12 @@ ADD_FUNCTION( |
|
|
|
ADD_FUNCTION( |
|
|
|
ADD_FUNCTION( |
|
|
|
"cons", |
|
|
|
"cons", |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (nodes.size() != 2) { |
|
|
|
CHECK_ARG_COUNT_IS("cons", nodes.size(), 2); |
|
|
|
Error::the().add(format("wrong number of arguments: cons, {}", nodes.size())); |
|
|
|
|
|
|
|
return nullptr; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
auto first_argument = *nodes.begin(); |
|
|
|
|
|
|
|
auto second_argument = *std::next(nodes.begin()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!is<Collection>(second_argument.get())) { |
|
|
|
VALUE_CAST(collection, Collection, (*std::next(nodes.begin()))); |
|
|
|
Error::the().add(format("wrong argument type: list, '{}'", second_argument)); |
|
|
|
|
|
|
|
return nullptr; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
auto result_nodes = std::static_pointer_cast<Collection>(second_argument)->nodes(); |
|
|
|
auto result_nodes = collection->nodes(); |
|
|
|
result_nodes.push_front(first_argument); |
|
|
|
result_nodes.push_front(nodes.front()); |
|
|
|
|
|
|
|
|
|
|
|
return makePtr<List>(result_nodes); |
|
|
|
return makePtr<List>(result_nodes); |
|
|
|
}); |
|
|
|
}); |
|
|
@ -558,12 +464,8 @@ ADD_FUNCTION( |
|
|
|
std::list<ValuePtr> result_nodes; |
|
|
|
std::list<ValuePtr> result_nodes; |
|
|
|
|
|
|
|
|
|
|
|
for (auto node : nodes) { |
|
|
|
for (auto node : nodes) { |
|
|
|
if (!is<Collection>(node.get())) { |
|
|
|
VALUE_CAST(collection, Collection, node); |
|
|
|
Error::the().add(format("wrong argument type: list, '{}'", node)); |
|
|
|
auto argument_nodes = collection->nodes(); |
|
|
|
return nullptr; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
auto argument_nodes = std::static_pointer_cast<Collection>(node)->nodes(); |
|
|
|
|
|
|
|
result_nodes.splice(result_nodes.end(), argument_nodes); |
|
|
|
result_nodes.splice(result_nodes.end(), argument_nodes); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -574,19 +476,11 @@ ADD_FUNCTION( |
|
|
|
ADD_FUNCTION( |
|
|
|
ADD_FUNCTION( |
|
|
|
"vec", |
|
|
|
"vec", |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (nodes.size() != 1) { |
|
|
|
CHECK_ARG_COUNT_IS("vec", nodes.size(), 1); |
|
|
|
Error::the().add(format("wrong number of arguments: vec, {}", nodes.size())); |
|
|
|
|
|
|
|
return nullptr; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!is<Collection>(nodes.front().get())) { |
|
|
|
|
|
|
|
Error::the().add(format("wrong argument type: list, '{}'", nodes.front())); |
|
|
|
|
|
|
|
return nullptr; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
auto result_nodes = std::static_pointer_cast<Collection>(nodes.front())->nodes(); |
|
|
|
VALUE_CAST(collection, Collection, nodes.front()); |
|
|
|
|
|
|
|
|
|
|
|
return makePtr<Vector>(result_nodes); |
|
|
|
return makePtr<Vector>(collection->nodes()); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
// -----------------------------------------
|
|
|
|
// -----------------------------------------
|
|
|
|