Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor slist and dlist according to NEURON #1110

Merged
merged 10 commits into from
Dec 7, 2023
13 changes: 12 additions & 1 deletion src/codegen/codegen_neuron_cpp_visitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,13 @@ void CodegenNeuronCppVisitor::print_neuron_includes() {


void CodegenNeuronCppVisitor::print_sdlists_init(bool print_initializers) {
iomaganaris marked this conversation as resolved.
Show resolved Hide resolved
printer->add_newline(2);
printer->add_line("static void _initlists() {");
printer->increase_indent();
printer->add_multi_line(R"CODE(
static int _first = 1;
if (!_first) return;
iomaganaris marked this conversation as resolved.
Show resolved Hide resolved
)CODE");
for (auto i = 0; i < info.prime_variables_by_order.size(); ++i) {
const auto& prime_var = info.prime_variables_by_order[i];
/// TODO: Something similar needs to happen for slist/dlist2 but I don't know their usage at
Expand Down Expand Up @@ -319,6 +326,9 @@ void CodegenNeuronCppVisitor::print_sdlists_init(bool print_initializers) {
position_of_float_var(prime_var_deriv_name));
}
}
printer->add_line("_first = 0;");
printer->decrease_indent();
printer->add_line("};");
}


Expand Down Expand Up @@ -389,7 +399,7 @@ void CodegenNeuronCppVisitor::print_mechanism_register() {
printer->add_newline(2);
printer->add_line("/** register channel with the simulator */");
printer->fmt_push_block("void _{}_reg()", info.mod_file);
print_sdlists_init(true);
printer->add_line("_initlists();");
// type related information
printer->add_newline();
printer->fmt_line("int mech_type = nrn_get_mechtype({}[1]);", get_channel_info_var_name());
Expand Down Expand Up @@ -659,6 +669,7 @@ void CodegenNeuronCppVisitor::print_codegen_routines() {
print_data_structures(true);
print_global_variables_for_hoc();
print_compute_functions(); // only nrn_cur and nrn_state
print_sdlists_init(true);
print_mechanism_register();
print_namespace_end();
codegen = false;
Expand Down
5 changes: 1 addition & 4 deletions test/unit/codegen/codegen_neuron_cpp_visitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,10 +227,7 @@ void _nrn_mechanism_register_data_fields(Args&&... args) {
THEN("Placeholder registration function is printed") {
std::string expected_placeholder_reg = R"(/** register channel with the simulator */
void __test_reg() {
/* s */
_slist1[0] = {4, 0};
/* Ds */
_dlist1[0] = {7, 0};
_initlists();
iomaganaris marked this conversation as resolved.
Show resolved Hide resolved

int mech_type = nrn_get_mechtype(mechanism_info[1]);
_nrn_mechanism_register_data_fields(mech_type,
Expand Down
Loading