示例#1
0
void nrnpy_reg_mech(int type) {
	int i;
	char* s;
	Memb_func* mf = memb_func + type;
	if (!nrnmodule_) { return; }
	if (mf->is_point) {
		if (nrn_is_artificial_[type] == 0) {
			Symlist* sl = nrn_pnt_template_[type]->symtable;
			Symbol* s = hoc_table_lookup("get_segment", sl);
			if (!s) {
				s = hoc_install("get_segment", OBFUNCTION, 0, &sl);
#if MAC
				s->u.u_proc->defn.pfo = (Object**(*)(...))pp_get_segment;
#else
				s->u.u_proc->defn.pfo = (Object**(*)())pp_get_segment;
#endif
			}
		}
		return;
	}
	s = mf->sym->name;
//printf("nrnpy_reg_mech %s %d\n", s, type); 
	if (PyDict_GetItemString(pmech_types, s)) {
		hoc_execerror(s, "mechanism already exists");
	}
	Py_INCREF(&nrnpy_MechanismType);
	PyModule_AddObject(nrnmodule_, s, (PyObject *)pmech_generic_type);
	PyDict_SetItemString(pmech_types, s, Py_BuildValue("i", type));
	for (i = 0; i < mf->sym->s_varn; ++i) {
		Symbol* sym = mf->sym->u.ppsym[i];
		rangevars_add(sym);
	}
}
示例#2
0
文件: getsym.c 项目: nrnhines/nrn
Psym *hoc_getsym(const char* cp) {
	Symbol *sp, *sym;
	Symlist *symlist = (Symlist *)0;
	Inst *last, *pcsav;
	int i, n;
	char s[256];
	Psym *p=0;

	Sprintf(s, "{%s}\n", cp);
	sp = hoc_install("", PROCEDURE, 0., &symlist);
	sp->u.u_proc->defn.in = STOP;
	sp->u.u_proc->list = (Symlist *)0;
	sp->u.u_proc->nauto = 0;
	n = hoc_xopen_run(sp, s);
	last = (Inst *)sp->u.u_proc->defn.in + n;
	if (n < 5 || last[-3].pf != hoc_eval) {
		hoc_execerror(s, " not a variable");
	}
	last[-3].in = STOP;	/*before doing last EVAL*/
	pcsav = hoc_pc;
	hoc_execute(sp->u.u_proc->defn.in);
	hoc_pc = pcsav;
	
	sym = hoc_spop();
	switch(sym->type) {
	case UNDEF:
		hoc_execerror(s, " is undefined");
	case VAR:
		if (ISARRAY(sym)) {
			Arrayinfo* a;
			if (sym->subtype == NOTUSER) {
				a = OPARINFO(sym);
			}else{
				a = sym->arayinfo;
			}
			p = (Psym *)emalloc((unsigned)(sizeof(Psym) +
				a->nsub));
			p->arayinfo = a;
			++a->refcount;
			p->nsub = a->nsub;
			for (i=p->nsub; i > 0;) {
				p->sub[--i] = hoc_xpop();
			}
		} else {
			p = (Psym *)emalloc(sizeof(Psym));
			p->arayinfo = 0;
			p->nsub = 0;
		}
		p->sym = sym;
		break;
	case AUTO:
		hoc_execerror(s, " is local variable");
	default:
		hoc_execerror(s, " not a variable");
	}
	hoc_free_list(&symlist);
	return p;	
}
示例#3
0
文件: getsym.c 项目: nrnhines/nrn
void hoc_execstr(const char* cp) {
	Symbol *sp;
	Symlist *symlist = (Symlist *)0;
	Inst *pcsav;
	char s[256];

	Sprintf(s, "{%s}\n", cp);
	sp = hoc_install("", PROCEDURE, 0., &symlist);
	sp->u.u_proc->defn.in = STOP;
	sp->u.u_proc->list = (Symlist *)0;
	sp->u.u_proc->nauto = 0;
	IGNORE(hoc_xopen_run(sp, s));
	pcsav = hoc_pc;
	hoc_execute(sp->u.u_proc->defn.in);
	hoc_pc = pcsav;
	hoc_free_list(&symlist);
}	
示例#4
0
void make_pointprocess() {
	char buf[256];
	int i, cnt, type, ptype;
	Symbol* sp, *s2;
	char* classname = gargstr(1);
//printf("classname=%s\n", classname);
	char* parnames = nil;
	if (ifarg(2)) {
		parnames = new char[strlen(gargstr(2)) + 1];
		strcpy(parnames, gargstr(2));
	}
//if(parnames) printf("parnames=%s\n", parnames);
	Symbol* classsym = hoc_lookup(classname);
	if (classsym->type != TEMPLATE) {
		hoc_execerror(classname, "not a template");
	}
	cTemplate* tp = classsym->u.ctemplate;
	Symlist* slist = tp->symtable;
	// increase the dataspace by 1 void pointer. The last element
	// is where the Point_process pointer can be found and when
	// the object dataspace is freed, so is the Point_process.
	if (tp->count > 0) {
fprintf(stderr, "%d object(s) of type %s already exist.\n", tp->count, classsym->name);
hoc_execerror("Can't make a template into a PointProcess when instances already exist", 0);
	}
	++tp->dataspace_size;
	char** m = make_m(false, cnt, slist, classsym->name, parnames);
	
	check_list("loc", slist);
	check_list("get_loc", slist);
	check_list("has_loc", slist);
	//so far we need only the name and type
	sp = hoc_install("loc", FUNCTION, 0., &slist); sp->cpublic = 1;
	sp = hoc_install("get_loc", FUNCTION, 0., &slist); sp->cpublic = 1;
	sp = hoc_install("has_loc", FUNCTION, 0., &slist); sp->cpublic = 1;

	Symlist* slsav = hoc_symlist;
	hoc_symlist = nil;
	HocMech* hm = common_register(m, classsym, slist, alloc_pnt, type);
	hm->slist = hoc_symlist;
	hoc_symlist = slsav;
	s2 = hoc_table_lookup(m[1], hm->slist);
	assert(s2->subtype == type);
//	type = s2->subtype;
	ptype = point_reg_helper(s2);
//printf("type=%d pointtype=%d %s %lx\n", type, ptype, s2->name, (long)s2);
	classsym->u.ctemplate->is_point_ = ptype;

	// classsym->name is already in slist as an undef, Remove it and
	// move s2 out of HocMech->slist and into slist.
	// That is the one with the u.ppsym.
	// The only reason it needs to be in slist is to find the
	// mechanims type. And it needs to be LAST in that list.
	// The only reason for the u.ppsym is for ndatclas.c and we
	// need to fill those symbols with oboff.
	sp = hoc_table_lookup(classsym->name, slist);
	hoc_unlink_symbol(sp, slist);
	hoc_unlink_symbol(s2, hm->slist);
	hoc_link_symbol(s2, slist);
	hoc_link_symbol(sp, hm->slist); // just so it isn't counted as leakage
	for (i=0; i < s2->s_varn; ++i) {
		Symbol* sp = hoc_table_lookup(s2->u.ppsym[i]->name, slist);
		s2->u.ppsym[i]->cpublic = 2;
		s2->u.ppsym[1]->u.oboff = sp->u.oboff;
	}
	for (i=0; i < cnt; ++i) {
		if (m[i]) {
			delete [] m[i];
		}
	}
	delete [] m;
	if (parnames) {
		delete [] parnames;
	}
	ret(1.);
}