Skip to content

Commit

Permalink
Merge pull request #2064 from anutosh491/GSoC_PR4.1
Browse files Browse the repository at this point in the history
Added support for freeing basic variables
  • Loading branch information
certik authored Jun 30, 2023
2 parents c210323 + 9157a20 commit 32273ce
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/libasr/codegen/asr_to_c_cpp.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ class SymEngineQueue {
std::vector<std::string> queue;
int queue_front = -1;
std::string& symengine_src;
std::unordered_set<std::string> variables_to_free;

SymEngineQueue(std::string& symengine_src) : symengine_src(symengine_src) {}

Expand All @@ -102,11 +103,13 @@ class SymEngineQueue {
symengine_src = indent + "basic " + var + ";\n";
symengine_src += indent + "basic_new_stack(" + var + ");\n";
}
variables_to_free.insert(queue[queue_front]);
return queue[queue_front++];
}

void pop() {
LCOMPILERS_ASSERT(queue_front != -1 && queue_front < static_cast<int>(queue.size()));
variables_to_free.insert(queue[queue_front]);
queue_front++;
}
};
Expand Down Expand Up @@ -783,6 +786,10 @@ R"(#include <stdio.h>
+ ";\n";
}

for (const auto& var : symengine_queue.variables_to_free) {
current_body += indent + "basic_free_stack(" + var + ");\n";
}
symengine_queue.variables_to_free.clear();
if (decl.size() > 0 || current_body.size() > 0) {
sub += "{\n" + decl + current_body + "}\n";
} else {
Expand Down

0 comments on commit 32273ce

Please sign in to comment.