|
|
@ -253,10 +253,7 @@ static ValuePtr startsWith(ValuePtr ast, const std::string& symbol) |
|
|
|
static ValuePtr evalQuasiQuoteImpl(ValuePtr ast) |
|
|
|
static ValuePtr evalQuasiQuoteImpl(ValuePtr ast) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (is<HashMap>(ast.get()) || is<Symbol>(ast.get())) { |
|
|
|
if (is<HashMap>(ast.get()) || is<Symbol>(ast.get())) { |
|
|
|
auto quoted_list = makePtr<List>(); |
|
|
|
return makePtr<List>(makePtr<Symbol>("quote"), ast); |
|
|
|
quoted_list->add(makePtr<Symbol>("quote")); |
|
|
|
|
|
|
|
quoted_list->add(ast); |
|
|
|
|
|
|
|
return quoted_list; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (!is<Collection>(ast.get())) { |
|
|
|
if (!is<Collection>(ast.get())) { |
|
|
@ -283,32 +280,23 @@ static ValuePtr evalQuasiQuoteImpl(ValuePtr ast) |
|
|
|
for (auto it = nodes.rbegin(); it != nodes.rend(); ++it) { |
|
|
|
for (auto it = nodes.rbegin(); it != nodes.rend(); ++it) { |
|
|
|
const auto elt = *it; |
|
|
|
const auto elt = *it; |
|
|
|
|
|
|
|
|
|
|
|
auto list = makePtr<List>(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const auto splice_unquote = startsWith(elt, "splice-unquote"); // (list 2 2 2)
|
|
|
|
const auto splice_unquote = startsWith(elt, "splice-unquote"); // (list 2 2 2)
|
|
|
|
if (splice_unquote) { |
|
|
|
if (splice_unquote) { |
|
|
|
list->add(makePtr<Symbol>("concat")); |
|
|
|
// (cons 1 (concat (list 2 2 2) (cons 3 ())))
|
|
|
|
list->add(splice_unquote); |
|
|
|
result = makePtr<List>(makePtr<Symbol>("concat"), splice_unquote, result); |
|
|
|
list->add(result); |
|
|
|
|
|
|
|
result = list; // (cons 1 (concat (list 2 2 2) (cons 3 ())))
|
|
|
|
|
|
|
|
continue; |
|
|
|
continue; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
list->add(makePtr<Symbol>("cons")); |
|
|
|
// (cons 1 (cons 2 (cons 3 ())))
|
|
|
|
list->add(evalQuasiQuoteImpl(elt)); |
|
|
|
result = makePtr<List>(makePtr<Symbol>("cons"), evalQuasiQuoteImpl(elt), result); |
|
|
|
list->add(result); |
|
|
|
|
|
|
|
result = list; // (cons 1 (cons 2 (cons 3 ())))
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (is<List>(ast.get())) { |
|
|
|
if (is<List>(ast.get())) { |
|
|
|
return result; |
|
|
|
return result; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Wrap Vector in (vec)
|
|
|
|
// Wrap result in (vec) for Vector types
|
|
|
|
auto vector = makePtr<List>(); |
|
|
|
return makePtr<List>(makePtr<Symbol>("vec"), result); |
|
|
|
vector->add(makePtr<Symbol>("vec")); |
|
|
|
|
|
|
|
vector->add(result); |
|
|
|
|
|
|
|
return vector; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void Eval::evalQuasiQuote(const std::list<ValuePtr>& nodes, EnvironmentPtr env) |
|
|
|
void Eval::evalQuasiQuote(const std::list<ValuePtr>& nodes, EnvironmentPtr env) |
|
|
|