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
8 changes: 7 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,10 @@ void CodegenNeuronCppVisitor::print_neuron_includes() {


void CodegenNeuronCppVisitor::print_sdlists_init(bool print_initializers) {
iomaganaris marked this conversation as resolved.
Show resolved Hide resolved
/// _initlists() should only be called once by the mechanism registration function
/// (_<mod_file>_reg())
printer->add_newline(2);
printer->push_block("static void _initlists()");
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 +323,7 @@ void CodegenNeuronCppVisitor::print_sdlists_init(bool print_initializers) {
position_of_float_var(prime_var_deriv_name));
}
}
printer->pop_block(";");
}


Expand Down Expand Up @@ -396,7 +401,7 @@ void CodegenNeuronCppVisitor::print_mechanism_register() {
printer->add_newline(2);
printer->add_line("/** register channel with the simulator */");
printer->fmt_push_block("extern \"C\" void _{}_reg()", info.mod_file);
print_sdlists_init(true);
printer->add_line("_initlists();");
printer->add_newline();

const auto compute_functions_parameters =
Expand Down Expand Up @@ -731,6 +736,7 @@ void CodegenNeuronCppVisitor::print_codegen_routines() {
print_nrn_alloc();
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
14 changes: 11 additions & 3 deletions test/unit/codegen/codegen_neuron_cpp_visitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,13 +227,21 @@ void _nrn_mechanism_register_data_fields(Args&&... args) {
REQUIRE_THAT(generated,
ContainsSubstring(reindent_and_trim_text(expected_placeholder_nrn_state)));
}
THEN("Placeholder registration function is printed") {
std::string expected_placeholder_reg = R"CODE(/** register channel with the simulator */
extern "C" void __test_reg() {
THEN("Initialization function for slist/dlist is printed correctly") {
std::string expected_initlists = R"(
static void _initlists() {
/* s */
_slist1[0] = {4, 0};
/* Ds */
_dlist1[0] = {7, 0};
};)";
iomaganaris marked this conversation as resolved.
Show resolved Hide resolved

REQUIRE_THAT(generated, ContainsSubstring(reindent_and_trim_text(expected_initlists)));
}
THEN("Placeholder registration function is printed") {
std::string expected_placeholder_reg = R"CODE(/** register channel with the simulator */
extern "C" void __test_reg() {
_initlists();
iomaganaris marked this conversation as resolved.
Show resolved Hide resolved

register_mech(mechanism_info, nrn_alloc_pas_test, nrn_cur_pas_test, nrn_jacob_pas_test, nrn_state_pas_test, nrn_init_pas_test, hoc_nrnpointerindex, 1);

Expand Down
Loading