1 #include <../../nrnconf.h> 12 #include <nrnpython_config.h> 33 void* (*nrnpy_opaque_obj2pyobj_p_)(
Object*);
42 static int connect_obsec_;
46 #define EXTERNAL_TYPE 2 64 hoc_oc(
"objref hoc_obj_[2]\n");
87 Sprintf(s,
"%s[%d]", ob->ctemplate->sym->name, ob->
index);
99 for (
i = a->
nsub-1;
i>=0; --
i) {
113 }
else switch (s->
type) {
124 for (
i = a->
nsub-1;
i>=0; --
i) {
145 if (hoc_objectdata == hoc_top_level_data) {
163 if (sym->
type != UNDEF) {
187 OPSTR(sym) = (
char **)0;
212 #define NTEMPLATESTACK 20 217 if (templatestackp == templatestack) {
220 return (--templatestackp);
223 #define pushtemplatesym(arg) chktemplate(); (templatestackp++)->sym = arg 224 #define pushtemplatesymlist(arg) chktemplate(); (templatestackp++)->symlist = arg 225 #define pushtemplatei(arg) chktemplate(); (templatestackp++)->i = arg 226 #define pushtemplateodata(arg) chktemplate(); (templatestackp++)->odata = arg 227 #define pushtemplateo(arg) chktemplate(); (templatestackp++)->o = arg 239 #define OBJ_STACK_SIZE 10 245 if (ob->ctemplate->constructor) {
268 ob = obj_stack_[obj_stack_loc -
i];
297 if (templatestackp == templatestack) {
306 if (!hoc_objectdata) {
317 if (templatestackp == templatestack) {
335 if (ob->ctemplate->constructor) {
336 hoc_execerror(
"Can't execute in a built-in class context", 0);
349 hoc_thisobject = objsave;
366 if (strlen(cmd) > 256 - 10) {
386 pushx((
double)(err));
411 hoc_thisobject = objsave;
423 hoc_thisobject =
nullptr;
440 if (hoc_objectdata == hoc_top_level_data) {
455 hoc_thisobject = *a1;
459 hoc_objectdata = *a2;
468 printf(
"new object from template %s created.\n", symtemp->
name);
479 ob->ctemplate->count++;
518 #define NEWOBJ1_ERR_SIZE 32 566 if (ne->
oji == oji) {
589 for (s = ob->ctemplate->symtable->first; s; s = s->
next) {
598 for(i=0; i<total; i++) {
614 for (i=0; i<total; i++) {
617 if (strcmp(s->
name,
"this") == 0) {
634 if (ob->ctemplate->is_point_) {
637 if (ob->ctemplate->init) {
640 for (i=0; i <
narg; ++
i) {
688 hoc_execerror(
"Assignment to $o only allowed if caller arg was declared as objref",
NULL);
715 hoc_thisobject = obsav;
730 Inst *pcsav, callcode[4];
742 gui_redirect_obj_ = ob;
744 hoc_thisobject = obsav;
745 if (sym->
type == OBFUNCTION) {
750 if (*o) {--(*o)->refcount;}
752 }
else if (sym->
type == STRFUNCTION) {
764 }
else if (ob->ctemplate->sym->subtype &
JAVAOBJECT) {
767 hoc_thisobject = obsav;
768 if (sym->
type == OBFUNCTION) {
773 if (*o) {--(*o)->refcount;}
775 }
else if (sym->
type == STRFUNCTION) {
793 callcode[1].
sym = sym;
794 callcode[2].
i =
narg;
801 if (sym->
type == PROCEDURE) {
813 hoc_thisobject = obsav;
821 Inst* stmtbegin, *stmtend;
832 stmtbegin =
pc +
pc->
i;
834 stmtend =
pc +
pc->
i;
843 hoc_thisobject = obsav;
853 printf(
"declareing %s as objectvar\n", sym->
name);
855 if (sym->
type == OBJECTVAR) {
int total,
i;
857 for (i=0; i<total; i++) {
863 sym->
type = OBJECTVAR;
873 for (i=0; i<size; i++) {
896 printf(
"code for hoc_objectvar()\n");
916 hoc_thisobject = obsav;
926 printf(
"code for hoc_objectarg()\n");
965 if (!sym || sym->
type != TEMPLATE) {
971 if (obj->
index == index) {
973 }
else if (obj->
index > index) {
993 pushx((
double)((
size_t)ob));
998 static void range_suffix(
Symbol* sym,
int nindex,
int narg) {
1013 if (sym->
type == RANGEVAR) {
1039 int nindex,
narg, cplus, isfunc;
1046 printf(
"code for hoc_object_component()\n");
1052 psym = &(
pc++)->sym;
1058 range_suffix(sym0, nindex, narg);
1061 if (connect_obsec_) {
1068 hoc_execerror(
"[...](...) syntax only allowed for array range variables:", sym0->
name);
1095 (*nrnpy_py2n_component)(obp, sym0, nindex, isfunc);
1100 if (obp->ctemplate->id == *ptid) {
1108 fprintf(stderr,
"%s not a public member of %s\n", sym0->
name, obp->ctemplate->sym->name);
1111 *ptid = obp->ctemplate->id;
1124 hoc_thisobject = obp;
1126 switch (sym->
type) {
1132 nindex =
araypt(sym, OBJECTVAR);
1158 nindex =
araypt(sym, OBJECTVAR);
1166 hoc_execerror(sym->
name,
": string can't have function arguments or array indices");
1184 case HOCOBJFUNCTION:
1192 if (*d) {(*d)->refcount++;}
1195 if (*d) {(*d)->refcount--;}
1215 if (sym != nrn_sec_sym) {
1222 hoc_thisobject = obsav;
1225 if ( connect_obsec_) {
1249 if (connect_obsec_) {
1260 nindex =
araypt(sym, OBJECTVAR);
1263 if (connect_obsec_) {
1272 if ((
pc++)->
i != ITERATOR) {
1315 hoc_thisobject = obsav;
1321 printf(
"code for hoc_object_eval\n");
1326 }
else if (type ==
SYMBOL) {
1329 if (d->
sym->
type == RANGEVAR) {
1352 printf(
"code for hoc_ob_pointer\n");
1356 }
else if (type ==
SYMBOL) {
1359 if (d->
sym->
type == RANGEVAR) {
1392 int type1, type2, op;
1399 if (d->
sym->
type == RANGEVAR) {
1405 if (type2 == RANGEVAR && type1 == NUMBER) {
1431 case VAR: {
double d, *pd;
1441 case OBJECTVAR: {
Object **d, **pd;
1443 hoc_execerror(
"Invalid assignment operator for object", (
char*)0);
1459 case STRING: {
char *d, **pd;
1461 hoc_execerror(
"Invalid assignment operator for string", (
char*)0);
1476 hoc_execerror(
"Invalid assignment operator for PythonObject", (
char*)0);
1478 (*nrnpy_hpoasgn)(
o, type1);
1492 if (s->
type != TEMPLATE) {
1495 if (!s1 || s1->
type != TEMPLATE) {
1518 if (type == TEMPLATE) {
1522 }
else if (type != UNDEF) {
1544 hoc_thisobject =
nullptr;
1554 if (strcmp(ts->
name, t->
name) != 0) {
1570 if (s && s->
type != PROCEDURE) {
1571 hoc_execerror(
"'init' can only be used as the initialization procedure for new objects",
1575 if (s && s->
type != PROCEDURE) {
1576 hoc_execerror(
"'unref' can only be used as the callback procedure when the reference count is decremented",
1586 int (*checkpoint)(
void**),
1609 if (m)
for (i=0; m[
i].
name; ++
i) {
1614 if (mobjret)
for (i=0; mobjret[
i].
name; ++
i) {
1619 if (strret)
for (i=0; strret[
i].
name; ++
i) {
1637 char mname[256], signature[256], *cn, *
buf;
1655 for (cp = meth; *cp; ++cp) {
1673 for (cn = mname; *cp !=
' '; ++cn, ++cp) {
1684 for (cn = signature; *cp !=
' ' && *cp !=
'\0'; ++cn, ++cp) {
1698 if (strcmp(mname,
"init") != 0) {
1711 for (cp = meth; *cp; ++cp) {
1729 for (cn = mname; *cp !=
' '; ++cn, ++cp) {
1740 for (cn = signature; *cp !=
' ' && *cp !=
'\0'; ++cn, ++cp) {
1750 sprintf(mname + strlen(mname),
"%ld%s",
1751 strlen(signature), signature);
1753 printf(
"%s derived from overloaded %s already exists\n", mname, s->
name);
1778 i += strlen(s->
name) + 1;
1779 if (i >= 80) {
printf(
"\n"); i = strlen(s->
name) + 1; }
1789 if (templatestackp == templatestack) {
1807 if (templatestackp == templatestack) {
1816 if (templatestackp == templatestack) {
1833 case HOCOBJFUNCTION:
1856 if (t == OBJECTVAR) {
1860 if (t == OBJECTVAR) {
1862 printf(
"dymnamic checking of type=%d\n", type);
1865 }
else if (type != t) {
1869 if (t != OBJECTVAR) {
1882 if (sl)
for (s = sl->
first; s; s = s->
next) {
1885 for (i=0; i<total; i++) {
1889 if ((*obp)->ctemplate == ctemplate) {
1900 if ((*obp)->ctemplate == ctemplate) {
1910 #define objectpath hoc_objectpath_impl 1911 #define pathprepend hoc_path_prepend 1917 sprintf(path,
"%s%s.%s",name, indx, buf);
1919 sprintf(path,
"%s%s", name, indx);
1936 hoc_warning(
"objectpath depth > 4 for", oblook->ctemplate->sym->name);
1939 if (oblook->ctemplate->constructor) {
1943 sl = oblook->ctemplate->symtable;
1949 if (sl)
for (s = sl->
first; s; s = s->
next) {
1952 for (i=0; i<total; i++) {
1954 if (*obp && *obp != oblook &&
objectpath(ob, *obp, path, depth)) {
1965 static char path[512];
1971 hoc_warning(
"Couldn't find a pathname to the object pointer",
1972 ob->ctemplate->sym->name);
1990 if (obj == (
Object *)0) {
2008 if (obj->ctemplate->unref) {
2030 hoc_thisobject = obj;
2033 hoc_thisobject = obsav;
2035 if (--obj->ctemplate->count <= 0) {
2036 obj->ctemplate->
index = 0;
2038 obj->ctemplate =
nullptr;
2054 hoc_objectdata = od;
2069 if (strcmp(
"this", s->
name) != 0) {
2071 for (i = 0; i < total; i++) {
2081 for (i = 0; i < total; ++
i) {
2100 hoc_objectdata = psav;
2135 if (sl)
for (s = sl->
first; s; s = s->
next) {
2136 if (s->
type == TEMPLATE) {
2140 for (i=0; i < nspace; ++
i) {
2155 if (s && s->
type == TEMPLATE) {
2159 for (i=0; i < nspace; ++
i) {
2182 if (sl)
for (s = sl->
first; s; s = s->
next) {
2185 for (i=0; i<total; i++) {
2187 for (
id=0;
id<depth;
id++) {
2191 Printf(
"obp %s[%d] -> %s with %d refs.\n",
2198 && (*obp)->u.dataspace != data
2201 (*obp)->recurse = 1;
2203 (*obp)->recurse = 0;
2212 if (!obj || strcmp(obj->ctemplate->sym->name, type_name) != 0) {
2214 sprintf(buf,
"object type is %s instead of",
2215 obj->ctemplate->sym->name);
2217 sprintf(buf,
"object type is nil instead of");
2224 if (obj && strcmp(obj->ctemplate->sym->name, type_name) == 0) {
void(* nrnpy_py2n_component)(Object *, Symbol *, int, int)
void connect_obsec_syntax(void)
size_t hoc_total_array_data(Symbol *s, Objectdata *obd)
void * ecalloc(size_t n, size_t size)
hoc_List * hoc_l_newlist()
void hoc_oop_initaftererror(void)
char **(* p_java2nrn_smeth)(Object *ho, Symbol *method)
void hoc_endtemplate(Symbol *t)
static void call_ob_iter(Object *ob, Symbol *sym, int narg)
int hoc_is_str_arg(int narg)
void hoc_obj_disconnect(Object *)
void * erealloc(void *ptr, size_t n)
Object * hoc_new_object(Symbol *symtemp, void *v)
void hoc_pushobj(Object **d)
void hoc_object_push(void)
#define pushtemplatesymlist(arg)
int hoc_resize_toplevel(int more)
void * nrn_opaque_obj2pyobj(Object *ho)
void hoc_external_var(Symbol *s)
void hocstr_delete(HocStr *hs)
double hoc_opasgn(int op, double dest, double src)
void hoc_l_delete(hoc_Item *)
void hoc_template_notify(Object *ob, int message)
#define ITERATE(itm, lst)
static int newobj1_err_size_
static void hoc_list_allobjref(Symlist *, Objectdata *, int)
void(* nrnpy_hpoasgn)(Object *, int)
static Object * obj_stack_[OBJ_STACK_SIZE+1]
Symbol * hoc_lookup(const char *)
void hoc_new_object_asgn(Object **obp, Symbol *st, void *v)
char * hoc_object_name(Object *ob)
int araypt(Symbol *sp, int type)
static Templatedatum templatestack[NTEMPLATESTACK]
Symbol * hoc_decl(Symbol *s)
void hoc_begintemplate(Symbol *t1)
size_t hoc_total_array(Symbol *s)
void * nrn_get_oji()
Return handle for the current longjump buffer info.
static void hoc_allobjects1(Symlist *sl, int nspace)
Symbol * nrnpy_pyobj_sym_
static void push_newobj1_err(Object *ob)
save partially constructed object and controlling longjump handle
void hoc_free_val_array(double *, size_t)
int hoc_max_builtin_class_id
sprintf(buf," if (secondorder) {\ " int _i;\" " for(_i=0;_i< %d;++_i) {\" " _p[_slist%d[_i]]+=dt *_p[_dlist%d[_i]];\" " }}\", numeqn, listnum, listnum)
static int newobj1_err_index_
hoc_Item * hoc_l_lappendobj(hoc_List *, struct Object *)
static void destruct(void *v)
Symbol * hoc_install(const char *, int, double, Symlist **)
void hoc_constobject(void)
void hoc_ob_pointer(void)
void hoc_construct_point(Object *, int)
double(* p_java2nrn_dmeth)(Object *ho, Symbol *method)
double hoc_call_func(Symbol *s, int narg)
void pop_newobj1_err()
pop the now fully constructed object
Symbol * ivoc_alias_lookup(const char *name, Object *ob)
int ivoc_list_look(Object *ob, Object *oblook, char *path, int)
void hoc_objvardecl(void)
Symlist * hoc_top_level_symlist
void hoc_assign_str(char **cpp, const char *buf)
void ivoc_free_alias(Object *ob)
static int icntobjectdata
void hoc_known_type(void)
Object ** hoc_temp_objvar(Symbol *symtemp, void *v)
void hoc_obj_set(int i, Object *obj)
void cable_prop_assign(Symbol *sym, double *pd, int op)
void hoc_free_symspace(Symbol *)
int const size_t const size_t n
static void free_objectdata(Objectdata *, cTemplate *)
Objectdata * hoc_top_level_data
Objectdata * hoc_objectdata
int hoc_inside_stacktype(int i)
void hoc_obj_unref(Object *obj)
static newobj1_err_t * newobj1_err_
void hoc_free_object(Object *)
Object **(* p_java2nrn_ometh)(Object *ho, Symbol *method)
void sec_free(hoc_Item *)
#define pushtemplatesym(arg)
void nrn_rangeconst(Section *sec, Symbol *s, double *pd, int op)
union Objectdata Objectdata
static void call_constructor(Object *, Symbol *, int)
int(* checkpoint)(void **)
HocStruct hoc_Item * itm_me
Objectdata * hoc_objectdata_restore(Objectdata *obdsav)
void hoc_free_allobjects(cTemplate *ctemplate, Symlist *sl, Objectdata *data)
void hoc_asgn_obj_to_str(void)
int hoc_arayinfo_install(Symbol *sp, int nsub)
HocStr * hocstr_create(size_t size)
void hoc_warning(const char *, const char *)
int hoc_errno_check(void)
int hoc_oc(const char *buf)
void(* p_java2nrn_destruct)(void *opaque_java_object)
void nrn_pushsec(Section *sec)
Object * hoc_obj_get(int i)
int hoc_obj_run(const char *cmd, Object *ob)
Brief explanation of hoc_obj_run.
void hoc_execerror(const char *, const char *)
int hoc_obj_look_inside_stack_index(int i)
void *(* constructor)(struct Object *)
HocStruct hoc_Item * secelm_
void hoc_dec_refcount(Object **pobj)
void oc_save_hoc_oop(Object **a1, Objectdata **a2, int *a4, Symlist **a5)
Object * hoc_obj_look_inside_stack(int)
void hoc_tobj_unref(Object **)
void hoc_push_current_object(void)
Object * hoc_name2obj(const char *name, int index)
fprintf(stderr, "Don't know the location of params at %p\, pp)
void hoc_push_object(Object *d)
void * nrn_get_hoc_jmp()
If one of the two jmp_buf is controlling the longjmp hoc_newobj1_err needs handle to know how much to...
void hoc_newobj1_err()
unref partially constructed objects controlled by current longjump handle
HocStruct Object * object_
void hoc_newobj_arg(void)
static Templatedatum * templatestackp
const char **(* member)(void *)
void free_arrayinfo(Arrayinfo *a)
char * emalloc(unsigned n)
void new_sections(Object *ob, Symbol *sym, Item **pitm, int size)
void hoc_obj_ref(Object *obj)
static void hoc_allobjects2(Symbol *s, int nspace)
Symlist * hoc_built_in_symlist
static void * cons(Object *o)
void(* oc_jump_target_)()
void hoc_object_component(void)
void hoc_object_pop(void)
void check_obj_type(Object *obj, const char *type_name)
void hoc_allobjectvars(void)
void hoc_unlink_symbol(Symbol *, Symlist *)
int special_pnt_call(Object *ob, Symbol *sym, int narg)
void hoc_install_object_data_index(Symbol *sp)
void class2oc(const char *name, void *(*cons)(Object *), void(*destruct)(void *), Member_func *m, int(*checkpoint)(void **), Member_ret_obj_func *mobjret, Member_ret_str_func *strret)
short cpublic
Note: public is a reserved keyword.
void ob_sec_access_push(Item *qsec)
#define pushtemplateodata(arg)
void hoc_add_publiclist(Symbol *s)
int hoc_print_first_instance
static void chktemplate(void)
struct Object **(* member)(void *)
Object * hoc_newobj1(Symbol *sym, int narg)
void hoc_object_asgn(void)
void push_frame(Symbol *sp, int narg)
HocStruct hoc_Item ** psecitm
HocStruct cTemplate * ctemplate
Section * nrn_sec_pop(void)
static Object * gui_redirect_obj_
#define NOT_PARALLEL_SUB(c1)
Symbol * hoc_table_lookup(const char *, Symlist *)
Datum * hoc_look_inside_stack(int, int)
int is_obj_type(Object *obj, const char *type_name)
char * hoc_object_pathname(Object *ob)
void hoc_install_hoc_obj(void)
double cable_prop_eval(Symbol *sym)
#define pushtemplatei(arg)
void call_ob_proc(Object *ob, Symbol *sym, int narg)
void hoc_freearay(Symbol *sp)
static Templatedatum * poptemplate(void)
void hoc_pushpx(double *d)
void hoc_pushstr(char **d)
double * nrn_rangepointer(Section *sec, Symbol *s, double d)
void hoc_obvar_declare(Symbol *sym, int type, int pmes)
void(* destructor)(void *)
Objectdata * hoc_objectdata_save(void)
void *(* p_java2nrn_cons)(Object *)
void hoc_newobj_ret(void)
void hoc_ob_check(int type)
double hoc_call_objfunc(Symbol *s, int narg, Object *ob)
char * hoc_araystr(Symbol *sym, int index, Objectdata *obd)
void hoc_stkobj_unref(Object *o, int stkindex)
Object ** hoc_temp_objptr(Object *)
void hoc_object_eval(void)
Symbol * hoc_which_template(Symbol *s)
Object * nrn_get_gui_redirect_obj()
#define NEWOBJ1_ERR_SIZE
If hoc_newob1 fails after creating a new object, that object needs to be unreffed.
void hoc_free_pstring(char **)
void hoc_object_pushed(void)
Object ** hoc_objgetarg(int)
Section * nrn_sectionref_steer(Section *sec, Symbol *sym, int *pnindex)
void oc_restore_hoc_oop(Object **a1, Objectdata **a2, int *a4, Symlist **a5)
double chkarg(int, double low, double high)
void hoc_iterator_object(Symbol *sym, int argcount, Inst *beginpc, Inst *endpc, Object *ob)
void destroy_point_process(void *)
void *(* nrnpy_opaque_obj2pyobj_p_)(Object *)
void hoc_allobjects(void)
#define pushtemplateo(arg)
Symbol * java2nrn_class(const char *name, int id, const char *meth)
Create a hoc class from a java one.
double * cable_prop_eval_pointer(Symbol *sym)