NEURON
hocdec.h
Go to the documentation of this file.
1 
2 #ifndef hocdec_h
3 #define hocdec_h
4 #define INCLUDEHOCH 1
5 #define OOP 1
6 
7 
8 #include <stdio.h>
9 #include "nrnapi.h"
10 #include "hocassrt.h" /* hoc_execerror instead of abort */
11 #include "nrnassrt.h" /* assert in case of side effects (eg. scanf) */
12 #include <string.h>
13 
14 #define gargstr hoc_gargstr
15 #define getarg hoc_getarg
16 
17 /* the dec alpha cxx doesn't understand struct foo* inside a struct */
18 
19 #if defined(__cplusplus)
20 #define HocStruct /**/
21 #define HocTypedef /**/
22 #define HocUnion /**/
23 union Inst;
24 struct Symbol;
25 struct Arrayinfo;
26 struct Proc;
27 struct Symlist;
28 union Datum;
29 struct cTemplate;
30 union Objectdata;
31 struct Object;
32 struct hoc_Item;
33 #else
34 #define HocStruct struct
35 #define HocUnion union
36 #define HocTypedef typedef
37 #endif
38 
39 typedef int (*Pfri)(void);
40 typedef void (*Pfrv)(void);
41 typedef double (*Pfrd)(void);
42 typedef struct Object** (*Pfro)(void);
43 typedef const char** (*Pfrs)(void);
44 
45 typedef int (*Pfri_vp)(void*);
46 typedef void (*Pfrv_vp)(void*);
47 typedef double (*Pfrd_vp)(void*);
48 typedef struct Object** (*Pfro_vp)(void*);
49 typedef const char** (*Pfrs_vp)(void*);
50 
51 typedef union Inst { /* machine instruction list type */
62  void* ptr;
63  int i;
64 } Inst;
65 
66 #define STOP (Inst*) 0
67 
68 typedef struct Arrayinfo { /* subscript info for arrays */
69  unsigned* a_varn; /* dependent variable number for array elms */
70  int nsub; /* number of subscripts */
71  int refcount; /* because one object always uses symbol's */
72  int sub[1]; /* subscript range */
74 
75 typedef struct Proc {
76  Inst defn; /* FUNCTION, PROCEDURE, FUN_BLTIN */
77  unsigned long size; /* length of instruction list */
78  HocStruct Symlist* list; /* For constants and strings */
79  /* not used by FUN_BLTIN */
80  int nauto; /* total # local variables */
81  int nobjauto; /* the last of these are pointers to objects */
82 } Proc;
83 
84 typedef struct Symlist {
88 
89 typedef char* Upoint;
90 
91 #define NOTUSER 0
92 #define USERINT 1 /* For subtype */
93 #define USERDOUBLE 2
94 #define USERPROPERTY 3 /* for newcable non-range variables */
95 #define USERFLOAT 4 /* John Miller's NEMO uses floats */
96 #if NEMO
97 #define NEMONODE 5 /* looks syntactically like vector */
98 #define NEMOAREA 6 /* looks like vector */
99 #endif
100 #define SYMBOL 7 /* for stack type */
101 #define OBJECTTMP 8 /* temporary object on stack */
102 #define STKOBJ_UNREF 9 /* already unreffed temporary object on stack */
103 #define DYNAMICUNITS 10 /* {modern, legacy} units pair */
104 #define CPLUSOBJECT 16 /* c++ registered class */
105 #define JAVAOBJECT 32 /* c++ registered class */
106 /* above two are bits, next must start at 64 */
107 #define OBJECTALIAS 1
108 #define VARALIAS 2
109 
110 typedef struct HocSymExtension {
111  float* parmlimits; /* some variables have suggested bounds */
112  char* units;
113  float tolerance; /* some states have cvode absolute tolerance */
115 
116 typedef struct Symbol { /* symbol table entry */
117  char* name;
118  short type;
119  short subtype; /* Flag for user integers */
120  /**
121  * Note: `public` is a reserved keyword. Keeping following __cplusplus comments a bit longer
122  * for future reference, with upcoming work for NMODL + eventual mod files to support cpp.
123  */
124  //#if defined(__cplusplus)
125  short cpublic; /* flag set public variable */
126  //#else
127  // short public; /* flag set public variable */
128  //#endif
129  short defined_on_the_fly; /* moved here because otherwize gcc and borland do not align the same
130  way */
131  union {
132  int oboff; /* offset into object data pointer space */
133 #if 0 /* these are now found via oboff. */
134  char *str; /* STRING */
135  HocStruct Object **objvar; /* possibly an array of object variables */
136 #endif
137  double* pval; /* User defined doubles - also for alias to scalar */
138  HocStruct Object* object_; /* alias to an object */
139  char* cstr; /* constant string */
140  double* pnum; /* Numbers */
141  int* pvalint; /* User defined integers */
142  float* pvalfloat; /* User defined floats */
143  int u_auto; /* stack offset # for AUTO variable */
144  double (*ptr)(double); /* if BLTIN */ // TODO: double as parameter?
146  struct {
147  short type; /* Membrane type to find Prop */
148  int index; /* prop->param[index] */
149  } rng;
150  HocStruct Symbol** ppsym; /* Pointer to symbol pointer array */
151  //#if defined(__cplusplus)
153  //#else
154  // HocStruct cTemplate *template;
155  //#endif
156  HocStruct Symbol* sym; /* for external */
157  } u;
158  unsigned s_varn; /* dependent variable number - 0 means indep */
159  Arrayinfo* arayinfo; /* ARRAY information if null then scalar */
160  HocSymExtension* extra; /* additions to symbol allow compatibility
161  with old nmodl dll's */
162  HocStruct Symbol* next; /* to link to another */
164 #define ISARRAY(arg) (arg->arayinfo != (Arrayinfo*) 0)
165 
166 
167 #ifndef hoc_list_h
168 #if defined(__cplusplus)
169 #define hoc_List struct hoc_Item
170 #else
171 typedef struct hoc_Item hoc_List;
172 #define List hoc_List
173 #define Item hoc_Item
174 #endif
175 #endif
176 
177 typedef union Datum { /* interpreter stack type */
178  double val;
180  int i;
181  double* pval; /* first used with Eion in NEURON */
183  HocStruct Object* obj; /* sections keep this to construct a name */
184  char** pstr;
187  void* _pvoid; /* not used on stack, see nrnoc/point.cpp */
189 
190 #if OOP
191 //#if defined(__cplusplus)
192 typedef struct cTemplate {
193  //#else
194  // typedef struct Template {
195  //#endif
199  int is_point_; /* actually the pointtype > 0 if a point process */
200  Symbol* init; /* null if there is no initialization function */
201  Symbol* unref; /* null if there is no function to call when refcount is decremented */
202  int index; /* next unique integer used for name for section */
203  int count; /* how many of this kind of object */
204  hoc_List* olist; /* list of all instances */
205  int id;
206  void* observers; /* hook to c++ ClassObservable */
207  void* (*constructor)(struct Object*);
208  void (*destructor)(void*);
209  void (*steer)(void*); /* normally nil */
210  int (*checkpoint)(void**);
211  //#if defined(__cplusplus)
213 //#else
214 //}
215 //#endif
216 
217 typedef union Objectdata {
218  double* pval; /* pointer to array of doubles, usually just 1 */
219  char** ppstr; /* pointer to pointer to string ,allows vectors someday*/
220  HocStruct Object** pobj; /* pointer to array of object pointers, usually just 1*/
221  HocStruct hoc_Item** psecitm; /* array of pointers to section items, usually just 1 */
222  hoc_List** plist; /* array of pointers to linked lists */
224  void* _pvoid; /* Point_process */
226 
227 typedef struct Object {
228  int refcount; /* how many object variables point to this */
229  int index; /* unique integer used for names of sections */
230  union {
231  Objectdata* dataspace; /* Points to beginning of object's data */
232  void* this_pointer; /* the c++ object */
233  } u;
234 #if defined(__cplusplus)
235  cTemplate* ctemplate;
236 #else
237  cTemplate* template;
238 #endif
239  void* aliases; /* more convenient names for e.g. Vector or List elements dynamically created by
240  this object*/
241  HocStruct hoc_Item* itm_me; /* this object in the template list */
242  HocStruct hoc_Item* secelm_; /* last of a set of contiguous section_list items used by forall */
243  void* observers; /* hook to c++ ObjObservable */
244  short recurse; /* to stop infinite recursions */
245  short unref_recurse_cnt; /* free only after last return from unref callback */
247 #endif
248 
249 typedef struct { /* User Functions */
250  const char* name;
252 } VoidFunc;
253 
254 typedef struct { /* User Double Scalars */
255  const char* name;
256  double* pdoub;
257 } DoubScal;
258 
259 typedef struct { /* User Vectors */
260  const char* name;
261  double* pdoub;
262  int index1;
263 } DoubVec;
264 
265 typedef struct { /* recommended limits for symbol values */
266  const char* name;
267  float bnd[2];
268 } HocParmLimits;
269 
270 typedef struct { /* recommended tolerance for CVODE */
271  const char* name;
272  float tolerance;
274 
275 typedef struct { /* units for symbol values */
276  const char* name;
277  char* units;
278 } HocParmUnits;
279 
280 #include "oc_ansi.h"
281 
282 #if defined(__cplusplus)
283 extern "C" {
284 #endif
285 
286 extern void* emalloc(size_t n);
287 extern void* ecalloc(size_t n, size_t size);
288 extern void* erealloc(void* ptr, size_t n);
289 
290 #if defined(__cplusplus)
291 }
292 #endif
293 
294 
296 extern Inst* hoc_pc;
297 
298 extern Objectdata* hoc_objectdata;
300 extern Object* hoc_thisobject;
301 extern Symlist* hoc_symlist;
304 extern Objectdata* hoc_objectdata_save(void);
306 #define OPVAL(sym) hoc_objectdata[sym->u.oboff].pval
307 #define OPSTR(sym) hoc_objectdata[sym->u.oboff].ppstr
308 #define OPOBJ(sym) hoc_objectdata[sym->u.oboff].pobj
309 #define OPSECITM(sym) hoc_objectdata[sym->u.oboff].psecitm
310 #define OPLIST(sym) hoc_objectdata[sym->u.oboff].plist
311 #define OPARINFO(sym) hoc_objectdata[sym->u.oboff + 1].arayinfo
312 
313 #if LINT
314 #undef assert
315 #define assert(arg) \
316  { \
317  if (arg) \
318  ; \
319  } /* so fprintf doesn't give lint */
320 #undef IGNORE
321 #define IGNORE(arg) \
322  { \
323  if (arg) \
324  ; \
325  }
326 #define LINTUSE(arg) \
327  { \
328  if (arg) \
329  ; \
330  }
331 char* cplint;
332 int ilint;
333 #define Strcat cplint = strcat
334 #define Strncat cplint = strncat
335 #define Strcpy cplint = strcpy
336 #define Strncpy cplint = strncpy
337 #define Sprintf cplint = sprintf
338 #define Printf ilint = printf
339 #else
340 #if defined(__TURBOC__)
341 #undef IGNORE
342 #define IGNORE
343 #else
344 #undef IGNORE
345 #define IGNORE(arg) arg
346 #endif
347 #define LINTUSE(arg)
348 #define Strcat strcat
349 #define Strncat strncat
350 #define Strcpy strcpy
351 #define Strncpy strncpy
352 #define Sprintf sprintf
353 #define Printf nrnpy_pr
354 #endif
355 
356 /* EINTR handling for LINDA */
357 #if LINDA
358 #include <errno.h>
359 #define ERRCHK(c1) \
360  { \
361  errno = EINTR; \
362  while (errno == EINTR) { \
363  errno = 0; \
364  c1 \
365  } \
366  }
367 
368 #else
369 #define ERRCHK(c1) c1
370 #endif
371 
372 #define IFGUI if (hoc_usegui) {
373 #define ENDGUI }
374 
375 extern int hoc_usegui; /* when 0 does not make interviews calls */
376 extern int nrn_istty_;
377 extern int parallel_sub; /* for use with parallel neuron (see parallel.cl) */
378 
379 #define NOT_PARALLEL_SUB(c1) \
380  { \
381  if (!parallel_sub) \
382  c1 \
383  }
384 
385 /* Enter handling for PVM NJP 11/21/94 */
386 #ifdef PVM
387 extern int init_parallel();
388 int num_procs;
389 int* tids;
390 int node_num;
391 int mytid;
392 #endif
393 
394 
395 #endif
double(* func)(double)
Definition: hoc_init.cpp:164
void * erealloc(void *ptr, size_t n)
Definition: symbol.cpp:263
int(* Pfri_vp)(void *)
Definition: hocdec.h:45
void * emalloc(size_t n)
Definition: symbol.cpp:197
union Datum Datum
Objectdata * hoc_objectdata_save(void)
Definition: hoc_oop.cpp:133
Symlist * hoc_top_level_symlist
Definition: symdir.cpp:23
struct Object **(* Pfro_vp)(void *)
Definition: hocdec.h:48
void * ecalloc(size_t n, size_t size)
Definition: symbol.cpp:215
const char **(* Pfrs)(void)
Definition: hocdec.h:43
struct Symlist Symlist
Inst * hoc_prog_parse_recover
Definition: hocdec.h:295
double(* Pfrd)(void)
Definition: hocdec.h:41
int nrn_istty_
Definition: hoc.cpp:882
Inst * hoc_progp
struct cTemplate cTemplate
struct Proc Proc
union Inst Inst
#define HocUnion
Definition: hocdec.h:35
struct Object **(* Pfro)(void)
Definition: hocdec.h:42
void(* Pfrv)(void)
Definition: hocdec.h:40
Objectdata * hoc_objectdata
Definition: hoc_oop.cpp:123
struct Arrayinfo Arrayinfo
Objectdata * hoc_objectdata_restore(Objectdata *)
Definition: hoc_oop.cpp:143
Inst * hoc_progbase
Definition: hocdec.h:295
int parallel_sub
Definition: parallel.cpp:30
struct Object Object
union Objectdata Objectdata
#define HocStruct
Definition: hocdec.h:34
struct Symbol Symbol
struct HocSymExtension HocSymExtension
char * Upoint
Definition: hocdec.h:89
Symlist * hoc_symlist
void(* Pfrv_vp)(void *)
Definition: hocdec.h:46
Inst * hoc_prog
Definition: hocdec.h:295
Objectdata * hoc_top_level_data
Definition: hoc_oop.cpp:124
const char **(* Pfrs_vp)(void *)
Definition: hocdec.h:49
Symlist * hoc_built_in_symlist
Definition: ivocmac.cpp:76
int hoc_usegui
Definition: hoc.cpp:148
double(* Pfrd_vp)(void *)
Definition: hocdec.h:47
int(* Pfri)(void)
Definition: hocdec.h:39
Object * hoc_thisobject
Definition: hoc_oop.cpp:122
Inst * hoc_pc
void
int const size_t const size_t n
Definition: nrngsl.h:11
HOC interpreter function declarations (included by hocdec.h)
static List * bnd[4]
Definition: partial.cpp:172
unsigned * a_varn
Definition: hocdec.h:69
int nsub
Definition: hocdec.h:70
int refcount
Definition: hocdec.h:71
int sub[1]
Definition: hocdec.h:72
double * pdoub
Definition: hocdec.h:256
const char * name
Definition: hocdec.h:255
const char * name
Definition: hocdec.h:260
double * pdoub
Definition: hocdec.h:261
int index1
Definition: hocdec.h:262
const char * name
Definition: hocdec.h:266
const char * name
Definition: hocdec.h:276
char * units
Definition: hocdec.h:277
const char * name
Definition: hocdec.h:271
float tolerance
Definition: hocdec.h:272
float * parmlimits
Definition: hocdec.h:111
char * units
Definition: hocdec.h:112
float tolerance
Definition: hocdec.h:113
Definition: hocdec.h:227
void * aliases
Definition: hocdec.h:239
void * this_pointer
Definition: hocdec.h:232
Objectdata * dataspace
Definition: hocdec.h:231
HocStruct hoc_Item * secelm_
Definition: hocdec.h:242
int index
Definition: hocdec.h:229
short unref_recurse_cnt
Definition: hocdec.h:245
void * observers
Definition: hocdec.h:243
int refcount
Definition: hocdec.h:228
HocStruct hoc_Item * itm_me
Definition: hocdec.h:241
short recurse
Definition: hocdec.h:244
union Object::@39 u
Definition: hocdec.h:75
int nauto
Definition: hocdec.h:80
Inst defn
Definition: hocdec.h:76
unsigned long size
Definition: hocdec.h:77
HocStruct Symlist * list
Definition: hocdec.h:78
int nobjauto
Definition: hocdec.h:81
Definition: model.h:57
Proc * u_proc
Definition: hocdec.h:145
HocStruct Symbol * sym
Definition: hocdec.h:156
short cpublic
Note: public is a reserved keyword.
Definition: hocdec.h:125
int u_auto
Definition: hocdec.h:143
HocStruct Symbol ** ppsym
Definition: hocdec.h:150
short type
Definition: model.h:58
double * pnum
Definition: hocdec.h:140
double(* ptr)(double)
Definition: hocdec.h:144
struct Symbol::@37::@38 rng
int * pvalint
Definition: hocdec.h:141
float * pvalfloat
Definition: hocdec.h:142
HocStruct Symbol * next
Definition: hocdec.h:162
int index
Definition: hocdec.h:148
char * cstr
Definition: hocdec.h:139
HocStruct Object * object_
Definition: hocdec.h:138
union Symbol::@18 u
short subtype
Definition: hocdec.h:119
unsigned s_varn
Definition: hocdec.h:158
char * name
Definition: model.h:72
HocSymExtension * extra
Definition: hocdec.h:160
char * str
Definition: model.h:63
double * pval
Definition: hocdec.h:137
HocStruct cTemplate * ctemplate
Definition: hocdec.h:152
int oboff
Definition: hocdec.h:132
Arrayinfo * arayinfo
Definition: hocdec.h:159
short defined_on_the_fly
Definition: hocdec.h:129
Definition: hocdec.h:84
HocStruct Symbol * first
Definition: hocdec.h:85
HocStruct Symbol * last
Definition: hocdec.h:86
const char * name
Definition: hocdec.h:250
Symbol * sym
Definition: hocdec.h:196
int dataspace_size
Definition: hocdec.h:198
Symbol * unref
Definition: hocdec.h:201
Symlist * symtable
Definition: hocdec.h:197
Symbol * init
Definition: hocdec.h:200
int id
Definition: hocdec.h:205
int(* checkpoint)(void **)
Definition: hocdec.h:210
hoc_List * olist
Definition: hocdec.h:204
void * observers
Definition: hocdec.h:206
int count
Definition: hocdec.h:203
void(* destructor)(void *)
Definition: hocdec.h:208
int is_point_
Definition: hocdec.h:199
int index
Definition: hocdec.h:202
void(* steer)(void *)
Definition: hocdec.h:209
Definition: hocdec.h:177
hoc_List * lst
Definition: hocdec.h:186
HocStruct Object * obj
Definition: hocdec.h:183
double * pval
Definition: hocdec.h:181
void * _pvoid
Definition: hocdec.h:187
HocStruct hoc_Item * itm
Definition: hocdec.h:185
int i
Definition: hocdec.h:180
char ** pstr
Definition: hocdec.h:184
Symbol * sym
Definition: hocdec.h:179
HocStruct Object ** pobj
Definition: hocdec.h:182
double val
Definition: hocdec.h:178
Definition: hocdec.h:51
Pfrv pf
Definition: hocdec.h:52
HocUnion Inst * in
Definition: hocdec.h:60
Pfrd pfd
Definition: hocdec.h:53
int i
Definition: hocdec.h:63
Pfrs_vp pfs_vp
Definition: hocdec.h:59
Pfro pfo
Definition: hocdec.h:54
HocStruct Symbol * sym
Definition: hocdec.h:61
Pfro_vp pfo_vp
Definition: hocdec.h:58
Pfrs pfs
Definition: hocdec.h:55
Pfrv_vp pfv_vp
Definition: hocdec.h:56
Pfrd_vp pfd_vp
Definition: hocdec.h:57
void * ptr
Definition: hocdec.h:62
char ** ppstr
Definition: hocdec.h:219
void * _pvoid
Definition: hocdec.h:224
hoc_List ** plist
Definition: hocdec.h:222
Arrayinfo * arayinfo
Definition: hocdec.h:223
double * pval
Definition: hocdec.h:218
HocStruct Object ** pobj
Definition: hocdec.h:220
HocStruct hoc_Item ** psecitm
Definition: hocdec.h:221