NEURON
code.cpp File Reference
#include <../../nrnconf.h>
#include "backtrace_utils.h"
#include "bbslsrv2.h"
#include "cabcode.h"
#include "code.h"
#include "hocstr.h"
#include "parse.hpp"
#include "ocfunc.h"
#include "ocmisc.h"
#include "oc_ansi.h"
#include "hocparse.h"
#include "equation.h"
#include <nrnmpi.h>
#include "nrnfilewrap.h"
#include "utils/enumerate.h"
#include "options.h"
#include "section.h"
#include <cerrno>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <variant>
#include <sstream>

Go to the source code of this file.

Classes

struct  stack_ndim_datum
 
struct  nrn::oc::frame
 

Namespaces

 nrn
 
 nrn::oc
 
 neuron
 In mechanism libraries, cannot use auto const token = nrn_ensure_model_data_are_sorted(); because the return type is incomplete (from include/neuron/model_data.hpp).
 

Macros

#define BBSPOLL
 
#define NPROG   50000
 
#define NFRAME   512 /* default size */
 
#define DEBUG_GARBAGE   1
 
#define TOBJ_POOL_SIZE   50
 
#define MAXINITFCNS   10
 
#define HOC_TEMP_CHARPTR_SIZE   128
 
#define relative(pc)   (pc + (pc)->i)
 

Typedefs

using StackDatum = std::variant< double, Symbol *, int, stack_ndim_datum, Object **, Object *, char **, neuron::container::generic_data_handle, std::nullptr_t >
 
using Frame = nrn::oc::frame
 

Functions

void bbs_handle ()
 
int nrn_isecstack ()
 
void debugzz (Inst *)
 
std::ostream & operator<< (std::ostream &os, const stack_ndim_datum &d)
 
Object ** hoc_temp_objptr (Object *obj)
 
void hoc_tobj_unref (Object **p)
 
void hoc_unref_defer ()
 
template<typename T >
T const & hoc_look_inside_stack (int i)
 Get the stack entry at depth i. More...
 
int hoc_stack_type ()
 Get the type of the top entry. More...
 
bool hoc_stack_type_is_ndim ()
 
void hoc_pop_defer ()
 
void hoc_stkobj_unref (Object *o, int stkindex)
 
static void frameobj_clean (Frame *f)
 
static void frame_objauto_recover_on_err (Frame *ff)
 
static void stack_obtmp_recover_on_err (int tcnt)
 
void hoc_init_space ()
 
void hoc_prstack ()
 Print up to the 10 most-recently-pushed elements on the stack. More...
 
void hoc_on_init_register (Pfrv pf)
 
void hoc_initcode ()
 
void oc_save_code (Inst **a1, Inst **a2, std::size_t &a3, Frame **a4, int *a5, int *a6, Inst **a7, Frame **a8, std::size_t &a9, Symlist **a10, Inst **a11, int *a12)
 
void oc_restore_code (Inst **a1, Inst **a2, std::size_t &a3, Frame **a4, int *a5, int *a6, Inst **a7, Frame **a8, std::size_t &a9, Symlist **a10, Inst **a11, int *a12)
 
int hoc_strgets_need (void)
 
char * hoc_strgets (char *cbuf, int nc)
 
static void rinitcode ()
 
int hoc_ParseExec (int yystart)
 
int hoc_xopen_run (Symbol *sp, const char *str)
 
char ** hoc_temp_charptr (void)
 
int hoc_is_temp_charptr (char **cpp)
 
int hoc_stacktype ()
 
void hoc_pushx (double d)
 
void hoc_pushobj (Object **d)
 
void hoc_push_object (Object *d)
 
void hoc_pushstr (char **d)
 
void hoc_push_string ()
 
void hoc_pushpx (double *d)
 
void hoc_pushs (Symbol *d)
 
void hoc_pushi (int d)
 
void hoc_push (neuron::container::generic_data_handle handle)
 
void hoc_push_ndim (int d)
 
int hoc_argtype (int narg)
 
int hoc_is_double_arg (int narg)
 
int hoc_is_pdouble_arg (int narg)
 
int hoc_is_str_arg (int narg)
 
int hoc_is_object_arg (int narg)
 
int hoc_is_tempobj_arg (int narg)
 
Objecthoc_obj_look_inside_stack (int i)
 
int hoc_inside_stacktype (int i)
 
double hoc_xpop ()
 
double * hoc_pxpop ()
 
Symbolhoc_spop ()
 
int hoc_pop_ndim ()
 
Object ** hoc_objpop ()
 Pop pointer to object pointer and return top elem from stack. More...
 
TmpObject hoc_pop_object ()
 
char ** hoc_strpop ()
 
int hoc_ipop ()
 
void hoc_nopop ()
 
void hoc_constpush ()
 
void hoc_pushzero ()
 
void hoc_varpush ()
 
void hoc_forcode (void)
 
void hoc_shortfor (void)
 
void hoc_iterator (void)
 
void hoc_iterator_object (Symbol *sym, int argcount, Inst *beginpc, Inst *endpc, Object *ob)
 
void hoc_iterator_stmt ()
 
static void for_segment2 (Symbol *sym, int mode)
 
void for_segment (void)
 
void for_segment1 (void)
 
void hoc_ifcode (void)
 
void hoc_Break (void)
 
void hoc_Continue (void)
 
void hoc_Stop (void)
 
void hoc_define (Symbol *sp)
 
void frame_debug ()
 
void hoc_push_frame (Symbol *sp, int narg)
 
void hoc_pop_frame (void)
 
void hoc_call ()
 
void hoc_fake_call (Symbol *s)
 
double hoc_call_func (Symbol *s, int narg)
 
void hoc_call_func_result_on_stack (Symbol *s, int narg)
 
void hoc_ret ()
 
void hoc_funcret (void)
 
void hoc_procret (void)
 
void hocobjret (void)
 
void hoc_Numarg (void)
 
void hoc_Argtype ()
 
int ifarg (int narg)
 
Object ** hoc_objgetarg (int narg)
 
char ** hoc_pgargstr (int narg)
 
double * hoc_getarg (int narg)
 
int hoc_argindex (void)
 
void hoc_arg ()
 
void hoc_stringarg (void)
 
double hoc_opasgn (int op, double dest, double src)
 
void hoc_argassign (void)
 
void hoc_argrefasgn (void)
 
void hoc_argref (void)
 
void hoc_argrefarg (void)
 
void hoc_bltin (void)
 
Symbolhoc_get_symbol (const char *var)
 
Symbolhoc_get_last_pointer_symbol (void)
 
void hoc_autoobject (void)
 
void hoc_eval (void)
 
void hoc_evalpointer ()
 
void hoc_add (void)
 
void hoc_sub (void)
 
void hoc_mul (void)
 
void hoc_div (void)
 
void hoc_cyclic (void)
 
void hoc_negate ()
 
void hoc_gt (void)
 
void hoc_lt ()
 
void hoc_ge (void)
 
void hoc_le (void)
 
void hoc_eq ()
 
void hoc_ne ()
 
void hoc_and ()
 
void hoc_or (void)
 
void hoc_not (void)
 
void hoc_power ()
 
void hoc_assign ()
 
void hoc_assign_str (char **cpp, const char *buf)
 
void hoc_assstr (void)
 
char * hoc_araystr (Symbol *sym, int index, Objectdata *obd)
 
static void ndim_chk_helper (int ndim)
 
void hoc_chk_sym_has_ndim1 ()
 
void hoc_chk_sym_has_ndim2 ()
 
void hoc_chk_sym_has_ndim ()
 
int hoc_araypt (Symbol *sp, int type)
 
void hoc_print ()
 
void hoc_prexpr ()
 
void hoc_prstr (void)
 
void hoc_delete_symbol (void)
 
void hoc_newline (void)
 
void hoc_varread (void)
 
static Instcodechk (void)
 
Insthoc_Code (Pfrv f)
 
Insthoc_codei (int f)
 
Insthoc_codeptr (void *vp)
 
void hoc_codesym (Symbol *f)
 
void hoc_codein (Inst *f)
 
void hoc_insertcode (Inst *begin, Inst *end, Pfrv f)
 
void hoc_execute (Inst *p)
 

Variables

int bbs_poll_
 
HocReturnType hoc_return_type_code = HocReturnType::floating
 
static std::vector< StackDatumstack {}
 The stack. More...
 
Insthoc_prog
 
Insthoc_progp
 
Insthoc_pc
 
Insthoc_progbase
 
Insthoc_prog_parse_recover
 
int hoc_returning
 
static Frameframe
 
static Framefp
 
static Frameframelast
 
static Object ** hoc_temp_obj_pool_
 
static int obj_pool_index_
 
static int tobj_count
 
static Objectunref_defer_
 
static int maxinitfcns
 
static Pfrv initfcns [MAXINITFCNS]
 
static Framerframe
 
static std::size_t rstack
 
static const char * parsestr
 
static char * stmp [HOC_TEMP_CHARPTR_SIZE]
 
static int istmp = 0
 

Macro Definition Documentation

◆ BBSPOLL

#define BBSPOLL
Value:
if (--bbs_poll_ == 0) { \
bbs_handle(); \
}
int bbs_poll_
Definition: code.cpp:32

Definition at line 34 of file code.cpp.

◆ DEBUG_GARBAGE

#define DEBUG_GARBAGE   1

Definition at line 116 of file code.cpp.

◆ HOC_TEMP_CHARPTR_SIZE

#define HOC_TEMP_CHARPTR_SIZE   128

Definition at line 713 of file code.cpp.

◆ MAXINITFCNS

#define MAXINITFCNS   10

Definition at line 431 of file code.cpp.

◆ NFRAME

#define NFRAME   512 /* default size */

Definition at line 95 of file code.cpp.

◆ NPROG

#define NPROG   50000

Definition at line 75 of file code.cpp.

◆ relative

#define relative (   pc)    (pc + (pc)->i)

Definition at line 998 of file code.cpp.

◆ TOBJ_POOL_SIZE

#define TOBJ_POOL_SIZE   50

Definition at line 117 of file code.cpp.

Typedef Documentation

◆ Frame

Definition at line 94 of file code.cpp.

◆ StackDatum

using StackDatum = std::variant<double, Symbol*, int, stack_ndim_datum, Object**, Object*, char**, neuron::container::generic_data_handle, std::nullptr_t>

Definition at line 58 of file code.cpp.

Function Documentation

◆ bbs_handle()

void bbs_handle ( )

Definition at line 210 of file bbssrvmpi.cpp.

◆ codechk()

static Inst* codechk ( void  )
static

Definition at line 2480 of file code.cpp.

◆ debugzz()

void debugzz ( Inst p)

Definition at line 32 of file debug.cpp.

◆ for_segment()

void for_segment ( void  )

Definition at line 1270 of file code.cpp.

◆ for_segment1()

void for_segment1 ( void  )

Definition at line 1274 of file code.cpp.

◆ for_segment2()

static void for_segment2 ( Symbol sym,
int  mode 
)
static

Definition at line 1190 of file code.cpp.

◆ frame_objauto_recover_on_err()

static void frame_objauto_recover_on_err ( Frame ff)
static

Definition at line 361 of file code.cpp.

◆ frameobj_clean()

static void frameobj_clean ( Frame f)
static

Definition at line 349 of file code.cpp.

◆ hoc_add()

void hoc_add ( void  )

Definition at line 1969 of file code.cpp.

◆ hoc_and()

void hoc_and ( void  )

Definition at line 2127 of file code.cpp.

◆ hoc_arg()

void hoc_arg ( )

Definition at line 1656 of file code.cpp.

◆ hoc_argassign()

void hoc_argassign ( void  )

Definition at line 1692 of file code.cpp.

◆ hoc_argref()

void hoc_argref ( void  )

Definition at line 1730 of file code.cpp.

◆ hoc_argrefarg()

void hoc_argrefarg ( void  )

Definition at line 1749 of file code.cpp.

◆ hoc_argrefasgn()

void hoc_argrefasgn ( void  )

Definition at line 1709 of file code.cpp.

◆ hoc_Argtype()

void hoc_Argtype ( void  )

Definition at line 1580 of file code.cpp.

◆ hoc_assign()

void hoc_assign ( )

Definition at line 2159 of file code.cpp.

◆ hoc_assstr()

void hoc_assstr ( void  )

Definition at line 2272 of file code.cpp.

◆ hoc_autoobject()

void hoc_autoobject ( void  )

Definition at line 1817 of file code.cpp.

◆ hoc_bltin()

void hoc_bltin ( void  )

Definition at line 1760 of file code.cpp.

◆ hoc_Break()

void hoc_Break ( void  )

Definition at line 1298 of file code.cpp.

◆ hoc_call()

void hoc_call ( void  )

Definition at line 1398 of file code.cpp.

◆ hoc_chk_sym_has_ndim()

void hoc_chk_sym_has_ndim ( )

Definition at line 2334 of file code.cpp.

◆ hoc_chk_sym_has_ndim1()

void hoc_chk_sym_has_ndim1 ( )

Definition at line 2328 of file code.cpp.

◆ hoc_chk_sym_has_ndim2()

void hoc_chk_sym_has_ndim2 ( )

Definition at line 2331 of file code.cpp.

◆ hoc_Code()

Inst* hoc_Code ( Pfrv  f)

Definition at line 2488 of file code.cpp.

◆ hoc_codei()

Inst* hoc_codei ( int  f)

Definition at line 2493 of file code.cpp.

◆ hoc_codein()

void hoc_codein ( Inst f)

Definition at line 2509 of file code.cpp.

◆ hoc_codeptr()

Inst* hoc_codeptr ( void *  vp)

Definition at line 2499 of file code.cpp.

◆ hoc_codesym()

void hoc_codesym ( Symbol f)

Definition at line 2504 of file code.cpp.

◆ hoc_constpush()

void hoc_constpush ( void  )

Definition at line 984 of file code.cpp.

◆ hoc_Continue()

void hoc_Continue ( void  )

Definition at line 1303 of file code.cpp.

◆ hoc_cyclic()

void hoc_cyclic ( void  )

Definition at line 2007 of file code.cpp.

◆ hoc_define()

void hoc_define ( Symbol sp)

Definition at line 1313 of file code.cpp.

◆ hoc_delete_symbol()

void hoc_delete_symbol ( void  )

Definition at line 2422 of file code.cpp.

◆ hoc_div()

void hoc_div ( void  )

Definition at line 1996 of file code.cpp.

◆ hoc_eq()

void hoc_eq ( )

Definition at line 2071 of file code.cpp.

◆ hoc_eval()

void hoc_eval ( void  )

Definition at line 1827 of file code.cpp.

◆ hoc_evalpointer()

void hoc_evalpointer ( void  )

Definition at line 1903 of file code.cpp.

◆ hoc_execute()

void hoc_execute ( Inst p)

Definition at line 2531 of file code.cpp.

◆ hoc_forcode()

void hoc_forcode ( void  )

Definition at line 1000 of file code.cpp.

◆ hoc_funcret()

void hoc_funcret ( void  )

Definition at line 1523 of file code.cpp.

◆ hoc_ge()

void hoc_ge ( void  )

Definition at line 2055 of file code.cpp.

◆ hoc_get_last_pointer_symbol()

Symbol* hoc_get_last_pointer_symbol ( void  )

Definition at line 1789 of file code.cpp.

◆ hoc_gt()

void hoc_gt ( void  )

Definition at line 2039 of file code.cpp.

◆ hoc_ifcode()

void hoc_ifcode ( void  )

Definition at line 1284 of file code.cpp.

◆ hoc_init_space()

void hoc_init_space ( void  )

Definition at line 416 of file code.cpp.

◆ hoc_insertcode()

void hoc_insertcode ( Inst begin,
Inst end,
Pfrv  f 
)

Definition at line 2514 of file code.cpp.

◆ hoc_iterator()

void hoc_iterator ( void  )

Definition at line 1087 of file code.cpp.

◆ hoc_iterator_object()

void hoc_iterator_object ( Symbol sym,
int  argcount,
Inst beginpc,
Inst endpc,
Object ob 
)

Definition at line 1102 of file code.cpp.

◆ hoc_iterator_stmt()

void hoc_iterator_stmt ( void  )

Definition at line 1130 of file code.cpp.

◆ hoc_le()

void hoc_le ( void  )

Definition at line 2063 of file code.cpp.

◆ hoc_lt()

void hoc_lt ( )

Definition at line 2047 of file code.cpp.

◆ hoc_mul()

void hoc_mul ( void  )

Definition at line 1987 of file code.cpp.

◆ hoc_ne()

void hoc_ne ( void  )

Definition at line 2099 of file code.cpp.

◆ hoc_negate()

void hoc_negate ( )

Definition at line 2034 of file code.cpp.

◆ hoc_newline()

void hoc_newline ( void  )

Definition at line 2446 of file code.cpp.

◆ hoc_not()

void hoc_not ( void  )

Definition at line 2142 of file code.cpp.

◆ hoc_Numarg()

void hoc_Numarg ( void  )

Definition at line 1568 of file code.cpp.

◆ hoc_on_init_register()

void hoc_on_init_register ( Pfrv  pf)

Definition at line 462 of file code.cpp.

◆ hoc_or()

void hoc_or ( void  )

Definition at line 2134 of file code.cpp.

◆ hoc_power()

void hoc_power ( void  )

Definition at line 2150 of file code.cpp.

◆ hoc_prexpr()

void hoc_prexpr ( void  )

Definition at line 2381 of file code.cpp.

◆ hoc_print()

void hoc_print ( void  )

Definition at line 2374 of file code.cpp.

◆ hoc_procret()

void hoc_procret ( void  )

Definition at line 1533 of file code.cpp.

◆ hoc_prstr()

void hoc_prstr ( void  )

Definition at line 2409 of file code.cpp.

◆ hoc_push_string()

void hoc_push_string ( void  )

Definition at line 805 of file code.cpp.

◆ hoc_pushzero()

void hoc_pushzero ( void  )

Definition at line 989 of file code.cpp.

◆ hoc_shortfor()

void hoc_shortfor ( void  )

Definition at line 1030 of file code.cpp.

◆ hoc_Stop()

void hoc_Stop ( void  )

Definition at line 1308 of file code.cpp.

◆ hoc_strgets()

char* hoc_strgets ( char *  cbuf,
int  nc 
)

Definition at line 576 of file code.cpp.

◆ hoc_strgets_need()

int hoc_strgets_need ( void  )

Definition at line 572 of file code.cpp.

◆ hoc_stringarg()

void hoc_stringarg ( void  )

Definition at line 1664 of file code.cpp.

◆ hoc_sub()

void hoc_sub ( void  )

Definition at line 1978 of file code.cpp.

◆ hoc_unref_defer()

void hoc_unref_defer ( )

Definition at line 181 of file code.cpp.

◆ hoc_varpush()

void hoc_varpush ( void  )

Definition at line 994 of file code.cpp.

◆ hoc_varread()

void hoc_varread ( void  )

Definition at line 2451 of file code.cpp.

◆ hocobjret()

void hocobjret ( void  )

Definition at line 1544 of file code.cpp.

◆ ndim_chk_helper()

static void ndim_chk_helper ( int  ndim)
static

Definition at line 2314 of file code.cpp.

◆ nrn_isecstack()

int nrn_isecstack ( )

Definition at line 85 of file cabcode.cpp.

◆ oc_restore_code()

void oc_restore_code ( Inst **  a1,
Inst **  a2,
std::size_t &  a3,
Frame **  a4,
int *  a5,
int *  a6,
Inst **  a7,
Frame **  a8,
std::size_t &  a9,
Symlist **  a10,
Inst **  a11,
int *  a12 
)

Definition at line 535 of file code.cpp.

◆ oc_save_code()

void oc_save_code ( Inst **  a1,
Inst **  a2,
std::size_t &  a3,
Frame **  a4,
int *  a5,
int *  a6,
Inst **  a7,
Frame **  a8,
std::size_t &  a9,
Symlist **  a10,
Inst **  a11,
int *  a12 
)

Definition at line 509 of file code.cpp.

◆ operator<<()

std::ostream& operator<< ( std::ostream &  os,
const stack_ndim_datum d 
)

Definition at line 53 of file code.cpp.

◆ rinitcode()

static void rinitcode ( )
static

Definition at line 586 of file code.cpp.

◆ stack_obtmp_recover_on_err()

static void stack_obtmp_recover_on_err ( int  tcnt)
static

Definition at line 399 of file code.cpp.

Variable Documentation

◆ bbs_poll_

int bbs_poll_

Definition at line 32 of file code.cpp.

◆ fp

Frame * fp
static

Definition at line 96 of file code.cpp.

◆ frame

Frame* frame
static

Definition at line 96 of file code.cpp.

◆ framelast

Frame * framelast
static

Definition at line 96 of file code.cpp.

◆ hoc_pc

Inst* hoc_pc

Definition at line 78 of file code.cpp.

◆ hoc_prog

Inst* hoc_prog

Definition at line 76 of file code.cpp.

◆ hoc_prog_parse_recover

Inst* hoc_prog_parse_recover

Definition at line 80 of file code.cpp.

◆ hoc_progbase

Inst* hoc_progbase

Definition at line 79 of file code.cpp.

◆ hoc_progp

Inst* hoc_progp

Definition at line 77 of file code.cpp.

◆ hoc_return_type_code

HocReturnType hoc_return_type_code = HocReturnType::floating

Definition at line 42 of file code.cpp.

◆ hoc_temp_obj_pool_

Object** hoc_temp_obj_pool_
static

Definition at line 118 of file code.cpp.

◆ initfcns

Pfrv initfcns[MAXINITFCNS]
static

Definition at line 433 of file code.cpp.

◆ istmp

int istmp = 0
static

Definition at line 715 of file code.cpp.

◆ maxinitfcns

int maxinitfcns
static

Definition at line 432 of file code.cpp.

◆ obj_pool_index_

int obj_pool_index_
static

Definition at line 119 of file code.cpp.

◆ parsestr

const char* parsestr
static

Definition at line 507 of file code.cpp.

◆ rframe

Frame* rframe
static

Definition at line 505 of file code.cpp.

◆ rstack

std::size_t rstack
static

Definition at line 506 of file code.cpp.

◆ stack

std::vector<StackDatum> stack {}
static

The stack.

It would be nice to use std::stack, but it seems that for now its API is too restrictive.

Definition at line 73 of file code.cpp.

◆ stmp

char* stmp[HOC_TEMP_CHARPTR_SIZE]
static

Definition at line 714 of file code.cpp.

◆ tobj_count

int tobj_count
static

Definition at line 120 of file code.cpp.

◆ unref_defer_

Object* unref_defer_
static

Definition at line 179 of file code.cpp.