glulx-asm 0.1.1

Assembler for the Glulx Virtual Machine for Interactive Fiction
Documentation
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
#![allow(clippy::too_many_arguments)]
//! Functions for concisely constructing items.
//!
//! Everything here is just a trivial wrapper around various enum variants, but
//! using it will make your code-generation code much more readable.
//!
//! * To construct a function header item: use [`fnhead_local`] or
//!   [`fnhead_stack`].
//! * To construct a load operand: use [`pop`], [`imm`], [`uimm`], [`imml`],
//!   [`imml_off`], [`derefl`], [`derefl_off`], [`derefl_uoff`], [`lloc`] or one
//!   of the reimports [`f32_to_imm`] or [`f64_to_imm`].
//! * To construct a store operand: use [`push`], [`discard`], [`storel`],
//!   [`storel_off`], [`storel_uoff`] or [`sloc`].
//! * To construct an instruction item: use the function named for the
//!   instruction, except that `mod` is [`modulo`] and `return` is [`ret`] to
//!   avoid colliding with Rust keywords. Branch instructions, for their branch
//!   target operand, just take an `L` rather than a `LoadOperand<L>`. They have
//!   each have a variant named *instr*`_ret` which instead takes a boolean,
//!   yielding an instruction which returns a 0 or 1 from the current call frame
//!   instead of branching.
//! * To construct a string or blob: use [`mystery_string`], [`utf32_string`],
//!   [`compressed_string`], or [`blob`].
//! * To contsruct a label: use [`label`].
//! * To construct a label reference item: use [`labelref`], [`labelref_off`],
//!   [`labelref_uoff`], [`labelref_off_shift`], or [`labelref_uoff_shift`].
//! * To construct an alignment item: use [`align`].
//! * To construct a decoding table item: use [`decoding_table`].
//! * To construct a zero-item: use [`zlabel`], [`zspace`], [`zalign`].

// The instruction constructors were generated by a Python script, because that
// was easier than a one-off proc macro. The source to the script is in comments
// at the bottom of the module.

use crate::{cast::CastSign, DecodeNode, LabelRef};
pub use crate::{f32_to_imm, f64_to_imm};
use crate::{
    CallingConvention, Instr, Item, LoadOperand, MysteryString, StoreOperand, Utf32String, ZeroItem,
};

use bytes::Bytes;

/// Constructs a function header item with the `ArgsInLocals` calling convention.
pub fn fnhead_local<L>(nlocals: u32) -> Item<L> {
    Item::FnHeader(CallingConvention::ArgsInLocals, nlocals)
}

/// Constructs a function header item with the `ArgsOnStack` calling convention.
pub fn fnhead_stack<L>(nlocals: u32) -> Item<L> {
    Item::FnHeader(CallingConvention::ArgsOnStack, nlocals)
}

/// Constructs a load operand that pops from the stack.
pub fn pop<L>() -> LoadOperand<L> {
    LoadOperand::Pop
}

/// Constructs an immediate load operand.
pub fn imm<L>(x: i32) -> LoadOperand<L> {
    LoadOperand::Imm(x)
}

/// Constructs an unsigned immediate load operand.
pub fn uimm<L>(x: u32) -> LoadOperand<L> {
    LoadOperand::Imm(x.cast_sign())
}

/// Constructs an immedate load operand from a label.
pub fn imml<L>(x: L) -> LoadOperand<L> {
    LoadOperand::ImmLabel(LabelRef(x, 0), 0)
}

/// Constructs an immedate load operand from a label and offset.
pub fn imml_off<L>(x: L, offset: i32) -> LoadOperand<L> {
    LoadOperand::ImmLabel(LabelRef(x, offset), 0)
}

/// Constructs an immedate load operand from a label and an unsigned offset.
pub fn imml_uoff<L>(x: L, offset: u32) -> LoadOperand<L> {
    LoadOperand::ImmLabel(LabelRef(x, offset.cast_sign()), 0)
}

/// Constructs an immedate load operand from a label, offset, and right-shift.
pub fn imml_off_shift<L>(x: L, offset: i32, shift: u8) -> LoadOperand<L> {
    LoadOperand::ImmLabel(LabelRef(x, offset), shift)
}

/// Constructs an immedate load operand from a label, unsigned offset, and right-shift.
pub fn imml_uoff_shift<L>(x: L, offset: u32, shift: u8) -> LoadOperand<L> {
    LoadOperand::ImmLabel(LabelRef(x, offset.cast_sign()), shift)
}

/// Constructs a load operand which derefernces a label.
pub fn derefl<L>(x: L) -> LoadOperand<L> {
    LoadOperand::DerefLabel(LabelRef(x, 0))
}

/// Constructs a load operand which derefernces a label and offset.
pub fn derefl_off<L>(x: L, offset: i32) -> LoadOperand<L> {
    LoadOperand::DerefLabel(LabelRef(x, offset))
}

/// Constructs a load operand which derefernces a label and unsigend offset.
pub fn derefl_uoff<L>(x: L, offset: u32) -> LoadOperand<L> {
    LoadOperand::DerefLabel(LabelRef(x, offset.cast_sign()))
}

/// Constructs a store operand which pushes to the stack.
pub fn push<L>() -> StoreOperand<L> {
    StoreOperand::Push
}

/// Constructs a store operand which discards the value.
pub fn discard<L>() -> StoreOperand<L> {
    StoreOperand::Discard
}

/// Constructs a store operand which stores to a labeled address.
pub fn storel<L>(l: L) -> StoreOperand<L> {
    StoreOperand::DerefLabel(LabelRef(l, 0))
}

/// Constructs a store operand which stores to a labeled address with offset.
pub fn storel_off<L>(l: L, offset: i32) -> StoreOperand<L> {
    StoreOperand::DerefLabel(LabelRef(l, offset))
}

/// Constructs a store operand which stores to a labeled address with unsigned offset.
pub fn storel_uoff<L>(l: L, offset: u32) -> StoreOperand<L> {
    StoreOperand::DerefLabel(LabelRef(l, offset.cast_sign()))
}

/// Constructs a load operand which loads from the `n`'th local.
pub fn lloc<L>(n: u32) -> LoadOperand<L> {
    LoadOperand::FrameAddr(4 * n)
}

/// Constructs a store operand which stores to the `n`'th local.
pub fn sloc<L>(n: u32) -> StoreOperand<L> {
    StoreOperand::FrameAddr(4 * n)
}

/// Constructs a `MysteryString` item.
///
/// This uses [`MysteryString::from_chars_lossy`].
pub fn mystery_string<L, S>(s: &S) -> Item<L>
where
    S: AsRef<str>,
{
    Item::MysteryString(MysteryString::from_chars_lossy(s.as_ref().chars()))
}

/// Constructs a `Utf32String` item.
///
/// This uses [`Utf32String::from_chars_lossy`].
pub fn utf32_string<L, S>(s: &S) -> Item<L>
where
    S: AsRef<str>,
{
    Item::Utf32String(Utf32String::from_chars_lossy(s.as_ref().chars()))
}

/// Constructs a `CompressedString` item.
pub fn compressed_string<L, B>(b: B) -> Item<L>
where
    B: Into<Bytes>,
{
    Item::CompressedString(b.into())
}

/// Constructs a `Blob` item.
pub fn blob<L, B>(b: B) -> Item<L>
where
    B: Into<Bytes>,
{
    Item::Blob(b.into())
}

/// Constructs an `Align` item.
///
/// Panics if its argument is 0.
pub fn align<L>(alignment: u32) -> Item<L> {
    Item::Align(alignment.try_into().unwrap())
}

/// Constructs a `DecodingTable` item.
pub fn decoding_table<L>(root: DecodeNode<L>) -> Item<L> {
    Item::DecodingTable(root)
}

/// Constructs a `Label` item.
pub fn label<L>(label: L) -> Item<L> {
    Item::Label(label)
}

/// Constructs a `LabelRef` item.
pub fn labelref<L>(label: L) -> Item<L> {
    Item::LabelRef(LabelRef(label, 0), 0)
}

/// Constructs a `LabelRef` item with an offset.
pub fn labelref_off<L>(label: L, offset: i32) -> Item<L> {
    Item::LabelRef(LabelRef(label, offset), 0)
}

/// Constructs a `LabelRef` item with an unsigned offset.
pub fn labelref_uoff<L>(label: L, offset: u32) -> Item<L> {
    Item::LabelRef(LabelRef(label, offset.cast_sign()), 0)
}

/// Constructs a `LabelRef` item with an offset and right shift.
pub fn labelref_off_shift<L>(label: L, offset: i32, shift: u8) -> Item<L> {
    Item::LabelRef(LabelRef(label, offset), shift)
}

/// Constructs a `LabelRef` item with an unsigned offset and right shift.
pub fn labelref_uoff_shift<L>(label: L, offset: u32, shift: u8) -> Item<L> {
    Item::LabelRef(LabelRef(label, offset.cast_sign()), shift)
}

/// Constructs a `Label` zero-item.
pub fn zlabel<L>(label: L) -> ZeroItem<L> {
    ZeroItem::Label(label)
}

/// Constructs an `Align` zero-item.
///
/// Panics if its argument is 0.
pub fn zalign<L>(alignment: u32) -> ZeroItem<L> {
    ZeroItem::Align(alignment.try_into().unwrap())
}

/// Constructs a `Space` zero-item.
pub fn zspace<L>(space: u32) -> ZeroItem<L> {
    ZeroItem::Space(space)
}

// SCRIPT OUTPUT BEGINS HERE

/// Constructs an item for the `nop` instruction.
pub fn nop<L>() -> Item<L> {
    Item::Instr(Instr::Nop)
}

/// Constructs an item for the `add` instruction.
pub fn add<L>(l1: LoadOperand<L>, l2: LoadOperand<L>, s1: StoreOperand<L>) -> Item<L> {
    Item::Instr(Instr::Add(l1, l2, s1))
}

/// Constructs an item for the `sub` instruction.
pub fn sub<L>(l1: LoadOperand<L>, l2: LoadOperand<L>, s1: StoreOperand<L>) -> Item<L> {
    Item::Instr(Instr::Sub(l1, l2, s1))
}

/// Constructs an item for the `mul` instruction.
pub fn mul<L>(l1: LoadOperand<L>, l2: LoadOperand<L>, s1: StoreOperand<L>) -> Item<L> {
    Item::Instr(Instr::Mul(l1, l2, s1))
}

/// Constructs an item for the `div` instruction.
pub fn div<L>(l1: LoadOperand<L>, l2: LoadOperand<L>, s1: StoreOperand<L>) -> Item<L> {
    Item::Instr(Instr::Div(l1, l2, s1))
}

/// Constructs an item for the `mod` instruction.
pub fn modulo<L>(l1: LoadOperand<L>, l2: LoadOperand<L>, s1: StoreOperand<L>) -> Item<L> {
    Item::Instr(Instr::Mod(l1, l2, s1))
}

/// Constructs an item for the `neg` instruction.
pub fn neg<L>(l1: LoadOperand<L>, s1: StoreOperand<L>) -> Item<L> {
    Item::Instr(Instr::Neg(l1, s1))
}

/// Constructs an item for the `bitand` instruction.
pub fn bitand<L>(l1: LoadOperand<L>, l2: LoadOperand<L>, s1: StoreOperand<L>) -> Item<L> {
    Item::Instr(Instr::Bitand(l1, l2, s1))
}

/// Constructs an item for the `bitor` instruction.
pub fn bitor<L>(l1: LoadOperand<L>, l2: LoadOperand<L>, s1: StoreOperand<L>) -> Item<L> {
    Item::Instr(Instr::Bitor(l1, l2, s1))
}

/// Constructs an item for the `bitxor` instruction.
pub fn bitxor<L>(l1: LoadOperand<L>, l2: LoadOperand<L>, s1: StoreOperand<L>) -> Item<L> {
    Item::Instr(Instr::Bitxor(l1, l2, s1))
}

/// Constructs an item for the `bitnot` instruction.
pub fn bitnot<L>(l1: LoadOperand<L>, s1: StoreOperand<L>) -> Item<L> {
    Item::Instr(Instr::Bitnot(l1, s1))
}

/// Constructs an item for the `shiftl` instruction.
pub fn shiftl<L>(l1: LoadOperand<L>, l2: LoadOperand<L>, s1: StoreOperand<L>) -> Item<L> {
    Item::Instr(Instr::Shiftl(l1, l2, s1))
}

/// Constructs an item for the `ushiftr` instruction.
pub fn ushiftr<L>(l1: LoadOperand<L>, l2: LoadOperand<L>, s1: StoreOperand<L>) -> Item<L> {
    Item::Instr(Instr::Ushiftr(l1, l2, s1))
}

/// Constructs an item for the `sshiftr` instruction.
pub fn sshiftr<L>(l1: LoadOperand<L>, l2: LoadOperand<L>, s1: StoreOperand<L>) -> Item<L> {
    Item::Instr(Instr::Sshiftr(l1, l2, s1))
}

/// Constructs an item for the `jump` instruction.
pub fn jump<L>(bt: L) -> Item<L> {
    Item::Instr(Instr::Jump(LoadOperand::Branch(bt)))
}

/// Constructs an item for the `jump` instruction, with a branch operand that returns 0 or 1 instead of branching
pub fn jump_ret<L>(bt: bool) -> Item<L> {
    Item::Instr(Instr::Jump(LoadOperand::Imm(bt.into())))
}

/// Constructs an item for the `jz` instruction.
pub fn jz<L>(l1: LoadOperand<L>, bt: L) -> Item<L> {
    Item::Instr(Instr::Jz(l1, LoadOperand::Branch(bt)))
}

/// Constructs an item for the `jz` instruction, with a branch operand that returns 0 or 1 instead of branching
pub fn jz_ret<L>(l1: LoadOperand<L>, bt: bool) -> Item<L> {
    Item::Instr(Instr::Jz(l1, LoadOperand::Imm(bt.into())))
}

/// Constructs an item for the `jnz` instruction.
pub fn jnz<L>(l1: LoadOperand<L>, bt: L) -> Item<L> {
    Item::Instr(Instr::Jnz(l1, LoadOperand::Branch(bt)))
}

/// Constructs an item for the `jnz` instruction, with a branch operand that returns 0 or 1 instead of branching
pub fn jnz_ret<L>(l1: LoadOperand<L>, bt: bool) -> Item<L> {
    Item::Instr(Instr::Jnz(l1, LoadOperand::Imm(bt.into())))
}

/// Constructs an item for the `jeq` instruction.
pub fn jeq<L>(l1: LoadOperand<L>, l2: LoadOperand<L>, bt: L) -> Item<L> {
    Item::Instr(Instr::Jeq(l1, l2, LoadOperand::Branch(bt)))
}

/// Constructs an item for the `jeq` instruction, with a branch operand that returns 0 or 1 instead of branching
pub fn jeq_ret<L>(l1: LoadOperand<L>, l2: LoadOperand<L>, bt: bool) -> Item<L> {
    Item::Instr(Instr::Jeq(l1, l2, LoadOperand::Imm(bt.into())))
}

/// Constructs an item for the `jne` instruction.
pub fn jne<L>(l1: LoadOperand<L>, l2: LoadOperand<L>, bt: L) -> Item<L> {
    Item::Instr(Instr::Jne(l1, l2, LoadOperand::Branch(bt)))
}

/// Constructs an item for the `jne` instruction, with a branch operand that returns 0 or 1 instead of branching
pub fn jne_ret<L>(l1: LoadOperand<L>, l2: LoadOperand<L>, bt: bool) -> Item<L> {
    Item::Instr(Instr::Jne(l1, l2, LoadOperand::Imm(bt.into())))
}

/// Constructs an item for the `jlt` instruction.
pub fn jlt<L>(l1: LoadOperand<L>, l2: LoadOperand<L>, bt: L) -> Item<L> {
    Item::Instr(Instr::Jlt(l1, l2, LoadOperand::Branch(bt)))
}

/// Constructs an item for the `jlt` instruction, with a branch operand that returns 0 or 1 instead of branching
pub fn jlt_ret<L>(l1: LoadOperand<L>, l2: LoadOperand<L>, bt: bool) -> Item<L> {
    Item::Instr(Instr::Jlt(l1, l2, LoadOperand::Imm(bt.into())))
}

/// Constructs an item for the `jle` instruction.
pub fn jle<L>(l1: LoadOperand<L>, l2: LoadOperand<L>, bt: L) -> Item<L> {
    Item::Instr(Instr::Jle(l1, l2, LoadOperand::Branch(bt)))
}

/// Constructs an item for the `jle` instruction, with a branch operand that returns 0 or 1 instead of branching
pub fn jle_ret<L>(l1: LoadOperand<L>, l2: LoadOperand<L>, bt: bool) -> Item<L> {
    Item::Instr(Instr::Jle(l1, l2, LoadOperand::Imm(bt.into())))
}

/// Constructs an item for the `jgt` instruction.
pub fn jgt<L>(l1: LoadOperand<L>, l2: LoadOperand<L>, bt: L) -> Item<L> {
    Item::Instr(Instr::Jgt(l1, l2, LoadOperand::Branch(bt)))
}

/// Constructs an item for the `jgt` instruction, with a branch operand that returns 0 or 1 instead of branching
pub fn jgt_ret<L>(l1: LoadOperand<L>, l2: LoadOperand<L>, bt: bool) -> Item<L> {
    Item::Instr(Instr::Jgt(l1, l2, LoadOperand::Imm(bt.into())))
}

/// Constructs an item for the `jge` instruction.
pub fn jge<L>(l1: LoadOperand<L>, l2: LoadOperand<L>, bt: L) -> Item<L> {
    Item::Instr(Instr::Jge(l1, l2, LoadOperand::Branch(bt)))
}

/// Constructs an item for the `jge` instruction, with a branch operand that returns 0 or 1 instead of branching
pub fn jge_ret<L>(l1: LoadOperand<L>, l2: LoadOperand<L>, bt: bool) -> Item<L> {
    Item::Instr(Instr::Jge(l1, l2, LoadOperand::Imm(bt.into())))
}

/// Constructs an item for the `jltu` instruction.
pub fn jltu<L>(l1: LoadOperand<L>, l2: LoadOperand<L>, bt: L) -> Item<L> {
    Item::Instr(Instr::Jltu(l1, l2, LoadOperand::Branch(bt)))
}

/// Constructs an item for the `jltu` instruction, with a branch operand that returns 0 or 1 instead of branching
pub fn jltu_ret<L>(l1: LoadOperand<L>, l2: LoadOperand<L>, bt: bool) -> Item<L> {
    Item::Instr(Instr::Jltu(l1, l2, LoadOperand::Imm(bt.into())))
}

/// Constructs an item for the `jleu` instruction.
pub fn jleu<L>(l1: LoadOperand<L>, l2: LoadOperand<L>, bt: L) -> Item<L> {
    Item::Instr(Instr::Jleu(l1, l2, LoadOperand::Branch(bt)))
}

/// Constructs an item for the `jleu` instruction, with a branch operand that returns 0 or 1 instead of branching
pub fn jleu_ret<L>(l1: LoadOperand<L>, l2: LoadOperand<L>, bt: bool) -> Item<L> {
    Item::Instr(Instr::Jleu(l1, l2, LoadOperand::Imm(bt.into())))
}

/// Constructs an item for the `jgtu` instruction.
pub fn jgtu<L>(l1: LoadOperand<L>, l2: LoadOperand<L>, bt: L) -> Item<L> {
    Item::Instr(Instr::Jgtu(l1, l2, LoadOperand::Branch(bt)))
}

/// Constructs an item for the `jgtu` instruction, with a branch operand that returns 0 or 1 instead of branching
pub fn jgtu_ret<L>(l1: LoadOperand<L>, l2: LoadOperand<L>, bt: bool) -> Item<L> {
    Item::Instr(Instr::Jgtu(l1, l2, LoadOperand::Imm(bt.into())))
}

/// Constructs an item for the `jgeu` instruction.
pub fn jgeu<L>(l1: LoadOperand<L>, l2: LoadOperand<L>, bt: L) -> Item<L> {
    Item::Instr(Instr::Jgeu(l1, l2, LoadOperand::Branch(bt)))
}

/// Constructs an item for the `jgeu` instruction, with a branch operand that returns 0 or 1 instead of branching
pub fn jgeu_ret<L>(l1: LoadOperand<L>, l2: LoadOperand<L>, bt: bool) -> Item<L> {
    Item::Instr(Instr::Jgeu(l1, l2, LoadOperand::Imm(bt.into())))
}

/// Constructs an item for the `jumpabs` instruction.
pub fn jumpabs<L>(l1: LoadOperand<L>) -> Item<L> {
    Item::Instr(Instr::Jumpabs(l1))
}

/// Constructs an item for the `copy` instruction.
pub fn copy<L>(l1: LoadOperand<L>, s1: StoreOperand<L>) -> Item<L> {
    Item::Instr(Instr::Copy(l1, s1))
}

/// Constructs an item for the `copys` instruction.
pub fn copys<L>(l1: LoadOperand<L>, s1: StoreOperand<L>) -> Item<L> {
    Item::Instr(Instr::Copys(l1, s1))
}

/// Constructs an item for the `copyb` instruction.
pub fn copyb<L>(l1: LoadOperand<L>, s1: StoreOperand<L>) -> Item<L> {
    Item::Instr(Instr::Copyb(l1, s1))
}

/// Constructs an item for the `sexs` instruction.
pub fn sexs<L>(l1: LoadOperand<L>, s1: StoreOperand<L>) -> Item<L> {
    Item::Instr(Instr::Sexs(l1, s1))
}

/// Constructs an item for the `sexb` instruction.
pub fn sexb<L>(l1: LoadOperand<L>, s1: StoreOperand<L>) -> Item<L> {
    Item::Instr(Instr::Sexb(l1, s1))
}

/// Constructs an item for the `astore` instruction.
pub fn astore<L>(l1: LoadOperand<L>, l2: LoadOperand<L>, l3: LoadOperand<L>) -> Item<L> {
    Item::Instr(Instr::Astore(l1, l2, l3))
}

/// Constructs an item for the `aload` instruction.
pub fn aload<L>(l1: LoadOperand<L>, l2: LoadOperand<L>, s1: StoreOperand<L>) -> Item<L> {
    Item::Instr(Instr::Aload(l1, l2, s1))
}

/// Constructs an item for the `astores` instruction.
pub fn astores<L>(l1: LoadOperand<L>, l2: LoadOperand<L>, l3: LoadOperand<L>) -> Item<L> {
    Item::Instr(Instr::Astores(l1, l2, l3))
}

/// Constructs an item for the `aloads` instruction.
pub fn aloads<L>(l1: LoadOperand<L>, l2: LoadOperand<L>, s1: StoreOperand<L>) -> Item<L> {
    Item::Instr(Instr::Aloads(l1, l2, s1))
}

/// Constructs an item for the `astoreb` instruction.
pub fn astoreb<L>(l1: LoadOperand<L>, l2: LoadOperand<L>, l3: LoadOperand<L>) -> Item<L> {
    Item::Instr(Instr::Astoreb(l1, l2, l3))
}

/// Constructs an item for the `aloadb` instruction.
pub fn aloadb<L>(l1: LoadOperand<L>, l2: LoadOperand<L>, s1: StoreOperand<L>) -> Item<L> {
    Item::Instr(Instr::Aloadb(l1, l2, s1))
}

/// Constructs an item for the `astorebit` instruction.
pub fn astorebit<L>(l1: LoadOperand<L>, l2: LoadOperand<L>, l3: LoadOperand<L>) -> Item<L> {
    Item::Instr(Instr::Astorebit(l1, l2, l3))
}

/// Constructs an item for the `aloadbit` instruction.
pub fn aloadbit<L>(l1: LoadOperand<L>, l2: LoadOperand<L>, s1: StoreOperand<L>) -> Item<L> {
    Item::Instr(Instr::Aloadbit(l1, l2, s1))
}

/// Constructs an item for the `stkcount` instruction.
pub fn stkcount<L>(s1: StoreOperand<L>) -> Item<L> {
    Item::Instr(Instr::Stkcount(s1))
}

/// Constructs an item for the `stkpeek` instruction.
pub fn stkpeek<L>(l1: LoadOperand<L>, s1: StoreOperand<L>) -> Item<L> {
    Item::Instr(Instr::Stkpeek(l1, s1))
}

/// Constructs an item for the `stkswap` instruction.
pub fn stkswap<L>() -> Item<L> {
    Item::Instr(Instr::Stkswap)
}

/// Constructs an item for the `stkcopy` instruction.
pub fn stkcopy<L>(l1: LoadOperand<L>) -> Item<L> {
    Item::Instr(Instr::Stkcopy(l1))
}

/// Constructs an item for the `stkroll` instruction.
pub fn stkroll<L>(l1: LoadOperand<L>, l2: LoadOperand<L>) -> Item<L> {
    Item::Instr(Instr::Stkroll(l1, l2))
}

/// Constructs an item for the `call` instruction.
pub fn call<L>(l1: LoadOperand<L>, l2: LoadOperand<L>, s1: StoreOperand<L>) -> Item<L> {
    Item::Instr(Instr::Call(l1, l2, s1))
}

/// Constructs an item for the `callf` instruction.
pub fn callf<L>(l1: LoadOperand<L>, s1: StoreOperand<L>) -> Item<L> {
    Item::Instr(Instr::Callf(l1, s1))
}

/// Constructs an item for the `callfi` instruction.
pub fn callfi<L>(l1: LoadOperand<L>, l2: LoadOperand<L>, s1: StoreOperand<L>) -> Item<L> {
    Item::Instr(Instr::Callfi(l1, l2, s1))
}

/// Constructs an item for the `callfii` instruction.
pub fn callfii<L>(
    l1: LoadOperand<L>,
    l2: LoadOperand<L>,
    l3: LoadOperand<L>,
    s1: StoreOperand<L>,
) -> Item<L> {
    Item::Instr(Instr::Callfii(l1, l2, l3, s1))
}

/// Constructs an item for the `callfiii` instruction.
pub fn callfiii<L>(
    l1: LoadOperand<L>,
    l2: LoadOperand<L>,
    l3: LoadOperand<L>,
    l4: LoadOperand<L>,
    s1: StoreOperand<L>,
) -> Item<L> {
    Item::Instr(Instr::Callfiii(l1, l2, l3, l4, s1))
}

/// Constructs an item for the `return` instruction.
pub fn ret<L>(l1: LoadOperand<L>) -> Item<L> {
    Item::Instr(Instr::Return(l1))
}

/// Constructs an item for the `tailcall` instruction.
pub fn tailcall<L>(l1: LoadOperand<L>, l2: LoadOperand<L>) -> Item<L> {
    Item::Instr(Instr::Tailcall(l1, l2))
}

/// Constructs an item for the `catch` instruction.
pub fn catch<L>(s1: StoreOperand<L>, bt: L) -> Item<L> {
    Item::Instr(Instr::Catch(s1, LoadOperand::Branch(bt)))
}

/// Constructs an item for the `catch` instruction, with a branch operand that returns 0 or 1 instead of branching
pub fn catch_ret<L>(s1: StoreOperand<L>, bt: bool) -> Item<L> {
    Item::Instr(Instr::Catch(s1, LoadOperand::Imm(bt.into())))
}

/// Constructs an item for the `throw` instruction.
pub fn throw<L>(l1: LoadOperand<L>, l2: LoadOperand<L>) -> Item<L> {
    Item::Instr(Instr::Throw(l1, l2))
}

/// Constructs an item for the `getmemsize` instruction.
pub fn getmemsize<L>(s1: StoreOperand<L>) -> Item<L> {
    Item::Instr(Instr::Getmemsize(s1))
}

/// Constructs an item for the `setmemsize` instruction.
pub fn setmemsize<L>(l1: LoadOperand<L>, s1: StoreOperand<L>) -> Item<L> {
    Item::Instr(Instr::Setmemsize(l1, s1))
}

/// Constructs an item for the `malloc` instruction.
pub fn malloc<L>(l1: LoadOperand<L>, s1: StoreOperand<L>) -> Item<L> {
    Item::Instr(Instr::Malloc(l1, s1))
}

/// Constructs an item for the `mfree` instruction.
pub fn mfree<L>(l1: LoadOperand<L>) -> Item<L> {
    Item::Instr(Instr::Mfree(l1))
}

/// Constructs an item for the `quit` instruction.
pub fn quit<L>() -> Item<L> {
    Item::Instr(Instr::Quit)
}

/// Constructs an item for the `restart` instruction.
pub fn restart<L>() -> Item<L> {
    Item::Instr(Instr::Restart)
}

/// Constructs an item for the `save` instruction.
pub fn save<L>(l1: LoadOperand<L>, s1: StoreOperand<L>) -> Item<L> {
    Item::Instr(Instr::Save(l1, s1))
}

/// Constructs an item for the `restore` instruction.
pub fn restore<L>(l1: LoadOperand<L>, s1: StoreOperand<L>) -> Item<L> {
    Item::Instr(Instr::Restore(l1, s1))
}

/// Constructs an item for the `saveundo` instruction.
pub fn saveundo<L>(s1: StoreOperand<L>) -> Item<L> {
    Item::Instr(Instr::Saveundo(s1))
}

/// Constructs an item for the `restoreundo` instruction.
pub fn restoreundo<L>(s1: StoreOperand<L>) -> Item<L> {
    Item::Instr(Instr::Restoreundo(s1))
}

/// Constructs an item for the `hasundo` instruction.
pub fn hasundo<L>(s1: StoreOperand<L>) -> Item<L> {
    Item::Instr(Instr::Hasundo(s1))
}

/// Constructs an item for the `discardundo` instruction.
pub fn discardundo<L>() -> Item<L> {
    Item::Instr(Instr::Discardundo)
}

/// Constructs an item for the `protect` instruction.
pub fn protect<L>(l1: LoadOperand<L>, l2: LoadOperand<L>) -> Item<L> {
    Item::Instr(Instr::Protect(l1, l2))
}

/// Constructs an item for the `verify` instruction.
pub fn verify<L>(s1: StoreOperand<L>) -> Item<L> {
    Item::Instr(Instr::Verify(s1))
}

/// Constructs an item for the `getiosys` instruction.
pub fn getiosys<L>(s1: StoreOperand<L>, s2: StoreOperand<L>) -> Item<L> {
    Item::Instr(Instr::Getiosys(s1, s2))
}

/// Constructs an item for the `setiosys` instruction.
pub fn setiosys<L>(l1: LoadOperand<L>, l2: LoadOperand<L>) -> Item<L> {
    Item::Instr(Instr::Setiosys(l1, l2))
}

/// Constructs an item for the `streamchar` instruction.
pub fn streamchar<L>(l1: LoadOperand<L>) -> Item<L> {
    Item::Instr(Instr::Streamchar(l1))
}

/// Constructs an item for the `streamunichar` instruction.
pub fn streamunichar<L>(l1: LoadOperand<L>) -> Item<L> {
    Item::Instr(Instr::Streamunichar(l1))
}

/// Constructs an item for the `streamnum` instruction.
pub fn streamnum<L>(l1: LoadOperand<L>) -> Item<L> {
    Item::Instr(Instr::Streamnum(l1))
}

/// Constructs an item for the `streamstr` instruction.
pub fn streamstr<L>(l1: LoadOperand<L>) -> Item<L> {
    Item::Instr(Instr::Streamstr(l1))
}

/// Constructs an item for the `getstringtbl` instruction.
pub fn getstringtbl<L>(s1: StoreOperand<L>) -> Item<L> {
    Item::Instr(Instr::Getstringtbl(s1))
}

/// Constructs an item for the `setstringtbl` instruction.
pub fn setstringtbl<L>(l1: LoadOperand<L>) -> Item<L> {
    Item::Instr(Instr::Setstringtbl(l1))
}

/// Constructs an item for the `numtof` instruction.
pub fn numtof<L>(l1: LoadOperand<L>, s1: StoreOperand<L>) -> Item<L> {
    Item::Instr(Instr::Numtof(l1, s1))
}

/// Constructs an item for the `ftonumz` instruction.
pub fn ftonumz<L>(l1: LoadOperand<L>, s1: StoreOperand<L>) -> Item<L> {
    Item::Instr(Instr::Ftonumz(l1, s1))
}

/// Constructs an item for the `ftonumn` instruction.
pub fn ftonumn<L>(l1: LoadOperand<L>, s1: StoreOperand<L>) -> Item<L> {
    Item::Instr(Instr::Ftonumn(l1, s1))
}

/// Constructs an item for the `fadd` instruction.
pub fn fadd<L>(l1: LoadOperand<L>, l2: LoadOperand<L>, s1: StoreOperand<L>) -> Item<L> {
    Item::Instr(Instr::Fadd(l1, l2, s1))
}

/// Constructs an item for the `fsub` instruction.
pub fn fsub<L>(l1: LoadOperand<L>, l2: LoadOperand<L>, s1: StoreOperand<L>) -> Item<L> {
    Item::Instr(Instr::Fsub(l1, l2, s1))
}

/// Constructs an item for the `fmul` instruction.
pub fn fmul<L>(l1: LoadOperand<L>, l2: LoadOperand<L>, s1: StoreOperand<L>) -> Item<L> {
    Item::Instr(Instr::Fmul(l1, l2, s1))
}

/// Constructs an item for the `fdiv` instruction.
pub fn fdiv<L>(l1: LoadOperand<L>, l2: LoadOperand<L>, s1: StoreOperand<L>) -> Item<L> {
    Item::Instr(Instr::Fdiv(l1, l2, s1))
}

/// Constructs an item for the `fmod` instruction.
pub fn fmod<L>(
    l1: LoadOperand<L>,
    l2: LoadOperand<L>,
    s1: StoreOperand<L>,
    s2: StoreOperand<L>,
) -> Item<L> {
    Item::Instr(Instr::Fmod(l1, l2, s1, s2))
}

/// Constructs an item for the `ceil` instruction.
pub fn ceil<L>(l1: LoadOperand<L>, s1: StoreOperand<L>) -> Item<L> {
    Item::Instr(Instr::Ceil(l1, s1))
}

/// Constructs an item for the `floor` instruction.
pub fn floor<L>(l1: LoadOperand<L>, s1: StoreOperand<L>) -> Item<L> {
    Item::Instr(Instr::Floor(l1, s1))
}

/// Constructs an item for the `sqrt` instruction.
pub fn sqrt<L>(l1: LoadOperand<L>, s1: StoreOperand<L>) -> Item<L> {
    Item::Instr(Instr::Sqrt(l1, s1))
}

/// Constructs an item for the `exp` instruction.
pub fn exp<L>(l1: LoadOperand<L>, s1: StoreOperand<L>) -> Item<L> {
    Item::Instr(Instr::Exp(l1, s1))
}

/// Constructs an item for the `log` instruction.
pub fn log<L>(l1: LoadOperand<L>, s1: StoreOperand<L>) -> Item<L> {
    Item::Instr(Instr::Log(l1, s1))
}

/// Constructs an item for the `pow` instruction.
pub fn pow<L>(l1: LoadOperand<L>, l2: LoadOperand<L>, s1: StoreOperand<L>) -> Item<L> {
    Item::Instr(Instr::Pow(l1, l2, s1))
}

/// Constructs an item for the `sin` instruction.
pub fn sin<L>(l1: LoadOperand<L>, s1: StoreOperand<L>) -> Item<L> {
    Item::Instr(Instr::Sin(l1, s1))
}

/// Constructs an item for the `cos` instruction.
pub fn cos<L>(l1: LoadOperand<L>, s1: StoreOperand<L>) -> Item<L> {
    Item::Instr(Instr::Cos(l1, s1))
}

/// Constructs an item for the `tan` instruction.
pub fn tan<L>(l1: LoadOperand<L>, s1: StoreOperand<L>) -> Item<L> {
    Item::Instr(Instr::Tan(l1, s1))
}

/// Constructs an item for the `asin` instruction.
pub fn asin<L>(l1: LoadOperand<L>, s1: StoreOperand<L>) -> Item<L> {
    Item::Instr(Instr::Asin(l1, s1))
}

/// Constructs an item for the `acos` instruction.
pub fn acos<L>(l1: LoadOperand<L>, s1: StoreOperand<L>) -> Item<L> {
    Item::Instr(Instr::Acos(l1, s1))
}

/// Constructs an item for the `atan` instruction.
pub fn atan<L>(l1: LoadOperand<L>, s1: StoreOperand<L>) -> Item<L> {
    Item::Instr(Instr::Atan(l1, s1))
}

/// Constructs an item for the `atan2` instruction.
pub fn atan2<L>(l1: LoadOperand<L>, s1: StoreOperand<L>) -> Item<L> {
    Item::Instr(Instr::Atan2(l1, s1))
}

/// Constructs an item for the `numtod` instruction.
pub fn numtod<L>(l1: LoadOperand<L>, s1: StoreOperand<L>, s2: StoreOperand<L>) -> Item<L> {
    Item::Instr(Instr::Numtod(l1, s1, s2))
}

/// Constructs an item for the `dtonumz` instruction.
pub fn dtonumz<L>(l1: LoadOperand<L>, l2: LoadOperand<L>, s1: StoreOperand<L>) -> Item<L> {
    Item::Instr(Instr::Dtonumz(l1, l2, s1))
}

/// Constructs an item for the `dtonumn` instruction.
pub fn dtonumn<L>(l1: LoadOperand<L>, l2: LoadOperand<L>, s1: StoreOperand<L>) -> Item<L> {
    Item::Instr(Instr::Dtonumn(l1, l2, s1))
}

/// Constructs an item for the `ftod` instruction.
pub fn ftod<L>(l1: LoadOperand<L>, s1: StoreOperand<L>, s2: StoreOperand<L>) -> Item<L> {
    Item::Instr(Instr::Ftod(l1, s1, s2))
}

/// Constructs an item for the `dtof` instruction.
pub fn dtof<L>(l1: LoadOperand<L>, l2: LoadOperand<L>, s1: StoreOperand<L>) -> Item<L> {
    Item::Instr(Instr::Dtof(l1, l2, s1))
}

/// Constructs an item for the `dadd` instruction.
pub fn dadd<L>(
    l1: LoadOperand<L>,
    l2: LoadOperand<L>,
    l3: LoadOperand<L>,
    l4: LoadOperand<L>,
    s1: StoreOperand<L>,
    s2: StoreOperand<L>,
) -> Item<L> {
    Item::Instr(Instr::Dadd(l1, l2, l3, l4, s1, s2))
}

/// Constructs an item for the `dsub` instruction.
pub fn dsub<L>(
    l1: LoadOperand<L>,
    l2: LoadOperand<L>,
    l3: LoadOperand<L>,
    l4: LoadOperand<L>,
    s1: StoreOperand<L>,
    s2: StoreOperand<L>,
) -> Item<L> {
    Item::Instr(Instr::Dsub(l1, l2, l3, l4, s1, s2))
}

/// Constructs an item for the `dmul` instruction.
pub fn dmul<L>(
    l1: LoadOperand<L>,
    l2: LoadOperand<L>,
    l3: LoadOperand<L>,
    l4: LoadOperand<L>,
    s1: StoreOperand<L>,
    s2: StoreOperand<L>,
) -> Item<L> {
    Item::Instr(Instr::Dmul(l1, l2, l3, l4, s1, s2))
}

/// Constructs an item for the `ddiv` instruction.
pub fn ddiv<L>(
    l1: LoadOperand<L>,
    l2: LoadOperand<L>,
    l3: LoadOperand<L>,
    l4: LoadOperand<L>,
    s1: StoreOperand<L>,
    s2: StoreOperand<L>,
) -> Item<L> {
    Item::Instr(Instr::Ddiv(l1, l2, l3, l4, s1, s2))
}

/// Constructs an item for the `dmodr` instruction.
pub fn dmodr<L>(
    l1: LoadOperand<L>,
    l2: LoadOperand<L>,
    l3: LoadOperand<L>,
    l4: LoadOperand<L>,
    s1: StoreOperand<L>,
    s2: StoreOperand<L>,
) -> Item<L> {
    Item::Instr(Instr::Dmodr(l1, l2, l3, l4, s1, s2))
}

/// Constructs an item for the `dmodq` instruction.
pub fn dmodq<L>(
    l1: LoadOperand<L>,
    l2: LoadOperand<L>,
    l3: LoadOperand<L>,
    l4: LoadOperand<L>,
    s1: StoreOperand<L>,
    s2: StoreOperand<L>,
) -> Item<L> {
    Item::Instr(Instr::Dmodq(l1, l2, l3, l4, s1, s2))
}

/// Constructs an item for the `dceil` instruction.
pub fn dceil<L>(
    l1: LoadOperand<L>,
    l2: LoadOperand<L>,
    s1: StoreOperand<L>,
    s2: StoreOperand<L>,
) -> Item<L> {
    Item::Instr(Instr::Dceil(l1, l2, s1, s2))
}

/// Constructs an item for the `dfloor` instruction.
pub fn dfloor<L>(
    l1: LoadOperand<L>,
    l2: LoadOperand<L>,
    s1: StoreOperand<L>,
    s2: StoreOperand<L>,
) -> Item<L> {
    Item::Instr(Instr::Dfloor(l1, l2, s1, s2))
}

/// Constructs an item for the `dsqrt` instruction.
pub fn dsqrt<L>(
    l1: LoadOperand<L>,
    l2: LoadOperand<L>,
    s1: StoreOperand<L>,
    s2: StoreOperand<L>,
) -> Item<L> {
    Item::Instr(Instr::Dsqrt(l1, l2, s1, s2))
}

/// Constructs an item for the `dexp` instruction.
pub fn dexp<L>(
    l1: LoadOperand<L>,
    l2: LoadOperand<L>,
    s1: StoreOperand<L>,
    s2: StoreOperand<L>,
) -> Item<L> {
    Item::Instr(Instr::Dexp(l1, l2, s1, s2))
}

/// Constructs an item for the `dlog` instruction.
pub fn dlog<L>(
    l1: LoadOperand<L>,
    l2: LoadOperand<L>,
    s1: StoreOperand<L>,
    s2: StoreOperand<L>,
) -> Item<L> {
    Item::Instr(Instr::Dlog(l1, l2, s1, s2))
}

/// Constructs an item for the `dpow` instruction.
pub fn dpow<L>(
    l1: LoadOperand<L>,
    l2: LoadOperand<L>,
    l3: LoadOperand<L>,
    l4: LoadOperand<L>,
    s1: StoreOperand<L>,
    s2: StoreOperand<L>,
) -> Item<L> {
    Item::Instr(Instr::Dpow(l1, l2, l3, l4, s1, s2))
}

/// Constructs an item for the `dsin` instruction.
pub fn dsin<L>(
    l1: LoadOperand<L>,
    l2: LoadOperand<L>,
    s1: StoreOperand<L>,
    s2: StoreOperand<L>,
) -> Item<L> {
    Item::Instr(Instr::Dsin(l1, l2, s1, s2))
}

/// Constructs an item for the `dcos` instruction.
pub fn dcos<L>(
    l1: LoadOperand<L>,
    l2: LoadOperand<L>,
    s1: StoreOperand<L>,
    s2: StoreOperand<L>,
) -> Item<L> {
    Item::Instr(Instr::Dcos(l1, l2, s1, s2))
}

/// Constructs an item for the `dtan` instruction.
pub fn dtan<L>(
    l1: LoadOperand<L>,
    l2: LoadOperand<L>,
    s1: StoreOperand<L>,
    s2: StoreOperand<L>,
) -> Item<L> {
    Item::Instr(Instr::Dtan(l1, l2, s1, s2))
}

/// Constructs an item for the `dasin` instruction.
pub fn dasin<L>(
    l1: LoadOperand<L>,
    l2: LoadOperand<L>,
    s1: StoreOperand<L>,
    s2: StoreOperand<L>,
) -> Item<L> {
    Item::Instr(Instr::Dasin(l1, l2, s1, s2))
}

/// Constructs an item for the `dacos` instruction.
pub fn dacos<L>(
    l1: LoadOperand<L>,
    l2: LoadOperand<L>,
    s1: StoreOperand<L>,
    s2: StoreOperand<L>,
) -> Item<L> {
    Item::Instr(Instr::Dacos(l1, l2, s1, s2))
}

/// Constructs an item for the `datan` instruction.
pub fn datan<L>(
    l1: LoadOperand<L>,
    l2: LoadOperand<L>,
    s1: StoreOperand<L>,
    s2: StoreOperand<L>,
) -> Item<L> {
    Item::Instr(Instr::Datan(l1, l2, s1, s2))
}

/// Constructs an item for the `datan2` instruction.
pub fn datan2<L>(
    l1: LoadOperand<L>,
    l2: LoadOperand<L>,
    l3: LoadOperand<L>,
    l4: LoadOperand<L>,
    s1: StoreOperand<L>,
    s2: StoreOperand<L>,
) -> Item<L> {
    Item::Instr(Instr::Datan2(l1, l2, l3, l4, s1, s2))
}

/// Constructs an item for the `jisnan` instruction.
pub fn jisnan<L>(l1: LoadOperand<L>, bt: L) -> Item<L> {
    Item::Instr(Instr::Jisnan(l1, LoadOperand::Branch(bt)))
}

/// Constructs an item for the `jisnan` instruction, with a branch operand that returns 0 or 1 instead of branching
pub fn jisnan_ret<L>(l1: LoadOperand<L>, bt: bool) -> Item<L> {
    Item::Instr(Instr::Jisnan(l1, LoadOperand::Imm(bt.into())))
}

/// Constructs an item for the `jisinf` instruction.
pub fn jisinf<L>(l1: LoadOperand<L>, bt: L) -> Item<L> {
    Item::Instr(Instr::Jisinf(l1, LoadOperand::Branch(bt)))
}

/// Constructs an item for the `jisinf` instruction, with a branch operand that returns 0 or 1 instead of branching
pub fn jisinf_ret<L>(l1: LoadOperand<L>, bt: bool) -> Item<L> {
    Item::Instr(Instr::Jisinf(l1, LoadOperand::Imm(bt.into())))
}

/// Constructs an item for the `jfeq` instruction.
pub fn jfeq<L>(l1: LoadOperand<L>, l2: LoadOperand<L>, l3: LoadOperand<L>, bt: L) -> Item<L> {
    Item::Instr(Instr::Jfeq(l1, l2, l3, LoadOperand::Branch(bt)))
}

/// Constructs an item for the `jfeq` instruction, with a branch operand that returns 0 or 1 instead of branching
pub fn jfeq_ret<L>(
    l1: LoadOperand<L>,
    l2: LoadOperand<L>,
    l3: LoadOperand<L>,
    bt: bool,
) -> Item<L> {
    Item::Instr(Instr::Jfeq(l1, l2, l3, LoadOperand::Imm(bt.into())))
}

/// Constructs an item for the `jfne` instruction.
pub fn jfne<L>(l1: LoadOperand<L>, l2: LoadOperand<L>, l3: LoadOperand<L>, bt: L) -> Item<L> {
    Item::Instr(Instr::Jfne(l1, l2, l3, LoadOperand::Branch(bt)))
}

/// Constructs an item for the `jfne` instruction, with a branch operand that returns 0 or 1 instead of branching
pub fn jfne_ret<L>(
    l1: LoadOperand<L>,
    l2: LoadOperand<L>,
    l3: LoadOperand<L>,
    bt: bool,
) -> Item<L> {
    Item::Instr(Instr::Jfne(l1, l2, l3, LoadOperand::Imm(bt.into())))
}

/// Constructs an item for the `jflt` instruction.
pub fn jflt<L>(l1: LoadOperand<L>, l2: LoadOperand<L>, bt: L) -> Item<L> {
    Item::Instr(Instr::Jflt(l1, l2, LoadOperand::Branch(bt)))
}

/// Constructs an item for the `jflt` instruction, with a branch operand that returns 0 or 1 instead of branching
pub fn jflt_ret<L>(l1: LoadOperand<L>, l2: LoadOperand<L>, bt: bool) -> Item<L> {
    Item::Instr(Instr::Jflt(l1, l2, LoadOperand::Imm(bt.into())))
}

/// Constructs an item for the `jfle` instruction.
pub fn jfle<L>(l1: LoadOperand<L>, l2: LoadOperand<L>, bt: L) -> Item<L> {
    Item::Instr(Instr::Jfle(l1, l2, LoadOperand::Branch(bt)))
}

/// Constructs an item for the `jfle` instruction, with a branch operand that returns 0 or 1 instead of branching
pub fn jfle_ret<L>(l1: LoadOperand<L>, l2: LoadOperand<L>, bt: bool) -> Item<L> {
    Item::Instr(Instr::Jfle(l1, l2, LoadOperand::Imm(bt.into())))
}

/// Constructs an item for the `jfgt` instruction.
pub fn jfgt<L>(l1: LoadOperand<L>, l2: LoadOperand<L>, bt: L) -> Item<L> {
    Item::Instr(Instr::Jfgt(l1, l2, LoadOperand::Branch(bt)))
}

/// Constructs an item for the `jfgt` instruction, with a branch operand that returns 0 or 1 instead of branching
pub fn jfgt_ret<L>(l1: LoadOperand<L>, l2: LoadOperand<L>, bt: bool) -> Item<L> {
    Item::Instr(Instr::Jfgt(l1, l2, LoadOperand::Imm(bt.into())))
}

/// Constructs an item for the `jfge` instruction.
pub fn jfge<L>(l1: LoadOperand<L>, l2: LoadOperand<L>, bt: L) -> Item<L> {
    Item::Instr(Instr::Jfge(l1, l2, LoadOperand::Branch(bt)))
}

/// Constructs an item for the `jfge` instruction, with a branch operand that returns 0 or 1 instead of branching
pub fn jfge_ret<L>(l1: LoadOperand<L>, l2: LoadOperand<L>, bt: bool) -> Item<L> {
    Item::Instr(Instr::Jfge(l1, l2, LoadOperand::Imm(bt.into())))
}

/// Constructs an item for the `jdisnan` instruction.
pub fn jdisnan<L>(l1: LoadOperand<L>, l2: LoadOperand<L>, bt: L) -> Item<L> {
    Item::Instr(Instr::Jdisnan(l1, l2, LoadOperand::Branch(bt)))
}

/// Constructs an item for the `jdisnan` instruction, with a branch operand that returns 0 or 1 instead of branching
pub fn jdisnan_ret<L>(l1: LoadOperand<L>, l2: LoadOperand<L>, bt: bool) -> Item<L> {
    Item::Instr(Instr::Jdisnan(l1, l2, LoadOperand::Imm(bt.into())))
}

/// Constructs an item for the `jdisinf` instruction.
pub fn jdisinf<L>(l1: LoadOperand<L>, l2: LoadOperand<L>, bt: L) -> Item<L> {
    Item::Instr(Instr::Jdisinf(l1, l2, LoadOperand::Branch(bt)))
}

/// Constructs an item for the `jdisinf` instruction, with a branch operand that returns 0 or 1 instead of branching
pub fn jdisinf_ret<L>(l1: LoadOperand<L>, l2: LoadOperand<L>, bt: bool) -> Item<L> {
    Item::Instr(Instr::Jdisinf(l1, l2, LoadOperand::Imm(bt.into())))
}

/// Constructs an item for the `jdeq` instruction.
pub fn jdeq<L>(
    l1: LoadOperand<L>,
    l2: LoadOperand<L>,
    l3: LoadOperand<L>,
    l4: LoadOperand<L>,
    l5: LoadOperand<L>,
    l6: LoadOperand<L>,
    bt: L,
) -> Item<L> {
    Item::Instr(Instr::Jdeq(l1, l2, l3, l4, l5, l6, LoadOperand::Branch(bt)))
}

/// Constructs an item for the `jdeq` instruction, with a branch operand that returns 0 or 1 instead of branching
pub fn jdeq_ret<L>(
    l1: LoadOperand<L>,
    l2: LoadOperand<L>,
    l3: LoadOperand<L>,
    l4: LoadOperand<L>,
    l5: LoadOperand<L>,
    l6: LoadOperand<L>,
    bt: bool,
) -> Item<L> {
    Item::Instr(Instr::Jdeq(
        l1,
        l2,
        l3,
        l4,
        l5,
        l6,
        LoadOperand::Imm(bt.into()),
    ))
}

/// Constructs an item for the `jdne` instruction.
pub fn jdne<L>(
    l1: LoadOperand<L>,
    l2: LoadOperand<L>,
    l3: LoadOperand<L>,
    l4: LoadOperand<L>,
    l5: LoadOperand<L>,
    l6: LoadOperand<L>,
    bt: L,
) -> Item<L> {
    Item::Instr(Instr::Jdne(l1, l2, l3, l4, l5, l6, LoadOperand::Branch(bt)))
}

/// Constructs an item for the `jdne` instruction, with a branch operand that returns 0 or 1 instead of branching
pub fn jdne_ret<L>(
    l1: LoadOperand<L>,
    l2: LoadOperand<L>,
    l3: LoadOperand<L>,
    l4: LoadOperand<L>,
    l5: LoadOperand<L>,
    l6: LoadOperand<L>,
    bt: bool,
) -> Item<L> {
    Item::Instr(Instr::Jdne(
        l1,
        l2,
        l3,
        l4,
        l5,
        l6,
        LoadOperand::Imm(bt.into()),
    ))
}

/// Constructs an item for the `jdlt` instruction.
pub fn jdlt<L>(
    l1: LoadOperand<L>,
    l2: LoadOperand<L>,
    l3: LoadOperand<L>,
    l4: LoadOperand<L>,
    bt: L,
) -> Item<L> {
    Item::Instr(Instr::Jdlt(l1, l2, l3, l4, LoadOperand::Branch(bt)))
}

/// Constructs an item for the `jdlt` instruction, with a branch operand that returns 0 or 1 instead of branching
pub fn jdlt_ret<L>(
    l1: LoadOperand<L>,
    l2: LoadOperand<L>,
    l3: LoadOperand<L>,
    l4: LoadOperand<L>,
    bt: bool,
) -> Item<L> {
    Item::Instr(Instr::Jdlt(l1, l2, l3, l4, LoadOperand::Imm(bt.into())))
}

/// Constructs an item for the `jdle` instruction.
pub fn jdle<L>(
    l1: LoadOperand<L>,
    l2: LoadOperand<L>,
    l3: LoadOperand<L>,
    l4: LoadOperand<L>,
    bt: L,
) -> Item<L> {
    Item::Instr(Instr::Jdle(l1, l2, l3, l4, LoadOperand::Branch(bt)))
}

/// Constructs an item for the `jdle` instruction, with a branch operand that returns 0 or 1 instead of branching
pub fn jdle_ret<L>(
    l1: LoadOperand<L>,
    l2: LoadOperand<L>,
    l3: LoadOperand<L>,
    l4: LoadOperand<L>,
    bt: bool,
) -> Item<L> {
    Item::Instr(Instr::Jdle(l1, l2, l3, l4, LoadOperand::Imm(bt.into())))
}

/// Constructs an item for the `jdgt` instruction.
pub fn jdgt<L>(
    l1: LoadOperand<L>,
    l2: LoadOperand<L>,
    l3: LoadOperand<L>,
    l4: LoadOperand<L>,
    bt: L,
) -> Item<L> {
    Item::Instr(Instr::Jdgt(l1, l2, l3, l4, LoadOperand::Branch(bt)))
}

/// Constructs an item for the `jdgt` instruction, with a branch operand that returns 0 or 1 instead of branching
pub fn jdgt_ret<L>(
    l1: LoadOperand<L>,
    l2: LoadOperand<L>,
    l3: LoadOperand<L>,
    l4: LoadOperand<L>,
    bt: bool,
) -> Item<L> {
    Item::Instr(Instr::Jdgt(l1, l2, l3, l4, LoadOperand::Imm(bt.into())))
}

/// Constructs an item for the `jdge` instruction.
pub fn jdge<L>(
    l1: LoadOperand<L>,
    l2: LoadOperand<L>,
    l3: LoadOperand<L>,
    l4: LoadOperand<L>,
    bt: L,
) -> Item<L> {
    Item::Instr(Instr::Jdge(l1, l2, l3, l4, LoadOperand::Branch(bt)))
}

/// Constructs an item for the `jdge` instruction, with a branch operand that returns 0 or 1 instead of branching
pub fn jdge_ret<L>(
    l1: LoadOperand<L>,
    l2: LoadOperand<L>,
    l3: LoadOperand<L>,
    l4: LoadOperand<L>,
    bt: bool,
) -> Item<L> {
    Item::Instr(Instr::Jdge(l1, l2, l3, l4, LoadOperand::Imm(bt.into())))
}

/// Constructs an item for the `random` instruction.
pub fn random<L>(l1: LoadOperand<L>, s1: StoreOperand<L>) -> Item<L> {
    Item::Instr(Instr::Random(l1, s1))
}

/// Constructs an item for the `setrandom` instruction.
pub fn setrandom<L>(l1: LoadOperand<L>) -> Item<L> {
    Item::Instr(Instr::Setrandom(l1))
}

/// Constructs an item for the `mzero` instruction.
pub fn mzero<L>(l1: LoadOperand<L>, l2: LoadOperand<L>) -> Item<L> {
    Item::Instr(Instr::Mzero(l1, l2))
}

/// Constructs an item for the `mcopy` instruction.
pub fn mcopy<L>(l1: LoadOperand<L>, l2: LoadOperand<L>, l3: LoadOperand<L>) -> Item<L> {
    Item::Instr(Instr::Mcopy(l1, l2, l3))
}

/// Constructs an item for the `linearsearch` instruction.
pub fn linearsearch<L>(
    l1: LoadOperand<L>,
    l2: LoadOperand<L>,
    l3: LoadOperand<L>,
    l4: LoadOperand<L>,
    l5: LoadOperand<L>,
    l6: LoadOperand<L>,
    l7: LoadOperand<L>,
    s1: StoreOperand<L>,
) -> Item<L> {
    Item::Instr(Instr::Linearsearch(l1, l2, l3, l4, l5, l6, l7, s1))
}

/// Constructs an item for the `binarysearch` instruction.
pub fn binarysearch<L>(
    l1: LoadOperand<L>,
    l2: LoadOperand<L>,
    l3: LoadOperand<L>,
    l4: LoadOperand<L>,
    l5: LoadOperand<L>,
    l6: LoadOperand<L>,
    l7: LoadOperand<L>,
    s1: StoreOperand<L>,
) -> Item<L> {
    Item::Instr(Instr::Binarysearch(l1, l2, l3, l4, l5, l6, l7, s1))
}

/// Constructs an item for the `linkedsearch` instruction.
pub fn linkedsearch<L>(
    l1: LoadOperand<L>,
    l2: LoadOperand<L>,
    l3: LoadOperand<L>,
    l4: LoadOperand<L>,
    l5: LoadOperand<L>,
    l6: LoadOperand<L>,
    s1: StoreOperand<L>,
) -> Item<L> {
    Item::Instr(Instr::Linkedsearch(l1, l2, l3, l4, l5, l6, s1))
}

/// Constructs an item for the `accelfunc` instruction.
pub fn accelfunc<L>(l1: LoadOperand<L>, l2: LoadOperand<L>) -> Item<L> {
    Item::Instr(Instr::Accelfunc(l1, l2))
}

/// Constructs an item for the `accelparam` instruction.
pub fn accelparam<L>(l1: LoadOperand<L>, l2: LoadOperand<L>) -> Item<L> {
    Item::Instr(Instr::Accelparam(l1, l2))
}

/// Constructs an item for the `gestalt` instruction.
pub fn gestalt<L>(l1: LoadOperand<L>, l2: LoadOperand<L>, s1: StoreOperand<L>) -> Item<L> {
    Item::Instr(Instr::Gestalt(l1, l2, s1))
}

/// Constructs an item for the `debugtrap` instruction.
pub fn debugtrap<L>(l1: LoadOperand<L>) -> Item<L> {
    Item::Instr(Instr::Debugtrap(l1))
}

/// Constructs an item for the `glk` instruction.
pub fn glk<L>(l1: LoadOperand<L>, l2: LoadOperand<L>, s1: StoreOperand<L>) -> Item<L> {
    Item::Instr(Instr::Glk(l1, l2, s1))
}

// SCRIPT OUTPUT ENDS HERE

/*
INSTRS = [
    ["nop"],
    ["add", "l1", "l2", "s1"],
    ["sub", "l1", "l2", "s1"],
    ["mul", "l1", "l2", "s1"],
    ["div", "l1", "l2", "s1"],
    ["mod", "l1", "l2", "s1"],
    ["neg", "l1", "s1"],
    ["bitand", "l1", "l2", "s1"],
    ["bitor", "l1", "l2", "s1"],
    ["bitxor", "l1", "l2", "s1"],
    ["bitnot", "l1", "s1"],
    ["shiftl", "l1", "l2", "s1"],
    ["ushiftr", "l1", "l2", "s1"],
    ["sshiftr", "l1", "l2", "s1"],
    ["jump", "bt"],
    ["jz", "l1", "bt"],
    ["jnz", "l1", "bt"],
    ["jeq", "l1", "l2", "bt"],
    ["jne", "l1", "l2", "bt"],
    ["jlt", "l1", "l2", "bt"],
    ["jle", "l1", "l2", "bt"],
    ["jgt", "l1", "l2", "bt"],
    ["jge", "l1", "l2", "bt"],
    ["jltu", "l1", "l2", "bt"],
    ["jleu", "l1", "l2", "bt"],
    ["jgtu", "l1", "l2", "bt"],
    ["jgeu", "l1", "l2", "bt"],
    ["jumpabs", "l1"],
    ["copy", "l1", "s1"],
    ["copys", "l1", "s1"],
    ["copyb", "l1", "s1"],
    ["sexs", "l1", "s1"],
    ["sexb", "l1", "s1"],
    ["astore", "l1", "l2", "l3"],
    ["aload", "l1", "l2", "s1"],
    ["astores", "l1", "l2", "l3"],
    ["aloads", "l1", "l2", "s1"],
    ["astoreb", "l1", "l2", "l3"],
    ["aloadb", "l1", "l2", "s1"],
    ["astorebit", "l1", "l2", "l3"],
    ["aloadbit", "l1", "l2", "s1"],
    ["stkcount", "s1"],
    ["stkpeek", "l1", "s1"],
    ["stkswap"],
    ["stkcopy", "l1"],
    ["stkroll", "l1", "l2"],
    ["call", "l1", "l2", "s1"],
    ["callf", "l1", "s1"],
    ["callfi", "l1", "l2", "s1"],
    ["callfii", "l1", "l2", "l3", "s1"],
    ["callfiii", "l1", "l2", "l3", "l4", "s1"],
    ["return", "l1"],
    ["tailcall", "l1", "l2"],
    ["catch", "s1", "bt"],
    ["throw", "l1", "l2"],
    ["getmemsize", "s1"],
    ["setmemsize", "l1", "s1"],
    ["malloc", "l1", "s1"],
    ["mfree", "l1"],
    ["quit"],
    ["restart"],
    ["save", "l1", "s1"],
    ["restore", "l1", "s1"],
    ["saveundo", "s1"],
    ["restoreundo", "s1"],
    ["hasundo", "s1"],
    ["discardundo"],
    ["protect", "l1", "l2"],
    ["verify", "s1"],
    ["getiosys", "s1", "s2"],
    ["setiosys", "l1", "l2"],
    ["streamchar", "l1"],
    ["streamunichar", "l1"],
    ["streamnum", "l1"],
    ["streamstr", "l1"],
    ["getstringtbl", "s1"],
    ["setstringtbl", "l1"],
    ["numtof", "l1", "s1"],
    ["ftonumz", "l1", "s1"],
    ["ftonumn", "l1", "s1"],
    ["fadd", "l1", "l2", "s1"],
    ["fsub", "l1", "l2", "s1"],
    ["fmul", "l1", "l2", "s1"],
    ["fdiv", "l1", "l2", "s1"],
    ["fmod", "l1", "l2", "s1", "s2"],
    ["ceil", "l1", "s1"],
    ["floor", "l1", "s1"],
    ["sqrt", "l1", "s1"],
    ["exp", "l1", "s1"],
    ["log", "l1", "s1"],
    ["pow", "l1", "l2", "s1"],
    ["sin", "l1", "s1"],
    ["cos", "l1", "s1"],
    ["tan", "l1", "s1"],
    ["asin", "l1", "s1"],
    ["acos", "l1", "s1"],
    ["atan", "l1", "s1"],
    ["atan2", "l1", "s1"],
    ["numtod", "l1", "s1", "s2"],
    ["dtonumz", "l1", "l2", "s1"],
    ["dtonumn", "l1", "l2", "s1"],
    ["ftod", "l1", "s1", "s2"],
    ["dtof", "l1", "l2", "s1"],
    ["dadd", "l1", "l2", "l3", "l4", "s1", "s2"],
    ["dsub", "l1", "l2", "l3", "l4", "s1", "s2"],
    ["dmul", "l1", "l2", "l3", "l4", "s1", "s2"],
    ["ddiv", "l1", "l2", "l3", "l4", "s1", "s2"],
    ["dmodr", "l1", "l2", "l3", "l4", "s1", "s2"],
    ["dmodq", "l1", "l2", "l3", "l4", "s1", "s2"],
    ["dceil", "l1", "l2", "s1", "s2"],
    ["dfloor", "l1", "l2", "s1", "s2"],
    ["dsqrt", "l1", "l2", "s1", "s2"],
    ["dexp", "l1", "l2", "s1", "s2"],
    ["dlog", "l1", "l2", "s1", "s2"],
    ["dpow", "l1", "l2", "l3", "l4", "s1", "s2"],
    ["dsin", "l1", "l2", "s1", "s2"],
    ["dcos", "l1", "l2", "s1", "s2"],
    ["dtan", "l1", "l2", "s1", "s2"],
    ["dasin", "l1", "l2", "s1", "s2"],
    ["dacos", "l1", "l2", "s1", "s2"],
    ["datan", "l1", "l2", "s1", "s2"],
    ["datan2", "l1", "l2", "l3", "l4", "s1", "s2"],
    ["jisnan", "l1", "bt"],
    ["jisinf", "l1", "bt"],
    ["jfeq", "l1", "l2", "l3", "bt"],
    ["jfne", "l1", "l2", "l3", "bt"],
    ["jflt", "l1", "l2", "bt"],
    ["jfle", "l1", "l2", "bt"],
    ["jfgt", "l1", "l2", "bt"],
    ["jfge", "l1", "l2", "bt"],
    ["jdisnan", "l1", "l2", "bt"],
    ["jdisinf", "l1", "l2", "bt"],
    ["jdeq", "l1", "l2", "l3", "l4", "l5", "l6", "bt"],
    ["jdne", "l1", "l2", "l3", "l4", "l5", "l6", "bt"],
    ["jdlt", "l1", "l2", "l3", "l4", "bt"],
    ["jdle", "l1", "l2", "l3", "l4", "bt"],
    ["jdgt", "l1", "l2", "l3", "l4", "bt"],
    ["jdge", "l1", "l2", "l3", "l4", "bt"],
    ["random", "l1", "s1"],
    ["setrandom", "l1"],
    ["mzero", "l1", "l2"],
    ["mcopy", "l1", "l2", "l3"],
    ["linearsearch", "l1", "l2", "l3", "l4", "l5", "l6", "l7", "s1"],
    ["binarysearch", "l1", "l2", "l3", "l4", "l5", "l6", "l7", "s1"],
    ["linkedsearch", "l1", "l2", "l3", "l4", "l5", "l6", "s1"],
    ["accelfunc", "l1", "l2"],
    ["accelparam", "l1", "l2"],
    ["gestalt", "l1", "l2", "s1"],
    ["debugtrap", "l1"],
    ["glk", "l1", "l2", "s1"],
]

for instr in INSTRS:
    op = instr[0]
    args = instr[1:]
    upper = op[0].upper() + op[1:]

    print("/// Constructs an item for the `{}` instruction.".format(op))

    if op == "mod":
        op = "modulo"
    if op == "return":
        op = "ret"

    print("pub fn {}<L>(".format(op), end='')
    for arg in args:
        if arg[0] == 'l':
            print("{}: LoadOperand<L>, ".format(arg), end='')
        elif arg[0] == 's':
            print("{}: StoreOperand<L>, ".format(arg), end='')
        else:
            print("{}: L, ".format(arg), end='')
    print(") -> Item<L> {", end = '')
    print("Item::Instr(Instr::{}".format(upper), end = '')
    if len(args) > 0:
        print("(", end='')
        for arg in args:
            if arg == "bt":
                print("LoadOperand::Branch(bt), ", end='')
            else:
                 print("{}, ".format(arg), end='')
        print(")) }\n")
    else:
        print(") } \n")

    if len(args) > 0 and args[-1] == "bt":
        print("/// Constructs an item for the `{}` instruction, with a branch operand that returns 0 or 1 instead of branching".format(op))
        print("pub fn {}_ret<L>(".format(op), end='')
        for arg in args:
            if arg[0] == 'l':
                print("{}: LoadOperand<L>, ".format(arg), end='')
            elif arg[0] == 's':
                print("{}: StoreOperand<L>, ".format(arg), end='')
            else:
                print("{}: bool, ".format(arg), end='')
        print(") -> Item<L> {", end = '')
        print("Item::Instr(Instr::{}(".format(upper), end = '')
        for arg in args:
            if arg == "bt":
                print("LoadOperand::Imm(bt.into()), ", end='')
            else:
                 print("{}, ".format(arg), end='')
        print(")) }\n")
*/