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 e87c7c3 commit fbe64de
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
24 changes: 16 additions & 8 deletions src/codegen/codegen_neuron_cpp_visitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -389,19 +389,27 @@ void CodegenNeuronCppVisitor::print_hoc_py_wrapper_setup(
}
}

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;
}

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 (info.point_process) {
printer->fmt_push_block("static double _hoc_{}(void* _vptr)", block_name);
return fmt::format("static double _hoc_{}(void* _vptr)", block_name);
} else if (wrapper_type == InterpreterWrapper::HOC) {
printer->fmt_push_block("static void _hoc_{}(void)", block_name);
return fmt::format("static void _hoc_{}(void)", block_name);
} else {
printer->fmt_push_block("static double _npy_{}(Prop* _prop)", block_name);
return fmt::format("static double _npy_{}(Prop* _prop)", 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;
}

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 fbe64de

Please sign in to comment.