Skip to content

Commit

Permalink
Extract HOC/Py signature.
Browse files Browse the repository at this point in the history
  • Loading branch information
1uc committed Oct 18, 2024
1 parent 22f889b commit 844bcbe
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
24 changes: 14 additions & 10 deletions src/codegen/codegen_neuron_cpp_visitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,6 @@ void CodegenNeuronCppVisitor::print_function_procedure_helper(const ast::Block&
void CodegenNeuronCppVisitor::print_hoc_py_wrapper_call_impl(
const ast::Block* function_or_procedure_block,
InterpreterWrapper wrapper_type) {

const auto block_name = function_or_procedure_block->get_node_name();

const auto get_func_call_str = [&]() {
Expand All @@ -299,7 +298,6 @@ void CodegenNeuronCppVisitor::print_hoc_py_wrapper_call_impl(
return func_call;
};


printer->add_line("double _r = 0.0;");
if (function_or_procedure_block->is_function_block()) {
printer->add_indent();
Expand Down Expand Up @@ -391,19 +389,25 @@ void CodegenNeuronCppVisitor::print_hoc_py_wrapper_setup(
}
}


std::string CodegenNeuronCppVisitor::hoc_py_wrapper_signature(
const ast::Block* function_or_procedure_block,
InterpreterWrapper wrapper_type) {
const auto block_name = function_or_procedure_block->get_node_name();
if (wrapper_type == InterpreterWrapper::HOC) {
return hoc_function_signature(block_name);
} else {
return py_function_signature(block_name);
}
}

void CodegenNeuronCppVisitor::print_hoc_py_wrapper(const ast::Block* function_or_procedure_block,
InterpreterWrapper wrapper_type) {
if (info.point_process && wrapper_type == InterpreterWrapper::Python) {
return;
}
const auto block_name = function_or_procedure_block->get_node_name();
if (info.point_process) {
printer->fmt_push_block("static double _hoc_{}(void* _vptr)", block_name);
} else if (wrapper_type == InterpreterWrapper::HOC) {
printer->fmt_push_block("static void _hoc_{}(void)", block_name);
} else {
printer->fmt_push_block("static double _npy_{}(Prop* _prop)", block_name);
}

printer->push_block(hoc_py_wrapper_signature(function_or_procedure_block, wrapper_type));

print_hoc_py_wrapper_setup(function_or_procedure_block, wrapper_type);
print_hoc_py_wrapper_call_impl(function_or_procedure_block, wrapper_type);
Expand Down
6 changes: 6 additions & 0 deletions src/codegen/codegen_neuron_cpp_visitor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,12 @@ class CodegenNeuronCppVisitor: public CodegenCppVisitor {
void print_hoc_py_wrapper_call_impl(const ast::Block* function_or_procedure_block,
InterpreterWrapper wrapper_type);

/** Return the wrapper signature.
*
* Everything without the { or ;.
*/
std::string hoc_py_wrapper_signature(const ast::Block* function_or_procedure_block,
InterpreterWrapper wrapper_type);

void print_hoc_py_wrapper_function_definitions();

Expand Down

0 comments on commit 844bcbe

Please sign in to comment.