NEURON
hocusr.cpp
Go to the documentation of this file.
1 #include <../../nrnconf.h>
2 
3 /* version 7.2.1 2-jan-89 */
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include "hocdec.h"
7 #include "parse.hpp"
8 #if 1
9 #include "hocusr.h"
10 #endif
11 
12 #define CHECK(name) nrn_load_name_check(name)
13 
14 
15 static char CHKmes[] = "The user defined name, %s, already exists.\n";
16 
18 
19 /* Return 0 if nrn_load_dll_called_ == NULL, otherwise recover and return 1.
20  If 1 is returned, then can recover with a hoc_execerror.
21 */
24  /* recoverable error for nrn_load_dll interpreter call */
28  return 1;
29  }
30  return 0;
31 }
32 
33 void nrn_load_name_check(const char* name) {
34  if (hoc_lookup(name) != (Symbol*) 0) {
36  hoc_execerror("The user defined name already exists:", name);
37  } else {
38  fprintf(stderr, CHKmes, name);
39  nrn_exit(1);
40  }
41  }
42 }
43 
44 
45 static void arayinstal(Symbol* sp, int nsub, int sub1, int sub2, int sub3);
46 
47 /* install user variables and functions */
48 void hoc_spinit() {
49  int i;
50  Symbol* s;
51 
53  for (i = 0; scint[i].name; i++) {
54  CHECK(scint[i].name);
55  s = hoc_install(scint[i].name, UNDEF, 0.0, &hoc_symlist);
56  s->type = VAR;
57  s->u.pvalint = scint[i].pint;
58  s->subtype = USERINT;
59  }
60  for (i = 0; scfloat[i].name; i++) {
61  CHECK(scfloat[i].name);
62  s = hoc_install(scfloat[i].name, UNDEF, 0.0, &hoc_symlist);
63  s->type = VAR;
64  s->u.pvalfloat = scfloat[i].pfloat;
65  s->subtype = USERFLOAT;
66  }
67  for (i = 0; vint[i].name; i++) {
68  CHECK(vint[i].name);
69  s = hoc_install(vint[i].name, UNDEF, 0.0, &hoc_symlist);
70  s->type = VAR;
71  arayinstal(s, 1, vint[i].index1, 0, 0);
72  s->u.pvalint = vint[i].pint;
73  s->subtype = USERINT;
74  }
75  for (i = 0; vfloat[i].name; i++) {
76  CHECK(vfloat[i].name);
77  s = hoc_install(vfloat[i].name, UNDEF, 0.0, &hoc_symlist);
78  s->type = VAR;
79  arayinstal(s, 1, vfloat[i].index1, 0, 0);
80  s->u.pvalfloat = vfloat[i].pfloat;
81  s->subtype = USERFLOAT;
82  }
83  for (i = 0; ardoub[i].name; i++) {
84  CHECK(ardoub[i].name);
85  s = hoc_install(ardoub[i].name, UNDEF, 0.0, &hoc_symlist);
86  s->type = VAR;
87  arayinstal(s, 2, ardoub[i].index1, ardoub[i].index2, 0);
88  s->u.pval = ardoub[i].pdoub;
89  s->subtype = USERDOUBLE;
90  }
91  for (i = 0; thredim[i].name; i++) {
92  CHECK(thredim[i].name);
93  s = hoc_install(thredim[i].name, UNDEF, 0.0, &hoc_symlist);
94  s->type = VAR;
96  s->u.pval = thredim[i].pdoub;
97  s->subtype = USERDOUBLE;
98  }
99  for (i = 0; functions[i].name; i++) {
100  if (!strncmp(functions[i].name, "init", 4)) {
102  (*functions[i].func)();
103  continue;
104  }
105  }
106  hoc_last_init();
107 }
108 
110  int i;
111  Symbol* s;
112 
113  if (scdoub)
114  for (i = 0; scdoub[i].name; i++) {
115  CHECK(scdoub[i].name);
116  s = hoc_install(scdoub[i].name, UNDEF, 0.0, &hoc_symlist);
117  s->type = VAR;
118  s->u.pval = scdoub[i].pdoub;
119  s->subtype = USERDOUBLE;
120  }
121  if (vdoub)
122  for (i = 0; vdoub[i].name; i++) {
123  CHECK(vdoub[i].name);
124  s = hoc_install(vdoub[i].name, UNDEF, 0.0, &hoc_symlist);
125  s->type = VAR;
126  arayinstal(s, 1, vdoub[i].index1, 0, 0);
127  s->u.pval = vdoub[i].pdoub;
128  s->subtype = USERDOUBLE;
129  }
130  if (fn)
131  for (i = 0; fn[i].name; i++) {
132  CHECK(fn[i].name);
133  s = hoc_install(fn[i].name, FUN_BLTIN, 0.0, &hoc_symlist);
134  s->u.u_proc->defn.pf = fn[i].func;
135  s->u.u_proc->nauto = 0;
136  s->u.u_proc->nobjauto = 0;
137  }
138 }
139 
140 /* set up arayinfo */
141 static void arayinstal(Symbol* sp, int nsub, int sub1, int sub2, int sub3) {
142  sp->type = VAR;
143  sp->s_varn = 0;
144  sp->arayinfo = (Arrayinfo*) emalloc((unsigned) (sizeof(Arrayinfo) + nsub * sizeof(int)));
145  sp->arayinfo->a_varn = (unsigned*) 0;
146  sp->arayinfo->nsub = nsub;
147  sp->arayinfo->sub[0] = sub1;
148  if (nsub > 1)
149  sp->arayinfo->sub[1] = sub2;
150  if (nsub > 2)
151  sp->arayinfo->sub[2] = sub3;
152 }
153 
154 void hoc_retpushx(double x) { /* utility return for user functions */
155  hoc_ret();
156  hoc_pushx(x);
157 }
#define i
Definition: md1redef.h:19
void hoc_ret()
void hoc_last_init(void)
Definition: init.cpp:308
Symbol * hoc_install(const char *, int, double, Symlist **)
Definition: symbol.cpp:77
void hoc_register_var(DoubScal *scdoub, DoubVec *vdoub, VoidFunc *fn)
Definition: hocusr.cpp:109
void hoc_retpushx(double x)
Definition: hocusr.cpp:154
void hoc_spinit()
Definition: hocusr.cpp:48
void hoc_fake_call(Symbol *s)
Definition: code.cpp:1463
Symbol * hoc_lookup(const char *)
Definition: symbol.cpp:59
#define USERFLOAT
Definition: hocdec.h:86
#define USERDOUBLE
Definition: hocdec.h:84
#define USERINT
Definition: hocdec.h:83
int index2
Definition: hocmodl.h:26
static struct @49 scint[]
int index3
Definition: hocmodl.h:34
static VoidFunc functions[]
Definition: hocmodl.h:4
int index1
Definition: hocmodl.h:15
static struct @51 ardoub[]
static struct @52 thredim[]
static DoubVec vdoub[]
Definition: hocmodl.h:20
static struct @50 vint[]
static void arayinstal(Symbol *sp, int nsub, int sub1, int sub2, int sub3)
Definition: hocusr.cpp:141
static char CHKmes[]
Definition: hocusr.cpp:15
#define CHECK(name)
Definition: hocusr.cpp:12
int nrn_load_dll_recover_error()
Definition: hocusr.cpp:22
void nrn_load_name_check(const char *name)
Definition: hocusr.cpp:33
Symlist * nrn_load_dll_called_
Definition: hocusr.cpp:17
void hoc_pushx(double)
Definition: code.cpp:779
const char * name
Definition: init.cpp:16
void nrn_exit(int err)
Definition: nrnoc_aux.cpp:30
void hoc_execerror(const char *s1, const char *s2)
Definition: nrnoc_aux.cpp:39
static void * emalloc(size_t size)
Definition: mpispike.cpp:30
s
Definition: multisend.cpp:521
static DoubScal scdoub[]
Definition: eion.cpp:37
Symlist * hoc_symlist
Definition: symbol.cpp:34
Symlist * hoc_built_in_symlist
Definition: symbol.cpp:28
unsigned * a_varn
Definition: hocdec.h:60
int nsub
Definition: hocdec.h:61
int sub[1]
Definition: hocdec.h:63
double * pdoub
Definition: hocdec.h:197
const char * name
Definition: hocdec.h:196
const char * name
Definition: hocdec.h:201
double * pdoub
Definition: hocdec.h:202
Definition: model.h:47
short type
Definition: model.h:48
unsigned s_varn
Definition: hocdec.h:129
Arrayinfo * arayinfo
Definition: hocdec.h:130
Definition: hocdec.h:75
const char * name
Definition: hocdec.h:191
void(* func)(void)
Definition: hocdec.h:192