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
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
|
/*
* Copyright (c) Contributors, http://opensimulator.org/
* See CONTRIBUTORS.TXT for a full list of copyright holders.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the OpenSimulator Project nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
using OpenSim.Region.ScriptEngine.Shared.ScriptBase;
using OpenSim.Region.ScriptEngine.Yengine;
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Reflection.Emit;
using System.Text;
using System.Text.RegularExpressions;
using OpenSim.Region.ScriptEngine.Shared;
using LSL_Float = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLFloat;
using LSL_Integer = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLInteger;
using LSL_Key = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString;
using LSL_List = OpenSim.Region.ScriptEngine.Shared.LSL_Types.list;
using LSL_Rotation = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Quaternion;
using LSL_String = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString;
using LSL_Vector = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Vector3;
namespace OpenSim.Region.ScriptEngine.Yengine
{
/**
* @brief This class is used to catalog the code emit routines based on a key string
* The key string has the two types (eg, "integer", "rotation") and the operator (eg, "*", "!=")
*/
public delegate void BinOpStrEmitBO(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result);
public class BinOpStr
{
public static readonly Dictionary<string, BinOpStr> defined = DefineBinOps();
public Type outtype; // type of result of computation
public BinOpStrEmitBO emitBO; // how to compute result
public bool rmwOK; // is the <operator>= form valid?
public BinOpStr(Type outtype, BinOpStrEmitBO emitBO)
{
this.outtype = outtype;
this.emitBO = emitBO;
this.rmwOK = false;
}
public BinOpStr(Type outtype, BinOpStrEmitBO emitBO, bool rmwOK)
{
this.outtype = outtype;
this.emitBO = emitBO;
this.rmwOK = rmwOK;
}
private static TokenTypeBool tokenTypeBool = new TokenTypeBool(null);
private static TokenTypeChar tokenTypeChar = new TokenTypeChar(null);
private static TokenTypeFloat tokenTypeFloat = new TokenTypeFloat(null);
private static TokenTypeInt tokenTypeInt = new TokenTypeInt(null);
private static TokenTypeList tokenTypeList = new TokenTypeList(null);
private static TokenTypeRot tokenTypeRot = new TokenTypeRot(null);
private static TokenTypeStr tokenTypeStr = new TokenTypeStr(null);
private static TokenTypeVec tokenTypeVec = new TokenTypeVec(null);
private static MethodInfo stringAddStringMethInfo = ScriptCodeGen.GetStaticMethod(typeof(string), "Concat", new Type[] { typeof(string), typeof(string) });
private static MethodInfo stringCmpStringMethInfo = ScriptCodeGen.GetStaticMethod(typeof(string), "Compare", new Type[] { typeof(string), typeof(string), typeof(StringComparison) });
private static MethodInfo infoMethListAddFloat = GetBinOpsMethod("MethListAddFloat", new Type[] { typeof(LSL_List), typeof(double) });
private static MethodInfo infoMethListAddInt = GetBinOpsMethod("MethListAddInt", new Type[] { typeof(LSL_List), typeof(int) });
private static MethodInfo infoMethListAddKey = GetBinOpsMethod("MethListAddKey", new Type[] { typeof(LSL_List), typeof(string) });
private static MethodInfo infoMethListAddRot = GetBinOpsMethod("MethListAddRot", new Type[] { typeof(LSL_List), typeof(LSL_Rotation) });
private static MethodInfo infoMethListAddStr = GetBinOpsMethod("MethListAddStr", new Type[] { typeof(LSL_List), typeof(string) });
private static MethodInfo infoMethListAddVec = GetBinOpsMethod("MethListAddVec", new Type[] { typeof(LSL_List), typeof(LSL_Vector) });
private static MethodInfo infoMethListAddList = GetBinOpsMethod("MethListAddList", new Type[] { typeof(LSL_List), typeof(LSL_List) });
private static MethodInfo infoMethFloatAddList = GetBinOpsMethod("MethFloatAddList", new Type[] { typeof(double), typeof(LSL_List) });
private static MethodInfo infoMethIntAddList = GetBinOpsMethod("MethIntAddList", new Type[] { typeof(int), typeof(LSL_List) });
private static MethodInfo infoMethKeyAddList = GetBinOpsMethod("MethKeyAddList", new Type[] { typeof(string), typeof(LSL_List) });
private static MethodInfo infoMethRotAddList = GetBinOpsMethod("MethRotAddList", new Type[] { typeof(LSL_Rotation), typeof(LSL_List) });
private static MethodInfo infoMethStrAddList = GetBinOpsMethod("MethStrAddList", new Type[] { typeof(string), typeof(LSL_List) });
private static MethodInfo infoMethVecAddList = GetBinOpsMethod("MethVecAddList", new Type[] { typeof(LSL_Vector), typeof(LSL_List) });
private static MethodInfo infoMethListEqList = GetBinOpsMethod("MethListEqList", new Type[] { typeof(LSL_List), typeof(LSL_List) });
private static MethodInfo infoMethListNeList = GetBinOpsMethod("MethListNeList", new Type[] { typeof(LSL_List), typeof(LSL_List) });
private static MethodInfo infoMethRotEqRot = GetBinOpsMethod("MethRotEqRot", new Type[] { typeof(LSL_Rotation), typeof(LSL_Rotation) });
private static MethodInfo infoMethRotNeRot = GetBinOpsMethod("MethRotNeRot", new Type[] { typeof(LSL_Rotation), typeof(LSL_Rotation) });
private static MethodInfo infoMethRotAddRot = GetBinOpsMethod("MethRotAddRot", new Type[] { typeof(LSL_Rotation), typeof(LSL_Rotation) });
private static MethodInfo infoMethRotSubRot = GetBinOpsMethod("MethRotSubRot", new Type[] { typeof(LSL_Rotation), typeof(LSL_Rotation) });
private static MethodInfo infoMethRotMulRot = GetBinOpsMethod("MethRotMulRot", new Type[] { typeof(LSL_Rotation), typeof(LSL_Rotation) });
private static MethodInfo infoMethRotDivRot = GetBinOpsMethod("MethRotDivRot", new Type[] { typeof(LSL_Rotation), typeof(LSL_Rotation) });
private static MethodInfo infoMethVecEqVec = GetBinOpsMethod("MethVecEqVec", new Type[] { typeof(LSL_Vector), typeof(LSL_Vector) });
private static MethodInfo infoMethVecNeVec = GetBinOpsMethod("MethVecNeVec", new Type[] { typeof(LSL_Vector), typeof(LSL_Vector) });
private static MethodInfo infoMethVecAddVec = GetBinOpsMethod("MethVecAddVec", new Type[] { typeof(LSL_Vector), typeof(LSL_Vector) });
private static MethodInfo infoMethVecSubVec = GetBinOpsMethod("MethVecSubVec", new Type[] { typeof(LSL_Vector), typeof(LSL_Vector) });
private static MethodInfo infoMethVecMulVec = GetBinOpsMethod("MethVecMulVec", new Type[] { typeof(LSL_Vector), typeof(LSL_Vector) });
private static MethodInfo infoMethVecModVec = GetBinOpsMethod("MethVecModVec", new Type[] { typeof(LSL_Vector), typeof(LSL_Vector) });
private static MethodInfo infoMethVecMulFloat = GetBinOpsMethod("MethVecMulFloat", new Type[] { typeof(LSL_Vector), typeof(double) });
private static MethodInfo infoMethFloatMulVec = GetBinOpsMethod("MethFloatMulVec", new Type[] { typeof(double), typeof(LSL_Vector) });
private static MethodInfo infoMethVecDivFloat = GetBinOpsMethod("MethVecDivFloat", new Type[] { typeof(LSL_Vector), typeof(double) });
private static MethodInfo infoMethVecMulInt = GetBinOpsMethod("MethVecMulInt", new Type[] { typeof(LSL_Vector), typeof(int) });
private static MethodInfo infoMethIntMulVec = GetBinOpsMethod("MethIntMulVec", new Type[] { typeof(int), typeof(LSL_Vector) });
private static MethodInfo infoMethVecDivInt = GetBinOpsMethod("MethVecDivInt", new Type[] { typeof(LSL_Vector), typeof(int) });
private static MethodInfo infoMethVecMulRot = GetBinOpsMethod("MethVecMulRot", new Type[] { typeof(LSL_Vector), typeof(LSL_Rotation) });
private static MethodInfo infoMethVecDivRot = GetBinOpsMethod("MethVecDivRot", new Type[] { typeof(LSL_Vector), typeof(LSL_Rotation) });
private static MethodInfo infoMethDoubleDivDouble = GetBinOpsMethod("MethDoubleDivDouble", new Type[] { typeof(Double), typeof(Double) });
private static MethodInfo infoMethLongDivLong = GetBinOpsMethod("MethLongDivLong", new Type[] { typeof(long), typeof(long) });
private static MethodInfo infoMethDoubleModDouble = GetBinOpsMethod("MethDoubleModDouble", new Type[] { typeof(Double), typeof(Double) });
private static MethodInfo infoMethLongModLong = GetBinOpsMethod("MethLongModLong", new Type[] { typeof(long), typeof(long) });
private static MethodInfo GetBinOpsMethod(string name, Type[] types)
{
return ScriptCodeGen.GetStaticMethod(typeof(BinOpStr), name, types);
}
/**
* @brief Create a dictionary for processing binary operators.
* This tells us, for a given type, an operator and another type,
* is the operation permitted, and if so, what is the type of the result?
* The key is <lefttype><opcode><righttype>,
* where <lefttype> and <righttype> are strings returned by (TokenType...).ToString()
* and <opcode> is string returned by (TokenKw...).ToString()
* The value is a BinOpStr struct giving the resultant type and a method to generate the code.
*/
private static Dictionary<string, BinOpStr> DefineBinOps()
{
Dictionary<string, BinOpStr> bos = new Dictionary<string, BinOpStr>();
string[] booltypes = new string[] { "bool", "char", "float", "integer", "key", "list", "string" };
/*
* Get the && and || all out of the way...
* Simply cast their left and right operands to boolean then process.
*/
for(int i = 0; i < booltypes.Length; i++)
{
for(int j = 0; j < booltypes.Length; j++)
{
bos.Add(booltypes[i] + "&&" + booltypes[j],
new BinOpStr(typeof(bool), BinOpStrAndAnd));
bos.Add(booltypes[i] + "||" + booltypes[j],
new BinOpStr(typeof(bool), BinOpStrOrOr));
}
}
/*
* Pound through all the other combinations we support.
*/
// boolean : somethingelse
DefineBinOpsBoolX(bos, "bool");
DefineBinOpsBoolX(bos, "char");
DefineBinOpsBoolX(bos, "float");
DefineBinOpsBoolX(bos, "integer");
DefineBinOpsBoolX(bos, "key");
DefineBinOpsBoolX(bos, "list");
DefineBinOpsBoolX(bos, "string");
// stuff with chars
DefineBinOpsChar(bos);
// somethingelse : boolean
DefineBinOpsXBool(bos, "char");
DefineBinOpsXBool(bos, "float");
DefineBinOpsXBool(bos, "integer");
DefineBinOpsXBool(bos, "key");
DefineBinOpsXBool(bos, "list");
DefineBinOpsXBool(bos, "string");
// float : somethingelse
DefineBinOpsFloatX(bos, "float");
DefineBinOpsFloatX(bos, "integer");
// integer : float
DefineBinOpsXFloat(bos, "integer");
// anything else with integers
DefineBinOpsInteger(bos);
// key : somethingelse
DefineBinOpsKeyX(bos, "key");
DefineBinOpsKeyX(bos, "string");
// string : key
DefineBinOpsXKey(bos, "string");
// things with lists
DefineBinOpsList(bos);
// things with rotations
DefineBinOpsRotation(bos);
// things with strings
DefineBinOpsString(bos);
// things with vectors
DefineBinOpsVector(bos);
// Contrary to some beliefs, scripts do things like string+integer and integer+string
bos.Add("bool+string", new BinOpStr(typeof(string), BinOpStrStrAddStr));
bos.Add("char+string", new BinOpStr(typeof(string), BinOpStrStrAddStr));
bos.Add("float+string", new BinOpStr(typeof(string), BinOpStrStrAddStr));
bos.Add("integer+string", new BinOpStr(typeof(string), BinOpStrStrAddStr));
bos.Add("string+bool", new BinOpStr(typeof(string), BinOpStrStrAddStr, true));
bos.Add("string+char", new BinOpStr(typeof(string), BinOpStrStrAddStr, true));
bos.Add("string+float", new BinOpStr(typeof(string), BinOpStrStrAddStr, true));
bos.Add("string+integer", new BinOpStr(typeof(string), BinOpStrStrAddStr, true));
// Now for our final slight-of-hand, we're going to scan through all those.
// And wherever we see an 'integer' in the key, we are going to make another
// entry with 'bool', as we want to accept a bool as having a value of 0 or 1.
// This lets us do things like 3.5 * (x > 0).
Dictionary<string, BinOpStr> bos2 = new Dictionary<string, BinOpStr>();
foreach(KeyValuePair<string, BinOpStr> kvp in bos)
{
string key = kvp.Key;
BinOpStr val = kvp.Value;
bos2.Add(key, val);
}
Regex wordReg = new Regex("\\w+");
Regex opReg = new Regex("\\W+");
foreach(KeyValuePair<string, BinOpStr> kvp in bos)
{
string key = kvp.Key;
BinOpStr val = kvp.Value;
MatchCollection matches = wordReg.Matches(key);
if(matches.Count != 2)
continue;
Match opM = opReg.Match(key);
if(!opM.Success)
continue;
string left = matches[0].Value;
string right = matches[1].Value;
string op = opM.Value;
string key2;
if(left == "integer" && right == "integer")
{
key2 = "bool" + op + "bool";
if(!bos2.ContainsKey(key2))
bos2.Add(key2, val);
key2 = "bool" + op + "integer";
if(!bos2.ContainsKey(key2))
bos2.Add(key2, val);
key2 = "integer" + op + "bool";
if(!bos2.ContainsKey(key2))
bos2.Add(key2, val);
}
else
{
key2 = key.Replace("integer", "bool");
if(!bos2.ContainsKey(key2))
bos2.Add(key2, val);
}
}
return bos2;
}
private static void DefineBinOpsBoolX(Dictionary<string, BinOpStr> bos, string x)
{
bos.Add("bool|" + x, new BinOpStr(typeof(int), BinOpStrBoolOrX));
bos.Add("bool^" + x, new BinOpStr(typeof(int), BinOpStrBoolXorX));
bos.Add("bool&" + x, new BinOpStr(typeof(int), BinOpStrBoolAndX));
bos.Add("bool==" + x, new BinOpStr(typeof(bool), BinOpStrBoolEqX));
bos.Add("bool!=" + x, new BinOpStr(typeof(bool), BinOpStrBoolNeX));
}
private static void DefineBinOpsXBool(Dictionary<string, BinOpStr> bos, string x)
{
bos.Add(x + "|bool", new BinOpStr(typeof(int), BinOpStrBoolOrX));
bos.Add(x + "^bool", new BinOpStr(typeof(int), BinOpStrBoolXorX));
bos.Add(x + "&bool", new BinOpStr(typeof(int), BinOpStrBoolAndX));
bos.Add(x + "==bool", new BinOpStr(typeof(bool), BinOpStrBoolEqX));
bos.Add(x + "!=bool", new BinOpStr(typeof(bool), BinOpStrBoolNeX));
}
private static void DefineBinOpsFloatX(Dictionary<string, BinOpStr> bos, string x)
{
bos.Add("float==" + x, new BinOpStr(typeof(bool), BinOpStrFloatEqX));
bos.Add("float!=" + x, new BinOpStr(typeof(bool), BinOpStrFloatNeX));
bos.Add("float<" + x, new BinOpStr(typeof(bool), BinOpStrFloatLtX));
bos.Add("float<=" + x, new BinOpStr(typeof(bool), BinOpStrFloatLeX));
bos.Add("float>" + x, new BinOpStr(typeof(bool), BinOpStrFloatGtX));
bos.Add("float>=" + x, new BinOpStr(typeof(bool), BinOpStrFloatGeX));
bos.Add("float+" + x, new BinOpStr(typeof(double), BinOpStrFloatAddX, true));
bos.Add("float-" + x, new BinOpStr(typeof(double), BinOpStrFloatSubX, true));
bos.Add("float*" + x, new BinOpStr(typeof(double), BinOpStrFloatMulX, true));
bos.Add("float/" + x, new BinOpStr(typeof(double), BinOpStrFloatDivX, true));
bos.Add("float%" + x, new BinOpStr(typeof(double), BinOpStrFloatModX, true));
}
private static void DefineBinOpsXFloat(Dictionary<string, BinOpStr> bos, string x)
{
bos.Add(x + "==float", new BinOpStr(typeof(bool), BinOpStrXEqFloat));
bos.Add(x + "!=float", new BinOpStr(typeof(bool), BinOpStrXNeFloat));
bos.Add(x + "<float", new BinOpStr(typeof(bool), BinOpStrXLtFloat));
bos.Add(x + "<=float", new BinOpStr(typeof(bool), BinOpStrXLeFloat));
bos.Add(x + ">float", new BinOpStr(typeof(bool), BinOpStrXGtFloat));
bos.Add(x + ">=float", new BinOpStr(typeof(bool), BinOpStrXGeFloat));
bos.Add(x + "+float", new BinOpStr(typeof(double), BinOpStrXAddFloat, true));
bos.Add(x + "-float", new BinOpStr(typeof(double), BinOpStrXSubFloat, true));
bos.Add(x + "*float", new BinOpStr(typeof(double), BinOpStrXMulFloat, true));
bos.Add(x + "/float", new BinOpStr(typeof(double), BinOpStrXDivFloat, true));
bos.Add(x + "%float", new BinOpStr(typeof(double), BinOpStrXModFloat, true));
}
private static void DefineBinOpsChar(Dictionary<string, BinOpStr> bos)
{
bos.Add("char==char", new BinOpStr(typeof(bool), BinOpStrCharEqChar));
bos.Add("char!=char", new BinOpStr(typeof(bool), BinOpStrCharNeChar));
bos.Add("char<char", new BinOpStr(typeof(bool), BinOpStrCharLtChar));
bos.Add("char<=char", new BinOpStr(typeof(bool), BinOpStrCharLeChar));
bos.Add("char>char", new BinOpStr(typeof(bool), BinOpStrCharGtChar));
bos.Add("char>=char", new BinOpStr(typeof(bool), BinOpStrCharGeChar));
bos.Add("char+integer", new BinOpStr(typeof(char), BinOpStrCharAddInt, true));
bos.Add("char-integer", new BinOpStr(typeof(char), BinOpStrCharSubInt, true));
bos.Add("char-char", new BinOpStr(typeof(int), BinOpStrCharSubChar));
}
private static void DefineBinOpsInteger(Dictionary<string, BinOpStr> bos)
{
bos.Add("integer==integer", new BinOpStr(typeof(bool), BinOpStrIntEqInt));
bos.Add("integer!=integer", new BinOpStr(typeof(bool), BinOpStrIntNeInt));
bos.Add("integer<integer", new BinOpStr(typeof(bool), BinOpStrIntLtInt));
bos.Add("integer<=integer", new BinOpStr(typeof(bool), BinOpStrIntLeInt));
bos.Add("integer>integer", new BinOpStr(typeof(bool), BinOpStrIntGtInt));
bos.Add("integer>=integer", new BinOpStr(typeof(bool), BinOpStrIntGeInt));
bos.Add("integer|integer", new BinOpStr(typeof(int), BinOpStrIntOrInt, true));
bos.Add("integer^integer", new BinOpStr(typeof(int), BinOpStrIntXorInt, true));
bos.Add("integer&integer", new BinOpStr(typeof(int), BinOpStrIntAndInt, true));
bos.Add("integer+integer", new BinOpStr(typeof(int), BinOpStrIntAddInt, true));
bos.Add("integer-integer", new BinOpStr(typeof(int), BinOpStrIntSubInt, true));
bos.Add("integer*integer", new BinOpStr(typeof(int), BinOpStrIntMulInt, true));
bos.Add("integer/integer", new BinOpStr(typeof(int), BinOpStrIntDivInt, true));
bos.Add("integer%integer", new BinOpStr(typeof(int), BinOpStrIntModInt, true));
bos.Add("integer<<integer", new BinOpStr(typeof(int), BinOpStrIntShlInt, true));
bos.Add("integer>>integer", new BinOpStr(typeof(int), BinOpStrIntShrInt, true));
}
private static void DefineBinOpsKeyX(Dictionary<string, BinOpStr> bos, string x)
{
bos.Add("key==" + x, new BinOpStr(typeof(bool), BinOpStrKeyEqX));
bos.Add("key!=" + x, new BinOpStr(typeof(bool), BinOpStrKeyNeX));
}
private static void DefineBinOpsXKey(Dictionary<string, BinOpStr> bos, string x)
{
bos.Add(x + "==key", new BinOpStr(typeof(bool), BinOpStrKeyEqX));
bos.Add(x + "!=key", new BinOpStr(typeof(bool), BinOpStrKeyNeX));
}
private static void DefineBinOpsList(Dictionary<string, BinOpStr> bos)
{
bos.Add("list+float", new BinOpStr(typeof(LSL_List), BinOpStrListAddFloat, true));
bos.Add("list+integer", new BinOpStr(typeof(LSL_List), BinOpStrListAddInt, true));
bos.Add("list+key", new BinOpStr(typeof(LSL_List), BinOpStrListAddKey, true));
bos.Add("list+list", new BinOpStr(typeof(LSL_List), BinOpStrListAddList, true));
bos.Add("list+rotation", new BinOpStr(typeof(LSL_List), BinOpStrListAddRot, true));
bos.Add("list+string", new BinOpStr(typeof(LSL_List), BinOpStrListAddStr, true));
bos.Add("list+vector", new BinOpStr(typeof(LSL_List), BinOpStrListAddVec, true));
bos.Add("float+list", new BinOpStr(typeof(LSL_List), BinOpStrFloatAddList));
bos.Add("integer+list", new BinOpStr(typeof(LSL_List), BinOpStrIntAddList));
bos.Add("key+list", new BinOpStr(typeof(LSL_List), BinOpStrKeyAddList));
bos.Add("rotation+list", new BinOpStr(typeof(LSL_List), BinOpStrRotAddList));
bos.Add("string+list", new BinOpStr(typeof(LSL_List), BinOpStrStrAddList));
bos.Add("vector+list", new BinOpStr(typeof(LSL_List), BinOpStrVecAddList));
bos.Add("list==list", new BinOpStr(typeof(bool), BinOpStrListEqList));
bos.Add("list!=list", new BinOpStr(typeof(int), BinOpStrListNeList));
}
// all operations allowed by LSL_Rotation definition
private static void DefineBinOpsRotation(Dictionary<string, BinOpStr> bos)
{
bos.Add("rotation==rotation", new BinOpStr(typeof(bool), BinOpStrRotEqRot));
bos.Add("rotation!=rotation", new BinOpStr(typeof(bool), BinOpStrRotNeRot));
bos.Add("rotation+rotation", new BinOpStr(typeof(LSL_Rotation), BinOpStrRotAddRot, true));
bos.Add("rotation-rotation", new BinOpStr(typeof(LSL_Rotation), BinOpStrRotSubRot, true));
bos.Add("rotation*rotation", new BinOpStr(typeof(LSL_Rotation), BinOpStrRotMulRot, true));
bos.Add("rotation/rotation", new BinOpStr(typeof(LSL_Rotation), BinOpStrRotDivRot, true));
}
private static void DefineBinOpsString(Dictionary<string, BinOpStr> bos)
{
bos.Add("string==string", new BinOpStr(typeof(bool), BinOpStrStrEqStr));
bos.Add("string!=string", new BinOpStr(typeof(bool), BinOpStrStrNeStr));
bos.Add("string<string", new BinOpStr(typeof(bool), BinOpStrStrLtStr));
bos.Add("string<=string", new BinOpStr(typeof(bool), BinOpStrStrLeStr));
bos.Add("string>string", new BinOpStr(typeof(bool), BinOpStrStrGtStr));
bos.Add("string>=string", new BinOpStr(typeof(bool), BinOpStrStrGeStr));
bos.Add("string+string", new BinOpStr(typeof(string), BinOpStrStrAddStr, true));
}
// all operations allowed by LSL_Vector definition
private static void DefineBinOpsVector(Dictionary<string, BinOpStr> bos)
{
bos.Add("vector==vector", new BinOpStr(typeof(bool), BinOpStrVecEqVec));
bos.Add("vector!=vector", new BinOpStr(typeof(bool), BinOpStrVecNeVec));
bos.Add("vector+vector", new BinOpStr(typeof(LSL_Vector), BinOpStrVecAddVec, true));
bos.Add("vector-vector", new BinOpStr(typeof(LSL_Vector), BinOpStrVecSubVec, true));
bos.Add("vector*vector", new BinOpStr(typeof(double), BinOpStrVecMulVec));
bos.Add("vector%vector", new BinOpStr(typeof(LSL_Vector), BinOpStrVecModVec, true));
bos.Add("vector*float", new BinOpStr(typeof(LSL_Vector), BinOpStrVecMulFloat, true));
bos.Add("float*vector", new BinOpStr(typeof(LSL_Vector), BinOpStrFloatMulVec));
bos.Add("vector/float", new BinOpStr(typeof(LSL_Vector), BinOpStrVecDivFloat, true));
bos.Add("vector*integer", new BinOpStr(typeof(LSL_Vector), BinOpStrVecMulInt, true));
bos.Add("integer*vector", new BinOpStr(typeof(LSL_Vector), BinOpStrIntMulVec));
bos.Add("vector/integer", new BinOpStr(typeof(LSL_Vector), BinOpStrVecDivInt, true));
bos.Add("vector*rotation", new BinOpStr(typeof(LSL_Vector), BinOpStrVecMulRot, true));
bos.Add("vector/rotation", new BinOpStr(typeof(LSL_Vector), BinOpStrVecDivRot, true));
}
/**
* @brief These methods actually emit the code to perform the arithmetic.
* @param scg = what script we are compiling
* @param left = left-hand operand location in memory (type as given by BinOpStr entry)
* @param right = right-hand operand location in memory (type as given by BinOpStr entry)
* @param result = result location in memory (type as given by BinOpStr entry)
*/
private static void BinOpStrAndAnd(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
{
result.PopPre(scg, errorAt);
left.PushVal(scg, errorAt, tokenTypeBool);
right.PushVal(scg, errorAt, tokenTypeBool);
scg.ilGen.Emit(errorAt, OpCodes.And);
result.PopPost(scg, errorAt, tokenTypeBool);
}
private static void BinOpStrOrOr(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
{
result.PopPre(scg, errorAt);
left.PushVal(scg, errorAt, tokenTypeBool);
right.PushVal(scg, errorAt, tokenTypeBool);
scg.ilGen.Emit(errorAt, OpCodes.Or);
result.PopPost(scg, errorAt, tokenTypeBool);
}
private static void BinOpStrBoolOrX(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
{
result.PopPre(scg, errorAt);
left.PushVal(scg, errorAt, tokenTypeInt);
right.PushVal(scg, errorAt, tokenTypeInt);
scg.ilGen.Emit(errorAt, OpCodes.Or);
result.PopPost(scg, errorAt, tokenTypeInt);
}
private static void BinOpStrBoolXorX(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
{
result.PopPre(scg, errorAt);
left.PushVal(scg, errorAt, tokenTypeInt);
right.PushVal(scg, errorAt, tokenTypeInt);
scg.ilGen.Emit(errorAt, OpCodes.Xor);
result.PopPost(scg, errorAt, tokenTypeInt);
}
private static void BinOpStrBoolAndX(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
{
result.PopPre(scg, errorAt);
left.PushVal(scg, errorAt, tokenTypeInt);
right.PushVal(scg, errorAt, tokenTypeInt);
scg.ilGen.Emit(errorAt, OpCodes.And);
result.PopPost(scg, errorAt, tokenTypeInt);
}
private static void BinOpStrBoolEqX(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
{
result.PopPre(scg, errorAt);
left.PushVal(scg, errorAt, tokenTypeBool);
right.PushVal(scg, errorAt, tokenTypeBool);
scg.ilGen.Emit(errorAt, OpCodes.Ceq);
result.PopPost(scg, errorAt, tokenTypeBool);
}
private static void BinOpStrBoolNeX(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
{
result.PopPre(scg, errorAt);
left.PushVal(scg, errorAt, tokenTypeBool);
right.PushVal(scg, errorAt, tokenTypeBool);
scg.ilGen.Emit(errorAt, OpCodes.Xor);
result.PopPost(scg, errorAt, tokenTypeBool);
}
private static void BinOpStrFloatEqX(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
{
result.PopPre(scg, errorAt);
left.PushVal(scg, errorAt, tokenTypeFloat);
right.PushVal(scg, errorAt, tokenTypeFloat);
scg.ilGen.Emit(errorAt, OpCodes.Ceq);
result.PopPost(scg, errorAt, tokenTypeBool);
}
private static void BinOpStrFloatNeX(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
{
result.PopPre(scg, errorAt);
left.PushVal(scg, errorAt, tokenTypeFloat);
right.PushVal(scg, errorAt, tokenTypeFloat);
scg.ilGen.Emit(errorAt, OpCodes.Ceq);
scg.ilGen.Emit(errorAt, OpCodes.Ldc_I4_1);
scg.ilGen.Emit(errorAt, OpCodes.Xor);
result.PopPost(scg, errorAt, tokenTypeBool);
}
private static void BinOpStrFloatLtX(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
{
result.PopPre(scg, errorAt);
left.PushVal(scg, errorAt, tokenTypeFloat);
right.PushVal(scg, errorAt, tokenTypeFloat);
scg.ilGen.Emit(errorAt, OpCodes.Clt);
result.PopPost(scg, errorAt, tokenTypeBool);
}
private static void BinOpStrFloatLeX(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
{
result.PopPre(scg, errorAt);
left.PushVal(scg, errorAt, tokenTypeFloat);
right.PushVal(scg, errorAt, tokenTypeFloat);
scg.ilGen.Emit(errorAt, OpCodes.Cgt);
scg.ilGen.Emit(errorAt, OpCodes.Ldc_I4_1);
scg.ilGen.Emit(errorAt, OpCodes.Xor);
result.PopPost(scg, errorAt, tokenTypeBool);
}
private static void BinOpStrFloatGtX(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
{
result.PopPre(scg, errorAt);
left.PushVal(scg, errorAt, tokenTypeFloat);
right.PushVal(scg, errorAt, tokenTypeFloat);
scg.ilGen.Emit(errorAt, OpCodes.Cgt);
result.PopPost(scg, errorAt, tokenTypeBool);
}
private static void BinOpStrFloatGeX(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
{
result.PopPre(scg, errorAt);
left.PushVal(scg, errorAt, tokenTypeFloat);
right.PushVal(scg, errorAt, tokenTypeFloat);
scg.ilGen.Emit(errorAt, OpCodes.Clt);
scg.ilGen.Emit(errorAt, OpCodes.Ldc_I4_1);
scg.ilGen.Emit(errorAt, OpCodes.Xor);
result.PopPost(scg, errorAt, tokenTypeBool);
}
private static void BinOpStrFloatAddX(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
{
result.PopPre(scg, errorAt);
left.PushVal(scg, errorAt, tokenTypeFloat);
right.PushVal(scg, errorAt, tokenTypeFloat);
scg.ilGen.Emit(errorAt, OpCodes.Add);
result.PopPost(scg, errorAt, tokenTypeFloat);
}
private static void BinOpStrFloatSubX(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
{
result.PopPre(scg, errorAt);
left.PushVal(scg, errorAt, tokenTypeFloat);
right.PushVal(scg, errorAt, tokenTypeFloat);
scg.ilGen.Emit(errorAt, OpCodes.Sub);
result.PopPost(scg, errorAt, tokenTypeFloat);
}
private static void BinOpStrFloatMulX(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
{
result.PopPre(scg, errorAt);
left.PushVal(scg, errorAt, tokenTypeFloat);
right.PushVal(scg, errorAt, tokenTypeFloat);
scg.ilGen.Emit(errorAt, OpCodes.Mul);
result.PopPost(scg, errorAt, tokenTypeFloat);
}
private static void BinOpStrFloatDivX(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
{
result.PopPre(scg, errorAt);
left.PushVal(scg, errorAt, tokenTypeFloat);
right.PushVal(scg, errorAt, tokenTypeFloat);
//scg.ilGen.Emit(errorAt, OpCodes.Div);
scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethDoubleDivDouble);
result.PopPost(scg, errorAt, tokenTypeFloat);
}
private static void BinOpStrFloatModX(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
{
result.PopPre(scg, errorAt);
left.PushVal(scg, errorAt, tokenTypeFloat);
right.PushVal(scg, errorAt, tokenTypeFloat);
//scg.ilGen.Emit(errorAt, OpCodes.Rem);
scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethDoubleModDouble);
result.PopPost(scg, errorAt, tokenTypeFloat);
}
private static void BinOpStrXEqFloat(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
{
result.PopPre(scg, errorAt);
left.PushVal(scg, errorAt, tokenTypeFloat);
right.PushVal(scg, errorAt, tokenTypeFloat);
scg.ilGen.Emit(errorAt, OpCodes.Ceq);
result.PopPost(scg, errorAt, tokenTypeBool);
}
private static void BinOpStrXNeFloat(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
{
result.PopPre(scg, errorAt);
left.PushVal(scg, errorAt, tokenTypeFloat);
right.PushVal(scg, errorAt, tokenTypeFloat);
scg.ilGen.Emit(errorAt, OpCodes.Ceq);
scg.ilGen.Emit(errorAt, OpCodes.Ldc_I4_1);
scg.ilGen.Emit(errorAt, OpCodes.Xor);
result.PopPost(scg, errorAt, tokenTypeBool);
}
private static void BinOpStrXLtFloat(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
{
result.PopPre(scg, errorAt);
left.PushVal(scg, errorAt, tokenTypeFloat);
right.PushVal(scg, errorAt, tokenTypeFloat);
scg.ilGen.Emit(errorAt, OpCodes.Clt);
result.PopPost(scg, errorAt, tokenTypeBool);
}
private static void BinOpStrXLeFloat(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
{
result.PopPre(scg, errorAt);
left.PushVal(scg, errorAt, tokenTypeFloat);
right.PushVal(scg, errorAt, tokenTypeFloat);
scg.ilGen.Emit(errorAt, OpCodes.Cgt);
scg.ilGen.Emit(errorAt, OpCodes.Ldc_I4_1);
scg.ilGen.Emit(errorAt, OpCodes.Xor);
result.PopPost(scg, errorAt, tokenTypeBool);
}
private static void BinOpStrXGtFloat(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
{
result.PopPre(scg, errorAt);
left.PushVal(scg, errorAt, tokenTypeFloat);
right.PushVal(scg, errorAt, tokenTypeFloat);
scg.ilGen.Emit(errorAt, OpCodes.Cgt);
result.PopPost(scg, errorAt, tokenTypeBool);
}
private static void BinOpStrXGeFloat(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
{
result.PopPre(scg, errorAt);
left.PushVal(scg, errorAt, tokenTypeFloat);
right.PushVal(scg, errorAt, tokenTypeFloat);
scg.ilGen.Emit(errorAt, OpCodes.Clt);
scg.ilGen.Emit(errorAt, OpCodes.Ldc_I4_1);
scg.ilGen.Emit(errorAt, OpCodes.Xor);
result.PopPost(scg, errorAt, tokenTypeBool);
}
private static void BinOpStrXAddFloat(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
{
result.PopPre(scg, errorAt);
left.PushVal(scg, errorAt, tokenTypeFloat);
right.PushVal(scg, errorAt, tokenTypeFloat);
scg.ilGen.Emit(errorAt, OpCodes.Add);
result.PopPost(scg, errorAt, tokenTypeFloat);
}
private static void BinOpStrXSubFloat(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
{
result.PopPre(scg, errorAt);
left.PushVal(scg, errorAt, tokenTypeFloat);
right.PushVal(scg, errorAt, tokenTypeFloat);
scg.ilGen.Emit(errorAt, OpCodes.Sub);
result.PopPost(scg, errorAt, tokenTypeFloat);
}
private static void BinOpStrXMulFloat(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
{
result.PopPre(scg, errorAt);
left.PushVal(scg, errorAt, tokenTypeFloat);
right.PushVal(scg, errorAt, tokenTypeFloat);
scg.ilGen.Emit(errorAt, OpCodes.Mul);
result.PopPost(scg, errorAt, tokenTypeFloat);
}
private static void BinOpStrXDivFloat(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
{
result.PopPre(scg, errorAt);
left.PushVal(scg, errorAt, tokenTypeFloat);
right.PushVal(scg, errorAt, tokenTypeFloat);
//scg.ilGen.Emit(errorAt, OpCodes.Div);
scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethDoubleDivDouble);
result.PopPost(scg, errorAt, tokenTypeFloat);
}
private static void BinOpStrXModFloat(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
{
result.PopPre(scg, errorAt);
left.PushVal(scg, errorAt, tokenTypeFloat);
right.PushVal(scg, errorAt, tokenTypeFloat);
//scg.ilGen.Emit(errorAt, OpCodes.Rem);
scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethDoubleModDouble);
result.PopPost(scg, errorAt, tokenTypeFloat);
}
private static void BinOpStrCharEqChar(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
{
result.PopPre(scg, errorAt);
left.PushVal(scg, errorAt, tokenTypeChar);
right.PushVal(scg, errorAt, tokenTypeChar);
scg.ilGen.Emit(errorAt, OpCodes.Ceq);
result.PopPost(scg, errorAt, tokenTypeBool);
}
private static void BinOpStrCharNeChar(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
{
result.PopPre(scg, errorAt);
left.PushVal(scg, errorAt, tokenTypeChar);
right.PushVal(scg, errorAt, tokenTypeChar);
scg.ilGen.Emit(errorAt, OpCodes.Ceq);
scg.ilGen.Emit(errorAt, OpCodes.Ldc_I4_1);
scg.ilGen.Emit(errorAt, OpCodes.Xor);
result.PopPost(scg, errorAt, tokenTypeBool);
}
private static void BinOpStrCharLtChar(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
{
result.PopPre(scg, errorAt);
left.PushVal(scg, errorAt, tokenTypeChar);
right.PushVal(scg, errorAt, tokenTypeChar);
scg.ilGen.Emit(errorAt, OpCodes.Clt);
result.PopPost(scg, errorAt, tokenTypeBool);
}
private static void BinOpStrCharLeChar(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
{
result.PopPre(scg, errorAt);
left.PushVal(scg, errorAt, tokenTypeChar);
right.PushVal(scg, errorAt, tokenTypeChar);
scg.ilGen.Emit(errorAt, OpCodes.Cgt);
scg.ilGen.Emit(errorAt, OpCodes.Ldc_I4_1);
scg.ilGen.Emit(errorAt, OpCodes.Xor);
result.PopPost(scg, errorAt, tokenTypeBool);
}
private static void BinOpStrCharGtChar(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
{
result.PopPre(scg, errorAt);
left.PushVal(scg, errorAt, tokenTypeChar);
right.PushVal(scg, errorAt, tokenTypeChar);
scg.ilGen.Emit(errorAt, OpCodes.Cgt);
result.PopPost(scg, errorAt, tokenTypeBool);
}
private static void BinOpStrCharGeChar(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
{
result.PopPre(scg, errorAt);
left.PushVal(scg, errorAt, tokenTypeChar);
right.PushVal(scg, errorAt, tokenTypeChar);
scg.ilGen.Emit(errorAt, OpCodes.Clt);
scg.ilGen.Emit(errorAt, OpCodes.Ldc_I4_1);
scg.ilGen.Emit(errorAt, OpCodes.Xor);
result.PopPost(scg, errorAt, tokenTypeBool);
}
private static void BinOpStrCharAddInt(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
{
result.PopPre(scg, errorAt);
left.PushVal(scg, errorAt, tokenTypeChar);
right.PushVal(scg, errorAt, tokenTypeInt);
scg.ilGen.Emit(errorAt, OpCodes.Add);
result.PopPost(scg, errorAt, tokenTypeChar);
}
private static void BinOpStrCharSubInt(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
{
result.PopPre(scg, errorAt);
left.PushVal(scg, errorAt, tokenTypeChar);
right.PushVal(scg, errorAt, tokenTypeInt);
scg.ilGen.Emit(errorAt, OpCodes.Sub);
result.PopPost(scg, errorAt, tokenTypeChar);
}
private static void BinOpStrCharSubChar(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
{
result.PopPre(scg, errorAt);
left.PushVal(scg, errorAt, tokenTypeChar);
right.PushVal(scg, errorAt, tokenTypeChar);
scg.ilGen.Emit(errorAt, OpCodes.Sub);
result.PopPost(scg, errorAt, tokenTypeInt);
}
private static void BinOpStrIntEqInt(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
{
result.PopPre(scg, errorAt);
left.PushVal(scg, errorAt, tokenTypeInt);
right.PushVal(scg, errorAt, tokenTypeInt);
scg.ilGen.Emit(errorAt, OpCodes.Ceq);
result.PopPost(scg, errorAt, tokenTypeBool);
}
private static void BinOpStrIntNeInt(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
{
result.PopPre(scg, errorAt);
left.PushVal(scg, errorAt, tokenTypeInt);
right.PushVal(scg, errorAt, tokenTypeInt);
scg.ilGen.Emit(errorAt, OpCodes.Ceq);
scg.ilGen.Emit(errorAt, OpCodes.Ldc_I4_1);
scg.ilGen.Emit(errorAt, OpCodes.Xor);
result.PopPost(scg, errorAt, tokenTypeBool);
}
private static void BinOpStrIntLtInt(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
{
result.PopPre(scg, errorAt);
left.PushVal(scg, errorAt, tokenTypeInt);
right.PushVal(scg, errorAt, tokenTypeInt);
scg.ilGen.Emit(errorAt, OpCodes.Clt);
result.PopPost(scg, errorAt, tokenTypeBool);
}
private static void BinOpStrIntLeInt(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
{
result.PopPre(scg, errorAt);
left.PushVal(scg, errorAt, tokenTypeInt);
right.PushVal(scg, errorAt, tokenTypeInt);
scg.ilGen.Emit(errorAt, OpCodes.Cgt);
scg.ilGen.Emit(errorAt, OpCodes.Ldc_I4_1);
scg.ilGen.Emit(errorAt, OpCodes.Xor);
result.PopPost(scg, errorAt, tokenTypeBool);
}
private static void BinOpStrIntGtInt(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
{
result.PopPre(scg, errorAt);
left.PushVal(scg, errorAt, tokenTypeInt);
right.PushVal(scg, errorAt, tokenTypeInt);
scg.ilGen.Emit(errorAt, OpCodes.Cgt);
result.PopPost(scg, errorAt, tokenTypeBool);
}
private static void BinOpStrIntGeInt(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
{
result.PopPre(scg, errorAt);
left.PushVal(scg, errorAt, tokenTypeInt);
right.PushVal(scg, errorAt, tokenTypeInt);
scg.ilGen.Emit(errorAt, OpCodes.Clt);
scg.ilGen.Emit(errorAt, OpCodes.Ldc_I4_1);
scg.ilGen.Emit(errorAt, OpCodes.Xor);
result.PopPost(scg, errorAt, tokenTypeBool);
}
private static void BinOpStrIntOrInt(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
{
result.PopPre(scg, errorAt);
left.PushVal(scg, errorAt, tokenTypeInt);
right.PushVal(scg, errorAt, tokenTypeInt);
scg.ilGen.Emit(errorAt, OpCodes.Or);
result.PopPost(scg, errorAt, tokenTypeInt);
}
private static void BinOpStrIntXorInt(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
{
result.PopPre(scg, errorAt);
left.PushVal(scg, errorAt, tokenTypeInt);
right.PushVal(scg, errorAt, tokenTypeInt);
scg.ilGen.Emit(errorAt, OpCodes.Xor);
result.PopPost(scg, errorAt, tokenTypeInt);
}
private static void BinOpStrIntAndInt(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
{
result.PopPre(scg, errorAt);
left.PushVal(scg, errorAt, tokenTypeInt);
right.PushVal(scg, errorAt, tokenTypeInt);
scg.ilGen.Emit(errorAt, OpCodes.And);
result.PopPost(scg, errorAt, tokenTypeInt);
}
private static void BinOpStrIntAddInt(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
{
result.PopPre(scg, errorAt);
left.PushVal(scg, errorAt, tokenTypeInt);
right.PushVal(scg, errorAt, tokenTypeInt);
scg.ilGen.Emit(errorAt, OpCodes.Add);
result.PopPost(scg, errorAt, tokenTypeInt);
}
private static void BinOpStrIntSubInt(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
{
result.PopPre(scg, errorAt);
left.PushVal(scg, errorAt, tokenTypeInt);
right.PushVal(scg, errorAt, tokenTypeInt);
scg.ilGen.Emit(errorAt, OpCodes.Sub);
result.PopPost(scg, errorAt, tokenTypeInt);
}
private static void BinOpStrIntMulInt(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
{
result.PopPre(scg, errorAt);
left.PushVal(scg, errorAt, tokenTypeInt);
right.PushVal(scg, errorAt, tokenTypeInt);
scg.ilGen.Emit(errorAt, OpCodes.Mul);
result.PopPost(scg, errorAt, tokenTypeInt);
}
private static void BinOpStrIntDivInt(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
{
// note that we must allow 0x800000/-1 -> 0x80000000 for lslangtest1.lsl
// so sign-extend the operands to 64-bit then divide and truncate result
result.PopPre(scg, errorAt);
left.PushVal(scg, errorAt, tokenTypeInt);
scg.ilGen.Emit(errorAt, OpCodes.Conv_I8);
right.PushVal(scg, errorAt, tokenTypeInt);
scg.ilGen.Emit(errorAt, OpCodes.Conv_I8);
//scg.ilGen.Emit(errorAt, OpCodes.Div);
scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethLongDivLong);
scg.ilGen.Emit(errorAt, OpCodes.Conv_I4);
result.PopPost(scg, errorAt, tokenTypeInt);
}
private static void BinOpStrIntModInt(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
{
// note that we must allow 0x800000%-1 -> 0 for lslangtest1.lsl
// so sign-extend the operands to 64-bit then mod and truncate result
result.PopPre(scg, errorAt);
left.PushVal(scg, errorAt, tokenTypeInt);
scg.ilGen.Emit(errorAt, OpCodes.Conv_I8);
right.PushVal(scg, errorAt, tokenTypeInt);
scg.ilGen.Emit(errorAt, OpCodes.Conv_I8);
//scg.ilGen.Emit(errorAt, OpCodes.Rem);
scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethLongModLong);
scg.ilGen.Emit(errorAt, OpCodes.Conv_I4);
result.PopPost(scg, errorAt, tokenTypeInt);
}
private static void BinOpStrIntShlInt(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
{
result.PopPre(scg, errorAt);
left.PushVal(scg, errorAt, tokenTypeInt);
right.PushVal(scg, errorAt, tokenTypeInt);
scg.ilGen.Emit(errorAt, OpCodes.Shl);
result.PopPost(scg, errorAt, tokenTypeInt);
}
private static void BinOpStrIntShrInt(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
{
result.PopPre(scg, errorAt);
left.PushVal(scg, errorAt, tokenTypeInt);
right.PushVal(scg, errorAt, tokenTypeInt);
scg.ilGen.Emit(errorAt, OpCodes.Shr);
result.PopPost(scg, errorAt, tokenTypeInt);
}
private static void BinOpStrKeyEqX(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
{
result.PopPre(scg, errorAt);
left.PushVal(scg, errorAt, tokenTypeStr);
right.PushVal(scg, errorAt, tokenTypeStr);
scg.ilGen.Emit(errorAt, OpCodes.Ldc_I4, (int)StringComparison.Ordinal);
scg.ilGen.Emit(errorAt, OpCodes.Call, stringCmpStringMethInfo);
scg.ilGen.Emit(errorAt, OpCodes.Ldc_I4_0);
scg.ilGen.Emit(errorAt, OpCodes.Ceq);
result.PopPost(scg, errorAt, tokenTypeBool);
}
private static void BinOpStrKeyNeX(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
{
result.PopPre(scg, errorAt);
left.PushVal(scg, errorAt, tokenTypeStr);
right.PushVal(scg, errorAt, tokenTypeStr);
scg.ilGen.Emit(errorAt, OpCodes.Ldc_I4, (int)StringComparison.Ordinal);
scg.ilGen.Emit(errorAt, OpCodes.Call, stringCmpStringMethInfo);
scg.ilGen.Emit(errorAt, OpCodes.Ldc_I4_0);
scg.ilGen.Emit(errorAt, OpCodes.Ceq);
scg.ilGen.Emit(errorAt, OpCodes.Ldc_I4_1);
scg.ilGen.Emit(errorAt, OpCodes.Xor);
result.PopPost(scg, errorAt, tokenTypeBool);
}
private static void BinOpStrListAddFloat(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
{
result.PopPre(scg, errorAt);
left.PushVal(scg, errorAt, tokenTypeList);
right.PushVal(scg, errorAt, tokenTypeFloat);
scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethListAddFloat);
result.PopPost(scg, errorAt, tokenTypeList);
}
private static void BinOpStrListAddInt(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
{
result.PopPre(scg, errorAt);
left.PushVal(scg, errorAt, tokenTypeList);
right.PushVal(scg, errorAt, tokenTypeInt);
scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethListAddInt);
result.PopPost(scg, errorAt, tokenTypeList);
}
private static void BinOpStrListAddKey(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
{
result.PopPre(scg, errorAt);
left.PushVal(scg, errorAt, tokenTypeList);
right.PushVal(scg, errorAt, tokenTypeStr);
scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethListAddKey);
result.PopPost(scg, errorAt, tokenTypeList);
}
private static void BinOpStrListAddList(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
{
result.PopPre(scg, errorAt);
left.PushVal(scg, errorAt, tokenTypeList);
right.PushVal(scg, errorAt, tokenTypeList);
scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethListAddList);
result.PopPost(scg, errorAt, tokenTypeList);
}
private static void BinOpStrListAddRot(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
{
result.PopPre(scg, errorAt);
left.PushVal(scg, errorAt, tokenTypeList);
right.PushVal(scg, errorAt, tokenTypeRot);
scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethListAddRot);
result.PopPost(scg, errorAt, tokenTypeList);
}
private static void BinOpStrListAddStr(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
{
result.PopPre(scg, errorAt);
left.PushVal(scg, errorAt, tokenTypeList);
right.PushVal(scg, errorAt, tokenTypeStr);
scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethListAddStr);
result.PopPost(scg, errorAt, tokenTypeList);
}
private static void BinOpStrListAddVec(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
{
result.PopPre(scg, errorAt);
left.PushVal(scg, errorAt, tokenTypeList);
right.PushVal(scg, errorAt, tokenTypeVec);
scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethListAddVec);
result.PopPost(scg, errorAt, tokenTypeList);
}
private static void BinOpStrFloatAddList(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
{
result.PopPre(scg, errorAt);
left.PushVal(scg, errorAt, tokenTypeFloat);
right.PushVal(scg, errorAt, tokenTypeList);
scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethFloatAddList);
result.PopPost(scg, errorAt, tokenTypeList);
}
private static void BinOpStrIntAddList(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
{
result.PopPre(scg, errorAt);
left.PushVal(scg, errorAt, tokenTypeInt);
right.PushVal(scg, errorAt, tokenTypeList);
scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethIntAddList);
result.PopPost(scg, errorAt, tokenTypeList);
}
private static void BinOpStrKeyAddList(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
{
result.PopPre(scg, errorAt);
left.PushVal(scg, errorAt, tokenTypeStr);
right.PushVal(scg, errorAt, tokenTypeList);
scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethKeyAddList);
result.PopPost(scg, errorAt, tokenTypeList);
}
private static void BinOpStrRotAddList(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
{
result.PopPre(scg, errorAt);
left.PushVal(scg, errorAt, tokenTypeRot);
right.PushVal(scg, errorAt, tokenTypeList);
scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethRotAddList);
result.PopPost(scg, errorAt, tokenTypeList);
}
private static void BinOpStrStrAddList(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
{
result.PopPre(scg, errorAt);
left.PushVal(scg, errorAt, tokenTypeStr);
right.PushVal(scg, errorAt, tokenTypeList);
scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethStrAddList);
result.PopPost(scg, errorAt, tokenTypeList);
}
private static void BinOpStrVecAddList(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
{
result.PopPre(scg, errorAt);
left.PushVal(scg, errorAt, tokenTypeVec);
right.PushVal(scg, errorAt, tokenTypeList);
scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethVecAddList);
result.PopPost(scg, errorAt, tokenTypeList);
}
private static void BinOpStrListEqList(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
{
result.PopPre(scg, errorAt);
left.PushVal(scg, errorAt, tokenTypeList);
right.PushVal(scg, errorAt, tokenTypeList);
scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethListEqList);
result.PopPost(scg, errorAt, tokenTypeBool);
}
private static void BinOpStrListNeList(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
{
result.PopPre(scg, errorAt);
left.PushVal(scg, errorAt, tokenTypeList);
right.PushVal(scg, errorAt, tokenTypeList);
scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethListNeList);
result.PopPost(scg, errorAt, tokenTypeBool);
}
private static void BinOpStrRotEqRot(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
{
result.PopPre(scg, errorAt);
left.PushVal(scg, errorAt, tokenTypeRot);
right.PushVal(scg, errorAt, tokenTypeRot);
scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethRotEqRot);
result.PopPost(scg, errorAt, tokenTypeBool);
}
private static void BinOpStrRotNeRot(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
{
result.PopPre(scg, errorAt);
left.PushVal(scg, errorAt, tokenTypeRot);
right.PushVal(scg, errorAt, tokenTypeRot);
scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethRotNeRot);
result.PopPost(scg, errorAt, tokenTypeBool);
}
private static void BinOpStrRotAddRot(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
{
result.PopPre(scg, errorAt);
left.PushVal(scg, errorAt, tokenTypeRot);
right.PushVal(scg, errorAt, tokenTypeRot);
scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethRotAddRot);
result.PopPost(scg, errorAt, tokenTypeRot);
}
private static void BinOpStrRotSubRot(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
{
result.PopPre(scg, errorAt);
left.PushVal(scg, errorAt, tokenTypeRot);
right.PushVal(scg, errorAt, tokenTypeRot);
scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethRotSubRot);
result.PopPost(scg, errorAt, tokenTypeRot);
}
private static void BinOpStrRotMulRot(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
{
result.PopPre(scg, errorAt);
left.PushVal(scg, errorAt, tokenTypeRot);
right.PushVal(scg, errorAt, tokenTypeRot);
scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethRotMulRot);
result.PopPost(scg, errorAt, tokenTypeRot);
}
private static void BinOpStrRotDivRot(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
{
result.PopPre(scg, errorAt);
left.PushVal(scg, errorAt, tokenTypeRot);
right.PushVal(scg, errorAt, tokenTypeRot);
scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethRotDivRot);
result.PopPost(scg, errorAt, tokenTypeRot);
}
private static void BinOpStrStrEqStr(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
{
result.PopPre(scg, errorAt);
left.PushVal(scg, errorAt, tokenTypeStr);
right.PushVal(scg, errorAt, tokenTypeStr);
scg.ilGen.Emit(errorAt, OpCodes.Ldc_I4, (int)StringComparison.Ordinal);
scg.ilGen.Emit(errorAt, OpCodes.Call, stringCmpStringMethInfo);
scg.ilGen.Emit(errorAt, OpCodes.Ldc_I4_0);
scg.ilGen.Emit(errorAt, OpCodes.Ceq);
result.PopPost(scg, errorAt, tokenTypeBool);
}
private static void BinOpStrStrNeStr(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
{
result.PopPre(scg, errorAt);
left.PushVal(scg, errorAt, tokenTypeStr);
right.PushVal(scg, errorAt, tokenTypeStr);
scg.ilGen.Emit(errorAt, OpCodes.Ldc_I4, (int)StringComparison.Ordinal);
scg.ilGen.Emit(errorAt, OpCodes.Call, stringCmpStringMethInfo);
scg.ilGen.Emit(errorAt, OpCodes.Ldc_I4_0);
scg.ilGen.Emit(errorAt, OpCodes.Ceq);
scg.ilGen.Emit(errorAt, OpCodes.Ldc_I4_1);
scg.ilGen.Emit(errorAt, OpCodes.Xor);
result.PopPost(scg, errorAt, tokenTypeBool);
}
private static void BinOpStrStrLtStr(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
{
result.PopPre(scg, errorAt);
left.PushVal(scg, errorAt, tokenTypeStr);
right.PushVal(scg, errorAt, tokenTypeStr);
scg.ilGen.Emit(errorAt, OpCodes.Ldc_I4, (int)StringComparison.Ordinal);
scg.ilGen.Emit(errorAt, OpCodes.Call, stringCmpStringMethInfo);
scg.ilGen.Emit(errorAt, OpCodes.Ldc_I4_0);
scg.ilGen.Emit(errorAt, OpCodes.Clt);
result.PopPost(scg, errorAt, tokenTypeBool);
}
private static void BinOpStrStrLeStr(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
{
result.PopPre(scg, errorAt);
left.PushVal(scg, errorAt, tokenTypeStr);
right.PushVal(scg, errorAt, tokenTypeStr);
scg.ilGen.Emit(errorAt, OpCodes.Ldc_I4, (int)StringComparison.Ordinal);
scg.ilGen.Emit(errorAt, OpCodes.Call, stringCmpStringMethInfo);
scg.ilGen.Emit(errorAt, OpCodes.Ldc_I4_1);
scg.ilGen.Emit(errorAt, OpCodes.Clt);
result.PopPost(scg, errorAt, tokenTypeBool);
}
private static void BinOpStrStrGtStr(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
{
result.PopPre(scg, errorAt);
left.PushVal(scg, errorAt, tokenTypeStr);
right.PushVal(scg, errorAt, tokenTypeStr);
scg.ilGen.Emit(errorAt, OpCodes.Ldc_I4, (int)StringComparison.Ordinal);
scg.ilGen.Emit(errorAt, OpCodes.Call, stringCmpStringMethInfo);
scg.ilGen.Emit(errorAt, OpCodes.Ldc_I4_0);
scg.ilGen.Emit(errorAt, OpCodes.Cgt);
result.PopPost(scg, errorAt, tokenTypeBool);
}
private static void BinOpStrStrGeStr(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
{
result.PopPre(scg, errorAt);
left.PushVal(scg, errorAt, tokenTypeStr);
right.PushVal(scg, errorAt, tokenTypeStr);
scg.ilGen.Emit(errorAt, OpCodes.Ldc_I4, (int)StringComparison.Ordinal);
scg.ilGen.Emit(errorAt, OpCodes.Call, stringCmpStringMethInfo);
scg.ilGen.Emit(errorAt, OpCodes.Ldc_I4_M1);
scg.ilGen.Emit(errorAt, OpCodes.Cgt);
result.PopPost(scg, errorAt, tokenTypeBool);
}
// Called by many type combinations so both operands need to be cast to strings
private static void BinOpStrStrAddStr(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
{
result.PopPre(scg, errorAt);
left.PushVal(scg, errorAt, tokenTypeStr);
right.PushVal(scg, errorAt, tokenTypeStr);
scg.ilGen.Emit(errorAt, OpCodes.Call, stringAddStringMethInfo);
result.PopPost(scg, errorAt, tokenTypeStr);
}
private static void BinOpStrVecEqVec(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
{
result.PopPre(scg, errorAt);
left.PushVal(scg, errorAt, tokenTypeVec);
right.PushVal(scg, errorAt, tokenTypeVec);
scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethVecEqVec);
result.PopPost(scg, errorAt, tokenTypeBool);
}
private static void BinOpStrVecNeVec(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
{
result.PopPre(scg, errorAt);
left.PushVal(scg, errorAt, tokenTypeVec);
right.PushVal(scg, errorAt, tokenTypeVec);
scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethVecNeVec);
result.PopPost(scg, errorAt, tokenTypeBool);
}
private static void BinOpStrVecAddVec(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
{
result.PopPre(scg, errorAt);
left.PushVal(scg, errorAt, tokenTypeVec);
right.PushVal(scg, errorAt, tokenTypeVec);
scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethVecAddVec);
result.PopPost(scg, errorAt, tokenTypeVec);
}
private static void BinOpStrVecSubVec(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
{
result.PopPre(scg, errorAt);
left.PushVal(scg, errorAt, tokenTypeVec);
right.PushVal(scg, errorAt, tokenTypeVec);
scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethVecSubVec);
result.PopPost(scg, errorAt, tokenTypeVec);
}
private static void BinOpStrVecMulVec(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
{
result.PopPre(scg, errorAt);
left.PushVal(scg, errorAt, tokenTypeVec);
right.PushVal(scg, errorAt, tokenTypeVec);
scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethVecMulVec);
result.PopPost(scg, errorAt, tokenTypeFloat);
}
private static void BinOpStrVecModVec(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
{
result.PopPre(scg, errorAt);
left.PushVal(scg, errorAt, tokenTypeVec);
right.PushVal(scg, errorAt, tokenTypeVec);
scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethVecModVec);
result.PopPost(scg, errorAt, tokenTypeVec);
}
private static void BinOpStrVecMulFloat(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
{
result.PopPre(scg, errorAt);
left.PushVal(scg, errorAt, tokenTypeVec);
right.PushVal(scg, errorAt, tokenTypeFloat);
scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethVecMulFloat);
result.PopPost(scg, errorAt, tokenTypeVec);
}
private static void BinOpStrFloatMulVec(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
{
result.PopPre(scg, errorAt);
left.PushVal(scg, errorAt, tokenTypeFloat);
right.PushVal(scg, errorAt, tokenTypeVec);
scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethFloatMulVec);
result.PopPost(scg, errorAt, tokenTypeVec);
}
private static void BinOpStrVecDivFloat(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
{
result.PopPre(scg, errorAt);
left.PushVal(scg, errorAt, tokenTypeVec);
right.PushVal(scg, errorAt, tokenTypeFloat);
scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethVecDivFloat);
result.PopPost(scg, errorAt, tokenTypeVec);
}
private static void BinOpStrVecMulInt(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
{
result.PopPre(scg, errorAt);
left.PushVal(scg, errorAt, tokenTypeVec);
right.PushVal(scg, errorAt, tokenTypeInt);
scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethVecMulInt);
result.PopPost(scg, errorAt, tokenTypeVec);
}
private static void BinOpStrIntMulVec(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
{
result.PopPre(scg, errorAt);
left.PushVal(scg, errorAt, tokenTypeInt);
right.PushVal(scg, errorAt, tokenTypeVec);
scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethIntMulVec);
result.PopPost(scg, errorAt, tokenTypeVec);
}
private static void BinOpStrVecDivInt(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
{
result.PopPre(scg, errorAt);
left.PushVal(scg, errorAt, tokenTypeVec);
right.PushVal(scg, errorAt, tokenTypeInt);
scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethVecDivInt);
result.PopPost(scg, errorAt, tokenTypeVec);
}
private static void BinOpStrVecMulRot(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
{
result.PopPre(scg, errorAt);
left.PushVal(scg, errorAt, tokenTypeVec);
right.PushVal(scg, errorAt, tokenTypeRot);
scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethVecMulRot);
result.PopPost(scg, errorAt, tokenTypeVec);
}
private static void BinOpStrVecDivRot(ScriptCodeGen scg, Token errorAt, CompValu left, CompValu right, CompValu result)
{
result.PopPre(scg, errorAt);
left.PushVal(scg, errorAt, tokenTypeVec);
right.PushVal(scg, errorAt, tokenTypeRot);
scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethVecDivRot);
result.PopPost(scg, errorAt, tokenTypeVec);
}
/**
* @brief These methods are called at runtime as helpers.
* Needed to pick up functionality defined by overloaded operators of LSL_ types.
* They need to be marked public or runtime says they are inaccessible.
*/
public static LSL_List MethListAddFloat(LSL_List left, double right)
{
return MethListAddObj(left, new LSL_Float(right));
}
public static LSL_List MethListAddInt(LSL_List left, int right)
{
return MethListAddObj(left, new LSL_Integer(right));
}
public static LSL_List MethListAddKey(LSL_List left, string right)
{
return MethListAddObj(left, new LSL_Key(right));
}
public static LSL_List MethListAddRot(LSL_List left, LSL_Rotation right)
{
return MethListAddObj(left, right);
}
public static LSL_List MethListAddStr(LSL_List left, string right)
{
return MethListAddObj(left, new LSL_String(right));
}
public static LSL_List MethListAddVec(LSL_List left, LSL_Vector right)
{
return MethListAddObj(left, right);
}
public static LSL_List MethListAddObj(LSL_List left, object right)
{
int oldlen = left.Length;
object[] newarr = new object[oldlen + 1];
Array.Copy(left.Data, newarr, oldlen);
newarr[oldlen] = right;
return new LSL_List(newarr);
}
public static LSL_List MethListAddList(LSL_List left, LSL_List right)
{
int leftlen = left.Length;
int ritelen = right.Length;
object[] newarr = new object[leftlen + ritelen];
Array.Copy(left.Data, newarr, leftlen);
Array.Copy(right.Data, 0, newarr, leftlen, ritelen);
return new LSL_List(newarr);
}
public static LSL_List MethFloatAddList(double left, LSL_List right)
{
return MethObjAddList(new LSL_Float(left), right);
}
public static LSL_List MethIntAddList(int left, LSL_List right)
{
return MethObjAddList(new LSL_Integer(left), right);
}
public static LSL_List MethKeyAddList(string left, LSL_List right)
{
return MethObjAddList(new LSL_Key(left), right);
}
public static LSL_List MethRotAddList(LSL_Rotation left, LSL_List right)
{
return MethObjAddList(left, right);
}
public static LSL_List MethStrAddList(string left, LSL_List right)
{
return MethObjAddList(new LSL_String(left), right);
}
public static LSL_List MethVecAddList(LSL_Vector left, LSL_List right)
{
return MethObjAddList(left, right);
}
public static LSL_List MethObjAddList(object left, LSL_List right)
{
int oldlen = right.Length;
object[] newarr = new object[oldlen + 1];
newarr[0] = left;
Array.Copy(right.Data, 0, newarr, 1, oldlen);
return new LSL_List(newarr);
}
public static bool MethListEqList(LSL_List left, LSL_List right)
{
return left == right;
}
// According to http://wiki.secondlife.com/wiki/LlGetListLength
// jackassed LSL allows 'somelist != []' to get the length of a list
public static int MethListNeList(LSL_List left, LSL_List right)
{
int leftlen = left.Length;
int ritelen = right.Length;
return leftlen - ritelen;
}
public static bool MethRotEqRot(LSL_Rotation left, LSL_Rotation right)
{
return left == right;
}
public static bool MethRotNeRot(LSL_Rotation left, LSL_Rotation right)
{
return left != right;
}
public static LSL_Rotation MethRotAddRot(LSL_Rotation left, LSL_Rotation right)
{
return left + right;
}
public static LSL_Rotation MethRotSubRot(LSL_Rotation left, LSL_Rotation right)
{
return left - right;
}
public static LSL_Rotation MethRotMulRot(LSL_Rotation left, LSL_Rotation right)
{
return left * right;
}
public static LSL_Rotation MethRotDivRot(LSL_Rotation left, LSL_Rotation right)
{
return left / right;
}
public static bool MethVecEqVec(LSL_Vector left, LSL_Vector right)
{
return left == right;
}
public static bool MethVecNeVec(LSL_Vector left, LSL_Vector right)
{
return left != right;
}
public static LSL_Vector MethVecAddVec(LSL_Vector left, LSL_Vector right)
{
return left + right;
}
public static LSL_Vector MethVecSubVec(LSL_Vector left, LSL_Vector right)
{
return left - right;
}
public static double MethVecMulVec(LSL_Vector left, LSL_Vector right)
{
return (double)(left * right).value;
}
public static LSL_Vector MethVecModVec(LSL_Vector left, LSL_Vector right)
{
return left % right;
}
public static LSL_Vector MethVecMulFloat(LSL_Vector left, double right)
{
return left * right;
}
public static LSL_Vector MethFloatMulVec(double left, LSL_Vector right)
{
return left * right;
}
public static LSL_Vector MethVecDivFloat(LSL_Vector left, double right)
{
return left / right;
}
public static LSL_Vector MethVecMulInt(LSL_Vector left, int right)
{
return left * right;
}
public static LSL_Vector MethIntMulVec(int left, LSL_Vector right)
{
return left * right;
}
public static LSL_Vector MethVecDivInt(LSL_Vector left, int right)
{
return left / right;
}
public static LSL_Vector MethVecMulRot(LSL_Vector left, LSL_Rotation right)
{
return left * right;
}
public static LSL_Vector MethVecDivRot(LSL_Vector left, LSL_Rotation right)
{
return left / right;
}
public static double MethDoubleDivDouble(double a, double b)
{
double r = a / b;
if (double.IsNaN(r) || double.IsInfinity(r))
throw new ScriptException("Division by Zero");
return r;
}
public static long MethLongDivLong(long a, long b)
{
try
{
return a / b;
}
catch (DivideByZeroException)
{
throw new ScriptException("Division by Zero");
}
}
public static double MethDoubleModDouble(double a, double b)
{
double r = a % b;
if (double.IsNaN(r) || double.IsInfinity(r))
throw new ScriptException("Division by Zero");
return r;
}
public static long MethLongModLong(long a, long b)
{
try
{
return a % b;
}
catch (DivideByZeroException)
{
throw new ScriptException("Division by Zero");
}
}
}
}
|