Skip to content

Commit

Permalink
Add drop_buffer to the prelude
Browse files Browse the repository at this point in the history
  • Loading branch information
benruijl committed Aug 13, 2024
1 parent 39cb180 commit 612fb22
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions src/evaluate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1179,18 +1179,18 @@ impl<T: std::fmt::Display> ExpressionEvaluator<T> {
}

pub fn export_asm_str(&self, function_name: &str, include_header: bool) -> String {
let mut res = if include_header {
"#include <iostream>\n#include <complex>\n#include <cmath>\n\n".to_string()
} else {
String::new()
let mut res = String::new();
if include_header {
res += &"#include <iostream>\n#include <complex>\n#include <cmath>\n\n";
res += &"extern \"C\" void drop_buffer_complex(std::complex<double> *buffer)\n{\n\tdelete[] buffer;\n}\n\n";
res += &"extern \"C\" void drop_buffer_double(double *buffer)\n{\n\tdelete[] buffer;\n}\n\n";
};

res += &format!(
"extern \"C\" std::complex<double> *{}_create_buffer_complex()\n{{\n\treturn new std::complex<double>[{}];\n}}\n\n",
function_name,
self.stack.len()
);
res += &"extern \"C\" void drop_buffer_complex(std::complex<double> *buffer)\n{\n\tdelete[] buffer;\n}\n\n";

res += &format!(
"static const std::complex<double> CONSTANTS_complex[{}] = {{{}}};\n\n",
Expand All @@ -1215,8 +1215,6 @@ impl<T: std::fmt::Display> ExpressionEvaluator<T> {
function_name,
self.stack.len()
);
res +=
&"extern \"C\" void drop_buffer_double(double *buffer)\n{\n\tdelete[] buffer;\n}\n\n";

res += &format!(
"static const double CONSTANTS_double[{}] = {{{}}};\n\n",
Expand Down

0 comments on commit 612fb22

Please sign in to comment.