File: ops2.c

package info (click to toggle)
yorick 1.4-14
  • links: PTS
  • area: main
  • in suites: potato
  • size: 5,948 kB
  • ctags: 6,609
  • sloc: ansic: 63,898; yacc: 889; makefile: 605; sh: 65; lisp: 60; fortran: 19
file content (1282 lines) | stat: -rw-r--r-- 44,419 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
/*
    OPS2.C
    Implement arithmetic binary operations:

    Add +   Subtract -   Multiply *   Divide /   Modulo %   Power ^
    Greater >   Less <   GreaterEQ >=   LessEQ <=   Equal ==   NotEqual !=

    $Id: ops2.c,v 1.1 1993/08/27 18:32:09 munro Exp $
 */
/*    Copyright (c) 1994.  The Regents of the University of California.
                    All rights reserved.  */

#include "ydata.h"
#include "defstr.h"

/*--------------------------------------------------------------------------*/

extern VMaction Power, Multiply, Divide, Modulo, Add, Subtract,
  ShiftL, ShiftR, Less, Greater, LessEQ, GreaterEQ, Equal, NotEqual;

extern StackOp AddII, AddIL, AddID, AddIB,
               AddLI, AddLL, AddLD, AddLB,
               AddDI, AddDL, AddDD, AddDB,
               AddBI, AddBL, AddBD, AddBB;
extern BinaryOp AddC, AddS, AddI, AddL,
                AddF, AddD, AddZ, AddQ, AddX;

extern StackOp SubtractII, SubtractIL, SubtractID, SubtractIB,
               SubtractLI, SubtractLL, SubtractLD, SubtractLB,
               SubtractDI, SubtractDL, SubtractDD, SubtractDB,
               SubtractBI, SubtractBL, SubtractBD, SubtractBB;
extern BinaryOp SubtractC, SubtractS, SubtractI, SubtractL,
                SubtractF, SubtractD, SubtractZ, SubtractX;

extern StackOp MultiplyII, MultiplyIL, MultiplyID, MultiplyIB,
               MultiplyLI, MultiplyLL, MultiplyLD, MultiplyLB,
               MultiplyDI, MultiplyDL, MultiplyDD, MultiplyDB,
               MultiplyBI, MultiplyBL, MultiplyBD, MultiplyBB;
extern BinaryOp MultiplyC, MultiplyS, MultiplyI, MultiplyL,
                MultiplyF, MultiplyD, MultiplyZ, MultiplyX;

extern StackOp DivideII, DivideIL, DivideID, DivideIB,
               DivideLI, DivideLL, DivideLD, DivideLB,
               DivideDI, DivideDL, DivideDD, DivideDB,
               DivideBI, DivideBL, DivideBD, DivideBB;
extern BinaryOp DivideC, DivideS, DivideI, DivideL,
                DivideF, DivideD, DivideZ, DivideX;

extern StackOp ModuloII, ModuloIL, ModuloID, ModuloIB,
               ModuloLI, ModuloLL, ModuloLD, ModuloLB,
               ModuloDI, ModuloDL, ModuloDD, ModuloDB,
               ModuloBI, ModuloBL, ModuloBD, ModuloBB;
extern BinaryOp ModuloC, ModuloS, ModuloI, ModuloL,
                ModuloF, ModuloD, ModuloZ, ModuloX;

extern StackOp PowerII, PowerIL, PowerID, PowerIB,
               PowerLI, PowerLL, PowerLD, PowerLB,
               PowerDI, PowerDL, PowerDD, PowerDB,
               PowerBI, PowerBL, PowerBD, PowerBB;
extern BinaryOp PowerC, PowerS, PowerI, PowerL,
                PowerF, PowerD, PowerZ, PowerX;

extern BinaryOp PowerXF, PowerXD, PowerXZ;

extern StackOp GreaterII, GreaterIL, GreaterID, GreaterIB,
               GreaterLI, GreaterLL, GreaterLD, GreaterLB,
               GreaterDI, GreaterDL, GreaterDD, GreaterDB,
               GreaterBI, GreaterBL, GreaterBD, GreaterBB;
extern BinaryOp GreaterC, GreaterS, GreaterI, GreaterL,
                GreaterF, GreaterD, GreaterZ, GreaterQ, GreaterX;

extern StackOp LessII, LessIL, LessID, LessIB,
               LessLI, LessLL, LessLD, LessLB,
               LessDI, LessDL, LessDD, LessDB,
               LessBI, LessBL, LessBD, LessBB;

extern StackOp GreaterEQII, GreaterEQIL, GreaterEQID, GreaterEQIB,
               GreaterEQLI, GreaterEQLL, GreaterEQLD, GreaterEQLB,
               GreaterEQDI, GreaterEQDL, GreaterEQDD, GreaterEQDB,
               GreaterEQBI, GreaterEQBL, GreaterEQBD, GreaterEQBB;
extern BinaryOp GreaterEQC, GreaterEQS, GreaterEQI, GreaterEQL,
                GreaterEQF, GreaterEQD, GreaterEQZ, GreaterEQQ, GreaterEQX;

extern StackOp LessEQII, LessEQIL, LessEQID, LessEQIB,
               LessEQLI, LessEQLL, LessEQLD, LessEQLB,
               LessEQDI, LessEQDL, LessEQDD, LessEQDB,
               LessEQBI, LessEQBL, LessEQBD, LessEQBB;

extern StackOp EqualII, EqualIL, EqualID, EqualIB,
               EqualLI, EqualLL, EqualLD, EqualLB,
               EqualDI, EqualDL, EqualDD, EqualDB,
               EqualBI, EqualBL, EqualBD, EqualBB;
extern BinaryOp EqualC, EqualS, EqualI, EqualL,
                EqualF, EqualD, EqualZ, EqualQ, EqualP,
                EqualSI, EqualR, EqualX;

extern StackOp NotEqualII, NotEqualIL, NotEqualID, NotEqualIB,
               NotEqualLI, NotEqualLL, NotEqualLD, NotEqualLB,
               NotEqualDI, NotEqualDL, NotEqualDD, NotEqualDB,
               NotEqualBI, NotEqualBL, NotEqualBD, NotEqualBB;
extern BinaryOp NotEqualC, NotEqualS, NotEqualI, NotEqualL,
                NotEqualF, NotEqualD, NotEqualZ, NotEqualQ, NotEqualP,
                NotEqualSI, NotEqualR, NotEqualX;

/*--------------------------------------------------------------------------*/

extern Operand *FormOperandIS(Symbol *owner, Operand *op);
extern Operand *FormOperandLS(Symbol *owner, Operand *op);
extern Operand *FormOperandDS(Symbol *owner, Operand *op);
extern Operand *FormOperandDB(Symbol *owner, Operand *op);

extern void PopToI(Symbol *s);
extern void PopToL(Symbol *s);
extern void PopToD(Symbol *s);

extern void *BuildResult2(Operand *l, Operand *r);
extern void *BuildResult1(Operand *l, Operand *r);
extern void *BuildResult0(Operand *l, Operand *r, StructDef *base);

extern double fmod(double, double);  /* required for real % operands */
#define RMOD(x,y) fmod((x),(y))
/* could also use x - y*floor(x/y), which differs for negative arguments */

/* Only one of the power operations is a standard C-library function */
extern double pow(double, double); /* pow is double-to-double in math.h */
extern long powLL(long, long);     /* powLL is long-to-long in nonc.c */
extern double powDL(double, long); /* powDL is double-to-long in nonc.c */
extern void powZL(double *, double *, long);
                                   /* powZL is complex-to-long in nonc.c */
extern void powZZ(double *, double *, double *);
                                   /* powZZ is complex-to-complex in nonc.c */

/*--------------------------------------------------------------------------*/

static Operand lop, rop;

/*--------------------------------------------------------------------------*/
/* Add */

void Add(void) { (sp-1)->ops->Add[sp->ops->id](); }

static void Add_BB(Operand *l, Operand *r);

void AddII(void) { Symbol *spr= sp--; sp->value.i+= spr->value.i; }
void AddIL(void) { Symbol *spr= sp--;
  sp->value.l= sp->value.i+spr->value.l; sp->ops= &longScalar; }
void AddID(void) { Symbol *spr= sp--;
  sp->value.d= sp->value.i+spr->value.d; sp->ops= &doubleScalar; }
void AddIB(void)
{ Add_BB(FormOperandIS(sp-1, &lop), FormOperandDB(sp, &rop)); }

void AddLI(void) { Symbol *spr= sp--; sp->value.l+= spr->value.i; }
void AddLL(void) { Symbol *spr= sp--; sp->value.l+= spr->value.l; }
void AddLD(void) { Symbol *spr= sp--;
  sp->value.d= sp->value.l+spr->value.d; sp->ops= &doubleScalar; }
void AddLB(void)
{ Add_BB(FormOperandLS(sp-1, &lop), FormOperandDB(sp, &rop)); }

void AddDI(void) { Symbol *spr= sp--; sp->value.d+= spr->value.i; }
void AddDL(void) { Symbol *spr= sp--; sp->value.d+= spr->value.l; }
void AddDD(void) { Symbol *spr= sp--; sp->value.d+= spr->value.d; }
void AddDB(void)
{ Add_BB(FormOperandDS(sp-1, &lop), FormOperandDB(sp, &rop)); }

void AddBI(void)
{ Add_BB(FormOperandDB(sp-1, &lop), FormOperandIS(sp, &rop)); }
void AddBL(void)
{ Add_BB(FormOperandDB(sp-1, &lop), FormOperandLS(sp, &rop)); }
void AddBD(void)
{ Add_BB(FormOperandDB(sp-1, &lop), FormOperandDS(sp, &rop)); }
void AddBB(void)
{ Add_BB(FormOperandDB(sp-1, &lop), FormOperandDB(sp, &rop)); }

static void Add_BB(Operand *l, Operand *r)
{
  Operations *ops= l->ops->Promote[r->ops->promoteID](l, r);
  if (!ops) YError("bad data type(s) in binary +");
  ops->Add(l, r);
  Drop(1);
}

static void AddError(void);
static void AddError(void)
{ YError("operands not conformable in binary +"); }

#undef OPERATION
#define OPERATION(opname, typd, Popper) \
void opname(Operand *l, Operand *r) \
{ typd *dst= BuildResult2(l, r); \
  if (dst) { \
    long i, n= l->type.number; \
    typd *lv= l->value, *rv= r->value; \
    for (i=0 ; i<n ; i++) dst[i]= lv[i]+rv[i]; \
    Popper(l->owner); \
  } else AddError(); }

OPERATION(AddC, char, PopTo)
OPERATION(AddS, short, PopTo)
OPERATION(AddI, int, PopToI)
OPERATION(AddL, long, PopToL)
OPERATION(AddF, float, PopTo)
OPERATION(AddD, double, PopToD)
void AddZ(Operand *l, Operand *r)
{ double *dst= BuildResult2(l, r);
  if (dst) {
    long i, n= 2*l->type.number;
    double *lv= l->value, *rv= r->value;
    for (i=0 ; i<n ; i++) dst[i]= lv[i]+rv[i];
    PopTo(l->owner);
  } else AddError();
}

/* + also represents string concatenation */
void AddQ(Operand *l, Operand *r)
{
  char **dst= BuildResult2(l, r);
  char *tmp;
  if (dst) {
    long i, n= l->type.number;
    char **lv= l->value, **rv= r->value;
    for (i=0 ; i<n ; i++) {
      tmp= dst[i];  /* may be lv[i] or rv[i] */
      dst[i]= StrCat(lv[i], rv[i]);
      StrFree(tmp);
    }
    PopTo(l->owner);
  } else AddError();
}

void AddX(Operand *l, Operand *r)
{ YError("non-numeric data type in binary +"); }

/*--------------------------------------------------------------------------*/
/* Subtract */

void Subtract(void) { (sp-1)->ops->Subtract[sp->ops->id](); }

static void Subtract_BB(Operand *l, Operand *r);

void SubtractII(void) { Symbol *spr= sp--; sp->value.i-= spr->value.i; }
void SubtractIL(void) { Symbol *spr= sp--;
  sp->value.l= sp->value.i-spr->value.l; sp->ops= &longScalar; }
void SubtractID(void) { Symbol *spr= sp--;
  sp->value.d= sp->value.i-spr->value.d; sp->ops= &doubleScalar; }
void SubtractIB(void)
{ Subtract_BB(FormOperandIS(sp-1, &lop), FormOperandDB(sp, &rop)); }

void SubtractLI(void) { Symbol *spr= sp--; sp->value.l-= spr->value.i; }
void SubtractLL(void) { Symbol *spr= sp--; sp->value.l-= spr->value.l; }
void SubtractLD(void) { Symbol *spr= sp--;
  sp->value.d= sp->value.l-spr->value.d; sp->ops= &doubleScalar; }
void SubtractLB(void)
{ Subtract_BB(FormOperandLS(sp-1, &lop), FormOperandDB(sp, &rop)); }

void SubtractDI(void) { Symbol *spr= sp--; sp->value.d-= spr->value.i; }
void SubtractDL(void) { Symbol *spr= sp--; sp->value.d-= spr->value.l; }
void SubtractDD(void) { Symbol *spr= sp--; sp->value.d-= spr->value.d; }
void SubtractDB(void)
{ Subtract_BB(FormOperandDS(sp-1, &lop), FormOperandDB(sp, &rop)); }

void SubtractBI(void)
{ Subtract_BB(FormOperandDB(sp-1, &lop), FormOperandIS(sp, &rop)); }
void SubtractBL(void)
{ Subtract_BB(FormOperandDB(sp-1, &lop), FormOperandLS(sp, &rop)); }
void SubtractBD(void)
{ Subtract_BB(FormOperandDB(sp-1, &lop), FormOperandDS(sp, &rop)); }
void SubtractBB(void)
{ Subtract_BB(FormOperandDB(sp-1, &lop), FormOperandDB(sp, &rop)); }

static void Subtract_BB(Operand *l, Operand *r)
{
  Operations *ops= l->ops->Promote[r->ops->promoteID](l, r);
  if (!ops) YError("bad data type(s) in binary -");
  ops->Subtract(l, r);
  Drop(1);
}

static void SubtractError(void);
static void SubtractError(void)
{ YError("operands not conformable in binary -"); }

#undef OPERATION
#define OPERATION(opname, typd, Popper) \
void opname(Operand *l, Operand *r) \
{ typd *dst= BuildResult2(l, r); \
  if (dst) { \
    long i, n= l->type.number; \
    typd *lv= l->value, *rv= r->value; \
    for (i=0 ; i<n ; i++) dst[i]= lv[i]-rv[i]; \
    Popper(l->owner); \
  } else SubtractError(); }

OPERATION(SubtractC, char, PopTo)
OPERATION(SubtractS, short, PopTo)
OPERATION(SubtractI, int, PopToI)
OPERATION(SubtractL, long, PopToL)
OPERATION(SubtractF, float, PopTo)
OPERATION(SubtractD, double, PopToD)
void SubtractZ(Operand *l, Operand *r)
{ double *dst= BuildResult2(l, r);
  if (dst) {
    long i, n= 2*l->type.number;
    double *lv= l->value, *rv= r->value;
    for (i=0 ; i<n ; i++) dst[i]= lv[i]-rv[i];
    PopTo(l->owner);
  } else SubtractError();
}

void SubtractX(Operand *l, Operand *r)
{ YError("non-numeric data type in binary -"); }

/*--------------------------------------------------------------------------*/
/* Multiply */

void Multiply(void) { (sp-1)->ops->Multiply[sp->ops->id](); }

static void Multiply_BB(Operand *l, Operand *r);

void MultiplyII(void) { Symbol *spr= sp--; sp->value.i*= spr->value.i; }
void MultiplyIL(void) { Symbol *spr= sp--;
  sp->value.l= sp->value.i*spr->value.l; sp->ops= &longScalar; }
void MultiplyID(void) { Symbol *spr= sp--;
  sp->value.d= sp->value.i*spr->value.d; sp->ops= &doubleScalar; }
void MultiplyIB(void)
{ Multiply_BB(FormOperandIS(sp-1, &lop), FormOperandDB(sp, &rop)); }

void MultiplyLI(void) { Symbol *spr= sp--; sp->value.l*= spr->value.i; }
void MultiplyLL(void) { Symbol *spr= sp--; sp->value.l*= spr->value.l; }
void MultiplyLD(void) { Symbol *spr= sp--;
  sp->value.d= sp->value.l*spr->value.d; sp->ops= &doubleScalar; }
void MultiplyLB(void)
{ Multiply_BB(FormOperandLS(sp-1, &lop), FormOperandDB(sp, &rop)); }

void MultiplyDI(void) { Symbol *spr= sp--; sp->value.d*= spr->value.i; }
void MultiplyDL(void) { Symbol *spr= sp--; sp->value.d*= spr->value.l; }
void MultiplyDD(void) { Symbol *spr= sp--; sp->value.d*= spr->value.d; }
void MultiplyDB(void)
{ Multiply_BB(FormOperandDS(sp-1, &lop), FormOperandDB(sp, &rop)); }

void MultiplyBI(void)
{ Multiply_BB(FormOperandDB(sp-1, &lop), FormOperandIS(sp, &rop)); }
void MultiplyBL(void)
{ Multiply_BB(FormOperandDB(sp-1, &lop), FormOperandLS(sp, &rop)); }
void MultiplyBD(void)
{ Multiply_BB(FormOperandDB(sp-1, &lop), FormOperandDS(sp, &rop)); }
void MultiplyBB(void)
{ Multiply_BB(FormOperandDB(sp-1, &lop), FormOperandDB(sp, &rop)); }

static void Multiply_BB(Operand *l, Operand *r)
{
  Operations *ops= l->ops->Promote[r->ops->promoteID](l, r);
  if (!ops) YError("bad data type(s) in binary *");
  ops->Multiply(l, r);
  Drop(1);
}

static void MultiplyError(void);
static void MultiplyError(void)
{ YError("operands not conformable in binary *"); }

#undef OPERATION
#define OPERATION(opname, typd, Popper) \
void opname(Operand *l, Operand *r) \
{ typd *dst= BuildResult2(l, r); \
  if (dst) { \
    long i, n= l->type.number; \
    typd *lv= l->value, *rv= r->value; \
    for (i=0 ; i<n ; i++) dst[i]= lv[i]*rv[i]; \
    Popper(l->owner); \
  } else MultiplyError(); }

OPERATION(MultiplyC, char, PopTo)
OPERATION(MultiplyS, short, PopTo)
OPERATION(MultiplyI, int, PopToI)
OPERATION(MultiplyL, long, PopToL)
OPERATION(MultiplyF, float, PopTo)
OPERATION(MultiplyD, double, PopToD)
void MultiplyZ(Operand *l, Operand *r)
{ double *dst= BuildResult2(l, r);
  if (dst) {
    long i, n= l->type.number;
    double *lv= l->value, *rv= r->value;
    double lr, li, rr, ri;  /* watch out for dst==lv or rv */
    for (i=0 ; i<n ; i++) {
      lr= lv[2*i];  li= lv[2*i+1];
      rr= rv[2*i];  ri= rv[2*i+1];
      dst[2*i]= lr*rr-li*ri;  dst[2*i+1]= lr*ri+li*rr;
    }
    PopTo(l->owner);
  } else MultiplyError();
}

void MultiplyX(Operand *l, Operand *r)
{ YError("non-numeric data type in binary *"); }

/*--------------------------------------------------------------------------*/
/* Divide */

void Divide(void) { (sp-1)->ops->Divide[sp->ops->id](); }

static void Divide_BB(Operand *l, Operand *r);

void DivideII(void) { Symbol *spr= sp--; sp->value.i/= spr->value.i; }
void DivideIL(void) { Symbol *spr= sp--;
  sp->value.l= sp->value.i/spr->value.l; sp->ops= &longScalar; }
void DivideID(void) { Symbol *spr= sp--;
  sp->value.d= sp->value.i/spr->value.d; sp->ops= &doubleScalar; }
void DivideIB(void)
{ Divide_BB(FormOperandIS(sp-1, &lop), FormOperandDB(sp, &rop)); }

void DivideLI(void) { Symbol *spr= sp--; sp->value.l/= spr->value.i; }
void DivideLL(void) { Symbol *spr= sp--; sp->value.l/= spr->value.l; }
void DivideLD(void) { Symbol *spr= sp--;
  sp->value.d= sp->value.l/spr->value.d; sp->ops= &doubleScalar; }
void DivideLB(void)
{ Divide_BB(FormOperandLS(sp-1, &lop), FormOperandDB(sp, &rop)); }

void DivideDI(void) { Symbol *spr= sp--; sp->value.d/= spr->value.i; }
void DivideDL(void) { Symbol *spr= sp--; sp->value.d/= spr->value.l; }
void DivideDD(void) { Symbol *spr= sp--; sp->value.d/= spr->value.d; }
void DivideDB(void)
{ Divide_BB(FormOperandDS(sp-1, &lop), FormOperandDB(sp, &rop)); }

void DivideBI(void)
{ Divide_BB(FormOperandDB(sp-1, &lop), FormOperandIS(sp, &rop)); }
void DivideBL(void)
{ Divide_BB(FormOperandDB(sp-1, &lop), FormOperandLS(sp, &rop)); }
void DivideBD(void)
{ Divide_BB(FormOperandDB(sp-1, &lop), FormOperandDS(sp, &rop)); }
void DivideBB(void)
{ Divide_BB(FormOperandDB(sp-1, &lop), FormOperandDB(sp, &rop)); }

static void Divide_BB(Operand *l, Operand *r)
{
  Operations *ops= l->ops->Promote[r->ops->promoteID](l, r);
  if (!ops) YError("bad data type(s) in binary /");
  ops->Divide(l, r);
  Drop(1);
}

static void DivideError(void);
static void DivideError(void)
{ YError("operands not conformable in binary /"); }

#undef OPERATION
#define OPERATION(opname, typd, Popper) \
void opname(Operand *l, Operand *r) \
{ typd *dst= BuildResult2(l, r); \
  if (dst) { \
    long i, n= l->type.number; \
    typd *lv= l->value, *rv= r->value; \
    for (i=0 ; i<n ; i++) dst[i]= lv[i]/rv[i]; \
    Popper(l->owner); \
  } else DivideError(); }

OPERATION(DivideC, char, PopTo)
OPERATION(DivideS, short, PopTo)
OPERATION(DivideI, int, PopToI)
OPERATION(DivideL, long, PopToL)
OPERATION(DivideF, float, PopTo)
OPERATION(DivideD, double, PopToD)
void DivideZ(Operand *l, Operand *r)
{ double *dst= BuildResult2(l, r);
  if (dst) {
    long i, n= l->type.number;
    double *lv= l->value, *rv= r->value;
    double lr, li, rr, ri, nrm;          /* watch out for dst==lv or rv */
    for (i=0 ; i<n ; i++) {
      lr= lv[2*i];  li= lv[2*i+1];
      rr= rv[2*i];  ri= rv[2*i+1];
      if ((rr>0?rr:-rr)>(ri>0?ri:-ri)) { /* be careful about overflow... */
	nrm=rr; rr=1.0; ri/=nrm; nrm*=1.0+ri*ri;
      } else {
	nrm=ri; ri=1.0; rr/=nrm; nrm*=1.0+rr*rr;
      }
      dst[2*i]= (lr*rr+li*ri)/nrm;
      dst[2*i+1]= (li*rr-lr*ri)/nrm;
    }
    PopTo(l->owner);
  } else DivideError();
}

void DivideX(Operand *l, Operand *r)
{ YError("non-numeric data type in binary /"); }

/*--------------------------------------------------------------------------*/
/* Modulo */

void Modulo(void) { (sp-1)->ops->Modulo[sp->ops->id](); }

static void Modulo_BB(Operand *l, Operand *r);

void ModuloII(void) { Symbol *spr= sp--; sp->value.i%= spr->value.i; }
void ModuloIL(void) { Symbol *spr= sp--;
  sp->value.l= sp->value.i%spr->value.l; sp->ops= &longScalar; }
void ModuloID(void) { Symbol *spr= sp--;
  sp->value.d= RMOD(sp->value.i,spr->value.d); sp->ops= &doubleScalar; }
void ModuloIB(void)
{ Modulo_BB(FormOperandIS(sp-1, &lop), FormOperandDB(sp, &rop)); }

void ModuloLI(void) { Symbol *spr= sp--; sp->value.l%= spr->value.i; }
void ModuloLL(void) { Symbol *spr= sp--; sp->value.l%= spr->value.l; }
void ModuloLD(void) { Symbol *spr= sp--;
  sp->value.d= RMOD(sp->value.l,spr->value.d); sp->ops= &doubleScalar; }
void ModuloLB(void)
{ Modulo_BB(FormOperandLS(sp-1, &lop), FormOperandDB(sp, &rop)); }

void ModuloDI(void) { Symbol *spr= sp--;
		      sp->value.d= RMOD(sp->value.d, spr->value.i); }
void ModuloDL(void) { Symbol *spr= sp--;
		      sp->value.d= RMOD(sp->value.d, spr->value.l); }
void ModuloDD(void) { Symbol *spr= sp--;
		      sp->value.d= RMOD(sp->value.d, spr->value.d); }
void ModuloDB(void)
{ Modulo_BB(FormOperandDS(sp-1, &lop), FormOperandDB(sp, &rop)); }

void ModuloBI(void)
{ Modulo_BB(FormOperandDB(sp-1, &lop), FormOperandIS(sp, &rop)); }
void ModuloBL(void)
{ Modulo_BB(FormOperandDB(sp-1, &lop), FormOperandLS(sp, &rop)); }
void ModuloBD(void)
{ Modulo_BB(FormOperandDB(sp-1, &lop), FormOperandDS(sp, &rop)); }
void ModuloBB(void)
{ Modulo_BB(FormOperandDB(sp-1, &lop), FormOperandDB(sp, &rop)); }

static void Modulo_BB(Operand *l, Operand *r)
{
  Operations *ops= l->ops->Promote[r->ops->promoteID](l, r);
  if (!ops) YError("bad data type(s) in binary %");
  ops->Modulo(l, r);
  Drop(1);
}

static void ModuloError(void);
static void ModuloError(void)
{ YError("operands not conformable in binary %"); }

#undef OPERATION
#define OPERATION(opname, typd, Popper) \
void opname(Operand *l, Operand *r) \
{ typd *dst= BuildResult2(l, r); \
  if (dst) { \
    long i, n= l->type.number; \
    typd *lv= l->value, *rv= r->value; \
    for (i=0 ; i<n ; i++) dst[i]= lv[i]%rv[i]; \
    Popper(l->owner); \
  } else ModuloError(); }

OPERATION(ModuloC, char, PopTo)
OPERATION(ModuloS, short, PopTo)
OPERATION(ModuloI, int, PopToI)
OPERATION(ModuloL, long, PopToL)

#undef OPERATION
#define OPERATION(opname, typd, Popper) \
void opname(Operand *l, Operand *r) \
{ typd *dst= BuildResult2(l, r); \
  if (dst) { \
    long i, n= l->type.number; \
    typd *lv= l->value, *rv= r->value; \
    for (i=0 ; i<n ; i++) dst[i]= RMOD(lv[i],rv[i]); \
    Popper(l->owner); \
  } else ModuloError(); }

OPERATION(ModuloF, float, PopTo)
OPERATION(ModuloD, double, PopToD)
void ModuloZ(Operand *l, Operand *r)
{ YError("complex operand not allowed in binary %"); }

void ModuloX(Operand *l, Operand *r)
{ YError("non-numeric data type in binary %"); }

/*--------------------------------------------------------------------------*/
/* Power -- really two operations:
      raising to integer power leaves data type of left operand unchanged
      raising to real or complex power follows ordinary binary promotion
              rules
 */

void Power(void) { (sp-1)->ops->Power[sp->ops->id](); }

static void Power_BB(Operand *l, Operand *r);

void PowerII(void) { Symbol *spr= sp--;
  sp->value.i= powLL(sp->value.i, spr->value.i); }
void PowerIL(void) { Symbol *spr= sp--;
  sp->value.l= powLL(sp->value.i, spr->value.l); sp->ops= &longScalar; }
void PowerID(void) { Symbol *spr= sp--;
  sp->value.d= pow(sp->value.i, spr->value.d); sp->ops= &doubleScalar; }
void PowerIB(void)
{ Power_BB(FormOperandIS(sp-1, &lop), FormOperandDB(sp, &rop)); }

void PowerLI(void) { Symbol *spr= sp--;
  sp->value.l= powLL(sp->value.l, spr->value.i); }
void PowerLL(void) { Symbol *spr= sp--;
  sp->value.l= powLL(sp->value.l, spr->value.l); }
void PowerLD(void) { Symbol *spr= sp--;
  sp->value.d= pow(sp->value.l, spr->value.d); sp->ops= &doubleScalar; }
void PowerLB(void)
{ Power_BB(FormOperandLS(sp-1, &lop), FormOperandDB(sp, &rop)); }

void PowerDI(void) { Symbol *spr= sp--;
  sp->value.d= powDL(sp->value.d, spr->value.i); }
void PowerDL(void) { Symbol *spr= sp--;
  sp->value.d= powDL(sp->value.d, spr->value.l); }
void PowerDD(void) { Symbol *spr= sp--;
  sp->value.d= pow(sp->value.d, spr->value.d); }
void PowerDB(void)
{ Power_BB(FormOperandDS(sp-1, &lop), FormOperandDB(sp, &rop)); }

void PowerBI(void)
{ Power_BB(FormOperandDB(sp-1, &lop), FormOperandIS(sp, &rop)); }
void PowerBL(void)
{ Power_BB(FormOperandDB(sp-1, &lop), FormOperandLS(sp, &rop)); }
void PowerBD(void)
{ Power_BB(FormOperandDB(sp-1, &lop), FormOperandDS(sp, &rop)); }
void PowerBB(void)
{ Power_BB(FormOperandDB(sp-1, &lop), FormOperandDB(sp, &rop)); }

static void Power_BB(Operand *l, Operand *r)
{
  int promoteID= r->ops->promoteID;
  if (promoteID<T_FLOAT && l->ops->promoteID<=T_COMPLEX) {
    /* raising to integer power does not change type of left operand,
       but right operand must always be long */
    r->ops->ToLong(r);
    l->ops->Power(l, r);
  } else {
    /* raising to non-integer power follows same promotion rules as
       all other arithmetic binary operators (only 3 possibilities) */
    Operations *ops= l->ops->Promote[promoteID](l, r);
    if (!ops) YError("bad data type(s) in binary ^");
    if (ops==&floatOps) PowerXF(l, r);
    else if (ops==&doubleOps) PowerXD(l, r);
    else if (ops==&complexOps) PowerXZ(l, r);
    else YError("bad data type(s) in binary ^");
  }
  Drop(1);
}

static void PowerError(void);
static void PowerError(void)
{ YError("operands not conformable in binary ^"); }

#undef OPERATION
#define OPERATION(opname, typd, Popper) \
void opname(Operand *l, Operand *r) \
{ typd *dst= BuildResult1(l, r); \
  if (dst) { \
    long i, n= l->type.number; \
    typd *lv= l->value; long *rv= r->value; \
    for (i=0 ; i<n ; i++) dst[i]= powLL(lv[i], rv[i]); \
    Popper(l->owner); \
  } else PowerError(); }

OPERATION(PowerC, char, PopTo)
OPERATION(PowerS, short, PopTo)
OPERATION(PowerI, int, PopToI)
OPERATION(PowerL, long, PopToL)

#undef OPERATION
#define OPERATION(opname, typd, Popper) \
void opname(Operand *l, Operand *r) \
{ typd *dst= BuildResult1(l, r); \
  if (dst) { \
    long i, n= l->type.number; \
    typd *lv= l->value; long *rv= r->value; \
    for (i=0 ; i<n ; i++) dst[i]= powDL(lv[i], rv[i]); \
    Popper(l->owner); \
  } else PowerError(); }

OPERATION(PowerF, float, PopTo)
OPERATION(PowerD, double, PopToD)
void PowerZ(Operand *l, Operand *r)
{ double *dst= BuildResult1(l, r);
  if (dst) {
    long i, n= l->type.number;
    double *lv= l->value; long *rv= r->value;
    for (i=0 ; i<n ; i++) powZL(&dst[2*i], &lv[2*i], rv[i]);
    PopTo(l->owner);
  } else PowerError();
}

#undef OPERATION
#define OPERATION(opname, typd, Popper) \
void opname(Operand *l, Operand *r) \
{ typd *dst= BuildResult2(l, r); \
  if (dst) { \
    long i, n= l->type.number; \
    typd *lv= l->value, *rv= r->value; \
    for (i=0 ; i<n ; i++) dst[i]= pow(lv[i], rv[i]); \
    Popper(l->owner); \
  } else PowerError(); }

OPERATION(PowerXF, float, PopTo)
OPERATION(PowerXD, double, PopToD)
void PowerXZ(Operand *l, Operand *r)
{ double *dst= BuildResult2(l, r);
  if (dst) {
    long i, n= 2*l->type.number;
    double *lv= l->value, *rv= r->value;
    for (i=0 ; i<n ; i+=2) powZZ(&dst[i], &lv[i], &rv[i]);
    PopTo(l->owner);
  } else PowerError();
}

void PowerX(Operand *l, Operand *r)
{ YError("non-numeric data type in binary ^"); }

/*--------------------------------------------------------------------------*/
/* Greater */

void Greater(void) { (sp-1)->ops->Greater[sp->ops->id](); }

static void Greater_BB(Operand *l, Operand *r);

void GreaterII(void) { Symbol *spr= sp--;
  sp->value.i= (sp->value.i>spr->value.i); }
void GreaterIL(void) { Symbol *spr= sp--;
  sp->value.i= (sp->value.i>spr->value.l); }
void GreaterID(void) { Symbol *spr= sp--;
  sp->value.i= (sp->value.i>spr->value.d); }
void GreaterIB(void)
{ Greater_BB(FormOperandIS(sp-1, &lop), FormOperandDB(sp, &rop)); }

void GreaterLI(void) { Symbol *spr= sp--;
  sp->value.i= (sp->value.l>spr->value.i); sp->ops= &intScalar; }
void GreaterLL(void) { Symbol *spr= sp--;
  sp->value.i= (sp->value.l>spr->value.l); sp->ops= &intScalar; }
void GreaterLD(void) { Symbol *spr= sp--;
  sp->value.i= (sp->value.l>spr->value.d); sp->ops= &intScalar; }
void GreaterLB(void)
{ Greater_BB(FormOperandLS(sp-1, &lop), FormOperandDB(sp, &rop)); }

void GreaterDI(void) { Symbol *spr= sp--;
  sp->value.i= (sp->value.d>spr->value.i); sp->ops= &intScalar; }
void GreaterDL(void) { Symbol *spr= sp--;
  sp->value.i= (sp->value.d>spr->value.l); sp->ops= &intScalar; }
void GreaterDD(void) { Symbol *spr= sp--;
  sp->value.i= (sp->value.d>spr->value.d); sp->ops= &intScalar; }
void GreaterDB(void)
{ Greater_BB(FormOperandDS(sp-1, &lop), FormOperandDB(sp, &rop)); }

void GreaterBI(void)
{ Greater_BB(FormOperandDB(sp-1, &lop), FormOperandIS(sp, &rop)); }
void GreaterBL(void)
{ Greater_BB(FormOperandDB(sp-1, &lop), FormOperandLS(sp, &rop)); }
void GreaterBD(void)
{ Greater_BB(FormOperandDB(sp-1, &lop), FormOperandDS(sp, &rop)); }
void GreaterBB(void)
{ Greater_BB(FormOperandDB(sp-1, &lop), FormOperandDB(sp, &rop)); }

static void Greater_BB(Operand *l, Operand *r)
{
  Operations *ops= l->ops->Promote[r->ops->promoteID](l, r);
  if (!ops) YError("bad data type(s) in binary >");
  ops->Greater(l, r);
  Drop(1);
}

static void GreaterError(void);
static void GreaterError(void)
{ YError("operands not conformable in binary > or <"); }

#undef OPERATION
#define OPERATION(opname, typd) \
void opname(Operand *l, Operand *r) \
{ int *dst= BuildResult0(l, r, &intStruct); \
  if (dst) { \
    long i, n= l->type.number; \
    typd *lv= l->value, *rv= r->value; \
    for (i=0 ; i<n ; i++) dst[i]= lv[i]>rv[i]; \
    PopToI(l->owner); \
  } else GreaterError(); }

OPERATION(GreaterC, char)
OPERATION(GreaterS, short)
OPERATION(GreaterI, int)
OPERATION(GreaterL, long)
OPERATION(GreaterF, float)
OPERATION(GreaterD, double)
void GreaterZ(Operand *l, Operand *r)
{ YError("complex operand not allowed in binary > or <"); }

void GreaterQ(Operand *l, Operand *r)
{
  int *dst= BuildResult0(l, r, &intStruct);
  if (dst) {
    long i, n= l->type.number;
    char **lv= l->value, **rv= r->value, *ls, *rs;
    for (i=0 ; i<n ; i++) {
      ls= lv[i];  rs= rv[i];
      if (ls && rs) dst[i]= strcmp(ls, rs)>0;
      else dst[i]= (ls && !rs);
    }
    PopTo(l->owner);
  } else GreaterError();
}

void GreaterX(Operand *l, Operand *r)
{ YError("non-numeric data type in binary > or <"); }

/*--------------------------------------------------------------------------*/
/* Less */

void Less(void) { (sp-1)->ops->Less[sp->ops->id](); }

static void Less_BB(Operand *l, Operand *r);

void LessII(void) { Symbol *spr= sp--;
  sp->value.i= (sp->value.i<spr->value.i); }
void LessIL(void) { Symbol *spr= sp--;
  sp->value.i= (sp->value.i<spr->value.l); }
void LessID(void) { Symbol *spr= sp--;
  sp->value.i= (sp->value.i<spr->value.d); }
void LessIB(void)
{ Less_BB(FormOperandIS(sp-1, &lop), FormOperandDB(sp, &rop)); }

void LessLI(void) { Symbol *spr= sp--;
  sp->value.i= (sp->value.l<spr->value.i); sp->ops= &intScalar; }
void LessLL(void) { Symbol *spr= sp--;
  sp->value.i= (sp->value.l<spr->value.l); sp->ops= &intScalar; }
void LessLD(void) { Symbol *spr= sp--;
  sp->value.i= (sp->value.l<spr->value.d); sp->ops= &intScalar; }
void LessLB(void)
{ Less_BB(FormOperandLS(sp-1, &lop), FormOperandDB(sp, &rop)); }

void LessDI(void) { Symbol *spr= sp--;
  sp->value.i= (sp->value.d<spr->value.i); sp->ops= &intScalar; }
void LessDL(void) { Symbol *spr= sp--;
  sp->value.i= (sp->value.d<spr->value.l); sp->ops= &intScalar; }
void LessDD(void) { Symbol *spr= sp--;
  sp->value.i= (sp->value.d<spr->value.d); sp->ops= &intScalar; }
void LessDB(void)
{ Less_BB(FormOperandDS(sp-1, &lop), FormOperandDB(sp, &rop)); }

void LessBI(void)
{ Less_BB(FormOperandDB(sp-1, &lop), FormOperandIS(sp, &rop)); }
void LessBL(void)
{ Less_BB(FormOperandDB(sp-1, &lop), FormOperandLS(sp, &rop)); }
void LessBD(void)
{ Less_BB(FormOperandDB(sp-1, &lop), FormOperandDS(sp, &rop)); }
void LessBB(void)
{ Less_BB(FormOperandDB(sp-1, &lop), FormOperandDB(sp, &rop)); }

static void Less_BB(Operand *l, Operand *r)
{
  Operations *ops= l->ops->Promote[r->ops->promoteID](l, r);
  if (!ops) YError("bad data type(s) in binary <");
  ops->Greater(r, l);
  PopTo(sp-1);   /* instead of Drop(1), since args reversed */
}

/*--------------------------------------------------------------------------*/
/* GreaterEQ */

void GreaterEQ(void) { (sp-1)->ops->GreaterEQ[sp->ops->id](); }

static void GreaterEQ_BB(Operand *l, Operand *r);

void GreaterEQII(void) { Symbol *spr= sp--;
  sp->value.i= (sp->value.i>=spr->value.i); }
void GreaterEQIL(void) { Symbol *spr= sp--;
  sp->value.i= (sp->value.i>=spr->value.l); }
void GreaterEQID(void) { Symbol *spr= sp--;
  sp->value.i= (sp->value.i>=spr->value.d); }
void GreaterEQIB(void)
{ GreaterEQ_BB(FormOperandIS(sp-1, &lop), FormOperandDB(sp, &rop)); }

void GreaterEQLI(void) { Symbol *spr= sp--;
  sp->value.i= (sp->value.l>=spr->value.i); sp->ops= &intScalar; }
void GreaterEQLL(void) { Symbol *spr= sp--;
  sp->value.i= (sp->value.l>=spr->value.l); sp->ops= &intScalar; }
void GreaterEQLD(void) { Symbol *spr= sp--;
  sp->value.i= (sp->value.l>=spr->value.d); sp->ops= &intScalar; }
void GreaterEQLB(void)
{ GreaterEQ_BB(FormOperandLS(sp-1, &lop), FormOperandDB(sp, &rop)); }

void GreaterEQDI(void) { Symbol *spr= sp--;
  sp->value.i= (sp->value.d>=spr->value.i); sp->ops= &intScalar; }
void GreaterEQDL(void) { Symbol *spr= sp--;
  sp->value.i= (sp->value.d>=spr->value.l); sp->ops= &intScalar; }
void GreaterEQDD(void) { Symbol *spr= sp--;
  sp->value.i= (sp->value.d>=spr->value.d); sp->ops= &intScalar; }
void GreaterEQDB(void)
{ GreaterEQ_BB(FormOperandDS(sp-1, &lop), FormOperandDB(sp, &rop)); }

void GreaterEQBI(void)
{ GreaterEQ_BB(FormOperandDB(sp-1, &lop), FormOperandIS(sp, &rop)); }
void GreaterEQBL(void)
{ GreaterEQ_BB(FormOperandDB(sp-1, &lop), FormOperandLS(sp, &rop)); }
void GreaterEQBD(void)
{ GreaterEQ_BB(FormOperandDB(sp-1, &lop), FormOperandDS(sp, &rop)); }
void GreaterEQBB(void)
{ GreaterEQ_BB(FormOperandDB(sp-1, &lop), FormOperandDB(sp, &rop)); }

static void GreaterEQ_BB(Operand *l, Operand *r)
{
  Operations *ops= l->ops->Promote[r->ops->promoteID](l, r);
  if (!ops) YError("bad data type(s) in binary >=");
  ops->GreaterEQ(l, r);
  Drop(1);
}

static void GreaterEQError(void);
static void GreaterEQError(void)
{ YError("operands not conformable in binary >= or <="); }

#undef OPERATION
#define OPERATION(opname, typd) \
void opname(Operand *l, Operand *r) \
{ int *dst= BuildResult0(l, r, &intStruct); \
  if (dst) { \
    long i, n= l->type.number; \
    typd *lv= l->value, *rv= r->value; \
    for (i=0 ; i<n ; i++) dst[i]= lv[i]>=rv[i]; \
    PopToI(l->owner); \
  } else GreaterEQError(); }

OPERATION(GreaterEQC, char)
OPERATION(GreaterEQS, short)
OPERATION(GreaterEQI, int)
OPERATION(GreaterEQL, long)
OPERATION(GreaterEQF, float)
OPERATION(GreaterEQD, double)
void GreaterEQZ(Operand *l, Operand *r)
{ YError("complex operand not allowed in binary >= or <="); }

void GreaterEQQ(Operand *l, Operand *r)
{
  int *dst= BuildResult0(l, r, &intStruct);
  if (dst) {
    long i, n= l->type.number;
    char **lv= l->value, **rv= r->value, *ls, *rs;
    for (i=0 ; i<n ; i++) {
      ls= lv[i];  rs= rv[i];
      if (ls && rs) dst[i]= strcmp(ls, rs)>=0;
      else dst[i]= (ls && !rs);
    }
    PopTo(l->owner);
  } else GreaterEQError();
}

void GreaterEQX(Operand *l, Operand *r)
{ YError("non-numeric data type in binary >= or <="); }

/*--------------------------------------------------------------------------*/
/* LessEQ */

void LessEQ(void) { (sp-1)->ops->LessEQ[sp->ops->id](); }

static void LessEQ_BB(Operand *l, Operand *r);

void LessEQII(void) { Symbol *spr= sp--;
  sp->value.i= (sp->value.i<=spr->value.i); }
void LessEQIL(void) { Symbol *spr= sp--;
  sp->value.i= (sp->value.i<=spr->value.l); }
void LessEQID(void) { Symbol *spr= sp--;
  sp->value.i= (sp->value.i<=spr->value.d); }
void LessEQIB(void)
{ LessEQ_BB(FormOperandIS(sp-1, &lop), FormOperandDB(sp, &rop)); }

void LessEQLI(void) { Symbol *spr= sp--;
  sp->value.i= (sp->value.l<=spr->value.i); sp->ops= &intScalar; }
void LessEQLL(void) { Symbol *spr= sp--;
  sp->value.i= (sp->value.l<=spr->value.l); sp->ops= &intScalar; }
void LessEQLD(void) { Symbol *spr= sp--;
  sp->value.i= (sp->value.l<=spr->value.d); sp->ops= &intScalar; }
void LessEQLB(void)
{ LessEQ_BB(FormOperandLS(sp-1, &lop), FormOperandDB(sp, &rop)); }

void LessEQDI(void) { Symbol *spr= sp--;
  sp->value.i= (sp->value.d<=spr->value.i); sp->ops= &intScalar; }
void LessEQDL(void) { Symbol *spr= sp--;
  sp->value.i= (sp->value.d<=spr->value.l); sp->ops= &intScalar; }
void LessEQDD(void) { Symbol *spr= sp--;
  sp->value.i= (sp->value.d<=spr->value.d); sp->ops= &intScalar; }
void LessEQDB(void)
{ LessEQ_BB(FormOperandDS(sp-1, &lop), FormOperandDB(sp, &rop)); }

void LessEQBI(void)
{ LessEQ_BB(FormOperandDB(sp-1, &lop), FormOperandIS(sp, &rop)); }
void LessEQBL(void)
{ LessEQ_BB(FormOperandDB(sp-1, &lop), FormOperandLS(sp, &rop)); }
void LessEQBD(void)
{ LessEQ_BB(FormOperandDB(sp-1, &lop), FormOperandDS(sp, &rop)); }
void LessEQBB(void)
{ LessEQ_BB(FormOperandDB(sp-1, &lop), FormOperandDB(sp, &rop)); }

static void LessEQ_BB(Operand *l, Operand *r)
{
  Operations *ops= l->ops->Promote[r->ops->promoteID](l, r);
  if (!ops) YError("bad data type(s) in binary <=");
  ops->GreaterEQ(r, l);
  PopTo(sp-1);   /* instead of Drop(1), since args reversed */
}

/*--------------------------------------------------------------------------*/
/* Equal */

void Equal(void) { (sp-1)->ops->Equal[sp->ops->id](); }

static void Equal_BB(Operand *l, Operand *r);

void EqualII(void) { Symbol *spr= sp--;
  sp->value.i= (sp->value.i==spr->value.i); }
void EqualIL(void) { Symbol *spr= sp--;
  sp->value.i= (sp->value.i==spr->value.l); }
void EqualID(void) { Symbol *spr= sp--;
  sp->value.i= (sp->value.i==spr->value.d); }
void EqualIB(void)
{ Equal_BB(FormOperandIS(sp-1, &lop), FormOperandDB(sp, &rop)); }

void EqualLI(void) { Symbol *spr= sp--;
  sp->value.i= (sp->value.l==spr->value.i); sp->ops= &intScalar; }
void EqualLL(void) { Symbol *spr= sp--;
  sp->value.i= (sp->value.l==spr->value.l); sp->ops= &intScalar; }
void EqualLD(void) { Symbol *spr= sp--;
  sp->value.i= (sp->value.l==spr->value.d); sp->ops= &intScalar; }
void EqualLB(void)
{ Equal_BB(FormOperandLS(sp-1, &lop), FormOperandDB(sp, &rop)); }

void EqualDI(void) { Symbol *spr= sp--;
  sp->value.i= (sp->value.d==spr->value.i); sp->ops= &intScalar; }
void EqualDL(void) { Symbol *spr= sp--;
  sp->value.i= (sp->value.d==spr->value.l); sp->ops= &intScalar; }
void EqualDD(void) { Symbol *spr= sp--;
  sp->value.i= (sp->value.d==spr->value.d); sp->ops= &intScalar; }
void EqualDB(void)
{ Equal_BB(FormOperandDS(sp-1, &lop), FormOperandDB(sp, &rop)); }

void EqualBI(void)
{ Equal_BB(FormOperandDB(sp-1, &lop), FormOperandIS(sp, &rop)); }
void EqualBL(void)
{ Equal_BB(FormOperandDB(sp-1, &lop), FormOperandLS(sp, &rop)); }
void EqualBD(void)
{ Equal_BB(FormOperandDB(sp-1, &lop), FormOperandDS(sp, &rop)); }
void EqualBB(void)
{ Equal_BB(FormOperandDB(sp-1, &lop), FormOperandDB(sp, &rop)); }

static void Equal_BB(Operand *l, Operand *r)
{
  Operations *ops= l->ops->Promote[r->ops->promoteID](l, r);
  if (ops) {
    ops->Equal(l, r);
    Drop(1);
  } else {
    /* If the data types don't match, the operands certainly aren't == */
    /* Can pointer or string be ==0? */
    Drop(2);
    PushIntValue(0);
  }
}

static void EqualError(void);
static void EqualError(void)
{ YError("operands not conformable in binary =="); }

#undef OPERATION
#define OPERATION(opname, typd) \
void opname(Operand *l, Operand *r) \
{ int *dst= BuildResult0(l, r, &intStruct); \
  if (dst) { \
    long i, n= l->type.number; \
    typd *lv= l->value; typd *rv= r->value; \
    for (i=0 ; i<n ; i++) dst[i]= lv[i]==rv[i]; \
    PopToI(l->owner); \
  } else EqualError(); }

OPERATION(EqualC, char)
OPERATION(EqualS, short)
OPERATION(EqualI, int)
OPERATION(EqualL, long)
OPERATION(EqualF, float)
OPERATION(EqualD, double)
void EqualZ(Operand *l, Operand *r)
{ int *dst= BuildResult0(l, r, &intStruct);
  if (dst) {
    long i, n= l->type.number;
    double *lv= l->value, *rv= r->value;
    for (i=0 ; i<n ; i++) dst[i]= (lv[2*i]==rv[2*i] && lv[2*i+1]==rv[2*i+1]);
    PopToI(l->owner);
  } else EqualError();
}

void EqualQ(Operand *l, Operand *r)
{
  int *dst= BuildResult0(l, r, &intStruct);
  if (dst) {
    long i, n= l->type.number;
    char **lv= l->value, **rv= r->value, *ls, *rs;
    for (i=0 ; i<n ; i++) {
      ls= lv[i];  rs= rv[i];
      if (ls && rs) dst[i]= strcmp(ls, rs)==0;
      else dst[i]= (ls==rs);
    }
    PopToI(l->owner);
  } else EqualError();
}

OPERATION(EqualP, void *)

void EqualSI(Operand *l, Operand *r)
{
  int *dst= BuildResult0(l, r, &intStruct);
  if (dst) {
    long i, n= l->type.number;
    if (StructEqual(l->type.base, r->type.base)) {
      long size= l->type.base->size;
      char *lv= l->value, *rv= r->value;
      for (i=0 ; i<n ; i++) {
	dst[i]= memcmp(lv, rv, size)==0;
	lv+= size;
	rv+= size;
      }
    } else {
      for (i=0 ; i<n ; i++) dst[i]= 0;
    }
    PopToI(l->owner);
  } else EqualError();
}

void EqualR(Operand *l, Operand *r)
{
  Range *lop= (Range *)l->owner->value.db, *rop= (Range *)r->owner->value.db;
  long lmin= lop->min, linc= lop->inc;
  int value= (lop->nilFlags==rop->nilFlags) && (lmin==rop->min) &&
    (linc==rop->inc) && ((lop->max-lmin)/linc == (rop->max-lmin)/linc);
  PushIntValue(value);
  PopToI(l->owner);
}

void EqualX(Operand *l, Operand *r)
{
  DataBlock *lop= l->owner->value.db,  *rop= r->owner->value.db;
  PushIntValue(lop==rop);
  PopToI(l->owner);
}

/*--------------------------------------------------------------------------*/
/* NotEqual */

void NotEqual(void) { (sp-1)->ops->NotEqual[sp->ops->id](); }

static void NotEqual_BB(Operand *l, Operand *r);

void NotEqualII(void) { Symbol *spr= sp--;
  sp->value.i= (sp->value.i!=spr->value.i); }
void NotEqualIL(void) { Symbol *spr= sp--;
  sp->value.i= (sp->value.i!=spr->value.l); }
void NotEqualID(void) { Symbol *spr= sp--;
  sp->value.i= (sp->value.i!=spr->value.d); }
void NotEqualIB(void)
{ NotEqual_BB(FormOperandIS(sp-1, &lop), FormOperandDB(sp, &rop)); }

void NotEqualLI(void) { Symbol *spr= sp--;
  sp->value.i= (sp->value.l!=spr->value.i); sp->ops= &intScalar; }
void NotEqualLL(void) { Symbol *spr= sp--;
  sp->value.i= (sp->value.l!=spr->value.l); sp->ops= &intScalar; }
void NotEqualLD(void) { Symbol *spr= sp--;
  sp->value.i= (sp->value.l!=spr->value.d); sp->ops= &intScalar; }
void NotEqualLB(void)
{ NotEqual_BB(FormOperandLS(sp-1, &lop), FormOperandDB(sp, &rop)); }

void NotEqualDI(void) { Symbol *spr= sp--;
  sp->value.i= (sp->value.d!=spr->value.i); sp->ops= &intScalar; }
void NotEqualDL(void) { Symbol *spr= sp--;
  sp->value.i= (sp->value.d!=spr->value.l); sp->ops= &intScalar; }
void NotEqualDD(void) { Symbol *spr= sp--;
  sp->value.i= (sp->value.d!=spr->value.d); sp->ops= &intScalar; }
void NotEqualDB(void)
{ NotEqual_BB(FormOperandDS(sp-1, &lop), FormOperandDB(sp, &rop)); }

void NotEqualBI(void)
{ NotEqual_BB(FormOperandDB(sp-1, &lop), FormOperandIS(sp, &rop)); }
void NotEqualBL(void)
{ NotEqual_BB(FormOperandDB(sp-1, &lop), FormOperandLS(sp, &rop)); }
void NotEqualBD(void)
{ NotEqual_BB(FormOperandDB(sp-1, &lop), FormOperandDS(sp, &rop)); }
void NotEqualBB(void)
{ NotEqual_BB(FormOperandDB(sp-1, &lop), FormOperandDB(sp, &rop)); }

static void NotEqual_BB(Operand *l, Operand *r)
{
  Operations *ops= l->ops->Promote[r->ops->promoteID](l, r);
  if (ops) {
    ops->NotEqual(l, r);
    Drop(1);
  } else {
    /* If the data types don't match, the operands certainly are != */
    /* Can pointer or string be !=0? */
    Drop(2);
    PushIntValue(1);
  }
}

static void NotEqualError(void);
static void NotEqualError(void)
{ YError("operands not conformable in binary !="); }

#undef OPERATION
#define OPERATION(opname, typd) \
void opname(Operand *l, Operand *r) \
{ int *dst= BuildResult0(l, r, &intStruct); \
  if (dst) { \
    long i, n= l->type.number; \
    typd *lv= l->value; typd *rv= r->value; \
    for (i=0 ; i<n ; i++) dst[i]= lv[i]!=rv[i]; \
    PopToI(l->owner); \
  } else NotEqualError(); }

OPERATION(NotEqualC, char)
OPERATION(NotEqualS, short)
OPERATION(NotEqualI, int)
OPERATION(NotEqualL, long)
OPERATION(NotEqualF, float)
OPERATION(NotEqualD, double)
void NotEqualZ(Operand *l, Operand *r)
{ int *dst= BuildResult0(l, r, &intStruct);
  if (dst) {
    long i, n= l->type.number;
    double *lv= l->value, *rv= r->value;
    for (i=0 ; i<n ; i++) dst[i]= (lv[2*i]!=rv[2*i] || lv[2*i+1]!=rv[2*i+1]);
    PopToI(l->owner);
  } else NotEqualError();
}

void NotEqualQ(Operand *l, Operand *r)
{
  int *dst= BuildResult0(l, r, &intStruct);
  if (dst) {
    long i, n= l->type.number;
    char **lv= l->value, **rv= r->value, *ls, *rs;
    for (i=0 ; i<n ; i++) {
      ls= lv[i];  rs= rv[i];
      if (ls && rs) dst[i]= strcmp(ls, rs)!=0;
      else dst[i]= (ls!=rs);
    }
    PopToI(l->owner);
  } else NotEqualError();
}

OPERATION(NotEqualP, void *)

void NotEqualSI(Operand *l, Operand *r)
{
  int *dst= BuildResult0(l, r, &intStruct);
  if (dst) {
    long i, n= l->type.number;
    if (StructEqual(l->type.base, r->type.base)) {
      long size= l->type.base->size;
      char *lv= l->value, *rv= r->value;
      for (i=0 ; i<n ; i++) {
	dst[i]= memcmp(lv, rv, size)!=0;
	lv+= size;
	rv+= size;
      }
    } else {
      for (i=0 ; i<n ; i++) dst[i]= 1;
    }
    PopToI(l->owner);
  } else NotEqualError();
}

void NotEqualR(Operand *l, Operand *r)
{
  Range *lop= (Range *)l->owner->value.db, *rop= (Range *)r->owner->value.db;
  long lmin= lop->min, linc= lop->inc;
  int value= (lop->nilFlags!=rop->nilFlags) || (lmin!=rop->min) ||
    (linc!=rop->inc) || ((lop->max-lmin)/linc != (rop->max-lmin)/linc);
  PushIntValue(value);
  PopToI(l->owner);
}

void NotEqualX(Operand *l, Operand *r)
{
  DataBlock *lop= l->owner->value.db,  *rop= r->owner->value.db;
  PushIntValue(lop!=rop);
  PopToI(l->owner);
}

/*--------------------------------------------------------------------------*/