コード例 #1
0
PUBLIC struct expression *pars_exp_binary(int op, struct expression *exp1,
					  struct expression *exp2)
{
	GETEXP(sizeof(struct two_exp));

	work->optype = T_BINARY;
	work->op = op;
	work->e.twoexp.exp1 = exp1;
	work->e.twoexp.exp2 = exp2;

	if (ISARRAY(exp1) || ISARRAY(exp2))
		pars_error("Arrays may not be part of an expression");

	return work;
}
コード例 #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
ファイル: nrnpy_nrn.cpp プロジェクト: bhache/pkg-neuron
static int segment_setattro(NPySegObj* self, PyObject* name, PyObject* value) {
	PyObject* rv;
	Symbol* sym;
	int err = 0;
	Py_INCREF(name);
	char* n = PyString_AsString(name);
//printf("segment_setattro %s\n", n);
	if (strcmp(n, "x") == 0) {
		int nseg;
		double x;
		if (PyArg_Parse(value, "d", &x) == 1 &&  x > 0. && x <= 1.) {
			if (x < 1e-9) {
				self->x_ = 0.;
			}else if (x > 1. - 1e-9) {
				self->x_ = 1.;
			}else{
				self->x_ = x;
			}
		}else{
			PyErr_SetString(PyExc_ValueError,
				"x must be in range 0. to 1.");
			err = -1;
		}
	}else if ((rv = PyDict_GetItemString(rangevars_, n)) != NULL) {
		sym = ((NPyRangeVar*)rv)->sym_;
		if (ISARRAY(sym)) {
			char s[200];
			sprintf(s, "%s needs an index for assignment", sym->name);
			PyErr_SetString(PyExc_IndexError, s);
			err = -1;
		}else{
			int errp;
			double* d = nrnpy_rangepointer(self->pysec_->sec_, sym, self->x_, &errp);
			if (!d) {
				rv_noexist(self->pysec_->sec_, n, self->x_, errp);
				Py_DECREF(name);
				return -1;
			}
			if (!PyArg_Parse(value, "d", d)) {
				PyErr_SetString(PyExc_ValueError, "bad value");
				Py_DECREF(name);
				return -1;
			}else if (sym->u.rng.type == MORPHOLOGY) {
				diam_changed = 1;
				self->pysec_->sec_->recalc_area_ = 1;
				nrn_diam_change(self->pysec_->sec_);
			}else if (sym->u.rng.type == EXTRACELL && sym->u.rng.index == 0) {
				// cannot execute because xraxial is an array
				diam_changed = 1;
			}
		}
	}else{
		err = PyObject_GenericSetAttr((PyObject*)self, name, value);
	}
	Py_DECREF(name);
	return err;
}
コード例 #4
0
ファイル: getsym.c プロジェクト: nrnhines/nrn
static void arayonstack(Psym* p) {
	int i;
	double d;
	
	if (p->nsub) {
		if (!ISARRAY(p->sym) || p->nsub != p->arayinfo->nsub) {
			hoc_execerror("wrong number of subscripts for ", p->sym->name);
		}
		for (i=0; i < p->nsub; i++) {
			d = p->sub[i];
			hoc_pushx(d);
		}
	}
}
コード例 #5
0
PUBLIC struct expression *pars_exp_unary(int op, struct expression *exp)
{
	GETEXP(sizeof(struct expression *));

	work->optype = T_UNARY;

	work->op = op;
	work->e.exp = exp;

	if (exp && ISARRAY(exp))
		pars_error("Arrays may not be part of an expression");

	return work;
}
コード例 #6
0
PUBLIC struct expression *pars_exp_substr(struct expression *exp,
					  struct two_exp *twoexp)
{
	GETEXP(sizeof(struct exp_substr));

	if (ISARRAY(exp))
		pars_error("You may not take a substring of an array in this way");


	work->optype = T_SUBSTR;
	work->e.expsubstr.exp = exp;
	work->e.expsubstr.twoexp = *twoexp;

	return work;
}
コード例 #7
0
ファイル: nrnpy_nrn.cpp プロジェクト: bhache/pkg-neuron
static PyObject* section_getattro(NPySecObj* self, PyObject* name) {
	Py_INCREF(name);
	PyObject* rv;
	char* n = PyString_AsString(name);
//printf("section_getattr %s\n", n);
	PyObject* result = 0;
	if (strcmp(n, "L") == 0) {
		result = Py_BuildValue("d", section_length(self->sec_));
	}else if (strcmp(n, "Ra") == 0) {
		result = Py_BuildValue("d", nrn_ra(self->sec_));
	}else if (strcmp(n, "nseg") == 0) {
		result = Py_BuildValue("i", self->sec_->nnode - 1);
	}else if ((rv = PyDict_GetItemString(rangevars_, n)) != NULL) {
		Symbol* sym = ((NPyRangeVar*)rv)->sym_;
		if (ISARRAY(sym)) {
			NPyRangeVar* r = PyObject_New(NPyRangeVar, range_type);
			r->pyseg_ = PyObject_New(NPySegObj, psegment_type);
			r->pyseg_->pysec_ = self;
			Py_INCREF(self);
			r->pyseg_->x_ = 0.5;
			r->sym_ = sym;
			r->isptr_ = 0;
			result = (PyObject*)r;
		}else{
			int err;
			double* d = nrnpy_rangepointer(self->sec_, sym, 0.5, &err);
			if (!d) {
				rv_noexist(self->sec_, n, 0.5, err);
				result = NULL;
			}else{
				result = Py_BuildValue("d", *d);
			}
		}
	}else if (strcmp(n, "rallbranch") == 0) {
		result = Py_BuildValue("d", self->sec_->prop->dparam[4].val);
	}else if (strcmp(n, "__dict__") == 0) {
		result = PyDict_New();
		assert(PyDict_SetItemString(result, "L", Py_None) == 0);
		assert(PyDict_SetItemString(result, "Ra", Py_None) == 0);
		assert(PyDict_SetItemString(result, "nseg", Py_None) == 0);
		assert(PyDict_SetItemString(result, "rallbranch", Py_None) == 0);
	}else{
		result = PyObject_GenericGetAttr((PyObject*)self, name);
	}
	Py_DECREF(name);
	return result;
}
コード例 #8
0
PUBLIC struct assign_list *pars_assign_item(int op,
					    struct expression *lval,
					    struct expression *rval)
{
	struct assign_list *work =
	    mem_alloc(PARSE_POOL, sizeof(struct assign_list));

	if (op!=becomesSYM && (ISARRAY(lval) || ISARRAY2(rval)))
		pars_error("Semi-complex assignment (e.g. :+ and :-) not supported with arrays");

	work->op = op;
	work->lval = lval;
	work->exp = rval;
	work->next = NULL;

	return work;
}
コード例 #9
0
ファイル: av.c プロジェクト: Quuxplusone/Advent
/* walks through a clist and numbers variables whose addresses are
   contained; if pass==-1, index is set to -1, if pass==0, index is set,
   otherwise vilist
   clcnt is used as index-counter in pass 0 */
void num_clist_refs(int pass,struct Typ *t,struct const_list *cl)
{
  /*FIXME: bei Aufrufen auch auf locale, nicht USEDASDEST|USEDASADDR */
  int i;zmax sz;
  if(ISARRAY(t->flags)){
    for(sz=l2zm(0L);!zmleq(t->size,sz)&&cl;sz=zmadd(sz,l2zm(1L)),cl=cl->next){
      if(!cl->other){ierror(0);return;}
      num_clist_refs(pass,t->next,cl->other);
    }
    return;
  }
  if(ISUNION(t->flags)){
    num_clist_refs(pass,(*t->exact->sl)[0].styp,cl);
    return;
  }
  if(ISSTRUCT(t->flags)&&!cl->tree){
    struct Typ *st;
    for(i=0;i<t->exact->count&&cl;i++){
      st=(*t->exact->sl)[i].styp;
      if(!(*t->exact->sl)[i].identifier) ierror(0);
      if((*t->exact->sl)[i].identifier[0]){
        if(!cl->other)
          ierror(0);
        num_clist_refs(pass,st,cl->other);
        cl=cl->next;
      }
    }
    return;
  }
  if(cl->tree&&(cl->tree->o.flags&VARADR)){
    struct Var *v=cl->tree->o.v;
    if(pass==-1){
      v->index=-1;
    }else if(pass==0){
      if(v->index<0) {v->index=clcnt++;v->inr=inr;}
    }else{
      if(v->index<0||v->index>=vcount-rcount)
	ierror(0);
      vilist[v->index]=v;
    }
  }
}
コード例 #10
0
ファイル: nrnpy_nrn.cpp プロジェクト: bhache/pkg-neuron
static PyObject* mech_getattro(NPyMechObj* self, PyObject* name) {
	Py_INCREF(name);
	char* n = PyString_AsString(name);
//printf("mech_getattro %s\n", n);
	PyObject* result = 0;
	NrnProperty np(self->prop_);	
	char buf[200];
	int isptr = (strncmp(n, "_ref_", 5) == 0);
	sprintf(buf, "%s_%s", isptr?n+5:n, memb_func[self->prop_->type].sym->name);
	Symbol* sym = np.find(buf);
	if (sym) {
//printf("mech_getattro sym %s\n", sym->name);
		if (ISARRAY(sym)) {
			NPyRangeVar* r = PyObject_New(NPyRangeVar, range_type);
			r->pyseg_ = self->pyseg_;
			Py_INCREF(r->pyseg_);
			r->sym_ = sym;
			r->isptr_ = isptr;
			result = (PyObject*)r;
		}else{
			double* px = np.prop_pval(sym, 0);
			if (!px) {
				rv_noexist(self->pyseg_->pysec_->sec_, sym->name, self->pyseg_->x_, 2);
			}else if (isptr) {
				result = nrn_hocobj_ptr(px);
			}else{
				result = Py_BuildValue("d", *px);
			}
		}
	}else if (strcmp(n, "__dict__") == 0) {
		result = PyDict_New();
		for (Symbol* s = np.first_var(); np.more_var(); s = np.next_var()) {
			assert(PyDict_SetItemString(result, s->name, Py_None) == 0);
		}
	}else{
		result = PyObject_GenericGetAttr((PyObject*)self, name);
	}
	Py_DECREF(name);
	return result;
}
コード例 #11
0
ファイル: parallel.c プロジェクト: bhache/pkg-neuron
hoc_parallel_begin() {
#if !OCSMALL
		  Symbol *sym;
        double first, last;
        char *method, *getenv();
	int parallel_hoc_main();
	int i, j;


        last = xpop();
        first = xpop();
	sym = spop();
	pushs(sym);

        method = getenv("NEURON_PARALLEL_METHOD");
        if (!method) {
                pushx(first);
                pushx(last);
                return;
        }
        if (parallel_seen++) {
                hoc_warning("Only one parallel loop per batch run allowed.",
			    "This loop is being executed serially");
                pushx(first);
                pushx(last);
                return;
        }
      
	if (!parallel_sub) { /* if 0 then master */
	    /* the master instance executes the following portion of the loop */
	    for (i = ((int)first)+1; i <= (int)last; i++) {
		char buf[10], *pnt = parallel_argv;

		/* increment pnt to "00000" */
		for (j = 0; j < 2; j++) {
		    /*EMPTY*/
		    while (*pnt++);
		}
		
		/* replace "00000" with actual value */
		sprintf(buf, "%5d", i);
		strcpy(pnt, buf);

		/* farm-out all but the first instance of the loop */
#if LINDA
		/* place arguments for eval() into tuple space, Linda
		   doesn't seem to want to let the fxn in an eval take 
		   arrays as args */
		__linda_out("parallel sargs", sargv, senvp);
 		__linda_out("parallel args", parallel_argv:sargv, parallel_envp:senvp); 
 		__linda_eval("parallel run", parallel_hoc_main(i), i);
#endif
	    }
	    
#if LINDA
	    /* do first pass though loop on master node (first to first) */
	    pushx(first);
	    pushx(first);
#else
	    /* run in serial if not LINDA */
	    pushx(first);
	    pushx(last);
#endif

	    /* block until all instances of loop have finished */
#if LINDA
	    i = (int)last - (int)first;
	    while (i-- > 0) {
		int err_val, err_num;
		
		__linda_in("parallel run", ?err_val, ?err_num);
		/* could test err_val != 0 but currently will always equal 0 */
	    }
#endif

	    /* assign value of symbol to last+1 as would be upon exiting a serial loop */
	    if (!ISARRAY(sym)) {
		if (sym->subtype == USERDOUBLE) {
		    pval = sym->u.pval;
		} else {
		    pval = OPVAL(sym);
		}
	    } else {
		if (sym->subtype == USERDOUBLE) {
		    pval = sym->u.pval + araypt(sym, SYMBOL);
		} else {
		    pval = OPVAL(sym) + araypt(sym, OBJECTVAR);	
		}
	    }
	    end_val = last + 1;

	} else {
コード例 #12
0
ファイル: Wbrwlinehb.c プロジェクト: georgyserea/Gestool
CLIPPER WBRWPANE( PARAMS ) // ( hWnd, hDC, Self, bLine, aSizes, nFirstItem,
                           //   nClrFore, nClrBack, hFont, aJustify, nStyle
                           //   lCellStyle, lFocused ) -> nRowsSkipped
                           //   bTextColor, bBkColor, nClrLine, nColorFondo, bFont ) // New's by CesoTech
#endif
{
   HWND hWnd        = ( HWND ) _parnl( 1 );
   HDC hDC          = ( HDC ) _parnl( 2 );
   WORD wRows;
   WORD wLastBottom = 0;
   WORD wRow        = 1;
   WORD wSkipped    = 1;
   PCLIPVAR Self    = _param( 3, -1 );
   PCLIPVAR bLine   = _param( 4, -1 );
   PCLIPVAR pASizes = _param( 5, -1 );
   HFONT hFont      = ( HFONT ) _parnl( 9 );
   HFONT hOldFont;
   BOOL bDestroyDC  = FALSE;
   WORD wHeight ;
   RECT rct, box, client;
   WORD wIndex      = _parni( 6 );
   PCLIPVAR bClrFore = 0, bClrBack = 0;
   COLORREF clrFore = 0;
   COLORREF clrBack = 0;
   HPEN hGrayPen    = CreatePen( PS_SOLID, 1, GetSysColor( COLOR_BTNSHADOW ) ) ; // RGB( 128, 128, 128 ) );
   HPEN hWhitePen   = CreatePen( PS_SOLID, 1, GetSysColor( COLOR_BTNHIGHLIGHT ) ); // GetStockObject( WHITE_PEN );
   #ifndef __HARBOUR__
   BOOL bColBlock   = pASizes->wType & BLOCK;
   #else
   BOOL bColBlock   = hb_itemType( pASizes ) & BLOCK;
   PHB_ITEM aLine = hb_itemNew( NULL );
   #endif
   PCLIPVAR pAJustify = ISARRAY( 10 ) ? _param( 10, -1 ): 0;
   WORD nHeightCtrl ; // by CeSoTech
   WORD nStyle = _parni( 11 );



   if( PCOUNT() > 6 )
   {
      if( ISBLOCK( 7 ) )
         bClrFore = _param( 7, -1 );
      else
         clrFore = _parnl( 7 );
   }

   if( PCOUNT() > 7 )
   {
      if( ISBLOCK( 8 ) )
      {
         bClrBack = _param( 8, -1 );
         _cEval0( bClrBack );
         clrBack = _parnl( -1 );
      }
      else
         clrBack = _parnl( 8 );
   }

   if( ! hDC )
   {
      bDestroyDC = TRUE;
      hDC = GetDC( hWnd );
   }

   if( ! pSkip )
       pSkip = _Get_Sym( "SKIP" );

   if( hFont )
      hOldFont = SelectObject( hDC, hFont );

   /////////////////////////
   // Borremos el Area de la derecha no coubierta
   if ( !bAdjBrowse && !bAdjLastCol )
   {
       GetClientRect( hWnd, &rct );
       SetBkColor( hDC, _parnl( 17 ) ) ;

       for( wIndex=wIndex ; wIndex <= (WORD) _parinfa( 5, NULL); wIndex++ )
       {
            rct.left += _parni( 5, wIndex ) ;
       }

       if ( !(nStyle == 0 || nStyle == 7 || nStyle == 8 || nStyle == 3) )
          rct.left++;

       ExtTextOut( hDC, rct.left, rct.top, ETO_OPAQUE | ETO_CLIPPED,
                   &rct, "", 0, 0 );

       wIndex = _parni( 6 );
       GetClientRect( hWnd, &rct );
   }
   /////////////////////////

   GetClientRect( hWnd, &client );

   nHeightCtrl = client.bottom-client.top ; // by CeSoTech

   wHeight = wLineHeight + 1 ;

   wRows = WBrwRowsC( hWnd, hDC, hFont );

   if( ! bClrFore )
      SetTextColor( hDC, clrFore );
      SetBkColor( hDC, clrBack );

   while( wRow <= wRows && wSkipped == 1 )
   {
      rct.top    = client.top + ( bDrawHeaders ? wHeaderHeight+1 : 0 ) +
                   (wHeight * (wRow-1) ) ;

      rct.bottom = rct.top + wHeight;
      rct.left   = 0;
      rct.right  = client.right;

      #ifndef __HARBOUR__

         _cEval0( bLine );
         _xPushM( _eval );

         if( bClrFore )
         {
            _cEval0( bClrFore );
            SetTextColor( hDC, _parnl( -1 ) );
         }

         if( bClrBack )
         {
            _cEval0( bClrBack );
            SetBkColor( hDC, _parnl( -1 ) );
         }

         if( bColBlock )
            _cEval0( pASizes );

         PaintTheLine( hDC, &rct, wIndex, _tos,
                       ( bColBlock ? _eval : pASizes ),
                       hWhitePen, hGrayPen,
                       bColBlock, pAJustify, 0, FALSE, _parni( 11 ),
                       _parni ( 12 ), _parl( 13 ),
                       ISBLOCK( 14 ) ? _param( 14, -1 ) : 0,   // CeSoTech
                       ISBLOCK( 15 ) ? _param( 15, -1 ) : 0,   // CeSoTech
                       wRow, nHeightCtrl,                      // CeSoTech
                       ISNUM( 16 ) ? _parnl( 16 ) : -1,        // CeSoTech
                       FALSE, FALSE,                           // CeSoTech
                       ISBLOCK( 18 ) ? _param( 18, -1 ) : 0,   // CeSoTech
                       FALSE ) ;

         _tos--;

         _PutSym( pSkip );
         _xPushM( Self );
         _PutQ( 1 );
         _xSend( 1 );

      #else
      {
         // aLine.type = HB_IT_NIL;

         // Esta extension de xHarbour no se puede aplicar en Harbour
         // hb_itemForwardValue( aLine, hb_vmEvalBlock( bLine ) );

         hb_itemCopy( aLine, hb_vmEvalBlock( bLine ) );

         if( bClrFore )
         {
            _cEval0( bClrFore );
            SetTextColor( hDC, _parnl( -1 ) );
         }

         if( bClrBack )
         {
            _cEval0( bClrBack );
            SetBkColor( hDC, _parnl( -1 ) );
         }

         PaintTheLine( hDC, &rct, wIndex, aLine,
                       ( bColBlock ? hb_vmEvalBlock( pASizes ) : pASizes ),
                       hWhitePen, hGrayPen,
                       bColBlock, pAJustify, 0, FALSE, _parnl( 11 ),
                       _parnl ( 12 ), _parl( 13 ),
                       ISBLOCK( 14 ) ? _param( 14, -1 ) : 0,   // CeSoTech
                       ISBLOCK( 15 ) ? _param( 15, -1 ) : 0,   // CeSoTech
                       wRow, nHeightCtrl,                      // CeSoTech
                       ISNUM( 16 ) ? _parnl( 16 ) : -1,        // CeSoTech
                       FALSE, FALSE,                           // CeSoTech
                       ISBLOCK( 18 ) ? _param( 18, -1 ) : 0,   // CeSoTech
                       FALSE ) ;

         if ( pSkip )
         {
            hb_vmPushSymbol( hb_dynsymSymbol( pSkip ) );
            hb_vmPush( Self );
            hb_vmPushLong( 1 );
            hb_vmDo( 1 );
         }
      }

      #endif

      wLastBottom = rct.bottom ;
      wSkipped = _parni( -1 );

      if( wSkipped == 1 )
          wRow++;
   }

   ////////////////////////
   // Borremos el Area de Abajo no cubierta
   GetClientRect( hWnd, &rct );
   SetBkColor( hDC, _parnl( 17 ) ) ;

   rct.top = wLastBottom + 1 ;
   if ( wLastBottom == 0 ) // No Mostro Registros
      rct.top = ( bDrawHeaders ? wHeaderHeight+1 : 0 ) ;

   rct.bottom-=  1 + ( bDrawFooters ? wFooterHeight+1 : 0 ) ;

   if (nStyle == 0 || nStyle == 5 || nStyle == 6 ||
       nStyle == 9 || nStyle == 10 || nStyle == 3 )
      rct.top--;

   if ( !bDrawFooters )
      rct.bottom++;


   if ( rct.top < rct.bottom )
   {
      ExtTextOut( hDC, rct.left, rct.top, ETO_OPAQUE | ETO_CLIPPED,
                  &rct, "", 0, 0 );
   }
   ////////////////////////

   DeleteObject( hGrayPen );
   DeleteObject( hWhitePen );

   if( hFont )
      SelectObject( hDC, hOldFont );

   if( bDestroyDC )
       ReleaseDC( hWnd, hDC );


   _retni( wRow );

}
コード例 #13
0
ファイル: nrnpy_nrn.cpp プロジェクト: bhache/pkg-neuron
static PyObject* segment_getattro(NPySegObj* self, PyObject* name) {
	Symbol* sym;
	Py_INCREF(name);
	char* n = PyString_AsString(name);
//printf("segment_getattr %s\n", n);
	PyObject* result = 0;
	PyObject* otype;
	PyObject* rv;
	if (strcmp(n, "v") == 0) {
		Node* nd = node_exact(self->pysec_->sec_, self->x_);
		result = Py_BuildValue("d", NODEV(nd));
	}else if ((otype = PyDict_GetItemString(pmech_types, n)) != NULL) {
		int type = PyInt_AsLong(otype);
//printf("segment_getattr type=%d\n", type);
		Node* nd = node_exact(self->pysec_->sec_, self->x_);
		Prop* p = nrn_mechanism(type, nd);
		if (!p) {
			rv_noexist(self->pysec_->sec_, n, self->x_, 1);
			Py_DECREF(name);
			return NULL;
		}	
		NPyMechObj* m = PyObject_New(NPyMechObj, pmech_generic_type);
		if (m == NULL) {
			Py_DECREF(name);
			return NULL;
		}
		m->pyseg_ = self;
		m->prop_ = p;
		Py_INCREF(m->pyseg_);
		result = (PyObject*)m;
	}else if ((rv = PyDict_GetItemString(rangevars_, n)) != NULL) {
		sym = ((NPyRangeVar*)rv)->sym_;
		if (ISARRAY(sym)) {
			NPyRangeVar* r = PyObject_New(NPyRangeVar, range_type);
			r->pyseg_ = self;
			Py_INCREF(r->pyseg_);
			r->sym_ = sym;
			r->isptr_ = 0;
			result = (PyObject*)r;
		}else{
			int err;
			double* d = nrnpy_rangepointer(self->pysec_->sec_, sym, self->x_, &err);
			if (!d) {
				rv_noexist(self->pysec_->sec_, n, self->x_, err);
				result = NULL;
			}else{
				result = Py_BuildValue("d", *d);
			}
		}
	}else if (strncmp(n, "_ref_", 5) == 0) {
		if (strcmp(n+5, "v") == 0) {
			Node* nd = node_exact(self->pysec_->sec_, self->x_);
			result = nrn_hocobj_ptr(&(NODEV(nd)));
		}else if ((sym = hoc_table_lookup(n+5, hoc_built_in_symlist)) != 0 && sym->type == RANGEVAR) {
			if (ISARRAY(sym)) {
				NPyRangeVar* r = PyObject_New(NPyRangeVar, range_type);
				r->pyseg_ = self;
				Py_INCREF(r->pyseg_);
				r->sym_ = sym;
				r->isptr_ = 1;
				result = (PyObject*)r;
			}else{
				int err;
				double* d = nrnpy_rangepointer(self->pysec_->sec_, sym, self->x_, &err);
				if (!d) {
					rv_noexist(self->pysec_->sec_, n+5, self->x_, err);
					result = NULL;
				}else{
					result = nrn_hocobj_ptr(d);
				}
			}
		}else{
			rv_noexist(self->pysec_->sec_, n, self->x_, 2);
			result = NULL;
		}
	}else if (strcmp(n, "__dict__") == 0) {
		Node* nd = node_exact(self->pysec_->sec_, self->x_);
		result = PyDict_New();
		assert(PyDict_SetItemString(result, "v", Py_None) == 0);
		assert(PyDict_SetItemString(result, "diam", Py_None) == 0);
		assert(PyDict_SetItemString(result, "cm", Py_None) == 0);
		for (Prop* p = nd->prop; p ; p = p->next) {
			if (p->type > CAP && !memb_func[p->type].is_point){
				char* pn = memb_func[p->type].sym->name;
				assert(PyDict_SetItemString(result, pn, Py_None) == 0);
			}
		}
	}else{
		result = PyObject_GenericGetAttr((PyObject*)self, name);
	}
	Py_DECREF(name);
	return result;
}
コード例 #14
0
ファイル: mlcfunc.c プロジェクト: philippe78/TrioGesmag
static PHB_EOL_INFO hb_mlGetEOLs( int iParam, int * piEOLs )
{
   PHB_EOL_INFO pEOLs = NULL;
   int iEOLs = 0;

#ifdef HB_EXTENSION
   char * szEOL;
   ULONG ulLen, ul;

   szEOL = hb_parc( iParam );
   if( szEOL )
   {
      ulLen = hb_parclen( iParam );
      if( ulLen )
      {
         pEOLs = ( PHB_EOL_INFO ) hb_xgrab( sizeof( HB_EOL_INFO ) );
         pEOLs->szEOL = szEOL;
         pEOLs->ulLen = ulLen;
         iEOLs = 1;
      }
   }
   else if( ISARRAY( iParam ) )
   {
      PHB_ITEM pArray = hb_param( iParam, HB_IT_ARRAY );
      ULONG ulSize = hb_arrayLen( pArray );
      for( ul = 1; ul <= ulSize; ++ul )
      {
         if( hb_arrayGetCLen( pArray, ul ) > 0 )
            ++iEOLs;
      }
      if( iEOLs )
      {
         iEOLs = 0;
         pEOLs = ( PHB_EOL_INFO ) hb_xgrab( sizeof( HB_EOL_INFO ) * iEOLs );
         for( ul = 1; ul <= ulSize; ++ul )
         {
            ulLen = hb_arrayGetCLen( pArray, ul );
            if( ulLen > 0 )
            {
               pEOLs[ iEOLs ].szEOL = hb_arrayGetCPtr( pArray, ul );
               pEOLs[ iEOLs ].ulLen = ulLen;
               ++iEOLs;
            }
         }
      }
   }
#else
   HB_SYMBOL_UNUSED( iParam );
#endif

   if( iEOLs == 0 )
   {
      pEOLs = ( PHB_EOL_INFO ) hb_xgrab( sizeof( HB_EOL_INFO ) );
      if( hb_set.HB_SET_EOL && hb_set.HB_SET_EOL[ 0 ] )
         pEOLs->szEOL = hb_set.HB_SET_EOL;
      else
         pEOLs->szEOL = hb_conNewLine();
      pEOLs->ulLen = strlen( pEOLs->szEOL );
      iEOLs = pEOLs->ulLen ? 1 : 0;
   }

   * piEOLs = iEOLs;
   return pEOLs;
}
コード例 #15
0
ファイル: Wbrwc3.c プロジェクト: azulae/Gestool
//---------------------------------------------------------------------------//
CLIPPER WBRWLINE( void ) // ( hWnd, hDC, nRow, aText, aSizes, nFirstItem, ;
                           // nClrFore, nClrBack, hFont, lTree, aJustify, nPressed,
                           // nStyle, nColAct, lFocused )
                           // bTextColor, bBkColor, nClrLine, lFooter, lSelect,
                           // bFont, lDrawFocusRect ) // New's by CesoTech

{
   HWND hWnd        = (HWND) _parnl( 1 );
   HDC hDC          = (HDC) _parnl( 2 );
   WORD wRow        = _parni( 3 );
   BOOL bDestroyDC  = FALSE;
   WORD wHeight;
   RECT rct, box;
   void * bClrFore;
   void * bClrBack;
   COLORREF clrFore = 0;
   COLORREF clrBack = 0;
   HPEN hGrayPen    ;
   HPEN hWhitePen   ;
   HFONT hFont      = (HFONT) _parnl( 9 );
   HFONT hOldFont;
   BOOL bTree       = _parl( 10 );
   BOOL bFooter     = ISLOGICAL( 19 ) ? _parl( 19 ) : FALSE ;  // CeSoTech

   WORD nHeightCtrl ; // by CeSoTech

   hGrayPen    = CreatePen( PS_SOLID, 1, GetSysColor( COLOR_BTNSHADOW ) ) ; // RGB( 128, 128, 128 ) );
   hWhitePen   = CreatePen( PS_SOLID, 1, GetSysColor( COLOR_BTNHIGHLIGHT ) ); // GetStockObject( WHITE_PEN );

   if( PCOUNT() > 6 )
   {
      if( ISBLOCK( 7 ) )
      {
         bClrFore = _param( 7, -1 );
         _cEval0( bClrFore );
         clrFore = _parnl( -1 );
      }
      else
      {
         clrFore = _parnl( 7 );
      }
   }

   if( PCOUNT() > 7 )
   {
      if( ISBLOCK( 8 ) )
      {
         bClrBack = _param( 8, -1 );
         _cEval0( bClrBack );
         clrBack = _parnl( -1 );
      }
      else
      {
         clrBack = _parnl( 8 );
      }
   }

   if( ! hDC )
   {
      bDestroyDC = TRUE;
      hDC = GetDC( hWnd );
   }

   if( hFont )
      hOldFont = SelectObject( hDC, hFont );

   GetClientRect( hWnd, &rct );

   nHeightCtrl = rct.bottom-rct.top ; // by CeSoTech

   SetTextColor( hDC, clrFore );
   SetBkColor( hDC, clrBack );

   wHeight = wLineHeight + 1 ;

   if ( ( wRow == 0 ) && bDrawHeaders )  // Es una Cabecera
      wHeight = wHeaderHeight + 1 ;

   if ( ! bFooter )
   {
      if ( ( wRow == 0 ) && bDrawHeaders )  // Es una Cabecera
      {
         rct.top    = 0 ;
         rct.bottom = wHeaderHeight + 1 ;
      }
      else
      {
        rct.top    = ( bDrawHeaders ? wHeaderHeight+1 : 0 ) + (wHeight * (wRow-1) )  ;
        rct.bottom = ( bDrawHeaders ? wHeaderHeight+1 : 0 ) + (wHeight * wRow)  ;
      }

   } else {
      rct.top    = rct.bottom - (wFooterHeight+1) ;
   }

   rct.left   = 0;

   PaintTheLine( hDC, &rct, _parni( 6 ), _param( 4, -1 ), _param( 5, -1 ),
                 hWhitePen, hGrayPen, bTree,
                 ISARRAY(11) ? _param( 11, -1 ) : 0, _parni( 12 ),
                 (wRow == 0), _parni( 13 ),
                 _parni( 14 ), _parl( 15 ),
                 ISBLOCK( 16 ) ? _param( 16, -1 ) : 0,   // CeSoTech
                 ISBLOCK( 17 ) ? _param( 17, -1 ) : 0,   // CeSoTech
                 wRow, nHeightCtrl,                      // CeSoTech
                 ISNUM( 18 ) ? _parnl( 18 ) : -1,        // CeSoTech
                 bFooter,                                // CeSoTech
                 ISLOGICAL( 20 ) ? _parl( 20 ) : FALSE,  // CeSoTech
                 ISBLOCK( 21 ) ? _param( 21, -1 ) : 0,   // CeSoTech
                 ISLOGICAL( 22 ) ? _parl( 22 ) : FALSE );// CeSoTech

   DeleteObject( hGrayPen );
   DeleteObject( hWhitePen );

   if( hFont )
      SelectObject( hDC, hOldFont );

   if( bDestroyDC )
       ReleaseDC( hWnd, hDC );

   _reta( 2 );
   _storni( rct.top,    -1, 1 );
   _storni( rct.bottom, -1, 2 );

}
コード例 #16
0
ファイル: nrnpy_nrn.cpp プロジェクト: bhache/pkg-neuron
static int section_setattro(NPySecObj* self, PyObject* name, PyObject* value) {
	PyObject* rv;
	int err = 0;
	Py_INCREF(name);
	char* n = PyString_AsString(name);
//printf("section_setattro %s\n", n);
	if (strcmp(n, "L") == 0) {
		double x;
		if (PyArg_Parse(value, "d", &x) == 1 &&  x > 0.) {
			if (can_change_morph(self->sec_)) {
				self->sec_->prop->dparam[2].val = x;
				nrn_length_change(self->sec_, x);
				diam_changed = 1;
				self->sec_->recalc_area_ = 1;
			}
		}else{
			PyErr_SetString(PyExc_ValueError,
				"L must be > 0.");
			err = -1;
		}
	}else if (strcmp(n, "Ra") == 0) {
		double x;
		if (PyArg_Parse(value, "d", &x) == 1 &&  x > 0.) {
			self->sec_->prop->dparam[7].val = x;
			diam_changed = 1;
			self->sec_->recalc_area_ = 1;
		}else{
			PyErr_SetString(PyExc_ValueError,
				"Ra must be > 0.");
			err = -1;
		}
	}else if (strcmp(n, "nseg") == 0) {
		int nseg;
		if (PyArg_Parse(value, "i", &nseg) == 1 &&  nseg > 0 && nseg <= 32767) {
			nrn_change_nseg(self->sec_, nseg);
		}else{
			PyErr_SetString(PyExc_ValueError,
				"nseg must be in range 1 to 32767");
			err = -1;
		}
//printf("section_setattro err=%d nseg=%d nnode\n", err, nseg, self->sec_->nnode);
	}else if ((rv = PyDict_GetItemString(rangevars_, n)) != NULL) {
		Symbol* sym = ((NPyRangeVar*)rv)->sym_;
		if (ISARRAY(sym)) {
			PyErr_SetString(PyExc_IndexError, "missing index");
			err = -1;
		}else{
			int errp;
			double* d = nrnpy_rangepointer(self->sec_, sym, 0.5, &errp);
			if (!d) {
				rv_noexist(self->sec_, n, 0.5, errp);
				Py_DECREF(name);
				return -1;
			}
			if (!PyArg_Parse(value, "d", d)) {
				PyErr_SetString(PyExc_ValueError, "bad value");
				Py_DECREF(name);
				return -1;
			}
			//only need to do following if nseg > 1, VINDEX, or EXTRACELL
			nrn_rangeconst(self->sec_, sym, d, 0);
		}
	}else if (strcmp(n, "rallbranch") == 0) {
		double x;
		if (PyArg_Parse(value, "d", &x) == 1 && x > 0.) {
			self->sec_->prop->dparam[4].val = x;
				diam_changed = 1;
				self->sec_->recalc_area_ = 1;
		}else{
			PyErr_SetString(PyExc_ValueError,
				"rallbranch must be > 0");
			err = -1;
		}
	}else{
		err = PyObject_GenericSetAttr((PyObject*)self, name, value);
	}
	Py_DECREF(name);
	return err;
}
コード例 #17
0
ファイル: Wbrwc3.c プロジェクト: azulae/Gestool
//---------------------------------------------------------------------------//
CLIPPER WBRWPANE( void ) // ( hWnd, hDC, Self, bLine, aSizes, nFirstItem,
                           //   nClrFore, nClrBack, hFont, aJustify, nStyle
                           //   lCellStyle, lFocused ) -> nRowsSkipped
                           //   bTextColor, bBkColor, nClrLine, nColorFondo, bFont ) // New's by CesoTech
{
   HWND hWnd        = ( HWND ) _parnl( 1 );
   HDC hDC          = ( HDC ) _parnl( 2 );
   WORD wRows;
   WORD wLastBottom = 0;
   WORD wRow        = 1;
   WORD wSkipped    = 1;
   void * Self    = _param( 3, -1 );
   void * bLine   = _param( 4, -1 );
   void * pASizes = _param( 5, -1 );
   HFONT hFont      = ( HFONT ) _parnl( 9 );
   HFONT hOldFont;
   BOOL bDestroyDC  = FALSE;
   WORD wHeight ;
   RECT rct, box, client;
   WORD wIndex      = _parni( 6 );
   void * bClrFore = 0;
   void * bClrBack = 0;
   COLORREF clrFore = 0;
   COLORREF clrBack = 0;
   HPEN hGrayPen    = CreatePen( PS_SOLID, 1, GetSysColor( COLOR_BTNSHADOW ) ) ; // RGB( 128, 128, 128 ) );
   HPEN hWhitePen   = CreatePen( PS_SOLID, 1, GetSysColor( COLOR_BTNHIGHLIGHT ) ); // GetStockObject( WHITE_PEN );

   BOOL bColBlock   = ( _itemType( pASizes ) & BLOCK );

   void * pAJustify = ISARRAY( 10 ) ? _param( 10, -1 ): 0;
   WORD nHeightCtrl ; // by CeSoTech
   WORD nStyle = _parni( 11 );

   if( PCOUNT() > 6 )
   {
      if( ISBLOCK( 7 ) )
         bClrFore = _param( 7, -1 );
      else
         clrFore = _parnl( 7 );
   }

   if( PCOUNT() > 7 )
   {
      if( ISBLOCK( 8 ) )
      {
         bClrBack = _param( 8, -1 );
         _cEval0( bClrBack );
         clrBack = _parnl( -1 );
      }
      else
         clrBack = _parnl( 8 );
   }

   if( ! hDC )
   {
      bDestroyDC = TRUE;
      hDC = GetDC( hWnd );
   }

   if( ! pSkip )
       pSkip = _get_sym( "SKIP" );

   if( hFont )
      hOldFont = SelectObject( hDC, hFont );

   /////////////////////////
   // Borremos el Area de la derecha no coubierta
   if ( !bAdjBrowse && !bAdjLastCol )
   {
       GetClientRect( hWnd, &rct );
       SetBkColor( hDC, _parnl( 17 ) ) ;

       for( wIndex=wIndex ; wIndex <= (WORD) _parinfa( 5, NULL); wIndex++ )
       {
            rct.left += _parni( 5, wIndex ) ;
       }

       if ( !(nStyle == 0 || nStyle == 7 || nStyle == 8 || nStyle == 3) )
          rct.left++;

       ExtTextOut( hDC, rct.left, rct.top, ETO_OPAQUE | ETO_CLIPPED,
                   &rct, "", 0, 0 );

       wIndex = _parni( 6 );
       GetClientRect( hWnd, &rct );
   }
   /////////////////////////

   GetClientRect( hWnd, &client );

   nHeightCtrl = client.bottom-client.top ; // by CeSoTech

   wHeight = wLineHeight + 1 ;

   wRows = WBrwRowsC( hWnd, hDC, hFont );

   if( ! bClrFore )
      SetTextColor( hDC, clrFore );
      SetBkColor( hDC, clrBack );

   while( wRow <= wRows && wSkipped == 1 )
   {
      rct.top    = client.top + ( bDrawHeaders ? wHeaderHeight+1 : 0 ) +
                   (wHeight * (wRow-1) ) ;

      rct.bottom = rct.top + wHeight;
      rct.left   = 0;
      rct.right  = client.right;

      _cEval0( bLine );
      _xpushm( _eval );

      if( bClrFore )
      {
         _cEval0( bClrFore );
         SetTextColor( hDC, _parnl( -1 ) );
      }

      if( bClrBack )
      {
         _cEval0( bClrBack );
         SetBkColor( hDC, _parnl( -1 ) );
      }

      if( bColBlock )
         _cEval0( pASizes );

      PaintTheLine( hDC, &rct, wIndex, _tos,
                    ( bColBlock ? _eval : pASizes ),
                    hWhitePen, hGrayPen,
                    bColBlock, pAJustify, 0, FALSE, _parni( 11 ),
                    _parni ( 12 ), _parl( 13 ),
                    ISBLOCK( 14 ) ? _param( 14, -1 ) : 0,   // CeSoTech
                    ISBLOCK( 15 ) ? _param( 15, -1 ) : 0,   // CeSoTech
                    wRow, nHeightCtrl,                      // CeSoTech
                    ISNUM( 16 ) ? _parnl( 16 ) : -1,        // CeSoTech
                    FALSE, FALSE,                           // CeSoTech
                    ISBLOCK( 18 ) ? _param( 18, -1 ) : 0,   // CeSoTech
                    FALSE ) ;

      _0POP();

      _putsym( pSkip );
      _xpushm( Self );
      _putq( 1 );
      _xsend( 1 );

      wLastBottom = rct.bottom ;
      wSkipped = _parni( -1 );

      if( wSkipped == 1 )
          wRow++;
   }

   ////////////////////////
   // Borremos el Area de Abajo no cubierta
   GetClientRect( hWnd, &rct );
   SetBkColor( hDC, _parnl( 17 ) ) ;

   rct.top = wLastBottom + 1 ;
   if ( wLastBottom == 0 ) // No Mostro Registros
      rct.top = ( bDrawHeaders ? wHeaderHeight+1 : 0 ) ;

   rct.bottom-=  1 + ( bDrawFooters ? wFooterHeight+1 : 0 ) ;

   if (nStyle == 0 || nStyle == 5 || nStyle == 6 ||
       nStyle == 9 || nStyle == 10 || nStyle == 3 )
      rct.top--;

   if ( !bDrawFooters )
      rct.bottom++;


   if ( rct.top < rct.bottom )
   {
      ExtTextOut( hDC, rct.left, rct.top, ETO_OPAQUE | ETO_CLIPPED,
                  &rct, "", 0, 0 );
   }
   ////////////////////////

   DeleteObject( hGrayPen );
   DeleteObject( hWhitePen );

   if( hFont )
      SelectObject( hDC, hOldFont );

   if( bDestroyDC )
       ReleaseDC( hWnd, hDC );

   _retni( wRow );

}
コード例 #18
0
ファイル: machine.c プロジェクト: VladisM/MARK_II
/*
 *  The main code-generation routine.
 *  f is the stream the code should be written to.
 *  p is a pointer to a doubly linked list of ICs
 *  containing the function body to generate code for.
 *  v is a pointer to the function.
 *  offset is the size of the stackframe the function
 *  needs for local variables.
 */
void gen_code(FILE *f,struct IC *p,struct Var *v,zmax offset){
    #ifdef DEBUG_MARK
    printf("Called gen_code(FILE *f,struct IC *p,struct Var *v,zmax offset)\n");
    printf("\tIdentifier: %s", v->identifier);
    #endif

    //emit function head
    if(v->storage_class==EXTERN){
        if( (v->flags & (INLINEFUNC|INLINEEXT)) != INLINEFUNC ){
            emit(f,".EXPORT \t %s \n",v->identifier);
        }
        emit(f,"%s: \n",v->identifier);
    }
    else{
        emit(f,"L_%ld:\n",zm2l(v->offset));
    }

    //emit function prologue
    emit(f, "\tPUSH \t %s\n", regnames[FP]);  //push FP
    emit(f, "\tOR   \t %s %s %s\n",regnames[R0], regnames[SP], regnames[FP]); //MOVE SP -> FP

    //make space for auto variables at stack
    for(int i = 0; i < zm2l(offset); i++){
        emit(f, "\tDEC \t %s %s\n", regnames[SP], regnames[SP]);
    }

    //store backend registers
    emit(f, "\tPUSH \t R1\n\tPUSH \t R2\n\tPUSH \t R3\n\tPUSH \t R4\n");

    //find used registers
    int saved_regs[7] = {0, 0, 0, 0, 0, 0, 0};

    struct IC *ps = p;
    for(;ps;ps=ps->next){
        if( ((ps->code) != FREEREG) && ((ps->code) != ALLOCREG) ){
            if(((ps->q1.flags) & (KONST|VAR|REG|DREFOBJ|VARADR)) == REG){
                if(((ps->q1.reg) > R5) && ((ps->q1.reg) < FP)){
                    saved_regs[(ps->q1.reg) - 7] = 1;
                }
            }
            if(((ps->q2.flags) & (KONST|VAR|REG|DREFOBJ|VARADR)) == REG){
                if(((ps->q2.reg) > R5) && ((ps->q2.reg) < FP)){
                    saved_regs[(ps->q2.reg) - 7] = 1;
                }
            }
            if(((ps->z.flags) & (KONST|VAR|REG|DREFOBJ|VARADR)) == REG){
                if(((ps->z.reg) > R5) && ((ps->z.reg) < FP)){
                    saved_regs[(ps->z.reg) - 7] = 1;
                }
            }
        }
    }

    //save used registers
    for(int i = 0; i < 7; i++){
        if(saved_regs[i] == 1){
            emit(f, "\tPUSH \t %s\n", regnames[i + 7]);
        }
    }

    //emit function body
    for(;p;p=p->next){
        int c = p->code;

        #ifdef DEBUG_MARK
        emit(f, "\n\t;p->code: %d\n", p->code);
        #endif

        switch(p->code){
            case ASSIGN:
                #ifdef DEBUG_MARK
                printf("\n\tASSIGN\n\tz.flags:%d\tq1.flags:%d\ttypf:%d\n", p->z.flags, p->q1.flags, p->typf);
                #endif

                //we can simplify assign when both operands are in registers
                if((((p->q1.flags) & (KONST|VAR|REG|DREFOBJ|VARADR)) == REG) &&
                   (((p->z.flags) & (KONST|VAR|REG|DREFOBJ|VARADR)) == REG) ){
                    emit(f, "\tOR   \t %s %s %s",regnames[R0], regnames[p->q1.reg], regnames[p->z.reg]);
                }

                //this is another optimalization, if have to assign zero; then
                //zero is read from R0 insted pushing constant into register
                else if(
                (((p->q1.flags) & (KONST|VAR|REG|DREFOBJ|VARADR)) == KONST) &&
                ((p->q1.val.vmax) == 0)
                ){
                    store_from_reg(f, R0, &(p->z), p->typf, R2, R3);
                }

                else{
                    load_into_reg(f, R1, &(p->q1), p->typf, R2);
                    store_from_reg(f, R1, &(p->z), p->typf, R2, R3);
                }

                break;
            case OR:
                #ifdef DEBUG_MARK
                printf("\n\tOR\n");
                #endif
                arithmetic(f, p);
                break;
            case XOR:
                #ifdef DEBUG_MARK
                printf("\n\tXOR\n");
                #endif
                arithmetic(f, p);
                break;
            case AND:
                #ifdef DEBUG_MARK
                printf("\n\tAND\n");
                #endif
                arithmetic(f, p);
                break;
            case LSHIFT:
                #ifdef DEBUG_MARK
                printf("\n\tLSHIFT\n");
                #endif
                arithmetic(f, p);
                break;
            case RSHIFT:
                #ifdef DEBUG_MARK
                printf("\n\tRSHIFT\n");
                #endif
                arithmetic(f, p);
                break;
            case ADD:
                #ifdef DEBUG_MARK
                printf("\n\tADD\n");
                #endif
                arithmetic(f, p);
                break;
            case SUB:
                #ifdef DEBUG_MARK
                printf("\n\tSUB\n");
                #endif
                arithmetic(f, p);
                break;
            case MULT:
                #ifdef DEBUG_MARK
                printf("\n\tMULT\n");
                #endif
                arithmetic(f, p);
                break;
            case DIV:
                #ifdef DEBUG_MARK
                printf("\n\tDIV\n");
                #endif
                arithmetic(f, p);
                break;
            case MOD:
                #ifdef DEBUG_MARK
                printf("\n\tMOD\n");
                #endif
                arithmetic(f, p);
                break;
            case KOMPLEMENT:
                #ifdef DEBUG_MARK
                printf("\n\tKOMPLEMENT\n");
                #endif
                arithmetic(f, p);
                break;
            case MINUS:
                #ifdef DEBUG_MARK
                printf("\n\tMINUS\n");
                #endif
                arithmetic(f, p);
                break;
            case ADDRESS:
                #ifdef DEBUG_MARK
                printf("\n\tADDRESS\n");
                #endif

                if(
                (((p->q1.flags) & (KONST|VAR|REG|DREFOBJ|VARADR)) == VAR) &&
                (((p->q1.v->storage_class) & (AUTO|REGISTER|STATIC|EXTERN)) == AUTO)
                ){
                    if(ISARRAY(p->q1.v->flags)){
                        load_cons(f, R1, zm2l(p->q1.v->offset)+zm2l(p->q1.val.vmax));
                    }
                    else{
                        load_cons(f, R1, zm2l(p->q1.v->offset));
                    }
                    emit(f, "\tADD \t R1 R13 R1\n");
                    store_from_reg(f, R1, &(p->z), p->typf, R2, R3);
                }
                else{
                    ierror(0);
                }

                break;
            case CALL:
                #ifdef DEBUG_MARK
                printf("\n\tCALL\n\tq1.flags: %d\n", p->q1.flags);
                #endif

                if((p->q1.flags & (VAR|DREFOBJ)) == VAR && p->q1.v->fi && p->q1.v->fi->inline_asm){
                    emit_inline_asm(f,p->q1.v->fi->inline_asm);
                }
                else{

                    if(((p->q1.flags) & (KONST|VAR|REG|DREFOBJ|VARADR)) == VAR){

                        #ifdef DEBUG_MARK
                        printf("\tq1.v->storage_class: %d\n", p->q1.v->storage_class);
                        #endif

                        switch((p->q1.v->storage_class) & (AUTO|REGISTER|STATIC|EXTERN)){
                            case EXTERN:
                                emit(f, "\tCALL \t %s\n", p->q1.v->identifier);
                                for(int i = 0; i < (p->q2.val.vmax); i++){
                                    emit(f, "\tINC \t %s %s\n", regnames[SP], regnames[SP]);
                                }
                                break;
                            case STATIC:
                                emit(f, "\tCALL \t L_%ld\n", zm2l(p->q1.v->offset));
                                for(int i = 0; i < (p->q2.val.vmax); i++){
                                    emit(f, "\tINC \t %s %s\n", regnames[SP], regnames[SP]);
                                }
                                break;
                            default:
                                #ifdef DEBUG_MARK
                                printf("\tThis is not implemented!\n");
                                #else
                                ierror(0);
                                #endif
                                break;
                        }

                    }
                    else if(((p->q1.flags) & (KONST|VAR|REG|DREFOBJ|VARADR)) == (VAR|DREFOBJ)){
                        #ifdef DEBUG_MARK
                        printf("\tq1.v->storage_class: %d\n", p->q1.v->storage_class);
                        #endif                        
                        load_into_reg(f, R1, &(p->q1), p->typf, R3);
                        emit(f, "\tCALLI\t %s\n", regnames[R1]);                        
                        emit(f, "\tINC \t %s %s\n", regnames[SP], regnames[SP]);                        
                    }
                    else{
                        #ifdef DEBUG_MARK
                        printf("\tThis is not implemented!\n");
                        #else
                        ierror(0);
                        #endif
                    }
                }
                break;
            case CONVERT:
                #ifdef DEBUG_MARK
                printf("\n\tCONVERT\n");
                #endif

                break;
            case ALLOCREG:
                #ifdef DEBUG_MARK
                printf("\n\tALLOCREG\n");
                #endif

                regs[p->q1.reg] = 1;
                break;
            case FREEREG:
                #ifdef DEBUG_MARK
                printf("\n\tFREEREG\n");
                #endif

                regs[p->q1.reg] = 0;
                break;
            case COMPARE:
                #ifdef DEBUG_MARK
                printf("\n\tCOMPARE\n");
                #endif

                compare(f, p);
                break;
            case TEST:
                #ifdef DEBUG_MARK
                printf("\n\tTEST\n");
                #endif

                compare(f, p);
                break;
            case LABEL:
                #ifdef DEBUG_MARK
                printf("\n\tLABEL\n");
                #endif

                emit(f,"L_%d:\n",p->typf);
                break;
            case BEQ:
                #ifdef DEBUG_MARK
                printf("\n\tBEQ\n");
                #endif

                emit(f, "\tBNZ \t R4 L_%d\n", p->typf);
                break;
            case BNE:
                #ifdef DEBUG_MARK
                printf("\n\tBNE\n");
                #endif

                emit(f, "\tBNZ \t R4 L_%d\n", p->typf);
                break;
            case BLT:
                #ifdef DEBUG_MARK
                printf("\n\tBLT\n");
                #endif

                emit(f, "\tBNZ \t R4 L_%d\n", p->typf);
                break;
            case BGE:
                #ifdef DEBUG_MARK
                printf("\n\tBGE\n");
                #endif

                emit(f, "\tBNZ \t R4 L_%d\n", p->typf);
                break;
            case BLE:
                #ifdef DEBUG_MARK
                printf("\n\tBLE\n");
                #endif

                emit(f, "\tBNZ \t R4 L_%d\n", p->typf);
                break;
            case BGT:
                #ifdef DEBUG_MARK
                printf("\n\tBGT\n");
                #endif

                emit(f, "\tBNZ \t R4 L_%d\n", p->typf);
                break;
            case BRA:
                #ifdef DEBUG_MARK
                printf("\n\tBRA\n");
                #endif

                emit(f, "\tBZ   \t R0 L_%d\n", p->typf);
                break;
            case PUSH:
                #ifdef DEBUG_MARK
                printf("\n\tPUSH\n");
                #endif

                load_into_reg(f, R1, &(p->q1), p->typf, R2);
                emit(f, "\tPUSH \t R1\n");
                break;
            case ADDI2P:
                #ifdef DEBUG_MARK
                printf("\n\tADDI2P\n");
                #endif
                arithmetic(f, p);
                break;
            case SUBIFP:
                #ifdef DEBUG_MARK
                printf("\n\tSUBIFP\n");
                #endif
                arithmetic(f, p);
                break;
            case SUBPFP:
                #ifdef DEBUG_MARK
                printf("\n\tSUBPFP\n");
                #endif
                arithmetic(f, p);
                break;
            case GETRETURN:
                #ifdef DEBUG_MARK
                printf("\n\tGETRETURN\n");
                #endif
                if((p->q1.reg) != 0){
                    store_from_reg(f, p->q1.reg, &(p->z), p->typf, R2, R3);
                }
                else{
                    #ifdef DEBUG_MARK
                    printf("\tq1.reg == 0, didn't know how to dealt with it!");
                    #else
                    ierror(0);
                    #endif
                }
                break;
            case SETRETURN:
                #ifdef DEBUG_MARK
                printf("\n\tSETRETURN\n\tz.flags:%d\n", p->z.flags);
                #endif
                if((p->z.reg) != 0){
                    load_into_reg(f, p->z.reg, &(p->q1), p->typf, R1);
                }
                else{
                    #ifdef DEBUG_MARK
                    printf("\tz.reg == 0, didn't know how to dealt with it!");
                    #else
                    ierror(0);
                    #endif
                }
                break;
            case MOVEFROMREG:
                #ifdef DEBUG_MARK
                printf("\n\tMOVEFROMREG\n");
                #endif

                store_from_reg(f, p->q1.reg, &(p->z), p->typf, R1, R3);
                break;
            case MOVETOREG:
                #ifdef DEBUG_MARK
                printf("\n\tMOVETOREG\n");
                #endif

                load_into_reg(f, p->z.reg, &(p->q1), p->typf, R1);
                break;
            case NOP:
                #ifdef DEBUG_MARK
                printf("\n\tNOP\n");
                #endif
                break;
            default:
                #ifdef DEBUG_MARK
                printf("\tSomething is wrong in gencode()!\n");
                #else
                ierror(0);
                #endif
                break;
        }
    }

    //restore used registers
    for(int i = 6; i >= 0; i--){
        if(saved_regs[i] == 1){
            emit(f, "\tPOP \t %s\n", regnames[i + 7]);
        }
    }

    //restore backend registers
    emit(f, "\tPOP \t R4\n\tPOP \t R3\n\tPOP \t R2\n\tPOP \t R1\n");

    //emit function epilogue
    emit(f, "\tOR  \t %s %s %s\n",regnames[R0], regnames[FP], regnames[SP]); //restore SP from FP
    emit(f, "\tPOP \t %s\n", regnames[FP]); //restore old FP from stack

    //return
    if((v->tattr)&INTERRUPT){
        emit(f, "\tRETI\n");
    }
    else{
        emit(f, "\tRET\n");
    }
}