Beispiel #1
0
/*
 * Process a function definition.
 */
cfunc()
{
	register char *cb;
	register sloc;

	sloc = isn;
	isn += 2;
	outcode("BBS", PROG, RLABEL, funcsym->name);
	regvar = 5;
	autolen = STAUTO;
	maxauto = STAUTO;
	blklev = 1;
	cb = locbase;
	declist(ARG);
	outcode("B", SAVE);
	if (proflg)
		outcode("BNS", PROFIL, isn++, funcsym->name);
	funchead();
	branch(sloc);
	label(sloc+1);
	retlab = isn++;
	blklev = 0;
	if ((peeksym = symbol()) != LBRACE)
		error("Compound statement required");
	statement();
	outcode("BNB", LABEL, retlab, RETRN);
	label(sloc);
/* add STAUTO; overlay bug fix, coupled with section in c11.c */
	outcode("BN", SETSTK, -maxauto+STAUTO);
	branch(sloc+1);
	locbase = cb;
}
Beispiel #2
0
static inline int process(int code, unsigned char **fill)
{
  static int avail, oldcode;
  codetype *p;

  if (code == clear) {
    codesize = datasize + 1;
    codemask = (1 << codesize) - 1;
    avail = clear + 2;
    oldcode = -1;
  }
  else if (code < avail) {
    outcode(&codetable[code], fill);
    if (oldcode != -1) {
      p = &codetable[avail++];
      p->prefix = &codetable[oldcode];
      p->first = p->prefix->first;
      p->suffix = codetable[code].first;

      if ((avail & codemask) == 0 && avail < 4096) {
	codesize++;
	codemask += avail;
      }
    }

    oldcode = code;
  }
  else if (code == avail && oldcode != -1) {
    p = &codetable[avail++];
    p->prefix = &codetable[oldcode];
    p->first = p->prefix->first;
    p->suffix = p->first;

    outcode(p, fill);

    if ((avail & codemask) == 0 && avail < 4096) {
      codesize++;
      codemask += avail;
    }
    oldcode = code;
  }
  else {
    fprintf(stderr, "Illegal code in raster data. Continuing\n");
    return PICERR_BADFORMAT;
  }

  return 0;
}
Beispiel #3
0
static void outcode(codetype *p, unsigned char **fill)
{
  if (p->prefix)
    outcode(p->prefix, fill);

  *(*fill)++ = p->suffix;
}
Beispiel #4
0
Datei: lex.c Projekt: hfeeki/go
void
cclean(void)
{

	outcode(AEND, Always, &nullgen, NREG, &nullgen);
	Bflush(&obuf);
}
Beispiel #5
0
void
codeswitch(tree *t, int eflag)
{
	int leave;		/* patch jump address to leave switch */
	int out;		/* jump here to leave switch */
	int nextcase;	/* patch jump address to next case */
	tree *tt;
	if(c1->child[0]==nil
	|| c1->child[0]->type!=';'
	|| !iscase(c1->child[0]->child[0])){
		yyerror("case missing in switch");
		return;
	}
	emitf(Xmark);
	outcode(c0, eflag);
	emitf(Xjump);
	nextcase = emiti(0);
	out = emitf(Xjump);
	leave = emiti(0);
	stuffdot(nextcase);
	t = c1->child[0];
	while(t->type==';'){
		tt = c1;
		emitf(Xmark);
		for(t = c0->child[0];t->type==ARGLIST;t = c0) outcode(c1, eflag);
		emitf(Xcase);
		nextcase = emiti(0);
		t = tt;
		for(;;){
			if(t->type==';'){
				if(iscase(c0)) break;
				outcode(c0, eflag);
				t = c1;
			}
			else{
				if(!iscase(t)) outcode(t, eflag);
				break;
			}
		}
		emitf(Xjump);
		emiti(out);
		stuffdot(nextcase);
	}
	stuffdot(leave);
	emitf(Xpopm);
}
Beispiel #6
0
void
cclean(void)
{
	Addr2 g2;

	g2.from = nullgen;
	g2.to = nullgen;
	outcode(AEND, &g2);
}
Beispiel #7
0
void
cclean(void)
{
	Gen2 g2;

	g2.from = nullgen;
	g2.to = nullgen;
	outcode(AEND, &g2);
	Bflush(&obuf);
}
Beispiel #8
0
int 
clip_to_rect(double x[2], double y[2], double r[4]) {
  int c0,c1,c2;
  c0 = outcode(x[0],y[0],r);
  c1 = outcode(x[1],y[1],r);
  while(1) {
    if(!(c0 | c1)) {
      return 1;
    }
    if((c0 & c1)) {
      return 0;
    }
    double tx, ty;
    c2 = c0 ? c0 : c1;
    if(c2 & TOP) {
      tx = x[0] + (x[1] - x[0]) * (r[3] - y[0]) / (y[1] - y[0]);
      ty = r[3];
    } else if(c2 & BOTTOM) {
      tx = x[0] + (x[1] - x[0]) * (r[2] - y[0]) / (y[1] - y[0]);
      ty = r[2];
    } else if(c2 & RIGHT) {
      ty = y[0] + (y[1] - y[0]) * (r[1] - x[0]) / (x[1] - x[0]);
      tx = r[1];
    } else if(c2 & LEFT) {
      ty = y[0] + (y[1] - y[0]) * (r[0] - x[0]) / (x[1] - x[0]);
      tx = r[0];
    }

    if(c2 == c0) {
      x[0] = tx;
      y[0] = ty;
      c0 = outcode(x[0],y[0],r);
    } else {
      x[1] = tx;
      y[1] = ty;
      c1 = outcode(x[1],y[1],r);
    }
  }
  return 0;
}
Beispiel #9
0
int
compile(tree *t)
{
	ncode = 100;
	codebuf = (code *)emalloc(ncode*sizeof codebuf[0]);
	codep = 0;
	emiti(0);			/* reference count */
	outcode(t, flag['e']?1:0);
	if(nerror){
		efree((char *)codebuf);
		return 0;
	}
	readhere();
	emitf(Xreturn);
	emitf(0);
	return 1;
}
Beispiel #10
0
/**
 * coarse box vs frustum test for culling.
 * corners of oriented box are transformed to clip space
 * and there is a test that all points are on the wrong side of the same plane
 * see http://www.lighthouse3d.com/tutorials/view-frustum-culling/geometric-approach-testing-boxes/
 *
 * should be equivalent to https://searchcode.com/codesearch/view/35195518/
 * qt3d /src/threed/painting/qglpainter.cpp
 * bool QGLPainter::isCullable(const QBox3D& box) const
 */
bool Qgs3DUtils::isCullable( const QgsAABB &bbox, const QMatrix4x4 &viewProjectionMatrix )
{
  uint out = 0xff;

  for ( int i = 0; i < 8; ++i )
  {
    QVector4D p( ( ( i >> 0 ) & 1 ) ? bbox.xMin : bbox.xMax,
                 ( ( i >> 1 ) & 1 ) ? bbox.yMin : bbox.yMax,
                 ( ( i >> 2 ) & 1 ) ? bbox.zMin : bbox.zMax, 1 );
    QVector4D pc = viewProjectionMatrix * p;

    // if the logical AND of all the outcodes is non-zero then the BB is
    // definitely outside the view frustum.
    out = out & outcode( pc );
  }
  return out;
}
Beispiel #11
0
/*
 * Process a single external definition
 */
extdef()
{
	register o, elsize;
	int type, sclass;
	register struct hshtab *ds;

	if(((o=symbol())==EOF) || o==SEMI)
		return;
	peeksym = o;
	type = INT;
	sclass = EXTERN;
	xdflg = FNDEL;
	if ((elsize = getkeywords(&sclass, &type)) == -1 && peeksym!=NAME)
		goto syntax;
	if (type==STRUCT)
		blkhed();
	do {
		defsym = 0;
		decl1(EXTERN, type, 0, elsize);
		if ((ds=defsym)==0)
			return;
		funcsym = ds;
		ds->hflag =| FNDEL;
		outcode("BS", SYMDEF, ds->name);
		xdflg = 0;
		if ((ds->type&XTYPE)==FUNC) {
			if ((peeksym=symbol())==LBRACE || peeksym==KEYW) {
				funcblk.type = decref(ds->type);
				cfunc(ds->name);
				return;
			}
		} else 
			cinit(ds);
	} while ((o=symbol())==COMMA);
	if (o==SEMI)
		return;
syntax:
	if (o==RBRACE) {
		error("Too many }'s");
		peeksym = 0;
		return;
	}
	error("External definition syntax");
	errflush(o);
	statement(0);
}
Beispiel #12
0
/*
 * Process a single external definition
 */
extdef()
{
	register o;
	int sclass, scflag;
	struct nmlist typer;
	register struct nmlist *ds;

	if(((o=symbol())==EOFC) || o==SEMI)
		return;
	peeksym = o;
	sclass = 0;
	blklev = 0;
	if (getkeywords(&sclass, &typer)==0) {
		sclass = EXTERN;
		if (peeksym!=NAME)
			goto syntax;
	}
	scflag = 0;
	if (sclass==DEFXTRN) {
		scflag++;
		sclass = EXTERN;
	}
	if (sclass!=EXTERN && sclass!=STATIC && sclass!=TYPEDEF)
		error("Illegal storage class");
	do {
		defsym = 0;
		paraml = NULL;
		parame = NULL;
		if (sclass==TYPEDEF) {
			decl1(TYPEDEF, &typer, 0, (struct nmlist *)NULL);
			continue;
		}
		decl1(EXTERN, &typer, 0, (struct nmlist *)NULL);
		if ((ds=defsym)==0)
			return;
		funcsym = ds;
		if ((ds->htype&XTYPE)==FUNC) {
			if ((peeksym=symbol())==LBRACE || peeksym==KEYW
			 || (peeksym==NAME && csym->hclass==TYPEDEF)) {
				funcblk.type = decref(ds->htype);
				funcblk.strp = ds->hstrp;
				setinit(ds);
				outcode("BS", SYMDEF, sclass==EXTERN?ds->name:"");
				cfunc();
				return;
			}
			if (paraml)
				error("Inappropriate parameters");
		} else if ((o=symbol())==COMMA || o==SEMI) {
			peeksym = o;
			o = (length((union tree *)ds)+ALIGN) & ~ALIGN;
			if (sclass==STATIC) {
				setinit(ds);
				outcode("BSBBSBN", SYMDEF, "", BSS, NLABEL, ds->name, SSPACE, o);
			} else if (scflag)
				outcode("BSN", CSPACE, ds->name, o);
		} else {
			if (o!=ASSIGN) {
				error("Declaration syntax");
				peeksym = o;
			}
			setinit(ds);
			if (sclass==EXTERN)
				outcode("BS", SYMDEF, ds->name);
			outcode("BBS", DATA, NLABEL, ds->name);
			if (cinit(ds, 1, sclass) & ALIGN)
				outcode("B", EVEN);
		}
	} while ((o=symbol())==COMMA);
	if (o==SEMI)
		return;
syntax:
	if (o==RBRACE) {
		error("Too many }'s");
		peeksym = 0;
		return;
	}
	error("External definition syntax");
	errflush(o);
	statement();
}
Beispiel #13
0
void
outcode(tree *t, int eflag)
{
	int p, q;
	tree *tt;
	if(t==0)
		return;
	if(t->type!=NOT && t->type!=';')
		runq->iflast = 0;
	switch(t->type){
	default:
		pfmt(err, "bad type %d in outcode\n", t->type);
		break;
	case '$':
		emitf(Xmark);
		outcode(c0, eflag);
		emitf(Xdol);
		break;
	case '"':
		emitf(Xmark);
		outcode(c0, eflag);
		emitf(Xqdol);
		break;
	case SUB:
		emitf(Xmark);
		outcode(c0, eflag);
		emitf(Xmark);
		outcode(c1, eflag);
		emitf(Xsub);
		break;
	case '&':
		emitf(Xasync);
		if(havefork){
			p = emiti(0);
			outcode(c0, eflag);
			emitf(Xexit);
			stuffdot(p);
		} else
			emits(fnstr(c0));
		break;
	case ';':
		outcode(c0, eflag);
		outcode(c1, eflag);
		break;
	case '^':
		emitf(Xmark);
		outcode(c1, eflag);
		emitf(Xmark);
		outcode(c0, eflag);
		emitf(Xconc);
		break;
	case '`':
		emitf(Xbackq);
		if(havefork){
			p = emiti(0);
			outcode(c0, 0);
			emitf(Xexit);
			stuffdot(p);
		} else
			emits(fnstr(c0));
		break;
	case ANDAND:
		outcode(c0, 0);
		emitf(Xtrue);
		p = emiti(0);
		outcode(c1, eflag);
		stuffdot(p);
		break;
	case ARGLIST:
		outcode(c1, eflag);
		outcode(c0, eflag);
		break;
	case BANG:
		outcode(c0, eflag);
		emitf(Xbang);
		break;
	case PCMD:
	case BRACE:
		outcode(c0, eflag);
		break;
	case COUNT:
		emitf(Xmark);
		outcode(c0, eflag);
		emitf(Xcount);
		break;
	case FN:
		emitf(Xmark);
		outcode(c0, eflag);
		if(c1){
			emitf(Xfn);
			p = emiti(0);
			emits(fnstr(c1));
			outcode(c1, eflag);
			emitf(Xunlocal);	/* get rid of $* */
			emitf(Xreturn);
			stuffdot(p);
		}
		else
			emitf(Xdelfn);
		break;
	case IF:
		outcode(c0, 0);
		emitf(Xif);
		p = emiti(0);
		outcode(c1, eflag);
		emitf(Xwastrue);
		stuffdot(p);
		break;
	case NOT:
		if(!runq->iflast)
			yyerror("`if not' does not follow `if(...)'");
		emitf(Xifnot);
		p = emiti(0);
		outcode(c0, eflag);
		stuffdot(p);
		break;
	case OROR:
		outcode(c0, 0);
		emitf(Xfalse);
		p = emiti(0);
		outcode(c1, eflag);
		stuffdot(p);
		break;
	case PAREN:
		outcode(c0, eflag);
		break;
	case SIMPLE:
		emitf(Xmark);
		outcode(c0, eflag);
		emitf(Xsimple);
		if(eflag)
			emitf(Xeflag);
		break;
	case SUBSHELL:
		emitf(Xsubshell);
		if(havefork){
			p = emiti(0);
			outcode(c0, eflag);
			emitf(Xexit);
			stuffdot(p);
		} else
			emits(fnstr(c0));
		if(eflag)
			emitf(Xeflag);
		break;
	case SWITCH:
		codeswitch(t, eflag);
		break;
	case TWIDDLE:
		emitf(Xmark);
		outcode(c1, eflag);
		emitf(Xmark);
		outcode(c0, eflag);
		emitf(Xmatch);
		if(eflag)
			emitf(Xeflag);
		break;
	case WHILE:
		q = codep;
		outcode(c0, 0);
		if(q==codep)
			emitf(Xsettrue);	/* empty condition == while(true) */
		emitf(Xtrue);
		p = emiti(0);
		outcode(c1, eflag);
		emitf(Xjump);
		emiti(q);
		stuffdot(p);
		break;
	case WORDS:
		outcode(c1, eflag);
		outcode(c0, eflag);
		break;
	case FOR:
		emitf(Xmark);
		if(c1){
			outcode(c1, eflag);
			emitf(Xglob);
		}
		else{
			emitf(Xmark);
			emitf(Xword);
			emits(strdup("*"));
			emitf(Xdol);
		}
		emitf(Xmark);		/* dummy value for Xlocal */
		emitf(Xmark);
		outcode(c0, eflag);
		emitf(Xlocal);
		p = emitf(Xfor);
		q = emiti(0);
		outcode(c2, eflag);
		emitf(Xjump);
		emiti(p);
		stuffdot(q);
		emitf(Xunlocal);
		break;
	case WORD:
		emitf(Xword);
		emits(strdup(t->str));
		break;
	case DUP:
		if(t->rtype==DUPFD){
			emitf(Xdup);
			emiti(t->fd0);
			emiti(t->fd1);
		}
		else{
			emitf(Xclose);
			emiti(t->fd0);
		}
		outcode(c1, eflag);
		emitf(Xpopredir);
		break;
	case PIPEFD:
		emitf(Xpipefd);
		emiti(t->rtype);
		if(havefork){
			p = emiti(0);
			outcode(c0, eflag);
			emitf(Xexit);
			stuffdot(p);
		} else {
			emits(fnstr(c0));
		}
		break;
	case REDIR:
		emitf(Xmark);
		outcode(c0, eflag);
		emitf(Xglob);
		switch(t->rtype){
		case APPEND:
			emitf(Xappend);
			break;
		case WRITE:
			emitf(Xwrite);
			break;
		case READ:
		case HERE:
			emitf(Xread);
			break;
		case RDWR:
			emitf(Xrdwr);
			break;
		}
		emiti(t->fd0);
		outcode(c1, eflag);
		emitf(Xpopredir);
		break;
	case '=':
		tt = t;
		for(;t && t->type=='=';t = c2);
		if(t){
			for(t = tt;t->type=='=';t = c2){
				emitf(Xmark);
				outcode(c1, eflag);
				emitf(Xmark);
				outcode(c0, eflag);
				emitf(Xlocal);
			}
			outcode(t, eflag);
			for(t = tt; t->type=='='; t = c2)
				emitf(Xunlocal);
		}
		else{
			for(t = tt;t;t = c2){
				emitf(Xmark);
				outcode(c1, eflag);
				emitf(Xmark);
				outcode(c0, eflag);
				emitf(Xassign);
			}
		}
		t = tt;	/* so tests below will work */
		break;
	case PIPE:
		emitf(Xpipe);
		emiti(t->fd0);
		emiti(t->fd1);
		if(havefork){
			p = emiti(0);
			q = emiti(0);
			outcode(c0, eflag);
			emitf(Xexit);
			stuffdot(p);
		} else {
			emits(fnstr(c0));
			q = emiti(0);
		}
		outcode(c1, eflag);
		emitf(Xreturn);
		stuffdot(q);
		emitf(Xpipewait);
		break;
	}
	if(t->type!=NOT && t->type!=';')
		runq->iflast = t->type==IF;
	else if(c0) runq->iflast = c0->type==IF;
}
Beispiel #14
0
static bool_t
cohen_sutherland( double xmin, double xmax, double ymin, double ymax,
	double x0, double y0, double x1, double y1,
	double *xc0, double *yc0, double *xc1, double *yc1 )
{
	unsigned out, out0, out1;
	bool_t accept, done;
	double x = 0., y = 0.;

	out0 = outcode( x0, y0, xmin, xmax, ymin, ymax );
	out1 = outcode( x1, y1, xmin, xmax, ymin, ymax );

	accept = FALSE;
	done = FALSE;

	do
	{
		if ( (out0 == 0) && (out1 == 0) )
		{
			/* trivially inside */
			accept = TRUE;
			done = TRUE;
		}
		else if ( (out0 & out1) != 0 )
		{
			/* trivially outside */
			done = TRUE;
		}
		else
		{
			out = ( out0 != 0 ) ? out0 : out1 ;

			if ( (out & BGL_TOP) != 0 )
			{
				x = x0 + (x1 - x0)*(ymax - y0)/(y1 - y0);
				y = ymax;
			}
			else if ( (out & BGL_BOTTOM) != 0 )
			{
				x = x0 + (x1 - x0)*(ymin - y0)/(y1 - y0);
				y = ymin;
			}
			else if ( (out & BGL_RIGHT) != 0 )
			{
				y = y0 + (y1 - y0)*(xmax - x0)/(x1 - x0);
				x = xmax;
			}
			else if ( (out & BGL_LEFT) != 0 )
			{
				y = y0 + (y1 - y0)*(xmin - x0)/(x1 - x0);
				x = xmin;
			}

			if ( out == out0 )
			{
				x0 = x;
				y0 = y;
				out0 = outcode( x, y, xmin, xmax, ymin, ymax ); 
			}
			else
			{
				x1 = x;
				y1 = y;
				out1 = outcode( x, y, xmin, xmax, ymin, ymax );
			}
		}
	}
	while ( done != TRUE );

	if ( accept == TRUE )
	{
		*xc0 = x0;
		*yc0 = y0;
		*xc1 = x1;
		*yc1 = y1;

		/* printf( "(%g %g) (%g %g)\n", x0, y0, x1, y1 ); */
	}

	return accept;
}
static bool cohen_sutherland_clip(int* X1, int* Y1, int* X2, int* Y2)
{
    int x1 = *X1;
    int y1 = *Y1;
    int x2 = *X2;
    int y2 = *Y2;

    const int clipX1 = a__screen.clipX;
    const int clipX2 = a__screen.clipX2;
    const int clipY1 = a__screen.clipY;
    const int clipY2 = a__screen.clipY2;

    #define A__OUT_LEFT  1
    #define A__OUT_RIGHT 2
    #define A__OUT_TOP   4
    #define A__OUT_DOWN  8

    #define outcode(o, x, y)                  \
    {                                         \
        if(x < clipX1) o |= A__OUT_LEFT;         \
        else if(x >= clipX2) o |= A__OUT_RIGHT;  \
                                              \
        if(y < clipY1) o |= A__OUT_TOP;          \
        else if(y >= clipY2) o |= A__OUT_DOWN;   \
    }

    #define solvex() (x1 + (x1 - x2) * (y - y1) / (y1 - y2))
    #define solvey() (y1 + (y1 - y2) * (x - x1) / (x1 - x2))

    while(true) {
        int outcode1 = 0;
        int outcode2 = 0;

        outcode(outcode1, x1, y1);
        outcode(outcode2, x2, y2);

        if((outcode1 | outcode2) == 0) {
            *X1 = x1;
            *Y1 = y1;
            *X2 = x2;
            *Y2 = y2;

            return true;
        } else if(outcode1 & outcode2) {
            return false;
        } else {
            int x, y;
            const int outcode = outcode1 ? outcode1 : outcode2;

            if(outcode & A__OUT_LEFT) {
                x = clipX1;
                y = solvey();
            } else if(outcode & A__OUT_RIGHT) {
                x = clipX2 - 1;
                y = solvey();
            } else if(outcode & A__OUT_TOP) {
                y = clipY1;
                x = solvex();
            } else { // outcode & A__OUT_DOWN
                y = clipY2 - 1;
                x = solvex();
            }

            if(outcode == outcode1) {
                x1 = x;
                y1 = y;
            } else {
                x2 = x;
                y2 = y;
            }
        }
    }
}
Beispiel #16
0
void gencode(ESTRUC_ *e, OPCODE_ opcode, ...)
{
    register size_t
        idx,
        last;
    int
        marker_value;
    size_t
        count;
    va_list
        marker;

    if (dead[dead_sp])
        return;

    va_start(marker, opcode);

    lastop = opcode;                        /* remember last opcode */
    outcode(e, (int)opcode, sizeof(char));

    switch (opcode)
    {
        case op_jmp:                        /* write target to jump to */
            switch ((JMP_COND_)va_arg(marker, JMP_COND_))
            {
                case j_uncond:              /* absolute jumplocation */
                    outcode(e, va_arg(marker, int), sizeof(INT16));
                break;

                case j_truelist:
                    patchtrue(e);           /* new truelist item */
                break;

                case j_falselist:
                    patchfalse(e);          /* new falselist item */
                break;
            }
        break;

        case op_jmp_false:                  /* write target to jump if false */
            patchfalse(e);
        break;

        case op_jmp_true:                   /* write target to jump if true */
            patchtrue(e);
        break;

        case op_push_strconst:              /* write idx of the const */
            outcode(e, 
                (int)stringtab[va_arg(marker, int)].index, sizeof(INT16));
        break;

        case op_frame:
            count = last = local.n_defined - n_params;
            outcode(e, (int)count, sizeof(char));
            for (idx = 0; idx < last; idx++)
            {
                count = local.symbol[n_params + idx].var.type & ALLTYPES;
                outcode(e, (int)count, sizeof(char));
            }
        break;

        case op_copy_var:                   /* write # of the var. */
        case op_push_imm:                   /* write value of the int */
        case op_push_var:                   /* write # of the var. */
        case op_dec:                        /* write # of the var. */
        case op_inc:                        /* write # of the var. */
        case op_call:                       /* write offset of function */
            outcode(e, va_arg(marker, int), sizeof(INT16));
        break;

        case op_asp:                        /* write # of args to remove */
            marker_value = va_arg(marker, int);
            if (!marker_value)              /* nothing to add to sp */
                e->codelen--;               /* opcode removed from code */
        else
                outcode(e, marker_value, sizeof(char));
        break;      

        case op_call_rss:                   /* write # of function */
            outcode(e, va_arg(marker, int), sizeof(char));
        break;

        case op_ret:
        case op_exit:
            ++dead[dead_sp];
        break;

        default:
/*
        The default switch entry is inserted to prvent a long compiler
        warning about a not-handled enum value

        following opcodes already out:

        op_pop_reg
        op_push_reg
        op_push_1_jmp_end
        op_push_0
        op_umin
        op_atoi
        op_itoa
        op_atol
        op_mul
        op_div
        op_mod
        op_add
        op_sub
        op_eq
        op_neq
        op_sm
        op_gr
        op_younger
        op_older
        op_smeq
        op_greq
*/
break;
    }
}
Beispiel #17
0
int
yyparse(void)
{
	struct
	{
		YYSTYPE	yyv;
		int	yys;
	} yys[YYMAXDEPTH], *yyp, *yypt;
	short *yyxi;
	int yyj, yym, yystate, yyn, yyg;
	long yychar;
	YYSTYPE save1, save2;
	int save3, save4;

	save1 = yylval;
	save2 = yyval;
	save3 = yynerrs;
	save4 = yyerrflag;

	yystate = 0;
	yychar = -1;
	yynerrs = 0;
	yyerrflag = 0;
	yyp = &yys[-1];
	goto yystack;

ret0:
	yyn = 0;
	goto ret;

ret1:
	yyn = 1;
	goto ret;

ret:
	yylval = save1;
	yyval = save2;
	yynerrs = save3;
	yyerrflag = save4;
	return yyn;

yystack:
	/* put a state and value onto the stack */
	if(yydebug >= 4)
		fprint(2, "char %s in %s", yytokname(yychar), yystatname(yystate));

	yyp++;
	if(yyp >= &yys[YYMAXDEPTH]) {
		yyerror("yacc stack overflow");
		goto ret1;
	}
	yyp->yys = yystate;
	yyp->yyv = yyval;

yynewstate:
	yyn = yypact[yystate];
	if(yyn <= YYFLAG)
		goto yydefault; /* simple state */
	if(yychar < 0)
		yychar = yylex1();
	yyn += yychar;
	if(yyn < 0 || yyn >= YYLAST)
		goto yydefault;
	yyn = yyact[yyn];
	if(yychk[yyn] == yychar) { /* valid shift */
		yychar = -1;
		yyval = yylval;
		yystate = yyn;
		if(yyerrflag > 0)
			yyerrflag--;
		goto yystack;
	}

yydefault:
	/* default state action */
	yyn = yydef[yystate];
	if(yyn == -2) {
		if(yychar < 0)
			yychar = yylex1();

		/* look through exception table */
		for(yyxi=yyexca;; yyxi+=2)
			if(yyxi[0] == -1 && yyxi[1] == yystate)
				break;
		for(yyxi += 2;; yyxi += 2) {
			yyn = yyxi[0];
			if(yyn < 0 || yyn == yychar)
				break;
		}
		yyn = yyxi[1];
		if(yyn < 0)
			goto ret0;
	}
	if(yyn == 0) {
		/* error ... attempt to resume parsing */
		switch(yyerrflag) {
		case 0:   /* brand new error */
			yyerror("syntax error");
			yynerrs++;
			if(yydebug >= 1) {
				fprint(2, "%s", yystatname(yystate));
				fprint(2, "saw %s\n", yytokname(yychar));
			}

		case 1:
		case 2: /* incompletely recovered error ... try again */
			yyerrflag = 3;

			/* find a state where "error" is a legal shift action */
			while(yyp >= yys) {
				yyn = yypact[yyp->yys] + YYERRCODE;
				if(yyn >= 0 && yyn < YYLAST) {
					yystate = yyact[yyn];  /* simulate a shift of "error" */
					if(yychk[yystate] == YYERRCODE)
						goto yystack;
				}

				/* the current yyp has no shift onn "error", pop stack */
				if(yydebug >= 2)
					fprint(2, "error recovery pops state %d, uncovers %d\n",
						yyp->yys, (yyp-1)->yys );
				yyp--;
			}
			/* there is no state on the stack with an error shift ... abort */
			goto ret1;

		case 3:  /* no shift yet; clobber input char */
			if(yydebug >= 2)
				fprint(2, "error recovery discards %s\n", yytokname(yychar));
			if(yychar == YYEOFCODE)
				goto ret1;
			yychar = -1;
			goto yynewstate;   /* try again in the same state */
		}
	}

	/* reduction by production yyn */
	if(yydebug >= 2)
		fprint(2, "reduce %d in:\n\t%s", yyn, yystatname(yystate));

	yypt = yyp;
	yyp -= yyr2[yyn];
	yyval = (yyp+1)->yyv;
	yym = yyn;

	/* consult goto table to find next state */
	yyn = yyr1[yyn];
	yyg = yypgo[yyn];
	yyj = yyg + yyp->yys + 1;

	if(yyj >= YYLAST || yychk[yystate=yyact[yyj]] != -yyn)
		yystate = yyact[yyg];
	switch(yym) {
		
case 3:
#line	40	"a.y"
{
		if(yypt[-1].yyv.sym->value != pc)
			yyerror("redeclaration of %s", yypt[-1].yyv.sym->name);
		yypt[-1].yyv.sym->value = pc;
	} break;
case 5:
#line	47	"a.y"
{
		yypt[-1].yyv.sym->type = LLAB;
		yypt[-1].yyv.sym->value = pc;
	} break;
case 10:
#line	58	"a.y"
{
		yypt[-2].yyv.sym->type = LVAR;
		yypt[-2].yyv.sym->value = yypt[-0].yyv.lval;
	} break;
case 11:
#line	63	"a.y"
{
		if(yypt[-2].yyv.sym->value != yypt[-0].yyv.lval)
			yyerror("redeclaration of %s", yypt[-2].yyv.sym->name);
		yypt[-2].yyv.sym->value = yypt[-0].yyv.lval;
	} break;
case 12:
#line	68	"a.y"
{ outcode(yypt[-1].yyv.lval, &yypt[-0].yyv.gen2); } break;
case 13:
#line	69	"a.y"
{ outcode(yypt[-1].yyv.lval, &yypt[-0].yyv.gen2); } break;
case 14:
#line	70	"a.y"
{ outcode(yypt[-1].yyv.lval, &yypt[-0].yyv.gen2); } break;
case 15:
#line	71	"a.y"
{ outcode(yypt[-1].yyv.lval, &yypt[-0].yyv.gen2); } break;
case 16:
#line	72	"a.y"
{ outcode(yypt[-1].yyv.lval, &yypt[-0].yyv.gen2); } break;
case 17:
#line	73	"a.y"
{ outcode(yypt[-1].yyv.lval, &yypt[-0].yyv.gen2); } break;
case 18:
#line	74	"a.y"
{ outcode(yypt[-1].yyv.lval, &yypt[-0].yyv.gen2); } break;
case 19:
#line	75	"a.y"
{ outcode(yypt[-1].yyv.lval, &yypt[-0].yyv.gen2); } break;
case 20:
#line	76	"a.y"
{ outcode(yypt[-1].yyv.lval, &yypt[-0].yyv.gen2); } break;
case 21:
#line	77	"a.y"
{ outcode(yypt[-1].yyv.lval, &yypt[-0].yyv.gen2); } break;
case 22:
#line	78	"a.y"
{ outcode(yypt[-1].yyv.lval, &yypt[-0].yyv.gen2); } break;
case 23:
#line	79	"a.y"
{ outcode(yypt[-1].yyv.lval, &yypt[-0].yyv.gen2); } break;
case 24:
#line	80	"a.y"
{ outcode(yypt[-1].yyv.lval, &yypt[-0].yyv.gen2); } break;
case 25:
#line	81	"a.y"
{ outcode(yypt[-1].yyv.lval, &yypt[-0].yyv.gen2); } break;
case 26:
#line	84	"a.y"
{
		yyval.gen2.from = nullgen;
		yyval.gen2.to = nullgen;
	} break;
case 27:
#line	89	"a.y"
{
		yyval.gen2.from = nullgen;
		yyval.gen2.to = nullgen;
	} break;
case 28:
#line	96	"a.y"
{
		yyval.gen2.from = yypt[-2].yyv.gen;
		yyval.gen2.to = yypt[-0].yyv.gen;
	} break;
case 29:
#line	103	"a.y"
{
		yyval.gen2.from = yypt[-2].yyv.gen;
		yyval.gen2.to = yypt[-0].yyv.gen;
	} break;
case 30:
#line	110	"a.y"
{
		yyval.gen2.from = yypt[-1].yyv.gen;
		yyval.gen2.to = nullgen;
	} break;
case 31:
#line	115	"a.y"
{
		yyval.gen2.from = yypt[-0].yyv.gen;
		yyval.gen2.to = nullgen;
	} break;
case 32:
#line	122	"a.y"
{
		yyval.gen2.from = nullgen;
		yyval.gen2.to = yypt[-0].yyv.gen;
	} break;
case 33:
#line	127	"a.y"
{
		yyval.gen2.from = nullgen;
		yyval.gen2.to = yypt[-0].yyv.gen;
	} break;
case 34:
#line	134	"a.y"
{
		yyval.gen2.from = nullgen;
		yyval.gen2.to = yypt[-0].yyv.gen;
	} break;
case 35:
#line	139	"a.y"
{
		yyval.gen2.from = nullgen;
		yyval.gen2.to = yypt[-0].yyv.gen;
	} break;
case 36:
#line	146	"a.y"
{
		yyval.gen2.from = yypt[-4].yyv.gen;
		yyval.gen2.from.scale = yypt[-2].yyv.lval;
		yyval.gen2.to = yypt[-0].yyv.gen;
	} break;
case 37:
#line	154	"a.y"
{
		yyval.gen2.from = yypt[-2].yyv.gen;
		yyval.gen2.to = yypt[-0].yyv.gen;
	} break;
case 38:
#line	159	"a.y"
{
		yyval.gen2.from = yypt[-4].yyv.gen;
		yyval.gen2.from.scale = yypt[-2].yyv.lval;
		yyval.gen2.to = yypt[-0].yyv.gen;
	} break;
case 39:
#line	167	"a.y"
{
		yyval.gen2.from = nullgen;
		yyval.gen2.to = yypt[-0].yyv.gen;
	} break;
case 40:
#line	172	"a.y"
{
		yyval.gen2.from = nullgen;
		yyval.gen2.to = yypt[-0].yyv.gen;
	} break;
case 43:
#line	183	"a.y"
{
		yyval.gen2.from = yypt[-2].yyv.gen;
		yyval.gen2.to = yypt[-0].yyv.gen;
	} break;
case 44:
#line	188	"a.y"
{
		yyval.gen2.from = yypt[-4].yyv.gen;
		yyval.gen2.to = yypt[-2].yyv.gen;
		if(yyval.gen2.from.index != D_NONE)
			yyerror("dp shift with lhs index");
		yyval.gen2.from.index = yypt[-0].yyv.lval;
	} break;
case 45:
#line	198	"a.y"
{
		yyval.gen2.from = yypt[-2].yyv.gen;
		yyval.gen2.to = yypt[-0].yyv.gen;
	} break;
case 46:
#line	203	"a.y"
{
		yyval.gen2.from = yypt[-4].yyv.gen;
		yyval.gen2.to = yypt[-2].yyv.gen;
		if(yyval.gen2.to.index != D_NONE)
			yyerror("dp move with lhs index");
		yyval.gen2.to.index = yypt[-0].yyv.lval;
	} break;
case 47:
#line	213	"a.y"
{
		yyval.gen2.from = yypt[-1].yyv.gen;
		yyval.gen2.to = nullgen;
	} break;
case 48:
#line	218	"a.y"
{
		yyval.gen2.from = yypt[-0].yyv.gen;
		yyval.gen2.to = nullgen;
	} break;
case 49:
#line	223	"a.y"
{
		yyval.gen2.from = yypt[-2].yyv.gen;
		yyval.gen2.to = yypt[-0].yyv.gen;
	} break;
case 50:
#line	230	"a.y"
{
		yyval.gen2.from = yypt[-2].yyv.gen;
		yyval.gen2.to = yypt[-0].yyv.gen;
	} break;
case 51:
#line	235	"a.y"
{
		yyval.gen2.from = yypt[-4].yyv.gen;
		yyval.gen2.from.scale = yypt[-2].yyv.lval;
		yyval.gen2.to = yypt[-0].yyv.gen;
	} break;
case 56:
#line	249	"a.y"
{
		yyval.gen = yypt[-0].yyv.gen;
	} break;
case 57:
#line	253	"a.y"
{
		yyval.gen = yypt[-0].yyv.gen;
	} break;
case 63:
#line	266	"a.y"
{
		yyval.gen = nullgen;
		yyval.gen.type = D_BRANCH;
		yyval.gen.offset = yypt[-3].yyv.lval + pc;
	} break;
case 64:
#line	272	"a.y"
{
		yyval.gen = nullgen;
		if(pass == 2)
			yyerror("undefined label: %s", yypt[-1].yyv.sym->name);
		yyval.gen.type = D_BRANCH;
		yyval.gen.sym = yypt[-1].yyv.sym;
		yyval.gen.offset = yypt[-0].yyv.lval;
	} break;
case 65:
#line	281	"a.y"
{
		yyval.gen = nullgen;
		yyval.gen.type = D_BRANCH;
		yyval.gen.sym = yypt[-1].yyv.sym;
		yyval.gen.offset = yypt[-1].yyv.sym->value + yypt[-0].yyv.lval;
	} break;
case 66:
#line	290	"a.y"
{
		yyval.gen = nullgen;
		yyval.gen.type = yypt[-0].yyv.lval;
	} break;
case 67:
#line	295	"a.y"
{
		yyval.gen = nullgen;
		yyval.gen.type = yypt[-0].yyv.lval;
	} break;
case 68:
#line	300	"a.y"
{
		yyval.gen = nullgen;
		yyval.gen.type = yypt[-0].yyv.lval;
	} break;
case 69:
#line	305	"a.y"
{
		yyval.gen = nullgen;
		yyval.gen.type = D_SP;
	} break;
case 70:
#line	310	"a.y"
{
		yyval.gen = nullgen;
		yyval.gen.type = yypt[-0].yyv.lval;
	} break;
case 71:
#line	317	"a.y"
{
		yyval.gen = nullgen;
		yyval.gen.type = D_CONST;
		yyval.gen.offset = yypt[-0].yyv.lval;
	} break;
case 72:
#line	323	"a.y"
{
		yyval.gen = yypt[-0].yyv.gen;
		yyval.gen.index = yypt[-0].yyv.gen.type;
		yyval.gen.type = D_ADDR;
		/*
		if($2.type == D_AUTO || $2.type == D_PARAM)
			yyerror("constant cannot be automatic: %s",
				$2.sym->name);
		 */
	} break;
case 73:
#line	334	"a.y"
{
		yyval.gen = nullgen;
		yyval.gen.type = D_SCONST;
		memcpy(yyval.gen.sval, yypt[-0].yyv.sval, sizeof(yyval.gen.sval));
	} break;
case 74:
#line	340	"a.y"
{
		yyval.gen = nullgen;
		yyval.gen.type = D_FCONST;
		yyval.gen.dval = yypt[-0].yyv.dval;
	} break;
case 75:
#line	346	"a.y"
{
		yyval.gen = nullgen;
		yyval.gen.type = D_FCONST;
		yyval.gen.dval = yypt[-1].yyv.dval;
	} break;
case 76:
#line	352	"a.y"
{
		yyval.gen = nullgen;
		yyval.gen.type = D_FCONST;
		yyval.gen.dval = -yypt[-0].yyv.dval;
	} break;
case 77:
#line	360	"a.y"
{
		yyval.gen = nullgen;
		yyval.gen.type = D_CONST2;
		yyval.gen.offset = yypt[-0].yyv.con2.v1;
		yyval.gen.offset2 = yypt[-0].yyv.con2.v2;
	} break;
case 78:
#line	369	"a.y"
{
		yyval.con2.v1 = yypt[-0].yyv.lval;
		yyval.con2.v2 = 0;
	} break;
case 79:
#line	374	"a.y"
{
		yyval.con2.v1 = -yypt[-0].yyv.lval;
		yyval.con2.v2 = 0;
	} break;
case 80:
#line	379	"a.y"
{
		yyval.con2.v1 = yypt[-2].yyv.lval;
		yyval.con2.v2 = yypt[-0].yyv.lval;
	} break;
case 81:
#line	384	"a.y"
{
		yyval.con2.v1 = -yypt[-2].yyv.lval;
		yyval.con2.v2 = yypt[-0].yyv.lval;
	} break;
case 84:
#line	395	"a.y"
{
		yyval.gen = nullgen;
		yyval.gen.type = D_INDIR+D_NONE;
		yyval.gen.offset = yypt[-0].yyv.lval;
	} break;
case 85:
#line	401	"a.y"
{
		yyval.gen = nullgen;
		yyval.gen.type = D_INDIR+yypt[-1].yyv.lval;
		yyval.gen.offset = yypt[-3].yyv.lval;
	} break;
case 86:
#line	407	"a.y"
{
		yyval.gen = nullgen;
		yyval.gen.type = D_INDIR+D_SP;
		yyval.gen.offset = yypt[-3].yyv.lval;
	} break;
case 87:
#line	413	"a.y"
{
		yyval.gen = nullgen;
		yyval.gen.type = D_INDIR+D_NONE;
		yyval.gen.offset = yypt[-5].yyv.lval;
		yyval.gen.index = yypt[-3].yyv.lval;
		yyval.gen.scale = yypt[-1].yyv.lval;
		checkscale(yyval.gen.scale);
	} break;
case 88:
#line	422	"a.y"
{
		yyval.gen = nullgen;
		yyval.gen.type = D_INDIR+yypt[-6].yyv.lval;
		yyval.gen.offset = yypt[-8].yyv.lval;
		yyval.gen.index = yypt[-3].yyv.lval;
		yyval.gen.scale = yypt[-1].yyv.lval;
		checkscale(yyval.gen.scale);
	} break;
case 89:
#line	431	"a.y"
{
		yyval.gen = nullgen;
		yyval.gen.type = D_INDIR+yypt[-1].yyv.lval;
	} break;
case 90:
#line	436	"a.y"
{
		yyval.gen = nullgen;
		yyval.gen.type = D_INDIR+D_SP;
	} break;
case 91:
#line	441	"a.y"
{
		yyval.gen = nullgen;
		yyval.gen.type = D_INDIR+yypt[-1].yyv.lval;
		yyval.gen.offset = yypt[-3].yyv.lval;
	} break;
case 92:
#line	447	"a.y"
{
		yyval.gen = nullgen;
		yyval.gen.type = D_INDIR+D_NONE;
		yyval.gen.index = yypt[-3].yyv.lval;
		yyval.gen.scale = yypt[-1].yyv.lval;
		checkscale(yyval.gen.scale);
	} break;
case 93:
#line	455	"a.y"
{
		yyval.gen = nullgen;
		yyval.gen.type = D_INDIR+yypt[-6].yyv.lval;
		yyval.gen.index = yypt[-3].yyv.lval;
		yyval.gen.scale = yypt[-1].yyv.lval;
		checkscale(yyval.gen.scale);
	} break;
case 94:
#line	465	"a.y"
{
		yyval.gen = yypt[-0].yyv.gen;
	} break;
case 95:
#line	469	"a.y"
{
		yyval.gen = yypt[-5].yyv.gen;
		yyval.gen.index = yypt[-3].yyv.lval;
		yyval.gen.scale = yypt[-1].yyv.lval;
		checkscale(yyval.gen.scale);
	} break;
case 96:
#line	478	"a.y"
{
		yyval.gen = nullgen;
		yyval.gen.type = yypt[-1].yyv.lval;
		yyval.gen.sym = yypt[-4].yyv.sym;
		yyval.gen.offset = yypt[-3].yyv.lval;
	} break;
case 97:
#line	485	"a.y"
{
		yyval.gen = nullgen;
		yyval.gen.type = D_STATIC;
		yyval.gen.sym = yypt[-6].yyv.sym;
		yyval.gen.offset = yypt[-3].yyv.lval;
	} break;
case 98:
#line	493	"a.y"
{
		yyval.lval = 0;
	} break;
case 99:
#line	497	"a.y"
{
		yyval.lval = yypt[-0].yyv.lval;
	} break;
case 100:
#line	501	"a.y"
{
		yyval.lval = -yypt[-0].yyv.lval;
	} break;
case 102:
#line	508	"a.y"
{
		yyval.lval = D_AUTO;
	} break;
case 105:
#line	516	"a.y"
{
		yyval.lval = yypt[-0].yyv.sym->value;
	} break;
case 106:
#line	520	"a.y"
{
		yyval.lval = -yypt[-0].yyv.lval;
	} break;
case 107:
#line	524	"a.y"
{
		yyval.lval = yypt[-0].yyv.lval;
	} break;
case 108:
#line	528	"a.y"
{
		yyval.lval = ~yypt[-0].yyv.lval;
	} break;
case 109:
#line	532	"a.y"
{
		yyval.lval = yypt[-1].yyv.lval;
	} break;
case 111:
#line	539	"a.y"
{
		yyval.lval = yypt[-2].yyv.lval + yypt[-0].yyv.lval;
	} break;
case 112:
#line	543	"a.y"
{
		yyval.lval = yypt[-2].yyv.lval - yypt[-0].yyv.lval;
	} break;
case 113:
#line	547	"a.y"
{
		yyval.lval = yypt[-2].yyv.lval * yypt[-0].yyv.lval;
	} break;
case 114:
#line	551	"a.y"
{
		yyval.lval = yypt[-2].yyv.lval / yypt[-0].yyv.lval;
	} break;
case 115:
#line	555	"a.y"
{
		yyval.lval = yypt[-2].yyv.lval % yypt[-0].yyv.lval;
	} break;
case 116:
#line	559	"a.y"
{
		yyval.lval = yypt[-3].yyv.lval << yypt[-0].yyv.lval;
	} break;
case 117:
#line	563	"a.y"
{
		yyval.lval = yypt[-3].yyv.lval >> yypt[-0].yyv.lval;
	} break;
case 118:
#line	567	"a.y"
{
		yyval.lval = yypt[-2].yyv.lval & yypt[-0].yyv.lval;
	} break;
case 119:
#line	571	"a.y"
{
		yyval.lval = yypt[-2].yyv.lval ^ yypt[-0].yyv.lval;
	} break;
case 120:
#line	575	"a.y"
{
		yyval.lval = yypt[-2].yyv.lval | yypt[-0].yyv.lval;
	} break;
	}
	goto yystack;  /* stack new state and value */
}
Beispiel #18
0
static int _ggi_clip2d_3(ggi_visual *vis,
			     int *_x0, int *_y0,
			     int *_x1, int *_y1,
			     int *clip_first, int *clip_last)
{
	int first,last, code;
	int x0,y0,x1,y1;
	int x,y;
	unsigned dx[3], dy[3], tmp[3];
	unsigned int absdx, absdy;
	int xmajor;
	int slope;
	int i;

	*clip_first = first = 0;
	*clip_last = last = 0;
	outcode(first,*_x0,*_y0);
	outcode(last,*_x1,*_y1);

	if ((first | last) == 0) {
		return 1; /* Trivially accepted! */
	}
	if ((first & last) != 0) {
		return 0; /* Trivially rejected! */
	}

	x0=*_x0; y0=*_y0;
	x1=*_x1; y1=*_y1;
	
	assign_int_3(dx, x1);
	assign_int_3(tmp, x0);
	sub_3(dx, tmp);

	assign_int_3(dy, y1);
	assign_int_3(tmp, y0);
	sub_3(dy, tmp);

	absdx = x0 < x1 ? x1 - x0 : x0 - x1;
	absdy = y0 < y1 ? y1 - y0 : y0 - y1;
	xmajor = absdx > absdy;
	slope = ((x1>=x0) && (y1>=y0)) || ((x1<x0) && (y1<y0));

	for (i = 0; i < 4; i++) {
		code = first;
		if (first==0)
			code = last;

		if (code&OC_LEFT) {
			x = LIBGGI_GC(vis)->cliptl.x;
			if (xmajor) {
				/* y = *_y0 + FloorDiv(dy*(x - *_x0)*2 + dx,
							2*dx); */
				unsigned _x[3], res[3];
				assign_int_3(_x, x);
				assign_int_3(tmp, *_x0);
				sub_3(_x, tmp);
				lshift_3(_x, 1);
				mul_3(_x, dy);
				add_3(_x, dx);
				assign_3(tmp, dx);
				lshift_3(tmp, 1);
				FloorDiv_3(res, _x, tmp);
				assign_int_3(tmp, *_y0);
				add_3(res, tmp);
				y = res[0];
			} else if (slope) {
				/* y = *_y0 + CeilDiv(dy*((x - *_x0)*2 - 1),
							2*dx); */
				unsigned _x[3], res[3];
				assign_int_3(_x, x);
				assign_int_3(tmp, *_x0);
				sub_3(_x, tmp);
				lshift_3(_x, 1);
				dec_3(_x);
				mul_3(_x, dy);
				assign_3(tmp, dx);
				lshift_3(tmp, 1);
				CeilDiv_3(res, _x, tmp);
				assign_int_3(tmp, *_y0);
				add_3(res, tmp);
				y = res[0];
			} else {
				/* y = *_y0 + FloorDiv(dy*((x - *_x0)*2 - 1),
							2*dx); */
				unsigned _x[3], res[3];
				assign_int_3(_x, x);
				assign_int_3(tmp, *_x0);
				sub_3(_x, tmp);
				lshift_3(_x, 1);
				dec_3(_x);
				mul_3(_x, dy);
				assign_3(tmp, dx);
				lshift_3(tmp, 1);
				FloorDiv_3(res, _x, tmp);
				assign_int_3(tmp, *_y0);
				add_3(res, tmp);
				y = res[0];
			}
		} else if (code&OC_RIGHT) {
			x = LIBGGI_GC(vis)->clipbr.x - 1;
			if (xmajor) {
				/* y = *_y0 + FloorDiv(dy*(x - *_x0)*2 + dx,
							2*dx); */
				unsigned _x[3], res[3];
				assign_int_3(_x, x);
				assign_int_3(tmp, *_x0);
				sub_3(_x, tmp);
				lshift_3(_x, 1);
				mul_3(_x, dy);
				add_3(_x, dx);
				assign_3(tmp, dx);
				lshift_3(tmp, 1);
				FloorDiv_3(res, _x, tmp);
				assign_int_3(tmp, *_y0);
				add_3(res, tmp);
				y = res[0];
			} else if (slope) {
				/* y = *_y0 + CeilDiv(dy*((x - *_x0)*2 + 1),
							2*dx)-1; */
				unsigned _x[3], res[3];
				assign_int_3(_x, x);
				assign_int_3(tmp, *_x0);
				sub_3(_x, tmp);
				lshift_3(_x, 1);
				inc_3(_x);
				mul_3(_x, dy);
				assign_3(tmp, dx);
				lshift_3(tmp, 1);
				CeilDiv_3(res, _x, tmp);
				dec_3(res);
				assign_int_3(tmp, *_y0);
				add_3(res, tmp);
				y = res[0];
			} else {
				/* y = *_y0 + FloorDiv(dy*((x - *_x0)*2 + 1),
							2*dx)+1; */
				unsigned _x[3], res[3];
				assign_int_3(_x, x);
				assign_int_3(tmp, *_x0);
				sub_3(_x, tmp);
				lshift_3(_x, 1);
				inc_3(_x);
				mul_3(_x, dy);
				assign_3(tmp, dx);
				lshift_3(tmp, 1);
				FloorDiv_3(res, _x, tmp);
				inc_3(res);
				assign_int_3(tmp, *_y0);
				add_3(res, tmp);
				y = res[0];
			}
		} else if (code&OC_TOP) {
			y = LIBGGI_GC(vis)->cliptl.y;
			if (!xmajor) {
				/* x = *_x0 + FloorDiv(dx*(y - *_y0)*2 + dy,
							2*dy); */
				unsigned _y[3], res[3];
				assign_int_3(_y, y);
				assign_int_3(tmp, *_y0);
				sub_3(_y, tmp);
				lshift_3(_y, 1);
				mul_3(_y, dx);
				add_3(_y, dy);
				assign_3(tmp, dy);
				lshift_3(tmp, 1);
				FloorDiv_3(res, _y, tmp);
				assign_int_3(tmp, *_x0);
				add_3(res, tmp);
				x = res[0];
			} else if (slope) {
				/* x = *_x0 + CeilDiv(dx*((y - *_y0)*2 - 1),
							2*dy); */
				unsigned _y[3], res[3];
				assign_int_3(_y, y);
				assign_int_3(tmp, *_y0);
				sub_3(_y, tmp);
				lshift_3(_y, 1);
				dec_3(_y);
				mul_3(_y, dx);
				assign_3(tmp, dy);
				lshift_3(tmp, 1);
				CeilDiv_3(res, _y, tmp);
				assign_int_3(tmp, *_x0);
				add_3(res, tmp);
				x = res[0];
			} else {
				/* x = *_x0 + FloorDiv(dx*((y - *_y0)*2 - 1),
							2*dy); */
				unsigned _y[3], res[3];
				assign_int_3(_y, y);
				assign_int_3(tmp, *_y0);
				sub_3(_y, tmp);
				lshift_3(_y, 1);
				dec_3(_y);
				mul_3(_y, dx);
				assign_3(tmp, dy);
				lshift_3(tmp, 1);
				FloorDiv_3(res, _y, tmp);
				assign_int_3(tmp, *_x0);
				add_3(res, tmp);
				x = res[0];
			}
		} else { /* OC_BOTTOM */
			LIB_ASSERT((code & OC_BOTTOM), "unknown outcode\n");
			y = LIBGGI_GC(vis)->clipbr.y - 1;
			if (!xmajor) {
				/* x = *_x0 + FloorDiv(dx*(y - *_y0)*2 + dy,
							2*dy); */
				unsigned _y[3], res[3];
				assign_int_3(_y, y);
				assign_int_3(tmp, *_y0);
				sub_3(_y, tmp);
				lshift_3(_y, 1);
				mul_3(_y, dx);
				add_3(_y, dy);
				assign_3(tmp, dy);
				lshift_3(tmp, 1);
				FloorDiv_3(res, _y, tmp);
				assign_int_3(tmp, *_x0);
				add_3(res, tmp);
				x = res[0];
			} else if (slope) {
				/* x = *_x0 + CeilDiv(dx*((y - *_y0)*2 + 1),
							2*dy)-1; */
				unsigned _y[3], res[3];
				assign_int_3(_y, y);
				assign_int_3(tmp, *_y0);
				sub_3(_y, tmp);
				lshift_3(_y, 1);
				inc_3(_y);
				mul_3(_y, dx);
				assign_3(tmp, dy);
				lshift_3(tmp, 1);
				CeilDiv_3(res, _y, tmp);
				dec_3(res);
				assign_int_3(tmp, *_x0);
				add_3(res, tmp);
				x = res[0];
			} else {
				/* x = *_x0 + FloorDiv(dx*((y - *_y0)*2 + 1),
							2*dy)+1; */
				unsigned _y[3], res[3];
				assign_int_3(_y, y);
				assign_int_3(tmp, *_y0);
				sub_3(_y, tmp);
				lshift_3(_y, 1);
				inc_3(_y);
				mul_3(_y, dx);
				assign_3(tmp, dy);
				lshift_3(tmp, 1);
				FloorDiv_3(res, _y, tmp);
				inc_3(res);
				assign_int_3(tmp, *_x0);
				add_3(res, tmp);
				x = res[0];
			}
		}

		if (first!=0) {
			x0 = x;
			y0 = y;
			outcode(first,x0,y0);
			*clip_first = 1;
		} else {
			x1 = x;
			y1 = y;
			last = code;
			outcode(last,x1,y1);
			*clip_last = 1;
		}

		if ((first & last) != 0) {
			return 0; /* Trivially rejected! */
		}
		if ((first | last) == 0) {
			*_x0=x0; *_y0=y0;
			*_x1=x1; *_y1=y1;
			return 1; /* Trivially accepted! */
		}
	}
	return 0; /* Aieee! Failed to clip, clip whole line... */
}
int cs_clipline(PSD psd,int *_x0, int *_y0, int *_x1, int *_y1,
                int *clip_first, int *clip_last)
{
    int first,last, code;
    int x0,y0,x1,y1;
    int x,y;
    int dx,dy;
    int xmajor;
    int slope;

    int tempclipminx,tempclipminy,tempclipmaxx,tempclipmaxy;
    if (psd->doclip) {
        tempclipminx = psd->clipminx;
        tempclipminy = psd->clipminy;
        tempclipmaxx = psd->clipmaxx;
        tempclipmaxy = psd->clipmaxy;
    } else {
        tempclipminx = 0;
        tempclipminy = 0;
        tempclipmaxx = psd->xres - 1;
        tempclipmaxy = psd->yres - 1;
    }

    first = 0;
    last = 0;
    outcode(first,*_x0,*_y0);
    outcode(last,*_x1,*_y1);

    if ((first | last) == 0) {
        return CLIP_VISIBLE; /* Trivially accepted! */
    }
    if ((first & last) != 0) {
        return CLIP_INVISIBLE; /* Trivially rejected! */
    }

    x0=*_x0;
    y0=*_y0;
    x1=*_x1;
    y1=*_y1;

    dx = x1 - x0;
    dy = y1 - y0;

    xmajor = (abs(dx) > abs(dy));
    slope = ((dx>=0) && (dy>=0)) || ((dx<0) && (dy<0));

    for (;;) {
        code = first;
        if (first==0)
            code = last;

        if (code&OC_LEFT) {
            x = tempclipminx;
            if (xmajor) {
                y = *_y0 +  FloorDiv(dy*(x - *_x0)*2 + dx,
                                     2*dx);
            } else {
                if (slope) {
                    y = *_y0 + CeilDiv(dy*((x - *_x0)*2
                                           - 1), 2*dx);
                } else {
                    y = *_y0 + FloorDiv(dy*((x - *_x0)*2
                                            - 1), 2*dx);
                }
            }
        } else if (code&OC_RIGHT) {
            x = tempclipmaxx;
            if (xmajor) {
                y = *_y0 +  FloorDiv(dy*(x - *_x0)*2 + dx, 2*dx);
            } else {
                if (slope) {
                    y = *_y0 + CeilDiv(dy*((x - *_x0)*2
                                           + 1), 2*dx)-1;
                } else {
                    y = *_y0 + FloorDiv(dy*((x - *_x0)*2
                                            + 1), 2*dx)+1;
                }
            }
        } else if (code&OC_TOP) {
            y = tempclipminy;
            if (xmajor) {
                if (slope) {
                    x = *_x0 + CeilDiv(dx*((y - *_y0)*2
                                           - 1), 2*dy);
                } else {
                    x = *_x0 + FloorDiv(dx*((y - *_y0)*2
                                            - 1), 2*dy);
                }
            } else {
                x = *_x0 +  FloorDiv( dx*(y - *_y0)*2 + dy,
                                      2*dy);
            }
        } else { /* OC_BOTTOM */
            y = tempclipmaxy;
            if (xmajor) {
                if (slope) {
                    x = *_x0 + CeilDiv(dx*((y - *_y0)*2
                                           + 1), 2*dy)-1;
                } else {
                    x = *_x0 + FloorDiv(dx*((y - *_y0)*2
                                            + 1), 2*dy)+1;
                }
            } else {
                x = *_x0 +  FloorDiv(dx*(y - *_y0)*2 + dy,
                                     2*dy);
            }
        }

        if (first!=0) {
            x0 = x;
            y0 = y;
            outcode(first,x0,y0);
            *clip_first = 1;
        } else {
            x1 = x;
            y1 = y;
            last = code;
            outcode(last,x1,y1);
            *clip_last = 1;
        }

        if ((first & last) != 0) {
            return CLIP_INVISIBLE; /* Trivially rejected! */
        }
        if ((first | last) == 0) {
            *_x0=x0;
            *_y0=y0;
            *_x1=x1;
            *_y1=y1;
            return CLIP_PARTIAL; /* Trivially accepted! */
        }
    }
}
Beispiel #20
0
static int _ggi_clip2d(ggi_visual *vis,int *_x0, int *_y0, int *_x1, int *_y1,
		       int *clip_first, int *clip_last)
{
	int first,last, code;
	int x0,y0,x1,y1;
	int x,y;
	int dx,dy;
	unsigned int absdx, absdy;
	int xmajor;
	int slope;
	int i;

	*clip_first = first = 0;
	*clip_last = last = 0;
	outcode(first,*_x0,*_y0);
	outcode(last,*_x1,*_y1);

	if ((first | last) == 0) {
		return 1; /* Trivially accepted! */
	}
	if ((first & last) != 0) {
		return 0; /* Trivially rejected! */
	}

	x0=*_x0; y0=*_y0;
	x1=*_x1; y1=*_y1;

	dx = x1 - x0;
	dy = y1 - y0;

	absdx = x0 < x1 ? x1 - x0 : x0 - x1;
	absdy = y0 < y1 ? y1 - y0 : y0 - y1;
	xmajor = absdx > absdy;
	slope = ((x1>=x0) && (y1>=y0)) || ((x1<x0) && (y1<y0));

	if ((absdx > MAX_DIFF) || (absdy > MAX_DIFF)) {
		return _ggi_clip2d_3(vis, _x0, _y0, _x1, _y1,
			clip_first, clip_last);
	}

	for (i = 0; i < 4; i++) {
		code = first;
		if (first==0)
			code = last;

		if (code&OC_LEFT) {
			x = LIBGGI_GC(vis)->cliptl.x;
			if (xmajor) {
				y = *_y0 +  FloorDiv(dy*(x - *_x0)*2 + dx,
						      2*dx);
			} else {
				if (slope) {
					y = *_y0 + CeilDiv(dy*((x - *_x0)*2
							       - 1), 2*dx);
				} else {
					y = *_y0 + FloorDiv(dy*((x - *_x0)*2
								- 1), 2*dx);
				}
			}
		} else if (code&OC_RIGHT) {
			x = LIBGGI_GC(vis)->clipbr.x - 1;
			if (xmajor) {
				y = *_y0 +  FloorDiv(dy*(x - *_x0)*2 + dx, 2*dx);
			} else {
				if (slope) {
					y = *_y0 + CeilDiv(dy*((x - *_x0)*2
							       + 1), 2*dx)-1;
				} else {
					y = *_y0 + FloorDiv(dy*((x - *_x0)*2
								+ 1), 2*dx)+1;
				}
			}
		} else if (code&OC_TOP) {
			y = LIBGGI_GC(vis)->cliptl.y;
			if (xmajor) {
				if (slope) {
					x = *_x0 + CeilDiv(dx*((y - *_y0)*2
							       - 1), 2*dy);
				} else {
					x = *_x0 + FloorDiv(dx*((y - *_y0)*2
								- 1), 2*dy);
				}
			} else {
				x = *_x0 +  FloorDiv( dx*(y - *_y0)*2 + dy,
						      2*dy);
			}
		} else { /* OC_BOTTOM */
			LIB_ASSERT((code & OC_BOTTOM), "unknown outcode\n");
			y = LIBGGI_GC(vis)->clipbr.y - 1;
			if (xmajor) {
				if (slope) {
					x = *_x0 + CeilDiv(dx*((y - *_y0)*2
							       + 1), 2*dy)-1;
				} else {
					x = *_x0 + FloorDiv(dx*((y - *_y0)*2
								+ 1), 2*dy)+1;
				}
			} else {
				x = *_x0 +  FloorDiv(dx*(y - *_y0)*2 + dy,
						     2*dy);
			}
		}

		if (first!=0) {
			x0 = x;
			y0 = y;
			outcode(first,x0,y0);
			*clip_first = 1;
		} else {
			x1 = x;
			y1 = y;
			last = code;
			outcode(last,x1,y1);
			*clip_last = 1;
		}

		if ((first & last) != 0) {
			return 0; /* Trivially rejected! */
		}
		if ((first | last) == 0) {
			*_x0=x0; *_y0=y0;
			*_x1=x1; *_y1=y1;
			return 1; /* Trivially accepted! */
		}
	}
	return 0; /* Aieee! Failed to clip, clip whole line... */
}