1 #include <../../nrnconf.h> 33 #define BBSPOLL if (--bbs_poll_ == 0) { bbs_handle(); } 43 # define STACKCHK if (stackp >= stacklast) \ 44 execerror("Stack too deep.", "Increase with -NSTACK stacksize option"); 50 for (k = 0, l = i; k < 2; k++, l =
j) {
74 s[
k] =
"(Object * already unreffed on stack)";
81 fprintf(stderr,
"bad stack access: expecting %s; really %s\n", s[1], s[0]);
82 execerror(
"interpreter stack type error", (
char *) 0);
106 #define tstkchk(i, j) (((i)!=(j))?tstkchk_actual(i,j):0) 107 #define pushxm(d) ((stackp++)->val = (d));((stackp++)->i = NUMBER) 108 #define pushsm(d) ((stackp++)->sym = (d));((stackp++)->i = SYMBOL) 109 #define nopopm() (stackp -= 2) 110 #define xpopm() (tstkchk(stackp[-1].i, NUMBER), nopopm(), stackp->val) 111 #define spopm() (tstkchk(stackp[-1].i, SYMBOL), nopopm(), stackp->sym) 113 #define pushxm(d) pushx(d) 114 #define pushsm(d) pushs(d) 115 #define xpopm() xpop() 116 #define spopm() spop() 117 #define nopopm() nopop() 118 #define tstkchk(i,j) tstkchk_actual(i,j) 121 #define EPS hoc_epsilon 124 #define nstack hoc_nstack 128 #define stack stlstack 153 #define nframe hoc_nframe 174 #define DEBUG_GARBAGE 1 175 #define TOBJ_POOL_SIZE 50 220 if (p >= hoc_temp_obj_pool_ && p < hoc_temp_obj_pool_ +
TOBJ_POOL_SIZE) {
246 unref_defer_ = (
Object*)0;
259 execerror(
"stack underflow", (
char *) 0);
261 unref_defer_ = stackp[-2].
obj;
292 for (i = f->
nargs - 1; i >= 0; --i) {
303 for (f = fp; f > ff; --f) {
328 stkp[-2 * i + 1].
i = 0;
339 for (stkp = stackp - 2; stkp >=
stack; stkp -= 2) {
346 printf(
"OBJECTTMP at stack index %ld already unreffed\n", stkp - stack);
361 stacklast = stack +
nstack;
364 framelast = frame +
nframe;
368 #define MAXINITFCNS 10 375 Printf(
"interpreter stack: %ld \n", (stackp - stack) / 2);
376 for (i = 0, s = stackp - 1; s >
stack; --
s, ++
i) {
381 Printf(
"%d stacktype=%d\n", i, s->
i);
391 fprintf(stderr,
"increase definition for MAXINITFCNS\n");
404 prog_parse_recover = progbase =
prog;
497 prog_parse_recover = *a11;
540 Inst *sprogbase, *sprogp, *spc, *sprog_parse_recover;
541 Datum *sstackp, *sstack;
561 "Maybe you were in the middle of a direct command.");
570 hoc_execerror(
"incomplete statement parse not allowed\n",
nullptr);
575 rframe=sframe; fp=sfp;
576 progbase=sprogbase; progp=sprogp; pc=spc;
577 prog_parse_recover=sprog_parse_recover;
578 stackp=sstackp; rstack=sstack;
p_symlist=sp_symlist;
601 }
else{
int savpipeflag;
607 execerror(
"Nothing to parse", (
char *)0);
609 n = (
int)(progp-progbase);
614 rframe=sframe; fp=sfp;
615 progbase=sprogbase; progp=sprogp; pc=spc;
616 prog_parse_recover=sprog_parse_recover;
617 stackp=sstackp; rstack=sstack;
p_symlist=sp_symlist;
621 #define HOC_TEMP_CHARPTR_SIZE 128 644 (stackp++)->
i = NUMBER;
649 if (d >= hoc_temp_obj_pool_ && d < (hoc_temp_obj_pool_ +
TOBJ_POOL_SIZE)) {
653 (stackp++)->pobj = d;
654 (stackp++)->
i = OBJECTVAR;
667 (stackp++)->pstr = d;
681 if (s->
type == CSTRING) {
704 (stackp++)->pval = d;
721 if (stackp <= stack) {
724 return (stackp - 1)->i;
728 if (narg > fp->
nargs)
730 return (fp->
argn[(narg - fp->
nargs) * 2 + 1].
i);
747 return (type == OBJECTVAR || type ==
OBJECTTMP);
755 tstkchk((stackp - 2 * i - 1)->i, type);
756 return stackp - 2 * (i + 1);
760 Datum *d = stackp - 2 * i - 2;
770 return (
int) ((stackp - 2 * i - 2) - stack);
774 return (stackp - 2 * i - 1)->i;
779 execerror(
"stack underflow", (
char *) 0);
790 for (d=stackp; d >
stack;) {
816 printf(
"(Object * already unreffed by hoc_stkobj_ref at stkindex %ld. Following name print may cause a crash if already freed.\n", d - stack);
829 execerror(
"stack underflow", (
char *) 0);
837 execerror(
"stack underflow", (
char *) 0);
851 execerror(
"stack underflow", (
char *) 0);
862 execerror(
"stack underflow", (
char *) 0);
870 execerror(
"stack underflow", (
char *) 0);
878 execerror(
"stack underflow", (
char *) 0);
886 execerror(
"stack underflow", (
char *) 0);
895 pushxm(*((pc++)->sym)->u.pnum);
908 # define relative(pc) (pc + (pc)->i) 943 static int first = 1;
947 sprintf(mes,
"Assignment to %s physical constant %s",
998 for (*pval = begin; *pval <=
end; *pval += 1.) {
1021 Inst *stmtbegin, *stmtend;
1024 argcount = (pc++)->
i;
1039 if (fp >= framelast) {
1041 execerror(sym->
name,
"call nested too deeply, increase with -NFRAME framesize option");
1044 fp->
nargs = argcount;
1046 fp->
argn = stackp - 2;
1074 fp->
sp = iter_f->
sp;
1075 fp->
ob = iter_f->
ob;
1114 hoc_execerror(
"return from within an iterator statement not allowed.",
1115 "Set a flag and use break.");
1138 extern int _method3;
1141 switch (sym->
type) {
1175 for (i=0, *pval=0; i <=
imax; i++) {
1176 if (mode == 0 && (i == imax || i == 0)) {
continue; }
1205 for (; i <=
imax; i++) {
1207 if (mode == 0) {
continue; }
1225 else if (i < imax) {
1233 execerror(
"for (var) {stmt} syntax only allowed in CABLE", (
char *) 0);
1247 mode = (
fabs(d) <
EPS) ? 0 : 1;
1259 else if ((savepc + 1)->
i)
1281 Inst *inst, *newinst;
1288 sp->
u.
u_proc->
size = (unsigned) (progp - progbase);
1291 for (inst = progbase; inst !=
progp;)
1292 *newinst++ = *inst++;
1307 for (i = 5, f = fp; f != frame && --
i; f = f - 1) {
1308 for (j = i;
j; j--) {
1316 for (j = 1; j <= f->
nargs;) {
1323 if (strlen(s) > 15) {
1324 Fprintf(stderr,
"\"%.10s...\"", s);
1337 if (++j <= f->nargs) {
1344 Fprintf(stderr,
"and others\n");
1349 if (++fp >= framelast) {
1351 execerror(sp->
name,
"call nested too deeply, increase with -NFRAME framesize option");
1355 fp->
argn = stackp - 2;
1362 for (i = 0; i < fp->
nargs; i++)
1372 if (++fp >= framelast) {
1374 execerror(sp->
name,
"call nested too deeply, increase with -NFRAME framesize option");
1381 fp->
argn = stackp - 2;
1386 if (sp->
type == FUN_BLTIN || sp->
type == OBJECTFUNC || sp->
type == STRINGFUNC) {
1448 if (s->
type == BLTIN) {
1473 for (i = 0; i < fp->
nargs; i++)
1494 "(func) returns no value");
1495 if (fp->
sp->
type == HOCOBJFUNCTION)
1497 "(obfunc) returns no value");
1506 if (fp->
sp->
type != HOCOBJFUNCTION)
1509 if (*d) { (*d)->refcount++; }
1515 if (*d) { (*d)->refcount--; }
1535 execerror(
"argtype can only be called in a func or proc", 0);
1537 iarg = (
int)
chkarg(1, -1000., 100000.);
1538 if (iarg > f->
nargs || iarg < 1) {
1541 type = (f->
argn[(iarg - f->
nargs) * 2 + 1].
i);
1563 if (narg > fp->
nargs)
1570 if (narg > fp->
nargs)
1584 if (narg > fp->
nargs)
1586 type = fp->
argn[(narg - fp->
nargs) * 2 + 1].
i;
1588 cpp = fp->
argn[(narg - fp->
nargs) * 2].pstr;
1589 }
else if (type !=
SYMBOL) {
1590 execerror(
"Expecting string argument", (
char *) 0);
1592 sym = fp->
argn[(narg - fp->
nargs) * 2].sym;
1593 if (sym->
type == CSTRING) {
1598 execerror(
"Expecting string argument", (
char *) 0);
1605 if (narg > fp->
nargs)
1612 if (narg > fp->
nargs)
1736 d = (*((pc++)->sym->u.ptr))(d);
1748 if (last[-2].pf ==
eval) {
1753 sym = last[-10].
sym;
1765 for (pcv = pc; pcv; --pcv) {
1779 }
else if (pcv->
in ==
STOP) {
1795 printf(
"code for hoc_autoobject()\n");
1819 switch (sym->
type) {
1864 hoc_eval_nemonode(sym,
xpopm(), &d);
1867 hoc_eval_nemoarea(sym,
xpopm(), &d);
1909 switch (sym->
type) {
1955 execerror(
"can't use pointer to local variable", sym->
name);
1961 execerror(
"attempt to evaluate pointer to a non-variable", sym->
name);
2008 static int intdiv(
double x,
double y,
int* iptr) {
2013 if (
fabs(x) > (1<<62) ||
fabs(y) > (1<<62))
2015 if (x == (
long) x && y == (
long) y)
2019 x *= (
long double) 10;
2020 y *= (
long double) 10;
2040 execerror(
"division by zero", (
char *) 0);
2045 if (intdiv(d1, d2, &i))
2068 }
else if (r <= -d2) {
2069 q =
floor(-d1 / d2);
2093 d1 = (double) (d1 > d2 +
EPS);
2101 d1 = (double) (d1 < d2 -
EPS);
2109 d1 = (double) (d1 >= d2 -
EPS);
2117 d1 = (double) (d1 <= d2 +
EPS);
2123 double d1 = 0.0, d2;
2124 t1 = (stackp - 1)->
i;
2125 t2 = (stackp - 3)->
i;
2131 d1 = (double) (d1 <= d2 + EPS && d1 >= d2 -
EPS);
2141 d1 = (double) (*o1 == *o2);
2147 hoc_execerror(
"don't know how to compare these types", (
char *) 0);
2154 double d1 = 0.0, d2;
2155 t1 = (stackp - 1)->
i;
2156 t2 = (stackp - 3)->
i;
2162 d1 = (double) (d1 < d2 - EPS || d1 > d2 +
EPS);
2172 d1 = (double) (*o1 != *o2);
2178 hoc_execerror(
"don't know how to compare these types", (
char *) 0);
2187 d1 = (double) (d1 != 0.0 && d2 != 0.0);
2195 d1 = (double) (d1 != 0.0 || d2 != 0.0);
2202 d = (double) (d == 0.0);
2235 switch (sym->
type) {
2245 *(sym->
u.
pval) = d2;
2286 (sym->
u.
pval)[ind] = d2;
2304 hoc_asgn_nemonode(sym,
xpopm(), &d2, op);
2307 hoc_asgn_nemoarea(sym,
xpopm(), &d2, op);
2311 ind =
araypt(sym, OBJECTVAR);
2315 (
OPVAL(sym))[ind] = d2;
2339 *cpp = (
char *)
emalloc((
unsigned) (strlen(buf) + 1));
2355 static char name[100];
2356 char *cp = name + 100;
2368 for (i = a->
nsub - 1; i >= 0; --i) {
2374 assert(n1 + 2 < cp - name);
2376 for (j = n1 - 1; j >= 0; --
j) {
2391 i =
araypt(sp, OBJECTVAR);
2406 if (type == OBJECTVAR) {
2413 for (i = 0; i < aray->
nsub; i++) {
2414 tstkchk((stackp - 2 * (aray->
nsub - i) + 1)->i, NUMBER);
2415 d = (
int) ((stackp - 2 * (aray->
nsub - i))->val +
EPS);
2416 if (d < 0 || d >= aray->
sub[i])
2418 total = total * (aray->
sub[
i]) + d;
2420 for (i = 0; i < aray->
nsub; i++)
2432 int nrnpnt_araypt(
Symbol* sp,
int pi) {
2442 for (i = 0; i < aray->
nsub; i++)
2444 tstkchk((stackp - 2*(aray->
nsub - i) + 1)->i, NUMBER);
2445 d = (
int)((stackp - 2*(aray->
nsub - i))->val +
EPS);
2446 if (d < 0 || d >= aray->
sub[i])
2448 total = total * (aray->
sub[
i]) + d;
2454 for (i = 0; i< aray->
nsub; i++)
2462 #if defined(__GO32__) 2467 grx_output_some_chars(buf, strlen(buf));
2469 grx_output_some_chars(
"\n", 1);
2541 doomed = (pc++)->sym;
2546 if (doomed->
type == UNDEF)
2547 fprintf(stderr,
"%s: no such variable\n", doomed->
name);
2549 fprintf(stderr,
"%s: can't be deleted\n", doomed->
name);
2582 d = *(
OPVAL(var)) = 0.0;
2597 if (progp >= prog +
NPROG - 1)
2598 execerror(
"procedure too big", (
char *) 0);
2632 for (i = end - 1; i !=
begin; i--) {
2639 printf(
"insert code: what follows is the entire code so far\n");
2640 for (p = prog; p <
progp; ++
p) {
2643 printf(
"end of insert code debugging\n");
2647 #if defined(DOS) || defined(__GO32__) || defined (WIN32) || (MAC && !defined(DARWIN)) 2658 if (++ntimes > 10) {
2665 #if defined(__GO32__) || (defined(WIN32) && !defined(CYGWIN)) 2666 if (++ntimes > 10) {
2671 #if MAC && !defined(DARWIN) 2673 if (++ntimes > 100) {
static void frame_objauto_recover_on_err(Frame *ff)
static void warn_assign_dynam_unit(const char *name)
int hoc_is_temp_charptr(char **cpp)
Inst * prog_parse_recover
int hoc_is_str_arg(int narg)
void hoc_pushobj(Object **d)
static const char * parsestr
double Pow(double x, double y)
int hoc_ParseExec(int yystart)
void hoc_init_space(void)
int nrnmpi_numprocs_world
int hoc_argtype(int narg)
double hoc_opasgn(int op, double dest, double src)
#define HOC_TEMP_CHARPTR_SIZE
int segment_limits(double *pdx)
Symbol * hoc_parse_stmt(const char *, Symlist **)
int hoc_is_double_arg(int narg)
char * hoc_object_name(Object *ob)
int araypt(Symbol *sp, int type)
Symbol * hoc_get_symbol(const char *var)
Objectdata * hoc_top_level_data
static Inst * codechk(void)
void hoc_free_string(char *)
void hoc_autoobject(void)
void hoc_run_stmt(Symbol *)
int nrnpy_pr(const char *fmt,...)
char ** hoc_pgargstr(int narg)
static philox4x32_key_t k
Object * hoc_obj_look_inside_stack(int i)
sprintf(buf," if (secondorder) {\ " int _i;\" " for(_i=0;_i< %d;++_i) {\" " _p[_slist%d[_i]]+=dt *_p[_dlist%d[_i]];\" " }}\", numeqn, listnum, listnum)
void hoc_argrefasgn(void)
double * hoc_pgetarg(int narg)
void oc_restore_code(Inst **a1, Inst **a2, Datum **a3, Frame **a4, int *a5, int *a6, Inst **a7, Frame **a8, Datum **a9, Symlist **a10, Inst **a11, int *a12)
void oc_save_code(Inst **a1, Inst **a2, Datum **a3, Frame **a4, int *a5, int *a6, Inst **a7, Frame **a8, Datum **a9, Symlist **a10, Inst **a11, int *a12)
static void stack_obtmp_recover_on_err(int tcnt)
int tstkchk_actual(int i, int j)
double hoc_call_func(Symbol *s, int narg)
int hoc_xopen_run(Symbol *sp, const char *str)
static Object * unref_defer_
static double done(void *v)
Symlist * hoc_top_level_symlist
void hoc_assign_str(char **cpp, const char *buf)
int hoc_is_pdouble_arg(int narg)
void cable_prop_assign(Symbol *sym, double *pd, int op)
int hoc_strgets_need(void)
void hoc_free_symspace(Symbol *)
int const size_t const size_t n
Inst * hoc_codeptr(void *vp)
Objectdata * hoc_objectdata
static void for_segment2(Symbol *sym, int mode)
int hoc_inside_stacktype(int i)
void hoc_obj_unref(Object *obj)
char * hoc_strgets(char *cbuf, int nc)
Objectdata * hoc_objectdata_restore(Objectdata *obdsav)
void hocstr_resize(HocStr *hs, size_t n)
HocStr * hocstr_create(size_t size)
void hoc_warning(const char *, const char *)
void hoc_unref_defer(void)
int hoc_errno_check(void)
int hoc_is_tempobj_arg(int narg)
void hoc_execerror(const char *, const char *)
int hoc_obj_look_inside_stack_index(int i)
void hoc_fake_call(Symbol *s)
Symbol * hoc_get_last_pointer_symbol(void)
void hoc_iterator_stmt(void)
fprintf(stderr, "Don't know the location of params at %p\, pp)
void hoc_push_object(Object *d)
static Object ** hoc_temp_obj_pool_
void free_list(Symlist **list)
Object * hoc_pop_object(void)
char * emalloc(unsigned n)
void hoc_obj_ref(Object *obj)
double * getarg(int narg)
void hoc_tobj_unref(Object **p)
int hoc_array_index(Symbol *sp, Objectdata *od)
Object ** hoc_objgetarg(int narg)
void hoc_delete_symbol(void)
void hoc_on_init_register(Pfrv pf)
static char * stmp[HOC_TEMP_CHARPTR_SIZE]
void hoc_define(Symbol *sp)
short cpublic
Note: public is a reserved keyword.
void rangevarevalpointer(void)
void push_frame(Symbol *sp, int narg)
void hoc_object_eval(void)
void hoc_ob_pointer(void)
Datum * hoc_look_inside_stack(int i, int type)
double cable_prop_eval(Symbol *sym)
Object ** hoc_objpop(void)
static int obj_pool_index_
void hoc_pushpx(double *d)
const char * secaccessname(void)
int hoc_is_object_arg(int narg)
void hoc_pushstr(char **d)
Objectdata * hoc_objectdata_save(void)
char * hoc_araystr(Symbol *sym, int index, Objectdata *obd)
void hoc_stkobj_unref(Object *o, int stkindex)
static void frameobj_clean(Frame *f)
char ** hoc_temp_charptr(void)
static void rinitcode(void)
void hoc_evalpointer(void)
double var(InputIterator begin, InputIterator end)
void hoc_push_string(void)
static Pfrv initfcns[MAXINITFCNS]
double chkarg(int, double low, double high)
void hoc_iterator_object(Symbol *sym, int argcount, Inst *beginpc, Inst *endpc, Object *ob)
void hoc_check_intupt(int intupt)
Object ** hoc_temp_objptr(Object *obj)
void insertcode(Inst *begin, Inst *end, Pfrv f)
double * cable_prop_eval_pointer(Symbol *sym)