wat4wasm 1.0.7 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -31,146 +31,27 @@
31
31
  (import "Reflect" "getOwnPropertyDescriptor" (func $self.Reflect.getOwnPropertyDescriptor<ext.ext>ext (param externref externref) (result externref)))
32
32
 
33
33
 
34
- (func $01-console.*
35
34
 
36
- (table.get $wat4wasm (i32.const 6));; hello world
37
35
 
38
- (call $self.console.log<ext>)
39
36
 
40
- (table.get $wat4wasm (i32.const 5));; bye bye world
41
- (i32.const -1)
42
- (call $self.console.log<ext.i32>)
43
37
 
44
- (table.get $wat4wasm (i32.const 16)) ;; $self.NaN<ext>
45
38
 
46
- (call $self.console.warn<ext>)
47
- )
48
39
 
49
- (func $02-array.*
50
40
 
51
- (call $self.Array.of<ext>ext
52
- (call $self.Reflect.apply<ext.ext.ext>ext
53
- (global.get $self.String.fromCharCode)
54
- (global.get $self)
55
- (call $self.Array.of<i32>ext (i32.const 55358)) ;; "🦋"
56
- )
57
- )
58
- (drop)
59
41
 
60
- (call $self.Array.isArray<ext>i32 (call $self.Array<>ext))
61
- (drop)
62
42
 
63
- (call $self.Array.fromAsync<ext>ext (call $self.Array<>ext))
64
- (drop)
65
- )
66
43
 
67
- (func $03-object.*
68
44
 
69
- (call $self.Object.is<ext.ext>i32 (ref.null extern) (table.get $wat4wasm (i32.const 17)) ;; $self.undefined<ext>
70
- )
71
- (drop)
72
-
73
- (call $self.Object.is<ext.f32>i32 (table.get $wat4wasm (i32.const 16)) ;; $self.NaN<ext>
74
- (f32.const nan))
75
- (drop)
76
45
 
77
- (call $self.Object.fromEntries<ext>ext (call $self.Array<>ext))
78
- (drop)
79
- )
80
46
 
81
- (func $04-reflect.*
82
-
83
- (call $self.Reflect.set<ext.ext.ext>i32
84
- (global.get $self) (table.get $wat4wasm (i32.const 1));; name
85
- (table.get $wat4wasm (i32.const 3));; test
86
-
87
- )
88
- (drop)
89
-
90
- (call $self.Reflect.get<ext.ext>ext
91
- (global.get $self) (table.get $wat4wasm (i32.const 1));; name
92
-
93
- )
94
- (drop)
95
47
 
96
- (call $self.Reflect.apply<ext.ext.ext>ext
97
- (table.get $wat4wasm (i32.const 10)) ;; $self.Math.floor<ext>
98
- (ref.null extern) (call $self.Array.of<f32>ext (f32.const 2.1))
99
- )
100
- (drop)
101
-
102
- (call $self.Reflect.construct<ext.ext>ext
103
- (table.get $wat4wasm (i32.const 9)) ;; $self.Object<ext>
104
- (call $self.Array<>ext)
105
- )
106
- (drop)
107
-
108
- (call $self.Reflect.ownKeys<ext>ext
109
- (table.get $wat4wasm (i32.const 8)) ;; $self.ArrayBuffer<ext>
110
-
111
- )
112
- (drop)
113
-
114
- (call $self.Reflect.getPrototypeOf<ext>ext
115
- (global.get $self)
116
- )
117
- (drop)
118
-
119
- (call $self.Reflect.getOwnPropertyDescriptor<ext.ext>ext
120
- (global.get $self) (table.get $wat4wasm (i32.const 1));; name
121
-
122
- )
123
- (drop)
124
- )
125
48
 
126
- (func $05-string.*
127
-
128
-
129
- (call $self.Reflect.apply<ext.ext.ext>ext
130
- (global.get $self.String.fromCharCode)
131
- (global.get $self)
132
- (global.get $self)
133
- )
134
-
135
- (drop)
136
- )
137
-
138
- (func $06-number.*
139
-
140
- (call $self.Number.isSafeInteger<i32>i32 (i32.const 47))
141
- (drop)
142
-
143
- (call $self.Number.isNaN<ext>i32 (global.get $self))
144
- (drop)
145
- )
146
-
147
- (func $07-math.*
148
-
149
- (call $self.Math.max<f32.f32>f32 (f32.const 47.2) (f32.const 42.7))
150
- (drop)
151
-
152
- (call $self.Math.random<>f32)
153
- (drop)
154
- )
155
-
156
- (func $08-url.*
157
-
158
- (call $self.URL.createObjectURL<ext>ext (call $self.Reflect.construct<ext.ext>ext
159
- (table.get $wat4wasm (i32.const 7)) ;; $self.MediaSource<ext>
160
-
161
- (call $self.Array.of<>ext)
162
- ))
163
- (drop)
164
-
165
- (call $self.URL.revokeObjectURL<ext> (ref.null extern))
166
- (nop)
167
- )
168
49
 
169
50
  (global $wat4wasm (mut externref) (ref.null extern))
170
51
 
171
- (table $wat4wasm 20 externref)
172
-
52
+ (table $wat4wasm 18 externref)
173
53
 
54
+ (elem $wat4wasm declare func)
174
55
 
175
56
 
176
57
  (func $wat4wasm
@@ -333,54 +214,6 @@
333
214
  (local.get $arguments) ;; name
334
215
  ))
335
216
  )
336
- (block $decodeText/4:4
337
- (local.set $viewAt (i32.const 0))
338
- (local.set $offset (i32.const 4))
339
- (local.set $length (i32.const 4))
340
- (local.set $arguments (call $self.Array<>ext))
341
-
342
- (call $self.Reflect.set<ext.i32.i32>
343
- (local.get $arguments) (i32.const 0) (local.get $length)
344
- )
345
- (local.set $arrayBufferView
346
- (call $self.Reflect.construct<ext.ext>ext
347
- (local.get $Uint8Array)
348
- (local.get $arguments)
349
- )
350
- )
351
- (loop $length--
352
- (if (local.get $length)
353
- (then
354
- (memory.init $wat4wasm
355
- (i32.const 0)
356
- (local.get $offset)
357
- (i32.const 1)
358
- )
359
- (call $self.Reflect.set<ext.i32.i32>
360
- (local.get $arrayBufferView)
361
- (local.get $viewAt)
362
- (i32.load8_u (i32.const 0))
363
- )
364
- (local.set $viewAt (i32.add (local.get $viewAt) (i32.const 1)))
365
- (local.set $offset (i32.add (local.get $offset) (i32.const 1)))
366
- (local.set $length (i32.sub (local.get $length) (i32.const 1)))
367
- (br $length--)
368
- )
369
- )
370
- )
371
- (local.set $arguments (call $self.Array<>ext))
372
- (call $self.Reflect.set<ext.i32.ext>
373
- (local.get $arguments)
374
- (i32.const 0)
375
- (local.get $arrayBufferView)
376
- )
377
- (table.set $wat4wasm (i32.const 2)
378
- (call $self.Reflect.apply<ext.ext.ext>ext
379
- (local.get $textDecoder.decode)
380
- (local.get $textDecoder)
381
- (local.get $arguments) ;; name
382
- ))
383
- )
384
217
  (block $decodeText/8:4
385
218
  (local.set $viewAt (i32.const 0))
386
219
  (local.set $offset (i32.const 8))
@@ -422,61 +255,13 @@
422
255
  (i32.const 0)
423
256
  (local.get $arrayBufferView)
424
257
  )
425
- (table.set $wat4wasm (i32.const 3)
258
+ (table.set $wat4wasm (i32.const 2)
426
259
  (call $self.Reflect.apply<ext.ext.ext>ext
427
260
  (local.get $textDecoder.decode)
428
261
  (local.get $textDecoder)
429
262
  (local.get $arguments) ;; test
430
263
  ))
431
264
  )
432
- (block $decodeText/4:4
433
- (local.set $viewAt (i32.const 0))
434
- (local.set $offset (i32.const 4))
435
- (local.set $length (i32.const 4))
436
- (local.set $arguments (call $self.Array<>ext))
437
-
438
- (call $self.Reflect.set<ext.i32.i32>
439
- (local.get $arguments) (i32.const 0) (local.get $length)
440
- )
441
- (local.set $arrayBufferView
442
- (call $self.Reflect.construct<ext.ext>ext
443
- (local.get $Uint8Array)
444
- (local.get $arguments)
445
- )
446
- )
447
- (loop $length--
448
- (if (local.get $length)
449
- (then
450
- (memory.init $wat4wasm
451
- (i32.const 0)
452
- (local.get $offset)
453
- (i32.const 1)
454
- )
455
- (call $self.Reflect.set<ext.i32.i32>
456
- (local.get $arrayBufferView)
457
- (local.get $viewAt)
458
- (i32.load8_u (i32.const 0))
459
- )
460
- (local.set $viewAt (i32.add (local.get $viewAt) (i32.const 1)))
461
- (local.set $offset (i32.add (local.get $offset) (i32.const 1)))
462
- (local.set $length (i32.sub (local.get $length) (i32.const 1)))
463
- (br $length--)
464
- )
465
- )
466
- )
467
- (local.set $arguments (call $self.Array<>ext))
468
- (call $self.Reflect.set<ext.i32.ext>
469
- (local.get $arguments)
470
- (i32.const 0)
471
- (local.get $arrayBufferView)
472
- )
473
- (table.set $wat4wasm (i32.const 4)
474
- (call $self.Reflect.apply<ext.ext.ext>ext
475
- (local.get $textDecoder.decode)
476
- (local.get $textDecoder)
477
- (local.get $arguments) ;; name
478
- ))
479
- )
480
265
  (block $decodeText/12:13
481
266
  (local.set $viewAt (i32.const 0))
482
267
  (local.set $offset (i32.const 12))
@@ -518,7 +303,7 @@
518
303
  (i32.const 0)
519
304
  (local.get $arrayBufferView)
520
305
  )
521
- (table.set $wat4wasm (i32.const 5)
306
+ (table.set $wat4wasm (i32.const 3)
522
307
  (call $self.Reflect.apply<ext.ext.ext>ext
523
308
  (local.get $textDecoder.decode)
524
309
  (local.get $textDecoder)
@@ -566,7 +351,7 @@
566
351
  (i32.const 0)
567
352
  (local.get $arrayBufferView)
568
353
  )
569
- (table.set $wat4wasm (i32.const 6)
354
+ (table.set $wat4wasm (i32.const 4)
570
355
  (call $self.Reflect.apply<ext.ext.ext>ext
571
356
  (local.get $textDecoder.decode)
572
357
  (local.get $textDecoder)
@@ -574,10 +359,10 @@
574
359
  ))
575
360
  )
576
361
 
577
- (block $decodeText/36:5
362
+ (block $decodeText/36:9
578
363
  (local.set $viewAt (i32.const 0))
579
364
  (local.set $offset (i32.const 36))
580
- (local.set $length (i32.const 5))
365
+ (local.set $length (i32.const 9))
581
366
  (local.set $arguments (call $self.Array<>ext))
582
367
 
583
368
  (call $self.Reflect.set<ext.i32.i32>
@@ -619,13 +404,13 @@
619
404
  (call $self.Reflect.apply<ext.ext.ext>ext
620
405
  (local.get $textDecoder.decode)
621
406
  (local.get $textDecoder)
622
- (local.get $arguments) ;; floor
407
+ (local.get $arguments) ;; undefined
623
408
  ))
624
409
  )
625
- (block $decodeText/41:4
410
+ (block $decodeText/45:3
626
411
  (local.set $viewAt (i32.const 0))
627
- (local.set $offset (i32.const 41))
628
- (local.set $length (i32.const 4))
412
+ (local.set $offset (i32.const 45))
413
+ (local.set $length (i32.const 3))
629
414
  (local.set $arguments (call $self.Array<>ext))
630
415
 
631
416
  (call $self.Reflect.set<ext.i32.i32>
@@ -667,13 +452,13 @@
667
452
  (call $self.Reflect.apply<ext.ext.ext>ext
668
453
  (local.get $textDecoder.decode)
669
454
  (local.get $textDecoder)
670
- (local.get $arguments) ;; Math
455
+ (local.get $arguments) ;; NaN
671
456
  ))
672
457
  )
673
- (block $decodeText/45:6
458
+ (block $decodeText/48:5
674
459
  (local.set $viewAt (i32.const 0))
675
- (local.set $offset (i32.const 45))
676
- (local.set $length (i32.const 6))
460
+ (local.set $offset (i32.const 48))
461
+ (local.set $length (i32.const 5))
677
462
  (local.set $arguments (call $self.Array<>ext))
678
463
 
679
464
  (call $self.Reflect.set<ext.i32.i32>
@@ -715,13 +500,13 @@
715
500
  (call $self.Reflect.apply<ext.ext.ext>ext
716
501
  (local.get $textDecoder.decode)
717
502
  (local.get $textDecoder)
718
- (local.get $arguments) ;; Object
503
+ (local.get $arguments) ;; floor
719
504
  ))
720
505
  )
721
- (block $decodeText/51:11
506
+ (block $decodeText/53:4
722
507
  (local.set $viewAt (i32.const 0))
723
- (local.set $offset (i32.const 51))
724
- (local.set $length (i32.const 11))
508
+ (local.set $offset (i32.const 53))
509
+ (local.set $length (i32.const 4))
725
510
  (local.set $arguments (call $self.Array<>ext))
726
511
 
727
512
  (call $self.Reflect.set<ext.i32.i32>
@@ -763,13 +548,13 @@
763
548
  (call $self.Reflect.apply<ext.ext.ext>ext
764
549
  (local.get $textDecoder.decode)
765
550
  (local.get $textDecoder)
766
- (local.get $arguments) ;; ArrayBuffer
551
+ (local.get $arguments) ;; Math
767
552
  ))
768
553
  )
769
- (block $decodeText/62:11
554
+ (block $decodeText/57:6
770
555
  (local.set $viewAt (i32.const 0))
771
- (local.set $offset (i32.const 62))
772
- (local.set $length (i32.const 11))
556
+ (local.set $offset (i32.const 57))
557
+ (local.set $length (i32.const 6))
773
558
  (local.set $arguments (call $self.Array<>ext))
774
559
 
775
560
  (call $self.Reflect.set<ext.i32.i32>
@@ -811,14 +596,13 @@
811
596
  (call $self.Reflect.apply<ext.ext.ext>ext
812
597
  (local.get $textDecoder.decode)
813
598
  (local.get $textDecoder)
814
- (local.get $arguments) ;; MediaSource
599
+ (local.get $arguments) ;; Object
815
600
  ))
816
601
  )
817
-
818
- (block $decodeText/73:9
602
+ (block $decodeText/63:11
819
603
  (local.set $viewAt (i32.const 0))
820
- (local.set $offset (i32.const 73))
821
- (local.set $length (i32.const 9))
604
+ (local.set $offset (i32.const 63))
605
+ (local.set $length (i32.const 11))
822
606
  (local.set $arguments (call $self.Array<>ext))
823
607
 
824
608
  (call $self.Reflect.set<ext.i32.i32>
@@ -856,17 +640,17 @@
856
640
  (i32.const 0)
857
641
  (local.get $arrayBufferView)
858
642
  )
859
- (table.set $wat4wasm (i32.const 18)
643
+ (table.set $wat4wasm (i32.const 16)
860
644
  (call $self.Reflect.apply<ext.ext.ext>ext
861
645
  (local.get $textDecoder.decode)
862
646
  (local.get $textDecoder)
863
- (local.get $arguments) ;; undefined
647
+ (local.get $arguments) ;; ArrayBuffer
864
648
  ))
865
649
  )
866
- (block $decodeText/82:3
650
+ (block $decodeText/74:11
867
651
  (local.set $viewAt (i32.const 0))
868
- (local.set $offset (i32.const 82))
869
- (local.set $length (i32.const 3))
652
+ (local.set $offset (i32.const 74))
653
+ (local.set $length (i32.const 11))
870
654
  (local.set $arguments (call $self.Array<>ext))
871
655
 
872
656
  (call $self.Reflect.set<ext.i32.i32>
@@ -904,11 +688,11 @@
904
688
  (i32.const 0)
905
689
  (local.get $arrayBufferView)
906
690
  )
907
- (table.set $wat4wasm (i32.const 19)
691
+ (table.set $wat4wasm (i32.const 17)
908
692
  (call $self.Reflect.apply<ext.ext.ext>ext
909
693
  (local.get $textDecoder.decode)
910
694
  (local.get $textDecoder)
911
- (local.get $arguments) ;; NaN
695
+ (local.get $arguments) ;; MediaSource
912
696
  ))
913
697
  )
914
698
  )
@@ -916,44 +700,44 @@
916
700
 
917
701
 
918
702
  (block $self.MediaSource<ext>
919
- (table.set $wat4wasm (i32.const 7)
703
+ (table.set $wat4wasm (i32.const 5)
920
704
  (call $self.Reflect.get<ext.ext>ext
921
705
  (global.get $self)
922
- (table.get $wat4wasm (i32.const 15));; MediaSource
706
+ (table.get $wat4wasm (i32.const 17));; MediaSource
923
707
  ;; MediaSource
924
708
  )
925
709
  ))
926
710
 
927
711
 
928
712
  (block $self.ArrayBuffer<ext>
929
- (table.set $wat4wasm (i32.const 8)
713
+ (table.set $wat4wasm (i32.const 6)
930
714
  (call $self.Reflect.get<ext.ext>ext
931
715
  (global.get $self)
932
- (table.get $wat4wasm (i32.const 14));; ArrayBuffer
716
+ (table.get $wat4wasm (i32.const 16));; ArrayBuffer
933
717
  ;; ArrayBuffer
934
718
  )
935
719
  ))
936
720
 
937
721
 
938
722
  (block $self.Object<ext>
939
- (table.set $wat4wasm (i32.const 9)
723
+ (table.set $wat4wasm (i32.const 7)
940
724
  (call $self.Reflect.get<ext.ext>ext
941
725
  (global.get $self)
942
- (table.get $wat4wasm (i32.const 13));; Object
726
+ (table.get $wat4wasm (i32.const 15));; Object
943
727
  ;; Object
944
728
  )
945
729
  ))
946
730
 
947
731
 
948
732
  (block $self.Math.floor<ext>
949
- (table.set $wat4wasm (i32.const 10)
733
+ (table.set $wat4wasm (i32.const 8)
950
734
  (call $self.Reflect.get<ext.ext>ext
951
735
  (call $self.Reflect.get<ext.ext>ext
952
736
  (global.get $self)
953
- (table.get $wat4wasm (i32.const 12));; Math
737
+ (table.get $wat4wasm (i32.const 14));; Math
954
738
  ;; Math
955
739
  )
956
- (table.get $wat4wasm (i32.const 11));; floor
740
+ (table.get $wat4wasm (i32.const 13));; floor
957
741
  ;; floor
958
742
  )
959
743
  ))
@@ -962,20 +746,20 @@
962
746
 
963
747
 
964
748
  (block $self.NaN<ext>
965
- (table.set $wat4wasm (i32.const 16)
749
+ (table.set $wat4wasm (i32.const 9)
966
750
  (call $self.Reflect.get<ext.ext>ext
967
751
  (global.get $self)
968
- (table.get $wat4wasm (i32.const 19));; NaN
752
+ (table.get $wat4wasm (i32.const 12));; NaN
969
753
  ;; NaN
970
754
  )
971
755
  ))
972
756
 
973
757
 
974
758
  (block $self.undefined<ext>
975
- (table.set $wat4wasm (i32.const 17)
759
+ (table.set $wat4wasm (i32.const 10)
976
760
  (call $self.Reflect.get<ext.ext>ext
977
761
  (global.get $self)
978
- (table.get $wat4wasm (i32.const 18));; undefined
762
+ (table.get $wat4wasm (i32.const 11));; undefined
979
763
  ;; undefined
980
764
  )
981
765
  ))
@@ -989,7 +773,9 @@
989
773
  )
990
774
 
991
775
 
992
- (data $wat4wasm "\55\00\00\00\6e\61\6d\65\74\65\73\74\62\79\65\20\62\79\65\20\77\6f\72\6c\64\68\65\6c\6c\6f\20\77\6f\72\6c\64\66\6c\6f\6f\72\4d\61\74\68\4f\62\6a\65\63\74\41\72\72\61\79\42\75\66\66\65\72\4d\65\64\69\61\53\6f\75\72\63\65\75\6e\64\65\66\69\6e\65\64\4e\61\4e")
776
+ (data $wat4wasm "\55\00\00\00\6e\61\6d\65\74\65\73\74\62\79\65\20\62\79\65\20\77\6f\72\6c\64\68\65\6c\6c\6f\20\77\6f\72\6c\64\75\6e\64\65\66\69\6e\65\64\4e\61\4e\66\6c\6f\6f\72\4d\61\74\68\4f\62\6a\65\63\74\41\72\72\61\79\42\75\66\66\65\72\4d\65\64\69\61\53\6f\75\72\63\65")
993
777
 
994
778
  (memory $wat4wasm 1)
779
+
780
+ (start $wat4wasm)
995
781
  )
@@ -94,7 +94,7 @@
94
94
 
95
95
  (table $wat4wasm 5 externref)
96
96
 
97
-
97
+ (elem $wat4wasm declare func)
98
98
 
99
99
 
100
100
  (func $wat4wasm
@@ -344,4 +344,6 @@
344
344
  (memory $wat4wasm 1)
345
345
 
346
346
 
347
+
348
+ (start $wat4wasm)
347
349
  )
@@ -0,0 +1,5 @@
1
+ export default function (wat) {
2
+ wat = wat.replaceAll("(malloc ", "(i32.atomic.rmw.add (i32.const 4) ")
3
+
4
+ return wat;
5
+ }
@@ -1 +1 @@
1
- <body onload="[WebAssembly.instantiate(Uint8Array.of(0,97,115,109,1,0,0,0,1,33,6,96,0,1,111,96,3,111,127,127,0,96,3,111,127,111,0,96,2,111,111,1,111,96,3,111,111,111,1,111,96,0,0,2,128,1,8,4,115,101,108,102,4,115,101,108,102,3,111,0,4,115,101,108,102,5,65,114,114,97,121,0,0,6,83,116,114,105,110,103,12,102,114,111,109,67,104,97,114,67,111,100,101,3,111,0,7,82,101,102,108,101,99,116,3,115,101,116,0,1,7,82,101,102,108,101,99,116,3,115,101,116,0,2,7,82,101,102,108,101,99,116,3,103,101,116,0,3,7,82,101,102,108,101,99,116,9,99,111,110,115,116,114,117,99,116,0,3,7,82,101,102,108,101,99,116,5,97,112,112,108,121,0,4,3,3,2,5,5,4,4,1,111,0,4,5,3,1,0,1,6,6,1,111,1,208,111,11,12,1,2,10,218,4,2,7,0,65,1,37,0,26,11,207,4,2,5,111,3,127,2,64,35,0,2,111,16,0,36,2,35,2,65,0,65,212,0,16,1,35,2,65,1,65,229,0,16,1,35,2,65,2,65,248,0,16,1,35,2,65,3,65,244,0,16,1,35,2,65,4,65,196,0,16,1,35,2,65,5,65,229,0,16,1,35,2,65,6,65,227,0,16,1,35,2,65,7,65,239,0,16,1,35,2,65,8,65,228,0,16,1,35,2,65,9,65,229,0,16,1,35,2,65,10,65,242,0,16,1,35,1,208,111,35,2,16,5,208,111,36,2,11,16,3,35,0,16,4,33,0,32,0,2,111,16,0,36,2,35,2,65,0,65,228,0,16,1,35,2,65,1,65,229,0,16,1,35,2,65,2,65,227,0,16,1,35,2,65,3,65,239,0,16,1,35,2,65,4,65,228,0,16,1,35,2,65,5,65,229,0,16,1,35,1,208,111,35,2,16,5,208,111,36,2,11,16,3,33,1,35,0,2,111,16,0,36,2,35,2,65,0,65,213,0,16,1,35,2,65,1,65,233,0,16,1,35,2,65,2,65,238,0,16,1,35,2,65,3,65,244,0,16,1,35,2,65,4,65,56,16,1,35,2,65,5,65,193,0,16,1,35,2,65,6,65,242,0,16,1,35,2,65,7,65,242,0,16,1,35,2,65,8,65,225,0,16,1,35,2,65,9,65,249,0,16,1,35,1,208,111,35,2,16,5,208,111,36,2,11,16,3,33,2,11,65,0,65,0,40,2,0,2,64,2,64,65,0,33,5,65,4,33,6,65,10,33,7,16,0,33,3,32,3,65,0,32,7,16,1,32,2,32,3,16,4,33,4,3,64,32,7,4,64,65,0,32,6,65,1,252,8,1,0,32,4,32,5,65,0,45,0,0,16,1,32,5,65,1,106,33,5,32,6,65,1,106,33,6,32,7,65,1,107,33,7,12,1,11,11,16,0,33,3,32,3,65,0,32,4,16,2,65,3,32,1,32,0,32,3,16,5,38,0,11,11,2,64,2,64,65,2,35,0,65,3,37,0,16,3,38,0,11,11,2,64,65,1,2,111,16,0,36,2,35,2,65,0,65,45,16,1,65,2,37,0,35,2,16,4,36,2,65,45,4,64,65,0,65,0,41,3,0,2,64,65,0,65,45,54,2,0,3,64,65,0,40,2,0,4,64,65,0,65,0,40,2,0,65,1,107,54,2,0,65,4,65,0,40,2,0,65,1,252,8,0,0,35,2,65,0,40,2,0,65,4,45,0,0,16,1,12,1,11,11,11,55,3,0,11,35,2,208,111,36,2,11,38,0,11,54,2,0,1,16,6,11,11,64,2,1,45,0,97,115,109,1,0,0,0,1,4,1,96,0,0,3,2,1,0,10,4,1,2,0,11,0,19,4,110,97,109,101,1,7,1,0,4,102,111,114,107,2,3,1,0,0,1,14,14,0,0,0,85,105,110,116,56,65,114,114,97,121,0,163,3,4,110,97,109,101,1,198,1,8,0,15,115,101,108,102,46,65,114,114,97,121,60,62,101,120,116,1,29,115,101,108,102,46,82,101,102,108,101,99,116,46,115,101,116,60,101,120,116,46,105,51,50,46,105,51,50,62,2,29,115,101,108,102,46,82,101,102,108,101,99,116,46,115,101,116,60,101,120,116,46,105,51,50,46,101,120,116,62,3,28,115,101,108,102,46,82,101,102,108,101,99,116,46,103,101,116,60,101,120,116,46,101,120,116,62,101,120,116,4,34,115,101,108,102,46,82,101,102,108,101,99,116,46,99,111,110,115,116,114,117,99,116,60,101,120,116,46,101,120,116,62,101,120,116,5,34,115,101,108,102,46,82,101,102,108,101,99,116,46,97,112,112,108,121,60,101,120,116,46,101,120,116,46,101,120,116,62,101,120,116,6,4,105,110,105,116,7,8,119,97,116,52,119,97,115,109,2,114,8,0,0,1,0,2,0,3,0,4,0,5,0,6,0,7,8,0,11,116,101,120,116,68,101,99,111,100,101,114,1,18,116,101,120,116,68,101,99,111,100,101,114,46,100,101,99,111,100,101,2,10,85,105,110,116,56,65,114,114,97,121,3,9,97,114,103,117,109,101,110,116,115,4,15,97,114,114,97,121,66,117,102,102,101,114,86,105,101,119,5,6,118,105,101,119,65,116,6,6,111,102,102,115,101,116,7,6,108,101,110,103,116,104,5,11,1,0,8,119,97,116,52,119,97,115,109,6,11,1,0,8,119,97,116,52,119,97,115,109,7,43,3,0,4,115,101,108,102,1,24,115,101,108,102,46,83,116,114,105,110,103,46,102,114,111,109,67,104,97,114,67,111,100,101,2,8,119,97,116,52,119,97,115,109,9,24,2,0,11,119,111,114,107,101,114,46,119,97,115,109,1,8,119,97,116,52,119,97,115,109), self).then(wasm => [console.warn(wasm)]),Reflect.set(document.head, String.fromCharCode(105,110,110,101,114,72,84,77,76), String.fromCharCode(60,108,105,110,107,32,114,101,108,61,105,99,111,110,32,104,114,101,102,61,100,97,116,97,58,110,117,108,108,62))]"></body>
1
+ <body onload="[WebAssembly.instantiate(Uint8Array.of(0,97,115,109,1,0,0,0,1,33,6,96,0,1,111,96,3,111,127,127,0,96,3,111,127,111,0,96,2,111,111,1,111,96,3,111,111,111,1,111,96,0,0,2,128,1,8,4,115,101,108,102,4,115,101,108,102,3,111,0,4,115,101,108,102,5,65,114,114,97,121,0,0,6,83,116,114,105,110,103,12,102,114,111,109,67,104,97,114,67,111,100,101,3,111,0,7,82,101,102,108,101,99,116,3,115,101,116,0,1,7,82,101,102,108,101,99,116,3,115,101,116,0,2,7,82,101,102,108,101,99,116,3,103,101,116,0,3,7,82,101,102,108,101,99,116,9,99,111,110,115,116,114,117,99,116,0,3,7,82,101,102,108,101,99,116,5,97,112,112,108,121,0,4,3,3,2,5,5,4,4,1,111,0,4,5,3,1,0,1,6,6,1,111,1,208,111,11,8,1,7,9,4,1,3,0,0,12,1,2,10,218,4,2,7,0,65,1,37,0,26,11,207,4,2,5,111,3,127,2,64,35,0,2,111,16,0,36,2,35,2,65,0,65,212,0,16,1,35,2,65,1,65,229,0,16,1,35,2,65,2,65,248,0,16,1,35,2,65,3,65,244,0,16,1,35,2,65,4,65,196,0,16,1,35,2,65,5,65,229,0,16,1,35,2,65,6,65,227,0,16,1,35,2,65,7,65,239,0,16,1,35,2,65,8,65,228,0,16,1,35,2,65,9,65,229,0,16,1,35,2,65,10,65,242,0,16,1,35,1,208,111,35,2,16,5,208,111,36,2,11,16,3,35,0,16,4,33,0,32,0,2,111,16,0,36,2,35,2,65,0,65,228,0,16,1,35,2,65,1,65,229,0,16,1,35,2,65,2,65,227,0,16,1,35,2,65,3,65,239,0,16,1,35,2,65,4,65,228,0,16,1,35,2,65,5,65,229,0,16,1,35,1,208,111,35,2,16,5,208,111,36,2,11,16,3,33,1,35,0,2,111,16,0,36,2,35,2,65,0,65,213,0,16,1,35,2,65,1,65,233,0,16,1,35,2,65,2,65,238,0,16,1,35,2,65,3,65,244,0,16,1,35,2,65,4,65,56,16,1,35,2,65,5,65,193,0,16,1,35,2,65,6,65,242,0,16,1,35,2,65,7,65,242,0,16,1,35,2,65,8,65,225,0,16,1,35,2,65,9,65,249,0,16,1,35,1,208,111,35,2,16,5,208,111,36,2,11,16,3,33,2,11,65,0,65,0,40,2,0,2,64,2,64,65,0,33,5,65,4,33,6,65,10,33,7,16,0,33,3,32,3,65,0,32,7,16,1,32,2,32,3,16,4,33,4,3,64,32,7,4,64,65,0,32,6,65,1,252,8,1,0,32,4,32,5,65,0,45,0,0,16,1,32,5,65,1,106,33,5,32,6,65,1,106,33,6,32,7,65,1,107,33,7,12,1,11,11,16,0,33,3,32,3,65,0,32,4,16,2,65,3,32,1,32,0,32,3,16,5,38,0,11,11,2,64,2,64,65,2,35,0,65,3,37,0,16,3,38,0,11,11,2,64,65,1,2,111,16,0,36,2,35,2,65,0,65,18,16,1,65,2,37,0,35,2,16,4,36,2,65,18,4,64,65,0,65,0,41,3,0,2,64,65,0,65,18,54,2,0,3,64,65,0,40,2,0,4,64,65,0,65,0,40,2,0,65,1,107,54,2,0,65,4,65,0,40,2,0,65,1,252,8,0,0,35,2,65,0,40,2,0,65,4,45,0,0,16,1,12,1,11,11,11,55,3,0,11,35,2,208,111,36,2,11,38,0,11,54,2,0,1,16,6,11,11,37,2,1,18,0,97,115,109,1,0,0,0,0,8,4,110,97,109,101,2,1,0,1,14,14,0,0,0,85,105,110,116,56,65,114,114,97,121,0,176,3,4,110,97,109,101,1,198,1,8,0,15,115,101,108,102,46,65,114,114,97,121,60,62,101,120,116,1,29,115,101,108,102,46,82,101,102,108,101,99,116,46,115,101,116,60,101,120,116,46,105,51,50,46,105,51,50,62,2,29,115,101,108,102,46,82,101,102,108,101,99,116,46,115,101,116,60,101,120,116,46,105,51,50,46,101,120,116,62,3,28,115,101,108,102,46,82,101,102,108,101,99,116,46,103,101,116,60,101,120,116,46,101,120,116,62,101,120,116,4,34,115,101,108,102,46,82,101,102,108,101,99,116,46,99,111,110,115,116,114,117,99,116,60,101,120,116,46,101,120,116,62,101,120,116,5,34,115,101,108,102,46,82,101,102,108,101,99,116,46,97,112,112,108,121,60,101,120,116,46,101,120,116,46,101,120,116,62,101,120,116,6,4,105,110,105,116,7,8,119,97,116,52,119,97,115,109,2,114,8,0,0,1,0,2,0,3,0,4,0,5,0,6,0,7,8,0,11,116,101,120,116,68,101,99,111,100,101,114,1,18,116,101,120,116,68,101,99,111,100,101,114,46,100,101,99,111,100,101,2,10,85,105,110,116,56,65,114,114,97,121,3,9,97,114,103,117,109,101,110,116,115,4,15,97,114,114,97,121,66,117,102,102,101,114,86,105,101,119,5,6,118,105,101,119,65,116,6,6,111,102,102,115,101,116,7,6,108,101,110,103,116,104,5,11,1,0,8,119,97,116,52,119,97,115,109,6,11,1,0,8,119,97,116,52,119,97,115,109,7,43,3,0,4,115,101,108,102,1,24,115,101,108,102,46,83,116,114,105,110,103,46,102,114,111,109,67,104,97,114,67,111,100,101,2,8,119,97,116,52,119,97,115,109,8,11,1,0,8,119,97,116,52,119,97,115,109,9,24,2,0,11,119,111,114,107,101,114,46,119,97,115,109,1,8,119,97,116,52,119,97,115,109), self).then(wasm => [console.warn(wasm)]),Reflect.set(document.head, String.fromCharCode(105,110,110,101,114,72,84,77,76), String.fromCharCode(60,108,105,110,107,32,114,101,108,61,105,99,111,110,32,104,114,101,102,61,100,97,116,97,58,110,117,108,108,62))]"></body>
@@ -1,60 +1,47 @@
1
1
  cd 01-text
2
- cp ../../wat4wasm wat4wasm
3
- ./wat4wasm --input=module.wat --output=module-output.wat
2
+ wat4wasm --input=module.wat --output=module-output.wat
4
3
  rm wat4wasm
5
4
  cd ..
6
5
 
7
6
  cd 02-include
8
- cp ../../wat4wasm wat4wasm
9
- ./wat4wasm --input=module.wat --output=module-output.wat
7
+ wat4wasm --input=module.wat --output=module-output.wat
10
8
  rm wat4wasm
11
9
  cd ..
12
10
 
13
11
  cd 03-ref.extern
14
- cp ../../wat4wasm wat4wasm
15
- ./wat4wasm --input=module.wat --output=module-output.wat
12
+ wat4wasm --input=module.wat --output=module-output.wat
16
13
  rm wat4wasm
17
14
  cd ..
18
15
 
19
16
  cd 04-ref.func
20
- cp ../../wat4wasm wat4wasm
21
- ./wat4wasm --input=module.wat --output=module-output.wat
17
+ wat4wasm --input=module.wat --output=module-output.wat
22
18
  rm wat4wasm
23
19
  cd ..
24
20
 
25
21
  cd 05-global.get
26
- cp ../../wat4wasm wat4wasm
27
- ./wat4wasm --input=module.wat --output=module-output.wat
22
+ wat4wasm --input=module.wat --output=module-output.wat
28
23
  rm wat4wasm
29
24
  cd ..
30
25
 
31
26
  cd 06-async
32
- cp ../../wat4wasm wat4wasm
33
- ./wat4wasm --input=module.wat --output=module-output.wat
27
+ wat4wasm --input=module.wat --output=module-output.wat
34
28
  rm wat4wasm
35
29
  cd ..
36
30
 
37
31
  cd 07-data
38
- cp ../../wat4wasm wat4wasm
39
- ./wat4wasm --input=module.wat --output=module-output.wat --wat2wasm=wat2wasm
32
+ wat4wasm --input=module.wat --output=module-output.wat --wat2wasm=wat2wasm
40
33
  rm wat4wasm
41
34
  cd ..
42
35
 
43
36
  cd 08-reflectors
44
- cp ../../wat4wasm wat4wasm
45
- ./wat4wasm --input=module.wat --output=module-output.wat
46
- rm wat4wasm
37
+ wat4wasm --input=module.wat --output=module-output.wat
47
38
  cd ..
48
39
 
49
40
  cd 09-replaceAll
50
- cp ../../wat4wasm wat4wasm
51
- ./wat4wasm --input=module.wat --output=module-output.wat
52
- rm wat4wasm
41
+ wat4wasm --input=module.wat --output=module-output.wat
53
42
  cd ..
54
43
 
55
44
 
56
45
  cd 99-complex
57
- cp ../../wat4wasm wat4wasm
58
- ./wat4wasm --input=module.wat --output=output.html --wat2wasm=wat2wasm --keep-window --keep-chrome-global --keep-document --wasm-from-numbers-array --log-instance --debug-names --enable-threads
59
- rm wat4wasm
46
+ wat4wasm --input=module.wat --output=output.html --wat2wasm=wat2wasm --keep-window --keep-chrome-global --keep-document --wasm-from-numbers-array --log-instance --debug-names --enable-threads --apply=apply_1.js
60
47
  cd ..
package/lib/cli.js CHANGED
@@ -25,6 +25,7 @@ export async function processCLI(compileCallback, PROCESS = process) {
25
25
  faviconLinkHref: "data:null",
26
26
  printOnly: false,
27
27
  passthroughArgs: [],
28
+ applyScripts: [],
28
29
  };
29
30
 
30
31
  for (let i = 0; i < args.length; i++) {
@@ -33,6 +34,8 @@ export async function processCLI(compileCallback, PROCESS = process) {
33
34
  config.outputFile = arg.split("=")[1];
34
35
  } else if (arg.startsWith("--input=")) {
35
36
  config.inputFile = arg.split("=")[1];
37
+ } else if (arg.startsWith("--apply=")) {
38
+ config.applyScripts.push(arg.split("=")[1]);
36
39
  } else if (arg.startsWith("--wat2wasm=")) {
37
40
  config.wat2wasmPath = arg.split("=")[1];
38
41
  } else if (arg.startsWith("--tag=")) {
@@ -80,6 +83,19 @@ export async function processCLI(compileCallback, PROCESS = process) {
80
83
  PROCESS.exit(1);
81
84
  }
82
85
 
86
+ config.inputDirectory = process
87
+ .cwd()
88
+ .replaceAll("file://", "")
89
+ .concat(config
90
+ .inputFile
91
+ .split("/")
92
+ .reverse().slice(1)
93
+ .reverse()
94
+ .join("/")
95
+ )
96
+ .concat("/")
97
+ .replaceAll("//", "/");
98
+
83
99
  const isJSTarget = config.outputFile?.endsWith(".js");
84
100
  const isHTMLTarget = config.outputFile?.endsWith(".html");
85
101
 
@@ -94,7 +110,6 @@ export async function processCLI(compileCallback, PROCESS = process) {
94
110
  config.outputFile = config.inputFile.replace(/\.wat$/, "-output.wat");
95
111
  }
96
112
 
97
-
98
113
  try {
99
114
  console.log(`\x1b[0m\x1b[33m🚀 Wat4Wasm: Processing ${config.inputFile}...\x1b[0m`);
100
115
  if (!fs.existsSync(config.inputFile)) {
@@ -104,7 +119,19 @@ export async function processCLI(compileCallback, PROCESS = process) {
104
119
  const rawCode = fs.readFileSync(config.inputFile, "utf8");
105
120
 
106
121
  // 2. Call the provided compile function
107
- const compiled = await compileCallback(rawCode);
122
+ let compiled = await compileCallback(rawCode);
123
+
124
+ let applyScript, applyCount = config.applyScripts.length;
125
+
126
+ while (applyScript = config.applyScripts[--applyCount]) {
127
+ const baseName = applyScript.split("/").pop().split(".").reverse().slice(1).reverse().join(".");
128
+ console.log(`\x1b[0m\x1b[34m🎸 apply call[\x1b[35m${applyCount}\x1b[0m] \x1b[32m-->\x1b[0m \x1b[35m${baseName}\x1b[0m(wat)\x1b[0m`);
129
+ const { default: applyFunction } = await import(
130
+ config.inputDirectory.concat(applyScript)
131
+ );
132
+ compiled = await applyFunction(compiled);
133
+ }
134
+
108
135
  console.log("\x1b[0m")
109
136
 
110
137
  // 3. Handle Output