-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjs_webasm_runner.js
More file actions
1364 lines (1247 loc) · 58.3 KB
/
Copy pathjs_webasm_runner.js
File metadata and controls
1364 lines (1247 loc) · 58.3 KB
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
const fs = require('fs');
async function main() {
const wasmBytes = fs.readFileSync('./program.wasm');
const outputFile = fs.createWriteStream('./output.wasm');
// This is for import functions to be exposed in WebAsm
const imports = {
env: {
print_i32: (value) => {
console.log(value);
},
write_char: (value) => {
console.log('write:', value);
outputFile.write(Buffer.from([value]));
}
}
}
const wasmModule = await WebAssembly.instantiate(wasmBytes, imports);
const instance = wasmModule.instance;
// handle inserting data to memory
const memory = instance.exports.memory;
const bytes = new Uint8Array(memory.buffer);
const replaceBytes = fs.readFileSync('./input.cwa');
for (let i = 0; i < replaceBytes.length; i++) {
bytes[i] = replaceBytes[i];
}
// calls the exported main function to begin the program
instance.exports.main();
outputFile.end();
}
function cmd(input) {
if (input == 'i32.add') { return 0x6A }
else if (input == 'i32.sub') { return 0x6B }
else if (input == 'i32.mul') { return 0x6C }
else if (input == 'i32.and') { return 0x71 }
else if (input == 'i32.or') { return 0x72 }
else if (input == 'i32.shr_u') { return 0x76 }
else if (input == 'i32.const') { return 0x41 }
else if (input == 'call') { return 0x10 }
else if (input == 'local.get') { return 0x20 }
else if (input == 'local.set') { return 0x21 }
else if (input == 'i32.load8_u') { return 0x2D }
else if (input == 'if') { return 0x04 }
else if (input == 'else') { return 0x05 }
else if (input == 'block') { return 0x02 }
else if (input == 'loop') { return 0x03 }
else if (input == 'end') { return 0x0B }
else if (input == 'i32.eq') { return 0x46 }
else if (input == 'i32.nq') { return 0x47 }
else if (input == 'i32.lt_u') { return 0x49 }
else if (input == 'i32.le_u') { return 0x4D }
else if (input == 'i32.gt_u') { return 0x4B }
else if (input == 'i32.ge_u') { return 0x4F }
else if (input == 'br') { return 0x0C }
else if (input == 'br_if') { return 0x0D }
else if (input == 'return') { return 0x0F }
console.error("Command, " + input + ", not found.");
process.exit(1);
}
function ULEB128(number) {
const bytes = [];
while (number > 0) {
const byte = number & 0x7F;
number >>>= 7;
if (number > 0) {
bytes.push(byte | 0x80);
} else {
bytes.push(byte);
}
}
return bytes;
}
function SLEB128(value) {
const bytes = [];
value |= 0;
let more = true;
while (more) {
let byte = value & 0x7F;
value >>= 7;
if ((value === 0 && (byte & 0x40) === 0) || (value === -1 && (byte & 0x40) !== 0)) {
more = false;
} else {
byte |= 0x80;
}
bytes.push(byte);
}
return bytes;
}
function createWasmFile() {
const functions = {print_i32: 0, write_char: 1, main: 2, WordToCMD: 3, WordToI32: 4, IntoULEB128: 5, WriteULEB128: 6};
const b1 = [
// HEADER
0x00, 0x61, 0x73, 0x6D, // magic number
0x01, 0x00, 0x00, 0x00, // version
// TYPE
0x01, 27, // 01 = Type Section, = length of section in bytes
0x06, // function type count
// print_i32(i32) -> void
0x60, 0x01, 0x7F, 0x00, // 60=function type, 01=1 parameter, 7F=i32, 00=0 return values
// write_char(i32) -> void
0x60, 0x01, 0x7F, 0x00, // 60=function type, 01=1 parameter, 7F=i32, 00=0 return values
// main() -> void
0x60, 0x00, 0x00, // 60=function type, 00=0 parameters, 00=0 return values
// WordToCMD(), WordToI32() -> i32
0x60, 0x02, 0x7F, 0x7F, 0x01, 0x7F, // 60=function type, 0x02=2 parameters, 7F=param1 i32, 7F=param2 i32, 1=returns value, 7F=returns i32
// IntoULEB128() -> i32
0x60, 0x01, 0x7F, 0x01, 0x7F, // 60=function type, 01=1 parameter, 7F=i32, 1=returns value, 7F=returns i32
// WriteULEB128() -> void
0x60, 0x01, 0x7F, 0x00, // 60=function type, 01=1 parameter, 7F=i32, 00=0 return values
// IMPORT
0x02, 34, // 02 = Import Section, = length of section in bytes
0x02, // = imports
// inside "env" module
0x03, 0x65, 0x6E, 0x76, // 03 = length of module name, "env"; rest = "env"
// import "print_i32" -> void
0x09, 0x70, 0x72, 0x69, 0x6E, 0x74, 0x5F, 0x69, 0x33, 0x32, // 09= length of function name, "print_i32"; rest = "print_i32"
0x00, 0x00, // 00 = import kind (function), 00 = type index (0)
// inside "env" module
0x03, 0x65, 0x6E, 0x76,
// import "write_char" -> void
0x0A, 0x77, 0x72, 0x69, 0x74, 0x65, 0x5F, 0x63, 0x68, 0x61, 0x72, // 0A= length of function name, "write_char"; rest = "write_char"
0x00, 0x01, // 00 = import kind (function), 01 = type index (1)
// FUNCTION
0x03, 6, // 03 = Function Section, = length of section in bytes
0x05, // =function count
0x02, // = type index -- main()
0x03, // = type index -- WordToCMD()
0x03, // = type index -- WordToI32()
0x04, // = type index -- IntoULEB128()
0x05, // = type index -- WriteULEB128()
// MEMORY
0x05, 3, // 05 = Memory Section, = length of section in bytes
0x01, // 01 = 1 page of memory (65,536 bytes)
0x00, 0x01, // 00 = limit flags (0 = no max), 01 = minumum size (1)
// EXPORT
0x07, 17, // 07 = Export Section, = length of section in bytes
0x02, // 02 = 2 exports
// expoort "main"
0x04, 0x6D, 0x61, 0x69, 0x6E, // 04 = length of export name, "main"; rest = "main"
0x00, 0x02, // 00 = export kind (function), function index
// export "memory"
0x06, 0x6D, 0x65, 0x6D, 0x6F, 0x72, 0x79, // 06 = length of export name, "memory"; rest = "memory"
0x02, 0x00, // 02 = export kind (memory), 00 = memory index (0)
// CODE SECTION
0x0A
];
const b3 = [
0x05, // = Number of functions
];
const mainVars = {
bytes: 0,
char: 1,
cmd: 2,
number: 3,
startWord: 4,
wordLength: 5,
stateCMD: 6,
}
const b5_main = [
1, // = local variable declaration group count
0x07, 0x7F, // byets, char, cmd, number, startWord, wordLength, stateCMD
// block loop:
// char = memory[bytes]
// bytes = bytes + 1
//
// if char == ENDOFFILEBYTE {
// break
// }
//
// if char == '\n' as i32 || char == '\r' as i32 {
// stateCMD = 1 // next byte is command
// startWord = bytes + 1
// goto loop
// }
// if char == ' ' as i32 || char == '\t' as i32 || char == ';' as i32 {
// if stateCMD == 2 { // End Of Command
// stateCMD = 0
// cmd = WordToCMD(startWord, wordLength)
// if cmd == 0xFB { // check for error
// print_i32(0xFB)
// return
// }
// write_char(cmd)
// }
// else if stateCMD == 0 { // End Of Argument
// number = WordToI32(startWord, wordLength)
// if number == 0xFC { // check for error
// print_i32(0xFC)
// return
// }
// writeULEB128(number)
// }
// startWord = bytes
// wordLength = 0
// goto loop
// }
// if (char >= 'a' && char <= 'z') || (char >= 'A' && char <= 'Z') || (char >= '0' && char <= '9') || char == '_' {
// if stateCMD == 1 {
// stateCMD = 2
// }
// wordLength = wordLength + 1
// } else {
// print_i32(0xFD) // error code invalid char
// return
// }
// goto loop
//end
//// END OF FILE SEQUENCE
//write_char(0xFE)
//write_char(0xFE)
//
//print_i32(bytes)
cmd('i32.const'), 1,
cmd('local.set'), mainVars['stateCMD'],
cmd('block'), 0x40, // block -> null
cmd('loop'), 0x40, // loop -> null
// char = memory[bytes]
cmd('local.get'), mainVars['bytes'],
cmd('i32.load8_u'), 0, 0,
cmd('local.set'), mainVars['char'],
// bytes = bytes + 1
cmd('local.get'), mainVars['bytes'],
cmd('i32.const'), 1,
cmd('i32.add'),
cmd('local.set'), mainVars['bytes'],
// char == 0xFE (EOF) || char == `|` as i32 (this is for ascii character for easaier writing cwa file)
cmd('local.get'), mainVars['char'],
cmd('i32.const'), ...ULEB128(0xFE),
cmd('i32.eq'),
cmd('local.get'), mainVars['char'],
cmd('i32.const'), ...ULEB128('|'.charCodeAt(0)),
cmd('i32.eq'),
cmd('i32.or'),
cmd('br_if'), 1, // br_if (loop=0, block=1)
//if char == '\n' || char == '\r' { stateCMD = 1; startWord = bytes + 1; goto loop }
cmd('local.get'), mainVars['char'],
cmd('i32.const'), ...ULEB128('\n'.charCodeAt(0)),
cmd('i32.eq'),
cmd('local.get'), mainVars['char'],
cmd('i32.const'), ...ULEB128('\r'.charCodeAt(0)),
cmd('i32.eq'),
cmd('i32.or'),
cmd('if'), 0x40, // if -> null
cmd('i32.const'), 1,
cmd('local.set'), mainVars['stateCMD'],
cmd('local.get'), mainVars['bytes'],
cmd('local.set'), mainVars['startWord'],
// goto loop
cmd('br'), 1, // (if=0, loop=1, block=2)
cmd('end'), // end [if]
// if char == ' ' || char == '\t' || char == ';'
cmd('local.get'), mainVars['char'],
cmd('i32.const'), ...ULEB128(' '.charCodeAt(0)),
cmd('i32.eq'),
cmd('local.get'), mainVars['char'],
cmd('i32.const'), ...ULEB128('\t'.charCodeAt(0)),
cmd('i32.eq'),
cmd('i32.or'),
cmd('local.get'), mainVars['char'],
cmd('i32.const'), ...ULEB128(';'.charCodeAt(0)),
cmd('i32.eq'),
cmd('i32.or'),
cmd('if'), 0x40, // if -> null
// if stateCMD == 2
cmd('local.get'), mainVars['stateCMD'],
cmd('i32.const'), 2,
cmd('i32.eq'),
cmd('if'), 0x40, // if -> null
// stateCMD = 0
cmd('i32.const'), 0,
cmd('local.set'), mainVars['stateCMD'],
// cmd = WordToCMD(startWord, wordLength)
cmd('local.get'), mainVars['startWord'],
cmd('local.get'), mainVars['wordLength'],
cmd('call'), functions['WordToCMD'],
cmd('local.set'), mainVars['cmd'],
// if cmd == 0xFB { print_i32(0xFB); return; }
cmd('local.get'), mainVars['cmd'],
cmd('i32.const'), ...ULEB128(0xFB),
cmd('i32.eq'),
cmd('if'), 0x40, // if -> null
cmd('i32.const'), ...ULEB128(0xFB),
cmd('call'), functions['print_i32'],
cmd('return'),
cmd('end'), // end [if]
// write_char(cmd)
cmd('local.get'), mainVars['cmd'],
cmd('call'), functions['write_char'],
cmd('else'),
// if stateCMD == 0
cmd('local.get'), mainVars['stateCMD'],
cmd('i32.const'), 0,
cmd('i32.eq'),
cmd('if'), 0x40, // if -> null
// number = WordToI32(startWord, wordLength)
cmd('local.get'), mainVars['startWord'],
cmd('local.get'), mainVars['wordLength'],
cmd('call'), functions['WordToI32'],
cmd('local.set'), mainVars['number'],
// if number == 0xFC { print_i32(0xFC); return; }
cmd('local.get'), mainVars['number'],
cmd('i32.const'), ...ULEB128(0xFC),
cmd('i32.eq'),
cmd('if'), 0x40, // if -> null
cmd('i32.const'), ...ULEB128(0xFC),
cmd('call'), functions['print_i32'],
cmd('return'),
cmd('end'), // end [if]
// writeULEB128(number)
cmd('local.get'), mainVars['number'],
cmd('call'), functions['WriteULEB128'],
cmd('end'), // end [if]
cmd('end'), // end [if]
// startWord = bytes
cmd('local.get'), mainVars['bytes'],
cmd('local.set'), mainVars['startWord'],
// wordLength = 0
cmd('i32.const'), 0,
cmd('local.set'), mainVars['wordLength'],
// goto loop
cmd('br'), 1, // (if=0, loop=1, block=2)
cmd('end'), // end [if]
// if (char >= 'a' && char <= 'z') || (char >= 'A' && char <= 'Z') || (char >= '0' && char <= '9') || char == '_'
// (char >= 'a' && char <= 'z')
cmd('local.get'), mainVars['char'],
cmd('i32.const'), ...SLEB128('a'.charCodeAt(0)),
cmd('i32.ge_u'), // pushes 1
cmd('local.get'), mainVars['char'],
cmd('i32.const'), ...SLEB128('z'.charCodeAt(0)),
cmd('i32.le_u'), // pushes 1
cmd('i32.and'), // pops both and pushes 1
// stack: (assuming char is letter a-z)
// | --- |
// | 1 |
// | --- |
// (char >= 'A' && char <= 'Z')
cmd('local.get'), mainVars['char'],
cmd('i32.const'), ...SLEB128('A'.charCodeAt(0)),
cmd('i32.ge_u'), // pushes 1
cmd('local.get'), mainVars['char'],
cmd('i32.const'), ...SLEB128('Z'.charCodeAt(0)),
cmd('i32.le_u'), // pushes 1
cmd('i32.and'), // pops both and pushes 1
// stack: (assuming char is letter a-z)
// | --- | --- |
// | 1 | 0 |
// | --- | --- |
// (char >= '0' && char <= '9')
cmd('local.get'), mainVars['char'],
cmd('i32.const'), ...SLEB128('0'.charCodeAt(0)),
cmd('i32.ge_u'), // pushes 0
cmd('local.get'), mainVars['char'],
cmd('i32.const'), ...SLEB128('9'.charCodeAt(0)),
cmd('i32.le_u'), // pushes 0
cmd('i32.and'), // pops both and pushes 0
// stack: (assuming char is letter a-z)
// | --- | --- | --- |
// | 1 | 0 | 0 |
// | --- | --- | --- |
// char == '_'
cmd('local.get'), mainVars['char'],
cmd('i32.const'), ...SLEB128('_'.charCodeAt(0)),
cmd('i32.eq'), // pushes 0
// stack: (assuming char is letter a-z)
// | --- | --- | --- | --- |
// | 1 | 0 | 0 | 0 |
// | --- | --- | --- | --- |
cmd('i32.or'),
// | --- | --- | --- |
// | 1 | 0 | 0 |
// | --- | --- | --- |
cmd('i32.or'),
// | --- | --- |
// | 1 | 0 |
// | --- | --- |
cmd('i32.or'),
// | --- |
// | 1 |
// | --- |
cmd('if'), 0x40, // if -> null
// if stateCMD == 1 { stateCMD = 2 }
cmd('local.get'), mainVars['stateCMD'],
cmd('i32.const'), 1,
cmd('i32.eq'),
cmd('if'), 0x40, // if -> null
cmd('i32.const'), 2,
cmd('local.set'), mainVars['stateCMD'],
cmd('end'), // end [if]
// wordLength = wordLength + 1
cmd('local.get'), mainVars['wordLength'],
cmd('i32.const'), 1,
cmd('i32.add'),
cmd('local.set'), mainVars['wordLength'],
cmd('else'),
// print_i32(0xFD)
cmd('local.get'), mainVars['char'],
cmd('call'), functions['print_i32'],
cmd('i32.const'), ...ULEB128(0xFD),
cmd('call'), functions['print_i32'],
// return
cmd('return'),
cmd('end'), // end [if]
cmd('br'), 0, // br (loop=0, block=1)
cmd('end'), // end [loop]
cmd('end'), // end [block]
// print_i32(bytes)
cmd('local.get'), mainVars['bytes'],
cmd('call'), functions['print_i32'],
cmd('end') // end
];
const wordToCMDVars = { startWord: 0, wordLength: 1 };
const b7_WordToCMD = [
0, // = local variable declaration group count
//if wordLength == 3 && memory[startWord] == 'a' && memory[startWord + 1] == 'd' && memory[startWord + 2] == 'd' {
// return 0x6A // opcode for `i32.add`
//}
//return 0xFB
// add
//////////////////////////////////////////////////////////////////////////
// wordLength == 3
cmd('i32.const'), 3, // stackLength: 1
cmd('local.get'), wordToCMDVars['wordLength'], // stackLength: 2
cmd('i32.eq'), // stackLength: 1
// memory[startWord] == 'a'
cmd('i32.const'), ...SLEB128('a'.charCodeAt(0)), // stackLength: 2
cmd('local.get'), wordToCMDVars['startWord'], // stackLength: 3
cmd('i32.load8_u'), 0, 0, // stackLength: 3
cmd('i32.eq'), // stackLength: 2
cmd('i32.and'), // stack length 1
// memory[startWord + 1] == 'd'
cmd('i32.const'), ...SLEB128('d'.charCodeAt(0)), // stackLength: 2
cmd('local.get'), wordToCMDVars['startWord'], // stackLength: 3
cmd('i32.const'), 1, // stackLength: 4
cmd('i32.add'), // stackLength: 3
cmd('i32.load8_u'), 0, 0, // stackLength: 3
cmd('i32.eq'), // stackLength: 2
cmd('i32.and'), // stackLength: 1
// memory[startWord + 2] == 'd'
cmd('i32.const'), ...SLEB128('d'.charCodeAt(0)), // stackLength: 2
cmd('local.get'), wordToCMDVars['startWord'], // stackLength: 3
cmd('i32.const'), 2, // stackLength: 4
cmd('i32.add'), // stackLength: 3
cmd('i32.load8_u'), 0, 0, // stackLength: 3
cmd('i32.eq'), // stackLength: 2
cmd('i32.and'), // stackLength: 1
cmd('if'), 0x40, // if -> void
cmd('i32.const'), ...SLEB128(0x6A), // opcode for `i32.add`
cmd('return'),
cmd('end'), // end [if]
//////////////////////////////////////////////////////////////////////////
/// mul //////////////////////////////////////////////////////////////////
cmd('i32.const'), 3, // stackLength: 1
cmd('local.get'), wordToCMDVars['wordLength'], // stackLength: 2
cmd('i32.eq'), // stackLength: 1
cmd('i32.const'), ...SLEB128('m'.charCodeAt(0)), // stackLength: 2
cmd('local.get'), wordToCMDVars['startWord'], // stackLength: 3
cmd('i32.load8_u'), 0, 0, // stackLength: 3
cmd('i32.eq'), // stackLength: 2
cmd('i32.and'), // stack length 1
cmd('i32.const'), ...SLEB128('u'.charCodeAt(0)), // stackLength: 2
cmd('local.get'), wordToCMDVars['startWord'], // stackLength: 3
cmd('i32.const'), 1, // stackLength: 4
cmd('i32.add'), // stackLength: 3
cmd('i32.load8_u'), 0, 0, // stackLength: 3
cmd('i32.eq'), // stackLength: 2
cmd('i32.and'), // stackLength: 1
cmd('i32.const'), ...SLEB128('l'.charCodeAt(0)), // stackLength: 2
cmd('local.get'), wordToCMDVars['startWord'], // stackLength: 3
cmd('i32.const'), 2, // stackLength: 4
cmd('i32.add'), // stackLength: 3
cmd('i32.load8_u'), 0, 0, // stackLength: 3
cmd('i32.eq'), // stackLength: 2
cmd('i32.and'), // stackLength: 1
cmd('if'), 0x40, // if -> void
cmd('i32.const'), ...SLEB128(0x6C), // opcode for `i32.mul`
cmd('return'),
cmd('end'), // end [if]
/// sub //////////////////////////////////////////////////////////////////
cmd('i32.const'), 3, // stackLength: 1
cmd('local.get'), wordToCMDVars['wordLength'], // stackLength: 2
cmd('i32.eq'), // stackLength: 1
cmd('i32.const'), ...SLEB128('s'.charCodeAt(0)), // stackLength: 2
cmd('local.get'), wordToCMDVars['startWord'], // stackLength: 3
cmd('i32.load8_u'), 0, 0, // stackLength: 3
cmd('i32.eq'), // stackLength: 2
cmd('i32.and'), // stack length 1
cmd('i32.const'), ...SLEB128('u'.charCodeAt(0)), // stackLength: 2
cmd('local.get'), wordToCMDVars['startWord'], // stackLength: 3
cmd('i32.const'), 1, // stackLength: 4
cmd('i32.add'), // stackLength: 3
cmd('i32.load8_u'), 0, 0, // stackLength: 3
cmd('i32.eq'), // stackLength: 2
cmd('i32.and'), // stackLength: 1
cmd('i32.const'), ...SLEB128('b'.charCodeAt(0)), // stackLength: 2
cmd('local.get'), wordToCMDVars['startWord'], // stackLength: 3
cmd('i32.const'), 2, // stackLength: 4
cmd('i32.add'), // stackLength: 3
cmd('i32.load8_u'), 0, 0, // stackLength: 3
cmd('i32.eq'), // stackLength: 2
cmd('i32.and'), // stackLength: 1
cmd('if'), 0x40, // if -> void
cmd('i32.const'), ...SLEB128(0x6B), // opcode for `i32.sub`
cmd('return'),
cmd('end'), // end [if]
/// and //////////////////////////////////////////////////////////////////
cmd('i32.const'), 3, // stackLength: 1
cmd('local.get'), wordToCMDVars['wordLength'], // stackLength: 2
cmd('i32.eq'), // stackLength: 1
cmd('i32.const'), ...SLEB128('a'.charCodeAt(0)), // stackLength: 2
cmd('local.get'), wordToCMDVars['startWord'], // stackLength: 3
cmd('i32.load8_u'), 0, 0, // stackLength: 3
cmd('i32.eq'), // stackLength: 2
cmd('i32.and'), // stack length 1
cmd('i32.const'), ...SLEB128('n'.charCodeAt(0)), // stackLength: 2
cmd('local.get'), wordToCMDVars['startWord'], // stackLength: 3
cmd('i32.const'), 1, // stackLength: 4
cmd('i32.add'), // stackLength: 3
cmd('i32.load8_u'), 0, 0, // stackLength: 3
cmd('i32.eq'), // stackLength: 2
cmd('i32.and'), // stackLength: 1
cmd('i32.const'), ...SLEB128('d'.charCodeAt(0)), // stackLength: 2
cmd('local.get'), wordToCMDVars['startWord'], // stackLength: 3
cmd('i32.const'), 2, // stackLength: 4
cmd('i32.add'), // stackLength: 3
cmd('i32.load8_u'), 0, 0, // stackLength: 3
cmd('i32.eq'), // stackLength: 2
cmd('i32.and'), // stackLength: 1
cmd('if'), 0x40, // if -> void
cmd('i32.const'), ...SLEB128(0x71), // opcode for `i32.and`
cmd('return'),
cmd('end'), // end [if]
/// or ///////////////////////////////////////////////////////////////////
cmd('i32.const'), 2, // stackLength: 1
cmd('local.get'), wordToCMDVars['wordLength'], // stackLength: 2
cmd('i32.eq'), // stackLength: 1
cmd('i32.const'), ...SLEB128('o'.charCodeAt(0)), // stackLength: 2
cmd('local.get'), wordToCMDVars['startWord'], // stackLength: 3
cmd('i32.load8_u'), 0, 0, // stackLength: 3
cmd('i32.eq'), // stackLength: 2
cmd('i32.and'), // stack length 1
cmd('i32.const'), ...SLEB128('r'.charCodeAt(0)), // stackLength: 2
cmd('local.get'), wordToCMDVars['startWord'], // stackLength: 3
cmd('i32.const'), 1, // stackLength: 4
cmd('i32.add'), // stackLength: 3
cmd('i32.load8_u'), 0, 0, // stackLength: 3
cmd('i32.eq'), // stackLength: 2
cmd('i32.and'), // stackLength: 1
cmd('if'), 0x40, // if -> void
cmd('i32.const'), ...SLEB128(0x72), // opcode for `i32.or`
cmd('return'),
cmd('end'), // end [if]
/// shr //////////////////////////////////////////////////////////////////
cmd('i32.const'), 3, // stackLength: 1
cmd('local.get'), wordToCMDVars['wordLength'], // stackLength: 2
cmd('i32.eq'), // stackLength: 1
cmd('i32.const'), ...SLEB128('s'.charCodeAt(0)), // stackLength: 2
cmd('local.get'), wordToCMDVars['startWord'], // stackLength: 3
cmd('i32.load8_u'), 0, 0, // stackLength: 3
cmd('i32.eq'), // stackLength: 2
cmd('i32.and'), // stack length 1
cmd('i32.const'), ...SLEB128('h'.charCodeAt(0)), // stackLength: 2
cmd('local.get'), wordToCMDVars['startWord'], // stackLength: 3
cmd('i32.const'), 1, // stackLength: 4
cmd('i32.add'), // stackLength: 3
cmd('i32.load8_u'), 0, 0, // stackLength: 3
cmd('i32.eq'), // stackLength: 2
cmd('i32.and'), // stackLength: 1
cmd('i32.const'), ...SLEB128('r'.charCodeAt(0)), // stackLength: 2
cmd('local.get'), wordToCMDVars['startWord'], // stackLength: 3
cmd('i32.const'), 2, // stackLength: 4
cmd('i32.add'), // stackLength: 3
cmd('i32.load8_u'), 0, 0, // stackLength: 3
cmd('i32.eq'), // stackLength: 2
cmd('i32.and'), // stackLength: 1
cmd('if'), 0x40, // if -> void
cmd('i32.const'), ...SLEB128(0x76), // opcode for `i32.shr_u`
cmd('return'),
cmd('end'), // end [if]
/// const ////////////////////////////////////////////////////////////////
cmd('i32.const'), 5, // stackLength: 1
cmd('local.get'), wordToCMDVars['wordLength'], // stackLength: 2
cmd('i32.eq'), // stackLength: 1
cmd('i32.const'), ...SLEB128('c'.charCodeAt(0)), // stackLength: 2
cmd('local.get'), wordToCMDVars['startWord'], // stackLength: 3
cmd('i32.load8_u'), 0, 0, // stackLength: 3
cmd('i32.eq'), // stackLength: 2
cmd('i32.and'), // stack length 1
cmd('i32.const'), ...SLEB128('o'.charCodeAt(0)), // stackLength: 2
cmd('local.get'), wordToCMDVars['startWord'], // stackLength: 3
cmd('i32.const'), 1, // stackLength: 4
cmd('i32.add'), // stackLength: 3
cmd('i32.load8_u'), 0, 0, // stackLength: 3
cmd('i32.eq'), // stackLength: 2
cmd('i32.and'), // stackLength: 1
cmd('i32.const'), ...SLEB128('n'.charCodeAt(0)), // stackLength: 2
cmd('local.get'), wordToCMDVars['startWord'], // stackLength: 3
cmd('i32.const'), 2, // stackLength: 4
cmd('i32.add'), // stackLength: 3
cmd('i32.load8_u'), 0, 0, // stackLength: 3
cmd('i32.eq'), // stackLength: 2
cmd('i32.and'), // stackLength: 1
cmd('i32.const'), ...SLEB128('s'.charCodeAt(0)), // stackLength: 2
cmd('local.get'), wordToCMDVars['startWord'], // stackLength: 3
cmd('i32.const'), 3, // stackLength: 4
cmd('i32.add'), // stackLength: 3
cmd('i32.load8_u'), 0, 0, // stackLength: 3
cmd('i32.eq'), // stackLength: 2
cmd('i32.and'), // stackLength: 1
cmd('i32.const'), ...SLEB128('t'.charCodeAt(0)), // stackLength: 2
cmd('local.get'), wordToCMDVars['startWord'], // stackLength: 3
cmd('i32.const'), 4, // stackLength: 4
cmd('i32.add'), // stackLength: 3
cmd('i32.load8_u'), 0, 0, // stackLength: 3
cmd('i32.eq'), // stackLength: 2
cmd('i32.and'), // stackLength: 1
cmd('if'), 0x40, // if -> void
cmd('i32.const'), ...SLEB128(0x41), // opcode for `i32.const`
cmd('return'),
cmd('end'), // end [if]
/// call /////////////////////////////////////////////////////////////////
cmd('i32.const'), 4, // stackLength: 1
cmd('local.get'), wordToCMDVars['wordLength'], // stackLength: 2
cmd('i32.eq'), // stackLength: 1
cmd('i32.const'), ...SLEB128('c'.charCodeAt(0)), // stackLength: 2
cmd('local.get'), wordToCMDVars['startWord'], // stackLength: 3
cmd('i32.load8_u'), 0, 0, // stackLength: 3
cmd('i32.eq'), // stackLength: 2
cmd('i32.and'), // stack length 1
cmd('i32.const'), ...SLEB128('a'.charCodeAt(0)), // stackLength: 2
cmd('local.get'), wordToCMDVars['startWord'], // stackLength: 3
cmd('i32.const'), 1, // stackLength: 4
cmd('i32.add'), // stackLength: 3
cmd('i32.load8_u'), 0, 0, // stackLength: 3
cmd('i32.eq'), // stackLength: 2
cmd('i32.and'), // stackLength: 1
cmd('i32.const'), ...SLEB128('l'.charCodeAt(0)), // stackLength: 2
cmd('local.get'), wordToCMDVars['startWord'], // stackLength: 3
cmd('i32.const'), 2, // stackLength: 4
cmd('i32.add'), // stackLength: 3
cmd('i32.load8_u'), 0, 0, // stackLength: 3
cmd('i32.eq'), // stackLength: 2
cmd('i32.and'), // stackLength: 1
cmd('i32.const'), ...SLEB128('l'.charCodeAt(0)), // stackLength: 2
cmd('local.get'), wordToCMDVars['startWord'], // stackLength: 3
cmd('i32.const'), 3, // stackLength: 4
cmd('i32.add'), // stackLength: 3
cmd('i32.load8_u'), 0, 0, // stackLength: 3
cmd('i32.eq'), // stackLength: 2
cmd('i32.and'), // stackLength: 1
cmd('if'), 0x40, // if -> void
cmd('i32.const'), ...SLEB128(0x10), // opcode for `call`
cmd('return'),
cmd('end'), // end [if]
/// set //////////////////////////////////////////////////////////////////
cmd('i32.const'), 3, // stackLength: 1
cmd('local.get'), wordToCMDVars['wordLength'], // stackLength: 2
cmd('i32.eq'), // stackLength: 1
cmd('i32.const'), ...SLEB128('s'.charCodeAt(0)), // stackLength: 2
cmd('local.get'), wordToCMDVars['startWord'], // stackLength: 3
cmd('i32.load8_u'), 0, 0, // stackLength: 3
cmd('i32.eq'), // stackLength: 2
cmd('i32.and'), // stack length 1
cmd('i32.const'), ...SLEB128('e'.charCodeAt(0)), // stackLength: 2
cmd('local.get'), wordToCMDVars['startWord'], // stackLength: 3
cmd('i32.const'), 1, // stackLength: 4
cmd('i32.add'), // stackLength: 3
cmd('i32.load8_u'), 0, 0, // stackLength: 3
cmd('i32.eq'), // stackLength: 2
cmd('i32.and'), // stackLength: 1
cmd('i32.const'), ...SLEB128('t'.charCodeAt(0)), // stackLength: 2
cmd('local.get'), wordToCMDVars['startWord'], // stackLength: 3
cmd('i32.const'), 2, // stackLength: 4
cmd('i32.add'), // stackLength: 3
cmd('i32.load8_u'), 0, 0, // stackLength: 3
cmd('i32.eq'), // stackLength: 2
cmd('i32.and'), // stackLength: 1
cmd('if'), 0x40, // if -> void
cmd('i32.const'), ...SLEB128(0x21), // opcode for `local.set`
cmd('return'),
cmd('end'), // end [if]
/// get //////////////////////////////////////////////////////////////////
cmd('i32.const'), 3, // stackLength: 1
cmd('local.get'), wordToCMDVars['wordLength'], // stackLength: 2
cmd('i32.eq'), // stackLength: 1
cmd('i32.const'), ...SLEB128('g'.charCodeAt(0)), // stackLength: 2
cmd('local.get'), wordToCMDVars['startWord'], // stackLength: 3
cmd('i32.load8_u'), 0, 0, // stackLength: 3
cmd('i32.eq'), // stackLength: 2
cmd('i32.and'), // stack length 1
cmd('i32.const'), ...SLEB128('e'.charCodeAt(0)), // stackLength: 2
cmd('local.get'), wordToCMDVars['startWord'], // stackLength: 3
cmd('i32.const'), 1, // stackLength: 4
cmd('i32.add'), // stackLength: 3
cmd('i32.load8_u'), 0, 0, // stackLength: 3
cmd('i32.eq'), // stackLength: 2
cmd('i32.and'), // stackLength: 1
cmd('i32.const'), ...SLEB128('t'.charCodeAt(0)), // stackLength: 2
cmd('local.get'), wordToCMDVars['startWord'], // stackLength: 3
cmd('i32.const'), 2, // stackLength: 4
cmd('i32.add'), // stackLength: 3
cmd('i32.load8_u'), 0, 0, // stackLength: 3
cmd('i32.eq'), // stackLength: 2
cmd('i32.and'), // stackLength: 1
cmd('if'), 0x40, // if -> void
cmd('i32.const'), ...SLEB128(0x20), // opcode for `local.get`
cmd('return'),
cmd('end'), // end [if]
/// load /////////////////////////////////////////////////////////////////
cmd('i32.const'), 4, // stackLength: 1
cmd('local.get'), wordToCMDVars['wordLength'], // stackLength: 2
cmd('i32.eq'), // stackLength: 1
cmd('i32.const'), ...SLEB128('l'.charCodeAt(0)), // stackLength: 2
cmd('local.get'), wordToCMDVars['startWord'], // stackLength: 3
cmd('i32.load8_u'), 0, 0, // stackLength: 3
cmd('i32.eq'), // stackLength: 2
cmd('i32.and'), // stack length 1
cmd('i32.const'), ...SLEB128('o'.charCodeAt(0)), // stackLength: 2
cmd('local.get'), wordToCMDVars['startWord'], // stackLength: 3
cmd('i32.const'), 1, // stackLength: 4
cmd('i32.add'), // stackLength: 3
cmd('i32.load8_u'), 0, 0, // stackLength: 3
cmd('i32.eq'), // stackLength: 2
cmd('i32.and'), // stackLength: 1
cmd('i32.const'), ...SLEB128('a'.charCodeAt(0)), // stackLength: 2
cmd('local.get'), wordToCMDVars['startWord'], // stackLength: 3
cmd('i32.const'), 2, // stackLength: 4
cmd('i32.add'), // stackLength: 3
cmd('i32.load8_u'), 0, 0, // stackLength: 3
cmd('i32.eq'), // stackLength: 2
cmd('i32.and'), // stackLength: 1
cmd('i32.const'), ...SLEB128('d'.charCodeAt(0)), // stackLength: 2
cmd('local.get'), wordToCMDVars['startWord'], // stackLength: 3
cmd('i32.const'), 3, // stackLength: 4
cmd('i32.add'), // stackLength: 3
cmd('i32.load8_u'), 0, 0, // stackLength: 3
cmd('i32.eq'), // stackLength: 2
cmd('i32.and'), // stackLength: 1
cmd('if'), 0x40, // if -> void
cmd('i32.const'), ...SLEB128(0x2D), // opcode for `load`
cmd('return'),
cmd('end'), // end [if]
/// if ///////////////////////////////////////////////////////////////////
cmd('i32.const'), 2, // stackLength: 1
cmd('local.get'), wordToCMDVars['wordLength'], // stackLength: 2
cmd('i32.eq'), // stackLength: 1
cmd('i32.const'), ...SLEB128('i'.charCodeAt(0)), // stackLength: 2
cmd('local.get'), wordToCMDVars['startWord'], // stackLength: 3
cmd('i32.load8_u'), 0, 0, // stackLength: 3
cmd('i32.eq'), // stackLength: 2
cmd('i32.and'), // stack length 1
cmd('i32.const'), ...SLEB128('f'.charCodeAt(0)), // stackLength: 2
cmd('local.get'), wordToCMDVars['startWord'], // stackLength: 3
cmd('i32.const'), 1, // stackLength: 4
cmd('i32.add'), // stackLength: 3
cmd('i32.load8_u'), 0, 0, // stackLength: 3
cmd('i32.eq'), // stackLength: 2
cmd('i32.and'), // stackLength: 1
cmd('if'), 0x40, // if -> void
cmd('i32.const'), ...SLEB128(0x04), // opcode for `if`
cmd('return'),
cmd('end'), // end [if]
/// else /////////////////////////////////////////////////////////////////
cmd('i32.const'), 4, // stackLength: 1
cmd('local.get'), wordToCMDVars['wordLength'], // stackLength: 2
cmd('i32.eq'), // stackLength: 1
cmd('i32.const'), ...SLEB128('e'.charCodeAt(0)), // stackLength: 2
cmd('local.get'), wordToCMDVars['startWord'], // stackLength: 3
cmd('i32.load8_u'), 0, 0, // stackLength: 3
cmd('i32.eq'), // stackLength: 2
cmd('i32.and'), // stack length 1
cmd('i32.const'), ...SLEB128('l'.charCodeAt(0)), // stackLength: 2
cmd('local.get'), wordToCMDVars['startWord'], // stackLength: 3
cmd('i32.const'), 1, // stackLength: 4
cmd('i32.add'), // stackLength: 3
cmd('i32.load8_u'), 0, 0, // stackLength: 3
cmd('i32.eq'), // stackLength: 2
cmd('i32.and'), // stackLength: 1
cmd('i32.const'), ...SLEB128('s'.charCodeAt(0)), // stackLength: 2
cmd('local.get'), wordToCMDVars['startWord'], // stackLength: 3
cmd('i32.const'), 2, // stackLength: 4
cmd('i32.add'), // stackLength: 3
cmd('i32.load8_u'), 0, 0, // stackLength: 3
cmd('i32.eq'), // stackLength: 2
cmd('i32.and'), // stackLength: 1
cmd('i32.const'), ...SLEB128('e'.charCodeAt(0)), // stackLength: 2
cmd('local.get'), wordToCMDVars['startWord'], // stackLength: 3
cmd('i32.const'), 3, // stackLength: 4
cmd('i32.add'), // stackLength: 3
cmd('i32.load8_u'), 0, 0, // stackLength: 3
cmd('i32.eq'), // stackLength: 2
cmd('i32.and'), // stackLength: 1
cmd('if'), 0x40, // if -> void
cmd('i32.const'), ...SLEB128(0x05), // opcode for `else`
cmd('return'),
cmd('end'), // end [if]
/// block ////////////////////////////////////////////////////////////////
cmd('i32.const'), 5, // stackLength: 1
cmd('local.get'), wordToCMDVars['wordLength'], // stackLength: 2
cmd('i32.eq'), // stackLength: 1
cmd('i32.const'), ...SLEB128('b'.charCodeAt(0)), // stackLength: 2
cmd('local.get'), wordToCMDVars['startWord'], // stackLength: 3
cmd('i32.load8_u'), 0, 0, // stackLength: 3
cmd('i32.eq'), // stackLength: 2
cmd('i32.and'), // stack length 1
cmd('i32.const'), ...SLEB128('l'.charCodeAt(0)), // stackLength: 2
cmd('local.get'), wordToCMDVars['startWord'], // stackLength: 3
cmd('i32.const'), 1, // stackLength: 4
cmd('i32.add'), // stackLength: 3
cmd('i32.load8_u'), 0, 0, // stackLength: 3
cmd('i32.eq'), // stackLength: 2
cmd('i32.and'), // stackLength: 1
cmd('i32.const'), ...SLEB128('o'.charCodeAt(0)), // stackLength: 2
cmd('local.get'), wordToCMDVars['startWord'], // stackLength: 3
cmd('i32.const'), 2, // stackLength: 4
cmd('i32.add'), // stackLength: 3
cmd('i32.load8_u'), 0, 0, // stackLength: 3
cmd('i32.eq'), // stackLength: 2
cmd('i32.and'), // stackLength: 1
cmd('i32.const'), ...SLEB128('c'.charCodeAt(0)), // stackLength: 2
cmd('local.get'), wordToCMDVars['startWord'], // stackLength: 3
cmd('i32.const'), 3, // stackLength: 4
cmd('i32.add'), // stackLength: 3
cmd('i32.load8_u'), 0, 0, // stackLength: 3
cmd('i32.eq'), // stackLength: 2
cmd('i32.and'), // stackLength: 1
cmd('i32.const'), ...SLEB128('k'.charCodeAt(0)), // stackLength: 2
cmd('local.get'), wordToCMDVars['startWord'], // stackLength: 3
cmd('i32.const'), 4, // stackLength: 4
cmd('i32.add'), // stackLength: 3
cmd('i32.load8_u'), 0, 0, // stackLength: 3
cmd('i32.eq'), // stackLength: 2
cmd('i32.and'), // stackLength: 1
cmd('if'), 0x40, // if -> void
cmd('i32.const'), ...SLEB128(0x02), // opcode for `block`
cmd('return'),
cmd('end'), // end [if]
/// loop /////////////////////////////////////////////////////////////////
cmd('i32.const'), 4, // stackLength: 1
cmd('local.get'), wordToCMDVars['wordLength'], // stackLength: 2
cmd('i32.eq'), // stackLength: 1
cmd('i32.const'), ...SLEB128('l'.charCodeAt(0)), // stackLength: 2
cmd('local.get'), wordToCMDVars['startWord'], // stackLength: 3
cmd('i32.load8_u'), 0, 0, // stackLength: 3
cmd('i32.eq'), // stackLength: 2
cmd('i32.and'), // stack length 1
cmd('i32.const'), ...SLEB128('o'.charCodeAt(0)), // stackLength: 2
cmd('local.get'), wordToCMDVars['startWord'], // stackLength: 3
cmd('i32.const'), 1, // stackLength: 4
cmd('i32.add'), // stackLength: 3
cmd('i32.load8_u'), 0, 0, // stackLength: 3
cmd('i32.eq'), // stackLength: 2
cmd('i32.and'), // stackLength: 1
cmd('i32.const'), ...SLEB128('o'.charCodeAt(0)), // stackLength: 2
cmd('local.get'), wordToCMDVars['startWord'], // stackLength: 3
cmd('i32.const'), 2, // stackLength: 4
cmd('i32.add'), // stackLength: 3
cmd('i32.load8_u'), 0, 0, // stackLength: 3
cmd('i32.eq'), // stackLength: 2
cmd('i32.and'), // stackLength: 1
cmd('i32.const'), ...SLEB128('p'.charCodeAt(0)), // stackLength: 2
cmd('local.get'), wordToCMDVars['startWord'], // stackLength: 3
cmd('i32.const'), 3, // stackLength: 4
cmd('i32.add'), // stackLength: 3
cmd('i32.load8_u'), 0, 0, // stackLength: 3
cmd('i32.eq'), // stackLength: 2
cmd('i32.and'), // stackLength: 1
cmd('if'), 0x40, // if -> void
cmd('i32.const'), ...SLEB128(0x03), // opcode for `loop`
cmd('return'),
cmd('end'), // end [if]
/// end //////////////////////////////////////////////////////////////////
cmd('i32.const'), 3, // stackLength: 1
cmd('local.get'), wordToCMDVars['wordLength'], // stackLength: 2
cmd('i32.eq'), // stackLength: 1
cmd('i32.const'), ...SLEB128('e'.charCodeAt(0)), // stackLength: 2
cmd('local.get'), wordToCMDVars['startWord'], // stackLength: 3
cmd('i32.load8_u'), 0, 0, // stackLength: 3
cmd('i32.eq'), // stackLength: 2
cmd('i32.and'), // stack length 1
cmd('i32.const'), ...SLEB128('n'.charCodeAt(0)), // stackLength: 2
cmd('local.get'), wordToCMDVars['startWord'], // stackLength: 3
cmd('i32.const'), 1, // stackLength: 4
cmd('i32.add'), // stackLength: 3
cmd('i32.load8_u'), 0, 0, // stackLength: 3
cmd('i32.eq'), // stackLength: 2
cmd('i32.and'), // stackLength: 1
cmd('i32.const'), ...SLEB128('d'.charCodeAt(0)), // stackLength: 2
cmd('local.get'), wordToCMDVars['startWord'], // stackLength: 3
cmd('i32.const'), 2, // stackLength: 4
cmd('i32.add'), // stackLength: 3
cmd('i32.load8_u'), 0, 0, // stackLength: 3
cmd('i32.eq'), // stackLength: 2
cmd('i32.and'), // stackLength: 1
cmd('if'), 0x40, // if -> void
cmd('i32.const'), ...SLEB128(0x0B), // opcode for `end`
cmd('return'),
cmd('end'), // end [if]
/// br ///////////////////////////////////////////////////////////////////
cmd('i32.const'), 2, // stackLength: 1
cmd('local.get'), wordToCMDVars['wordLength'], // stackLength: 2
cmd('i32.eq'), // stackLength: 1
cmd('i32.const'), ...SLEB128('b'.charCodeAt(0)), // stackLength: 2
cmd('local.get'), wordToCMDVars['startWord'], // stackLength: 3
cmd('i32.load8_u'), 0, 0, // stackLength: 3
cmd('i32.eq'), // stackLength: 2
cmd('i32.and'), // stack length 1
cmd('i32.const'), ...SLEB128('r'.charCodeAt(0)), // stackLength: 2
cmd('local.get'), wordToCMDVars['startWord'], // stackLength: 3
cmd('i32.const'), 1, // stackLength: 4
cmd('i32.add'), // stackLength: 3
cmd('i32.load8_u'), 0, 0, // stackLength: 3
cmd('i32.eq'), // stackLength: 2
cmd('i32.and'), // stackLength: 1
cmd('if'), 0x40, // if -> void
cmd('i32.const'), ...SLEB128(0xC4), // opcode for `br`
cmd('return'),
cmd('end'), // end [if]
/// br_if ////////////////////////////////////////////////////////////////
cmd('i32.const'), 5, // stackLength: 1
cmd('local.get'), wordToCMDVars['wordLength'], // stackLength: 2
cmd('i32.eq'), // stackLength: 1
cmd('i32.const'), ...SLEB128('b'.charCodeAt(0)), // stackLength: 2
cmd('local.get'), wordToCMDVars['startWord'], // stackLength: 3
cmd('i32.load8_u'), 0, 0, // stackLength: 3