| 73 | |
| 74 | |
| 75 | struct Return { |
| 76 | template<typename T> |
| 77 | auto optimize(eval::AST_Node_Impl_Ptr<T> p) |
| 78 | { |
| 79 | if ( (p->identifier == AST_Node_Type::Def || p->identifier == AST_Node_Type::Lambda) |
| 80 | && !p->children.empty()) |
| 81 | { |
| 82 | auto &last_child = p->children.back(); |
| 83 | if (last_child->identifier == AST_Node_Type::Block) { |
| 84 | auto &block_last_child = last_child->children.back(); |
| 85 | if (block_last_child->identifier == AST_Node_Type::Return) { |
| 86 | if (block_last_child->children.size() == 1) { |
| 87 | last_child->children.back() = std::move(block_last_child->children[0]); |
| 88 | } |
| 89 | } |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | return p; |
| 94 | } |
| 95 | }; |
| 96 | |
| 97 | template<typename T> |
| 98 | bool contains_var_decl_in_scope(const eval::AST_Node_Impl<T> &node) |