1
2 /*
3 # Sfront, a SAOL to C translator
4 # This file: Variable declarations for core opcodes
5 #
6 # Copyright (c) 1999-2006, Regents of the University of California
7 # All rights reserved.
8 #
9 # Redistribution and use in source and binary forms, with or without
10 # modification, are permitted provided that the following conditions are
11 # met:
12 #
13 # Redistributions of source code must retain the above copyright
14 # notice, this list of conditions and the following disclaimer.
15 #
16 # Redistributions in binary form must reproduce the above copyright
17 # notice, this list of conditions and the following disclaimer in the
18 # documentation and/or other materials provided with the distribution.
19 #
20 # Neither the name of the University of California, Berkeley nor the
21 # names of its contributors may be used to endorse or promote products
22 # derived from this software without specific prior written permission.
23 #
24 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
27 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
28 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
29 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
30 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
31 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
32 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
34 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 #
36 # Maintainer: John Lazzaro, lazzaro@cs.berkeley.edu
37 */
38
39
40 #include "tree.h"
41
42 /******************************************************************/
43 /* prints out opcode local variables */
44 /******************************************************************/
45
coreparamvars(tnode * tptr)46 void coreparamvars(tnode * tptr)
47
48 {
49
50 sigsym * sptr;
51
52 sptr = tptr->sptr->defnode->sptr;
53 while (sptr != NULL)
54 {
55 if (sptr->kind == K_PFIELD)
56 {
57 if ((sptr->vartype == TABLETYPE)||(sptr->vartype == TMAPTYPE))
58 fprintf(outfile," PSIZE %s;\n",sptr->val);
59 else
60 fprintf(outfile," float %s;\n",sptr->val);
61 }
62 sptr = sptr->next;
63 }
64 fprintf(outfile," float ret;\n");
65
66 }
67
68 /*********************************************************/
69 /* adds variable decls for code opcodes */
70 /*********************************************************/
71
coreopcodevars(tnode * tptr)72 void coreopcodevars(tnode * tptr)
73
74 {
75
76 if (!coreopcodename(tptr))
77 return;
78
79 coreparamvars(tptr);
80 switch (tptr->val[0]) {
81 case 'a':
82 if (!(strcmp(tptr->val,"abs")))
83 return;
84 if (!(strcmp(tptr->val,"acos")))
85 return;
86 if (!(strcmp(tptr->val,"aexpon")))
87 return ;
88 if (!(strcmp(tptr->val,"aexprand")))
89 return ;
90 if (!(strcmp(tptr->val,"agaussrand")))
91 return ;
92 if (!(strcmp(tptr->val,"aline")))
93 return ;
94 if (!(strcmp(tptr->val,"alinrand")))
95 {
96 fprintf(outfile," float a,b;\n");
97 return ;
98 }
99 if (!(strcmp(tptr->val,"allpass")))
100 {
101 fprintf(outfile," int i;\n");
102 return ;
103 }
104 if (!(strcmp(tptr->val,"ampdb")))
105 return;
106 if (!(strcmp(tptr->val,"aphasor")))
107 {
108 fprintf(outfile," float index;\n");
109 fprintf(outfile," unsigned int nint, nfrac, j;\n");
110 return ;
111 }
112 if (!(strcmp(tptr->val,"apoissonrand")))
113 return ;
114 if (!(strcmp(tptr->val,"arand")))
115 return ;
116 if (!(strcmp(tptr->val,"asin")))
117 return;
118 if (!(strcmp(tptr->val,"atan")))
119 return;
120 return ;
121 case 'b':
122 if (!(strcmp(tptr->val,"balance")))
123 {
124 fprintf(outfile," int i;\n");
125 return ;
126 }
127 if (!(strcmp(tptr->val,"bandpass")))
128 {
129 fprintf(outfile," float c,d,e;\n");
130 return ;
131 }
132 if (!(strcmp(tptr->val,"bandstop")))
133 {
134 fprintf(outfile," float c,d,e;\n");
135 return ;
136 }
137 if (!(strcmp(tptr->val,"biquad")))
138 return ;
139 if (!(strcmp(tptr->val,"buzz")))
140 {
141 fprintf(outfile," int tnharm;\n");
142 fprintf(outfile," double dscale;\n");
143 fprintf(outfile," float denom, q, n, rad;\n");
144 fprintf(outfile," float c1, c2, c3, s1, s2, s3;\n");
145 return ;
146 }
147 return ;
148 case 'c':
149 if (!(strcmp(tptr->val,"ceil")))
150 return;
151 if (!(strcmp(tptr->val,"chorus")))
152 {
153 fprintf(outfile," int i,k,len;\n");
154 fprintf(outfile," float index;\n");
155 if (interp == INTERP_SINC)
156 {
157 fprintf(outfile," unsigned int fptr, rptr;\n");
158 fprintf(outfile," int incr;\n");
159 }
160 return ;
161 }
162 if (!(strcmp(tptr->val,"comb")))
163 {
164 fprintf(outfile," int i;\n");
165 return ;
166 }
167 if (!(strcmp(tptr->val,"compressor")))
168 {
169 fprintf(outfile," int i;\n");
170 return ;
171 }
172 if (!(strcmp(tptr->val,"cos")))
173 return;
174 if (!(strcmp(tptr->val,"cpsmidi")))
175 return;
176 if (!(strcmp(tptr->val,"cpsoct")))
177 return;
178 if (!(strcmp(tptr->val,"cpspch")))
179 return;
180 return ;
181 case 'd':
182 if (!(strcmp(tptr->val,"dbamp")))
183 return;
184 if (!(strcmp(tptr->val,"decimate")))
185 return ;
186 if (!(strcmp(tptr->val,"delay")))
187 {
188 fprintf(outfile," int i;\n");
189 return ;
190 }
191 if (!(strcmp(tptr->val,"delay1")))
192 return ;
193 if (!(strcmp(tptr->val,"doscil")))
194 {
195 if (interp == INTERP_LINEAR)
196 fprintf(outfile," unsigned int i, j, k;\n");
197 if (interp == INTERP_SINC)
198 fprintf(outfile," unsigned int i, j, k, x0, fptr, rptr;\n");
199 return ;
200 }
201 if (!(strcmp(tptr->val,"downsamp")))
202 {
203 fprintf(outfile," int i;\n");
204 return ;
205 }
206 return ;
207 case 'e':
208 if (!(strcmp(tptr->val,"exp")))
209 return;
210 return;
211 case 'f':
212 if (!(strcmp(tptr->val,"fft")))
213 {
214 fprintf(outfile," int i,j,len,ds,dc;\n");
215 fprintf(outfile," int bsize, bhalf, bincr;\n");
216 fprintf(outfile," float re1,im1,re2,im2,cv,sv;\n");
217 return;
218 }
219 if (!(strcmp(tptr->val,"fir")))
220 return ;
221 if (!(strcmp(tptr->val,"firt")))
222 {
223 fprintf(outfile," int i,j,last;\n");
224 return ;
225 }
226 if (!(strcmp(tptr->val,"flange")))
227 {
228 fprintf(outfile," int i,k,len;\n");
229 fprintf(outfile," float index;\n");
230 if (interp == INTERP_SINC)
231 {
232 fprintf(outfile," unsigned int fptr, rptr;\n");
233 fprintf(outfile," int incr;\n");
234 }
235 return ;
236 }
237 if (!(strcmp(tptr->val,"floor")))
238 return;
239 if (!(strcmp(tptr->val,"frac")))
240 return;
241 if (!(strcmp(tptr->val,"fracdelay")))
242 {
243 fprintf(outfile," int i,k,len;\n");
244 fprintf(outfile," float index;\n");
245 if (interp == INTERP_SINC)
246 {
247 fprintf(outfile," unsigned int fptr, rptr;\n");
248 fprintf(outfile," int incr;\n");
249 }
250 return ;
251 }
252 if (!(strcmp(tptr->val,"ftbasecps")))
253 return;
254 if (!(strcmp(tptr->val,"ftlen")))
255 return;
256 if (!(strcmp(tptr->val,"ftloop")))
257 return;
258 if (!(strcmp(tptr->val,"ftloopend")))
259 return;
260 if (!(strcmp(tptr->val,"ftsetbase")))
261 return;
262 if (!(strcmp(tptr->val,"ftsetend")))
263 return;
264 if (!(strcmp(tptr->val,"ftsetloop")))
265 return;
266 if (!(strcmp(tptr->val,"ftsetsr")))
267 {
268 fprintf(outfile," double intdummy;\n");
269 return ;
270 }
271 return;
272 if (!(strcmp(tptr->val,"ftsr")))
273 return;
274 return ;
275 case 'g':
276 if (!(strcmp(tptr->val,"gain")))
277 {
278 fprintf(outfile," int i;\n");
279 fprintf(outfile," float root;\n");
280 return ;
281 }
282 if (!(strcmp(tptr->val,"gettempo")))
283 return;
284 if (!(strcmp(tptr->val,"gettune")))
285 return;
286 if (!(strcmp(tptr->val,"grain")))
287 {
288 fprintf(outfile," int i,j;\n");
289 fprintf(outfile," float index,out,sc;\n");
290 fprintf(outfile," float * state;\n");
291 return ;
292 }
293 return ;
294 case 'h':
295 if (!(strcmp(tptr->val,"hipass")))
296 {
297 fprintf(outfile," float c,e;\n");
298 return ;
299 }
300 return ;
301 case 'i':
302 if (!(strcmp(tptr->val,"iexprand")))
303 return ;
304 if (!(strcmp(tptr->val,"ifft")))
305 {
306 fprintf(outfile," int i,j,len,ds,dc,bsize,bhalf,bincr;\n");
307 fprintf(outfile," float re2,im2,cv,sv;\n");
308 return;
309 }
310 if (!(strcmp(tptr->val,"igaussrand")))
311 return ;
312 if (!(strcmp(tptr->val,"iir")))
313 return ;
314 if (!(strcmp(tptr->val,"iirt")))
315 {
316 fprintf(outfile," int i,j;\n");
317 return ;
318 }
319 if (!(strcmp(tptr->val,"ilinrand")))
320 {
321 fprintf(outfile," float a,b;\n");
322 return ;
323 }
324 if (!(strcmp(tptr->val,"int")))
325 return;
326 if (!(strcmp(tptr->val,"irand")))
327 return;
328 return ;
329 case 'j':
330 return ;
331 case 'k':
332 if (!(strcmp(tptr->val,"kexpon")))
333 return ;
334 if (!(strcmp(tptr->val,"kexprand")))
335 return ;
336 if (!(strcmp(tptr->val,"kgaussrand")))
337 return ;
338 if (!(strcmp(tptr->val,"kline")))
339 return ;
340 if (!(strcmp(tptr->val,"klinrand")))
341 {
342 fprintf(outfile," float a,b;\n");
343 }
344 if (!(strcmp(tptr->val,"koscil")))
345 {
346 fprintf(outfile," float index;\n");
347 fprintf(outfile," unsigned int nint, nfrac, i, j;\n");
348 if (interp == INTERP_SINC)
349 {
350 fprintf(outfile," float sffl;\n");
351 fprintf(outfile," unsigned int k, fptr, rptr, sfui, kosincr;\n");
352 }
353 return ;
354 }
355 if (!(strcmp(tptr->val,"kphasor")))
356 {
357 fprintf(outfile," float index;\n");
358 fprintf(outfile," unsigned int nint, nfrac, j;\n");
359 return ;
360 }
361 if (!(strcmp(tptr->val,"kpoissonrand")))
362 return ;
363 if (!(strcmp(tptr->val,"krand")))
364 return ;
365 return ;
366 case 'l':
367 if (!(strcmp(tptr->val,"log")))
368 return;
369 if (!(strcmp(tptr->val,"log10")))
370 return;
371 if (!(strcmp(tptr->val,"lopass")))
372 {
373 fprintf(outfile," float c,e;\n");
374 return ;
375 }
376 if (!(strcmp(tptr->val,"loscil")))
377 {
378 fprintf(outfile," int inloop;\n");
379 fprintf(outfile," float index;\n");
380 fprintf(outfile," unsigned int nint, nfrac, i, j, k;\n");
381 if (interp == INTERP_SINC)
382 {
383 fprintf(outfile," float sffl;\n");
384 fprintf(outfile," unsigned int fptr, rptr, sfui, losincr;\n");
385 }
386 return ;
387 }
388 return;
389 case 'm':
390 if (!(strcmp(tptr->val,"max")))
391 return ;
392 if (!(strcmp(tptr->val,"midicps")))
393 return;
394 if (!(strcmp(tptr->val,"midioct")))
395 return;
396 if (!(strcmp(tptr->val,"midipch")))
397 return;
398 if (!(strcmp(tptr->val,"min")))
399 return;
400 return ;
401 case 'n':
402 return ;
403 case 'o':
404 if (!(strcmp(tptr->val,"octcps")))
405 return ;
406 if (!(strcmp(tptr->val,"octmidi")))
407 return;
408 if (!(strcmp(tptr->val,"octpch")))
409 return;
410 if (!(strcmp(tptr->val,"oscil")))
411 {
412 fprintf(outfile," float index;\n");
413 fprintf(outfile," unsigned int nint, nfrac, i, j;\n");
414 if (interp == INTERP_SINC)
415 {
416 fprintf(outfile," float sffl;\n");
417 fprintf(outfile," unsigned int k, fptr, rptr, sfui, osincr;\n");
418 }
419 return ;
420 }
421 return ;
422 case 'p':
423 if (!(strcmp(tptr->val,"pchcps")))
424 return ;
425 if (!(strcmp(tptr->val,"pchmidi")))
426 return;
427 if (!(strcmp(tptr->val,"pchoct")))
428 return;
429 if (!(strcmp(tptr->val,"pluck")))
430 {
431 fprintf(outfile," unsigned int nint, nfrac, i, j, k;\n");
432 fprintf(outfile," int len;\n");
433 fprintf(outfile," float index;\n");
434 fprintf(outfile," float * h;\n");
435 if (interp == INTERP_SINC)
436 {
437 fprintf(outfile," float sffl;\n");
438 fprintf(outfile," unsigned int m, fptr, rptr, sfui, osincr;\n");
439 }
440 return ;
441 }
442 if (!(strcmp(tptr->val,"port")))
443 {
444 fprintf(outfile," float diff;\n");
445 return ;
446 }
447 if (!(strcmp(tptr->val,"pow")))
448 return;
449 return ;
450 case 'q':
451 return ;
452 case 'r':
453 if (!(strcmp(tptr->val,"reverb")))
454 {
455 fprintf(outfile," int i;\n");
456 fprintf(outfile," float apout1,apout2,csum,fout,c,e;\n");
457 return ;
458 }
459 if (!(strcmp(tptr->val,"rms")))
460 {
461 fprintf(outfile," int i;\n");
462 return ;
463 }
464 return ;
465 case 's':
466 if (!(strcmp(tptr->val,"samphold")))
467 return ;
468 if (!(strcmp(tptr->val,"sblock")))
469 {
470 fprintf(outfile," int i;\n");
471 return ;
472 }
473 if (!(strcmp(tptr->val,"settempo")))
474 return;
475 if (!(strcmp(tptr->val,"settune")))
476 return;
477 if (!(strcmp(tptr->val,"sgn")))
478 return;
479 if (!(strcmp(tptr->val,"sin")))
480 return;
481 if (!(strcmp(tptr->val,"spatialize")))
482 {
483 fprintf(outfile," int i,len;\n");
484 fprintf(outfile," float lpc,lpe,in,phi,theta,esum,ein;\n");
485 fprintf(outfile," float pL,pR,aleft,aright,left,right,room;\n");
486 return ;
487 }
488 if (!(strcmp(tptr->val,"speedt")))
489 return;
490 if (!(strcmp(tptr->val,"sqrt")))
491 return;
492 return ;
493 case 't':
494 if (!(strcmp(tptr->val,"tableread")))
495 {
496 fprintf(outfile," int i,len;\n");
497 if (interp == INTERP_SINC)
498 {
499 fprintf(outfile," float ksffl;\n");
500 fprintf(outfile," unsigned int j, k, fptr, rptr, ksfui, kdsincr;\n");
501 fprintf(outfile," int incr;\n");
502 }
503 return ;
504 }
505 if (!(strcmp(tptr->val,"tablewrite")))
506 {
507 fprintf(outfile," int i;\n");
508 return ;
509 }
510 return;
511 case 'u':
512 if (!(strcmp(tptr->val,"upsamp")))
513 {
514 fprintf(outfile," int i;\n");
515 return ;
516 }
517 return ;
518 case 'v':
519 return ;
520 case 'w':
521 return ;
522 case 'x':
523 return ;
524 case 'y':
525 return ;
526 case 'z':
527 return ;
528 default:
529 return ;
530 }
531 }
532
533
534 /*********************************************************/
535 /* returns 1 if S_IDENT is a core opcode, else 0 */
536 /*********************************************************/
537
coreopcodename(tnode * ident)538 int coreopcodename(tnode * ident)
539
540
541 {
542
543 switch (ident->val[0]) {
544 case 'a':
545 if (!(strcmp(ident->val,"abs")))
546 return 1;
547 if (!(strcmp(ident->val,"acos")))
548 return 1;
549 if (!(strcmp(ident->val,"aexpon")))
550 return 1;
551 if (!(strcmp(ident->val,"aexprand")))
552 return 1;
553 if (!(strcmp(ident->val,"agaussrand")))
554 return 1;
555 if (!(strcmp(ident->val,"aline")))
556 return 1;
557 if (!(strcmp(ident->val,"alinrand")))
558 return 1;
559 if (!(strcmp(ident->val,"allpass")))
560 return 1;
561 if (!(strcmp(ident->val,"ampdb")))
562 return 1;
563 if (!(strcmp(ident->val,"aphasor")))
564 return 1;
565 if (!(strcmp(ident->val,"apoissonrand")))
566 return 1;
567 if (!(strcmp(ident->val,"arand")))
568 return 1;
569 if (!(strcmp(ident->val,"asin")))
570 return 1;
571 if (!(strcmp(ident->val,"atan")))
572 return 1;
573 return 0;
574 case 'b':
575 if (!(strcmp(ident->val,"balance")))
576 return 1;
577 if (!(strcmp(ident->val,"bandpass")))
578 return 1;
579 if (!(strcmp(ident->val,"bandstop")))
580 return 1;
581 if (!(strcmp(ident->val,"biquad")))
582 return 1;
583 if (!(strcmp(ident->val,"buzz")))
584 return 1;
585 return 0;
586 case 'c':
587 if (!(strcmp(ident->val,"ceil")))
588 return 1;
589 if (!(strcmp(ident->val,"chorus")))
590 return 1;
591 if (!(strcmp(ident->val,"comb")))
592 return 1;
593 if (!(strcmp(ident->val,"compressor")))
594 return 1;
595 if (!(strcmp(ident->val,"cos")))
596 return 1;
597 if (!(strcmp(ident->val,"cpsmidi")))
598 return 1;
599 if (!(strcmp(ident->val,"cpsoct")))
600 return 1;
601 if (!(strcmp(ident->val,"cpspch")))
602 return 1;
603 return 0;
604 case 'd':
605 if (!(strcmp(ident->val,"dbamp")))
606 return 1;
607 if (!(strcmp(ident->val,"decimate")))
608 return 1;
609 if (!(strcmp(ident->val,"delay")))
610 return 1;
611 if (!(strcmp(ident->val,"delay1")))
612 return 1;
613 if (!(strcmp(ident->val,"doscil")))
614 return 1;
615 if (!(strcmp(ident->val,"downsamp")))
616 return 1;
617 return 0;
618 case 'e':
619 if (!(strcmp(ident->val,"exp")))
620 return 1;
621 return 0;
622 case 'f':
623 if (!(strcmp(ident->val,"fft")))
624 return 1;
625 if (!(strcmp(ident->val,"fir")))
626 return 1;
627 if (!(strcmp(ident->val,"firt")))
628 return 1;
629 if (!(strcmp(ident->val,"flange")))
630 return 1;
631 if (!(strcmp(ident->val,"floor")))
632 return 1;
633 if (!(strcmp(ident->val,"frac")))
634 return 1;
635 if (!(strcmp(ident->val,"fracdelay")))
636 return 1;
637 if (!(strcmp(ident->val,"ftbasecps")))
638 return 1;
639 if (!(strcmp(ident->val,"ftlen")))
640 return 1;
641 if (!(strcmp(ident->val,"ftloop")))
642 return 1;
643 if (!(strcmp(ident->val,"ftloopend")))
644 return 1;
645 if (!(strcmp(ident->val,"ftsetbase")))
646 return 1;
647 if (!(strcmp(ident->val,"ftsetend")))
648 return 1;
649 if (!(strcmp(ident->val,"ftsetloop")))
650 return 1;
651 if (!(strcmp(ident->val,"ftsetsr")))
652 return 1;
653 if (!(strcmp(ident->val,"ftsr")))
654 return 1;
655 return 0;
656 case 'g':
657 if (!(strcmp(ident->val,"gain")))
658 return 1;
659 if (!(strcmp(ident->val,"gettempo")))
660 return 1;
661 if (!(strcmp(ident->val,"gettune")))
662 return 1;
663 if (!(strcmp(ident->val,"grain")))
664 return 1;
665 return 0;
666 case 'h':
667 if (!(strcmp(ident->val,"hipass")))
668 return 1;
669 return 0;
670 case 'i':
671 if (!(strcmp(ident->val,"iexprand")))
672 return 1;
673 if (!(strcmp(ident->val,"ifft")))
674 return 1;
675 if (!(strcmp(ident->val,"igaussrand")))
676 return 1;
677 if (!(strcmp(ident->val,"iir")))
678 return 1;
679 if (!(strcmp(ident->val,"iirt")))
680 return 1;
681 if (!(strcmp(ident->val,"ilinrand")))
682 return 1;
683 if (!(strcmp(ident->val,"int")))
684 return 1;
685 if (!(strcmp(ident->val,"irand")))
686 return 1;
687 return 0;
688 case 'j':
689 return 0;
690 case 'k':
691 if (!(strcmp(ident->val,"kexpon")))
692 return 1;
693 if (!(strcmp(ident->val,"kexprand")))
694 return 1;
695 if (!(strcmp(ident->val,"kgaussrand")))
696 return 1;
697 if (!(strcmp(ident->val,"kline")))
698 return 1;
699 if (!(strcmp(ident->val,"klinrand")))
700 return 1;
701 if (!(strcmp(ident->val,"koscil")))
702 return 1;
703 if (!(strcmp(ident->val,"kphasor")))
704 return 1;
705 if (!(strcmp(ident->val,"kpoissonrand")))
706 return 1;
707 if (!(strcmp(ident->val,"krand")))
708 return 1;
709 return 0;
710 case 'l':
711 if (!(strcmp(ident->val,"log")))
712 return 1;
713 if (!(strcmp(ident->val,"log10")))
714 return 1;
715 if (!(strcmp(ident->val,"lopass")))
716 return 1;
717 if (!(strcmp(ident->val,"loscil")))
718 return 1;
719 return 0;
720 case 'm':
721 if (!(strcmp(ident->val,"max")))
722 return 1;
723 if (!(strcmp(ident->val,"midicps")))
724 return 1;
725 if (!(strcmp(ident->val,"midioct")))
726 return 1;
727 if (!(strcmp(ident->val,"midipch")))
728 return 1;
729 if (!(strcmp(ident->val,"min")))
730 return 1;
731 return 0;
732 case 'n':
733 return 0;
734 case 'o':
735 if (!(strcmp(ident->val,"octcps")))
736 return 1;
737 if (!(strcmp(ident->val,"octmidi")))
738 return 1;
739 if (!(strcmp(ident->val,"octpch")))
740 return 1;
741 if (!(strcmp(ident->val,"oscil")))
742 return 1;
743 return 0;
744 case 'p':
745 if (!(strcmp(ident->val,"pchcps")))
746 return 1;
747 if (!(strcmp(ident->val,"pchmidi")))
748 return 1;
749 if (!(strcmp(ident->val,"pchoct")))
750 return 1;
751 if (!(strcmp(ident->val,"pluck")))
752 return 1;
753 if (!(strcmp(ident->val,"port")))
754 return 1;
755 if (!(strcmp(ident->val,"pow")))
756 return 1;
757 return 0;
758 case 'q':
759 return 0;
760 case 'r':
761 if (!(strcmp(ident->val,"reverb")))
762 return 1;
763 if (!(strcmp(ident->val,"rms")))
764 return 1;
765 return 0;
766 case 's':
767 if (!(strcmp(ident->val,"samphold")))
768 return 1;
769 if (!(strcmp(ident->val,"sblock")))
770 return 1;
771 if (!(strcmp(ident->val,"settempo")))
772 return 1;
773 if (!(strcmp(ident->val,"settune")))
774 return 1;
775 if (!(strcmp(ident->val,"sgn")))
776 return 1;
777 if (!(strcmp(ident->val,"sin")))
778 return 1;
779 if (!(strcmp(ident->val,"spatialize")))
780 return 1;
781 if (!(strcmp(ident->val,"speedt")))
782 return 1;
783 if (!(strcmp(ident->val,"sqrt")))
784 return 1;
785 return 0;
786 case 't':
787 if (!(strcmp(ident->val,"tableread")))
788 return 1;
789 if (!(strcmp(ident->val,"tablewrite")))
790 return 1;
791 return 0;
792 case 'u':
793 if (!(strcmp(ident->val,"upsamp")))
794 return 1;
795 return 0;
796 case 'v':
797 return 0;
798 case 'w':
799 return 0;
800 case 'x':
801 return 0;
802 case 'y':
803 return 0;
804 case 'z':
805 return 0;
806 }
807 return 0; /* will never execute */
808 }
809
810
811 /*********************************************************/
812 /* returns 1 if opcode has optional formal paramaters */
813 /*********************************************************/
814
coreopcodehasextras(tnode * ident)815 int coreopcodehasextras(tnode * ident)
816
817 {
818
819 switch (ident->val[0]) {
820 case 'a':
821 if (!(strcmp(ident->val,"aexpon")))
822 return 1;
823 if (!(strcmp(ident->val,"aline")))
824 return 1;
825 return 0;
826 case 'b':
827 if (!(strcmp(ident->val,"balance")))
828 return 1;
829 return 0;
830 case 'c':
831 return 0;
832 case 'd':
833 if (!(strcmp(ident->val,"downsamp")))
834 return 1;
835 return 0;
836 case 'e':
837 return 0;
838 case 'f':
839 if (!(strcmp(ident->val,"fft")))
840 return 1;
841 if (!(strcmp(ident->val,"fir")))
842 return 1;
843 if (!(strcmp(ident->val,"firt")))
844 return 1;
845 if (!(strcmp(ident->val,"fracdelay")))
846 return 1;
847 return 0;
848 case 'g':
849 if (!(strcmp(ident->val,"gain")))
850 return 1;
851 if (!(strcmp(ident->val,"gettempo")))
852 return 1;
853 if (!(strcmp(ident->val,"gettune")))
854 return 1;
855 return 0;
856 case 'h':
857 return 0;
858 case 'i':
859 if (!(strcmp(ident->val,"ifft")))
860 return 1;
861 if (!(strcmp(ident->val,"iir")))
862 return 1;
863 if (!(strcmp(ident->val,"iirt")))
864 return 1;
865 return 0;
866 case 'j':
867 return 0;
868 case 'k':
869 if (!(strcmp(ident->val,"kexpon")))
870 return 1;
871 if (!(strcmp(ident->val,"kline")))
872 return 1;
873 if (!(strcmp(ident->val,"koscil")))
874 return 1;
875 return 0;
876 case 'l':
877 if (!(strcmp(ident->val,"loscil")))
878 return 1;
879 return 0;
880 case 'm':
881 if (!(strcmp(ident->val,"max")))
882 return 1;
883 if (!(strcmp(ident->val,"min")))
884 return 1;
885 return 0;
886 case 'n':
887 return 0;
888 case 'o':
889 if (!(strcmp(ident->val,"oscil")))
890 return 1;
891 return 0;
892 case 'p':
893 return 0;
894 case 'q':
895 return 0;
896 case 'r':
897 if (!(strcmp(ident->val,"reverb")))
898 return 1;
899 if (!(strcmp(ident->val,"rms")))
900 return 1;
901 return 0;
902 case 's':
903 return 0;
904 case 't':
905 return 0;
906 case 'u':
907 if (!(strcmp(ident->val,"upsamp")))
908 return 1;
909 return 0;
910 case 'v':
911 return 0;
912 case 'w':
913 return 0;
914 case 'x':
915 return 0;
916 case 'y':
917 return 0;
918 case 'z':
919 return 0;
920 }
921 return 0; /* will never execute */
922 }
923
924
925 /*********************************************************/
926 /* returns 1 if opcode is: */
927 /* */
928 /* [1] A krate, irate, or polymorphic opcode, that */
929 /* [2] Has internal state updates that make rate */
930 /* optimization dangerous in some situations. */
931 /* */
932 /* For now specialops not included, but remain as */
933 /* commented out checks to change this. */
934 /*********************************************************/
935
coreopcodespeedtrap(tnode * ident)936 int coreopcodespeedtrap(tnode * ident)
937
938
939 {
940
941 switch (ident->val[0]) {
942 case 'a':
943 return 0;
944 case 'b':
945 return 0;
946 case 'c':
947 return 0;
948 case 'd':
949 /*
950 *if (!(strcmp(ident->val,"decimate")))
951 * return 1;
952 *if (!(strcmp(ident->val,"downsamp")))
953 * return 1;
954 */
955 return 0;
956 case 'e':
957 return 0;
958 case 'f':
959 /*
960 * if (!(strcmp(ident->val,"fft")))
961 * return 1;
962 */
963 if (!(strcmp(ident->val,"ftsetbase")))
964 return 1;
965 if (!(strcmp(ident->val,"ftsetend")))
966 return 1;
967 if (!(strcmp(ident->val,"ftsetloop")))
968 return 1;
969 if (!(strcmp(ident->val,"ftsetsr")))
970 return 1;
971 return 0;
972 case 'g':
973 return 0;
974 case 'h':
975 return 0;
976 case 'i':
977 return 0;
978 case 'j':
979 return 0;
980 case 'k':
981 if (!(strcmp(ident->val,"kexpon")))
982 return 1;
983 if (!(strcmp(ident->val,"kline")))
984 return 1;
985 if (!(strcmp(ident->val,"koscil")))
986 return 1;
987 if (!(strcmp(ident->val,"kphasor")))
988 return 1;
989 return 0;
990 case 'l':
991 return 0;
992 case 'm':
993 return 0;
994 case 'n':
995 return 0;
996 case 'o':
997 return 0;
998 case 'p':
999 if (!(strcmp(ident->val,"port")))
1000 return 1;
1001 return 0;
1002 case 'q':
1003 return 0;
1004 case 'r':
1005 /*
1006 * if (!(strcmp(ident->val,"rms")))
1007 * return 1;
1008 */
1009 return 0;
1010 case 's':
1011 if (!(strcmp(ident->val,"samphold")))
1012 return 1;
1013 /*
1014 * if (!(strcmp(ident->val,"sblock")))
1015 * return 1;
1016 */
1017 if (!(strcmp(ident->val,"settempo")))
1018 return 1;
1019 if (!(strcmp(ident->val,"speedt")))
1020 return 1;
1021 return 0;
1022 case 't':
1023 if (!(strcmp(ident->val,"tablewrite")))
1024 return 1;
1025 return 0;
1026 case 'u':
1027 /*
1028 * if (!(strcmp(ident->val,"upsamp")))
1029 * return 1;
1030 */
1031 return 0;
1032 case 'v':
1033 return 0;
1034 case 'w':
1035 return 0;
1036 case 'x':
1037 return 0;
1038 case 'y':
1039 return 0;
1040 case 'z':
1041 return 0;
1042 }
1043 return 0; /* will never execute */
1044 }
1045
1046
1047 /***********************************************************************/
1048 /* table core opcodes that should obey strict guard/enclosure rules */
1049 /***********************************************************************/
1050
delicatepolyops(tnode * tptr)1051 int delicatepolyops(tnode * tptr)
1052
1053 {
1054 if ((tptr->val[0] != 'f') && (tptr->val[0] != 't') && (tptr->val[0] != 'g'))
1055 return 0;
1056
1057 if ((!strcmp(tptr->val,"ftlen")) || /* may be UNKNOWN */
1058 (!strcmp(tptr->val,"ftloop")) ||
1059 (!strcmp(tptr->val,"ftloopend")) ||
1060 (!strcmp(tptr->val,"ftsr")) ||
1061 (!strcmp(tptr->val,"gettempo")) ||
1062 (!strcmp(tptr->val,"gettune")) ||
1063 (!strcmp(tptr->val,"ftbasecps")) ||
1064 (!strcmp(tptr->val,"tableread")) || /* side-effects paranoia; */
1065 (!strcmp(tptr->val,"tablewrite"))) /* optrate.c may handle it. */
1066 return 1;
1067
1068 return 0;
1069 }
1070
1071 /***********************************************************************/
1072 /* flags poly opcode exceptions to slower-rate opcall semantics */
1073 /***********************************************************************/
1074
polyopcallexcept(tnode * ident)1075 int polyopcallexcept(tnode * ident)
1076
1077 {
1078
1079 switch (ident->val[0]) {
1080 case 'a':
1081 if (!(strcmp(ident->val,"abs")))
1082 return 1;
1083 break;
1084 case 'c':
1085 if (!(strcmp(ident->val,"ceil")))
1086 return 1;
1087 break;
1088 case 'f':
1089 if (!(strcmp(ident->val,"floor")))
1090 return 1;
1091 if (!(strcmp(ident->val,"ftbasecps")))
1092 return 1;
1093 if (!(strcmp(ident->val,"ftlen")))
1094 return 1;
1095 if (!(strcmp(ident->val,"ftloop")))
1096 return 1;
1097 if (!(strcmp(ident->val,"ftloopend")))
1098 return 1;
1099 if (!(strcmp(ident->val,"ftsr")))
1100 return 1;
1101 break;
1102 case 'g':
1103 if (!(strcmp(ident->val,"gettempo")))
1104 return 1;
1105 if (!(strcmp(ident->val,"gettune")))
1106 return 1;
1107 break;
1108 case 'i':
1109 if (!(strcmp(ident->val,"int")))
1110 return 1;
1111 break;
1112 case 's':
1113 if (!(strcmp(ident->val,"sgn")))
1114 return 1;
1115 break;
1116 case 't':
1117 /* non-compliant, revisit later */
1118 if (!(strcmp(ident->val,"tableread")))
1119 return 1;
1120 if (!(strcmp(ident->val,"tablewrite")))
1121 return 1;
1122 break;
1123 }
1124
1125 return 0;
1126
1127 }
1128
1129
1130 /*********************************************************/
1131 /* returns 1 if constant-input opcode can be precomputed */
1132 /*********************************************************/
1133
coreopcodeprecompute(tnode * ident)1134 int coreopcodeprecompute(tnode * ident)
1135
1136 {
1137
1138 switch (ident->val[0]) {
1139 case 'a':
1140 if (!(strcmp(ident->val,"abs")))
1141 return 1;
1142 if (!(strcmp(ident->val,"acos")))
1143 return 1;
1144 if (!(strcmp(ident->val,"ampdb")))
1145 return 1;
1146 if (!(strcmp(ident->val,"asin")))
1147 return 1;
1148 if (!(strcmp(ident->val,"atan")))
1149 return 1;
1150 return 0;
1151 case 'b':
1152 return 0;
1153 case 'c':
1154 if (!(strcmp(ident->val,"ceil")))
1155 return 1;
1156 if (!(strcmp(ident->val,"cos")))
1157 return 1;
1158 if ((!(strcmp(ident->val,"cpsmidi")))||
1159 (!(strcmp(ident->val,"cpsoct"))) ||
1160 (!(strcmp(ident->val,"cpspch"))))
1161 {
1162 if (has.o_settune)
1163 return 0;
1164 return 1;
1165 }
1166 return 0;
1167 case 'd':
1168 if (!(strcmp(ident->val,"dbamp")))
1169 return 1;
1170 return 0;
1171 case 'e':
1172 if (!(strcmp(ident->val,"exp")))
1173 return 1;
1174 return 0;
1175 case 'f':
1176 if (!(strcmp(ident->val,"floor")))
1177 return 1;
1178 if (!(strcmp(ident->val,"frac")))
1179 return 1;
1180 if (!(strcmp(ident->val,"ftbasecps"))) /* do later */
1181 return 0;
1182 if (!(strcmp(ident->val,"ftlen"))) /* do later */
1183 return 0;
1184 if (!(strcmp(ident->val,"ftloop"))) /* do later */
1185 return 0;
1186 if (!(strcmp(ident->val,"ftloopend"))) /* do later */
1187 return 0;
1188 if (!(strcmp(ident->val,"ftsetbase"))) /* do later */
1189 return 0;
1190 if (!(strcmp(ident->val,"ftsetend"))) /* do later */
1191 return 0;
1192 if (!(strcmp(ident->val,"ftsetloop"))) /* do later */
1193 return 0;
1194 if (!(strcmp(ident->val,"ftsetsr"))) /* do later */
1195 return 0;
1196 if (!(strcmp(ident->val,"ftsr"))) /* do later */
1197 return 0;
1198 return 0;
1199 case 'g':
1200 if (!(strcmp(ident->val,"gettune")))
1201 {
1202 if (has.o_settune)
1203 return 0;
1204 return 1;
1205 }
1206 return 0;
1207 case 'h':
1208 return 0;
1209 case 'i':
1210 if (!(strcmp(ident->val,"int")))
1211 return 1;
1212 return 0;
1213 case 'j':
1214 return 0;
1215 case 'k':
1216 return 0;
1217 case 'l':
1218 if (!(strcmp(ident->val,"log")))
1219 return 1;
1220 if (!(strcmp(ident->val,"log10")))
1221 return 1;
1222 return 0;
1223 case 'm':
1224 if (!(strcmp(ident->val,"max")))
1225 return 1;
1226 if (!(strcmp(ident->val,"midicps")))
1227 {
1228 if (has.o_settune)
1229 return 0;
1230 return 1;
1231 }
1232 if (!(strcmp(ident->val,"midioct")))
1233 return 1;
1234 if (!(strcmp(ident->val,"midipch")))
1235 return 1;
1236 if (!(strcmp(ident->val,"min")))
1237 return 1;
1238 return 0;
1239 case 'n':
1240 return 0;
1241 case 'o':
1242 if (!(strcmp(ident->val,"octcps")))
1243 {
1244 if (has.o_settune)
1245 return 0;
1246 return 1;
1247 }
1248 if (!(strcmp(ident->val,"octmidi")))
1249 return 1;
1250 if (!(strcmp(ident->val,"octpch")))
1251 return 1;
1252 return 0;
1253 case 'p':
1254 if (!(strcmp(ident->val,"pchcps")))
1255 {
1256 if (has.o_settune)
1257 return 0;
1258 return 1;
1259 }
1260 if (!(strcmp(ident->val,"pchmidi")))
1261 return 1;
1262 if (!(strcmp(ident->val,"pchoct")))
1263 return 1;
1264 if (!(strcmp(ident->val,"pow")))
1265 return 1;
1266 return 0;
1267 case 'q':
1268 return 0;
1269 case 'r':
1270 return 0;
1271 case 's':
1272 if (!(strcmp(ident->val,"settempo"))) /* do later */
1273 return 0;
1274 if (!(strcmp(ident->val,"settune"))) /* do later */
1275 return 0;
1276 if (!(strcmp(ident->val,"sgn")))
1277 return 1;
1278 if (!(strcmp(ident->val,"sin")))
1279 return 1;
1280 if (!(strcmp(ident->val,"speedt"))) /* do later */
1281 return 0;
1282 if (!(strcmp(ident->val,"sqrt")))
1283 return 1;
1284 return 0;
1285 case 't':
1286 if (!(strcmp(ident->val,"tableread"))) /* do later */
1287 return 0;
1288 if (!(strcmp(ident->val,"tablewrite")))
1289 return 0;
1290 return 0;
1291 case 'u':
1292 return 0;
1293 case 'v':
1294 return 0;
1295 case 'w':
1296 return 0;
1297 case 'x':
1298 return 0;
1299 case 'y':
1300 return 0;
1301 case 'z':
1302 return 0;
1303 }
1304 return 0; /* will never execute */
1305 }
1306
1307 /*********************************************************/
1308 /* changes fields for typical math core opcode */
1309 /*********************************************************/
1310
mathfloatop(tnode * ident,char * name)1311 void mathfloatop(tnode * ident, char * name)
1312
1313 {
1314 ident->val = dupval(name);
1315 ident->rate = IRATETYPE;
1316 ident->ttype = S_NUMBER;
1317 ident->res = ASFLOAT;
1318 }
1319
1320 /*********************************************************/
1321 /* changes fields for typical math core opcode */
1322 /*********************************************************/
1323
mathintop(tnode * ident,char * name)1324 void mathintop(tnode * ident, char * name)
1325
1326 {
1327 ident->val = dupval(name);
1328 ident->rate = IRATETYPE;
1329 ident->ttype = S_INTGR;
1330 ident->res = ASINT;
1331 }
1332
1333 /*********************************************************/
1334 /* changes fields for max and min */
1335 /*********************************************************/
1336
mathmaxmin(tnode * ident,tnode * tptr)1337 void mathmaxmin(tnode * ident, tnode * tptr)
1338
1339 {
1340 float fval, rval;
1341 tnode * tm;
1342 int ismax = strcmp(ident->val,"min");
1343
1344 tm = tptr;
1345 fval = (float)atof(tptr->down->val);
1346 tptr = tptr->next;
1347 while (tptr != NULL)
1348 {
1349 if (tptr->ttype == S_EXPR)
1350 {
1351 rval = (float)atof(tptr->down->val);
1352 if ((ismax && (rval > fval)) || (!ismax && (rval < fval)))
1353 {
1354 fval = rval;
1355 tm = tptr;
1356 }
1357 }
1358 tptr = tptr->next;
1359 }
1360
1361 ident->val = dupval(tm->down->val);
1362 ident->rate = IRATETYPE;
1363 ident->ttype = tm->down->ttype;
1364 ident->res = tm->down->res;
1365 return;
1366
1367 }
1368
1369 /*********************************************************/
1370 /* collapses core opcode into constant */
1371 /*********************************************************/
1372
coreopcodecollapse(tnode * ident,tnode * tptr)1373 void coreopcodecollapse(tnode * ident, tnode * tptr)
1374
1375 {
1376 char name[128];
1377 float fval, rval;
1378 int ival;
1379 int i;
1380
1381 switch (ident->val[0]) {
1382 case 'a':
1383 if (!(strcmp(ident->val,"abs")))
1384 {
1385 if (tptr->down->val[0] == '-')
1386 strcpy(name, &(tptr->down->val[1]));
1387 else
1388 strcpy(name, tptr->down->val);
1389 ident->val = dupval(name);
1390 ident->rate = IRATETYPE;
1391 ident->ttype = tptr->down->ttype;
1392 ident->res = tptr->down->res;
1393 return;
1394 }
1395 if (!(strcmp(ident->val,"acos")))
1396 {
1397 sprintf(name,"%e", (float)(acos(atof(tptr->down->val))));
1398 mathfloatop(ident, name);
1399 return;
1400 }
1401 if (!(strcmp(ident->val,"ampdb")))
1402 {
1403 sprintf(name,"%e", (float)(pow(10.0F,
1404 5.0e-2F*(atof(tptr->down->val)-90.0F))));
1405 mathfloatop(ident, name);
1406 return;
1407 }
1408 if (!(strcmp(ident->val,"asin")))
1409 {
1410 sprintf(name,"%e", (float)(asin(atof(tptr->down->val))));
1411 mathfloatop(ident, name);
1412 return;
1413 }
1414 if (!(strcmp(ident->val,"atan")))
1415 {
1416 sprintf(name,"%e", (float)(atan(atof(tptr->down->val))));
1417 mathfloatop(ident, name);
1418 return;
1419 }
1420 return;
1421 case 'b':
1422 return;
1423 case 'c':
1424 if (!(strcmp(ident->val,"ceil")))
1425 {
1426 sprintf(name,"%i", (int)(ceil(atof(tptr->down->val))+ 0.5F));
1427 mathintop(ident, name);
1428 return;
1429 }
1430 if (!(strcmp(ident->val,"cos")))
1431 {
1432 sprintf(name,"%e", (float)(cos(atof(tptr->down->val))));
1433 mathfloatop(ident, name);
1434 return;
1435 }
1436 if (!(strcmp(ident->val,"cpsmidi")))
1437 {
1438 fval = (float)atof(tptr->down->val);
1439 if (fval <= 0.0F)
1440 {
1441 printf("Error: x <= 0 argument to cpsmidi()\n");
1442 showerrorplace(ident->linenum, ident->filename);
1443 }
1444 sprintf(name,"%e", globaltune*(float)pow(2.0F, 8.333334e-02F*(fval-69.0F)));
1445 mathfloatop(ident, name);
1446 return;
1447 }
1448 if (!(strcmp(ident->val,"cpsoct")))
1449 {
1450 fval = (float)atof(tptr->down->val);
1451 if (fval <= 0.0F)
1452 {
1453 printf("Error: x <= 0 argument to cpsoct()\n");
1454 showerrorplace(ident->linenum, ident->filename);
1455 }
1456 sprintf(name,"%e", globaltune*(float)pow(2.0F, (fval-8.75F)));
1457 mathfloatop(ident, name);
1458 return;
1459 }
1460 if (!(strcmp(ident->val,"cpspch")))
1461 {
1462 fval = (float)atof(tptr->down->val);
1463 if (fval <= 0.0F)
1464 {
1465 printf("Error: x <= 0 argument to cpspch()\n");
1466 showerrorplace(ident->linenum, ident->filename);
1467 }
1468 ival = (int)(0.5F + 100.0F*(fval - (int)fval));
1469 rval = (ival > 11.0F) ? 0.0F : 8.333334e-2F*ival;
1470 sprintf(name,"%e", globaltune*(float)pow(2.0F,(int)(fval)+rval-8.75F));
1471 mathfloatop(ident, name);
1472 return;
1473 }
1474 return;
1475 case 'd':
1476 if (!(strcmp(ident->val,"dbamp")))
1477 {
1478 fval = (float)atof(tptr->down->val);
1479 if (fval <= 0.0F)
1480 {
1481 printf("Error: x <= 0 argument to dbamp()\n");
1482 showerrorplace(ident->linenum, ident->filename);
1483 }
1484 sprintf(name,"%e", (float)(90.0F+20.0F*(float)log10(fval+1e-10F)));
1485 mathfloatop(ident, name);
1486 return;
1487 }
1488 return;
1489 case 'e':
1490 if (!(strcmp(ident->val,"exp")))
1491 {
1492 sprintf(name,"%e", (float)(exp(atof(tptr->down->val))));
1493 mathfloatop(ident, name);
1494 return;
1495 }
1496 return;
1497 case 'f':
1498 if (!(strcmp(ident->val,"floor")))
1499 {
1500 sprintf(name,"%i", (int)(floor(atof(tptr->down->val))));
1501 mathintop(ident, name);
1502 return;
1503 }
1504 if (!(strcmp(ident->val,"frac")))
1505 {
1506 fval = (float)atof(tptr->down->val);
1507 sprintf(name,"%e", fval - (int)fval);
1508 mathfloatop(ident, name);
1509 return;
1510 }
1511 if (!(strcmp(ident->val,"ftbasecps"))) /* do these later */
1512 return;
1513 if (!(strcmp(ident->val,"ftlen")))
1514 return;
1515 if (!(strcmp(ident->val,"ftloop")))
1516 return;
1517 if (!(strcmp(ident->val,"ftloopend")))
1518 return;
1519 if (!(strcmp(ident->val,"ftsetbase")))
1520 return;
1521 if (!(strcmp(ident->val,"ftsetend")))
1522 return;
1523 if (!(strcmp(ident->val,"ftsetloop")))
1524 return;
1525 if (!(strcmp(ident->val,"ftsetsr")))
1526 return;
1527 if (!(strcmp(ident->val,"ftsr")))
1528 return;
1529 return;
1530 case 'g':
1531 if (!(strcmp(ident->val,"gettune")))
1532 {
1533 sprintf(name,"%e", globaltune);
1534 mathfloatop(ident, name);
1535 return;
1536 }
1537 return;
1538 case 'h':
1539 return;
1540 case 'i':
1541 if (!(strcmp(ident->val,"int")))
1542 {
1543 sprintf(name,"%i", (int)(atof(tptr->down->val)));
1544 mathintop(ident, name);
1545 return;
1546 }
1547 return;
1548 case 'j':
1549 return;
1550 case 'k':
1551 return;
1552 case 'l':
1553 if (!(strcmp(ident->val,"log")))
1554 {
1555 fval = (float)atof(tptr->down->val);
1556 if (fval <= 0.0F)
1557 {
1558 printf("Error: x <= 0 argument to log()\n");
1559 showerrorplace(ident->linenum, ident->filename);
1560 }
1561 sprintf(name,"%e", log(fval));
1562 mathfloatop(ident, name);
1563 return;
1564 }
1565 if (!(strcmp(ident->val,"log10")))
1566 {
1567 fval = (float)atof(tptr->down->val);
1568 if (fval <= 0.0F)
1569 {
1570 printf("Error: x <= 0 argument to log10()\n");
1571 showerrorplace(ident->linenum, ident->filename);
1572 }
1573 sprintf(name,"%e", log10(fval));
1574 mathfloatop(ident, name);
1575 return;
1576 }
1577 return;
1578 case 'm':
1579 if (!(strcmp(ident->val,"max")))
1580 {
1581 mathmaxmin(ident, tptr);
1582 return;
1583 }
1584 if (!(strcmp(ident->val,"midicps")))
1585 {
1586 fval = (float)atof(tptr->down->val);
1587 if (fval <= 0.0F)
1588 {
1589 printf("Error: x <= 0 argument to midicps()\n");
1590 showerrorplace(ident->linenum, ident->filename);
1591 }
1592 sprintf(name,"%i", (int)(69.5F + 1.731234e+01F*log(fval/globaltune)));
1593 mathintop(ident, name);
1594 return;
1595
1596 }
1597 if (!(strcmp(ident->val,"midioct")))
1598 {
1599 fval = (float)atof(tptr->down->val);
1600 if (fval <= 3.0F)
1601 {
1602 printf("Error: x <= 3.0 argument to midioct()\n");
1603 showerrorplace(ident->linenum, ident->filename);
1604 }
1605 sprintf(name,"%i", (int)(12.0F*(fval - 3.0F) + 0.5F));
1606 mathintop(ident, name);
1607 return;
1608
1609 }
1610 if (!(strcmp(ident->val,"midipch")))
1611 {
1612 fval = (float)atof(tptr->down->val);
1613 if (fval <= 3.0F)
1614 {
1615 printf("Error: x <= 3.0 argument to midipch()\n");
1616 showerrorplace(ident->linenum, ident->filename);
1617 }
1618 ival = (int)(0.5 + 100.0F*(fval - (int)fval));
1619 rval = (ival > 11.0F) ? 0.0F : ival;
1620 sprintf(name,"%i", (int)(rval + 12.0F*(- 3 + (int) fval)));
1621 mathintop(ident, name);
1622 return;
1623 }
1624 if (!(strcmp(ident->val,"min")))
1625 {
1626 mathmaxmin(ident, tptr);
1627 return;
1628 }
1629 return;
1630 case 'n':
1631 return;
1632 case 'o':
1633 if (!(strcmp(ident->val,"octcps")))
1634 {
1635 fval = (float)atof(tptr->down->val);
1636 if (fval <= 0.0F)
1637 {
1638 printf("Error: x <= 0.0 argument to octcps()\n");
1639 showerrorplace(ident->linenum, ident->filename);
1640 }
1641 sprintf(name,"%e", 8.75F + 1.442695F*(float)log(fval/globaltune));
1642 mathfloatop(ident, name);
1643 return;
1644 }
1645 if (!(strcmp(ident->val,"octmidi")))
1646 {
1647 fval = (float)atof(tptr->down->val);
1648 if (fval <= 0.0F)
1649 {
1650 printf("Error: x <= 0.0 argument to octmidi()\n");
1651 showerrorplace(ident->linenum, ident->filename);
1652 }
1653 sprintf(name,"%e", 8.333334e-2F*(fval+36.0F));
1654 mathfloatop(ident, name);
1655 return;
1656 }
1657 if (!(strcmp(ident->val,"octpch")))
1658 {
1659 fval = (float)atof(tptr->down->val);
1660 if (fval <= 0.0F)
1661 {
1662 printf("Error: x <= 0.0 argument to octpch()\n");
1663 showerrorplace(ident->linenum, ident->filename);
1664 }
1665 ival = (int)(0.5 + 100.0F*(fval - (int)fval));
1666 rval = (ival > 11.0F) ? 0.0F : ival;
1667 sprintf(name,"%e", 8.333334e-2F*rval + (int) fval);
1668 mathfloatop(ident, name);
1669 return;
1670 }
1671 return;
1672 case 'p':
1673 if (!(strcmp(ident->val,"pchcps")))
1674 {
1675 fval = (float)atof(tptr->down->val);
1676 if (fval <= 0.0F)
1677 {
1678 printf("Error: x <= 0.0 argument to pchcps()\n");
1679 showerrorplace(ident->linenum, ident->filename);
1680 }
1681 rval = 8.75F + 1.442695F*(float)log(fval/globaltune);
1682 ival = (int)(0.5 + 12.0F*(rval - (int) rval));
1683 sprintf(name,"%e", 1.0e-2F*ival + (int) rval);
1684 mathfloatop(ident, name);
1685 return;
1686 }
1687 if (!(strcmp(ident->val,"pchmidi")))
1688 {
1689 fval = (float)atof(tptr->down->val);
1690 if (fval <= 0.0F)
1691 {
1692 printf("Error: x <= 0.0 argument to pchmidi()\n");
1693 showerrorplace(ident->linenum, ident->filename);
1694 }
1695 rval = 8.333334e-02F*((int)(fval + 0.5)+36.0F);
1696 sprintf(name,"%e", 12.0e-2F*(rval-(int)rval) + (int)rval);
1697 mathfloatop(ident, name);
1698 return;
1699 }
1700 if (!(strcmp(ident->val,"pchoct")))
1701 {
1702 fval = (float)atof(tptr->down->val);
1703 if (fval <= 0.0F)
1704 {
1705 printf("Error: x <= 0.0 argument to pchoct()\n");
1706 showerrorplace(ident->linenum, ident->filename);
1707 }
1708 ival = (int)(12.0F*(fval- (int) fval) + 0.5F);
1709 sprintf(name,"%e", 1.0e-2F*ival + (int) fval);
1710 mathfloatop(ident, name);
1711 return;
1712 }
1713 if (!(strcmp(ident->val,"pow")))
1714 {
1715 fval = (float)atof(tptr->down->val);
1716 tptr = tptr->next;
1717 if (tptr->ttype != S_EXPR)
1718 tptr = tptr->next;
1719 rval = (float)pow(fval, atof(tptr->down->val));
1720 sprintf(name,"%e", rval);
1721 for (i = 0; i < strlen(name); i++) /* Inf, Nan */
1722 if ((name[i] == 'I') || (name[i] == 'N') ||
1723 (name[i] == 'i') || (name[i] == 'n'))
1724 {
1725 printf("Error: Inapproproate arguments to pow()\n");
1726 showerrorplace(ident->linenum, ident->filename);
1727 }
1728 mathfloatop(ident, name);
1729 return;
1730 }
1731 return;
1732 case 'q':
1733 return;
1734 case 'r':
1735 return;
1736 case 's':
1737 if (!(strcmp(ident->val,"settempo"))) /* do later */
1738 return;
1739 if (!(strcmp(ident->val,"settune"))) /* do later */
1740 return;
1741 if (!(strcmp(ident->val,"sgn")))
1742 {
1743 fval = (float)atof(tptr->down->val);
1744 if (fval == 0.0)
1745 sprintf(name,"0");
1746 else
1747 {
1748 if (fval > 0)
1749 sprintf(name,"1");
1750 else
1751 sprintf(name,"-1");
1752 }
1753 mathintop(ident, name);
1754 return;
1755 }
1756 if (!(strcmp(ident->val,"sin")))
1757 {
1758 sprintf(name,"%e", (float)(sin(atof(tptr->down->val))));
1759 mathfloatop(ident, name);
1760 return;
1761 }
1762 if (!(strcmp(ident->val,"speedt"))) /* do later */
1763 return;
1764 if (!(strcmp(ident->val,"sqrt")))
1765 {
1766 fval = (float)atof(tptr->down->val);
1767 if (fval < 0.0F)
1768 {
1769 printf("Error: x < 0 argument to sqrt()\n");
1770 showerrorplace(ident->linenum, ident->filename);
1771 }
1772 sprintf(name,"%e", sqrt(fval));
1773 mathfloatop(ident, name);
1774 return;
1775 }
1776 return;
1777 case 't':
1778 if (!(strcmp(ident->val,"tableread"))) /* do later */
1779 return;
1780 if (!(strcmp(ident->val,"tablewrite"))) /* do later */
1781 return;
1782 return;
1783 case 'u':
1784 return;
1785 case 'v':
1786 return;
1787 case 'w':
1788 return;
1789 case 'x':
1790 return;
1791 case 'y':
1792 return;
1793 case 'z':
1794 return;
1795 default:
1796 return;
1797 }
1798 }
1799
1800 /*********************************************************/
1801 /* reference counts for each core opcode */
1802 /*********************************************************/
1803
hascoreopcode(tnode * ident,int incr)1804 void hascoreopcode(tnode * ident, int incr)
1805
1806 {
1807
1808 switch (ident->val[0]) {
1809 case 'a':
1810 if (!(strcmp(ident->val,"abs")))
1811 {
1812 has.o_abs+= incr;
1813 return;
1814 }
1815 if (!(strcmp(ident->val,"acos")))
1816 {
1817 has.o_acos+= incr;
1818 return;
1819 }
1820 if (!(strcmp(ident->val,"aexpon")))
1821 {
1822 has.o_aexpon+= incr;
1823 return;
1824 }
1825 if (!(strcmp(ident->val,"aexprand")))
1826 {
1827 has.o_aexprand+= incr;
1828 return;
1829 }
1830 if (!(strcmp(ident->val,"agaussrand")))
1831 {
1832 has.o_agaussrand+= incr;
1833 return;
1834 }
1835 if (!(strcmp(ident->val,"aline")))
1836 {
1837 has.o_aline+= incr;
1838 return;
1839 }
1840 if (!(strcmp(ident->val,"alinrand")))
1841 {
1842 has.o_alinrand+= incr;
1843 return;
1844 }
1845 if (!(strcmp(ident->val,"allpass")))
1846 {
1847 has.o_allpass+= incr;
1848 return;
1849 }
1850 if (!(strcmp(ident->val,"ampdb")))
1851 {
1852 has.o_ampdb+= incr;
1853 return;
1854 }
1855 if (!(strcmp(ident->val,"aphasor")))
1856 {
1857 has.o_aphasor+= incr;
1858 return;
1859 }
1860 if (!(strcmp(ident->val,"apoissonrand")))
1861 {
1862 has.o_apoissonrand+= incr;
1863 return;
1864 }
1865 if (!(strcmp(ident->val,"arand")))
1866 {
1867 has.o_arand+= incr;
1868 return;
1869 }
1870 if (!(strcmp(ident->val,"asin")))
1871 {
1872 has.o_asin+= incr;
1873 return;
1874 }
1875 if (!(strcmp(ident->val,"atan")))
1876 {
1877 has.o_atan+= incr;
1878 return;
1879 }
1880 return;
1881 case 'b':
1882 if (!(strcmp(ident->val,"balance")))
1883 {
1884 has.o_balance+= incr;
1885 return;
1886 }
1887 if (!(strcmp(ident->val,"bandpass")))
1888 {
1889 has.o_bandpass+= incr;
1890 return;
1891 }
1892 if (!(strcmp(ident->val,"bandstop")))
1893 {
1894 has.o_bandstop+= incr;
1895 return;
1896 }
1897 if (!(strcmp(ident->val,"biquad")))
1898 {
1899 has.o_biquad+= incr;
1900 return;
1901 }
1902 if (!(strcmp(ident->val,"buzz")))
1903 {
1904 has.o_buzz+= incr;
1905 return;
1906 }
1907 return;
1908 case 'c':
1909 if (!(strcmp(ident->val,"ceil")))
1910 {
1911 has.o_ceil+= incr;
1912 return;
1913 }
1914 if (!(strcmp(ident->val,"chorus")))
1915 {
1916 has.o_chorus+= incr;
1917 return;
1918 }
1919 if (!(strcmp(ident->val,"comb")))
1920 {
1921 has.o_comb+= incr;
1922 return;
1923 }
1924 if (!(strcmp(ident->val,"compressor")))
1925 {
1926 has.o_compressor+= incr;
1927 return;
1928 }
1929 if (!(strcmp(ident->val,"cos")))
1930 {
1931 has.o_cos+= incr;
1932 return;
1933 }
1934 if (!(strcmp(ident->val,"cpsmidi")))
1935 {
1936 has.o_cpsmidi+= incr;
1937 return;
1938 }
1939 if (!(strcmp(ident->val,"cpsoct")))
1940 {
1941 has.o_cpsoct+= incr;
1942 return;
1943 }
1944 if (!(strcmp(ident->val,"cpspch")))
1945 {
1946 has.o_cpspch+= incr;
1947 return;
1948 }
1949 return;
1950 case 'd':
1951 if (!(strcmp(ident->val,"dbamp")))
1952 {
1953 has.o_dbamp+= incr;
1954 return;
1955 }
1956 if (!(strcmp(ident->val,"decimate")))
1957 {
1958 has.o_decimate+= incr;
1959 return;
1960 }
1961 if (!(strcmp(ident->val,"delay")))
1962 {
1963 has.o_delay+= incr;
1964 return;
1965 }
1966 if (!(strcmp(ident->val,"delay1")))
1967 {
1968 has.o_delay1+= incr;
1969 return;
1970 }
1971 if (!(strcmp(ident->val,"doscil")))
1972 {
1973 has.o_doscil+= incr;
1974 return;
1975 }
1976 if (!(strcmp(ident->val,"downsamp")))
1977 {
1978 has.o_downsamp+= incr;
1979 return;
1980 }
1981 return;
1982 case 'e':
1983 if (!(strcmp(ident->val,"exp")))
1984 {
1985 has.o_exp+= incr;
1986 return;
1987 }
1988 return;
1989 case 'f':
1990 if (!(strcmp(ident->val,"fft")))
1991 {
1992 has.o_fft+= incr;
1993 return;
1994 }
1995 if (!(strcmp(ident->val,"fir")))
1996 {
1997 has.o_fir+= incr;
1998 return;
1999 }
2000 if (!(strcmp(ident->val,"firt")))
2001 {
2002 has.o_firt+= incr;
2003 return;
2004 }
2005 if (!(strcmp(ident->val,"flange")))
2006 {
2007 has.o_flange+= incr;
2008 return;
2009 }
2010 if (!(strcmp(ident->val,"floor")))
2011 {
2012 has.o_floor+= incr;
2013 return;
2014 }
2015 if (!(strcmp(ident->val,"frac")))
2016 {
2017 has.o_frac+= incr;
2018 return;
2019 }
2020 if (!(strcmp(ident->val,"fracdelay")))
2021 {
2022 has.o_fracdelay+= incr;
2023 return;
2024 }
2025 if (!(strcmp(ident->val,"ftbasecps")))
2026 {
2027 has.o_ftbasecps+= incr;
2028 return;
2029 }
2030 if (!(strcmp(ident->val,"ftlen")))
2031 {
2032 has.o_ftlen+= incr;
2033 return;
2034 }
2035 if (!(strcmp(ident->val,"ftloop")))
2036 {
2037 has.o_ftloop+= incr;
2038 return;
2039 }
2040 if (!(strcmp(ident->val,"ftloopend")))
2041 {
2042 has.o_ftloopend+= incr;
2043 return;
2044 }
2045 if (!(strcmp(ident->val,"ftsetbase")))
2046 {
2047 has.o_ftsetbase+= incr;
2048 return;
2049 }
2050 if (!(strcmp(ident->val,"ftsetend")))
2051 {
2052 has.o_ftsetend+= incr;
2053 return;
2054 }
2055 if (!(strcmp(ident->val,"ftsetloop")))
2056 {
2057 has.o_ftsetloop+= incr;
2058 return;
2059 }
2060 if (!(strcmp(ident->val,"ftsetsr")))
2061 {
2062 has.o_ftsetsr+= incr;
2063 return;
2064 }
2065 if (!(strcmp(ident->val,"ftsr")))
2066 {
2067 has.o_ftsr+= incr;
2068 return;
2069 }
2070 return;
2071 case 'g':
2072 if (!(strcmp(ident->val,"gain")))
2073 {
2074 has.o_gain+= incr;
2075 return;
2076 }
2077 if (!(strcmp(ident->val,"gettempo")))
2078 {
2079 has.o_gettempo+= incr;
2080 return;
2081 }
2082 if (!(strcmp(ident->val,"gettune")))
2083 {
2084 has.o_gettune+= incr;
2085 return;
2086 }
2087 if (!(strcmp(ident->val,"grain")))
2088 {
2089 has.o_grain+= incr;
2090 return;
2091 }
2092 return;
2093 case 'h':
2094 if (!(strcmp(ident->val,"hipass")))
2095 {
2096 has.o_hipass+= incr;
2097 return;
2098 }
2099 return;
2100 case 'i':
2101 if (!(strcmp(ident->val,"iexprand")))
2102 {
2103 has.o_iexprand+= incr;
2104 return;
2105 }
2106 if (!(strcmp(ident->val,"ifft")))
2107 {
2108 has.o_ifft+= incr;
2109 return;
2110 }
2111 if (!(strcmp(ident->val,"igaussrand")))
2112 {
2113 has.o_igaussrand+= incr;
2114 return;
2115 }
2116 if (!(strcmp(ident->val,"iir")))
2117 {
2118 has.o_iir+= incr;
2119 return;
2120 }
2121 if (!(strcmp(ident->val,"iirt")))
2122 {
2123 has.o_iirt+= incr;
2124 return;
2125 }
2126 if (!(strcmp(ident->val,"ilinrand")))
2127 {
2128 has.o_ilinrand+= incr;
2129 return;
2130 }
2131 if (!(strcmp(ident->val,"int")))
2132 {
2133 has.o_int+= incr;
2134 return;
2135 }
2136 if (!(strcmp(ident->val,"irand")))
2137 {
2138 has.o_irand+= incr;
2139 return;
2140 }
2141 return;
2142 case 'j':
2143 return;
2144 case 'k':
2145 if (!(strcmp(ident->val,"kexpon")))
2146 {
2147 has.o_kexpon+= incr;
2148 return;
2149 }
2150 if (!(strcmp(ident->val,"kexprand")))
2151 {
2152 has.o_kexprand+= incr;
2153 return;
2154 }
2155 if (!(strcmp(ident->val,"kgaussrand")))
2156 {
2157 has.o_kgaussrand+= incr;
2158 return;
2159 }
2160 if (!(strcmp(ident->val,"kline")))
2161 {
2162 has.o_kline+= incr;
2163 return;
2164 }
2165 if (!(strcmp(ident->val,"klinrand")))
2166 {
2167 has.o_klinrand+= incr;
2168 return;
2169 }
2170 if (!(strcmp(ident->val,"koscil")))
2171 {
2172 has.o_koscil+= incr;
2173 return;
2174 }
2175 if (!(strcmp(ident->val,"kphasor")))
2176 {
2177 has.o_kphasor+= incr;
2178 return;
2179 }
2180 if (!(strcmp(ident->val,"kpoissonrand")))
2181 {
2182 has.o_kpoissonrand+= incr;
2183 return;
2184 }
2185 if (!(strcmp(ident->val,"krand")))
2186 {
2187 has.o_krand+= incr;
2188 return;
2189 }
2190 return;
2191 case 'l':
2192 if (!(strcmp(ident->val,"log")))
2193 {
2194 has.o_log+= incr;
2195 return;
2196 }
2197 if (!(strcmp(ident->val,"log10")))
2198 {
2199 has.o_log10+= incr;
2200 return;
2201 }
2202 if (!(strcmp(ident->val,"lopass")))
2203 {
2204 has.o_lopass+= incr;
2205 return;
2206 }
2207 if (!(strcmp(ident->val,"loscil")))
2208 {
2209 has.o_loscil+= incr;
2210 return;
2211 }
2212 return;
2213 case 'm':
2214 if (!(strcmp(ident->val,"max")))
2215 {
2216 has.o_max+= incr;
2217 return;
2218 }
2219 if (!(strcmp(ident->val,"midicps")))
2220 {
2221 has.o_midicps+= incr;
2222 return;
2223 }
2224 if (!(strcmp(ident->val,"midioct")))
2225 {
2226 has.o_midioct+= incr;
2227 return;
2228 }
2229 if (!(strcmp(ident->val,"midipch")))
2230 {
2231 has.o_midipch+= incr;
2232 return;
2233 }
2234 if (!(strcmp(ident->val,"min")))
2235 {
2236 has.o_min+= incr;
2237 return;
2238 }
2239 return;
2240 case 'n':
2241 return;
2242 case 'o':
2243 if (!(strcmp(ident->val,"octcps")))
2244 {
2245 has.o_octcps+= incr;
2246 return;
2247 }
2248 if (!(strcmp(ident->val,"octmidi")))
2249 {
2250 has.o_octmidi+= incr;
2251 return;
2252 }
2253 if (!(strcmp(ident->val,"octpch")))
2254 {
2255 has.o_octpch+= incr;
2256 return;
2257 }
2258 if (!(strcmp(ident->val,"oscil")))
2259 {
2260 has.o_oscil+= incr;
2261 return;
2262 }
2263 return;
2264 case 'p':
2265 if (!(strcmp(ident->val,"pchcps")))
2266 {
2267 has.o_pchcps+= incr;
2268 return;
2269 }
2270 if (!(strcmp(ident->val,"pchmidi")))
2271 {
2272 has.o_pchmidi+= incr;
2273 return;
2274 }
2275 if (!(strcmp(ident->val,"pchoct")))
2276 {
2277 has.o_pchoct+= incr;
2278 return;
2279 }
2280 if (!(strcmp(ident->val,"pluck")))
2281 {
2282 has.o_pluck+= incr;
2283 return;
2284 }
2285 if (!(strcmp(ident->val,"port")))
2286 {
2287 has.o_port+= incr;
2288 return;
2289 }
2290 if (!(strcmp(ident->val,"pow")))
2291 {
2292 has.o_pow+= incr;
2293 return;
2294 }
2295 return;
2296 case 'q':
2297 return;
2298 case 'r':
2299 if (!(strcmp(ident->val,"reverb")))
2300 {
2301 has.o_reverb+= incr;
2302 return;
2303 }
2304 if (!(strcmp(ident->val,"rms")))
2305 {
2306 has.o_rms+= incr;
2307 return;
2308 }
2309 return;
2310 case 's':
2311 if (!(strcmp(ident->val,"samphold")))
2312 {
2313 has.o_samphold+= incr;
2314 return;
2315 }
2316 if (!(strcmp(ident->val,"sblock")))
2317 {
2318 has.o_sblock+= incr;
2319 return;
2320 }
2321 if (!(strcmp(ident->val,"settempo")))
2322 {
2323 has.o_settempo+= incr;
2324 return;
2325 }
2326 if (!(strcmp(ident->val,"settune")))
2327 {
2328 has.o_settune+= incr;
2329 return;
2330 }
2331 if (!(strcmp(ident->val,"sgn")))
2332 {
2333 has.o_sgn+= incr;
2334 return;
2335 }
2336 if (!(strcmp(ident->val,"sin")))
2337 {
2338 has.o_sin+= incr;
2339 return;
2340 }
2341 if (!(strcmp(ident->val,"spatialize")))
2342 {
2343 has.spatialize+= incr;
2344 return;
2345 }
2346 if (!(strcmp(ident->val,"speedt")))
2347 {
2348 has.o_speedt+= incr;
2349 return;
2350 }
2351 if (!(strcmp(ident->val,"sqrt")))
2352 {
2353 has.o_sqrt+= incr;
2354 return;
2355 }
2356 return;
2357 case 't':
2358 if (!(strcmp(ident->val,"tableread")))
2359 {
2360 has.o_tableread+= incr;
2361 return;
2362 }
2363 if (!(strcmp(ident->val,"tablewrite")))
2364 {
2365 has.o_tablewrite+= incr;
2366 return;
2367 }
2368 return;
2369 case 'u':
2370 if (!(strcmp(ident->val,"upsamp")))
2371 {
2372 has.o_upsamp+= incr;
2373 return;
2374 }
2375 return;
2376 case 'v':
2377 return;
2378 case 'w':
2379 return;
2380 case 'x':
2381 return;
2382 case 'y':
2383 return;
2384 case 'z':
2385 return;
2386 default:
2387 return;
2388 }
2389 }
2390
2391 /*********************************************************/
2392 /* optrefer reference counts for core opcodes */
2393 /*********************************************************/
2394
corerefer(sigsym * sptr,tnode * ident,tnode * tptr,int passtype)2395 void corerefer(sigsym * sptr, tnode * ident, tnode * tptr, int passtype)
2396
2397 {
2398
2399 switch (ident->val[0]) {
2400 case 'f':
2401 if (!(strcmp(ident->val,"fft")))
2402 {
2403 /* find the re table */
2404
2405 tptr = tptr->next;
2406
2407 while (tptr->ttype != S_EXPR)
2408 tptr = tptr->next;
2409
2410 /* reference counts for re */
2411
2412 (tptr->down->sptr->tref->assigntot)++;
2413 (tptr->down->sptr->tref->assigntval)++;
2414 if (whilerefdepth)
2415 (tptr->down->sptr->tref->assignwhile)++;
2416 if (ifrefdepth)
2417 (tptr->down->sptr->tref->assignif)++;
2418
2419 /* since its a special-op */
2420
2421 tptr->down->sptr->tref->assignrate = ARATETYPE;
2422 tmaprefer(tptr->down->sptr, TVALCHANGE, ARATETYPE);
2423
2424 tptr = tptr->next;
2425
2426 /* find the im table */
2427
2428 while (tptr->ttype != S_EXPR)
2429 tptr = tptr->next;
2430
2431 /* reference counts for im */
2432
2433 (tptr->down->sptr->tref->assigntot)++;
2434 (tptr->down->sptr->tref->assigntval)++;
2435 if (whilerefdepth)
2436 (tptr->down->sptr->tref->assignwhile)++;
2437 if (ifrefdepth)
2438 (tptr->down->sptr->tref->assignif)++;
2439 tptr->down->sptr->tref->assignrate = ARATETYPE;
2440 tmaprefer(tptr->down->sptr, TVALCHANGE, ARATETYPE);
2441
2442 /* reference counts for instr/opcode */
2443
2444 (sptr->cref->statewave)++;
2445 return;
2446 }
2447 if ((!(strcmp(ident->val,"ftsetbase"))) ||
2448 (!(strcmp(ident->val,"ftsetend"))) ||
2449 (!(strcmp(ident->val,"ftsetloop"))) ||
2450 (!(strcmp(ident->val,"ftsetsr"))))
2451 {
2452 (tptr->down->sptr->tref->assigntot)++;
2453 if (whilerefdepth)
2454 (tptr->down->sptr->tref->assignwhile)++;
2455 if (ifrefdepth)
2456 (tptr->down->sptr->tref->assignif)++;
2457 if (passtype > tptr->down->sptr->tref->assignrate)
2458 tptr->down->sptr->tref->assignrate = passtype;
2459 tmaprefer(tptr->down->sptr, TPARAMCHANGE, passtype);
2460
2461 (sptr->cref->statewave)++;
2462 return;
2463 }
2464 return;
2465 case 's':
2466 if (!(strcmp(ident->val,"sblock")))
2467 {
2468 /* find the table */
2469
2470 tptr = tptr->next;
2471
2472 while (tptr->ttype != S_EXPR)
2473 tptr = tptr->next;
2474
2475 /* reference counts for table */
2476
2477 (tptr->down->sptr->tref->assigntot)++;
2478 (tptr->down->sptr->tref->assigntval)++;
2479 if (whilerefdepth)
2480 (tptr->down->sptr->tref->assignwhile)++;
2481 if (ifrefdepth)
2482 (tptr->down->sptr->tref->assignif)++;
2483
2484 /* since its a special-op */
2485
2486 tptr->down->sptr->tref->assignrate = ARATETYPE;
2487 tmaprefer(tptr->down->sptr, TVALCHANGE, ARATETYPE);
2488
2489 /* reference counts for instr/opcode */
2490
2491 (sptr->cref->statewave)++;
2492
2493 return;
2494 }
2495 if (!(strcmp(ident->val,"settune")))
2496 {
2497 if (passtype > sptr->cref->settune)
2498 sptr->cref->settune = passtype;
2499 return;
2500 }
2501 if (!(strcmp(ident->val,"speedt")))
2502 {
2503 /* find the out table */
2504
2505 tptr = tptr->next;
2506
2507 while (tptr->ttype != S_EXPR)
2508 tptr = tptr->next;
2509
2510 /* reference counts for table */
2511
2512 (tptr->down->sptr->tref->assigntot)++;
2513 (tptr->down->sptr->tref->assigntval)++;
2514 if (whilerefdepth)
2515 (tptr->down->sptr->tref->assignwhile)++;
2516 if (ifrefdepth)
2517 (tptr->down->sptr->tref->assignif)++;
2518 if (passtype > tptr->down->sptr->tref->assignrate)
2519 tptr->down->sptr->tref->assignrate = passtype;
2520 tmaprefer(tptr->down->sptr, TVALCHANGE, passtype);
2521
2522 /* reference counts for instr/opcode */
2523
2524 (sptr->cref->statewave)++;
2525
2526 return;
2527 }
2528 return;
2529 case 't':
2530 if (!(strcmp(ident->val,"tablewrite")))
2531 {
2532 (tptr->down->sptr->tref->assigntot)++;
2533 (tptr->down->sptr->tref->assigntval)++;
2534 if (whilerefdepth)
2535 (tptr->down->sptr->tref->assignwhile)++;
2536 if (ifrefdepth)
2537 (tptr->down->sptr->tref->assignif)++;
2538 if (passtype > tptr->down->sptr->tref->assignrate)
2539 tptr->down->sptr->tref->assignrate = passtype;
2540 tmaprefer(tptr->down->sptr, TVALCHANGE, passtype);
2541
2542 (sptr->cref->statewave)++;
2543 return;
2544 }
2545 return;
2546 default:
2547 return;
2548 }
2549 }
2550
2551 /*********************************************************/
2552 /* returns 1 if S_IDENT is a specialop, else 0 */
2553 /*********************************************************/
2554
coreopcodespecial(tnode * ident)2555 int coreopcodespecial(tnode * ident)
2556
2557 {
2558
2559 if (!(strcmp(ident->val,"fft")))
2560 return 1;
2561 if (!(strcmp(ident->val,"rms")))
2562 return 1;
2563 if (!(strcmp(ident->val,"sblock")))
2564 return 1;
2565 if (!(strcmp(ident->val,"downsamp")))
2566 return 1;
2567 if (!(strcmp(ident->val,"decimate")))
2568 return 1;
2569 return 0;
2570
2571 }
2572
2573 /*********************************************************/
2574 /* returns ASINT if a core opcode always returns an INT */
2575 /* else returns ASFLOAT */
2576 /*********************************************************/
2577
coreopcodeasint(tnode * ident)2578 int coreopcodeasint(tnode * ident)
2579
2580 {
2581 /* only does int() right now, because there's */
2582 /* never a speed hit taken. expansion to other */
2583 /* integral opcodes should be done with care */
2584
2585 if (!(strcmp(ident->val,"int")))
2586 return ASINT;
2587
2588 return ASFLOAT;
2589
2590 }
2591
2592 /*********************************************************/
2593 /* creates an opcode declaration */
2594 /* optype IDENT LP paramlist RP LC opvardecls block RC */
2595 /*********************************************************/
2596
createopcode(tnode * tptr,sigsym ** nametable,int type)2597 sigsym * createopcode(tnode * tptr, sigsym ** nametable, int type)
2598
2599 {
2600 sigsym * newsym;
2601 tnode * t_optype = NULL; /* initialization not needed */
2602 tnode * t_ident;
2603 tnode * t_lp;
2604 tnode * t_paramlist;
2605 tnode * t_rp;
2606 tnode * t_lc;
2607 tnode * t_opvardecls;
2608 tnode * t_block;
2609 tnode * t_rc;
2610
2611 symcheck(addvsym(nametable, tptr->val, K_OPCODENAME), tptr);
2612 newsym = (*nametable);
2613 newsym->width = 1;
2614 newsym->defnode = make_tnode("<opcodedecl>",S_OPCODEDECL);
2615
2616 switch (type) {
2617 case S_IOPCODE:
2618 t_optype = make_tnode("iopcode", type);
2619 newsym->rate = t_optype->rate = IRATETYPE;
2620 break;
2621 case S_KOPCODE:
2622 t_optype = make_tnode("kopcode", type);
2623 newsym->rate = t_optype->rate = KRATETYPE;
2624 break;
2625 case S_SOPCODE:
2626 t_optype = make_tnode("kopcode", type);
2627 newsym->rate = t_optype->rate = KRATETYPE;
2628 newsym->special = t_optype->special = 1;
2629 break;
2630 case S_AOPCODE:
2631 t_optype = make_tnode("aopcode", type);
2632 newsym->rate = t_optype->rate = ARATETYPE;
2633 break;
2634 case S_OPCODE:
2635 t_optype = make_tnode("opcode", type);
2636 newsym->rate = t_optype->rate = XRATETYPE;
2637 break;
2638 }
2639
2640 t_ident = make_tnode(tptr->val, S_IDENT);
2641 t_lp = make_tnode("(", S_LP);
2642 t_paramlist = make_tnode("<paramlist>",S_PARAMLIST);
2643 t_rp = make_tnode(")", S_RP);
2644 t_lc = make_tnode("{", S_LC);
2645 t_opvardecls = make_tnode("<opvardecls>",S_OPVARDECLS);
2646 t_block = make_tnode("<block>",S_BLOCK);
2647 t_rc = make_tnode("}", S_RC);
2648
2649 newsym->defnode->down = t_optype;
2650 t_optype->next = t_ident;
2651 t_ident->next = t_lp;
2652 t_lp->next = t_paramlist;
2653 t_paramlist->next = t_rp;
2654 t_rp->next = t_lc;
2655 t_lc->next = t_opvardecls;
2656 t_opvardecls->next = t_block;
2657 t_block->next = t_rc;
2658
2659 t_paramlist->rate = UNKNOWN;
2660 if (type == S_SOPCODE)
2661 t_paramlist->special = 1;
2662
2663 return newsym;
2664
2665 }
2666
2667 /*********************************************************/
2668 /* adds a parameter to an opcode definition */
2669 /*********************************************************/
2670
2671
addopcodevar(sigsym * newsym,int type,char * name)2672 void addopcodevar(sigsym * newsym, int type, char * name)
2673
2674 {
2675 tnode * paramdecl;
2676
2677 symcheck(addvsym(&(newsym->defnode->sptr), name, K_NORMAL), NULL);
2678 newsym->defnode->sptr->width = 1;
2679 paramdecl = newsym->defnode->down->next->next->next;
2680
2681 switch (type) {
2682 case S_IVAR:
2683 newsym->defnode->sptr->rate = IRATETYPE;
2684 if (paramdecl->rate == UNKNOWN)
2685 paramdecl->rate = IRATETYPE;
2686 break;
2687 case S_KSIG:
2688 newsym->defnode->sptr->rate = KRATETYPE;
2689 if ( (paramdecl->rate == UNKNOWN) ||
2690 (paramdecl->rate == IRATETYPE) )
2691 paramdecl->rate = KRATETYPE;
2692 break;
2693 case S_ASIG:
2694 paramdecl->rate = newsym->defnode->sptr->rate = ARATETYPE;
2695 break;
2696 case S_XSIG:
2697 newsym->defnode->sptr->rate = XRATETYPE;
2698 break;
2699 case S_TABLE:
2700 newsym->defnode->sptr->rate = IRATETYPE;
2701 newsym->defnode->sptr->vartype =TABLETYPE;
2702 newsym->defnode->sptr->kind = K_INTERNAL;
2703 break;
2704 default:
2705 break;
2706 }
2707
2708 return;
2709
2710 }
2711
2712 /*********************************************************/
2713 /* adds a parameter to an opcode definition */
2714 /*********************************************************/
2715
addopcodepfield(sigsym * newsym,int type,char * name)2716 void addopcodepfield(sigsym * newsym, int type, char * name)
2717
2718
2719 {
2720
2721 tnode * tptr;
2722 tnode * newparam;
2723
2724 tptr = newsym->defnode->down->next->next->next;
2725 newparam = make_tnode("<paramdecl>",S_PARAMDECL);
2726 switch (type) {
2727 case S_IVAR:
2728 newparam->down = make_tnode("ivar",type);
2729 newparam->rate = IRATETYPE;
2730 break;
2731 case S_KSIG:
2732 newparam->down = make_tnode("ksig",type);
2733 newparam->rate = KRATETYPE;
2734 tptr->rate = (tptr->rate == IRATETYPE) ? KRATETYPE : tptr->rate;
2735 break;
2736 case S_ASIG:
2737 newparam->down = make_tnode("asig",type);
2738 tptr->rate = newparam->rate = ARATETYPE;
2739 break;
2740 case S_XSIG:
2741 newparam->down = make_tnode("xsig",type);
2742 newparam->rate = XRATETYPE;
2743 break;
2744 case S_TABLE:
2745 newparam->down = make_tnode("table",type);
2746 newparam->vartype = TABLETYPE;
2747 newparam->rate = IRATETYPE;
2748 break;
2749 default:
2750 break;
2751 }
2752
2753 newparam->down->next = make_tnode("<name>",S_NAME);
2754 newparam->down->next->down = make_tnode(name,S_IDENT);
2755
2756 symcheck(addvsym(&(newsym->defnode->sptr), name, K_PFIELD), NULL);
2757 newparam->sptr = newparam->down->next->sptr =
2758 newparam->down->next->down->sptr = newsym->defnode->sptr;
2759 newsym->defnode->sptr->rate = newparam->down->rate =
2760 newparam->down->next->rate = newparam->rate;
2761 newsym->defnode->sptr->vartype = newparam->down->vartype =
2762 newparam->down->next->vartype = newparam->vartype;
2763 newsym->defnode->sptr->width = newparam->width
2764 = newparam->down->width = newparam->down->next->width = 1;
2765
2766 if (tptr->down == NULL)
2767 tptr->down = newparam;
2768 else
2769 {
2770 tptr = tptr->down;
2771 while (tptr->next != NULL)
2772 tptr = tptr->next;
2773 tptr->next = make_tnode(",",S_COM);
2774 tptr->next->next = newparam;
2775 }
2776
2777 }
2778
2779
2780
2781 /*********************************************************/
2782 /* adds varargs parameter to an opcode call */
2783 /*********************************************************/
2784
2785
addextraparam(tnode * tcall,int type,char * name)2786 void addextraparam(tnode * tcall, int type, char * name)
2787
2788 {
2789
2790 tnode * newparam;
2791
2792 newparam = make_tnode("<paramdecl>",S_PARAMDECL);
2793 switch (type) {
2794 case S_IVAR:
2795 newparam->down = make_tnode("ivar",type);
2796 newparam->rate = IRATETYPE;
2797 if (tcall->extrarate == UNKNOWN)
2798 tcall->extrarate = IRATETYPE;
2799 break;
2800 case S_KSIG:
2801 newparam->down = make_tnode("ksig",type);
2802 newparam->rate = KRATETYPE;
2803 if ((tcall->extrarate == UNKNOWN)||
2804 (tcall->extrarate == IRATETYPE))
2805 tcall->extrarate = KRATETYPE;
2806 break;
2807 case S_ASIG:
2808 newparam->down = make_tnode("asig",type);
2809 tcall->extrarate = newparam->rate = ARATETYPE;
2810 break;
2811 case S_XSIG:
2812 newparam->down = make_tnode("xsig",type);
2813 newparam->rate = XRATETYPE;
2814 break;
2815 case S_TABLE:
2816 newparam->down = make_tnode("table",type);
2817 newparam->vartype = TABLETYPE;
2818 break;
2819 default:
2820 break;
2821 }
2822
2823 newparam->down->next = make_tnode("<name>", S_NAME);
2824 newparam->down->next->down = make_tnode(name, S_IDENT);
2825 newparam->down->rate = newparam->down->next->rate
2826 = newparam->rate;
2827 newparam->down->width = newparam->down->next->width
2828 = newparam->width = 1;
2829
2830 if (tcall->extra == NULL)
2831 tcall->extra = newparam;
2832 else
2833 {
2834 tcall = tcall->extra;
2835 while (tcall->next != NULL)
2836 tcall = tcall->next;
2837 tcall->next = make_tnode(",",S_COM);
2838 tcall->next->next = newparam;
2839 }
2840 }
2841
2842
2843 /*********************************************************/
2844 /* adds one-argument, xrate opcode to nametable */
2845 /*********************************************************/
2846
oneargopcode(tnode * tptr,sigsym ** nametable)2847 sigsym * oneargopcode(tnode * tptr, sigsym ** nametable)
2848
2849 {
2850 sigsym * newsym;
2851
2852 newsym = createopcode(tptr, nametable, S_OPCODE);
2853 addopcodepfield(newsym, S_XSIG,"x");
2854 return newsym;
2855 }
2856
2857
2858 /*********************************************************/
2859 /* adds needed core opcode to nametable */
2860 /*********************************************************/
2861
coreopcodeadd(tnode * tptr,sigsym ** nametable)2862 sigsym * coreopcodeadd(tnode * tptr, sigsym ** nametable)
2863
2864
2865 {
2866 sigsym * newsym;
2867
2868 switch (tptr->val[0]) {
2869 case 'a':
2870 if (!(strcmp(tptr->val,"abs")))
2871 return oneargopcode(tptr, nametable);
2872 if (!(strcmp(tptr->val,"acos")))
2873 return oneargopcode(tptr, nametable);
2874 if (!(strcmp(tptr->val,"aexpon")))
2875 {
2876 newsym = createopcode(tptr, nametable, S_AOPCODE);
2877 addopcodepfield(newsym, S_IVAR,"x1");
2878 addopcodepfield(newsym, S_IVAR,"dur1");
2879 addopcodepfield(newsym, S_IVAR,"x2");
2880 addopcodevar(newsym, S_ASIG,"t");
2881 addopcodevar(newsym, S_ASIG,"clp");
2882 addopcodevar(newsym, S_ASIG,"crp");
2883 addopcodevar(newsym, S_ASIG,"cdur");
2884 addopcodevar(newsym, S_ASIG,"ratio");
2885 addopcodevar(newsym, S_ASIG,"invcdur");
2886 addopcodevar(newsym, S_ASIG,"outT");
2887 addopcodevar(newsym, S_ASIG,"multK");
2888 addopcodevar(newsym, S_ASIG,"first");
2889 return newsym;
2890 }
2891 if (!(strcmp(tptr->val,"aexprand")))
2892 {
2893 newsym = createopcode(tptr, nametable, S_AOPCODE);
2894 addopcodepfield(newsym, S_ASIG,"p1");
2895 return newsym;
2896 }
2897 if (!(strcmp(tptr->val,"agaussrand")))
2898 {
2899 newsym = createopcode(tptr, nametable, S_AOPCODE);
2900 addopcodepfield(newsym, S_ASIG,"mean");
2901 addopcodepfield(newsym, S_ASIG,"var");
2902 return newsym;
2903 }
2904 if (!(strcmp(tptr->val,"aline")))
2905 {
2906 newsym = createopcode(tptr, nametable, S_AOPCODE);
2907 addopcodepfield(newsym, S_IVAR,"x1");
2908 addopcodepfield(newsym, S_IVAR,"dur1");
2909 addopcodepfield(newsym, S_IVAR,"x2");
2910 addopcodevar(newsym, S_ASIG,"t");
2911 addopcodevar(newsym, S_ASIG,"clp");
2912 addopcodevar(newsym, S_ASIG,"crp");
2913 addopcodevar(newsym, S_ASIG,"cdur");
2914 addopcodevar(newsym, S_ASIG,"mult");
2915 addopcodevar(newsym, S_ASIG,"outT");
2916 addopcodevar(newsym, S_ASIG,"addK");
2917 addopcodevar(newsym, S_ASIG,"first");
2918 return newsym;
2919 }
2920 if (!(strcmp(tptr->val,"alinrand")))
2921 {
2922 newsym = createopcode(tptr, nametable, S_AOPCODE);
2923 addopcodepfield(newsym, S_ASIG,"p1");
2924 addopcodepfield(newsym, S_ASIG,"p2");
2925 return newsym;
2926 }
2927 if (!(strcmp(tptr->val,"allpass")))
2928 {
2929 newsym = createopcode(tptr, nametable, S_AOPCODE);
2930 addopcodepfield(newsym, S_ASIG,"input");
2931 addopcodepfield(newsym, S_IVAR,"time");
2932 addopcodepfield(newsym, S_IVAR,"gain");
2933 addopcodevar(newsym, S_TABLE,"dline");
2934 addopcodevar(newsym, S_ASIG,"kcyc");
2935 return newsym;
2936 }
2937 if (!(strcmp(tptr->val,"ampdb")))
2938 return oneargopcode(tptr, nametable);
2939 if (!(strcmp(tptr->val,"aphasor")))
2940 {
2941 newsym = createopcode(tptr, nametable, S_AOPCODE);
2942 addopcodepfield(newsym, S_ASIG,"cps");
2943 addopcodevar(newsym, S_ASIG,"pint");
2944 addopcodevar(newsym, S_ASIG,"pfrac");
2945 addopcodevar(newsym, S_ASIG,"kcyc");
2946 return newsym;
2947 }
2948 if (!(strcmp(tptr->val,"apoissonrand")))
2949 {
2950 newsym = createopcode(tptr, nametable, S_AOPCODE);
2951 addopcodepfield(newsym, S_ASIG,"p1");
2952 addopcodevar(newsym, S_ASIG,"state");
2953 return newsym;
2954 }
2955 if (!(strcmp(tptr->val,"arand")))
2956 {
2957 newsym = createopcode(tptr, nametable, S_AOPCODE);
2958 addopcodepfield(newsym, S_ASIG,"p");
2959 return newsym;
2960 }
2961 if (!(strcmp(tptr->val,"asin")))
2962 return oneargopcode(tptr, nametable);
2963 if (!(strcmp(tptr->val,"atan")))
2964 return oneargopcode(tptr, nametable);
2965 return NULL;
2966 case 'b':
2967 if (!(strcmp(tptr->val,"balance")))
2968 {
2969 newsym = createopcode(tptr, nametable, S_AOPCODE);
2970 addopcodepfield(newsym, S_ASIG,"x");
2971 addopcodepfield(newsym, S_ASIG,"ref");
2972 addopcodevar(newsym, S_KSIG,"lcount");
2973 addopcodevar(newsym, S_KSIG,"lval");
2974 addopcodevar(newsym, S_ASIG,"atten");
2975 addopcodevar(newsym, S_ASIG,"acc");
2976 addopcodevar(newsym, S_ASIG,"racc");
2977 return newsym;
2978 }
2979 if (!(strcmp(tptr->val,"bandpass")))
2980 {
2981 newsym = createopcode(tptr, nametable, S_AOPCODE);
2982 addopcodepfield(newsym, S_ASIG,"input");
2983 addopcodepfield(newsym, S_KSIG,"cf");
2984 addopcodepfield(newsym, S_KSIG,"bw");
2985 addopcodevar(newsym, S_ASIG,"kcyc");
2986 addopcodevar(newsym, S_ASIG,"ocf");
2987 addopcodevar(newsym, S_ASIG,"obw");
2988 addopcodevar(newsym, S_ASIG,"b0");
2989 addopcodevar(newsym, S_ASIG,"b1");
2990 addopcodevar(newsym, S_ASIG,"b2");
2991 addopcodevar(newsym, S_ASIG,"a1");
2992 addopcodevar(newsym, S_ASIG,"a2");
2993 addopcodevar(newsym, S_ASIG,"d1");
2994 addopcodevar(newsym, S_ASIG,"d2");
2995 return newsym;
2996 }
2997 if (!(strcmp(tptr->val,"bandstop")))
2998 {
2999 newsym = createopcode(tptr, nametable, S_AOPCODE);
3000 addopcodepfield(newsym, S_ASIG,"input");
3001 addopcodepfield(newsym, S_KSIG,"cf");
3002 addopcodepfield(newsym, S_KSIG,"bw");
3003 addopcodevar(newsym, S_ASIG,"kcyc");
3004 addopcodevar(newsym, S_ASIG,"ocf");
3005 addopcodevar(newsym, S_ASIG,"obw");
3006 addopcodevar(newsym, S_ASIG,"b0");
3007 addopcodevar(newsym, S_ASIG,"b1");
3008 addopcodevar(newsym, S_ASIG,"b2");
3009 addopcodevar(newsym, S_ASIG,"a1");
3010 addopcodevar(newsym, S_ASIG,"a2");
3011 addopcodevar(newsym, S_ASIG,"d1");
3012 addopcodevar(newsym, S_ASIG,"d2");
3013 return newsym;
3014 }
3015 if (!(strcmp(tptr->val,"biquad")))
3016 {
3017 newsym = createopcode(tptr, nametable, S_AOPCODE);
3018 addopcodepfield(newsym, S_ASIG,"input");
3019 addopcodepfield(newsym, S_IVAR,"b0");
3020 addopcodepfield(newsym, S_IVAR,"b1");
3021 addopcodepfield(newsym, S_IVAR,"b2");
3022 addopcodepfield(newsym, S_IVAR,"a1");
3023 addopcodepfield(newsym, S_IVAR,"a2");
3024 addopcodevar(newsym, S_ASIG,"d1");
3025 addopcodevar(newsym, S_ASIG,"d2");
3026 addopcodevar(newsym, S_ASIG,"first");
3027 return newsym;
3028 }
3029 if (!(strcmp(tptr->val,"buzz")))
3030 {
3031 newsym = createopcode(tptr, nametable, S_AOPCODE);
3032 addopcodepfield(newsym, S_ASIG,"cps");
3033 addopcodepfield(newsym, S_KSIG,"nharm");
3034 addopcodepfield(newsym, S_KSIG,"lowharm");
3035 addopcodepfield(newsym, S_KSIG,"rolloff");
3036
3037 addopcodevar(newsym, S_ASIG,"p");
3038 addopcodevar(newsym, S_ASIG,"scale");
3039 addopcodevar(newsym, S_ASIG,"r");
3040 addopcodevar(newsym, S_ASIG,"ntab");
3041 addopcodevar(newsym, S_ASIG,"qtab");
3042 addopcodevar(newsym, S_ASIG,"d");
3043 addopcodevar(newsym, S_ASIG,"k1");
3044 addopcodevar(newsym, S_ASIG,"k2");
3045 addopcodevar(newsym, S_ASIG,"kcyc");
3046
3047 return newsym;
3048 }
3049 return NULL;
3050 case 'c':
3051 if (!(strcmp(tptr->val,"ceil")))
3052 return oneargopcode(tptr, nametable);
3053 if (!(strcmp(tptr->val,"chorus")))
3054 {
3055 newsym = createopcode(tptr, nametable, S_AOPCODE);
3056 addopcodepfield(newsym, S_ASIG,"x");
3057 addopcodepfield(newsym, S_KSIG,"rate");
3058 addopcodepfield(newsym, S_KSIG,"depth");
3059 addopcodevar(newsym, S_ASIG,"p");
3060 addopcodevar(newsym, S_ASIG,"kcyc");
3061 addopcodevar(newsym, S_TABLE,"dline");
3062 addopcodevar(newsym, S_TABLE,"sweep");
3063 return newsym;
3064 }
3065 if (!(strcmp(tptr->val,"comb")))
3066 {
3067 newsym = createopcode(tptr, nametable, S_AOPCODE);
3068 addopcodepfield(newsym, S_ASIG,"input");
3069 addopcodepfield(newsym, S_IVAR,"time");
3070 addopcodepfield(newsym, S_IVAR,"gain");
3071 addopcodevar(newsym, S_TABLE,"dline");
3072 addopcodevar(newsym, S_ASIG,"kcyc");
3073 return newsym;
3074 }
3075 if (!(strcmp(tptr->val,"compressor")))
3076 {
3077 newsym = createopcode(tptr, nametable, S_AOPCODE);
3078 addopcodepfield(newsym, S_ASIG,"x");
3079 addopcodepfield(newsym, S_ASIG,"comp");
3080 addopcodepfield(newsym, S_KSIG,"nfloor");
3081 addopcodepfield(newsym, S_KSIG,"thresh");
3082 addopcodepfield(newsym, S_KSIG,"loknee");
3083 addopcodepfield(newsym, S_KSIG,"hiknee");
3084 addopcodepfield(newsym, S_KSIG,"ratio");
3085 addopcodepfield(newsym, S_KSIG,"att");
3086 addopcodepfield(newsym, S_KSIG,"rel");
3087 addopcodepfield(newsym, S_IVAR,"look");
3088 addopcodevar(newsym, S_TABLE,"xdly");
3089 addopcodevar(newsym, S_TABLE,"compdly");
3090 addopcodevar(newsym, S_ASIG,"change");
3091 addopcodevar(newsym, S_ASIG,"comp1");
3092 addopcodevar(newsym, S_ASIG,"comp2");
3093 addopcodevar(newsym, S_ASIG,"env");
3094 addopcodevar(newsym, S_ASIG,"projEnv");
3095 addopcodevar(newsym, S_ASIG,"oldval");
3096 addopcodevar(newsym, S_ASIG,"invatt");
3097 addopcodevar(newsym, S_ASIG,"invrel");
3098 addopcodevar(newsym, S_ASIG,"mult");
3099 addopcodevar(newsym, S_ASIG,"lval");
3100 addopcodevar(newsym, S_ASIG,"invr");
3101 addopcodevar(newsym, S_ASIG,"kcyc");
3102 addopcodevar(newsym, S_KSIG,"mtail");
3103 addopcodevar(newsym, S_KSIG,"xtail");
3104 addopcodevar(newsym, S_KSIG,"logmin");
3105 return newsym;
3106 }
3107 if (!(strcmp(tptr->val,"cos")))
3108 return oneargopcode(tptr, nametable);
3109 if (!(strcmp(tptr->val,"cpsmidi")))
3110 return oneargopcode(tptr, nametable);
3111 if (!(strcmp(tptr->val,"cpsoct")))
3112 return oneargopcode(tptr, nametable);
3113 if (!(strcmp(tptr->val,"cpspch")))
3114 return oneargopcode(tptr, nametable);
3115 return NULL;
3116 case 'd':
3117 if (!(strcmp(tptr->val,"dbamp")))
3118 return oneargopcode(tptr, nametable);
3119 if (!(strcmp(tptr->val,"decimate")))
3120 {
3121 newsym = createopcode(tptr, nametable, S_SOPCODE);
3122 addopcodepfield(newsym, S_ASIG,"input");
3123 addopcodevar(newsym, S_ASIG,"state");
3124 addopcodevar(newsym, S_ASIG,"krun");
3125 return newsym;
3126 }
3127 if (!(strcmp(tptr->val,"delay")))
3128 {
3129 newsym = createopcode(tptr, nametable, S_AOPCODE);
3130 addopcodepfield(newsym, S_ASIG,"x");
3131 addopcodepfield(newsym, S_IVAR,"t");
3132 addopcodevar(newsym, S_TABLE,"dline");
3133 return newsym;
3134 }
3135 if (!(strcmp(tptr->val,"delay1")))
3136 {
3137 newsym = createopcode(tptr, nametable, S_AOPCODE);
3138 addopcodepfield(newsym, S_ASIG,"x");
3139 addopcodevar(newsym, S_ASIG,"d");
3140 return newsym;
3141 }
3142 if (!(strcmp(tptr->val,"doscil")))
3143 {
3144 newsym = createopcode(tptr, nametable, S_AOPCODE);
3145 addopcodepfield(newsym, S_TABLE,"t");
3146 addopcodevar(newsym, S_ASIG,"pint");
3147 addopcodevar(newsym, S_ASIG,"pfrac");
3148 addopcodevar(newsym, S_ASIG,"play");
3149 return newsym;
3150 }
3151 if (!(strcmp(tptr->val,"downsamp")))
3152 {
3153 newsym = createopcode(tptr, nametable, S_SOPCODE);
3154 addopcodepfield(newsym, S_ASIG,"input");
3155 addopcodevar(newsym, S_ASIG,"kcyc");
3156 addopcodevar(newsym, S_TABLE,"buffer");
3157 return newsym;
3158 }
3159 return NULL;
3160 case 'e':
3161 if (!(strcmp(tptr->val,"exp")))
3162 return oneargopcode(tptr, nametable);
3163 return NULL;
3164 case 'f':
3165 if (!(strcmp(tptr->val,"fft")))
3166 {
3167 newsym = createopcode(tptr, nametable, S_SOPCODE);
3168 addopcodepfield(newsym, S_ASIG,"input");
3169 addopcodepfield(newsym, S_TABLE,"re");
3170 addopcodepfield(newsym, S_TABLE,"im");
3171 addopcodevar(newsym, S_KSIG,"done");
3172 addopcodevar(newsym, S_TABLE,"buffer");
3173 addopcodevar(newsym, S_TABLE,"new");
3174 addopcodevar(newsym, S_TABLE,"cos");
3175 addopcodevar(newsym, S_TABLE,"map");
3176 addopcodevar(newsym, S_IVAR,"scale");
3177 return newsym;
3178 }
3179 if (!(strcmp(tptr->val,"fir")))
3180 {
3181 newsym = createopcode(tptr, nametable, S_AOPCODE);
3182 addopcodepfield(newsym, S_ASIG,"input");
3183 addopcodepfield(newsym, S_KSIG,"b0");
3184 addopcodevar(newsym, S_ASIG,"p");
3185 return newsym;
3186 }
3187 if (!(strcmp(tptr->val,"firt")))
3188 {
3189 newsym = createopcode(tptr, nametable, S_AOPCODE);
3190 addopcodepfield(newsym, S_ASIG,"input");
3191 addopcodepfield(newsym, S_TABLE,"t");
3192 addopcodevar(newsym, S_TABLE,"dline");
3193 addopcodevar(newsym, S_ASIG,"kcyc");
3194 return newsym;
3195 }
3196 if (!(strcmp(tptr->val,"flange")))
3197 {
3198 newsym = createopcode(tptr, nametable, S_AOPCODE);
3199 addopcodepfield(newsym, S_ASIG,"x");
3200 addopcodepfield(newsym, S_KSIG,"rate");
3201 addopcodepfield(newsym, S_KSIG,"depth");
3202 addopcodevar(newsym, S_ASIG,"p");
3203 addopcodevar(newsym, S_ASIG,"kcyc");
3204 addopcodevar(newsym, S_TABLE,"dline");
3205 addopcodevar(newsym, S_TABLE,"sweep");
3206 return newsym;
3207 }
3208 if (!(strcmp(tptr->val,"floor")))
3209 return oneargopcode(tptr, nametable);
3210 if (!(strcmp(tptr->val,"frac")))
3211 return oneargopcode(tptr, nametable);
3212 if (!(strcmp(tptr->val,"fracdelay")))
3213 {
3214 newsym = createopcode(tptr, nametable, S_AOPCODE);
3215 addopcodepfield(newsym, S_KSIG,"method");
3216 addopcodevar(newsym, S_TABLE,"dline");
3217 return newsym;
3218 }
3219 if (!(strcmp(tptr->val,"ftbasecps")))
3220 {
3221 newsym = createopcode(tptr, nametable, S_OPCODE);
3222 addopcodepfield(newsym, S_TABLE,"t");
3223 return newsym;
3224 }
3225 if (!(strcmp(tptr->val,"ftlen")))
3226 {
3227 newsym = createopcode(tptr, nametable, S_OPCODE);
3228 addopcodepfield(newsym, S_TABLE,"t");
3229 return newsym;
3230 }
3231 if (!(strcmp(tptr->val,"ftloop")))
3232 {
3233 newsym = createopcode(tptr, nametable, S_OPCODE);
3234 addopcodepfield(newsym, S_TABLE,"t");
3235 return newsym;
3236 }
3237 if (!(strcmp(tptr->val,"ftloopend")))
3238 {
3239 newsym = createopcode(tptr, nametable, S_OPCODE);
3240 addopcodepfield(newsym, S_TABLE,"t");
3241 return newsym;
3242 }
3243 if (!(strcmp(tptr->val,"ftsetbase")))
3244 {
3245 newsym = createopcode(tptr, nametable, S_KOPCODE);
3246 addopcodepfield(newsym, S_TABLE,"t");
3247 addopcodepfield(newsym, S_KSIG,"x");
3248 return newsym;
3249 }
3250 if (!(strcmp(tptr->val,"ftsetend")))
3251 {
3252 newsym = createopcode(tptr, nametable, S_KOPCODE);
3253 addopcodepfield(newsym, S_TABLE,"t");
3254 addopcodepfield(newsym, S_KSIG,"x");
3255 return newsym;
3256 }
3257 if (!(strcmp(tptr->val,"ftsetloop")))
3258 {
3259 newsym = createopcode(tptr, nametable, S_KOPCODE);
3260 addopcodepfield(newsym, S_TABLE,"t");
3261 addopcodepfield(newsym, S_KSIG,"x");
3262 return newsym;
3263 }
3264 if (!(strcmp(tptr->val,"ftsetsr")))
3265 {
3266 newsym = createopcode(tptr, nametable, S_KOPCODE);
3267 addopcodepfield(newsym, S_TABLE,"t");
3268 addopcodepfield(newsym, S_KSIG,"x");
3269 return newsym;
3270 }
3271 if (!(strcmp(tptr->val,"ftsr")))
3272 {
3273 newsym = createopcode(tptr, nametable, S_OPCODE);
3274 addopcodepfield(newsym, S_TABLE,"t");
3275 return newsym;
3276 }
3277 return NULL;
3278 case 'g':
3279 if (!(strcmp(tptr->val,"gain")))
3280 {
3281 newsym = createopcode(tptr, nametable, S_AOPCODE);
3282 addopcodepfield(newsym, S_ASIG,"x");
3283 addopcodepfield(newsym, S_KSIG,"gain");
3284 addopcodevar(newsym, S_KSIG,"lcount");
3285 addopcodevar(newsym, S_KSIG,"lval");
3286 addopcodevar(newsym, S_KSIG,"scale");
3287 addopcodevar(newsym, S_ASIG,"atten");
3288 addopcodevar(newsym, S_ASIG,"acc");
3289 return newsym;
3290 }
3291 if (!(strcmp(tptr->val,"gettempo")))
3292 {
3293 newsym = createopcode(tptr, nametable, S_OPCODE);
3294 return newsym;
3295 }
3296 if (!(strcmp(tptr->val,"gettune")))
3297 {
3298 newsym = createopcode(tptr, nametable, S_OPCODE);
3299 return newsym;
3300 }
3301 if (!(strcmp(tptr->val,"grain")))
3302 {
3303 newsym = createopcode(tptr, nametable, S_AOPCODE);
3304 addopcodepfield(newsym, S_TABLE,"wave");
3305 addopcodepfield(newsym, S_TABLE,"env");
3306 addopcodepfield(newsym, S_KSIG,"density");
3307 addopcodepfield(newsym, S_KSIG,"freq");
3308 addopcodepfield(newsym, S_KSIG,"amp");
3309 addopcodepfield(newsym, S_KSIG,"dur");
3310 addopcodepfield(newsym, S_KSIG,"time");
3311 addopcodepfield(newsym, S_KSIG,"phase");
3312 addopcodevar(newsym, S_TABLE,"state");
3313 addopcodevar(newsym, S_ASIG,"kcyc");
3314 addopcodevar(newsym, S_ASIG,"trip");
3315 addopcodevar(newsym, S_ASIG,"oscil");
3316 addopcodevar(newsym, S_ASIG,"dclock");
3317 addopcodevar(newsym, S_ASIG,"tclock");
3318 addopcodevar(newsym, S_ASIG,"invdens");
3319 addopcodevar(newsym, S_ASIG,"lconst");
3320 addopcodevar(newsym, S_ASIG,"dconst");
3321 return newsym;
3322 }
3323 return NULL;
3324 case 'h':
3325 if (!(strcmp(tptr->val,"hipass")))
3326 {
3327 newsym = createopcode(tptr, nametable, S_AOPCODE);
3328 addopcodepfield(newsym, S_ASIG,"input");
3329 addopcodepfield(newsym, S_KSIG,"cut");
3330 addopcodevar(newsym, S_ASIG,"kcyc");
3331 addopcodevar(newsym, S_ASIG,"ocut");
3332 addopcodevar(newsym, S_ASIG,"b0");
3333 addopcodevar(newsym, S_ASIG,"b1");
3334 addopcodevar(newsym, S_ASIG,"b2");
3335 addopcodevar(newsym, S_ASIG,"a1");
3336 addopcodevar(newsym, S_ASIG,"a2");
3337 addopcodevar(newsym, S_ASIG,"d1");
3338 addopcodevar(newsym, S_ASIG,"d2");
3339 return newsym;
3340 }
3341 return NULL;
3342 case 'i':
3343 if (!(strcmp(tptr->val,"iexprand")))
3344 {
3345 newsym = createopcode(tptr, nametable, S_IOPCODE);
3346 addopcodepfield(newsym, S_IVAR,"p1");
3347 return newsym;
3348 }
3349 if (!(strcmp(tptr->val,"ifft")))
3350 {
3351 newsym = createopcode(tptr, nametable, S_AOPCODE);
3352 addopcodepfield(newsym, S_TABLE,"re");
3353 addopcodepfield(newsym, S_TABLE,"im");
3354 addopcodevar(newsym, S_TABLE,"buffer");
3355 addopcodevar(newsym, S_TABLE,"new");
3356 addopcodevar(newsym, S_TABLE,"imnew");
3357 addopcodevar(newsym, S_TABLE,"cos");
3358 addopcodevar(newsym, S_TABLE,"map");
3359 addopcodevar(newsym, S_IVAR,"scale");
3360 return newsym;
3361 }
3362 if (!(strcmp(tptr->val,"igaussrand")))
3363 {
3364 newsym = createopcode(tptr, nametable, S_IOPCODE);
3365 addopcodepfield(newsym, S_IVAR,"mean");
3366 addopcodepfield(newsym, S_IVAR,"var");
3367 return newsym;
3368 }
3369 if (!(strcmp(tptr->val,"iir")))
3370 {
3371 newsym = createopcode(tptr, nametable, S_AOPCODE);
3372 addopcodepfield(newsym, S_ASIG,"input");
3373 addopcodepfield(newsym, S_KSIG,"b0");
3374 return newsym;
3375 }
3376 if (!(strcmp(tptr->val,"iirt")))
3377 {
3378 newsym = createopcode(tptr, nametable, S_AOPCODE);
3379 addopcodepfield(newsym, S_ASIG,"input");
3380 addopcodepfield(newsym, S_TABLE,"a");
3381 addopcodepfield(newsym, S_TABLE,"b");
3382 addopcodevar(newsym, S_TABLE,"dline");
3383 addopcodevar(newsym, S_ASIG,"kcyc");
3384 return newsym;
3385 }
3386 if (!(strcmp(tptr->val,"ilinrand")))
3387 {
3388 newsym = createopcode(tptr, nametable, S_IOPCODE);
3389 addopcodepfield(newsym, S_IVAR,"p1");
3390 addopcodepfield(newsym, S_IVAR,"p2");
3391 return newsym;
3392 }
3393 if (!(strcmp(tptr->val,"int")))
3394 return oneargopcode(tptr, nametable);
3395 if (!(strcmp(tptr->val,"irand")))
3396 {
3397 newsym = createopcode(tptr, nametable, S_IOPCODE);
3398 addopcodepfield(newsym, S_IVAR,"p");
3399 return newsym;
3400 }
3401 return NULL;
3402 case 'j':
3403 return NULL;
3404 case 'k':
3405 if (!(strcmp(tptr->val,"kexpon")))
3406 {
3407 newsym = createopcode(tptr, nametable, S_KOPCODE);
3408 addopcodepfield(newsym, S_IVAR,"x1");
3409 addopcodepfield(newsym, S_IVAR,"dur1");
3410 addopcodepfield(newsym, S_IVAR,"x2");
3411 addopcodevar(newsym, S_KSIG,"t");
3412 addopcodevar(newsym, S_KSIG,"clp");
3413 addopcodevar(newsym, S_KSIG,"crp");
3414 addopcodevar(newsym, S_KSIG,"cdur");
3415 addopcodevar(newsym, S_KSIG,"ratio");
3416 addopcodevar(newsym, S_KSIG,"invcdur");
3417 addopcodevar(newsym, S_KSIG,"outT");
3418 addopcodevar(newsym, S_KSIG,"multK");
3419 addopcodevar(newsym, S_KSIG,"first");
3420 return newsym;
3421 }
3422 if (!(strcmp(tptr->val,"kexprand")))
3423 {
3424 newsym = createopcode(tptr, nametable, S_KOPCODE);
3425 addopcodepfield(newsym, S_KSIG,"p1");
3426 return newsym;
3427 }
3428 if (!(strcmp(tptr->val,"kgaussrand")))
3429 {
3430 newsym = createopcode(tptr, nametable, S_KOPCODE);
3431 addopcodepfield(newsym, S_KSIG,"mean");
3432 addopcodepfield(newsym, S_KSIG,"var");
3433 return newsym;
3434 }
3435 if (!(strcmp(tptr->val,"kline")))
3436 {
3437 newsym = createopcode(tptr, nametable, S_KOPCODE);
3438 addopcodepfield(newsym, S_IVAR,"x1");
3439 addopcodepfield(newsym, S_IVAR,"dur1");
3440 addopcodepfield(newsym, S_IVAR,"x2");
3441 addopcodevar(newsym, S_KSIG,"t");
3442 addopcodevar(newsym, S_KSIG,"clp");
3443 addopcodevar(newsym, S_KSIG,"crp");
3444 addopcodevar(newsym, S_KSIG,"cdur");
3445 addopcodevar(newsym, S_KSIG,"mult");
3446 addopcodevar(newsym, S_KSIG,"outT");
3447 addopcodevar(newsym, S_KSIG,"addK");
3448 addopcodevar(newsym, S_KSIG,"first");
3449 return newsym;
3450 }
3451 if (!(strcmp(tptr->val,"klinrand")))
3452 {
3453 newsym = createopcode(tptr, nametable, S_KOPCODE);
3454 addopcodepfield(newsym, S_KSIG,"p1");
3455 addopcodepfield(newsym, S_KSIG,"p2");
3456 return newsym;
3457 }
3458 if (!(strcmp(tptr->val,"koscil")))
3459 {
3460 newsym = createopcode(tptr, nametable, S_KOPCODE);
3461 addopcodepfield(newsym, S_TABLE,"t");
3462 addopcodepfield(newsym, S_KSIG,"freq");
3463 addopcodevar(newsym, S_ASIG,"iloops");
3464 addopcodevar(newsym, S_KSIG,"first");
3465 addopcodevar(newsym, S_ASIG,"pint");
3466 addopcodevar(newsym, S_ASIG,"pfrac");
3467 addopcodevar(newsym, S_ASIG,"kconst");
3468 return newsym;
3469 }
3470 if (!(strcmp(tptr->val,"kphasor")))
3471 {
3472 newsym = createopcode(tptr, nametable, S_KOPCODE);
3473 addopcodepfield(newsym, S_KSIG,"cps");
3474 addopcodevar(newsym, S_ASIG,"pint");
3475 addopcodevar(newsym, S_ASIG,"pfrac");
3476 addopcodevar(newsym, S_ASIG,"kcyc");
3477 return newsym;
3478 }
3479 if (!(strcmp(tptr->val,"kpoissonrand")))
3480 {
3481 newsym = createopcode(tptr, nametable, S_KOPCODE);
3482 addopcodepfield(newsym, S_KSIG,"p1");
3483 addopcodevar(newsym, S_KSIG,"state");
3484 return newsym;
3485 }
3486 if (!(strcmp(tptr->val,"krand")))
3487 {
3488 newsym = createopcode(tptr, nametable, S_KOPCODE);
3489 addopcodepfield(newsym, S_KSIG,"p");
3490 return newsym;
3491 }
3492 return NULL;
3493 case 'l':
3494 if (!(strcmp(tptr->val,"log")))
3495 return oneargopcode(tptr, nametable);
3496 if (!(strcmp(tptr->val,"log10")))
3497 return oneargopcode(tptr, nametable);
3498 if (!(strcmp(tptr->val,"lopass")))
3499 {
3500 newsym = createopcode(tptr, nametable, S_AOPCODE);
3501 addopcodepfield(newsym, S_ASIG,"input");
3502 addopcodepfield(newsym, S_KSIG,"cut");
3503 addopcodevar(newsym, S_ASIG,"kcyc");
3504 addopcodevar(newsym, S_ASIG,"ocut");
3505 addopcodevar(newsym, S_ASIG,"b0");
3506 addopcodevar(newsym, S_ASIG,"b1");
3507 addopcodevar(newsym, S_ASIG,"b2");
3508 addopcodevar(newsym, S_ASIG,"a1");
3509 addopcodevar(newsym, S_ASIG,"a2");
3510 addopcodevar(newsym, S_ASIG,"d1");
3511 addopcodevar(newsym, S_ASIG,"d2");
3512 return newsym;
3513 }
3514 if (!(strcmp(tptr->val,"loscil")))
3515 {
3516 newsym = createopcode(tptr, nametable, S_AOPCODE);
3517 addopcodepfield(newsym, S_TABLE,"t");
3518 addopcodepfield(newsym, S_ASIG,"freq");
3519 addopcodevar(newsym, S_ASIG,"kcyc");
3520 addopcodevar(newsym, S_ASIG,"lconst");
3521 addopcodevar(newsym, S_ASIG,"pint");
3522 addopcodevar(newsym, S_ASIG,"pfrac");
3523 addopcodevar(newsym, S_ASIG,"dint");
3524 addopcodevar(newsym, S_ASIG,"tstartint");
3525 addopcodevar(newsym, S_ASIG,"tendint");
3526 addopcodevar(newsym, S_ASIG,"rollover");
3527 addopcodevar(newsym, S_ASIG,"stamp");
3528 if (interp == INTERP_SINC)
3529 addopcodevar(newsym, S_ASIG,"second");
3530 return newsym;
3531 }
3532 return NULL;
3533 case 'm':
3534 if (!(strcmp(tptr->val,"max")))
3535 {
3536 newsym = createopcode(tptr, nametable, S_OPCODE);
3537 addopcodepfield(newsym, S_XSIG,"x1");
3538 return newsym;
3539 }
3540 if (!(strcmp(tptr->val,"midicps")))
3541 return oneargopcode(tptr, nametable);
3542 if (!(strcmp(tptr->val,"midioct")))
3543 return oneargopcode(tptr, nametable);
3544 if (!(strcmp(tptr->val,"midipch")))
3545 return oneargopcode(tptr, nametable);
3546 if (!(strcmp(tptr->val,"min")))
3547 {
3548 newsym = createopcode(tptr, nametable, S_OPCODE);
3549 addopcodepfield(newsym, S_XSIG,"x1");
3550 return newsym;
3551 }
3552 return NULL;
3553 case 'n':
3554 return NULL;
3555 case 'o':
3556 if (!(strcmp(tptr->val,"octcps")))
3557 return oneargopcode(tptr, nametable);
3558 if (!(strcmp(tptr->val,"octmidi")))
3559 return oneargopcode(tptr, nametable);
3560 if (!(strcmp(tptr->val,"octpch")))
3561 return oneargopcode(tptr, nametable);
3562 if (!(strcmp(tptr->val,"oscil")))
3563 {
3564 newsym = createopcode(tptr, nametable, S_AOPCODE);
3565 addopcodepfield(newsym, S_TABLE,"t");
3566 addopcodepfield(newsym, S_ASIG,"freq");
3567 addopcodevar(newsym, S_ASIG,"iloops");
3568 addopcodevar(newsym, S_ASIG,"kcyc");
3569 addopcodevar(newsym, S_ASIG,"pint");
3570 addopcodevar(newsym, S_ASIG,"pfrac");
3571 addopcodevar(newsym, S_ASIG,"kint");
3572 addopcodevar(newsym, S_ASIG,"kfrac");
3573 addopcodevar(newsym, S_ASIG,"fsign");
3574 if (interp == INTERP_SINC)
3575 {
3576 addopcodevar(newsym, S_ASIG,"sffl");
3577 addopcodevar(newsym, S_ASIG,"sfui");
3578 addopcodevar(newsym, S_ASIG,"osincr");
3579 }
3580 return newsym;
3581 }
3582 return NULL;
3583 case 'p':
3584 if (!(strcmp(tptr->val,"pchcps")))
3585 return oneargopcode(tptr, nametable);
3586 if (!(strcmp(tptr->val,"pchmidi")))
3587 return oneargopcode(tptr, nametable);
3588 if (!(strcmp(tptr->val,"pchoct")))
3589 return oneargopcode(tptr, nametable);
3590 if (!(strcmp(tptr->val,"pluck")))
3591 {
3592 newsym = createopcode(tptr, nametable, S_AOPCODE);
3593 addopcodepfield(newsym, S_ASIG,"cps");
3594 addopcodepfield(newsym, S_IVAR,"buflen");
3595 addopcodepfield(newsym, S_TABLE,"init");
3596 addopcodepfield(newsym, S_KSIG,"atten");
3597 addopcodepfield(newsym, S_KSIG,"smoothrate");
3598 addopcodevar(newsym, S_ASIG,"pint");
3599 addopcodevar(newsym, S_ASIG,"pfrac");
3600 addopcodevar(newsym, S_ASIG,"oconst");
3601 addopcodevar(newsym, S_ASIG,"sc");
3602 addopcodevar(newsym, S_ASIG,"first");
3603 addopcodevar(newsym, S_TABLE,"t");
3604 addopcodevar(newsym, S_TABLE,"ts");
3605 return newsym;
3606 }
3607 if (!(strcmp(tptr->val,"port")))
3608 {
3609 newsym = createopcode(tptr, nametable, S_KOPCODE);
3610 addopcodepfield(newsym, S_KSIG,"ctrl");
3611 addopcodepfield(newsym, S_KSIG,"htime");
3612 addopcodevar(newsym, S_KSIG,"new");
3613 addopcodevar(newsym, S_KSIG,"curr");
3614 addopcodevar(newsym, S_KSIG,"int");
3615 addopcodevar(newsym, S_KSIG,"ohtime");
3616 addopcodevar(newsym, S_KSIG,"sl");
3617 addopcodevar(newsym, S_KSIG,"first");
3618 addopcodevar(newsym, S_KSIG,"done");
3619 return newsym;
3620 }
3621 if (!(strcmp(tptr->val,"pow")))
3622 {
3623 newsym = createopcode(tptr, nametable, S_OPCODE);
3624 addopcodepfield(newsym, S_XSIG,"x");
3625 addopcodepfield(newsym, S_XSIG,"y");
3626 return newsym;
3627 }
3628 return NULL;
3629 case 'q':
3630 return NULL;
3631 case 'r':
3632 if (!(strcmp(tptr->val,"reverb")))
3633 {
3634 newsym = createopcode(tptr, nametable, S_AOPCODE);
3635 addopcodepfield(newsym, S_ASIG,"x");
3636 addopcodepfield(newsym, S_IVAR,"f0");
3637 addopcodevar(newsym, S_TABLE,"ap1");
3638 addopcodevar(newsym, S_TABLE,"ap2");
3639 addopcodevar(newsym, S_TABLE,"dline0_0");
3640 addopcodevar(newsym, S_TABLE,"dline0_1");
3641 addopcodevar(newsym, S_TABLE,"dline0_2");
3642 addopcodevar(newsym, S_TABLE,"dline0_3");
3643 addopcodevar(newsym, S_IVAR,"g0_0");
3644 addopcodevar(newsym, S_IVAR,"g0_1");
3645 addopcodevar(newsym, S_IVAR,"g0_2");
3646 addopcodevar(newsym, S_IVAR,"g0_3");
3647 return newsym;
3648 }
3649 if (!(strcmp(tptr->val,"rms")))
3650 {
3651 newsym = createopcode(tptr, nametable, S_SOPCODE);
3652 addopcodepfield(newsym, S_ASIG,"x");
3653 addopcodevar(newsym, S_ASIG,"kcyc");
3654 addopcodevar(newsym, S_ASIG,"scale");
3655 addopcodevar(newsym, S_TABLE,"buffer");
3656 return newsym;
3657 }
3658 return NULL;
3659 case 's':
3660 if (!(strcmp(tptr->val,"samphold")))
3661 {
3662 newsym = createopcode(tptr, nametable, S_OPCODE);
3663 addopcodepfield(newsym, S_XSIG,"input");
3664 addopcodepfield(newsym, S_KSIG,"gate");
3665 addopcodevar(newsym, S_XSIG,"lpv");
3666 return newsym;
3667 }
3668 if (!(strcmp(tptr->val,"sblock")))
3669 {
3670 newsym = createopcode(tptr, nametable, S_SOPCODE);
3671 addopcodepfield(newsym, S_ASIG,"x");
3672 addopcodepfield(newsym, S_TABLE,"t");
3673 addopcodevar(newsym, S_ASIG,"idx");
3674 addopcodevar(newsym, S_ASIG,"kcyc");
3675 return newsym;
3676 }
3677 if (!(strcmp(tptr->val,"settempo")))
3678 {
3679 newsym = createopcode(tptr, nametable, S_KOPCODE);
3680 addopcodepfield(newsym, S_KSIG,"x");
3681 return newsym;
3682 }
3683 if (!(strcmp(tptr->val,"settune")))
3684 {
3685 newsym = createopcode(tptr, nametable, S_OPCODE);
3686 addopcodepfield(newsym, S_XSIG,"x");
3687 return newsym;
3688 }
3689 if (!(strcmp(tptr->val,"sgn")))
3690 return oneargopcode(tptr, nametable);
3691 if (!(strcmp(tptr->val,"sin")))
3692 return oneargopcode(tptr, nametable);
3693 if (!(strcmp(tptr->val,"spatialize")))
3694 {
3695 newsym = createopcode(tptr, nametable, S_OPCODE);
3696 addopcodepfield(newsym, S_ASIG,"x");
3697 addopcodepfield(newsym, S_KSIG,"azimuth");
3698 addopcodepfield(newsym, S_KSIG,"elevation");
3699 addopcodepfield(newsym, S_KSIG,"distance");
3700 addopcodevar(newsym, S_ASIG,"kcyc");
3701 addopcodevar(newsym, S_ASIG,"oaz");
3702 addopcodevar(newsym, S_ASIG,"oel");
3703
3704 addopcodevar(newsym, S_ASIG,"odis");
3705 addopcodevar(newsym, S_ASIG,"dis_b0");
3706 addopcodevar(newsym, S_ASIG,"dis_b1");
3707 addopcodevar(newsym, S_ASIG,"dis_b2");
3708 addopcodevar(newsym, S_ASIG,"dis_a1");
3709 addopcodevar(newsym, S_ASIG,"dis_a2");
3710 addopcodevar(newsym, S_ASIG,"dis_d1");
3711 addopcodevar(newsym, S_ASIG,"dis_d2");
3712
3713 addopcodevar(newsym, S_ASIG,"t0");
3714 addopcodevar(newsym, S_ASIG,"i0");
3715 addopcodevar(newsym, S_ASIG,"t1");
3716 addopcodevar(newsym, S_ASIG,"i1");
3717 addopcodevar(newsym, S_ASIG,"t2");
3718 addopcodevar(newsym, S_ASIG,"i2");
3719 addopcodevar(newsym, S_ASIG,"t3");
3720 addopcodevar(newsym, S_ASIG,"i3");
3721 addopcodevar(newsym, S_ASIG,"t4");
3722 addopcodevar(newsym, S_ASIG,"i4");
3723 addopcodevar(newsym, S_ASIG,"t5");
3724 addopcodevar(newsym, S_ASIG,"i5");
3725 addopcodevar(newsym, S_ASIG,"t6");
3726 addopcodevar(newsym, S_ASIG,"i6");
3727
3728 addopcodevar(newsym, S_TABLE,"d0");
3729 addopcodevar(newsym, S_TABLE,"d1");
3730 addopcodevar(newsym, S_TABLE,"d2");
3731 addopcodevar(newsym, S_TABLE,"d3");
3732 addopcodevar(newsym, S_TABLE,"d4");
3733 addopcodevar(newsym, S_TABLE,"d5");
3734 addopcodevar(newsym, S_TABLE,"d6");
3735 addopcodevar(newsym, S_TABLE,"d7");
3736
3737 addopcodevar(newsym, S_ASIG,"az_b0L");
3738 addopcodevar(newsym, S_ASIG,"az_b0R");
3739 addopcodevar(newsym, S_ASIG,"az_b1L");
3740 addopcodevar(newsym, S_ASIG,"az_b1R");
3741 addopcodevar(newsym, S_ASIG,"az_a1");
3742 addopcodevar(newsym, S_ASIG,"az_d1L");
3743 addopcodevar(newsym, S_ASIG,"az_d1R");
3744
3745 return newsym;
3746 }
3747 if (!(strcmp(tptr->val,"speedt")))
3748 {
3749 newsym = createopcode(tptr, nametable, S_IOPCODE);
3750 addopcodepfield(newsym, S_TABLE,"in");
3751 addopcodepfield(newsym, S_TABLE,"out");
3752 addopcodepfield(newsym, S_IVAR,"factor");
3753 return newsym;
3754 }
3755 if (!(strcmp(tptr->val,"sqrt")))
3756 return oneargopcode(tptr, nametable);
3757 return NULL;
3758 case 't':
3759 if (!(strcmp(tptr->val,"tableread")))
3760 {
3761 newsym = createopcode(tptr, nametable, S_OPCODE);
3762 addopcodepfield(newsym, S_TABLE,"t");
3763 addopcodepfield(newsym, S_XSIG,"index");
3764 return newsym;
3765 }
3766 if (!(strcmp(tptr->val,"tablewrite")))
3767 {
3768 newsym = createopcode(tptr, nametable, S_OPCODE);
3769 addopcodepfield(newsym, S_TABLE,"t");
3770 addopcodepfield(newsym, S_XSIG,"index");
3771 addopcodepfield(newsym, S_XSIG,"val");
3772 return newsym;
3773 }
3774 return NULL;
3775 case 'u':
3776 if (!(strcmp(tptr->val,"upsamp")))
3777 {
3778 newsym = createopcode(tptr, nametable, S_AOPCODE);
3779 addopcodepfield(newsym, S_ASIG,"input");
3780 addopcodevar(newsym, S_TABLE,"buffer");
3781 addopcodevar(newsym, S_ASIG,"kcyc");
3782 return newsym;
3783 }
3784 return NULL;
3785 case 'v':
3786 return NULL;
3787 case 'w':
3788 return NULL;
3789 case 'x':
3790 return NULL;
3791 case 'y':
3792 return NULL;
3793 case 'z':
3794 return NULL;
3795 }
3796 return NULL;
3797 }
3798
3799 /*********************************************************/
3800 /* checks that extra params are scalar non-tables */
3801 /*********************************************************/
3802
extracheckargs(tnode * tcall,tnode * tptr)3803 void extracheckargs(tnode * tcall, tnode * tptr)
3804
3805 {
3806 tablecheck(tptr);
3807 if (truewidth(tptr->width) != 1)
3808 {
3809 printf("Error: Opcode (varargs) call width mismatch.\n");
3810 showerrorplace(tcall->optr->down->linenum,
3811 tcall->optr->down->filename);
3812 }
3813 }
3814
3815 /*********************************************************/
3816 /* identifies opcodes with variable arguments */
3817 /*********************************************************/
3818
coreopcodeargs(tnode * tcall,tnode * textra)3819 int coreopcodeargs(tnode * tcall, tnode * textra)
3820
3821
3822 {
3823 tnode * tptr;
3824 int i,j;
3825 char name[32];
3826
3827 if (tcall->extra != NULL) /* earlier call created variables, */
3828 return 1; /* did arg count, */
3829
3830 if ((!(strcmp(tcall->val,"max")))||(!(strcmp(tcall->val,"min"))))
3831 {
3832 tptr = textra;
3833 i = 2;
3834 while (tptr != NULL)
3835 {
3836 if (tptr->ttype == S_EXPR)
3837 {
3838 extracheckargs(tcall, tptr);
3839 sprintf(name,"x%i",i);
3840 addextraparam(tcall, S_XSIG, dupval(name));
3841 i++;
3842 }
3843 tptr = tptr->next;
3844 }
3845 return 1;
3846 }
3847
3848 if ((!(strcmp(tcall->val,"gettune")))||(!(strcmp(tcall->val,"gettempo"))))
3849 {
3850 tptr = textra;
3851 i = 1;
3852 while (tptr != NULL)
3853 {
3854 if (tptr->ttype == S_EXPR)
3855 {
3856 if (i>1)
3857 {
3858 printf("Error: Too many parameters.\n");
3859 showerrorplace(tcall->optr->down->linenum,
3860 tcall->optr->down->filename);
3861 }
3862 extracheckargs(tcall, tptr);
3863 sprintf(name,"dummy");
3864 addextraparam(tcall, S_XSIG, dupval(name));
3865 i++;
3866 }
3867 tptr = tptr->next;
3868 }
3869 return 1;
3870 }
3871
3872 if ((!(strcmp(tcall->val,"firt")))||(!(strcmp(tcall->val,"iirt"))))
3873 {
3874 tptr = textra;
3875 i = 1;
3876 while (tptr != NULL)
3877 {
3878 if (tptr->ttype == S_EXPR)
3879 {
3880 if (i>1)
3881 {
3882 printf("Error: Too many parameters.\n");
3883 showerrorplace(tcall->optr->down->linenum,
3884 tcall->optr->down->filename);
3885 }
3886 extracheckargs(tcall, tptr);
3887 sprintf(name,"order");
3888 addextraparam(tcall, S_KSIG, dupval(name));
3889 i++;
3890 }
3891 tptr = tptr->next;
3892 }
3893 return 1;
3894 }
3895
3896 if ((!(strcmp(tcall->val,"gain")))||(!(strcmp(tcall->val,"balance")))
3897 ||(!(strcmp(tcall->val,"rms"))))
3898 {
3899 tptr = textra;
3900 i = 1;
3901 while (tptr != NULL)
3902 {
3903 if (tptr->ttype == S_EXPR)
3904 {
3905 if (i>1)
3906 {
3907 printf("Error: Too many parameters.\n");
3908 showerrorplace(tcall->optr->down->linenum,
3909 tcall->optr->down->filename);
3910 }
3911 extracheckargs(tcall, tptr);
3912 sprintf(name,"length");
3913 addextraparam(tcall, S_IVAR, dupval(name));
3914 i++;
3915 }
3916 tptr = tptr->next;
3917 }
3918 return 1;
3919 }
3920
3921 if ((!(strcmp(tcall->val,"upsamp")))||(!(strcmp(tcall->val,"downsamp"))))
3922 {
3923 tptr = textra;
3924 i = 1;
3925 while (tptr != NULL)
3926 {
3927 if (tptr->ttype == S_EXPR)
3928 {
3929 if (i>1)
3930 {
3931 printf("Error: Too many parameters.\n");
3932 showerrorplace(tcall->optr->down->linenum,
3933 tcall->optr->down->filename);
3934 }
3935 if (tptr->vartype != TABLETYPE)
3936 {
3937 printf("Error: Parameter must be a table.\n");
3938 showerrorplace(tcall->optr->down->linenum,
3939 tcall->optr->down->filename);
3940 }
3941 sprintf(name,"win");
3942 addextraparam(tcall, S_TABLE, dupval(name));
3943 i++;
3944 }
3945 tptr = tptr->next;
3946 }
3947 return 1;
3948 }
3949
3950 if ((!(strcmp(tcall->val,"oscil")))||(!(strcmp(tcall->val,"koscil"))) )
3951 {
3952 tptr = textra;
3953 i = 1;
3954 while (tptr != NULL)
3955 {
3956 if (tptr->ttype == S_EXPR)
3957 {
3958 if (i>1)
3959 {
3960 printf("Error: Too many parameters.\n");
3961 showerrorplace(tcall->optr->down->linenum,
3962 tcall->optr->down->filename);
3963 }
3964 extracheckargs(tcall, tptr);
3965 sprintf(name,"loops");
3966 addextraparam(tcall, S_IVAR, dupval(name));
3967 i++;
3968 }
3969 tptr = tptr->next;
3970 }
3971 return 1;
3972 }
3973
3974 if (!(strcmp(tcall->val,"loscil")))
3975 {
3976 tptr = textra;
3977 i = 1;
3978 while (tptr != NULL)
3979 {
3980 if (tptr->ttype == S_EXPR)
3981 {
3982 if (i>3)
3983 {
3984 printf("Error: Too many parameters.\n");
3985 showerrorplace(tcall->optr->down->linenum,
3986 tcall->optr->down->filename);
3987 }
3988 extracheckargs(tcall, tptr);
3989 switch (i) {
3990 case 1:
3991 sprintf(name,"basefreq");
3992 break;
3993 case 2:
3994 sprintf(name,"loopstart");
3995 break;
3996 case 3:
3997 sprintf(name,"loopend");
3998 break;
3999 default:
4000 internalerror("corevars.c","case default");
4001 }
4002 addextraparam(tcall, S_IVAR, dupval(name));
4003 i++;
4004 }
4005 tptr = tptr->next;
4006 }
4007 return 1;
4008 }
4009
4010 if (!(strcmp(tcall->val,"fracdelay")))
4011 {
4012 tptr = textra;
4013 i = 1;
4014 while (tptr != NULL)
4015 {
4016 if (tptr->ttype == S_EXPR)
4017 {
4018 if (i>2)
4019 {
4020 printf("Error: Too many parameters.\n");
4021 showerrorplace(tcall->optr->down->linenum,
4022 tcall->optr->down->filename);
4023 }
4024 extracheckargs(tcall, tptr);
4025 switch (i) {
4026 case 1:
4027 addextraparam(tcall, S_XSIG, "p1");
4028 break;
4029 case 2:
4030 addextraparam(tcall, S_XSIG, "p2");
4031 break;
4032 default:
4033 internalerror("corevars.c","case default");
4034 }
4035 i++;
4036 }
4037 tptr = tptr->next;
4038 }
4039 return 1;
4040 }
4041
4042 if ((!(strcmp(tcall->val,"fft")))||(!(strcmp(tcall->val,"ifft"))))
4043 {
4044 tptr = textra;
4045 i = 1;
4046 while (tptr != NULL)
4047 {
4048 if (tptr->ttype == S_EXPR)
4049 {
4050 switch (i) {
4051 case 1:
4052 extracheckargs(tcall, tptr);
4053 addextraparam(tcall, S_IVAR, "len");
4054 break;
4055 case 2:
4056 extracheckargs(tcall, tptr);
4057 addextraparam(tcall, S_IVAR, "shift");
4058 break;
4059 case 3:
4060 extracheckargs(tcall, tptr);
4061 addextraparam(tcall, S_IVAR, "size");
4062 break;
4063 case 4:
4064 if (tptr->vartype != TABLETYPE)
4065 {
4066 printf("Error: Parameter must be a table.\n");
4067 showerrorplace(tcall->optr->down->linenum,
4068 tcall->optr->down->filename);
4069 }
4070 addextraparam(tcall, S_TABLE, "win");
4071 break;
4072 default:
4073 {
4074 printf("Error: Too many parameters.\n");
4075 showerrorplace(tcall->optr->down->linenum,
4076 tcall->optr->down->filename);
4077 }
4078 }
4079 i++;
4080 }
4081 tptr = tptr->next;
4082 }
4083 return 1;
4084 }
4085
4086 if ((!(strcmp(tcall->val,"aline")))||(!(strcmp(tcall->val,"kline")))||
4087 (!(strcmp(tcall->val,"aexpon")))||(!(strcmp(tcall->val,"kexpon"))))
4088 {
4089 tptr = textra;
4090 i = 2; j = 0;
4091 while (tptr != NULL)
4092 {
4093 if (tptr->ttype == S_EXPR)
4094 {
4095 extracheckargs(tcall, tptr);
4096 switch (j) {
4097 case 0:
4098 j = 1;
4099 sprintf(name,"dur%i",i);
4100 break;
4101 case 1:
4102 j = 0; i++;
4103 sprintf(name,"x%i",i);
4104 break;
4105 default:
4106 internalerror("corevars.c","case default");
4107 }
4108 addextraparam(tcall, S_IVAR, dupval(name));
4109 }
4110 tptr = tptr->next;
4111 }
4112 if (j == 1)
4113 {
4114 printf("Error: Even number of parameters.\n");
4115 showerrorplace(tcall->optr->down->linenum,
4116 tcall->optr->down->filename);
4117 }
4118 return 1;
4119 }
4120
4121 if (!(strcmp(tcall->val,"fir")))
4122 {
4123 tptr = textra;
4124 i = 1;
4125 while (tptr != NULL)
4126 {
4127 if (tptr->ttype == S_EXPR)
4128 {
4129 extracheckargs(tcall, tptr);
4130 sprintf(name,"b%i",i);
4131 addextraparam(tcall, S_KSIG, dupval(name));
4132 i++;
4133 }
4134 tptr = tptr->next;
4135 }
4136 j = 1;
4137 while (j<i)
4138 {
4139 sprintf(name,"z%i",j);
4140 addvsym(&(tcall->optr->sptr->defnode->sptr),name,K_NORMAL);
4141 tcall->optr->sptr->defnode->sptr->width = 1;
4142 tcall->optr->sptr->defnode->sptr->rate = ARATETYPE;
4143 j++;
4144 }
4145 return 1;
4146 }
4147
4148 if (!(strcmp(tcall->val,"iir")))
4149 {
4150 tptr = textra;
4151 i = 1;
4152 j = 0;
4153 while (tptr != NULL)
4154 {
4155 if (tptr->ttype == S_EXPR)
4156 {
4157 extracheckargs(tcall, tptr);
4158 if ((i % 2) == 1)
4159 {
4160 sprintf(name,"a%i",(i/2)+1);
4161 j++;
4162 }
4163 else
4164 sprintf(name,"b%i",(i/2));
4165 addextraparam(tcall, S_KSIG, dupval(name));
4166 i++;
4167 }
4168 tptr = tptr->next;
4169 }
4170 while (j>0)
4171 {
4172 sprintf(name,"d%i",j);
4173 addvsym(&(tcall->optr->sptr->defnode->sptr),name,K_NORMAL);
4174 tcall->optr->sptr->defnode->sptr->width = 1;
4175 tcall->optr->sptr->defnode->sptr->rate = ARATETYPE;
4176 j--;
4177 }
4178 return 1;
4179 }
4180
4181 if (!(strcmp(tcall->val,"reverb")))
4182 {
4183 tptr = textra;
4184 i = 1; j = 0;
4185 while (tptr != NULL)
4186 {
4187 if (tptr->ttype == S_EXPR)
4188 {
4189 extracheckargs(tcall, tptr);
4190 if ((i % 2) == 1)
4191 {
4192 sprintf(name,"r%i",(i/2));
4193 }
4194 else
4195 {
4196 sprintf(name,"f%i",(i/2));
4197 j++;
4198 }
4199 addextraparam(tcall, S_IVAR, dupval(name));
4200 i++;
4201 }
4202 tptr = tptr->next;
4203 }
4204 if ((i % 2) == 1)
4205 {
4206 printf("Error: F without an R pair.\n");
4207 showerrorplace(tcall->optr->down->linenum,
4208 tcall->optr->down->filename);
4209 }
4210 if (i >= 2)
4211 {
4212 sprintf(name,"d2_0");
4213 addvsym(&(tcall->optr->sptr->defnode->sptr),name,K_NORMAL);
4214 tcall->optr->sptr->defnode->sptr->width = 1;
4215 tcall->optr->sptr->defnode->sptr->rate = IRATETYPE;
4216
4217 sprintf(name,"d1_0");
4218 addvsym(&(tcall->optr->sptr->defnode->sptr),name,K_NORMAL);
4219 tcall->optr->sptr->defnode->sptr->width = 1;
4220 tcall->optr->sptr->defnode->sptr->rate = IRATETYPE;
4221
4222 sprintf(name,"b0_0");
4223 addvsym(&(tcall->optr->sptr->defnode->sptr),name,K_NORMAL);
4224 tcall->optr->sptr->defnode->sptr->width = 1;
4225 tcall->optr->sptr->defnode->sptr->rate = IRATETYPE;
4226
4227 sprintf(name,"b1_0");
4228 addvsym(&(tcall->optr->sptr->defnode->sptr),name,K_NORMAL);
4229 tcall->optr->sptr->defnode->sptr->width = 1;
4230 tcall->optr->sptr->defnode->sptr->rate = IRATETYPE;
4231
4232 sprintf(name,"b2_0");
4233 addvsym(&(tcall->optr->sptr->defnode->sptr),name,K_NORMAL);
4234 tcall->optr->sptr->defnode->sptr->width = 1;
4235 tcall->optr->sptr->defnode->sptr->rate = IRATETYPE;
4236
4237 sprintf(name,"a1_0");
4238 addvsym(&(tcall->optr->sptr->defnode->sptr),name,K_NORMAL);
4239 tcall->optr->sptr->defnode->sptr->width = 1;
4240 tcall->optr->sptr->defnode->sptr->rate = IRATETYPE;
4241
4242 sprintf(name,"a2_0");
4243 addvsym(&(tcall->optr->sptr->defnode->sptr),name,K_NORMAL);
4244 tcall->optr->sptr->defnode->sptr->width = 1;
4245 tcall->optr->sptr->defnode->sptr->rate = IRATETYPE;
4246
4247 }
4248 while (j>0)
4249 {
4250 sprintf(name,"dline%i_0",j);
4251 addvsym(&(tcall->optr->sptr->defnode->sptr),name,K_NORMAL);
4252 tcall->optr->sptr->defnode->sptr->width = 1;
4253 tcall->optr->sptr->defnode->sptr->rate = IRATETYPE;
4254 tcall->optr->sptr->defnode->sptr->vartype = TABLETYPE;
4255 tcall->optr->sptr->defnode->sptr->kind = K_INTERNAL;
4256
4257 sprintf(name,"dline%i_1",j);
4258 addvsym(&(tcall->optr->sptr->defnode->sptr),name,K_NORMAL);
4259 tcall->optr->sptr->defnode->sptr->width = 1;
4260 tcall->optr->sptr->defnode->sptr->rate = IRATETYPE;
4261 tcall->optr->sptr->defnode->sptr->vartype = TABLETYPE;
4262 tcall->optr->sptr->defnode->sptr->kind = K_INTERNAL;
4263
4264 sprintf(name,"dline%i_2",j);
4265 addvsym(&(tcall->optr->sptr->defnode->sptr),name,K_NORMAL);
4266 tcall->optr->sptr->defnode->sptr->width = 1;
4267 tcall->optr->sptr->defnode->sptr->rate = IRATETYPE;
4268 tcall->optr->sptr->defnode->sptr->vartype = TABLETYPE;
4269 tcall->optr->sptr->defnode->sptr->kind = K_INTERNAL;
4270
4271 sprintf(name,"dline%i_3",j);
4272 addvsym(&(tcall->optr->sptr->defnode->sptr),name,K_NORMAL);
4273 tcall->optr->sptr->defnode->sptr->width = 1;
4274 tcall->optr->sptr->defnode->sptr->rate = IRATETYPE;
4275 tcall->optr->sptr->defnode->sptr->vartype = TABLETYPE;
4276 tcall->optr->sptr->defnode->sptr->kind = K_INTERNAL;
4277
4278 sprintf(name,"g%i_0",j);
4279 addvsym(&(tcall->optr->sptr->defnode->sptr),name,K_NORMAL);
4280 tcall->optr->sptr->defnode->sptr->width = 1;
4281 tcall->optr->sptr->defnode->sptr->rate = IRATETYPE;
4282
4283 sprintf(name,"g%i_1",j);
4284 addvsym(&(tcall->optr->sptr->defnode->sptr),name,K_NORMAL);
4285 tcall->optr->sptr->defnode->sptr->width = 1;
4286 tcall->optr->sptr->defnode->sptr->rate = IRATETYPE;
4287
4288 sprintf(name,"g%i_2",j);
4289 addvsym(&(tcall->optr->sptr->defnode->sptr),name,K_NORMAL);
4290 tcall->optr->sptr->defnode->sptr->width = 1;
4291 tcall->optr->sptr->defnode->sptr->rate = IRATETYPE;
4292
4293 sprintf(name,"g%i_3",j);
4294 addvsym(&(tcall->optr->sptr->defnode->sptr),name,K_NORMAL);
4295 tcall->optr->sptr->defnode->sptr->width = 1;
4296 tcall->optr->sptr->defnode->sptr->rate = IRATETYPE;
4297
4298 sprintf(name,"d2_%i",j);
4299 addvsym(&(tcall->optr->sptr->defnode->sptr),name,K_NORMAL);
4300 tcall->optr->sptr->defnode->sptr->width = 1;
4301 tcall->optr->sptr->defnode->sptr->rate = IRATETYPE;
4302
4303 sprintf(name,"d1_%i",j);
4304 addvsym(&(tcall->optr->sptr->defnode->sptr),name,K_NORMAL);
4305 tcall->optr->sptr->defnode->sptr->width = 1;
4306 tcall->optr->sptr->defnode->sptr->rate = IRATETYPE;
4307
4308 sprintf(name,"b0_%i",j);
4309 addvsym(&(tcall->optr->sptr->defnode->sptr),name,K_NORMAL);
4310 tcall->optr->sptr->defnode->sptr->width = 1;
4311 tcall->optr->sptr->defnode->sptr->rate = IRATETYPE;
4312
4313 sprintf(name,"b1_%i",j);
4314 addvsym(&(tcall->optr->sptr->defnode->sptr),name,K_NORMAL);
4315 tcall->optr->sptr->defnode->sptr->width = 1;
4316 tcall->optr->sptr->defnode->sptr->rate = IRATETYPE;
4317
4318 sprintf(name,"b2_%i",j);
4319 addvsym(&(tcall->optr->sptr->defnode->sptr),name,K_NORMAL);
4320 tcall->optr->sptr->defnode->sptr->width = 1;
4321 tcall->optr->sptr->defnode->sptr->rate = IRATETYPE;
4322
4323 sprintf(name,"a1_%i",j);
4324 addvsym(&(tcall->optr->sptr->defnode->sptr),name,K_NORMAL);
4325 tcall->optr->sptr->defnode->sptr->width = 1;
4326 tcall->optr->sptr->defnode->sptr->rate = IRATETYPE;
4327
4328 sprintf(name,"a2_%i",j);
4329 addvsym(&(tcall->optr->sptr->defnode->sptr),name,K_NORMAL);
4330 tcall->optr->sptr->defnode->sptr->width = 1;
4331 tcall->optr->sptr->defnode->sptr->rate = IRATETYPE;
4332
4333
4334 j--;
4335 }
4336 return 1;
4337 }
4338
4339 return 0;
4340
4341 }
4342
4343
4344 /****************************************************************/
4345 /* add variable argument structures to opcode calls */
4346 /****************************************************************/
4347
coreopcodevarargs(tnode * tcall)4348 void coreopcodevarargs(tnode * tcall)
4349
4350 {
4351 tnode * tptr;
4352 tnode * dptr;
4353
4354 /* tptr holds actual arguments */
4355
4356 switch(tcall->ttype) {
4357 case S_OPCALL:
4358 tptr = tcall->optr->down->next->next->down;
4359 break;
4360 case S_OPARRAYCALL:
4361 tptr = tcall->optr->down->next->next->next->next->next->down;
4362 break;
4363 default:
4364 return;
4365 }
4366
4367 /* dptr holds formal arguments */
4368
4369 dptr = tcall->sptr->defnode->down->next->next->next->down;
4370
4371 if ((dptr != NULL) && (tptr == NULL))
4372 {
4373 printf("Error: Opcode call argument mismatch (%s).\n",
4374 tcall->optr->down->val);
4375 showerrorplace(tcall->optr->down->linenum,
4376 tcall->optr->down->filename);
4377 }
4378
4379 while (dptr != NULL)
4380 {
4381 if (dptr->ttype == S_PARAMDECL)
4382 {
4383 if (((tptr->vartype != TABLETYPE) && (dptr->vartype == TABLETYPE))||
4384 ((tptr->vartype == TABLETYPE) && (dptr->vartype != TABLETYPE))||
4385 (tptr->vartype == TMAPTYPE))
4386 {
4387 printf("Error: Opcode table parameter mismatch.\n");
4388 showerrorplace(tcall->optr->down->linenum,
4389 tcall->optr->down->filename);
4390 }
4391 }
4392 dptr = dptr->next;
4393 if (tptr == NULL)
4394 {
4395 printf("Error: Opcode call argument mismatch (%s).\n",
4396 tcall->optr->down->val);
4397 showerrorplace(tcall->optr->down->linenum,
4398 tcall->optr->down->filename);
4399 }
4400 tptr = tptr->next;
4401 }
4402
4403 if ((tptr != NULL) && (!coreopcodeargs(tcall,tptr)))
4404 {
4405 printf("Error: Opcode call argument mismatch (%s).\n",
4406 tcall->optr->down->val);
4407 showerrorplace(tcall->optr->down->linenum,
4408 tcall->optr->down->filename);
4409 }
4410
4411 }
4412
4413
4414
4415
4416
4417