|
|
1.1 root 1: #include <stdio.h>
2: #include "pico.h"
3: #include "pico2.h"
4: #include "y.tab.h"
5:
6: extern struct SRC src[MANY];
7: extern short CURSCRATCH, CUROLD;
8: extern char faster, frameb, metheus;
9: extern int DEF_LL, DEF_NL;
10:
11: #define NNODE 8000
12:
13: Node nodearray[NNODE];
14: int nalloc=0;
15:
16: Node *
17: Index(k)
18: Node *k;
19: {
20: switch(k->type) {
21: case ACOMMA: if (commacount(k) == 2)
22: return
23: new(OADD, new(OMUL, k->right, VR(&DEF_LL), Z), k->left, Z);
24: break;
25: case COMP: return new(ODIV, sumchans(k->left), NR(3), Z);
26: }
27: return k;
28: }
29:
30: Node *
31: ncopy(n)
32: Node *n;
33: {
34: if (n == Z)
35: return n;
36:
37: n = new(n->type, ncopy(n->left), ncopy(n->right), n->other);
38:
39: if (n->type == CONDI)
40: n->other = ncopy(n->other);
41:
42: return n;
43: }
44:
45: int spare;
46:
47: Node *
48: modulo(p, q)
49: Node *p, *q;
50: { Node *tmp1, *tmp2;
51:
52: if (p->type == OCOMMA || p->type == ACOMMA)
53: yyerror("lefthand-side of modulo is a composite");
54:
55: tmp1 = new(OASS, VR(&spare), ncopy(p), Z);
56: tmp2 = new(OSUB, VR(&spare),
57: new(OMUL, new(ODIV, VR(&spare), ncopy(q), Z), ncopy(q), Z), Z);
58:
59: return new(OCOMMA, tmp1, new(CONDI, tmp2, VR(&spare), q), Z);
60: }
61:
62: Node *
63: divide(p, q)
64: Node *p, *q;
65: { Node *tmp = ncopy(q);
66: extern Node zero;
67: return new(CONDI, new(ODIV, p, q, Z), &zero, tmp);
68: }
69:
70: int fixspot;
71: /* encodes the assignment of a composite to a composite */
72: Node *
73: fixit(n, m)
74: Node *n, *m;
75: { Node *tmp1 = new(OASS, VR(&fixspot), ncopy(m), Z);
76:
77: Node *tmp2 = ncopy(n->left->left); /* r */
78: Node *tmp3 = ncopy(n->left->right->left); /* g */
79: Node *tmp4 = ncopy(n->left->right->right); /* b */
80:
81: Node *low = new(OAND, VR(&fixspot), NR(255), Z);
82: Node *med = new(OLSH, notnew(OAND, VR(&fixspot), NR(255<<8)),
83: new(OMINUS, NR(8), Z, Z), Z);
84: Node *hig = new(OLSH, VR(&fixspot),
85: new(OMINUS, NR(16), Z, Z), Z);
86:
87: Node *tmp5 = new(OASS, tmp2, low, Z);
88: Node *tmp6 = new(OASS, tmp3, med, Z);
89: Node *tmp7 = new(OASS, tmp4, hig, Z);
90:
91: Node *tmp8 = new(OCOMMA, tmp5, tmp6, Z);
92: Node *tmp9 = new(OCOMMA, tmp7, tmp8, Z);
93:
94: return new(OCOMMA, tmp1, tmp9, Z);
95: }
96:
97: Node *
98: catch(what, n, m)
99: int what;
100: Node *n, *m;
101: {
102: switch (what)
103: {
104: case DIVV: return divide(n, m);
105: case MODU: return modulo(n, m);
106: case OASS: if (n->type == COMP)
107: { if (m->type == CONDI)
108: return fixit(n, m);
109: else
110: return new(OCOMMA, par(what, n->left, m->left), Z, Z);
111: }
112: default: return new(what, n, m, Z);
113: }
114: }
115:
116: Node *
117: new(type, left, right, oth)
118: Node *left, *right, *oth;
119: {
120: register Node *n;
121:
122: if (nalloc >= NNODE)
123: yyerror("NNODE too small; recompile pico");
124: n = nodearray+nalloc++;
125: n->type = type;
126: n->left = left;
127: n->right = right;
128: n->other = oth;
129:
130: return n;
131: }
132:
133: Node *
134: sumchans(n)
135: Node *n;
136: {
137: if (n == Z || n->type != ACOMMA)
138: return n;
139: return new(OADD, sumchans(n->left), sumchans(n->right), Z);
140: }
141:
142: Node *
143: cast(n)
144: Node *n;
145: {
146: if (n == Z || n->type != ACOMMA)
147: return n;
148:
149: return new(ODIV, sumchans(n->left), NR(3), Z);
150: }
151:
152: #define Par(side) par(what, n1->side, n2->side)
153:
154: Node *
155: par(what, n1, n2)
156: int what;
157: Node *n1, *n2;
158: {
159: if (n1 == Z || n2 == Z)
160: return Z;
161:
162: if (n1->type != ACOMMA || n2->type != ACOMMA)
163: return catch(what, ncopy(n1), ncopy(n2));
164:
165: if (what == OASS)
166: return new(OCOMMA, Par(left), Par(right), Z);
167: else
168: return new(ACOMMA, Par(left), Par(right), Z);
169: }
170:
171: Node *
172: promote(m)
173: Node *m;
174: {
175: Node *n;
176:
177: if (m->type == CONDI)
178: return new(CONDI, promote(m->left), promote(m->right), m->other);
179: if (m->type == COMP)
180: return m;
181: n = new(ACOMMA, ncopy(m), ncopy(m), Z);
182: n = new(ACOMMA, ncopy(m), n, Z);
183:
184: return new(COMP, n, Z, Z);
185: }
186:
187: Node *
188: disp(what, n, e)
189: int what;
190: Node *n, *e;
191: {
192: if (n == Z)
193: return Z;
194:
195: if (n->type != ACOMMA)
196: return catch(what, ncopy(n), ncopy(e));
197:
198: return new(OCOMMA, disp(what, n->left, e), disp(what, n->right, e), Z);
199: }
200:
201: Node *
202: notnew(what, n1, n2)
203: int what;
204: Node *n1, *n2;
205: {
206: int how = 0;
207:
208: if (n1->type == COMP) how += 1;
209: if (n2->type == COMP) how += 2;
210:
211: switch (how) {
212: case 1: n2 = promote(n2); /* fall through */
213: case 0: return catch(what, n1, n2);
214: case 2: if (what == OASS)
215: return catch(what, n1, new(ODIV, sumchans(n2->left), NR(3), Z));
216: n1 = promote(n1); /* fall through */
217: case 3: if (what == OASS)
218: return catch(what, n1, n2); /* else: */
219: return new(COMP, par(what, n1->left, n2->left), Z, Z);
220: }
221: }
222:
223: Node *
224: threechans(q, r)
225: struct SRC *q;
226: Node *r;
227: {
228: Node *n;
229:
230: if (q->nchan >= 3)
231: { n = new(ACOMMA, DOLGRN(q, r), DOLBLU(q, r), Z);
232: n = new(ACOMMA, DOLRED(q, r), n, Z);
233: return new(COMP, n, Z, Z);
234: } else
235: return DOLRED(q, r);
236: }
237:
238: SNode *
239: nsup(n, x, y, i)
240: Node *n, *x, *y;
241: char i;
242: {
243: SNode *tmp;
244:
245: tmp = (SNode *) Emalloc(sizeof(SNode));
246: tmp->n = n;
247: tmp->x = x;
248: tmp->y = y;
249: tmp->i = i;
250:
251: return tmp;
252: }
253:
254: Node *
255: splatter(n)
256: SNode *n;
257: {
258: extern int ramlyank(), fblyank(), metlyank();
259:
260: if (metheus)
261: return new(CCALL, new(ACOMMA, n->x, n->y, Z), Z, metlyank);
262: else if (frameb)
263: return new(CCALL, new(ACOMMA, n->x, n->y, Z), Z, fblyank);
264: }
265:
266: Node *
267: weird(n, m)
268: SNode *n;
269: Node *m;
270: {
271: Node *tmp;
272:
273: if (m == Z)
274: return n->n;
275:
276: tmp = notnew(OASS, n->n, m);
277: if (n->i != CURSCRATCH
278: || (!frameb && !metheus)
279: || (faster && notafunc() && metheus)
280: || (faster && Old->nchan==1 && notafunc() && frameb))
281: return tmp;
282: else
283: return new(OCOMMA, tmp, splatter(n), Z);
284: }
285:
286: Node *
287: getx(n)
288: Node *n;
289: {
290: if (n == Z)
291: return AREG(XREG);
292: if (n->type == ACOMMA)
293: { if (commacount(n) == 2)
294: return n->left;
295: else
296: yyerror("bad index");
297: }
298: return modulo(n, VR(&DEF_LL));
299: }
300:
301: Node *
302: gety(n)
303: Node *n;
304: {
305: if (n == Z)
306: return AREG(YREG);
307: if (n->type == ACOMMA)
308: { if (commacount(n) == 2)
309: return n->right;
310: else
311: yyerror("bad index");
312: }
313: return divide(n, VR(&DEF_LL));
314: }
315:
316: SNode *
317: super(a, b, t)
318: Node *b;
319: {
320: Node *tmp;
321: Node *n = (b == Z)? DII: Index(b);
322:
323: switch (t) {
324: case RGB: tmp = threechans(&src[a], n); break;
325: case BW: if (src[a].nchan == 1)
326: tmp = DOLRED((&src[a]), n);
327: else
328: tmp = cast(threechans(&src[a], n));
329: break;
330: case RCHAN: tmp = DOLRED((&src[a]), n); break;
331: case GCHAN: tmp = DOLGRN((&src[a]), n); break;
332: case BCHAN: tmp = DOLBLU((&src[a]), n); break;
333: }
334:
335: if (b == Z)
336: return nsup(tmp, AREG(XREG), AREG(YREG), a);
337: else
338: return nsup(tmp, getx(b), gety(b), a);
339: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.