-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
1279 lines (1161 loc) · 341 KB
/
index.html
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
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
<meta name="theme-color" content="#222"><meta name="generator" content="Hexo 6.3.0">
<link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
<link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
<link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
<link rel="mask-icon" href="/images/logo.svg" color="#222">
<link rel="stylesheet" href="/css/main.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" integrity="sha256-HtsXJanqjKTc8vVQjO4YMhiqFoXkfBsjBWcX91T1jr8=" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.1.1/animate.min.css" integrity="sha256-PR7ttpcvz8qrF57fur/yAx1qXMFJeJFiA6pSzWi0OIE=" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/fancybox/3.5.7/jquery.fancybox.min.css" integrity="sha256-Vzbj7sDDS/woiFS3uNKo8eIuni59rjyNGtXfstRzStA=" crossorigin="anonymous">
<script class="next-config" data-name="main" type="application/json">{"hostname":"c0mm4nd.com","root":"/","images":"/images","scheme":"Muse","darkmode":false,"version":"8.17.0","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":true,"style":null,"show_result":false},"bookmark":{"enable":true,"color":"#222","save":"auto"},"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":true,"nav":null},"stickytabs":false,"motion":{"enable":true,"async":false,"transition":{"menu_item":"fadeInDown","post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},"prism":false,"i18n":{"placeholder":"Searching...","empty":"We didn't find any results for the search: ${query}","hits_time":"${hits} results found in ${time} ms","hits":"${hits} results found"},"path":"/search.xml","localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false}}</script><script src="/js/config.js"></script>
<meta name="description" content="细枝末节略,无关内容略。">
<meta property="og:type" content="article">
<meta property="og:title" content="WebAssembly核心标准:WebAssembly Core Specification">
<meta property="og:url" content="https://c0mm4nd.com/wasm-core-1/index.html">
<meta property="og:site_name" content="Talkless">
<meta property="og:description" content="细枝末节略,无关内容略。">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2020-09-21T17:06:31.000Z">
<meta property="article:modified_time" content="2021-10-11T09:21:36.000Z">
<meta property="article:author" content="Command M">
<meta property="article:tag" content="wasm">
<meta property="article:tag" content="todo">
<meta property="article:tag" content="specification">
<meta name="twitter:card" content="summary">
<link rel="canonical" href="https://c0mm4nd.com/wasm-core-1/">
<script class="next-config" data-name="page" type="application/json">{"sidebar":"","isHome":false,"isPost":true,"lang":"zh-CN","comments":true,"permalink":"https://c0mm4nd.com/wasm-core-1/","path":"/wasm-core-1/","title":"WebAssembly核心标准:WebAssembly Core Specification"}</script>
<script class="next-config" data-name="calendar" type="application/json">""</script>
<title>WebAssembly核心标准:WebAssembly Core Specification | Talkless</title>
<script async src="https://www.googletagmanager.com/gtag/js?id=G-70Z2TEBDS4"></script>
<script class="next-config" data-name="google_analytics" type="application/json">{"tracking_id":"G-70Z2TEBDS4","only_pageview":false}</script>
<script src="/js/third-party/analytics/google-analytics.js"></script>
<noscript>
<link rel="stylesheet" href="/css/noscript.css">
</noscript>
</head>
<body itemscope itemtype="http://schema.org/WebPage" class="use-motion">
<div class="headband"></div>
<main class="main">
<div class="column">
<header class="header" itemscope itemtype="http://schema.org/WPHeader"><div class="site-brand-container">
<div class="site-nav-toggle">
<div class="toggle" aria-label="切换导航栏" role="button">
<span class="toggle-line"></span>
<span class="toggle-line"></span>
<span class="toggle-line"></span>
</div>
</div>
<div class="site-meta">
<a href="/" class="brand" rel="start">
<i class="logo-line"></i>
<p class="site-title">Talkless</p>
<i class="logo-line"></i>
</a>
</div>
<div class="site-nav-right">
<div class="toggle popup-trigger" aria-label="搜索" role="button">
<i class="fa fa-search fa-fw fa-lg"></i>
</div>
</div>
</div>
<nav class="site-nav">
<ul class="main-menu menu"><li class="menu-item menu-item-home"><a href="/" rel="section"><i class="fa fa-home fa-fw"></i>Home</a></li><li class="menu-item menu-item-about"><a href="https://github.com/c0mm4nd" rel="section" target="_blank"><i class="fa fa-user fa-fw"></i>About</a></li><li class="menu-item menu-item-tags"><a href="/tags/" rel="section"><i class="fa fa-tags fa-fw"></i>Tags<span class="badge">77</span></a></li><li class="menu-item menu-item-archives"><a href="/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>Archives<span class="badge">74</span></a></li>
<li class="menu-item menu-item-search">
<a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>Search
</a>
</li>
</ul>
</nav>
<div class="search-pop-overlay">
<div class="popup search-popup"><div class="search-header">
<span class="search-icon">
<i class="fa fa-search"></i>
</span>
<div class="search-input-container">
<input autocomplete="off" autocapitalize="off" maxlength="80"
placeholder="Searching..." spellcheck="false"
type="search" class="search-input">
</div>
<span class="popup-btn-close" role="button">
<i class="fa fa-times-circle"></i>
</span>
</div>
<div class="search-result-container no-result">
<div class="search-result-icon">
<i class="fa fa-spinner fa-pulse fa-5x"></i>
</div>
</div>
</div>
</div>
</header>
<aside class="sidebar">
<div class="sidebar-inner sidebar-nav-active sidebar-toc-active">
<ul class="sidebar-nav">
<li class="sidebar-nav-toc">
文章目录
</li>
<li class="sidebar-nav-overview">
站点概览
</li>
</ul>
<div class="sidebar-panel-container">
<!--noindex-->
<div class="post-toc-wrap sidebar-panel">
<div class="post-toc animated"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#%E7%AE%80%E4%BB%8B"><span class="nav-number">1.</span> <span class="nav-text"> 简介</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#1-%E5%BC%95%E8%A8%80"><span class="nav-number">2.</span> <span class="nav-text"> 1. 引言</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#11-%E5%BC%95%E8%A8%80"><span class="nav-number">2.1.</span> <span class="nav-text"> 1.1. 引言</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#111-%E8%AE%BE%E8%AE%A1%E7%9B%AE%E6%A0%87"><span class="nav-number">2.1.1.</span> <span class="nav-text"> 1.1.1. 设计目标</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#112-%E4%BD%9C%E7%94%A8%E5%9F%9F"><span class="nav-number">2.1.2.</span> <span class="nav-text"> 1.1.2. 作用域</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#12-%E5%AE%89%E5%85%A8%E6%80%A7%E8%80%83%E9%87%8F"><span class="nav-number">2.2.</span> <span class="nav-text"> 1.2. 安全性考量</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#121-%E4%BE%9D%E8%B5%96"><span class="nav-number">2.2.1.</span> <span class="nav-text"> 1.2.1. 依赖</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#13-%E6%A6%82%E8%A7%88"><span class="nav-number">2.3.</span> <span class="nav-text"> 1.3. 概览</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#131-%E6%A6%82%E5%BF%B5"><span class="nav-number">2.3.1.</span> <span class="nav-text"> 1.3.1 概念</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#132-%E8%AF%AD%E4%B9%89%E8%A7%A3%E6%9E%90"><span class="nav-number">2.3.2.</span> <span class="nav-text"> 1.3.2. 语义解析</span></a></li></ol></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-%E6%9E%B6%E6%9E%84"><span class="nav-number">3.</span> <span class="nav-text"> 2. 架构</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#21-%E8%A7%84%E5%AE%9A"><span class="nav-number">3.1.</span> <span class="nav-text"> 2.1. 规定</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#211-%E8%AF%AD%E6%B3%95%E7%AC%A6%E5%8F%B7"><span class="nav-number">3.1.1.</span> <span class="nav-text"> 2.1.1. 语法符号</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#212-%E8%BE%85%E5%8A%A9%E7%AC%A6%E5%8F%B7"><span class="nav-number">3.1.2.</span> <span class="nav-text"> 2.1.2. 辅助符号</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#213-%E5%90%91%E9%87%8F"><span class="nav-number">3.1.3.</span> <span class="nav-text"> 2.1.3. 向量</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#22-%E5%80%BC"><span class="nav-number">3.2.</span> <span class="nav-text"> 2.2. 值</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#221-bytes"><span class="nav-number">3.2.1.</span> <span class="nav-text"> 2.2.1. Bytes</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#2211-%E6%83%AF%E4%BE%8B"><span class="nav-number">3.2.1.1.</span> <span class="nav-text"> 2.2.1.1. 惯例</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#2221-%E6%83%AF%E4%BE%8B"><span class="nav-number">3.2.1.2.</span> <span class="nav-text"> 2.2.2.1. 惯例</span></a></li></ol></li><li class="nav-item nav-level-4"><a class="nav-link" href="#223-%E6%B5%AE%E7%82%B9%E6%95%B0"><span class="nav-number">3.2.2.</span> <span class="nav-text"> 2.2.3. 浮点数</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#2231-%E6%83%AF%E4%BE%8B"><span class="nav-number">3.2.2.1.</span> <span class="nav-text"> 2.2.3.1. 惯例</span></a></li></ol></li><li class="nav-item nav-level-4"><a class="nav-link" href="#224-%E5%90%8D%E7%A7%B0names"><span class="nav-number">3.2.3.</span> <span class="nav-text"> 2.2.4. 名称Names</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#2241-%E6%83%AF%E4%BE%8B"><span class="nav-number">3.2.3.1.</span> <span class="nav-text"> 2.2.4.1. 惯例</span></a></li></ol></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#23-%E7%B1%BB%E5%9E%8Btypes"><span class="nav-number">3.3.</span> <span class="nav-text"> 2.3 类型Types</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#231-%E5%80%BCvalue%E7%B1%BB%E5%9E%8B"><span class="nav-number">3.3.1.</span> <span class="nav-text"> 2.3.1 值(Value)类型</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#2331-%E6%83%AF%E4%BE%8B"><span class="nav-number">3.3.1.1.</span> <span class="nav-text"> 2.3.3.1. 惯例</span></a></li></ol></li><li class="nav-item nav-level-4"><a class="nav-link" href="#232-%E7%BB%93%E6%9E%9Cresult%E7%B1%BB%E5%9E%8B"><span class="nav-number">3.3.2.</span> <span class="nav-text"> 2.3.2. 结果(Result)类型</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#233-%E5%87%BD%E6%95%B0function%E7%B1%BB%E5%9E%8B"><span class="nav-number">3.3.3.</span> <span class="nav-text"> 2.3.3 函数(Function)类型</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#234-%E9%99%90%E5%88%B6"><span class="nav-number">3.3.4.</span> <span class="nav-text"> 2.3.4. 限制</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#235-%E5%86%85%E5%AD%98memories%E7%B1%BB%E5%9E%8B"><span class="nav-number">3.3.5.</span> <span class="nav-text"> 2.3.5. 内存(Memories)类型</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#236-%E8%A1%A8%E6%A0%BC%E7%B1%BB%E5%9E%8B"><span class="nav-number">3.3.6.</span> <span class="nav-text"> 2.3.6. 表格类型</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#237-%E5%85%A8%E5%B1%80%E5%8F%98%E9%87%8F%E7%B1%BB%E5%9E%8B"><span class="nav-number">3.3.7.</span> <span class="nav-text"> 2.3.7. 全局变量类型</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#2381-%E6%83%AF%E4%BE%8B"><span class="nav-number">3.3.7.1.</span> <span class="nav-text"> 2.3.8.1 惯例</span></a></li></ol></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#24-%E6%8C%87%E4%BB%A4instructions"><span class="nav-number">3.4.</span> <span class="nav-text"> 2.4. 指令Instructions</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#241-%E6%95%B0%E5%80%BC%E6%8C%87%E4%BB%A4"><span class="nav-number">3.4.1.</span> <span class="nav-text"> 2.4.1. 数值指令</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#2411-%E6%83%AF%E4%BE%8B"><span class="nav-number">3.4.1.1.</span> <span class="nav-text"> 2.4.1.1. 惯例</span></a></li></ol></li><li class="nav-item nav-level-4"><a class="nav-link" href="#242-%E5%8F%82%E6%95%B0%E6%8C%87%E4%BB%A4"><span class="nav-number">3.4.2.</span> <span class="nav-text"> 2.4.2. 参数指令</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#243-%E5%8F%98%E9%87%8F%E6%8C%87%E4%BB%A4"><span class="nav-number">3.4.3.</span> <span class="nav-text"> 2.4.3. 变量指令</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#244-%E5%86%85%E5%AD%98%E6%8C%87%E4%BB%A4"><span class="nav-number">3.4.4.</span> <span class="nav-text"> 2.4.4. 内存指令</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#245-%E6%8E%A7%E5%88%B6%E6%8C%87%E4%BB%A4"><span class="nav-number">3.4.5.</span> <span class="nav-text"> 2.4.5. 控制指令</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#246-%E8%A1%A8%E8%BE%BE%E5%BC%8Fexpression"><span class="nav-number">3.4.6.</span> <span class="nav-text"> 2.4.6. 表达式Expression</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#25-%E6%A8%A1%E5%9D%97-modules"><span class="nav-number">3.5.</span> <span class="nav-text"> 2.5 模块 Modules</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#251-%E7%B4%A2%E5%BC%95"><span class="nav-number">3.5.1.</span> <span class="nav-text"> 2.5.1. 索引</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#2511-%E6%83%AF%E4%BE%8B"><span class="nav-number">3.5.1.1.</span> <span class="nav-text"> 2.5.1.1. 惯例</span></a></li></ol></li><li class="nav-item nav-level-4"><a class="nav-link" href="#252-%E7%B1%BB%E5%9E%8B"><span class="nav-number">3.5.2.</span> <span class="nav-text"> 2.5.2. 类型</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#253-%E5%87%BD%E6%95%B0"><span class="nav-number">3.5.3.</span> <span class="nav-text"> 2.5.3. 函数</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#254-%E8%A1%A8"><span class="nav-number">3.5.4.</span> <span class="nav-text"> 2.5.4. 表</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#255-%E5%86%85%E5%AD%98"><span class="nav-number">3.5.5.</span> <span class="nav-text"> 2.5.5. 内存</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#256-%E5%85%A8%E5%B1%80%E5%8F%98%E9%87%8Fglobals"><span class="nav-number">3.5.6.</span> <span class="nav-text"> 2.5.6. 全局变量Globals</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#257-%E5%85%83%E7%B4%A0%E6%AE%B5-element-segments"><span class="nav-number">3.5.7.</span> <span class="nav-text"> 2.5.7. 元素段 Element Segments</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#258-%E6%95%B0%E6%8D%AE%E6%AE%B5-data-segments"><span class="nav-number">3.5.8.</span> <span class="nav-text"> 2.5.8. 数据段 Data Segments</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#259-%E5%90%AF%E5%8A%A8%E5%87%BD%E6%95%B0-start-function"><span class="nav-number">3.5.9.</span> <span class="nav-text"> 2.5.9. 启动函数 Start Function</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#2510-%E5%AF%BC%E5%87%BA-exports"><span class="nav-number">3.5.10.</span> <span class="nav-text"> 2.5.10. 导出 exports</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#25101-%E6%83%AF%E4%BE%8B"><span class="nav-number">3.5.10.1.</span> <span class="nav-text"> 2.5.10.1. 惯例</span></a></li></ol></li><li class="nav-item nav-level-4"><a class="nav-link" href="#2511-%E5%AF%BC%E5%85%A5-imports"><span class="nav-number">3.5.11.</span> <span class="nav-text"> 2.5.11. 导入 imports</span></a></li></ol></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3-%E9%AA%8C%E8%AF%81"><span class="nav-number">4.</span> <span class="nav-text"> 3. 验证</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#31-%E6%83%AF%E4%BE%8B"><span class="nav-number">4.1.</span> <span class="nav-text"> 3.1. 惯例</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#311-%E4%B8%8A%E4%B8%8B%E6%96%87"><span class="nav-number">4.1.1.</span> <span class="nav-text"> 3.1.1. 上下文</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#312-%E8%A1%8C%E6%96%87%E7%AC%A6%E5%8F%B7"><span class="nav-number">4.1.2.</span> <span class="nav-text"> 3.1.2. 行文符号</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#313-%E6%AD%A3%E5%BC%8F%E7%AC%A6%E5%8F%B7"><span class="nav-number">4.1.3.</span> <span class="nav-text"> 3.1.3. 正式符号</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#32-%E7%B1%BB%E5%9E%8B"><span class="nav-number">4.2.</span> <span class="nav-text"> 3.2. 类型</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#321-%E9%99%90%E5%88%B6limits"><span class="nav-number">4.2.1.</span> <span class="nav-text"> 3.2.1. 限制Limits</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#3211-min-n-max-m"><span class="nav-number">4.2.1.1.</span> <span class="nav-text"> 3.2.1.1. {min n,max m?}\{min\ n, max\ m^?\}{min n,max m?}</span></a></li></ol></li><li class="nav-item nav-level-4"><a class="nav-link" href="#322-%E5%87%BD%E6%95%B0%E7%B1%BB%E5%9E%8B"><span class="nav-number">4.2.2.</span> <span class="nav-text"> 3.2.2. 函数类型</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#3221-t_1n-to-t_2m"><span class="nav-number">4.2.2.1.</span> <span class="nav-text"> 3.2.2.1. [t1n]→[t2m][t_1^n] \to [t_2^m][t1n]→[t2m]</span></a></li></ol></li><li class="nav-item nav-level-4"><a class="nav-link" href="#323-%E8%A1%A8%E7%B1%BB%E5%9E%8B"><span class="nav-number">4.2.3.</span> <span class="nav-text"> 3.2.3. 表类型</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#3231-%E5%85%83%E7%B4%A0%E7%B1%BB%E5%9E%8B%E9%99%90%E5%88%B6"><span class="nav-number">4.2.3.1.</span> <span class="nav-text"> 3.2.3.1. 元素类型:限制</span></a></li></ol></li><li class="nav-item nav-level-4"><a class="nav-link" href="#324-%E5%86%85%E5%AD%98%E7%B1%BB%E5%9E%8B"><span class="nav-number">4.2.4.</span> <span class="nav-text"> 3.2.4. 内存类型</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#3241-%E9%99%90%E5%88%B6"><span class="nav-number">4.2.4.1.</span> <span class="nav-text"> 3.2.4.1. 限制</span></a></li></ol></li><li class="nav-item nav-level-4"><a class="nav-link" href="#325-%E5%85%A8%E5%B1%80%E7%B1%BB%E5%9E%8B"><span class="nav-number">4.2.5.</span> <span class="nav-text"> 3.2.5. 全局类型</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#3251-%E5%8F%AF%E5%8F%98%E5%80%BC%E7%B1%BB%E5%9E%8B"><span class="nav-number">4.2.5.1.</span> <span class="nav-text"> 3.2.5.1. 可变值类型</span></a></li></ol></li><li class="nav-item nav-level-4"><a class="nav-link" href="#326-%E5%A4%96%E9%83%A8%E7%B1%BB%E5%9E%8B"><span class="nav-number">4.2.6.</span> <span class="nav-text"> 3.2.6. 外部类型</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#3261-%E5%87%BD%E6%95%B0%E7%B1%BB%E5%9E%8B-func"><span class="nav-number">4.2.6.1.</span> <span class="nav-text"> 3.2.6.1. 函数类型 func</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#3262-%E8%A1%A8%E7%B1%BB%E5%9E%8B-table"><span class="nav-number">4.2.6.2.</span> <span class="nav-text"> 3.2.6.2. 表类型 table</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#3263-%E5%86%85%E5%AD%98%E7%B1%BB%E5%9E%8B-mem"><span class="nav-number">4.2.6.3.</span> <span class="nav-text"> 3.2.6.3. 内存类型 mem</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#3264-%E5%85%A8%E5%B1%80%E7%B1%BB%E5%9E%8B-global"><span class="nav-number">4.2.6.4.</span> <span class="nav-text"> 3.2.6.4. 全局类型 global</span></a></li></ol></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#33-%E6%8C%87%E4%BB%A4"><span class="nav-number">4.3.</span> <span class="nav-text"> 3.3. 指令</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#4-%E6%89%A7%E8%A1%8C"><span class="nav-number">5.</span> <span class="nav-text"> 4. 执行</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#5-%E4%BA%8C%E8%BF%9B%E5%88%B6%E6%A0%BC%E5%BC%8F"><span class="nav-number">6.</span> <span class="nav-text"> 5. 二进制格式</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#6-%E6%96%87%E6%9C%AC%E6%A0%BC%E5%BC%8F"><span class="nav-number">7.</span> <span class="nav-text"> 6. 文本格式</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#a-%E9%99%84%E5%BD%95"><span class="nav-number">8.</span> <span class="nav-text"> A. 附录</span></a></li></ol></div>
</div>
<!--/noindex-->
<div class="site-overview-wrap sidebar-panel">
<div class="site-author animated" itemprop="author" itemscope itemtype="http://schema.org/Person">
<p class="site-author-name" itemprop="name">Command M</p>
<div class="site-description" itemprop="description"></div>
</div>
<div class="site-state-wrap animated">
<nav class="site-state">
<div class="site-state-item site-state-posts">
<a href="/archives/">
<span class="site-state-item-count">74</span>
<span class="site-state-item-name">posts</span>
</a>
</div>
<div class="site-state-item site-state-tags">
<a href="/tags/">
<span class="site-state-item-count">77</span>
<span class="site-state-item-name">tags</span></a>
</div>
</nav>
</div>
<div class="links-of-author animated">
<span class="links-of-author-item">
<a href="https://github.com/c0mm4nd" title="GitHub → https://github.com/c0mm4nd" rel="noopener me" target="_blank"><i class="fab fa-github fa-fw"></i>GitHub</a>
</span>
<span class="links-of-author-item">
<a href="mailto:[email protected]" title="E-Mail → mailto:[email protected]" rel="noopener me"><i class="fa fa-envelope fa-fw"></i>E-Mail</a>
</span>
<span class="links-of-author-item">
<a href="https://twitter.com/k0mm4nd" title="Twitter → https://twitter.com/k0mm4nd" rel="noopener me" target="_blank"><i class="fab fa-twitter fa-fw"></i>Twitter</a>
</span>
</div>
</div>
</div>
</div>
<div class="sidebar-inner sidebar-blogroll">
<div class="links-of-blogroll animated">
<div class="links-of-blogroll-title"><i class="fa fa-link fa-fw"></i>
链接
</div>
<ul class="links-of-blogroll-list">
<li class="links-of-blogroll-item">
<a href="https://ngchain.org/" title="https://ngchain.org" rel="noopener" target="_blank">ngchain</a>
</li>
<li class="links-of-blogroll-item">
<a href="https://huggingface.co/spaces/c0mm4nd/LaTeX-OCR" title="https://huggingface.co/spaces/c0mm4nd/LaTeX-OCR" rel="noopener" target="_blank">Latex-OCR</a>
</li>
<li class="links-of-blogroll-item">
<a href="https://mathml-to-latex.c0mm4nd.com/" title="https://mathml-to-latex.c0mm4nd.com/" rel="noopener" target="_blank">MathML-to-Latex</a>
</li>
</ul>
</div>
</div>
</aside>
</div>
<div class="main-inner post posts-expand">
<div class="post-block">
<article itemscope itemtype="http://schema.org/Article" class="post-content" lang="zh-CN">
<link itemprop="mainEntityOfPage" href="https://c0mm4nd.com/wasm-core-1/">
<span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
<meta itemprop="image" content="/images/avatar.gif">
<meta itemprop="name" content="Command M">
</span>
<span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
<meta itemprop="name" content="Talkless">
<meta itemprop="description" content="">
</span>
<span hidden itemprop="post" itemscope itemtype="http://schema.org/CreativeWork">
<meta itemprop="name" content="WebAssembly核心标准:WebAssembly Core Specification | Talkless">
<meta itemprop="description" content="">
</span>
<header class="post-header">
<h1 class="post-title" itemprop="name headline">
WebAssembly核心标准:WebAssembly Core Specification
</h1>
<div class="post-meta-container">
<div class="post-meta">
<span class="post-meta-item">
<span class="post-meta-item-icon">
<i class="far fa-calendar"></i>
</span>
<span class="post-meta-item-text">发表于</span>
<time title="创建时间:2020-09-22 01:06:31" itemprop="dateCreated datePublished" datetime="2020-09-22T01:06:31+08:00">2020-09-22</time>
</span>
<span class="post-meta-item">
<span class="post-meta-item-icon">
<i class="far fa-calendar-check"></i>
</span>
<span class="post-meta-item-text">更新于</span>
<time title="修改时间:2021-10-11 17:21:36" itemprop="dateModified" datetime="2021-10-11T17:21:36+08:00">2021-10-11</time>
</span>
</div>
</div>
</header>
<div class="post-body" itemprop="articleBody"><p>细枝末节略,无关内容略。</p>
<span id="more"></span>
<h2 id="简介"><a class="markdownIt-Anchor" href="#简介"></a> 简介</h2>
<p>本文档介绍了WebAssembly核心标准的1.0版。WebAssembly是一种安全,可移植的低级代码格式,旨在有效执行和紧凑表达。</p>
<p>相关文档:核心WebAssembly规范,WebAssembly JS接口和WebAssembly Web API。</p>
<h2 id="1-引言"><a class="markdownIt-Anchor" href="#1-引言"></a> 1. 引言</h2>
<h3 id="11-引言"><a class="markdownIt-Anchor" href="#11-引言"></a> 1.1. 引言</h3>
<p>WebAssembly(缩写为Wasm)是一种安全,可移植的低级代码格式,旨在高效执行和紧凑表达。</p>
<p>它的主要目标是在Web上启用高性能应用程序,但是它没有做任何特定于Web的假设或提供特定于Web的功能,因此它也可以在其他环境中使用。</p>
<p>WebAssembly是W3C组织开发的开放标准。</p>
<p>本文档介绍了核心WebAssembly标准的1.0版。其未来将被替换为添加具有其他功能的新增量发行版。</p>
<h4 id="111-设计目标"><a class="markdownIt-Anchor" href="#111-设计目标"></a> 1.1.1. 设计目标</h4>
<p>WebAssembly的设计目标如下:</p>
<ul>
<li>快速,安全和可移植的语义:</li>
</ul>
<p><strong>快速</strong>:利用几乎所有现代硬件共有的功能,以接近本机的代码性能执行。</p>
<p><strong>安全</strong>:代码经过验证并在内存安全的[2]沙盒环境中执行,可防止数据损坏或安全漏洞。</p>
<p><strong>定义明确</strong>:以易于非正式地和正式地进行推理的方式,全面而精确地定义有效的程序及其行为。</p>
<p><strong>与硬件无关</strong>:可以在所有现代体系结构,台式机或移动设备以及嵌入式系统上进行编译。</p>
<p><strong>与语言无关</strong>:不青睐任何特定的语言,编程模型或对象模型。</p>
<p><strong>与平台无关</strong>:可以嵌入在浏览器中,作为独立VM运行或集成在其他环境中。</p>
<p><strong>开放</strong>:程序可以通过简单通用的方式与其环境进行互操作。</p>
<ul>
<li>高效便携的表示形式:</li>
</ul>
<p><strong>紧凑</strong>:具有比典型文本或本机代码格式小的传输速度快的二进制格式。</p>
<p><strong>模块化</strong>:程序可以分成较小的部分,可以分别传输,缓存和使用。</p>
<p><strong>高效</strong>:可以通过一次快速遍历进行解码,验证和编译,等同于即时(JIT)或提前(AOT)编译。</p>
<p><strong>可流式传输</strong>:允许在看到所有数据之前尽快开始解码,验证和编译。</p>
<p><strong>可并行化</strong>:允许将解码,验证和编译分为许多独立的并行任务。</p>
<p><strong>可移植性</strong>:没有任何现代硬件无法广泛支持的架构假设。</p>
<p>WebAssembly代码还旨在易于检查和调试,尤其是在Web浏览器之类的环境中,但是此类功能超出了本规范的范围。</p>
<p>[1]“WebAssembly”的缩写,而不是首字母缩写,因此未使用大写字母。</p>
<p>[2]没有任何程序可以破坏WebAssembly的内存模型。当然,它不能保证编译为WebAssembly的不安全语言不会破坏其自身的内存布局,例如WebAssembly的线性内存中。</p>
<h4 id="112-作用域"><a class="markdownIt-Anchor" href="#112-作用域"></a> 1.1.2. 作用域</h4>
<p>WebAssembly的核心是一套<em>虚拟指令集体系结构(虚拟ISA)</em>。<br />
因此,其具有许多用例,且可以嵌入许多不同的环境中。<br />
为了涵盖它们的多样性并实现最大程度的重用,WebAssembly规范被拆分并分层为多个文档。</p>
<p>本文档与WebAssembly的核心ISA层有关。<br />
它定义了指令集,二进制编码,验证和执行语义以及文本表示形式。<br />
但是,它没有定义WebAssembly程序如何与它们在其中执行的特定环境交互,也没有定义如何从这样的环境中调用它们。</p>
<p>取而代之的是,此规范得到了其他文档的补充,这些文档定义了到特定嵌入环境(例如Web)的接口。<br />
这些都将定义适合给定环境的WebAssembly<em>应用程序编程接口(API)</em>。</p>
<h3 id="12-安全性考量"><a class="markdownIt-Anchor" href="#12-安全性考量"></a> 1.2. 安全性考量</h3>
<p>WebAssembly不提供对执行代码的计算环境的环境访问。<br />
与环境的任何交互(例如I/O,对资源的访问或操作系统调用)只能通过调用嵌入器提供的功能并将其导入WebAssembly模块中来执行。<br />
嵌入程序可以通过控制或限制其可用于导入的功能来建立适用于相应环境的安全策略。<br />
这些注意事项是嵌入程序的责任,也是特定环境的API定义的内容。</p>
<p>由于WebAssembly旨在转换为直接在主机硬件上运行的机器代码,因此可能会在硬件级别受到旁通道攻击。<br />
在这是一个潜在的脆弱的环境中,嵌入程序可能必须设置适当的缓解措施以隔离WebAssembly计算。</p>
<h4 id="121-依赖"><a class="markdownIt-Anchor" href="#121-依赖"></a> 1.2.1. 依赖</h4>
<p>WebAssembly依赖于两个现有标准:</p>
<ul>
<li>[IEEE-754-2019],用于表示浮点数据和相应数字运算的语义。</li>
<li>[UNICODE],用于表示导入/导出名称和文本格式。</li>
</ul>
<p>但是,为了使本规范变得独立,将上述标准的相关方面定义并正式化为本规范的一部分,例如二进制表示和浮点值的取整,以及Unicode的值范围和UTF-8编码字符。</p>
<blockquote>
<p>注意!</p>
<p>前述标准是所有各个定义的权威来源。本规范中给出的形式化旨在与这些定义匹配。所描述的语法或语义上的任何差异均应视为错误。</p>
</blockquote>
<h3 id="13-概览"><a class="markdownIt-Anchor" href="#13-概览"></a> 1.3. 概览</h3>
<h4 id="131-概念"><a class="markdownIt-Anchor" href="#131-概念"></a> 1.3.1 概念</h4>
<p>WebAssembly编码一种低级的,类似于程序集的编程语言。该语言围绕以下概念构建。</p>
<p><strong>值Values</strong></p>
<blockquote>
<p>WebAssembly仅提供四种基本值类型。这些是整数和<a target="_blank" rel="noopener" href="https://www.w3.org/TR/wasm-core-1/#biblio-ieee-754-2019">IEEE-754-2019</a>数字,分别为32位和64位宽度。32位整数还用作布尔值和内存地址。可以使用这些类型的常规操作,包括它们之间转换的完整矩阵。有符号和无符号整数类型之间没有区别。取而代之的是,整数会被相应的操作解释为无符号或有两个补码表示形式的符号。</p>
</blockquote>
<p><strong>指令Instructions</strong></p>
<blockquote>
<p>WebAssembly的计算模型基于<em>堆栈计算机</em> 。代码由按顺序执行的指令序列组成。指令在隐式操作数堆栈[1]上操作值,并分为两个主要类别。简单的指令对数据执行基本操作。它们从操作数堆栈中弹出参数,并将结果压回该操作数堆栈。控制指令会改变控制流程。控制流是结构化的,这意味着它可以用嵌套好的结构(例如块,循环和条件)来表示。分支只能针对此类构造。</p>
</blockquote>
<p><strong>陷阱Traps</strong></p>
<blockquote>
<p>w在某些情况下,某些指令可能会产生陷阱,该陷阱会立即中止执行。陷阱不能由WebAssembly代码处理,但是会报告给外部环境,通常可以在外部环境中捕获它们。</p>
</blockquote>
<p><strong>功能Functions</strong></p>
<blockquote>
<p>代码被组织成单独的功能。每个函数都将值序列作为参数,并返回值序列作为结果。 [2]函数可以互相调用,包括递归调用,从而导致无法直接访问的隐式调用堆栈。函数还可以声明可用作虚拟寄存器的可变局部变量。</p>
</blockquote>
<p><strong>表Tables</strong></p>
<blockquote>
<p>表是特定元素类型的不透明值的数组。它允许程序通过动态索引操作数间接选择这些值。当前,唯一可用的元素类型是无类型的函数引用。因此,程序可以通过向表中的动态索引间接调用函数。例如,这允许通过表索引模拟功能指针。</p>
</blockquote>
<p><strong>线性内存Linear Memory</strong></p>
<blockquote>
<p>线性内存是连续,可变的原始字节数组。这样的存储器以初始大小创建,但是可以动态增长。程序可以在任何字节地址(包括未对齐)将线性存储器中的值加载/存储在线性存储器中或将其存储在其中。整数加载和存储可以指定小于各自值类型的大小的存储大小。如果访问不在当前内存大小的范围内,则会发生陷阱。</p>
</blockquote>
<p><strong>模块Modules</strong></p>
<blockquote>
<p>WebAssembly二进制文件采用模块的形式,该模块包含函数,表和线性内存的定义以及可变或不可变的全局变量。也可以导入定义,指定模块/名称对和合适的类型。每个定义可以选择以一个或多个名称导出。除定义外,模块还可以为其内存或表定义初始化数据,该初始化数据采用复制到给定偏移量的段的形式。他们还可以定义自动执行的启动功能。</p>
</blockquote>
<p><strong>嵌入器Embedder</strong></p>
<blockquote>
<p>WebAssembly实现通常将嵌入到主机环境中。此环境定义了如何启动模块加载,如何提供导入(包括主机端定义)以及如何访问导出。但是,任何特定嵌入的细节都超出了本规范的范围,而是由互补的,特定于环境的API定义提供。</p>
</blockquote>
<p>[1]实际上,实现无需维护实际的操作数堆栈。取而代之的是,堆栈可以看作是一组由指令隐式引用的匿名寄存器。类型系统可确保始终静态地了解堆栈高度,从而确保所有引用的寄存器。<br />
[2]在当前版本的WebAssembly中,最多只有一个结果值。</p>
<h4 id="132-语义解析"><a class="markdownIt-Anchor" href="#132-语义解析"></a> 1.3.2. 语义解析</h4>
<p>从概念上讲,WebAssembly的语义分为三个阶段。对于语言的每个部分,规范都会对其进行指定。</p>
<p><strong>解码Decoding</strong></p>
<blockquote>
<p>WebAssembly模块以二进制格式分发。解码过程将格式化并将其转换为模块的内部表示形式。在本规范中,此表示是通过抽象语法建模的,但是实际的实现可以改为直接编译为机器代码。</p>
</blockquote>
<p><strong>验证Validation</strong></p>
<blockquote>
<p>被解码的模块必须<em>有效</em>。验证检查许多格式正确的条件,以确保模块有意义且安全。特别是,它对功能及其内部的指令序列进行类型检查,以确保例如一致地使用操作数堆栈。</p>
</blockquote>
<p><strong>执行Execution</strong></p>
<blockquote>
<p>最后,一个有效的模块可以被<em>执行</em>。执行可以进一步分为两个阶段:</p>
<p><strong>实例化Instantiation</strong>。模块实例是模块的动态表示,带有其自己的状态和执行堆栈。实例化将执行模块主体本身,并为其定义所有导入。它将初始化全局变量,内存和表,并调用模块的启动函数(如果已定义)。它返回模块导出的实例。</p>
<p><strong>调用Invocation</strong>。一旦实例化,就可以通过在模块实例上<em>调用</em>导出的函数来启动进一步的WebAssembly计算。给定必需的参数,该函数将执行相应的函数并返回其结果。</p>
<p>实例化和调用是在嵌入环境中的操作。</p>
</blockquote>
<h2 id="2-架构"><a class="markdownIt-Anchor" href="#2-架构"></a> 2. 架构</h2>
<h3 id="21-规定"><a class="markdownIt-Anchor" href="#21-规定"></a> 2.1. 规定</h3>
<p>WebAssembly是一种编程语言,具有多种具体表示形式(其二进制格式和文本格式)。 两者都映射到一个共同的结构。为简明起见,以抽象语法的形式描述了此结构。本规范的所有部分均根据此抽象语法定义。</p>
<h4 id="211-语法符号"><a class="markdownIt-Anchor" href="#211-语法符号"></a> 2.1.1. 语法符号</h4>
<p>在定义抽象语法的语法规则时采用以下约定。</p>
<ul>
<li>结束符号(原子)以sans-serif字体编写<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi mathvariant="normal">i</mi><mn>32</mn><mo separator="true">,</mo><mi mathvariant="normal">e</mi><mi mathvariant="normal">n</mi><mi mathvariant="normal">d</mi></mrow><annotation encoding="application/x-tex">\mathrm{i32, end}</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8888799999999999em;vertical-align:-0.19444em;"></span><span class="mord"><span class="mord mathrm">i</span><span class="mord mathrm">3</span><span class="mord mathrm">2</span><span class="mpunct">,</span><span class="mspace" style="margin-right:0.16666666666666666em;"></span><span class="mord mathrm">e</span><span class="mord mathrm">n</span><span class="mord mathrm">d</span></span></span></span></span>。</li>
<li>非结束符以斜体字体表示:<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>v</mi><mi>a</mi><mi>l</mi><mi>t</mi><mi>y</mi><mi>p</mi><mi>e</mi><mtext>,</mtext><mi>i</mi><mi>n</mi><mi>s</mi><mi>t</mi><mi>r</mi></mrow><annotation encoding="application/x-tex">valtype,instr</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8888799999999999em;vertical-align:-0.19444em;"></span><span class="mord mathnormal" style="margin-right:0.03588em;">v</span><span class="mord mathnormal">a</span><span class="mord mathnormal" style="margin-right:0.01968em;">l</span><span class="mord mathnormal">t</span><span class="mord mathnormal" style="margin-right:0.03588em;">y</span><span class="mord mathnormal">p</span><span class="mord mathnormal">e</span><span class="mord cjk_fallback">,</span><span class="mord mathnormal">i</span><span class="mord mathnormal">n</span><span class="mord mathnormal">s</span><span class="mord mathnormal">t</span><span class="mord mathnormal" style="margin-right:0.02778em;">r</span></span></span></span>。</li>
<li><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msup><mi>A</mi><mi>n</mi></msup></mrow><annotation encoding="application/x-tex">A^n</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.68333em;vertical-align:0em;"></span><span class="mord"><span class="mord mathnormal">A</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.664392em;"><span style="top:-3.063em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">n</span></span></span></span></span></span></span></span></span></span></span>是A的<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>n</mi><mo>≥</mo><mn>0</mn></mrow><annotation encoding="application/x-tex">n\geq0</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.7719400000000001em;vertical-align:-0.13597em;"></span><span class="mord mathnormal">n</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">≥</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:0.64444em;vertical-align:0em;"></span><span class="mord">0</span></span></span></span>个迭代的序列。</li>
<li><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msup><mi>A</mi><mo>∗</mo></msup></mrow><annotation encoding="application/x-tex">A^*</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.688696em;vertical-align:0em;"></span><span class="mord"><span class="mord mathnormal">A</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.688696em;"><span style="top:-3.063em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mbin mtight">∗</span></span></span></span></span></span></span></span></span></span></span>是A的可能是空的迭代序列。(这是n无关的<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msup><mi>A</mi><mi>n</mi></msup></mrow><annotation encoding="application/x-tex">A^n</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.68333em;vertical-align:0em;"></span><span class="mord"><span class="mord mathnormal">A</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.664392em;"><span style="top:-3.063em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">n</span></span></span></span></span></span></span></span></span></span></span>的简写。)</li>
<li><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msup><mi>A</mi><mo>+</mo></msup></mrow><annotation encoding="application/x-tex">A^+</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.771331em;vertical-align:0em;"></span><span class="mord"><span class="mord mathnormal">A</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.771331em;"><span style="top:-3.063em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mbin mtight">+</span></span></span></span></span></span></span></span></span></span></span>是A的非空迭代序列。(这是<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msup><mi>A</mi><mi>n</mi></msup></mrow><annotation encoding="application/x-tex">A^n</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.68333em;vertical-align:0em;"></span><span class="mord"><span class="mord mathnormal">A</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.664392em;"><span style="top:-3.063em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">n</span></span></span></span></span></span></span></span></span></span></span>的简写,其中n≥1。)</li>
<li><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msup><mi>A</mi><mo stretchy="false">?</mo></msup></mrow><annotation encoding="application/x-tex">A^?</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.849108em;vertical-align:0em;"></span><span class="mord"><span class="mord mathnormal">A</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.849108em;"><span style="top:-3.063em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mclose mtight">?</span></span></span></span></span></span></span></span></span></span></span>是A的可选出现。(这是<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msup><mi>A</mi><mi>n</mi></msup></mrow><annotation encoding="application/x-tex">A^n</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.68333em;vertical-align:0em;"></span><span class="mord"><span class="mord mathnormal">A</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.664392em;"><span style="top:-3.063em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">n</span></span></span></span></span></span></span></span></span></span></span>的简写,其中n≤1。)</li>
<li>产生式被写成<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>s</mi><mi>y</mi><mi>m</mi><mo>:</mo><mo>:</mo><mo>=</mo><msub><mi>A</mi><mn>1</mn></msub><mo>∣</mo><mi mathvariant="normal">.</mi><mi mathvariant="normal">.</mi><mi mathvariant="normal">.</mi><mo>∣</mo><msub><mi>A</mi><mi>n</mi></msub></mrow><annotation encoding="application/x-tex">sym::=A_1∣...∣A_n</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.625em;vertical-align:-0.19444em;"></span><span class="mord mathnormal">s</span><span class="mord mathnormal" style="margin-right:0.03588em;">y</span><span class="mord mathnormal">m</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">:</span></span><span class="base"><span class="strut" style="height:0.43056em;vertical-align:0em;"></span><span class="mrel">:</span></span><span class="base"><span class="strut" style="height:0.36687em;vertical-align:0em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord"><span class="mord mathnormal">A</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.30110799999999993em;"><span style="top:-2.5500000000000003em;margin-left:0em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">1</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">∣</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord">.</span><span class="mord">.</span><span class="mord">.</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">∣</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:0.83333em;vertical-align:-0.15em;"></span><span class="mord"><span class="mord mathnormal">A</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.151392em;"><span style="top:-2.5500000000000003em;margin-left:0em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">n</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span></span></span>。</li>
<li>大型产生式可能会分为多个定义,可以用第一个以显式椭圆<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>s</mi><mi>y</mi><mi>m</mi><mo>:</mo><mo>:</mo><mo>=</mo><msub><mi>A</mi><mn>1</mn></msub><mi mathvariant="normal">∣</mi><mi mathvariant="normal">.</mi><mi mathvariant="normal">.</mi><mi mathvariant="normal">.</mi></mrow><annotation encoding="application/x-tex">sym::=A_1|...</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.625em;vertical-align:-0.19444em;"></span><span class="mord mathnormal">s</span><span class="mord mathnormal" style="margin-right:0.03588em;">y</span><span class="mord mathnormal">m</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">:</span></span><span class="base"><span class="strut" style="height:0.43056em;vertical-align:0em;"></span><span class="mrel">:</span></span><span class="base"><span class="strut" style="height:0.36687em;vertical-align:0em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord"><span class="mord mathnormal">A</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.30110799999999993em;"><span style="top:-2.5500000000000003em;margin-left:0em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">1</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mord">∣</span><span class="mord">.</span><span class="mord">.</span><span class="mord">.</span></span></span></span>结束,并以椭圆以<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>s</mi><mi>y</mi><mi>m</mi><mo>:</mo><mo>:</mo><mo>=</mo><mi mathvariant="normal">.</mi><mi mathvariant="normal">.</mi><mi mathvariant="normal">.</mi><mo>∣</mo><msub><mi>A</mi><mn>2</mn></msub></mrow><annotation encoding="application/x-tex">sym::=...∣A_2</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.625em;vertical-align:-0.19444em;"></span><span class="mord mathnormal">s</span><span class="mord mathnormal" style="margin-right:0.03588em;">y</span><span class="mord mathnormal">m</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">:</span></span><span class="base"><span class="strut" style="height:0.43056em;vertical-align:0em;"></span><span class="mrel">:</span></span><span class="base"><span class="strut" style="height:0.36687em;vertical-align:0em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord">.</span><span class="mord">.</span><span class="mord">.</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">∣</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:0.83333em;vertical-align:-0.15em;"></span><span class="mord"><span class="mord mathnormal">A</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.30110799999999993em;"><span style="top:-2.5500000000000003em;margin-left:0em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">2</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span></span></span>开头来表示。</li>
<li>一些产品在括号中加上附加条件“<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mo stretchy="false">(</mo><mrow><mi mathvariant="normal">i</mi><mi mathvariant="normal">f</mi></mrow><mi>c</mi><mi>o</mi><mi>n</mi><mi>d</mi><mi>i</mi><mi>t</mi><mi>i</mi><mi>o</mi><mi>n</mi><mo stretchy="false">)</mo></mrow><annotation encoding="application/x-tex">(\mathrm{if} condition)</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mopen">(</span><span class="mord"><span class="mord mathrm">i</span><span class="mord mathrm" style="margin-right:0.07778em;">f</span></span><span class="mord mathnormal">c</span><span class="mord mathnormal">o</span><span class="mord mathnormal">n</span><span class="mord mathnormal">d</span><span class="mord mathnormal">i</span><span class="mord mathnormal">t</span><span class="mord mathnormal">i</span><span class="mord mathnormal">o</span><span class="mord mathnormal">n</span><span class="mclose">)</span></span></span></span>”,这为将产品组合扩展为许多单独的案例提供了捷径。</li>
</ul>
<h4 id="212-辅助符号"><a class="markdownIt-Anchor" href="#212-辅助符号"></a> 2.1.2. 辅助符号</h4>
<p>在处理语法结构时,还使用以下表示法:</p>
<ul>
<li><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>ϵ</mi></mrow><annotation encoding="application/x-tex">\epsilon</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.43056em;vertical-align:0em;"></span><span class="mord mathnormal">ϵ</span></span></span></span>表示空序列。</li>
<li><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi mathvariant="normal">∣</mi><mi>s</mi><mi mathvariant="normal">∣</mi></mrow><annotation encoding="application/x-tex">|s|</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord">∣</span><span class="mord mathnormal">s</span><span class="mord">∣</span></span></span></span>表示序列s的长度。</li>
<li><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>s</mi><mo stretchy="false">[</mo><mi>i</mi><mo stretchy="false">]</mo></mrow><annotation encoding="application/x-tex">s[i]</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord mathnormal">s</span><span class="mopen">[</span><span class="mord mathnormal">i</span><span class="mclose">]</span></span></span></span>表示序列s的第i个元素,从0开始。</li>
<li><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>s</mi><mo stretchy="false">[</mo><mi>i</mi><mo>:</mo><mi>n</mi><mo stretchy="false">]</mo></mrow><annotation encoding="application/x-tex">s[i:n]</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord mathnormal">s</span><span class="mopen">[</span><span class="mord mathnormal">i</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">:</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord mathnormal">n</span><span class="mclose">]</span></span></span></span>表示序列s的子序列<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>s</mi><mo stretchy="false">[</mo><mi>i</mi><mo stretchy="false">]</mo><mi mathvariant="normal">.</mi><mi mathvariant="normal">.</mi><mi mathvariant="normal">.</mi><mi>s</mi><mo stretchy="false">[</mo><mi>i</mi><mo>+</mo><mi>n</mi><mo>−</mo><mn>1</mn><mo stretchy="false">]</mo></mrow><annotation encoding="application/x-tex">s[i]...s [i+n-1]</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord mathnormal">s</span><span class="mopen">[</span><span class="mord mathnormal">i</span><span class="mclose">]</span><span class="mord">.</span><span class="mord">.</span><span class="mord">.</span><span class="mord mathnormal">s</span><span class="mopen">[</span><span class="mord mathnormal">i</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">+</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span></span><span class="base"><span class="strut" style="height:0.66666em;vertical-align:-0.08333em;"></span><span class="mord mathnormal">n</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">−</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord">1</span><span class="mclose">]</span></span></span></span>。</li>
<li><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>s</mi><mtext> </mtext><mi>w</mi><mi>i</mi><mi>t</mi><mi>h</mi><mo stretchy="false">[</mo><mi>i</mi><mo stretchy="false">]</mo><mo>=</mo><mi>A</mi></mrow><annotation encoding="application/x-tex">s\ with [i] = A</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord mathnormal">s</span><span class="mspace"> </span><span class="mord mathnormal" style="margin-right:0.02691em;">w</span><span class="mord mathnormal">i</span><span class="mord mathnormal">t</span><span class="mord mathnormal">h</span><span class="mopen">[</span><span class="mord mathnormal">i</span><span class="mclose">]</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:0.68333em;vertical-align:0em;"></span><span class="mord mathnormal">A</span></span></span></span>表示与s相同的序列,除了第i个元素被A代替。</li>
<li><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>s</mi><mtext> </mtext><mi>w</mi><mi>i</mi><mi>t</mi><mi>h</mi><mo stretchy="false">[</mo><mi>i</mi><mo>:</mo><mi>n</mi><mo stretchy="false">]</mo><mo>=</mo><msup><mi>A</mi><mi>n</mi></msup></mrow><annotation encoding="application/x-tex">s\ with [i:n] = A^n</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord mathnormal">s</span><span class="mspace"> </span><span class="mord mathnormal" style="margin-right:0.02691em;">w</span><span class="mord mathnormal">i</span><span class="mord mathnormal">t</span><span class="mord mathnormal">h</span><span class="mopen">[</span><span class="mord mathnormal">i</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">:</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord mathnormal">n</span><span class="mclose">]</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:0.68333em;vertical-align:0em;"></span><span class="mord"><span class="mord mathnormal">A</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.664392em;"><span style="top:-3.063em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">n</span></span></span></span></span></span></span></span></span></span></span>表示与s相同的序列,不同之处在于子序列<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>s</mi><mo stretchy="false">[</mo><mi>i</mi><mo>:</mo><mi>n</mi><mo stretchy="false">]</mo></mrow><annotation encoding="application/x-tex">s[i:n]</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord mathnormal">s</span><span class="mopen">[</span><span class="mord mathnormal">i</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">:</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord mathnormal">n</span><span class="mclose">]</span></span></span></span>被An取代。</li>
<li><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>c</mi><mi>o</mi><mi>n</mi><mi>c</mi><mi>a</mi><mi>t</mi><mo stretchy="false">(</mo><msup><mi>s</mi><mo>∗</mo></msup><mo stretchy="false">)</mo></mrow><annotation encoding="application/x-tex">concat(s^*)</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord mathnormal">c</span><span class="mord mathnormal">o</span><span class="mord mathnormal">n</span><span class="mord mathnormal">c</span><span class="mord mathnormal">a</span><span class="mord mathnormal">t</span><span class="mopen">(</span><span class="mord"><span class="mord mathnormal">s</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.688696em;"><span style="top:-3.063em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mbin mtight">∗</span></span></span></span></span></span></span></span><span class="mclose">)</span></span></span></span>表示通过将<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msup><mi>s</mi><mo>∗</mo></msup></mrow><annotation encoding="application/x-tex">s^*</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.688696em;vertical-align:0em;"></span><span class="mord"><span class="mord mathnormal">s</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.688696em;"><span style="top:-3.063em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mbin mtight">∗</span></span></span></span></span></span></span></span></span></span></span>中的所有序列<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msup><mi>s</mi><mi>i</mi></msup></mrow><annotation encoding="application/x-tex">s^i</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.824664em;vertical-align:0em;"></span><span class="mord"><span class="mord mathnormal">s</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.824664em;"><span style="top:-3.063em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">i</span></span></span></span></span></span></span></span></span></span></span>串联而形成的平坦序列。</li>
</ul>
<p>此外,采用以下约定:</p>
<ul>
<li>
<p>符号<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msup><mi>x</mi><mi>n</mi></msup></mrow><annotation encoding="application/x-tex">x^n</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.664392em;vertical-align:0em;"></span><span class="mord"><span class="mord mathnormal">x</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.664392em;"><span style="top:-3.063em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">n</span></span></span></span></span></span></span></span></span></span></span>(其中x是非终结符号)被视为跨x的各个序列(类似于<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msup><mi>x</mi><mo>∗</mo></msup></mrow><annotation encoding="application/x-tex">x^*</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.688696em;vertical-align:0em;"></span><span class="mord"><span class="mord mathnormal">x</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.688696em;"><span style="top:-3.063em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mbin mtight">∗</span></span></span></span></span></span></span></span></span></span></span>,<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msup><mi>x</mi><mo>+</mo></msup></mrow><annotation encoding="application/x-tex">x^+</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.771331em;vertical-align:0em;"></span><span class="mord"><span class="mord mathnormal">x</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.771331em;"><span style="top:-3.063em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mbin mtight">+</span></span></span></span></span></span></span></span></span></span></span>,<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msup><mi>x</mi><mo stretchy="false">?</mo></msup></mrow><annotation encoding="application/x-tex">x^?</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.849108em;vertical-align:0em;"></span><span class="mord"><span class="mord mathnormal">x</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.849108em;"><span style="top:-3.063em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mclose mtight">?</span></span></span></span></span></span></span></span></span></span></span>)的元变量。</p>
</li>
<li>
<p>当给定一个序列<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msup><mi>x</mi><mi>n</mi></msup></mrow><annotation encoding="application/x-tex">x^n</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.664392em;vertical-align:0em;"></span><span class="mord"><span class="mord mathnormal">x</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.664392em;"><span style="top:-3.063em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">n</span></span></span></span></span></span></span></span></span></span></span>时,则假定在<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mo stretchy="false">(</mo><mi>A</mi><mn>1</mn><mi>x</mi><mi>A</mi><mn>2</mn><msup><mo stretchy="false">)</mo><mi>n</mi></msup></mrow><annotation encoding="application/x-tex">(A1xA2)^n</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mopen">(</span><span class="mord mathnormal">A</span><span class="mord">1</span><span class="mord mathnormal">x</span><span class="mord mathnormal">A</span><span class="mord">2</span><span class="mclose"><span class="mclose">)</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.664392em;"><span style="top:-3.063em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">n</span></span></span></span></span></span></span></span></span></span></span>中写入的序列中x的出现与xn呈逐点对应关系(对于<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msup><mi>x</mi><mo>∗</mo></msup></mrow><annotation encoding="application/x-tex">x^*</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.688696em;vertical-align:0em;"></span><span class="mord"><span class="mord mathnormal">x</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.688696em;"><span style="top:-3.063em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mbin mtight">∗</span></span></span></span></span></span></span></span></span></span></span>,<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msup><mi>x</mi><mo>+</mo></msup></mrow><annotation encoding="application/x-tex">x^+</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.771331em;vertical-align:0em;"></span><span class="mord"><span class="mord mathnormal">x</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.771331em;"><span style="top:-3.063em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mbin mtight">+</span></span></span></span></span></span></span></span></span></span></span>,<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msup><mi>x</mi><mo stretchy="false">?</mo></msup></mrow><annotation encoding="application/x-tex">x^?</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.849108em;vertical-align:0em;"></span><span class="mord"><span class="mord mathnormal">x</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.849108em;"><span style="top:-3.063em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mclose mtight">?</span></span></span></span></span></span></span></span></span></span></span>同样)。这隐式表达了在序列上映射语法结构的形式。</p>
</li>
</ul>
<p>以下形式的生产被解释为分别将一组固定的字段<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>f</mi><mi>i</mi><mi>e</mi><mi>l</mi><msub><mi>d</mi><mi>i</mi></msub></mrow><annotation encoding="application/x-tex">field_i</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8888799999999999em;vertical-align:-0.19444em;"></span><span class="mord mathnormal" style="margin-right:0.10764em;">f</span><span class="mord mathnormal">i</span><span class="mord mathnormal">e</span><span class="mord mathnormal" style="margin-right:0.01968em;">l</span><span class="mord"><span class="mord mathnormal">d</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.31166399999999994em;"><span style="top:-2.5500000000000003em;margin-left:0em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">i</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span></span></span>映射到“值” Ai的记录:</p>
<p class='katex-block'><span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><mi>r</mi><mo>:</mo><mo>:</mo><mo>=</mo><mo stretchy="false">{</mo><mi>f</mi><mi>i</mi><mi>e</mi><mi>l</mi><msub><mi>d</mi><mn>1</mn></msub><msub><mi>A</mi><mn>1</mn></msub><mo separator="true">,</mo><mi>f</mi><mi>i</mi><mi>e</mi><mi>l</mi><msub><mi>d</mi><mn>2</mn></msub><msub><mi>A</mi><mn>2</mn></msub><mo separator="true">,</mo><mi mathvariant="normal">.</mi><mi mathvariant="normal">.</mi><mi mathvariant="normal">.</mi><mo stretchy="false">}</mo></mrow><annotation encoding="application/x-tex">r ::= \{ field_1 A_1, field_2 A_2,... \}
</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.43056em;vertical-align:0em;"></span><span class="mord mathnormal" style="margin-right:0.02778em;">r</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">:</span></span><span class="base"><span class="strut" style="height:0.43056em;vertical-align:0em;"></span><span class="mrel">:</span></span><span class="base"><span class="strut" style="height:0.36687em;vertical-align:0em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mopen">{</span><span class="mord mathnormal" style="margin-right:0.10764em;">f</span><span class="mord mathnormal">i</span><span class="mord mathnormal">e</span><span class="mord mathnormal" style="margin-right:0.01968em;">l</span><span class="mord"><span class="mord mathnormal">d</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.30110799999999993em;"><span style="top:-2.5500000000000003em;margin-left:0em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">1</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mord"><span class="mord mathnormal">A</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.30110799999999993em;"><span style="top:-2.5500000000000003em;margin-left:0em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">1</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mpunct">,</span><span class="mspace" style="margin-right:0.16666666666666666em;"></span><span class="mord mathnormal" style="margin-right:0.10764em;">f</span><span class="mord mathnormal">i</span><span class="mord mathnormal">e</span><span class="mord mathnormal" style="margin-right:0.01968em;">l</span><span class="mord"><span class="mord mathnormal">d</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.30110799999999993em;"><span style="top:-2.5500000000000003em;margin-left:0em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">2</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mord"><span class="mord mathnormal">A</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.30110799999999993em;"><span style="top:-2.5500000000000003em;margin-left:0em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">2</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mpunct">,</span><span class="mspace" style="margin-right:0.16666666666666666em;"></span><span class="mord">.</span><span class="mord">.</span><span class="mord">.</span><span class="mclose">}</span></span></span></span></span></p>
<p>使用以下表示法来处理此类记录:</p>
<ul>
<li>
<p><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>r</mi><mi mathvariant="normal">.</mi><mi>f</mi><mi>i</mi><mi>e</mi><mi>l</mi><mi>d</mi></mrow><annotation encoding="application/x-tex">r.field</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8888799999999999em;vertical-align:-0.19444em;"></span><span class="mord mathnormal" style="margin-right:0.02778em;">r</span><span class="mord">.</span><span class="mord mathnormal" style="margin-right:0.10764em;">f</span><span class="mord mathnormal">i</span><span class="mord mathnormal">e</span><span class="mord mathnormal" style="margin-right:0.01968em;">l</span><span class="mord mathnormal">d</span></span></span></span>表示r的字段filed的内容。</p>
</li>
<li>
<p><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>r</mi><mtext> </mtext><mi>w</mi><mi>i</mi><mi>t</mi><mi>h</mi><mtext> </mtext><mi>f</mi><mi>i</mi><mi>e</mi><mi>l</mi><mi>d</mi><mo>=</mo><mi>A</mi></mrow><annotation encoding="application/x-tex">r\ with\ field = A</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8888799999999999em;vertical-align:-0.19444em;"></span><span class="mord mathnormal" style="margin-right:0.02778em;">r</span><span class="mspace"> </span><span class="mord mathnormal" style="margin-right:0.02691em;">w</span><span class="mord mathnormal">i</span><span class="mord mathnormal">t</span><span class="mord mathnormal">h</span><span class="mspace"> </span><span class="mord mathnormal" style="margin-right:0.10764em;">f</span><span class="mord mathnormal">i</span><span class="mord mathnormal">e</span><span class="mord mathnormal" style="margin-right:0.01968em;">l</span><span class="mord mathnormal">d</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:0.68333em;vertical-align:0em;"></span><span class="mord mathnormal">A</span></span></span></span>表示与r相同的记录,除了字段组件的内容被A代替。</p>
</li>
<li>
<p><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>r</mi><mn>1</mn><mo>⊕</mo><mi>r</mi><mn>2</mn></mrow><annotation encoding="application/x-tex">r1 \oplus r2</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.72777em;vertical-align:-0.08333em;"></span><span class="mord mathnormal" style="margin-right:0.02778em;">r</span><span class="mord">1</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">⊕</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span></span><span class="base"><span class="strut" style="height:0.64444em;vertical-align:0em;"></span><span class="mord mathnormal" style="margin-right:0.02778em;">r</span><span class="mord">2</span></span></span></span>通过逐点追加每个序列来表示具有相同序列字段的两个记录的组合:</p>
</li>
</ul>
<p class='katex-block'><span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><mo stretchy="false">{</mo><mi>f</mi><mi>i</mi><mi>e</mi><mi>l</mi><msub><mi>d</mi><mn>1</mn></msub><msubsup><mi>A</mi><mn>1</mn><mo>∗</mo></msubsup><mo separator="true">,</mo><mi>f</mi><mi>i</mi><mi>e</mi><mi>l</mi><msub><mi>d</mi><mn>2</mn></msub><msubsup><mi>A</mi><mn>2</mn><mo>∗</mo></msubsup><mo separator="true">,</mo><mi mathvariant="normal">.</mi><mi mathvariant="normal">.</mi><mi mathvariant="normal">.</mi><mo stretchy="false">}</mo><mo stretchy="false">{</mo><mi>f</mi><mi>i</mi><mi>e</mi><mi>l</mi><msub><mi>d</mi><mn>1</mn></msub><msubsup><mi>B</mi><mn>1</mn><mo>∗</mo></msubsup><mo separator="true">,</mo><mi>f</mi><mi>i</mi><mi>e</mi><mi>l</mi><msub><mi>d</mi><mn>2</mn></msub><msubsup><mi>B</mi><mn>2</mn><mo>∗</mo></msubsup><mo separator="true">,</mo><mi mathvariant="normal">.</mi><mi mathvariant="normal">.</mi><mi mathvariant="normal">.</mi><mo stretchy="false">}</mo><mo>=</mo><mo stretchy="false">{</mo><mi>f</mi><mi>i</mi><mi>e</mi><mi>l</mi><msub><mi>d</mi><mn>1</mn></msub><msubsup><mi>A</mi><mn>1</mn><mo>∗</mo></msubsup><msubsup><mi>B</mi><mn>1</mn><mo>∗</mo></msubsup><mo separator="true">,</mo><mi>f</mi><mi>i</mi><mi>e</mi><mi>l</mi><msub><mi>d</mi><mn>2</mn></msub><msubsup><mi>A</mi><mn>2</mn><mo>∗</mo></msubsup><msubsup><mi>B</mi><mn>2</mn><mo>∗</mo></msubsup><mo separator="true">,</mo><mi mathvariant="normal">.</mi><mi mathvariant="normal">.</mi><mi mathvariant="normal">.</mi><mo stretchy="false">}</mo></mrow><annotation encoding="application/x-tex">\{ field_1 A_1^*, field_2 A_2^*, ... \} \{field_1 B_1^*, field_2 B_2^*, ... \} = \{ field_1 A_1^* B_1^*, field_2 A_2^* B_2^*,... \}
</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mopen">{</span><span class="mord mathnormal" style="margin-right:0.10764em;">f</span><span class="mord mathnormal">i</span><span class="mord mathnormal">e</span><span class="mord mathnormal" style="margin-right:0.01968em;">l</span><span class="mord"><span class="mord mathnormal">d</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.30110799999999993em;"><span style="top:-2.5500000000000003em;margin-left:0em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">1</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mord"><span class="mord mathnormal">A</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.7386959999999999em;"><span style="top:-2.4530000000000003em;margin-left:0em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">1</span></span></span><span style="top:-3.113em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mbin mtight">∗</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.247em;"><span></span></span></span></span></span></span><span class="mpunct">,</span><span class="mspace" style="margin-right:0.16666666666666666em;"></span><span class="mord mathnormal" style="margin-right:0.10764em;">f</span><span class="mord mathnormal">i</span><span class="mord mathnormal">e</span><span class="mord mathnormal" style="margin-right:0.01968em;">l</span><span class="mord"><span class="mord mathnormal">d</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.30110799999999993em;"><span style="top:-2.5500000000000003em;margin-left:0em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">2</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mord"><span class="mord mathnormal">A</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.7386959999999999em;"><span style="top:-2.4530000000000003em;margin-left:0em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">2</span></span></span><span style="top:-3.113em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mbin mtight">∗</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.247em;"><span></span></span></span></span></span></span><span class="mpunct">,</span><span class="mspace" style="margin-right:0.16666666666666666em;"></span><span class="mord">.</span><span class="mord">.</span><span class="mord">.</span><span class="mclose">}</span><span class="mopen">{</span><span class="mord mathnormal" style="margin-right:0.10764em;">f</span><span class="mord mathnormal">i</span><span class="mord mathnormal">e</span><span class="mord mathnormal" style="margin-right:0.01968em;">l</span><span class="mord"><span class="mord mathnormal">d</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.30110799999999993em;"><span style="top:-2.5500000000000003em;margin-left:0em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">1</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.05017em;">B</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.7386959999999999em;"><span style="top:-2.4530000000000003em;margin-left:-0.05017em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">1</span></span></span><span style="top:-3.113em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mbin mtight">∗</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.247em;"><span></span></span></span></span></span></span><span class="mpunct">,</span><span class="mspace" style="margin-right:0.16666666666666666em;"></span><span class="mord mathnormal" style="margin-right:0.10764em;">f</span><span class="mord mathnormal">i</span><span class="mord mathnormal">e</span><span class="mord mathnormal" style="margin-right:0.01968em;">l</span><span class="mord"><span class="mord mathnormal">d</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.30110799999999993em;"><span style="top:-2.5500000000000003em;margin-left:0em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">2</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.05017em;">B</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.7386959999999999em;"><span style="top:-2.4530000000000003em;margin-left:-0.05017em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">2</span></span></span><span style="top:-3.113em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mbin mtight">∗</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.247em;"><span></span></span></span></span></span></span><span class="mpunct">,</span><span class="mspace" style="margin-right:0.16666666666666666em;"></span><span class="mord">.</span><span class="mord">.</span><span class="mord">.</span><span class="mclose">}</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mopen">{</span><span class="mord mathnormal" style="margin-right:0.10764em;">f</span><span class="mord mathnormal">i</span><span class="mord mathnormal">e</span><span class="mord mathnormal" style="margin-right:0.01968em;">l</span><span class="mord"><span class="mord mathnormal">d</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.30110799999999993em;"><span style="top:-2.5500000000000003em;margin-left:0em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">1</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mord"><span class="mord mathnormal">A</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.7386959999999999em;"><span style="top:-2.4530000000000003em;margin-left:0em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">1</span></span></span><span style="top:-3.113em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mbin mtight">∗</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.247em;"><span></span></span></span></span></span></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.05017em;">B</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.7386959999999999em;"><span style="top:-2.4530000000000003em;margin-left:-0.05017em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">1</span></span></span><span style="top:-3.113em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mbin mtight">∗</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.247em;"><span></span></span></span></span></span></span><span class="mpunct">,</span><span class="mspace" style="margin-right:0.16666666666666666em;"></span><span class="mord mathnormal" style="margin-right:0.10764em;">f</span><span class="mord mathnormal">i</span><span class="mord mathnormal">e</span><span class="mord mathnormal" style="margin-right:0.01968em;">l</span><span class="mord"><span class="mord mathnormal">d</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.30110799999999993em;"><span style="top:-2.5500000000000003em;margin-left:0em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">2</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mord"><span class="mord mathnormal">A</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.7386959999999999em;"><span style="top:-2.4530000000000003em;margin-left:0em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">2</span></span></span><span style="top:-3.113em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mbin mtight">∗</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.247em;"><span></span></span></span></span></span></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.05017em;">B</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.7386959999999999em;"><span style="top:-2.4530000000000003em;margin-left:-0.05017em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">2</span></span></span><span style="top:-3.113em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mbin mtight">∗</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.247em;"><span></span></span></span></span></span></span><span class="mpunct">,</span><span class="mspace" style="margin-right:0.16666666666666666em;"></span><span class="mord">.</span><span class="mord">.</span><span class="mord">.</span><span class="mclose">}</span></span></span></span></span></p>
<ul>
<li><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mo>⊕</mo><msup><mi>r</mi><mo>∗</mo></msup></mrow><annotation encoding="application/x-tex">\oplus r^*</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.772026em;vertical-align:-0.08333em;"></span><span class="mord">⊕</span><span class="mord"><span class="mord mathnormal" style="margin-right:0.02778em;">r</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.688696em;"><span style="top:-3.063em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mbin mtight">∗</span></span></span></span></span></span></span></span></span></span></span>分别表示记录序列的组成;如果序列为空,则结果记录的所有字段均为空。</li>
</ul>
<p>序列和记录的更新符号递归地概括为“路径” <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>p</mi><mi>t</mi><mi>h</mi><mo>:</mo><mo>:</mo><mo>=</mo><mo stretchy="false">(</mo><mo stretchy="false">[</mo><mi mathvariant="normal">.</mi><mi mathvariant="normal">.</mi><mi mathvariant="normal">.</mi><mo stretchy="false">]</mo><mi mathvariant="normal">∣</mi><mi mathvariant="normal">.</mi><mi>f</mi><mi>i</mi><mi>e</mi><mi>l</mi><mi>d</mi><msup><mo stretchy="false">)</mo><mo>+</mo></msup></mrow><annotation encoding="application/x-tex">pth ::=([...]|.field)^+</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8888799999999999em;vertical-align:-0.19444em;"></span><span class="mord mathnormal">p</span><span class="mord mathnormal">t</span><span class="mord mathnormal">h</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">:</span></span><span class="base"><span class="strut" style="height:0.43056em;vertical-align:0em;"></span><span class="mrel">:</span></span><span class="base"><span class="strut" style="height:0.36687em;vertical-align:0em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:1.021331em;vertical-align:-0.25em;"></span><span class="mopen">(</span><span class="mopen">[</span><span class="mord">.</span><span class="mord">.</span><span class="mord">.</span><span class="mclose">]</span><span class="mord">∣</span><span class="mord">.</span><span class="mord mathnormal" style="margin-right:0.10764em;">f</span><span class="mord mathnormal">i</span><span class="mord mathnormal">e</span><span class="mord mathnormal" style="margin-right:0.01968em;">l</span><span class="mord mathnormal">d</span><span class="mclose"><span class="mclose">)</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.771331em;"><span style="top:-3.063em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mbin mtight">+</span></span></span></span></span></span></span></span></span></span></span>所访问的嵌套组件:</p>
<ul>
<li><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>s</mi><mtext> </mtext><mi>w</mi><mi>i</mi><mi>t</mi><mi>h</mi><mtext> </mtext><mo stretchy="false">[</mo><mi>i</mi><mo stretchy="false">]</mo><mtext> </mtext><mi>p</mi><mi>t</mi><mi>h</mi><mo>=</mo><mi>A</mi></mrow><annotation encoding="application/x-tex">s\ with\ [i]\ pth = A</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord mathnormal">s</span><span class="mspace"> </span><span class="mord mathnormal" style="margin-right:0.02691em;">w</span><span class="mord mathnormal">i</span><span class="mord mathnormal">t</span><span class="mord mathnormal">h</span><span class="mspace"> </span><span class="mopen">[</span><span class="mord mathnormal">i</span><span class="mclose">]</span><span class="mspace"> </span><span class="mord mathnormal">p</span><span class="mord mathnormal">t</span><span class="mord mathnormal">h</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:0.68333em;vertical-align:0em;"></span><span class="mord mathnormal">A</span></span></span></span>是<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>s</mi><mtext> </mtext><mi>w</mi><mi>i</mi><mi>t</mi><mi>h</mi><mo stretchy="false">[</mo><mi>i</mi><mo stretchy="false">]</mo><mo>=</mo><mo stretchy="false">(</mo><mi>s</mi><mo stretchy="false">[</mo><mi>i</mi><mo stretchy="false">]</mo><mtext> </mtext><mi>w</mi><mi>i</mi><mi>t</mi><mi>h</mi><mtext> </mtext><mi>p</mi><mi>t</mi><mi>h</mi><mo>=</mo><mi>A</mi><mo stretchy="false">)</mo></mrow><annotation encoding="application/x-tex">s\ with [i] =(s[i]\ with\ pth = A)</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord mathnormal">s</span><span class="mspace"> </span><span class="mord mathnormal" style="margin-right:0.02691em;">w</span><span class="mord mathnormal">i</span><span class="mord mathnormal">t</span><span class="mord mathnormal">h</span><span class="mopen">[</span><span class="mord mathnormal">i</span><span class="mclose">]</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mopen">(</span><span class="mord mathnormal">s</span><span class="mopen">[</span><span class="mord mathnormal">i</span><span class="mclose">]</span><span class="mspace"> </span><span class="mord mathnormal" style="margin-right:0.02691em;">w</span><span class="mord mathnormal">i</span><span class="mord mathnormal">t</span><span class="mord mathnormal">h</span><span class="mspace"> </span><span class="mord mathnormal">p</span><span class="mord mathnormal">t</span><span class="mord mathnormal">h</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord mathnormal">A</span><span class="mclose">)</span></span></span></span>的缩写。</li>
<li><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>r</mi><mtext> </mtext><mi>w</mi><mi>i</mi><mi>t</mi><mi>h</mi><mtext> </mtext><mi>f</mi><mi>i</mi><mi>e</mi><mi>l</mi><mi>d</mi><mtext> </mtext><mi>p</mi><mi>t</mi><mi>h</mi><mo>=</mo><mi>A</mi></mrow><annotation encoding="application/x-tex">r\ with\ field\ pth = A</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8888799999999999em;vertical-align:-0.19444em;"></span><span class="mord mathnormal" style="margin-right:0.02778em;">r</span><span class="mspace"> </span><span class="mord mathnormal" style="margin-right:0.02691em;">w</span><span class="mord mathnormal">i</span><span class="mord mathnormal">t</span><span class="mord mathnormal">h</span><span class="mspace"> </span><span class="mord mathnormal" style="margin-right:0.10764em;">f</span><span class="mord mathnormal">i</span><span class="mord mathnormal">e</span><span class="mord mathnormal" style="margin-right:0.01968em;">l</span><span class="mord mathnormal">d</span><span class="mspace"> </span><span class="mord mathnormal">p</span><span class="mord mathnormal">t</span><span class="mord mathnormal">h</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:0.68333em;vertical-align:0em;"></span><span class="mord mathnormal">A</span></span></span></span>是<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>r</mi><mtext> </mtext><mi>w</mi><mi>i</mi><mi>t</mi><mi>h</mi><mtext> </mtext><mi>f</mi><mi>i</mi><mi>e</mi><mi>l</mi><mi>d</mi><mo>=</mo><mo stretchy="false">(</mo><mi>r</mi><mi mathvariant="normal">.</mi><mi>f</mi><mi>i</mi><mi>e</mi><mi>l</mi><mi>d</mi><mtext> </mtext><mi>w</mi><mi>i</mi><mi>t</mi><mi>h</mi><mtext> </mtext><mi>p</mi><mi>t</mi><mi>h</mi><mo>=</mo><mi>A</mi><mo stretchy="false">)</mo></mrow><annotation encoding="application/x-tex">r\ with\ field =(r.field\ with\ pth = A)</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8888799999999999em;vertical-align:-0.19444em;"></span><span class="mord mathnormal" style="margin-right:0.02778em;">r</span><span class="mspace"> </span><span class="mord mathnormal" style="margin-right:0.02691em;">w</span><span class="mord mathnormal">i</span><span class="mord mathnormal">t</span><span class="mord mathnormal">h</span><span class="mspace"> </span><span class="mord mathnormal" style="margin-right:0.10764em;">f</span><span class="mord mathnormal">i</span><span class="mord mathnormal">e</span><span class="mord mathnormal" style="margin-right:0.01968em;">l</span><span class="mord mathnormal">d</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mopen">(</span><span class="mord mathnormal" style="margin-right:0.02778em;">r</span><span class="mord">.</span><span class="mord mathnormal" style="margin-right:0.10764em;">f</span><span class="mord mathnormal">i</span><span class="mord mathnormal">e</span><span class="mord mathnormal" style="margin-right:0.01968em;">l</span><span class="mord mathnormal">d</span><span class="mspace"> </span><span class="mord mathnormal" style="margin-right:0.02691em;">w</span><span class="mord mathnormal">i</span><span class="mord mathnormal">t</span><span class="mord mathnormal">h</span><span class="mspace"> </span><span class="mord mathnormal">p</span><span class="mord mathnormal">t</span><span class="mord mathnormal">h</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord mathnormal">A</span><span class="mclose">)</span></span></span></span>的缩写。</li>
</ul>
<p>其中<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>r</mi><mtext> </mtext><mi>w</mi><mi>i</mi><mi>t</mi><mi>h</mi><mtext> </mtext><mi mathvariant="normal">.</mi><mi>f</mi><mi>i</mi><mi>e</mi><mi>l</mi><mi>d</mi><mo>=</mo><mi>A</mi></mrow><annotation encoding="application/x-tex">r\ with\ .field = A</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8888799999999999em;vertical-align:-0.19444em;"></span><span class="mord mathnormal" style="margin-right:0.02778em;">r</span><span class="mspace"> </span><span class="mord mathnormal" style="margin-right:0.02691em;">w</span><span class="mord mathnormal">i</span><span class="mord mathnormal">t</span><span class="mord mathnormal">h</span><span class="mspace"> </span><span class="mord">.</span><span class="mord mathnormal" style="margin-right:0.10764em;">f</span><span class="mord mathnormal">i</span><span class="mord mathnormal">e</span><span class="mord mathnormal" style="margin-right:0.01968em;">l</span><span class="mord mathnormal">d</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:0.68333em;vertical-align:0em;"></span><span class="mord mathnormal">A</span></span></span></span>缩写为<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>r</mi><mtext> </mtext><mi>w</mi><mi>i</mi><mi>t</mi><mi>h</mi><mtext> </mtext><mi>f</mi><mi>i</mi><mi>e</mi><mi>l</mi><mi>d</mi><mo>=</mo><mi>A</mi></mrow><annotation encoding="application/x-tex">r\ with\ field = A</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8888799999999999em;vertical-align:-0.19444em;"></span><span class="mord mathnormal" style="margin-right:0.02778em;">r</span><span class="mspace"> </span><span class="mord mathnormal" style="margin-right:0.02691em;">w</span><span class="mord mathnormal">i</span><span class="mord mathnormal">t</span><span class="mord mathnormal">h</span><span class="mspace"> </span><span class="mord mathnormal" style="margin-right:0.10764em;">f</span><span class="mord mathnormal">i</span><span class="mord mathnormal">e</span><span class="mord mathnormal" style="margin-right:0.01968em;">l</span><span class="mord mathnormal">d</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:0.68333em;vertical-align:0em;"></span><span class="mord mathnormal">A</span></span></span></span></p>
<h4 id="213-向量"><a class="markdownIt-Anchor" href="#213-向量"></a> 2.1.3. 向量</h4>
<p>向量是形式为<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msup><mi>A</mi><mi>n</mi></msup></mrow><annotation encoding="application/x-tex">A^n</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.68333em;vertical-align:0em;"></span><span class="mord"><span class="mord mathnormal">A</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.664392em;"><span style="top:-3.063em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">n</span></span></span></span></span></span></span></span></span></span></span>(或<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msup><mi>A</mi><mo>∗</mo></msup></mrow><annotation encoding="application/x-tex">A^*</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.688696em;vertical-align:0em;"></span><span class="mord"><span class="mord mathnormal">A</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.688696em;"><span style="top:-3.063em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mbin mtight">∗</span></span></span></span></span></span></span></span></span></span></span>)的有界序列,其中A可以是值或复杂的构造。一个向量最多可包含<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msup><mn>2</mn><mn>3</mn></msup><mn>2</mn><mo>−</mo><mn>1</mn></mrow><annotation encoding="application/x-tex">2^32-1</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.897438em;vertical-align:-0.08333em;"></span><span class="mord"><span class="mord">2</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.8141079999999999em;"><span style="top:-3.063em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">3</span></span></span></span></span></span></span></span><span class="mord">2</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">−</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span></span><span class="base"><span class="strut" style="height:0.64444em;vertical-align:0em;"></span><span class="mord">1</span></span></span></span>(即MaxUint256)个元素。</p>
<p class='katex-block'><span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><mi>v</mi><mi>e</mi><mi>c</mi><mo stretchy="false">(</mo><mi>A</mi><mo stretchy="false">)</mo><mo>:</mo><mo>:</mo><mo>=</mo><msup><mi>A</mi><mi>n</mi></msup><mtext> </mtext><mo stretchy="false">(</mo><mi>i</mi><mi>f</mi><mtext> </mtext><mi>n</mi><mo><</mo><msup><mn>2</mn><mn>32</mn></msup><mo stretchy="false">)</mo></mrow><annotation encoding="application/x-tex">vec(A) ::= A^n\ (if\ n<2^{32})
</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord mathnormal" style="margin-right:0.03588em;">v</span><span class="mord mathnormal">e</span><span class="mord mathnormal">c</span><span class="mopen">(</span><span class="mord mathnormal">A</span><span class="mclose">)</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">:</span></span><span class="base"><span class="strut" style="height:0.43056em;vertical-align:0em;"></span><span class="mrel">:</span></span><span class="base"><span class="strut" style="height:0.36687em;vertical-align:0em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord"><span class="mord mathnormal">A</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.7143919999999999em;"><span style="top:-3.113em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">n</span></span></span></span></span></span></span></span><span class="mspace"> </span><span class="mopen">(</span><span class="mord mathnormal">i</span><span class="mord mathnormal" style="margin-right:0.10764em;">f</span><span class="mspace"> </span><span class="mord mathnormal">n</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel"><</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:1.1141079999999999em;vertical-align:-0.25em;"></span><span class="mord"><span class="mord">2</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.8641079999999999em;"><span style="top:-3.113em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mtight">3</span><span class="mord mtight">2</span></span></span></span></span></span></span></span></span><span class="mclose">)</span></span></span></span></span></p>
<h3 id="22-值"><a class="markdownIt-Anchor" href="#22-值"></a> 2.2. 值</h3>
<p>WebAssembly程序对原始数值进行操作。<br />
此外,在程序的定义中,值的不可变序列出现以表示更复杂的数据,例如文本字符串或其他向量。</p>
<h4 id="221-bytes"><a class="markdownIt-Anchor" href="#221-bytes"></a> 2.2.1. Bytes</h4>
<p>值的最简单形式是未解释的原始字节。<br />
在抽象语法中,它们表示为十六进制文字。</p>
<p class='katex-block'><span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><mi>b</mi><mi>y</mi><mi>t</mi><mi>e</mi><mtext></mtext><mo>:</mo><mo>:</mo><mo>=</mo><mtext></mtext><mn>0</mn><mi>x</mi><mn>00</mn><mi mathvariant="normal">∣</mi><mi mathvariant="normal">.</mi><mi mathvariant="normal">.</mi><mi mathvariant="normal">.</mi><mi mathvariant="normal">∣</mi><mn>0</mn><mi>x</mi><mi>F</mi><mi>F</mi><mtext></mtext></mrow><annotation encoding="application/x-tex">byte::=0x00 |...| 0xFF
</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8888799999999999em;vertical-align:-0.19444em;"></span><span class="mord mathnormal">b</span><span class="mord mathnormal" style="margin-right:0.03588em;">y</span><span class="mord mathnormal">t</span><span class="mord mathnormal">e</span><span class="mord"></span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">:</span></span><span class="base"><span class="strut" style="height:0.43056em;vertical-align:0em;"></span><span class="mrel">:</span></span><span class="base"><span class="strut" style="height:0.36687em;vertical-align:0em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord"></span><span class="mord">0</span><span class="mord mathnormal">x</span><span class="mord">0</span><span class="mord">0</span><span class="mord">∣</span><span class="mord">.</span><span class="mord">.</span><span class="mord">.</span><span class="mord">∣</span><span class="mord">0</span><span class="mord mathnormal">x</span><span class="mord mathnormal" style="margin-right:0.13889em;">F</span><span class="mord mathnormal" style="margin-right:0.13889em;">F</span><span class="mord"></span></span></span></span></span></p>
<h5 id="2211-惯例"><a class="markdownIt-Anchor" href="#2211-惯例"></a> 2.2.1.1. 惯例</h5>
<ul>
<li>
<p>元变量<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>b</mi></mrow><annotation encoding="application/x-tex">b</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.69444em;vertical-align:0em;"></span><span class="mord mathnormal">b</span></span></span></span>的范围为字节。</p>
</li>
<li>
<p>字节有时被解释为自然数<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>n</mi><mo><</mo><mn>256</mn></mrow><annotation encoding="application/x-tex">n < 256</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.5782em;vertical-align:-0.0391em;"></span><span class="mord mathnormal">n</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel"><</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:0.64444em;vertical-align:0em;"></span><span class="mord">2</span><span class="mord">5</span><span class="mord">6</span></span></span></span>。</p>
</li>
</ul>
<p>2.2.2. 整数</p>
<p>具有不同值范围的不同类别的整数通过其<em>位宽</em><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>N</mi></mrow><annotation encoding="application/x-tex">N</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.68333em;vertical-align:0em;"></span><span class="mord mathnormal" style="margin-right:0.10903em;">N</span></span></span></span>以及是<em>无符号</em>还是<em>有符号</em>来区分。</p>
<p class='katex-block'><span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><mi>u</mi><mi>N</mi><mo>:</mo><mo>:</mo><mo>=</mo><mn>0</mn><mi mathvariant="normal">∣</mi><mn>1</mn><mi mathvariant="normal">∣</mi><mi mathvariant="normal">.</mi><mi mathvariant="normal">.</mi><mi mathvariant="normal">.</mi><mi mathvariant="normal">∣</mi><msup><mn>2</mn><mi>N</mi></msup><mo>−</mo><mn>1</mn></mrow><annotation encoding="application/x-tex">uN ::= 0 | 1| ... | 2^N-1
</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.68333em;vertical-align:0em;"></span><span class="mord mathnormal">u</span><span class="mord mathnormal" style="margin-right:0.10903em;">N</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">:</span></span><span class="base"><span class="strut" style="height:0.43056em;vertical-align:0em;"></span><span class="mrel">:</span></span><span class="base"><span class="strut" style="height:0.36687em;vertical-align:0em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:1.1413309999999999em;vertical-align:-0.25em;"></span><span class="mord">0</span><span class="mord">∣</span><span class="mord">1</span><span class="mord">∣</span><span class="mord">.</span><span class="mord">.</span><span class="mord">.</span><span class="mord">∣</span><span class="mord"><span class="mord">2</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.8913309999999999em;"><span style="top:-3.113em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight" style="margin-right:0.10903em;">N</span></span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">−</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span></span><span class="base"><span class="strut" style="height:0.64444em;vertical-align:0em;"></span><span class="mord">1</span></span></span></span></span></p>
<p class='katex-block'><span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><mi>s</mi><mi>N</mi><mo>:</mo><mo>:</mo><mo>=</mo><mo>−</mo><msup><mn>2</mn><mi>N</mi></msup><mo>−</mo><mn>1</mn><mi mathvariant="normal">∣</mi><mi mathvariant="normal">.</mi><mi mathvariant="normal">.</mi><mi mathvariant="normal">.</mi><mi mathvariant="normal">∣</mi><mo>−</mo><mn>1</mn><mi mathvariant="normal">∣</mi><mn>0</mn><mi mathvariant="normal">∣</mi><mn>1</mn><mi mathvariant="normal">∣</mi><mi mathvariant="normal">.</mi><mi mathvariant="normal">.</mi><mi mathvariant="normal">.</mi><mi mathvariant="normal">∣</mi><msup><mn>2</mn><mi>N</mi></msup><mo>−</mo><mn>1</mn></mrow><annotation encoding="application/x-tex">sN ::= -2^N-1|...| -1 | 0 | 1 | ... | 2^N-1
</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.68333em;vertical-align:0em;"></span><span class="mord mathnormal">s</span><span class="mord mathnormal" style="margin-right:0.10903em;">N</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">:</span></span><span class="base"><span class="strut" style="height:0.43056em;vertical-align:0em;"></span><span class="mrel">:</span></span><span class="base"><span class="strut" style="height:0.36687em;vertical-align:0em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:0.9746609999999999em;vertical-align:-0.08333em;"></span><span class="mord">−</span><span class="mord"><span class="mord">2</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.8913309999999999em;"><span style="top:-3.113em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight" style="margin-right:0.10903em;">N</span></span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">−</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord">1</span><span class="mord">∣</span><span class="mord">.</span><span class="mord">.</span><span class="mord">.</span><span class="mord">∣</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">−</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span></span><span class="base"><span class="strut" style="height:1.1413309999999999em;vertical-align:-0.25em;"></span><span class="mord">1</span><span class="mord">∣</span><span class="mord">0</span><span class="mord">∣</span><span class="mord">1</span><span class="mord">∣</span><span class="mord">.</span><span class="mord">.</span><span class="mord">.</span><span class="mord">∣</span><span class="mord"><span class="mord">2</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.8913309999999999em;"><span style="top:-3.113em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight" style="margin-right:0.10903em;">N</span></span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">−</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span></span><span class="base"><span class="strut" style="height:0.64444em;vertical-align:0em;"></span><span class="mord">1</span></span></span></span></span></p>
<p class='katex-block'><span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><mi>i</mi><mi>N</mi><mo>:</mo><mo>:</mo><mo>=</mo><mi>u</mi><mi>N</mi></mrow><annotation encoding="application/x-tex">iN ::= uN
</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.68333em;vertical-align:0em;"></span><span class="mord mathnormal">i</span><span class="mord mathnormal" style="margin-right:0.10903em;">N</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">:</span></span><span class="base"><span class="strut" style="height:0.43056em;vertical-align:0em;"></span><span class="mrel">:</span></span><span class="base"><span class="strut" style="height:0.36687em;vertical-align:0em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:0.68333em;vertical-align:0em;"></span><span class="mord mathnormal">u</span><span class="mord mathnormal" style="margin-right:0.10903em;">N</span></span></span></span></span></p>
<p>后者定义了未解释的整数,其有符号性解释会根据上下文而变化。<br />
在抽象语法中,它们表示为无符号值。<br />
但是,某些运算会根据二进制补码解释将其转换为带符号。</p>
<blockquote>
<p>注意</p>
<p>在本规范中出现的主要整数类型是u32,u64,s32,s64,i8,i16,i32,i64。但是,例如在浮点数的定义中,其他大小也可以作为辅助结构。</p>
</blockquote>
<h5 id="2221-惯例"><a class="markdownIt-Anchor" href="#2221-惯例"></a> 2.2.2.1. 惯例</h5>
<ul>
<li>元变量<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>m</mi><mtext>,</mtext><mi>n</mi><mtext>,</mtext><mi>i</mi></mrow><annotation encoding="application/x-tex">m,n,i</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.68333em;vertical-align:0em;"></span><span class="mord mathnormal">m</span><span class="mord cjk_fallback">,</span><span class="mord mathnormal">n</span><span class="mord cjk_fallback">,</span><span class="mord mathnormal">i</span></span></span></span>的范围是整数。</li>
<li>如上面的语法所示,数字可以用简单的算术表示。<br />
为了区分<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msup><mn>2</mn><mi>N</mi></msup></mrow><annotation encoding="application/x-tex">2^N</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8413309999999999em;vertical-align:0em;"></span><span class="mord"><span class="mord">2</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.8413309999999999em;"><span style="top:-3.063em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight" style="margin-right:0.10903em;">N</span></span></span></span></span></span></span></span></span></span></span>之类的算术与<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mo stretchy="false">(</mo><mn>1</mn><msup><mo stretchy="false">)</mo><mi>N</mi></msup></mrow><annotation encoding="application/x-tex">(1)^N</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:1.0913309999999998em;vertical-align:-0.25em;"></span><span class="mopen">(</span><span class="mord">1</span><span class="mclose"><span class="mclose">)</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.8413309999999999em;"><span style="top:-3.063em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight" style="margin-right:0.10903em;">N</span></span></span></span></span></span></span></span></span></span></span>之类的序列,用括号将后者区分。</li>
</ul>
<h4 id="223-浮点数"><a class="markdownIt-Anchor" href="#223-浮点数"></a> 2.2.3. 浮点数</h4>
<p>浮点数据表示32或64位值,它们对应于[IEEE-754-2019]标准(第3.3节)的相应二进制格式。</p>
<p>每个值都有一个符号和大小。 幅值可以表示为形式为<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>m</mi><mn>0</mn></msub><msub><mi>m</mi><mn>1</mn></msub><msub><mi>m</mi><mn>2</mn></msub><mo>…</mo><msub><mi>m</mi><mi>M</mi></msub><mo>⋅</mo><msup><mn>2</mn><mi>e</mi></msup></mrow><annotation encoding="application/x-tex">m_0 m_1 m_2 \ldots m_M \cdot 2^e</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.59445em;vertical-align:-0.15em;"></span><span class="mord"><span class="mord mathnormal">m</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.30110799999999993em;"><span style="top:-2.5500000000000003em;margin-left:0em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">0</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mord"><span class="mord mathnormal">m</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.30110799999999993em;"><span style="top:-2.5500000000000003em;margin-left:0em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">1</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mord"><span class="mord mathnormal">m</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.30110799999999993em;"><span style="top:-2.5500000000000003em;margin-left:0em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">2</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.16666666666666666em;"></span><span class="minner">…</span><span class="mspace" style="margin-right:0.16666666666666666em;"></span><span class="mord"><span class="mord mathnormal">m</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.32833099999999993em;"><span style="top:-2.5500000000000003em;margin-left:0em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight" style="margin-right:0.10903em;">M</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">⋅</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span></span><span class="base"><span class="strut" style="height:0.664392em;vertical-align:0em;"></span><span class="mord"><span class="mord">2</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.664392em;"><span style="top:-3.063em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">e</span></span></span></span></span></span></span></span></span></span></span>的正态数,其中<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>e</mi></mrow><annotation encoding="application/x-tex">e</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.43056em;vertical-align:0em;"></span><span class="mord mathnormal">e</span></span></span></span>是指数,m是其最高位<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>m</mi><mn>0</mn></msub></mrow><annotation encoding="application/x-tex">m_0</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.58056em;vertical-align:-0.15em;"></span><span class="mord"><span class="mord mathnormal">m</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.30110799999999993em;"><span style="top:-2.5500000000000003em;margin-left:0em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">0</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span></span></span>为1的有效数,或者以次正规数来表示 指数固定为最小可能值,且<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>m</mi><mn>0</mn></msub></mrow><annotation encoding="application/x-tex">m_0</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.58056em;vertical-align:-0.15em;"></span><span class="mord"><span class="mord mathnormal">m</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.30110799999999993em;"><span style="top:-2.5500000000000003em;margin-left:0em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">0</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span></span></span>为0; 在次法线中的是零正值和负值。 由于有效位数是二进制值,因此法线以<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mo stretchy="false">(</mo><mn>1</mn><mo>+</mo><mi>m</mi><mo>⋅</mo><msup><mn>2</mn><mrow><mo>−</mo><mi>M</mi></mrow></msup><mo stretchy="false">)</mo><mo>⋅</mo><mn>2</mn><mi>e</mi></mrow><annotation encoding="application/x-tex">(1 +m\cdot 2^{-M})\cdot 2e</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mopen">(</span><span class="mord">1</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">+</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span></span><span class="base"><span class="strut" style="height:0.44445em;vertical-align:0em;"></span><span class="mord mathnormal">m</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">⋅</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span></span><span class="base"><span class="strut" style="height:1.0913309999999998em;vertical-align:-0.25em;"></span><span class="mord"><span class="mord">2</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.8413309999999999em;"><span style="top:-3.063em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mtight">−</span><span class="mord mathnormal mtight" style="margin-right:0.10903em;">M</span></span></span></span></span></span></span></span></span><span class="mclose">)</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">⋅</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span></span><span class="base"><span class="strut" style="height:0.64444em;vertical-align:0em;"></span><span class="mord">2</span><span class="mord mathnormal">e</span></span></span></span>的形式表示,其中<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>M</mi></mrow><annotation encoding="application/x-tex">M</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.68333em;vertical-align:0em;"></span><span class="mord mathnormal" style="margin-right:0.10903em;">M</span></span></span></span>是<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>m</mi></mrow><annotation encoding="application/x-tex">m</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.43056em;vertical-align:0em;"></span><span class="mord mathnormal">m</span></span></span></span>的位宽; 对于次普通人也是如此。</p>
<p>可能的大小还包括特殊值<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi mathvariant="normal">∞</mi></mrow><annotation encoding="application/x-tex">\infty</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.43056em;vertical-align:0em;"></span><span class="mord">∞</span></span></span></span>(无穷大)和nan(即NaN,非数字)。NaN值具有一个有效载荷,该载荷描述了基础二进制表示形式中的尾数位。 信号和安静的NaN之间没有区别。</p>
<p class='katex-block'><span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><mi>f</mi><mi>N</mi><mo>:</mo><mo>:</mo><mo>=</mo><mo>+</mo><mi>f</mi><mi>N</mi><mi>m</mi><mi>a</mi><mi>g</mi><mi mathvariant="normal">∣</mi><mo>−</mo><mi>f</mi><mi>N</mi><mi>m</mi><mi>a</mi><mi>g</mi></mrow><annotation encoding="application/x-tex">fN ::= +fNmag | -fNmag
</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8888799999999999em;vertical-align:-0.19444em;"></span><span class="mord mathnormal" style="margin-right:0.10764em;">f</span><span class="mord mathnormal" style="margin-right:0.10903em;">N</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">:</span></span><span class="base"><span class="strut" style="height:0.43056em;vertical-align:0em;"></span><span class="mrel">:</span></span><span class="base"><span class="strut" style="height:0.36687em;vertical-align:0em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord">+</span><span class="mord mathnormal" style="margin-right:0.10764em;">f</span><span class="mord mathnormal" style="margin-right:0.10903em;">N</span><span class="mord mathnormal">m</span><span class="mord mathnormal">a</span><span class="mord mathnormal" style="margin-right:0.03588em;">g</span><span class="mord">∣</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">−</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span></span><span class="base"><span class="strut" style="height:0.8888799999999999em;vertical-align:-0.19444em;"></span><span class="mord mathnormal" style="margin-right:0.10764em;">f</span><span class="mord mathnormal" style="margin-right:0.10903em;">N</span><span class="mord mathnormal">m</span><span class="mord mathnormal">a</span><span class="mord mathnormal" style="margin-right:0.03588em;">g</span></span></span></span></span></p>
<p class='katex-block katex-error' title='ParseError: KaTeX parse error: Undefined control sequence: \displaylines at position 1: \̲d̲i̲s̲p̲l̲a̲y̲l̲i̲n̲e̲s̲{fNmag ::=(1+uM…'>\displaylines{fNmag ::=(1+uM\cdot 2^{-M})\cdot 2^e ((if\ −2^{E−1} + 2 \leq e \leq 2^{E−1}−1))\\
|\ (0+uM\cdot 2^{-M})\cdot 2^e (if\ e=-2^{E-1}+2)\\
\infty\\
nan(n)\ (if 1\leq n\lt 2^M)}</p>
<p>当 M=signif(N) 且 E=expon(N) 则</p>
<p class='katex-block katex-error' title='ParseError: KaTeX parse error: Undefined control sequence: \displaylines at position 1: \̲d̲i̲s̲p̲l̲a̲y̲l̲i̲n̲e̲s̲{signif(32) = 2…'>\displaylines{signif(32) = 23 \\
expon(32) =8 \\
signif(64)=52\\
expon(64)=11}</p>
<p>一个*规范的(canonical)*NaN是浮点数值<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mo>±</mo><mi>n</mi><mi>a</mi><mi>n</mi><mo stretchy="false">(</mo><mi>c</mi><mi>a</mi><mi>n</mi><mi>o</mi><msub><mi>n</mi><mi>N</mi></msub><mo stretchy="false">)</mo></mrow><annotation encoding="application/x-tex">\pm nan(canon_N)</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord">±</span><span class="mord mathnormal">n</span><span class="mord mathnormal">a</span><span class="mord mathnormal">n</span><span class="mopen">(</span><span class="mord mathnormal">c</span><span class="mord mathnormal">a</span><span class="mord mathnormal">n</span><span class="mord mathnormal">o</span><span class="mord"><span class="mord mathnormal">n</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.32833099999999993em;"><span style="top:-2.5500000000000003em;margin-left:0em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight" style="margin-right:0.10903em;">N</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mclose">)</span></span></span></span>,其中<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>c</mi><mi>a</mi><mi>n</mi><mi>o</mi><msub><mi>n</mi><mi>N</mi></msub></mrow><annotation encoding="application/x-tex">canon_N</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.58056em;vertical-align:-0.15em;"></span><span class="mord mathnormal">c</span><span class="mord mathnormal">a</span><span class="mord mathnormal">n</span><span class="mord mathnormal">o</span><span class="mord"><span class="mord mathnormal">n</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.32833099999999993em;"><span style="top:-2.5500000000000003em;margin-left:0em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight" style="margin-right:0.10903em;">N</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span></span></span>是有效载荷,其最高有效位为1而所有其他均为0:</p>
<p class='katex-block'><span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><mi>c</mi><mi>a</mi><mi>n</mi><mi>o</mi><msub><mi>n</mi><mi>N</mi></msub><mo>=</mo><msup><mn>2</mn><mrow><mi>s</mi><mi>i</mi><mi>g</mi><mi>n</mi><mi>i</mi><mi>f</mi><mo stretchy="false">(</mo><mi>N</mi><mo stretchy="false">)</mo><mo>−</mo><mn>1</mn></mrow></msup></mrow><annotation encoding="application/x-tex">canon_N = 2^{signif(N)-1}
</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.58056em;vertical-align:-0.15em;"></span><span class="mord mathnormal">c</span><span class="mord mathnormal">a</span><span class="mord mathnormal">n</span><span class="mord mathnormal">o</span><span class="mord"><span class="mord mathnormal">n</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.32833099999999993em;"><span style="top:-2.5500000000000003em;margin-left:0em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight" style="margin-right:0.10903em;">N</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:0.938em;vertical-align:0em;"></span><span class="mord"><span class="mord">2</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.938em;"><span style="top:-3.113em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathnormal mtight">s</span><span class="mord mathnormal mtight">i</span><span class="mord mathnormal mtight" style="margin-right:0.03588em;">g</span><span class="mord mathnormal mtight">n</span><span class="mord mathnormal mtight">i</span><span class="mord mathnormal mtight" style="margin-right:0.10764em;">f</span><span class="mopen mtight">(</span><span class="mord mathnormal mtight" style="margin-right:0.10903em;">N</span><span class="mclose mtight">)</span><span class="mbin mtight">−</span><span class="mord mtight">1</span></span></span></span></span></span></span></span></span></span></span></span></span></p>
<p>一个*算术(arithmetic)*NaN是<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>n</mi><mo>≥</mo><mi>c</mi><mi>a</mi><mi>n</mi><mi>o</mi><msub><mi>n</mi><mi>N</mi></msub></mrow><annotation encoding="application/x-tex">n\geq canon_N</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.7719400000000001em;vertical-align:-0.13597em;"></span><span class="mord mathnormal">n</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">≥</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:0.58056em;vertical-align:-0.15em;"></span><span class="mord mathnormal">c</span><span class="mord mathnormal">a</span><span class="mord mathnormal">n</span><span class="mord mathnormal">o</span><span class="mord"><span class="mord mathnormal">n</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.32833099999999993em;"><span style="top:-2.5500000000000003em;margin-left:0em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight" style="margin-right:0.10903em;">N</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span></span></span>的浮点值<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mo>±</mo><mi>n</mi><mi>a</mi><mi>n</mi><mo stretchy="false">(</mo><mi>n</mi><mo stretchy="false">)</mo></mrow><annotation encoding="application/x-tex">\pm nan(n)</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord">±</span><span class="mord mathnormal">n</span><span class="mord mathnormal">a</span><span class="mord mathnormal">n</span><span class="mopen">(</span><span class="mord mathnormal">n</span><span class="mclose">)</span></span></span></span>,因此最高有效位为1,其他所有位均为任意。</p>
<blockquote>
<p>注意</p>
<p>在抽象语法中,子范数以有效数字的前导0区分。 次正态的指数与正态数的最小可能指数具有相同的值。 仅在二进制表示中,次正态的指数与任何正态数的指数的编码方式不同。</p>
</blockquote>
<h5 id="2231-惯例"><a class="markdownIt-Anchor" href="#2231-惯例"></a> 2.2.3.1. 惯例</h5>
<ul>
<li>元变量z取自从上下文清晰可辨的浮点值。</li>
</ul>
<h4 id="224-名称names"><a class="markdownIt-Anchor" href="#224-名称names"></a> 2.2.4. 名称Names</h4>
<p>名称是字符序列,是[UNICODE](第2.4节)定义的标量值。</p>
<p class='katex-block katex-error' title='ParseError: KaTeX parse error: Undefined control sequence: \displaylines at position 1: \̲d̲i̲s̲p̲l̲a̲y̲l̲i̲n̲e̲s̲{name::= char^*…'>\displaylines{name::= char^* \ (if\ |utf8(char^*)|<2^{32})\\
char ::= U+00|\ldots|U+D7FF|U+E000|...U+10FFFF}</p>
<p>由于二进制格式的限制,名称的长度受其UTF-8编码的长度限制。</p>
<h5 id="2241-惯例"><a class="markdownIt-Anchor" href="#2241-惯例"></a> 2.2.4.1. 惯例</h5>
<ul>
<li>字符(Unicode标量值)有时与n <1114112的自然数互换使用。</li>
</ul>
<h3 id="23-类型types"><a class="markdownIt-Anchor" href="#23-类型types"></a> 2.3 类型Types</h3>
<p>WebAssembly中的各种实体按类型分类。<br />
在验证,实例化以及可能的执行期间检查类型。</p>
<h4 id="231-值value类型"><a class="markdownIt-Anchor" href="#231-值value类型"></a> 2.3.1 值(Value)类型</h4>
<p>值类型对WebAssembly代码可以计算的单个值以及变量接受的值进行分类。</p>
<p class='katex-block'><span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><mi>v</mi><mi>a</mi><mi>l</mi><mi>t</mi><mi>y</mi><mi>p</mi><mi>e</mi><mo>:</mo><mo>:</mo><mo>=</mo><mi>i</mi><mn>32</mn><mi mathvariant="normal">∣</mi><mi>i</mi><mn>64</mn><mi mathvariant="normal">∣</mi><mi>f</mi><mn>32</mn><mi mathvariant="normal">∣</mi><mi>f</mi><mn>64</mn></mrow><annotation encoding="application/x-tex">valtype ::= i32|i64|f32|f64
</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8888799999999999em;vertical-align:-0.19444em;"></span><span class="mord mathnormal" style="margin-right:0.03588em;">v</span><span class="mord mathnormal">a</span><span class="mord mathnormal" style="margin-right:0.01968em;">l</span><span class="mord mathnormal">t</span><span class="mord mathnormal" style="margin-right:0.03588em;">y</span><span class="mord mathnormal">p</span><span class="mord mathnormal">e</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">:</span></span><span class="base"><span class="strut" style="height:0.43056em;vertical-align:0em;"></span><span class="mrel">:</span></span><span class="base"><span class="strut" style="height:0.36687em;vertical-align:0em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord mathnormal">i</span><span class="mord">3</span><span class="mord">2</span><span class="mord">∣</span><span class="mord mathnormal">i</span><span class="mord">6</span><span class="mord">4</span><span class="mord">∣</span><span class="mord mathnormal" style="margin-right:0.10764em;">f</span><span class="mord">3</span><span class="mord">2</span><span class="mord">∣</span><span class="mord mathnormal" style="margin-right:0.10764em;">f</span><span class="mord">6</span><span class="mord">4</span></span></span></span></span></p>
<p>i32和i64类型分别将32位和64位整数分类。<br />
整数不是固有地带符号或无符号的,它们的解释由单个操作确定。</p>
<p>f32和f64类型分别将32位和64位浮点数分类。<br />
它们分别对应于[IEEE-754-2019]标准(第3.3节)定义的相应二进制浮点表示形式,也称为单精度和双精度。</p>
<h5 id="2331-惯例"><a class="markdownIt-Anchor" href="#2331-惯例"></a> 2.3.3.1. 惯例</h5>
<ul>
<li>元变量t可以从清晰的上下文中范围内的值类型。</li>
<li>符号<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi mathvariant="normal">∣</mi><mi>t</mi><mi mathvariant="normal">∣</mi></mrow><annotation encoding="application/x-tex">|t|</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord">∣</span><span class="mord mathnormal">t</span><span class="mord">∣</span></span></span></span>表示值类型的位宽。即,<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi mathvariant="normal">∣</mi><mi>i</mi><mn>32</mn><mi mathvariant="normal">∣</mi><mo>=</mo><mi mathvariant="normal">∣</mi><mi>f</mi><mn>32</mn><mi mathvariant="normal">∣</mi><mo>=</mo><mn>32</mn></mrow><annotation encoding="application/x-tex">|i32|=|f32|=32</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord">∣</span><span class="mord mathnormal">i</span><span class="mord">3</span><span class="mord">2</span><span class="mord">∣</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord">∣</span><span class="mord mathnormal" style="margin-right:0.10764em;">f</span><span class="mord">3</span><span class="mord">2</span><span class="mord">∣</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:0.64444em;vertical-align:0em;"></span><span class="mord">3</span><span class="mord">2</span></span></span></span>和<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi mathvariant="normal">∣</mi><mi>i</mi><mn>64</mn><mi mathvariant="normal">∣</mi><mo>=</mo><mi mathvariant="normal">∣</mi><mi>f</mi><mn>64</mn><mi mathvariant="normal">∣</mi><mtext>=</mtext><mn>64</mn></mrow><annotation encoding="application/x-tex">|i64|=|f64|=64</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord">∣</span><span class="mord mathnormal">i</span><span class="mord">6</span><span class="mord">4</span><span class="mord">∣</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord">∣</span><span class="mord mathnormal" style="margin-right:0.10764em;">f</span><span class="mord">6</span><span class="mord">4</span><span class="mord">∣</span><span class="mord cjk_fallback">=</span><span class="mord">6</span><span class="mord">4</span></span></span></span>。</li>
</ul>
<h4 id="232-结果result类型"><a class="markdownIt-Anchor" href="#232-结果result类型"></a> 2.3.2. 结果(Result)类型</h4>
<p>结果类型对执行指令或块的结果进行分类,该指令或块是用括号写入的一系列值。</p>
<p class='katex-block'><span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><mi>r</mi><mi>e</mi><mi>s</mi><mi>u</mi><mi>l</mi><mi>t</mi><mi>t</mi><mi>y</mi><mi>l</mi><mi>e</mi><mo>:</mo><mo>:</mo><mo>=</mo><mo stretchy="false">[</mo><mi>v</mi><mi>a</mi><mi>l</mi><mi>t</mi><mi>y</mi><mi>p</mi><msup><mi>e</mi><mo stretchy="false">?</mo></msup><mo stretchy="false">]</mo></mrow><annotation encoding="application/x-tex">resulttyle ::= [valtype^?]
</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8888799999999999em;vertical-align:-0.19444em;"></span><span class="mord mathnormal" style="margin-right:0.02778em;">r</span><span class="mord mathnormal">e</span><span class="mord mathnormal">s</span><span class="mord mathnormal">u</span><span class="mord mathnormal" style="margin-right:0.01968em;">l</span><span class="mord mathnormal">t</span><span class="mord mathnormal">t</span><span class="mord mathnormal" style="margin-right:0.03588em;">y</span><span class="mord mathnormal" style="margin-right:0.01968em;">l</span><span class="mord mathnormal">e</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">:</span></span><span class="base"><span class="strut" style="height:0.43056em;vertical-align:0em;"></span><span class="mrel">:</span></span><span class="base"><span class="strut" style="height:0.36687em;vertical-align:0em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:1.149108em;vertical-align:-0.25em;"></span><span class="mopen">[</span><span class="mord mathnormal" style="margin-right:0.03588em;">v</span><span class="mord mathnormal">a</span><span class="mord mathnormal" style="margin-right:0.01968em;">l</span><span class="mord mathnormal">t</span><span class="mord mathnormal" style="margin-right:0.03588em;">y</span><span class="mord mathnormal">p</span><span class="mord"><span class="mord mathnormal">e</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.8991079999999999em;"><span style="top:-3.113em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mclose mtight">?</span></span></span></span></span></span></span></span><span class="mclose">]</span></span></span></span></span></p>
<blockquote>
<p>注意</p>
<p>在当前版本的WebAssembly中,结果最多允许一个值。但是,这可能会泛化为将来版本中的值序列。</p>
</blockquote>
<h4 id="233-函数function类型"><a class="markdownIt-Anchor" href="#233-函数function类型"></a> 2.3.3 函数(Function)类型</h4>
<p>函数类型对函数的签名进行分类,将参数向量映射到结果向量,如下所示。</p>
<p class='katex-block'><span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><mi>f</mi><mi>u</mi><mi>n</mi><mi>c</mi><mi>t</mi><mi>y</mi><mi>p</mi><mi>e</mi><mo>:</mo><mo>:</mo><mo>=</mo><mo stretchy="false">[</mo><mi>v</mi><mi>e</mi><mi>c</mi><mo stretchy="false">(</mo><mi>v</mi><mi>a</mi><mi>l</mi><mi>t</mi><mi>y</mi><mi>p</mi><mi>e</mi><mo stretchy="false">)</mo><mo stretchy="false">]</mo><mo>−</mo><mo>></mo><mo stretchy="false">[</mo><mi>v</mi><mi>e</mi><mi>c</mi><mo stretchy="false">(</mo><mi>v</mi><mi>a</mi><mi>l</mi><mi>t</mi><mi>y</mi><mi>p</mi><mi>e</mi><mo stretchy="false">)</mo><mo stretchy="false">]</mo></mrow><annotation encoding="application/x-tex">functype ::= [vec(valtype)] -> [vec(valtype)]
</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8888799999999999em;vertical-align:-0.19444em;"></span><span class="mord mathnormal" style="margin-right:0.10764em;">f</span><span class="mord mathnormal">u</span><span class="mord mathnormal">n</span><span class="mord mathnormal">c</span><span class="mord mathnormal">t</span><span class="mord mathnormal" style="margin-right:0.03588em;">y</span><span class="mord mathnormal">p</span><span class="mord mathnormal">e</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">:</span></span><span class="base"><span class="strut" style="height:0.43056em;vertical-align:0em;"></span><span class="mrel">:</span></span><span class="base"><span class="strut" style="height:0.36687em;vertical-align:0em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mopen">[</span><span class="mord mathnormal" style="margin-right:0.03588em;">v</span><span class="mord mathnormal">e</span><span class="mord mathnormal">c</span><span class="mopen">(</span><span class="mord mathnormal" style="margin-right:0.03588em;">v</span><span class="mord mathnormal">a</span><span class="mord mathnormal" style="margin-right:0.01968em;">l</span><span class="mord mathnormal">t</span><span class="mord mathnormal" style="margin-right:0.03588em;">y</span><span class="mord mathnormal">p</span><span class="mord mathnormal">e</span><span class="mclose">)</span><span class="mclose">]</span><span class="mord">−</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">></span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mopen">[</span><span class="mord mathnormal" style="margin-right:0.03588em;">v</span><span class="mord mathnormal">e</span><span class="mord mathnormal">c</span><span class="mopen">(</span><span class="mord mathnormal" style="margin-right:0.03588em;">v</span><span class="mord mathnormal">a</span><span class="mord mathnormal" style="margin-right:0.01968em;">l</span><span class="mord mathnormal">t</span><span class="mord mathnormal" style="margin-right:0.03588em;">y</span><span class="mord mathnormal">p</span><span class="mord mathnormal">e</span><span class="mclose">)</span><span class="mclose">]</span></span></span></span></span></p>
<blockquote>
<p>注意</p>
<p>在当前版本的WebAssembly中,有效函数类型的结果类型向量的长度最多为1。此限制在将来的版本中可能会消除。</p>
</blockquote>
<h4 id="234-限制"><a class="markdownIt-Anchor" href="#234-限制"></a> 2.3.4. 限制</h4>
<p>限制对与内存类型和表类型关联的可调整大小的存储的大小范围进行分类。</p>
<p class='katex-block'><span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><mi>l</mi><mi>i</mi><mi>m</mi><mi>i</mi><mi>t</mi><mi>s</mi><mo>:</mo><mo>:</mo><mo>=</mo><mrow><mi>m</mi><mi>i</mi><mi>n</mi><mi>u</mi><mn>32</mn><mo separator="true">,</mo><mi>m</mi><mi>a</mi><mi>x</mi><mi>u</mi><mn>3</mn><msup><mn>2</mn><mo stretchy="false">?</mo></msup></mrow></mrow><annotation encoding="application/x-tex">limits ::= {min u32, max u32^?}
</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.69444em;vertical-align:0em;"></span><span class="mord mathnormal" style="margin-right:0.01968em;">l</span><span class="mord mathnormal">i</span><span class="mord mathnormal">m</span><span class="mord mathnormal">i</span><span class="mord mathnormal">t</span><span class="mord mathnormal">s</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">:</span></span><span class="base"><span class="strut" style="height:0.43056em;vertical-align:0em;"></span><span class="mrel">:</span></span><span class="base"><span class="strut" style="height:0.36687em;vertical-align:0em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:1.093548em;vertical-align:-0.19444em;"></span><span class="mord"><span class="mord mathnormal">m</span><span class="mord mathnormal">i</span><span class="mord mathnormal">n</span><span class="mord mathnormal">u</span><span class="mord">3</span><span class="mord">2</span><span class="mpunct">,</span><span class="mspace" style="margin-right:0.16666666666666666em;"></span><span class="mord mathnormal">m</span><span class="mord mathnormal">a</span><span class="mord mathnormal">x</span><span class="mord mathnormal">u</span><span class="mord">3</span><span class="mord"><span class="mord">2</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.8991079999999999em;"><span style="top:-3.113em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mclose mtight">?</span></span></span></span></span></span></span></span></span></span></span></span></span></p>
<p>如果没有给出最大值,则相应的存储可以增长到任何大小。</p>
<h4 id="235-内存memories类型"><a class="markdownIt-Anchor" href="#235-内存memories类型"></a> 2.3.5. 内存(Memories)类型</h4>
<p>存储器类型将线性存储器及其大小范围分类。</p>
<p class='katex-block'><span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><mi>m</mi><mi>e</mi><mi>m</mi><mi>t</mi><mi>y</mi><mi>p</mi><mi>e</mi><mo>:</mo><mo>:</mo><mo>=</mo><mi>l</mi><mi>i</mi><mi>m</mi><mi>i</mi><mi>t</mi><mi>s</mi></mrow><annotation encoding="application/x-tex">memtype ::= limits
</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.80952em;vertical-align:-0.19444em;"></span><span class="mord mathnormal">m</span><span class="mord mathnormal">e</span><span class="mord mathnormal">m</span><span class="mord mathnormal">t</span><span class="mord mathnormal" style="margin-right:0.03588em;">y</span><span class="mord mathnormal">p</span><span class="mord mathnormal">e</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">:</span></span><span class="base"><span class="strut" style="height:0.43056em;vertical-align:0em;"></span><span class="mrel">:</span></span><span class="base"><span class="strut" style="height:0.36687em;vertical-align:0em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:0.69444em;vertical-align:0em;"></span><span class="mord mathnormal" style="margin-right:0.01968em;">l</span><span class="mord mathnormal">i</span><span class="mord mathnormal">m</span><span class="mord mathnormal">i</span><span class="mord mathnormal">t</span><span class="mord mathnormal">s</span></span></span></span></span></p>
<p>这些限制限制了内存的最小和最大可选大小。 限制以页面大小为单位给出。</p>
<h4 id="236-表格类型"><a class="markdownIt-Anchor" href="#236-表格类型"></a> 2.3.6. 表格类型</h4>
<p>表类型根据大小范围内的元素类型的元素对表进行分类。</p>
<p class='katex-block katex-error' title='ParseError: KaTeX parse error: Undefined control sequence: \displaylines at position 1: \̲d̲i̲s̲p̲l̲a̲y̲l̲i̲n̲e̲s̲{tabletype ::= …'>\displaylines{tabletype ::= limits elemtype\\
elemtype::=funcref}</p>
<p>像内存一样,表格的最小和最大大小限制也受到限制。<br />
限制以条目数给出。</p>
<p>元素类型funcref是所有函数类型的无限并集。<br />
因此,该类型的表包含对异构类型函数的引用。</p>
<blockquote>
<p>注意</p>
<p>在WebAssembly的未来版本中,可能会引入其他元素类型。</p>
</blockquote>
<h4 id="237-全局变量类型"><a class="markdownIt-Anchor" href="#237-全局变量类型"></a> 2.3.7. 全局变量类型</h4>
<p>全局变量类型对全局变量进行分类,这些全局变量具有一个值,并且可以是可变的或不可变的。</p>
<p class='katex-block katex-error' title='ParseError: KaTeX parse error: Undefined control sequence: \displaylines at position 1: \̲d̲i̲s̲p̲l̲a̲y̲l̲i̲n̲e̲s̲{globaltype ::=…'>\displaylines{globaltype ::= mut valtype\\mut ::= const | var}
#### 2.3.8. 外部类型
外部类型使用各自的类型对导入和外部值进行分类。
$$ externtype :: = func functype| table tabletype | mem memtype | global globaltype </p>
<h5 id="2381-惯例"><a class="markdownIt-Anchor" href="#2381-惯例"></a> 2.3.8.1 惯例</h5>
<p>为外部类型的序列定义了以下辅助符号。<br />
它以保留顺序的方式筛选出特定种类的条目:</p>
<p class='katex-block katex-error' title='ParseError: KaTeX parse error: Undefined control sequence: \displaylines at position 1: \̲d̲i̲s̲p̲l̲a̲y̲l̲i̲n̲e̲s̲{funcs(externty…'>\displaylines{funcs(externtype^*)=[functype|(func functype) \in externtype^*] \\
tables(externtype^*)=[tabletype | (table tabletype)\in externtype^*] \\
mems(externtype^*)=[memtype | (mem memtype)\in externtype^*] \\
globals(externtype^*)=[globaltype | (global globaltype)\in externtype^*]}</p>
<h3 id="24-指令instructions"><a class="markdownIt-Anchor" href="#24-指令instructions"></a> 2.4. 指令Instructions</h3>
<p>WebAssembly代码由指令序列组成。 它的计算模型基于堆栈机,其中指令在隐式操作数堆栈上操纵值,使用(弹出)自变量值并生成或返回(推入)结果值。</p>
<blockquote>
<p>注意</p>
<p>在当前版本的WebAssembly中,单个指令最多可以推入一个结果值。在将来的版本中可能会取消此限制。</p>
</blockquote>
<p>除了来自堆栈的动态操作数之外,某些指令还具有静态中间参数,通常是索引或类型注释,它们是指令本身的一部分。</p>
<p>某些指令的结构在于将嵌套的指令序列括起来。</p>
<p>以下各节将指令分为许多不同的类别。</p>
<h4 id="241-数值指令"><a class="markdownIt-Anchor" href="#241-数值指令"></a> 2.4.1. 数值指令</h4>
<p>数值指令提供对特定类型数值的基本操作。<br />
这些操作与硬件中可用的各个操作紧密匹配。</p>
<p class='katex-block'><span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><mi>n</mi><mi>n</mi><mo separator="true">,</mo><mi>m</mi><mi>m</mi><mo>:</mo><mo>:</mo><mo>=</mo><mn>32</mn><mi mathvariant="normal">∣</mi><mn>64</mn></mrow><annotation encoding="application/x-tex">nn,mm::= 32| 64
</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.625em;vertical-align:-0.19444em;"></span><span class="mord mathnormal">n</span><span class="mord mathnormal">n</span><span class="mpunct">,</span><span class="mspace" style="margin-right:0.16666666666666666em;"></span><span class="mord mathnormal">m</span><span class="mord mathnormal">m</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">:</span></span><span class="base"><span class="strut" style="height:0.43056em;vertical-align:0em;"></span><span class="mrel">:</span></span><span class="base"><span class="strut" style="height:0.36687em;vertical-align:0em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord">3</span><span class="mord">2</span><span class="mord">∣</span><span class="mord">6</span><span class="mord">4</span></span></span></span></span></p>
<p class='katex-block'><span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><mi>s</mi><mi>x</mi><mo>:</mo><mo>:</mo><mo>=</mo><mrow><mi mathvariant="normal">u</mi><mi mathvariant="normal">∣</mi><mi mathvariant="normal">s</mi></mrow></mrow><annotation encoding="application/x-tex">sx ::= \rm{u} | \rm{s}
</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.43056em;vertical-align:0em;"></span><span class="mord mathnormal">s</span><span class="mord mathnormal">x</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">:</span></span><span class="base"><span class="strut" style="height:0.43056em;vertical-align:0em;"></span><span class="mrel">:</span></span><span class="base"><span class="strut" style="height:0.36687em;vertical-align:0em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord"><span class="mord"><span class="mord mathrm">u</span></span><span class="mord mathrm">∣</span><span class="mord"><span class="mord"><span class="mord mathrm">s</span></span></span></span></span></span></span></span></p>
<p class='katex-block katex-error' title='ParseError: KaTeX parse error: Undefined control sequence: \displaylines at position 1: \̲d̲i̲s̲p̲l̲a̲y̲l̲i̲n̲e̲s̲{instr ::= \mat…'>\displaylines{instr ::= \mathrm{i} nn.\mathrm{const}\ inn | \mathrm{i}nn.\mathrm{const}\ fnn \\
| \mathrm{i}nn.iunop | \mathrm{f}nn.funop \\
| \mathrm{i}nn.ibinop | \mathrm{f}nn.fbinop \\
| \mathrm{i}nn.itestop \\
| \mathrm{i}nn.irelop | \mathrm{f}nn.frelop \\
| \mathrm{i32.wrap\_i64} | \mathrm{i64.extend\_i32\_}sx | \mathrm{i}nn.\mathrm{trunc\_f}mm\_sx \\
| \mathrm{f32.demote\_f64} | \mathrm{f64.promote\_f32} | \mathrm{f}nn.\mathrm{convert\_i}mm\_sx \\
| \mathrm{i}nn.\mathrm{reinterpret\_f}nn | \mathrm{i}nn.\mathrm{reinterpret\_i}nn \\
| \ldots}</p>
<p class='katex-block'><span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><mi>i</mi><mi>u</mi><mi>n</mi><mi>o</mi><mi>p</mi><mo>:</mo><mo>:</mo><mo>=</mo><mrow><mi mathvariant="normal">c</mi><mi mathvariant="normal">l</mi><mi mathvariant="normal">z</mi><mi mathvariant="normal">∣</mi><mi mathvariant="normal">c</mi><mi mathvariant="normal">t</mi><mi mathvariant="normal">z</mi><mi mathvariant="normal">∣</mi><mi mathvariant="normal">o</mi><mi mathvariant="normal">p</mi><mi mathvariant="normal">o</mi><mi mathvariant="normal">c</mi><mi mathvariant="normal">n</mi><mi mathvariant="normal">t</mi></mrow></mrow><annotation encoding="application/x-tex">iunop ::= \mathrm{clz | ctz | opocnt}
</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.85396em;vertical-align:-0.19444em;"></span><span class="mord mathnormal">i</span><span class="mord mathnormal">u</span><span class="mord mathnormal">n</span><span class="mord mathnormal">o</span><span class="mord mathnormal">p</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">:</span></span><span class="base"><span class="strut" style="height:0.43056em;vertical-align:0em;"></span><span class="mrel">:</span></span><span class="base"><span class="strut" style="height:0.36687em;vertical-align:0em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord"><span class="mord mathrm">c</span><span class="mord mathrm">l</span><span class="mord mathrm">z</span><span class="mord mathrm">∣</span><span class="mord mathrm">c</span><span class="mord mathrm">t</span><span class="mord mathrm">z</span><span class="mord mathrm">∣</span><span class="mord mathrm">o</span><span class="mord mathrm">p</span><span class="mord mathrm">o</span><span class="mord mathrm">c</span><span class="mord mathrm">n</span><span class="mord mathrm">t</span></span></span></span></span></span></p>
<p class='katex-block katex-error' title='ParseError: KaTeX parse error: Undefined control sequence: \displaylines at position 2: \̲d̲i̲s̲p̲l̲a̲y̲l̲i̲n̲e̲s̲{ibinop ::= \ma…'> \displaylines{ibinop ::= \mathrm{add | sub | mul | div\_}sx \mathrm{|rem\_}sx \\
| \mathrm{and | or | xor | shl | shr\_}sx \mathrm{| rtol | rtor} }</p>
<p class='katex-block'><span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><mi>f</mi><mi>u</mi><mi>n</mi><mi>o</mi><mi>p</mi><mo>:</mo><mo>:</mo><mo>=</mo><mrow><mi mathvariant="normal">a</mi><mi mathvariant="normal">b</mi><mi mathvariant="normal">s</mi><mi mathvariant="normal">∣</mi><mi mathvariant="normal">n</mi><mi mathvariant="normal">e</mi><mi mathvariant="normal">g</mi><mi mathvariant="normal">∣</mi><mi mathvariant="normal">s</mi><mi mathvariant="normal">q</mi><mi mathvariant="normal">r</mi><mi mathvariant="normal">t</mi><mi mathvariant="normal">∣</mi><mi mathvariant="normal">c</mi><mi mathvariant="normal">e</mi><mi mathvariant="normal">i</mi><mi mathvariant="normal">l</mi><mi mathvariant="normal">∣</mi><mi mathvariant="normal">f</mi><mi mathvariant="normal">l</mi><mi mathvariant="normal">o</mi><mi mathvariant="normal">o</mi><mi mathvariant="normal">r</mi><mi mathvariant="normal">∣</mi><mi mathvariant="normal">t</mi><mi mathvariant="normal">r</mi><mi mathvariant="normal">u</mi><mi mathvariant="normal">n</mi><mi mathvariant="normal">c</mi><mi mathvariant="normal">∣</mi><mi mathvariant="normal">n</mi><mi mathvariant="normal">e</mi><mi mathvariant="normal">a</mi><mi mathvariant="normal">r</mi><mi mathvariant="normal">e</mi><mi mathvariant="normal">s</mi><mi mathvariant="normal">t</mi></mrow></mrow><annotation encoding="application/x-tex">funop ::= \mathrm{abs | neg | sqrt | ceil | floor | trunc | nearest}
</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8888799999999999em;vertical-align:-0.19444em;"></span><span class="mord mathnormal" style="margin-right:0.10764em;">f</span><span class="mord mathnormal">u</span><span class="mord mathnormal">n</span><span class="mord mathnormal">o</span><span class="mord mathnormal">p</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">:</span></span><span class="base"><span class="strut" style="height:0.43056em;vertical-align:0em;"></span><span class="mrel">:</span></span><span class="base"><span class="strut" style="height:0.36687em;vertical-align:0em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord"><span class="mord mathrm">a</span><span class="mord mathrm">b</span><span class="mord mathrm">s</span><span class="mord mathrm">∣</span><span class="mord mathrm">n</span><span class="mord mathrm">e</span><span class="mord mathrm" style="margin-right:0.01389em;">g</span><span class="mord mathrm">∣</span><span class="mord mathrm">s</span><span class="mord mathrm">q</span><span class="mord mathrm">r</span><span class="mord mathrm">t</span><span class="mord mathrm">∣</span><span class="mord mathrm">c</span><span class="mord mathrm">e</span><span class="mord mathrm">i</span><span class="mord mathrm">l</span><span class="mord mathrm">∣</span><span class="mord mathrm" style="margin-right:0.07778em;">f</span><span class="mord mathrm">l</span><span class="mord mathrm">o</span><span class="mord mathrm">o</span><span class="mord mathrm">r</span><span class="mord mathrm">∣</span><span class="mord mathrm">t</span><span class="mord mathrm">r</span><span class="mord mathrm">u</span><span class="mord mathrm">n</span><span class="mord mathrm">c</span><span class="mord mathrm">∣</span><span class="mord mathrm">n</span><span class="mord mathrm">e</span><span class="mord mathrm">a</span><span class="mord mathrm">r</span><span class="mord mathrm">e</span><span class="mord mathrm">s</span><span class="mord mathrm">t</span></span></span></span></span></span></p>
<p class='katex-block'><span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><mi>f</mi><mi>b</mi><mi>i</mi><mi>n</mi><mi>o</mi><mi>p</mi><mo>:</mo><mo>:</mo><mo>=</mo><mrow><mi mathvariant="normal">a</mi><mi mathvariant="normal">d</mi><mi mathvariant="normal">d</mi><mi mathvariant="normal">∣</mi><mi mathvariant="normal">s</mi><mi mathvariant="normal">u</mi><mi mathvariant="normal">b</mi><mi mathvariant="normal">∣</mi><mi mathvariant="normal">m</mi><mi mathvariant="normal">u</mi><mi mathvariant="normal">l</mi><mi mathvariant="normal">∣</mi><mi mathvariant="normal">d</mi><mi mathvariant="normal">i</mi><mi mathvariant="normal">v</mi><mi mathvariant="normal">∣</mi><mi mathvariant="normal">m</mi><mi mathvariant="normal">i</mi><mi mathvariant="normal">n</mi><mi mathvariant="normal">∣</mi><mi mathvariant="normal">m</mi><mi mathvariant="normal">a</mi><mi mathvariant="normal">x</mi><mi mathvariant="normal">∣</mi><mi mathvariant="normal">c</mi><mi mathvariant="normal">o</mi><mi mathvariant="normal">p</mi><mi mathvariant="normal">y</mi><mi mathvariant="normal">s</mi><mi mathvariant="normal">i</mi><mi mathvariant="normal">g</mi><mi mathvariant="normal">n</mi></mrow></mrow><annotation encoding="application/x-tex">fbinop ::= \mathrm{add | sub | mul | div | min | max | copysign}
</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8888799999999999em;vertical-align:-0.19444em;"></span><span class="mord mathnormal" style="margin-right:0.10764em;">f</span><span class="mord mathnormal">b</span><span class="mord mathnormal">i</span><span class="mord mathnormal">n</span><span class="mord mathnormal">o</span><span class="mord mathnormal">p</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">:</span></span><span class="base"><span class="strut" style="height:0.43056em;vertical-align:0em;"></span><span class="mrel">:</span></span><span class="base"><span class="strut" style="height:0.36687em;vertical-align:0em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord"><span class="mord mathrm">a</span><span class="mord mathrm">d</span><span class="mord mathrm">d</span><span class="mord mathrm">∣</span><span class="mord mathrm">s</span><span class="mord mathrm">u</span><span class="mord mathrm">b</span><span class="mord mathrm">∣</span><span class="mord mathrm">m</span><span class="mord mathrm">u</span><span class="mord mathrm">l</span><span class="mord mathrm">∣</span><span class="mord mathrm">d</span><span class="mord mathrm">i</span><span class="mord mathrm" style="margin-right:0.01389em;">v</span><span class="mord mathrm">∣</span><span class="mord mathrm">m</span><span class="mord mathrm">i</span><span class="mord mathrm">n</span><span class="mord mathrm">∣</span><span class="mord mathrm">m</span><span class="mord mathrm">a</span><span class="mord mathrm">x</span><span class="mord mathrm">∣</span><span class="mord mathrm">c</span><span class="mord mathrm">o</span><span class="mord mathrm">p</span><span class="mord mathrm" style="margin-right:0.01389em;">y</span><span class="mord mathrm">s</span><span class="mord mathrm">i</span><span class="mord mathrm" style="margin-right:0.01389em;">g</span><span class="mord mathrm">n</span></span></span></span></span></span></p>
<p class='katex-block'><span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><mi>i</mi><mi>t</mi><mi>e</mi><mi>s</mi><mi>t</mi><mi>o</mi><mi>p</mi><mo>:</mo><mo>:</mo><mo>=</mo><mrow><mi mathvariant="normal">e</mi><mi mathvariant="normal">q</mi><mi mathvariant="normal">z</mi></mrow></mrow><annotation encoding="application/x-tex">itestop ::= \mathrm{eqz}
</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.85396em;vertical-align:-0.19444em;"></span><span class="mord mathnormal">i</span><span class="mord mathnormal">t</span><span class="mord mathnormal">e</span><span class="mord mathnormal">s</span><span class="mord mathnormal">t</span><span class="mord mathnormal">o</span><span class="mord mathnormal">p</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">:</span></span><span class="base"><span class="strut" style="height:0.43056em;vertical-align:0em;"></span><span class="mrel">:</span></span><span class="base"><span class="strut" style="height:0.36687em;vertical-align:0em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:0.625em;vertical-align:-0.19444em;"></span><span class="mord"><span class="mord mathrm">e</span><span class="mord mathrm">q</span><span class="mord mathrm">z</span></span></span></span></span></span></p>
<p class='katex-block'><span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><mi>i</mi><mi>r</mi><mi>e</mi><mi>l</mi><mi>o</mi><mi>p</mi><mo>:</mo><mo>:</mo><mo>=</mo><mrow><mi mathvariant="normal">e</mi><mi mathvariant="normal">q</mi><mi mathvariant="normal">∣</mi><mi mathvariant="normal">n</mi><mi mathvariant="normal">e</mi><mi mathvariant="normal">∣</mi><mi mathvariant="normal">l</mi><mi mathvariant="normal">t</mi><mi mathvariant="normal">_</mi></mrow><mi>s</mi><mi>x</mi><mrow><mi mathvariant="normal">∣</mi><mi mathvariant="normal">g</mi><mi mathvariant="normal">t</mi><mi mathvariant="normal">_</mi></mrow><mi>s</mi><mi>c</mi><mrow><mi mathvariant="normal">∣</mi><mi mathvariant="normal">l</mi><mi mathvariant="normal">e</mi><mi mathvariant="normal">_</mi></mrow><mi>s</mi><mi>x</mi><mrow><mi mathvariant="normal">∣</mi><mi mathvariant="normal">g</mi><mi mathvariant="normal">e</mi><mi mathvariant="normal">_</mi></mrow><mi>s</mi><mi>x</mi></mrow><annotation encoding="application/x-tex">irelop ::= \mathrm{eq | ne | lt\_}sx \mathrm{| gt\_}sc \mathrm{| le\_}sx \mathrm{| ge\_}sx
</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8888799999999999em;vertical-align:-0.19444em;"></span><span class="mord mathnormal">i</span><span class="mord mathnormal" style="margin-right:0.02778em;">r</span><span class="mord mathnormal">e</span><span class="mord mathnormal" style="margin-right:0.01968em;">l</span><span class="mord mathnormal">o</span><span class="mord mathnormal">p</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">:</span></span><span class="base"><span class="strut" style="height:0.43056em;vertical-align:0em;"></span><span class="mrel">:</span></span><span class="base"><span class="strut" style="height:0.36687em;vertical-align:0em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:1.06em;vertical-align:-0.31em;"></span><span class="mord"><span class="mord mathrm">e</span><span class="mord mathrm">q</span><span class="mord mathrm">∣</span><span class="mord mathrm">n</span><span class="mord mathrm">e</span><span class="mord mathrm">∣</span><span class="mord mathrm">l</span><span class="mord mathrm">t</span><span class="mord mathrm" style="margin-right:0.02778em;">_</span></span><span class="mord mathnormal">s</span><span class="mord mathnormal">x</span><span class="mord"><span class="mord mathrm">∣</span><span class="mord mathrm" style="margin-right:0.01389em;">g</span><span class="mord mathrm">t</span><span class="mord mathrm" style="margin-right:0.02778em;">_</span></span><span class="mord mathnormal">s</span><span class="mord mathnormal">c</span><span class="mord"><span class="mord mathrm">∣</span><span class="mord mathrm">l</span><span class="mord mathrm">e</span><span class="mord mathrm" style="margin-right:0.02778em;">_</span></span><span class="mord mathnormal">s</span><span class="mord mathnormal">x</span><span class="mord"><span class="mord mathrm">∣</span><span class="mord mathrm" style="margin-right:0.01389em;">g</span><span class="mord mathrm">e</span><span class="mord mathrm" style="margin-right:0.02778em;">_</span></span><span class="mord mathnormal">s</span><span class="mord mathnormal">x</span></span></span></span></span></p>
<p class='katex-block'><span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><mi>f</mi><mi>r</mi><mi>e</mi><mi>l</mi><mi>o</mi><mi>p</mi><mo>:</mo><mo>:</mo><mo>=</mo><mrow><mi mathvariant="normal">e</mi><mi mathvariant="normal">q</mi><mi mathvariant="normal">∣</mi><mi mathvariant="normal">n</mi><mi mathvariant="normal">e</mi><mi mathvariant="normal">∣</mi><mi mathvariant="normal">l</mi><mi mathvariant="normal">t</mi><mi mathvariant="normal">∣</mi><mi mathvariant="normal">g</mi><mi mathvariant="normal">t</mi><mi mathvariant="normal">∣</mi><mi mathvariant="normal">l</mi><mi mathvariant="normal">e</mi><mi mathvariant="normal">∣</mi><mi mathvariant="normal">g</mi><mi mathvariant="normal">e</mi></mrow></mrow><annotation encoding="application/x-tex">frelop ::= \mathrm{eq | ne | lt | gt | le | ge }
</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8888799999999999em;vertical-align:-0.19444em;"></span><span class="mord mathnormal" style="margin-right:0.10764em;">f</span><span class="mord mathnormal" style="margin-right:0.02778em;">r</span><span class="mord mathnormal">e</span><span class="mord mathnormal" style="margin-right:0.01968em;">l</span><span class="mord mathnormal">o</span><span class="mord mathnormal">p</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">:</span></span><span class="base"><span class="strut" style="height:0.43056em;vertical-align:0em;"></span><span class="mrel">:</span></span><span class="base"><span class="strut" style="height:0.36687em;vertical-align:0em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord"><span class="mord mathrm">e</span><span class="mord mathrm">q</span><span class="mord mathrm">∣</span><span class="mord mathrm">n</span><span class="mord mathrm">e</span><span class="mord mathrm">∣</span><span class="mord mathrm">l</span><span class="mord mathrm">t</span><span class="mord mathrm">∣</span><span class="mord mathrm" style="margin-right:0.01389em;">g</span><span class="mord mathrm">t</span><span class="mord mathrm">∣</span><span class="mord mathrm">l</span><span class="mord mathrm">e</span><span class="mord mathrm">∣</span><span class="mord mathrm" style="margin-right:0.01389em;">g</span><span class="mord mathrm">e</span></span></span></span></span></span></p>
<p>数字指令按值类型划分。 对于每种类型,可以区分几个子类别:</p>
<ul>
<li>常量:返回静态常量。</li>
<li>一元运算符:使用一个操作数并产生相应类型的一个结果。</li>
<li>二进制运算符:使用两个操作数并产生一个相应类型的结果。</li>
<li>测试:消耗一个相应类型的操作数,并产生一个布尔整数结果。</li>
<li>比较:消耗两个各自类型的操作数,并产生一个布尔整数结果。</li>
<li>转换:使用一种类型的值并产生另一种类型的结果(转换的源类型是“_”之后的类型)。</li>
</ul>
<p>一些整数指令有两种形式,其中带符号注释sx区分是将操作数解释为无符号整数还是带符号整数。<br />
对于其他整数指令,对有符号的解释使用二进制补码意味着无论有符号性如何,它们的行为都相同。</p>
<h5 id="2411-惯例"><a class="markdownIt-Anchor" href="#2411-惯例"></a> 2.4.1.1. 惯例</h5>
<p>有时,根据以下语法速记将操作分组在一起很方便:</p>
<p class='katex-block'><span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><mi>u</mi><mi>n</mi><mi>o</mi><mi>p</mi><mo>:</mo><mo>:</mo><mo>=</mo><mi>i</mi><mi>u</mi><mi>n</mi><mi>o</mi><mi>p</mi><mi mathvariant="normal">∣</mi><mi>f</mi><mi>u</mi><mi>n</mi><mi>o</mi><mi>p</mi></mrow><annotation encoding="application/x-tex">unop ::= iunop | funop
</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.625em;vertical-align:-0.19444em;"></span><span class="mord mathnormal">u</span><span class="mord mathnormal">n</span><span class="mord mathnormal">o</span><span class="mord mathnormal">p</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">:</span></span><span class="base"><span class="strut" style="height:0.43056em;vertical-align:0em;"></span><span class="mrel">:</span></span><span class="base"><span class="strut" style="height:0.36687em;vertical-align:0em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord mathnormal">i</span><span class="mord mathnormal">u</span><span class="mord mathnormal">n</span><span class="mord mathnormal">o</span><span class="mord mathnormal">p</span><span class="mord">∣</span><span class="mord mathnormal" style="margin-right:0.10764em;">f</span><span class="mord mathnormal">u</span><span class="mord mathnormal">n</span><span class="mord mathnormal">o</span><span class="mord mathnormal">p</span></span></span></span></span></p>
<p class='katex-block'><span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><mi>b</mi><mi>i</mi><mi>n</mi><mi>o</mi><mi>p</mi><mo>:</mo><mo>:</mo><mo>=</mo><mi>i</mi><mi>b</mi><mi>i</mi><mi>n</mi><mi>o</mi><mi>p</mi><mi mathvariant="normal">∣</mi><mi>f</mi><mi>b</mi><mi>i</mi><mi>n</mi><mi>o</mi><mi>p</mi></mrow><annotation encoding="application/x-tex">binop ::= ibinop | fbinop
</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8888799999999999em;vertical-align:-0.19444em;"></span><span class="mord mathnormal">b</span><span class="mord mathnormal">i</span><span class="mord mathnormal">n</span><span class="mord mathnormal">o</span><span class="mord mathnormal">p</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">:</span></span><span class="base"><span class="strut" style="height:0.43056em;vertical-align:0em;"></span><span class="mrel">:</span></span><span class="base"><span class="strut" style="height:0.36687em;vertical-align:0em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord mathnormal">i</span><span class="mord mathnormal">b</span><span class="mord mathnormal">i</span><span class="mord mathnormal">n</span><span class="mord mathnormal">o</span><span class="mord mathnormal">p</span><span class="mord">∣</span><span class="mord mathnormal" style="margin-right:0.10764em;">f</span><span class="mord mathnormal">b</span><span class="mord mathnormal">i</span><span class="mord mathnormal">n</span><span class="mord mathnormal">o</span><span class="mord mathnormal">p</span></span></span></span></span></p>
<p class='katex-block'><span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><mi>t</mi><mi>e</mi><mi>s</mi><mi>t</mi><mi>o</mi><mi>p</mi><mo>:</mo><mo>:</mo><mo>=</mo><mi>i</mi><mi>t</mi><mi>e</mi><mi>s</mi><mi>t</mi><mi>o</mi><mi>p</mi></mrow><annotation encoding="application/x-tex">testop ::= itestop
</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.80952em;vertical-align:-0.19444em;"></span><span class="mord mathnormal">t</span><span class="mord mathnormal">e</span><span class="mord mathnormal">s</span><span class="mord mathnormal">t</span><span class="mord mathnormal">o</span><span class="mord mathnormal">p</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">:</span></span><span class="base"><span class="strut" style="height:0.43056em;vertical-align:0em;"></span><span class="mrel">:</span></span><span class="base"><span class="strut" style="height:0.36687em;vertical-align:0em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:0.85396em;vertical-align:-0.19444em;"></span><span class="mord mathnormal">i</span><span class="mord mathnormal">t</span><span class="mord mathnormal">e</span><span class="mord mathnormal">s</span><span class="mord mathnormal">t</span><span class="mord mathnormal">o</span><span class="mord mathnormal">p</span></span></span></span></span></p>
<p class='katex-block'><span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><mi>r</mi><mi>e</mi><mi>l</mi><mi>o</mi><mi>p</mi><mo>:</mo><mo>:</mo><mo>=</mo><mi>i</mi><mi>r</mi><mi>e</mi><mi>l</mi><mi>o</mi><mi>p</mi><mi mathvariant="normal">∣</mi><mi>f</mi><mi>r</mi><mi>e</mi><mi>l</mi><mi>o</mi><mi>p</mi></mrow><annotation encoding="application/x-tex">relop ::= irelop | frelop
</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8888799999999999em;vertical-align:-0.19444em;"></span><span class="mord mathnormal" style="margin-right:0.02778em;">r</span><span class="mord mathnormal">e</span><span class="mord mathnormal" style="margin-right:0.01968em;">l</span><span class="mord mathnormal">o</span><span class="mord mathnormal">p</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">:</span></span><span class="base"><span class="strut" style="height:0.43056em;vertical-align:0em;"></span><span class="mrel">:</span></span><span class="base"><span class="strut" style="height:0.36687em;vertical-align:0em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord mathnormal">i</span><span class="mord mathnormal" style="margin-right:0.02778em;">r</span><span class="mord mathnormal">e</span><span class="mord mathnormal" style="margin-right:0.01968em;">l</span><span class="mord mathnormal">o</span><span class="mord mathnormal">p</span><span class="mord">∣</span><span class="mord mathnormal" style="margin-right:0.10764em;">f</span><span class="mord mathnormal" style="margin-right:0.02778em;">r</span><span class="mord mathnormal">e</span><span class="mord mathnormal" style="margin-right:0.01968em;">l</span><span class="mord mathnormal">o</span><span class="mord mathnormal">p</span></span></span></span></span></p>
<p class='katex-block'><span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><mi>c</mi><mi>u</mi><mi>t</mi><mi>o</mi><mi>p</mi><mo>:</mo><mo>:</mo><mo>=</mo><mrow><mi mathvariant="normal">w</mi><mi mathvariant="normal">r</mi><mi mathvariant="normal">a</mi><mi mathvariant="normal">p</mi><mi mathvariant="normal">∣</mi><mi mathvariant="normal">e</mi><mi mathvariant="normal">n</mi><mi mathvariant="normal">t</mi><mi mathvariant="normal">e</mi><mi mathvariant="normal">n</mi><mi mathvariant="normal">d</mi><mi mathvariant="normal">∣</mi><mi mathvariant="normal">t</mi><mi mathvariant="normal">r</mi><mi mathvariant="normal">u</mi><mi mathvariant="normal">n</mi><mi mathvariant="normal">c</mi><mi mathvariant="normal">∣</mi><mi mathvariant="normal">c</mi><mi mathvariant="normal">o</mi><mi mathvariant="normal">n</mi><mi mathvariant="normal">v</mi><mi mathvariant="normal">e</mi><mi mathvariant="normal">r</mi><mi mathvariant="normal">t</mi><mi mathvariant="normal">∣</mi><mi mathvariant="normal">d</mi><mi mathvariant="normal">e</mi><mi mathvariant="normal">m</mi><mi mathvariant="normal">o</mi><mi mathvariant="normal">t</mi><mi mathvariant="normal">e</mi><mi mathvariant="normal">∣</mi><mi mathvariant="normal">p</mi><mi mathvariant="normal">r</mi><mi mathvariant="normal">o</mi><mi mathvariant="normal">m</mi><mi mathvariant="normal">o</mi><mi mathvariant="normal">t</mi><mi mathvariant="normal">e</mi><mi mathvariant="normal">∣</mi><mi mathvariant="normal">r</mi><mi mathvariant="normal">e</mi><mi mathvariant="normal">i</mi><mi mathvariant="normal">n</mi><mi mathvariant="normal">t</mi><mi mathvariant="normal">e</mi><mi mathvariant="normal">r</mi><mi mathvariant="normal">p</mi><mi mathvariant="normal">r</mi><mi mathvariant="normal">e</mi><mi mathvariant="normal">t</mi></mrow></mrow><annotation encoding="application/x-tex">cutop ::= \mathrm{wrap | entend | trunc | convert | demote | promote | reinterpret}
</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.80952em;vertical-align:-0.19444em;"></span><span class="mord mathnormal">c</span><span class="mord mathnormal">u</span><span class="mord mathnormal">t</span><span class="mord mathnormal">o</span><span class="mord mathnormal">p</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">:</span></span><span class="base"><span class="strut" style="height:0.43056em;vertical-align:0em;"></span><span class="mrel">:</span></span><span class="base"><span class="strut" style="height:0.36687em;vertical-align:0em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord"><span class="mord mathrm" style="margin-right:0.01389em;">w</span><span class="mord mathrm">r</span><span class="mord mathrm">a</span><span class="mord mathrm">p</span><span class="mord mathrm">∣</span><span class="mord mathrm">e</span><span class="mord mathrm">n</span><span class="mord mathrm">t</span><span class="mord mathrm">e</span><span class="mord mathrm">n</span><span class="mord mathrm">d</span><span class="mord mathrm">∣</span><span class="mord mathrm">t</span><span class="mord mathrm">r</span><span class="mord mathrm">u</span><span class="mord mathrm">n</span><span class="mord mathrm">c</span><span class="mord mathrm">∣</span><span class="mord mathrm">c</span><span class="mord mathrm">o</span><span class="mord mathrm">n</span><span class="mord mathrm" style="margin-right:0.01389em;">v</span><span class="mord mathrm">e</span><span class="mord mathrm">r</span><span class="mord mathrm">t</span><span class="mord mathrm">∣</span><span class="mord mathrm">d</span><span class="mord mathrm">e</span><span class="mord mathrm">m</span><span class="mord mathrm">o</span><span class="mord mathrm">t</span><span class="mord mathrm">e</span><span class="mord mathrm">∣</span><span class="mord mathrm">p</span><span class="mord mathrm">r</span><span class="mord mathrm">o</span><span class="mord mathrm">m</span><span class="mord mathrm">o</span><span class="mord mathrm">t</span><span class="mord mathrm">e</span><span class="mord mathrm">∣</span><span class="mord mathrm">r</span><span class="mord mathrm">e</span><span class="mord mathrm">i</span><span class="mord mathrm">n</span><span class="mord mathrm">t</span><span class="mord mathrm">e</span><span class="mord mathrm">r</span><span class="mord mathrm">p</span><span class="mord mathrm">r</span><span class="mord mathrm">e</span><span class="mord mathrm">t</span></span></span></span></span></span></p>
<h4 id="242-参数指令"><a class="markdownIt-Anchor" href="#242-参数指令"></a> 2.4.2. 参数指令</h4>
<p>该组中的指令可以对任何值类型的操作数进行运算。</p>
<p class='katex-block katex-error' title='ParseError: KaTeX parse error: Undefined control sequence: \displaylines at position 2: \̲d̲i̲s̲p̲l̲a̲y̲l̲i̲n̲e̲s̲{ instr ::= \ld…'> \displaylines{ instr ::= \ldots \\
| \mathrm{drop} \\
| \mathrm{select} }</p>
<p>drop运算符只是丢掉单个操作数。</p>
<p>select运算符根据其第三个操作数是否为零来选择执行其前两个操作数之一。</p>
<h4 id="243-变量指令"><a class="markdownIt-Anchor" href="#243-变量指令"></a> 2.4.3. 变量指令</h4>
<p>变量指令涉及对局部或全局变量的访问。</p>
<p class='katex-block katex-error' title='ParseError: KaTeX parse error: Undefined control sequence: \displaylines at position 2: \̲d̲i̲s̲p̲l̲a̲y̲l̲i̲n̲e̲s̲{ instr ::= \ld…'> \displaylines{ instr ::= \ldots \\
| \mathrm{local.get}\ localidx \\
| \mathrm{local.set}\ localidx \\
| \mathrm{local.tee}\ localidx \\
| \mathrm{global.get}\ globalidx \\
| \mathrm{global.set}\ globalidx}</p>
<p>这些指令分别获取或设置变量的值。<br />
local.tee指令类似于local.set,但会返回其参数。</p>
<h4 id="244-内存指令"><a class="markdownIt-Anchor" href="#244-内存指令"></a> 2.4.4. 内存指令</h4>
<p>该组指令与线性内存有关。</p>
<p class='katex-block'><span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><mi>m</mi><mi>e</mi><mi>m</mi><mi>a</mi><mi>r</mi><mi>g</mi><mo>:</mo><mo>:</mo><mo>=</mo><mo stretchy="false">{</mo><mrow><mi mathvariant="normal">o</mi><mi mathvariant="normal">f</mi><mi mathvariant="normal">f</mi><mi mathvariant="normal">s</mi><mi mathvariant="normal">e</mi><mi mathvariant="normal">t</mi></mrow><mtext> </mtext><mi>u</mi><mn>32</mn><mo separator="true">,</mo><mrow><mi mathvariant="normal">a</mi><mi mathvariant="normal">l</mi><mi mathvariant="normal">i</mi><mi mathvariant="normal">g</mi><mi mathvariant="normal">n</mi></mrow><mtext> </mtext><mi>u</mi><mn>32</mn><mo stretchy="false">}</mo></mrow><annotation encoding="application/x-tex">memarg ::= \{ \mathrm{offset}\ u32, \mathrm{align}\ u32 \}
</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.625em;vertical-align:-0.19444em;"></span><span class="mord mathnormal">m</span><span class="mord mathnormal">e</span><span class="mord mathnormal">m</span><span class="mord mathnormal">a</span><span class="mord mathnormal" style="margin-right:0.02778em;">r</span><span class="mord mathnormal" style="margin-right:0.03588em;">g</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">:</span></span><span class="base"><span class="strut" style="height:0.43056em;vertical-align:0em;"></span><span class="mrel">:</span></span><span class="base"><span class="strut" style="height:0.36687em;vertical-align:0em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mopen">{</span><span class="mord"><span class="mord mathrm">o</span><span class="mord mathrm" style="margin-right:0.07778em;">f</span><span class="mord mathrm" style="margin-right:0.07778em;">f</span><span class="mord mathrm">s</span><span class="mord mathrm">e</span><span class="mord mathrm">t</span></span><span class="mspace"> </span><span class="mord mathnormal">u</span><span class="mord">3</span><span class="mord">2</span><span class="mpunct">,</span><span class="mspace" style="margin-right:0.16666666666666666em;"></span><span class="mord"><span class="mord mathrm">a</span><span class="mord mathrm">l</span><span class="mord mathrm">i</span><span class="mord mathrm" style="margin-right:0.01389em;">g</span><span class="mord mathrm">n</span></span><span class="mspace"> </span><span class="mord mathnormal">u</span><span class="mord">3</span><span class="mord">2</span><span class="mclose">}</span></span></span></span></span></p>
<p>内存可以通过使用不同<em>值类型</em>的加载(load)和存储(store)指令来访问。<br />
它们都使用一个内存中间值memarg,该值包含一个地址<em>偏移量(offset)<em>和一个预期的</em>编排方式</em>(表示为2的幂的指数)。<br />
整数的加载和存储可以选择指定小于各自值类型的位宽度的存储大小。<br />
在一些加载情况下,则需要符号扩展模式<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>s</mi><mi>x</mi></mrow><annotation encoding="application/x-tex">sx</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.43056em;vertical-align:0em;"></span><span class="mord mathnormal">s</span><span class="mord mathnormal">x</span></span></span></span>来选择适当的行为。</p>
<p>静态地址偏移量被添加到动态地址操作数,从而产生33位长度的<em>有效地址</em>,该地址是从零开始的索引,可从该索引访问内存。<br />
所有值以Little-Endian读取和写入。<br />
如果任何已访问的内存字节超出了内存当前大小所隐含的地址范围,就会产生陷阱(Trap)。</p>
<blockquote>
<p>注意</p>
<p>WebAssembly的未来版本可能会提供具有64位地址范围的内存指令。</p>
<p>(这也是为啥现在叫wasm32)</p>
</blockquote>
<p>memory.size指令返回当前的内存大小。<br />
memory.grow指令将内存增加给定的增量,并返回先前的大小;如果无法分配足够的内存,则返回-1。<br />
两条指令均以页面大小为单位。</p>
<blockquote>
<p>注意</p>
<p>在当前版本的WebAssembly中,所有内存指令都隐式地(默认)对内存索引0进行操作。此限制在将来的版本中可能会取消。</p>
</blockquote>
<h4 id="245-控制指令"><a class="markdownIt-Anchor" href="#245-控制指令"></a> 2.4.5. 控制指令</h4>
<p>该组中的指令会影响控制流程。</p>
<p class='katex-block katex-error' title='ParseError: KaTeX parse error: Undefined control sequence: \displaylines at position 2: \̲d̲i̲s̲p̲l̲a̲y̲l̲i̲n̲e̲s̲{ instr ::= \ld…'> \displaylines{ instr ::= \ldots \\
| \mathrm{nop} \\
| \mathrm{unreachable} \\
| \mathrm{block}\ resulttype\ instr^*\ \mathrm{end} \\
| \mathrm{loop }\ resulttype\ instr^*\ \mathrm{end} \\
| \mathrm{if}\ resulttype\ instr^*\ \mathrm{else}\ instr^*\ \mathrm{end} \\
| \mathrm{br}\ labelidx \\
| \mathrm{br\_if}\ labelidx \\
| \mathrm{br\_table}\ vec(labelidx)\ labelidx \\
| \mathrm{return} \\
| \mathrm{call}\ funcidx \\
| \mathrm{call\_indirect}\ typeidx}</p>
<p>nop指令不执行任何操作。</p>
<p>unreachable指令触发无条件的陷阱。</p>
<p>block,loop以及if指令是结构化指令。<br />
它们将嵌套的指令序列(称为块)括起来,以指令末尾或伪指令终止或分隔。<br />
正如语法规定的那样,必须将它们嵌套好。<br />
结构化指令可以产生一个如注释结果类型描述的值。</p>
<p>每个结构化控制指令都会引入一个隐式标签。<br />
标签(Label)是分支指令通过标签索引引用的目标。<br />
与其他索引空间不同,标签的索引是相对于嵌套深度的,也就是说,标签0指的是包围引用分支指令的最内部结构化控制指令,而递增的索引则引用更远的索引。<br />
因此,只能从关联的结构化控制指令中引用标签。<br />
这也意味着分支只能指向外部,“脱离”它们所针对的控制构造的块。<br />
具体效果取决于该控制结构:<br />
在block或if情况下,向前跳转直到匹配到end后恢复执行。<br />
在loop循环情况下,向后跳到loop开始。</p>
<blockquote>
<p>注意</p>
<p>这将强制执行结构化的控制流程。<br />
直观地讲,在大多数类似于C的语言中,针对块的if分支的行为类似于break语句,而针对循环的分支的行为类似于continue语句。</p>
</blockquote>
<p>分支(Branch)指令有以下几种形式:<br />
br:执行无条件分支<br />
br_if:执行条件分支<br />
br_table:通过操作数索引到标签向量的间接操作来执行该间接操作,该标签向量是指令的直接执行对象,如果操作数超出范围,则指向默认目标。<br />
return:无条件分支到最外层代码块的快捷方式,该块隐式地是当前函数的主体。<br />
采取分支将操作数堆栈展开到输入目标结构化控制指令的高度。<br />
但是,以非空结果类型为目标的控制指令作为目标的前向分支首先消耗匹配的操作数,并在展开后将它们推回操作数堆栈中,以作为终止的结构化指令的结果。</p>
<p>call指令调用另一个函数,从堆栈中使用必要的参数并返回调用的结果值。<br />
call_indirect指令通过将操作数索引到表中来间接调用函数。<br />
由于表(table)可能包含异构类型funcref的函数元素,因此将根据指令的立即数对被调用方进行动态检查,以检查该函数类型(function type),如果调用不匹配,则调用将使用陷阱(trap)中止。</p>
<blockquote>
<p>注意</p>
<p>在当前版本的WebAssembly中,call_indirect默认对表索引(tableidx)0操作。在将来的版本中可能会取消此限制。</p>
</blockquote>
<h4 id="246-表达式expression"><a class="markdownIt-Anchor" href="#246-表达式expression"></a> 2.4.6. 表达式Expression</h4>
<p>函数(function)主体,全局变量(globals)的初始化值以及元素(element)或数据(data)段的偏移量都作为表达式给出。表达式是由结束(end)标记终止的指令(instruction)序列。</p>
<p class='katex-block'><span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><mi>e</mi><mi>x</mi><mi>p</mi><mi>r</mi><mo>:</mo><mo>:</mo><mo>=</mo><mi>i</mi><mi>n</mi><mi>s</mi><mi>t</mi><mi>r</mi><mo>∗</mo><mrow><mi mathvariant="normal">e</mi><mi mathvariant="normal">n</mi><mi mathvariant="normal">d</mi></mrow></mrow><annotation encoding="application/x-tex">expr ::= instr* \mathrm{end}
</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.625em;vertical-align:-0.19444em;"></span><span class="mord mathnormal">e</span><span class="mord mathnormal">x</span><span class="mord mathnormal">p</span><span class="mord mathnormal" style="margin-right:0.02778em;">r</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">:</span></span><span class="base"><span class="strut" style="height:0.43056em;vertical-align:0em;"></span><span class="mrel">:</span></span><span class="base"><span class="strut" style="height:0.36687em;vertical-align:0em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:0.65952em;vertical-align:0em;"></span><span class="mord mathnormal">i</span><span class="mord mathnormal">n</span><span class="mord mathnormal">s</span><span class="mord mathnormal">t</span><span class="mord mathnormal" style="margin-right:0.02778em;">r</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">∗</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span></span><span class="base"><span class="strut" style="height:0.69444em;vertical-align:0em;"></span><span class="mord"><span class="mord mathrm">e</span><span class="mord mathrm">n</span><span class="mord mathrm">d</span></span></span></span></span></span></p>
<p>在某些地方,验证器将表达式限制为常量,从而限制了被允许的指令集。</p>
<h3 id="25-模块-modules"><a class="markdownIt-Anchor" href="#25-模块-modules"></a> 2.5 模块 Modules</h3>
<p>WebAssembly程序被组织成模块,这些模块是部署,加载和编译的单元。<br />
一个模块包含了类型(types),函数(functions),表(tables),内存(memories)和全局变量(globals)的定义。<br />
此外,它可以声明导入(imports)和导出(exports),并以数据(data)和元素(element)段或启动函数的形式提供初始化逻辑。</p>
<p class='katex-block katex-error' title='ParseError: KaTeX parse error: Undefined control sequence: \displaylines at position 2: \̲d̲i̲s̲p̲l̲a̲y̲l̲i̲n̲e̲s̲{ module ::= \{…'> \displaylines{ module ::= \{ types\ vec(functype),
funcs\ vec(func), \\
tables\ vec(table), \\
mems vec(mem), \\
globals\ vec(elem), \\
data\ vec(data), \\
start\ start^?, \\
imports\ vec(import),
exports\ vec(export) \}}</p>
<p>每个向量,甚至整个模块,都可能是空的。</p>
<h4 id="251-索引"><a class="markdownIt-Anchor" href="#251-索引"></a> 2.5.1. 索引</h4>
<p>定义被以从0开始的索引引用。<br />
每个定义类都有其自己专属的索引空间,如以下类所示。</p>
<p class='katex-block katex-error' title='ParseError: KaTeX parse error: Undefined control sequence: \displaylines at position 1: \̲d̲i̲s̲p̲l̲a̲y̲l̲i̲n̲e̲s̲{ typeidx ::= u…'>\displaylines{ typeidx ::= u32\\
funcidx ::= u32\\
tableidx ::= u32\\
memidx ::= u32\\
globalidx ::= u32\\
localidx ::= u32\\
labelidx ::= u32}</p>
<p>函数(functions),表(tables),内存(memories)和全局变量(globals)的索引空间包括在同一模块中声明的相应导入(imports)中。<br />
这些导入(imports)的索引在同一索引空间中优先于其他定义的索引。</p>
<p>局部变量(locals)的索引空间只能在函数内部访问,并且包括以此为参数的函数。这种函数位于局部变量之前。</p>
<p>标签(label)索引引用指令序列内的结构化控制指令。</p>
<h5 id="2511-惯例"><a class="markdownIt-Anchor" href="#2511-惯例"></a> 2.5.1.1. 惯例</h5>
<ul>
<li>元变量l覆盖标签索引。</li>
<li>元变量x,y覆盖其他任何索引空间中的索引。</li>
</ul>
<h4 id="252-类型"><a class="markdownIt-Anchor" href="#252-类型"></a> 2.5.2. 类型</h4>
<p>模块的类型组件定义了一个功能类型(function types)的向量。</p>
<p>所有功能类型必须在此组件中定义模块中使用。<br />
它们由类型索引引用。</p>
<blockquote>
<p>注意</p>
<p>WebAssembly的未来版本可能会添加类型定义的其他形式。</p>
</blockquote>
<h4 id="253-函数"><a class="markdownIt-Anchor" href="#253-函数"></a> 2.5.3. 函数</h4>
<p>模块的funcs组件定义具有以下结构的函数向量:</p>
<p class='katex-block'><span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><mi>f</mi><mi>u</mi><mi>n</mi><mi>c</mi><mo>:</mo><mo>:</mo><mo>=</mo><mo stretchy="false">{</mo><mrow><mi mathvariant="normal">t</mi><mi mathvariant="normal">y</mi><mi mathvariant="normal">p</mi><mi mathvariant="normal">e</mi></mrow><mtext> </mtext><mi>t</mi><mi>y</mi><mi>p</mi><mi>e</mi><mi>i</mi><mi>d</mi><mi>x</mi><mo separator="true">,</mo><mrow><mi mathvariant="normal">l</mi><mi mathvariant="normal">o</mi><mi mathvariant="normal">c</mi><mi mathvariant="normal">a</mi><mi mathvariant="normal">l</mi><mi mathvariant="normal">s</mi></mrow><mtext> </mtext><mi>v</mi><mi>e</mi><mi>c</mi><mo stretchy="false">(</mo><mi>v</mi><mi>a</mi><mi>l</mi><mi>t</mi><mi>y</mi><mi>p</mi><mi>e</mi><mo stretchy="false">)</mo><mo separator="true">,</mo><mrow><mi mathvariant="normal">b</mi><mi mathvariant="normal">o</mi><mi mathvariant="normal">d</mi><mi mathvariant="normal">y</mi></mrow><mtext> </mtext><mi>e</mi><mi>x</mi><mi>p</mi><mi>r</mi><mo stretchy="false">}</mo></mrow><annotation encoding="application/x-tex">func ::= \{\mathrm{type}\ typeidx, \mathrm{locals}\ vec(valtype), \mathrm{body}\ expr\}
</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8888799999999999em;vertical-align:-0.19444em;"></span><span class="mord mathnormal" style="margin-right:0.10764em;">f</span><span class="mord mathnormal">u</span><span class="mord mathnormal">n</span><span class="mord mathnormal">c</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">:</span></span><span class="base"><span class="strut" style="height:0.43056em;vertical-align:0em;"></span><span class="mrel">:</span></span><span class="base"><span class="strut" style="height:0.36687em;vertical-align:0em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mopen">{</span><span class="mord"><span class="mord mathrm">t</span><span class="mord mathrm" style="margin-right:0.01389em;">y</span><span class="mord mathrm">p</span><span class="mord mathrm">e</span></span><span class="mspace"> </span><span class="mord mathnormal">t</span><span class="mord mathnormal" style="margin-right:0.03588em;">y</span><span class="mord mathnormal">p</span><span class="mord mathnormal">e</span><span class="mord mathnormal">i</span><span class="mord mathnormal">d</span><span class="mord mathnormal">x</span><span class="mpunct">,</span><span class="mspace" style="margin-right:0.16666666666666666em;"></span><span class="mord"><span class="mord mathrm">l</span><span class="mord mathrm">o</span><span class="mord mathrm">c</span><span class="mord mathrm">a</span><span class="mord mathrm">l</span><span class="mord mathrm">s</span></span><span class="mspace"> </span><span class="mord mathnormal" style="margin-right:0.03588em;">v</span><span class="mord mathnormal">e</span><span class="mord mathnormal">c</span><span class="mopen">(</span><span class="mord mathnormal" style="margin-right:0.03588em;">v</span><span class="mord mathnormal">a</span><span class="mord mathnormal" style="margin-right:0.01968em;">l</span><span class="mord mathnormal">t</span><span class="mord mathnormal" style="margin-right:0.03588em;">y</span><span class="mord mathnormal">p</span><span class="mord mathnormal">e</span><span class="mclose">)</span><span class="mpunct">,</span><span class="mspace" style="margin-right:0.16666666666666666em;"></span><span class="mord"><span class="mord mathrm">b</span><span class="mord mathrm">o</span><span class="mord mathrm">d</span><span class="mord mathrm" style="margin-right:0.01389em;">y</span></span><span class="mspace"> </span><span class="mord mathnormal">e</span><span class="mord mathnormal">x</span><span class="mord mathnormal">p</span><span class="mord mathnormal" style="margin-right:0.02778em;">r</span><span class="mclose">}</span></span></span></span></span></p>
<p>函数(function)的类型通过引用模块中定义的类型来声明其签名。<br />
该函数的参数通过函数主体中从0的局部索引进行引用; 他们是可变的。</p>
<p>局部变量(locals)声明一个可变局部变量及其类型的向量。<br />
这些变量是通过函数体内的局部索引来引用的。<br />
第一个局部变量的索引是最小索引,其不引用任何参数。</p>
<p>主体(body)是一个指令序列,在终止时必须产生一个与函数类型的结果类型(result type)匹配的堆栈。</p>
<p>函数通过函数索引被引用,由最小索引开始,不引用任何函数导入(function import)。</p>
<h4 id="254-表"><a class="markdownIt-Anchor" href="#254-表"></a> 2.5.4. 表</h4>
<p>模块的表组件定义了由表类型描述的一个表向量:</p>
<p class='katex-block'><span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><mi>t</mi><mi>a</mi><mi>b</mi><mi>l</mi><mi>e</mi><mo>:</mo><mo>:</mo><mo>=</mo><mo stretchy="false">{</mo><mrow><mi mathvariant="normal">t</mi><mi mathvariant="normal">y</mi><mi mathvariant="normal">p</mi><mi mathvariant="normal">e</mi></mrow><mtext> </mtext><mi>t</mi><mi>a</mi><mi>b</mi><mi>l</mi><mi>e</mi><mi>t</mi><mi>y</mi><mi>p</mi><mi>e</mi><mo stretchy="false">}</mo></mrow><annotation encoding="application/x-tex">table ::= \{ \mathrm{type}\ tabletype \}
</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.69444em;vertical-align:0em;"></span><span class="mord mathnormal">t</span><span class="mord mathnormal">a</span><span class="mord mathnormal">b</span><span class="mord mathnormal" style="margin-right:0.01968em;">l</span><span class="mord mathnormal">e</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">:</span></span><span class="base"><span class="strut" style="height:0.43056em;vertical-align:0em;"></span><span class="mrel">:</span></span><span class="base"><span class="strut" style="height:0.36687em;vertical-align:0em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mopen">{</span><span class="mord"><span class="mord mathrm">t</span><span class="mord mathrm" style="margin-right:0.01389em;">y</span><span class="mord mathrm">p</span><span class="mord mathrm">e</span></span><span class="mspace"> </span><span class="mord mathnormal">t</span><span class="mord mathnormal">a</span><span class="mord mathnormal">b</span><span class="mord mathnormal" style="margin-right:0.01968em;">l</span><span class="mord mathnormal">e</span><span class="mord mathnormal">t</span><span class="mord mathnormal" style="margin-right:0.03588em;">y</span><span class="mord mathnormal">p</span><span class="mord mathnormal">e</span><span class="mclose">}</span></span></span></span></span></p>
<p>表是特定表元素类型的不透明值的向量。<br />
表类型的限制中的最小的大小指定了该表的初始大小。<br />
而如果存在最大则其大小限制该表稍后可以增长至的大小。</p>
<p>可以通过元素段(element segment)初始化表。</p>
<p>通过表索引引用表,从最小索引开始,不需要引用一个表导入(table import)。<br />
大多数构造都隐式引用表索引0。</p>
<blockquote>
<p>注意</p>
<p>在当前版本的WebAssembly中,最多可以在一个模块中定义或导入一个表,并且所有构造都隐式引用表0。此限制在将来的版本中可能会取消。</p>
</blockquote>
<h4 id="255-内存"><a class="markdownIt-Anchor" href="#255-内存"></a> 2.5.5. 内存</h4>
<p>模块的内存(mems)组件定义了一个线性存储器(或简称为存储器)的向量,如其存储器类型所述:</p>
<p class='katex-block'><span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><mi>m</mi><mi>e</mi><mi>m</mi><mo>:</mo><mo>=</mo><mo stretchy="false">{</mo><mrow><mi mathvariant="normal">t</mi><mi mathvariant="normal">y</mi><mi mathvariant="normal">p</mi><mi mathvariant="normal">e</mi></mrow><mtext> </mtext><mi>m</mi><mi>e</mi><mi>m</mi><mi>t</mi><mi>y</mi><mi>p</mi><mi>e</mi><mo stretchy="false">}</mo></mrow><annotation encoding="application/x-tex">mem := \{\mathrm{type}\ memtype \}
</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.43056em;vertical-align:0em;"></span><span class="mord mathnormal">m</span><span class="mord mathnormal">e</span><span class="mord mathnormal">m</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">:</span></span><span class="base"><span class="strut" style="height:0.36687em;vertical-align:0em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mopen">{</span><span class="mord"><span class="mord mathrm">t</span><span class="mord mathrm" style="margin-right:0.01389em;">y</span><span class="mord mathrm">p</span><span class="mord mathrm">e</span></span><span class="mspace"> </span><span class="mord mathnormal">m</span><span class="mord mathnormal">e</span><span class="mord mathnormal">m</span><span class="mord mathnormal">t</span><span class="mord mathnormal" style="margin-right:0.03588em;">y</span><span class="mord mathnormal">p</span><span class="mord mathnormal">e</span><span class="mclose">}</span></span></span></span></span></p>
<p>内存是未被解释的原始字节的向量。<br />
内存类型的限制中的最小(Min)大小指定该内存的初始大小,而最大内存大小(Max,如果存在)则限制了以后可以增长的大小。<br />
两者均以页面大小为单位。</p>
<p>可以通过数据段(data segment)初始化内存。</p>
<p>内存被内存索引引用,从最小索引开始,不引用内存导入(memory import)。<br />
大多数构造都隐式引用内存索引0。</p>
<blockquote>
<p>注意</p>
<p>在当前版本的WebAssembly中,最多可以在一个模块中定义或导入一个内存,并且所有构造都隐式引用此内存0。此限制在将来的版本中可能会取消。</p>
<p>(换句话说现在的mems根本就是个单元素数组,里面就一个memory)</p>
</blockquote>
<h4 id="256-全局变量globals"><a class="markdownIt-Anchor" href="#256-全局变量globals"></a> 2.5.6. 全局变量Globals</h4>
<p>模块的全局变量组件定义了一个全局变量的向量(或简称为globals):</p>
<p class='katex-block'><span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><mi>g</mi><mi>l</mi><mi>o</mi><mi>b</mi><mi>a</mi><mi>l</mi><mo>:</mo><mo>:</mo><mo>=</mo><mo stretchy="false">{</mo><mrow><mi mathvariant="normal">t</mi><mi mathvariant="normal">y</mi><mi mathvariant="normal">p</mi><mi mathvariant="normal">e</mi></mrow><mtext> </mtext><mi>g</mi><mi>l</mi><mi>o</mi><mi>b</mi><mi>a</mi><mi>l</mi><mi>t</mi><mi>y</mi><mi>p</mi><mi>e</mi><mo separator="true">,</mo><mrow><mi mathvariant="normal">i</mi><mi mathvariant="normal">n</mi><mi mathvariant="normal">i</mi><mi mathvariant="normal">t</mi></mrow><mtext> </mtext><mi>e</mi><mi>x</mi><mi>p</mi><mi>r</mi><mo stretchy="false">}</mo></mrow><annotation encoding="application/x-tex">global ::= \{ \mathrm{type}\ globaltype, \mathrm{init}\ expr\}
</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8888799999999999em;vertical-align:-0.19444em;"></span><span class="mord mathnormal" style="margin-right:0.03588em;">g</span><span class="mord mathnormal" style="margin-right:0.01968em;">l</span><span class="mord mathnormal">o</span><span class="mord mathnormal">b</span><span class="mord mathnormal">a</span><span class="mord mathnormal" style="margin-right:0.01968em;">l</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">:</span></span><span class="base"><span class="strut" style="height:0.43056em;vertical-align:0em;"></span><span class="mrel">:</span></span><span class="base"><span class="strut" style="height:0.36687em;vertical-align:0em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mopen">{</span><span class="mord"><span class="mord mathrm">t</span><span class="mord mathrm" style="margin-right:0.01389em;">y</span><span class="mord mathrm">p</span><span class="mord mathrm">e</span></span><span class="mspace"> </span><span class="mord mathnormal" style="margin-right:0.03588em;">g</span><span class="mord mathnormal" style="margin-right:0.01968em;">l</span><span class="mord mathnormal">o</span><span class="mord mathnormal">b</span><span class="mord mathnormal">a</span><span class="mord mathnormal" style="margin-right:0.01968em;">l</span><span class="mord mathnormal">t</span><span class="mord mathnormal" style="margin-right:0.03588em;">y</span><span class="mord mathnormal">p</span><span class="mord mathnormal">e</span><span class="mpunct">,</span><span class="mspace" style="margin-right:0.16666666666666666em;"></span><span class="mord"><span class="mord mathrm">i</span><span class="mord mathrm">n</span><span class="mord mathrm">i</span><span class="mord mathrm">t</span></span><span class="mspace"> </span><span class="mord mathnormal">e</span><span class="mord mathnormal">x</span><span class="mord mathnormal">p</span><span class="mord mathnormal" style="margin-right:0.02778em;">r</span><span class="mclose">}</span></span></span></span></span></p>
<p>每个全局变量都存储给定全局变量类型(global type)的单个值。<br />
它的类型还指定了全局变量是不可变的还是可变的。<br />
此外,每个全局变量都使用常量初始化表达式(expr)给出的初始化值进行初始化。</p>
<p>全局变量通过全局索引引用,从最小的索引开始,不引用全局导入。</p>
<h4 id="257-元素段-element-segments"><a class="markdownIt-Anchor" href="#257-元素段-element-segments"></a> 2.5.7. 元素段 Element Segments</h4>
<p>表的初始内容未初始化。<br />
模块的elem组件定义元素段的向量,这些向量以给定的偏移量从元素的静态向量初始化表的子范围。</p>
<p class='katex-block'><span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><mi>e</mi><mi>l</mi><mi>e</mi><mi>m</mi><mo>:</mo><mo>:</mo><mo>=</mo><mo stretchy="false">{</mo><mrow><mi mathvariant="normal">t</mi><mi mathvariant="normal">a</mi><mi mathvariant="normal">b</mi><mi mathvariant="normal">l</mi><mi mathvariant="normal">e</mi></mrow><mtext> </mtext><mi>t</mi><mi>a</mi><mi>b</mi><mi>l</mi><mi>e</mi><mi>i</mi><mi>d</mi><mi>x</mi><mo separator="true">,</mo><mrow><mi mathvariant="normal">o</mi><mi mathvariant="normal">f</mi><mi mathvariant="normal">f</mi><mi mathvariant="normal">s</mi><mi mathvariant="normal">e</mi><mi mathvariant="normal">t</mi></mrow><mtext> </mtext><mi>e</mi><mi>x</mi><mi>p</mi><mi>r</mi><mi>e</mi><mi>s</mi><mi>s</mi><mo separator="true">,</mo><mrow><mi mathvariant="normal">i</mi><mi mathvariant="normal">n</mi><mi mathvariant="normal">i</mi><mi mathvariant="normal">t</mi></mrow><mi>v</mi><mi>e</mi><mi>c</mi><mo stretchy="false">(</mo><mi>f</mi><mi>u</mi><mi>n</mi><mi>c</mi><mi>i</mi><mi>d</mi><mi>x</mi><mo stretchy="false">)</mo><mo stretchy="false">}</mo></mrow><annotation encoding="application/x-tex">elem ::= \{ \mathrm{table}\ tableidx, \mathrm{offset}\ express, \mathrm{init} vec(funcidx)\}
</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.69444em;vertical-align:0em;"></span><span class="mord mathnormal">e</span><span class="mord mathnormal" style="margin-right:0.01968em;">l</span><span class="mord mathnormal">e</span><span class="mord mathnormal">m</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">:</span></span><span class="base"><span class="strut" style="height:0.43056em;vertical-align:0em;"></span><span class="mrel">:</span></span><span class="base"><span class="strut" style="height:0.36687em;vertical-align:0em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mopen">{</span><span class="mord"><span class="mord mathrm">t</span><span class="mord mathrm">a</span><span class="mord mathrm">b</span><span class="mord mathrm">l</span><span class="mord mathrm">e</span></span><span class="mspace"> </span><span class="mord mathnormal">t</span><span class="mord mathnormal">a</span><span class="mord mathnormal">b</span><span class="mord mathnormal" style="margin-right:0.01968em;">l</span><span class="mord mathnormal">e</span><span class="mord mathnormal">i</span><span class="mord mathnormal">d</span><span class="mord mathnormal">x</span><span class="mpunct">,</span><span class="mspace" style="margin-right:0.16666666666666666em;"></span><span class="mord"><span class="mord mathrm">o</span><span class="mord mathrm" style="margin-right:0.07778em;">f</span><span class="mord mathrm" style="margin-right:0.07778em;">f</span><span class="mord mathrm">s</span><span class="mord mathrm">e</span><span class="mord mathrm">t</span></span><span class="mspace"> </span><span class="mord mathnormal">e</span><span class="mord mathnormal">x</span><span class="mord mathnormal">p</span><span class="mord mathnormal" style="margin-right:0.02778em;">r</span><span class="mord mathnormal">e</span><span class="mord mathnormal">s</span><span class="mord mathnormal">s</span><span class="mpunct">,</span><span class="mspace" style="margin-right:0.16666666666666666em;"></span><span class="mord"><span class="mord mathrm">i</span><span class="mord mathrm">n</span><span class="mord mathrm">i</span><span class="mord mathrm">t</span></span><span class="mord mathnormal" style="margin-right:0.03588em;">v</span><span class="mord mathnormal">e</span><span class="mord mathnormal">c</span><span class="mopen">(</span><span class="mord mathnormal" style="margin-right:0.10764em;">f</span><span class="mord mathnormal">u</span><span class="mord mathnormal">n</span><span class="mord mathnormal">c</span><span class="mord mathnormal">i</span><span class="mord mathnormal">d</span><span class="mord mathnormal">x</span><span class="mclose">)</span><span class="mclose">}</span></span></span></span></span></p>
<p>偏移量(offset)由一个常量表达式给出。</p>
<blockquote>
<p>注意</p>
<p>在当前版本的WebAssembly中,模块中最多允许一个表。因此,唯一有效的tableidx为0。</p>
</blockquote>
<h4 id="258-数据段-data-segments"><a class="markdownIt-Anchor" href="#258-数据段-data-segments"></a> 2.5.8. 数据段 Data Segments</h4>
<p>内存的初始内容为一堆零值字节。<br />
模块的数据组件定义数据段的向量,这些数据段以给定的偏移量和静态字节向量来初始化内存范围。</p>
<p class='katex-block'><span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><mi>d</mi><mi>a</mi><mi>t</mi><mi>a</mi><mo>:</mo><mo>:</mo><mo>=</mo><mo stretchy="false">{</mo><mrow><mi mathvariant="normal">d</mi><mi mathvariant="normal">a</mi><mi mathvariant="normal">t</mi><mi mathvariant="normal">a</mi></mrow><mtext> </mtext><mi>m</mi><mi>e</mi><mi>m</mi><mi>i</mi><mi>d</mi><mi>x</mi><mo separator="true">,</mo><mrow><mi mathvariant="normal">o</mi><mi mathvariant="normal">f</mi><mi mathvariant="normal">f</mi><mi mathvariant="normal">s</mi><mi mathvariant="normal">e</mi><mi mathvariant="normal">t</mi></mrow><mtext> </mtext><mi>e</mi><mi>x</mi><mi>p</mi><mi>r</mi><mo separator="true">,</mo><mrow><mi mathvariant="normal">i</mi><mi mathvariant="normal">n</mi><mi mathvariant="normal">i</mi><mi mathvariant="normal">t</mi></mrow><mtext> </mtext><mi>v</mi><mi>e</mi><mi>c</mi><mo stretchy="false">(</mo><mi>b</mi><mi>y</mi><mi>t</mi><mi>e</mi><mo stretchy="false">)</mo><mo stretchy="false">}</mo></mrow><annotation encoding="application/x-tex">data ::= \{ \mathrm{data}\ memidx, \mathrm{offset}\ expr, \mathrm{init}\ vec(byte) \}
</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.69444em;vertical-align:0em;"></span><span class="mord mathnormal">d</span><span class="mord mathnormal">a</span><span class="mord mathnormal">t</span><span class="mord mathnormal">a</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">:</span></span><span class="base"><span class="strut" style="height:0.43056em;vertical-align:0em;"></span><span class="mrel">:</span></span><span class="base"><span class="strut" style="height:0.36687em;vertical-align:0em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mopen">{</span><span class="mord"><span class="mord mathrm">d</span><span class="mord mathrm">a</span><span class="mord mathrm">t</span><span class="mord mathrm">a</span></span><span class="mspace"> </span><span class="mord mathnormal">m</span><span class="mord mathnormal">e</span><span class="mord mathnormal">m</span><span class="mord mathnormal">i</span><span class="mord mathnormal">d</span><span class="mord mathnormal">x</span><span class="mpunct">,</span><span class="mspace" style="margin-right:0.16666666666666666em;"></span><span class="mord"><span class="mord mathrm">o</span><span class="mord mathrm" style="margin-right:0.07778em;">f</span><span class="mord mathrm" style="margin-right:0.07778em;">f</span><span class="mord mathrm">s</span><span class="mord mathrm">e</span><span class="mord mathrm">t</span></span><span class="mspace"> </span><span class="mord mathnormal">e</span><span class="mord mathnormal">x</span><span class="mord mathnormal">p</span><span class="mord mathnormal" style="margin-right:0.02778em;">r</span><span class="mpunct">,</span><span class="mspace" style="margin-right:0.16666666666666666em;"></span><span class="mord"><span class="mord mathrm">i</span><span class="mord mathrm">n</span><span class="mord mathrm">i</span><span class="mord mathrm">t</span></span><span class="mspace"> </span><span class="mord mathnormal" style="margin-right:0.03588em;">v</span><span class="mord mathnormal">e</span><span class="mord mathnormal">c</span><span class="mopen">(</span><span class="mord mathnormal">b</span><span class="mord mathnormal" style="margin-right:0.03588em;">y</span><span class="mord mathnormal">t</span><span class="mord mathnormal">e</span><span class="mclose">)</span><span class="mclose">}</span></span></span></span></span></p>
<p>偏移量(offset)由一个常量表达式给出。</p>
<blockquote>
<p>注意</p>
<p>在当前版本的WebAssembly中,一个模块中最多允许有一个内存。 因此,唯一有效的memidx为0。</p>
</blockquote>
<h4 id="259-启动函数-start-function"><a class="markdownIt-Anchor" href="#259-启动函数-start-function"></a> 2.5.9. 启动函数 Start Function</h4>
<p>模块的启动(start)组件声明一个启动函数的函数索引,该函数在初始化表和内存后在实例化模块时自动调用。</p>
<p class='katex-block'><span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><mi>s</mi><mi>t</mi><mi>a</mi><mi>r</mi><mi>t</mi><mo>:</mo><mo>:</mo><mo>=</mo><mo stretchy="false">{</mo><mrow><mi mathvariant="normal">f</mi><mi mathvariant="normal">u</mi><mi mathvariant="normal">n</mi><mi mathvariant="normal">c</mi></mrow><mtext> </mtext><mi>f</mi><mi>u</mi><mi>n</mi><mi>c</mi><mi>i</mi><mi>d</mi><mi>x</mi><mo stretchy="false">}</mo></mrow><annotation encoding="application/x-tex">start ::= \{ \mathrm{func}\ funcidx \}
</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.61508em;vertical-align:0em;"></span><span class="mord mathnormal">s</span><span class="mord mathnormal">t</span><span class="mord mathnormal">a</span><span class="mord mathnormal" style="margin-right:0.02778em;">r</span><span class="mord mathnormal">t</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">:</span></span><span class="base"><span class="strut" style="height:0.43056em;vertical-align:0em;"></span><span class="mrel">:</span></span><span class="base"><span class="strut" style="height:0.36687em;vertical-align:0em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mopen">{</span><span class="mord"><span class="mord mathrm" style="margin-right:0.07778em;">f</span><span class="mord mathrm">u</span><span class="mord mathrm">n</span><span class="mord mathrm">c</span></span><span class="mspace"> </span><span class="mord mathnormal" style="margin-right:0.10764em;">f</span><span class="mord mathnormal">u</span><span class="mord mathnormal">n</span><span class="mord mathnormal">c</span><span class="mord mathnormal">i</span><span class="mord mathnormal">d</span><span class="mord mathnormal">x</span><span class="mclose">}</span></span></span></span></span></p>
<blockquote>
<p>注意</p>
<p>启动功能用于初始化模块的状态。在初始化完成之前,无法访问模块及其导出(exports)。</p>
</blockquote>
<h4 id="2510-导出-exports"><a class="markdownIt-Anchor" href="#2510-导出-exports"></a> 2.5.10. 导出 exports</h4>
<p>模块的导出组件定义了一组导出。一旦实例化该模块,主机环境就可以访问它们。</p>
<p class='katex-block'><span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><mi>e</mi><mi>x</mi><mi>p</mi><mi>o</mi><mi>r</mi><mi>t</mi><mo>:</mo><mo>:</mo><mo>=</mo><mo stretchy="false">{</mo><mrow><mi mathvariant="normal">n</mi><mi mathvariant="normal">a</mi><mi mathvariant="normal">m</mi><mi mathvariant="normal">e</mi></mrow><mtext> </mtext><mi>n</mi><mi>a</mi><mi>m</mi><mi>e</mi><mo separator="true">,</mo><mrow><mi mathvariant="normal">d</mi><mi mathvariant="normal">e</mi><mi mathvariant="normal">s</mi><mi mathvariant="normal">c</mi></mrow><mtext> </mtext><mi>e</mi><mi>x</mi><mi>p</mi><mi>o</mi><mi>r</mi><mi>t</mi><mi>d</mi><mi>e</mi><mi>s</mi><mi>c</mi><mo stretchy="false">}</mo></mrow><annotation encoding="application/x-tex">export ::= \{ \mathrm{name}\ name, \mathrm{desc}\ exportdesc \}
</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.80952em;vertical-align:-0.19444em;"></span><span class="mord mathnormal">e</span><span class="mord mathnormal">x</span><span class="mord mathnormal">p</span><span class="mord mathnormal">o</span><span class="mord mathnormal" style="margin-right:0.02778em;">r</span><span class="mord mathnormal">t</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">:</span></span><span class="base"><span class="strut" style="height:0.43056em;vertical-align:0em;"></span><span class="mrel">:</span></span><span class="base"><span class="strut" style="height:0.36687em;vertical-align:0em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mopen">{</span><span class="mord"><span class="mord mathrm">n</span><span class="mord mathrm">a</span><span class="mord mathrm">m</span><span class="mord mathrm">e</span></span><span class="mspace"> </span><span class="mord mathnormal">n</span><span class="mord mathnormal">a</span><span class="mord mathnormal">m</span><span class="mord mathnormal">e</span><span class="mpunct">,</span><span class="mspace" style="margin-right:0.16666666666666666em;"></span><span class="mord"><span class="mord mathrm">d</span><span class="mord mathrm">e</span><span class="mord mathrm">s</span><span class="mord mathrm">c</span></span><span class="mspace"> </span><span class="mord mathnormal">e</span><span class="mord mathnormal">x</span><span class="mord mathnormal">p</span><span class="mord mathnormal">o</span><span class="mord mathnormal" style="margin-right:0.02778em;">r</span><span class="mord mathnormal">t</span><span class="mord mathnormal">d</span><span class="mord mathnormal">e</span><span class="mord mathnormal">s</span><span class="mord mathnormal">c</span><span class="mclose">}</span></span></span></span></span></p>
<p class='katex-block katex-error' title='ParseError: KaTeX parse error: Undefined control sequence: \displaylines at position 2: \̲d̲i̲s̲p̲l̲a̲y̲l̲i̲n̲e̲s̲{ exportdesc ::…'> \displaylines{ exportdesc ::= \mathrm{func}\ funcidx\\
| \mathrm{table}\ tableidx\\
| \mathrm{mem}\ memidx\\
| \mathrm{global}\ globalidx}</p>
<p>每个导出都用唯一的名称标记。<br />
可导出的定义是函数,表,内存和全局变量,它们通过相应的描述符进行引用。</p>
<h5 id="25101-惯例"><a class="markdownIt-Anchor" href="#25101-惯例"></a> 2.5.10.1. 惯例</h5>
<p>为导出序列定义了以下辅助符号,以保留顺序的方式过滤出特定种类的索引:</p>
<ul>
<li><span class='katex-error' title='ParseError: KaTeX parse error: Undefined control sequence: \[ at position 16: func(export^*)=\̲[̲ funcidx | \mat…'>func(export^*)=\[ funcidx | \mathrm(func)\ funcidx \in (export.\mathrm{desc}) \]</span></li>
<li><span class='katex-error' title='ParseError: KaTeX parse error: Undefined control sequence: \[ at position 18: …bles(export^*)=\̲[̲ tableidx | \ma…'>tables(export^*)=\[ tableidx | \mathrm(table)\ tableidx \in (export.\mathrm{desc}) \]</span></li>
<li><span class='katex-error' title='ParseError: KaTeX parse error: Undefined control sequence: \[ at position 16: mems(export^*)=\̲[̲ memidx | \math…'>mems(export^*)=\[ memidx | \mathrm(mem)\ memidx \in (export.\mathrm{desc}) \]</span></li>
<li><span class='katex-error' title='ParseError: KaTeX parse error: Undefined control sequence: \[ at position 19: …bals(export^*)=\̲[̲ globalidx | \m…'>globals(export^*)=\[ globalidx | \mathrm(global)\ globalidx \in (export.\mathrm{desc}) \]</span></li>
</ul>
<h4 id="2511-导入-imports"><a class="markdownIt-Anchor" href="#2511-导入-imports"></a> 2.5.11. 导入 imports</h4>
<p>模块的导入组件定义了实例化所需的一组导入。</p>
<p class='katex-block'><span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><mi>i</mi><mi>m</mi><mi>p</mi><mi>o</mi><mi>r</mi><mi>t</mi><mo>:</mo><mo>:</mo><mo>=</mo><mo stretchy="false">{</mo><mrow><mi mathvariant="normal">m</mi><mi mathvariant="normal">o</mi><mi mathvariant="normal">d</mi><mi mathvariant="normal">u</mi><mi mathvariant="normal">l</mi><mi mathvariant="normal">e</mi></mrow><mtext> </mtext><mi>n</mi><mi>a</mi><mi>m</mi><mi>e</mi><mo separator="true">,</mo><mrow><mi mathvariant="normal">n</mi><mi mathvariant="normal">a</mi><mi mathvariant="normal">m</mi><mi mathvariant="normal">e</mi></mrow><mtext> </mtext><mi>n</mi><mi>a</mi><mi>m</mi><mi>e</mi><mo separator="true">,</mo><mrow><mi mathvariant="normal">d</mi><mi mathvariant="normal">e</mi><mi mathvariant="normal">s</mi><mi mathvariant="normal">c</mi></mrow><mtext> </mtext><mi>i</mi><mi>m</mi><mi>p</mi><mi>o</mi><mi>r</mi><mi>t</mi><mi>d</mi><mi>e</mi><mi>s</mi><mi>c</mi><mo stretchy="false">}</mo></mrow><annotation encoding="application/x-tex">import ::= \{ \mathrm{module}\ name, \mathrm{name}\ name, \mathrm{desc}\ importdesc\}
</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.85396em;vertical-align:-0.19444em;"></span><span class="mord mathnormal">i</span><span class="mord mathnormal">m</span><span class="mord mathnormal">p</span><span class="mord mathnormal">o</span><span class="mord mathnormal" style="margin-right:0.02778em;">r</span><span class="mord mathnormal">t</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">:</span></span><span class="base"><span class="strut" style="height:0.43056em;vertical-align:0em;"></span><span class="mrel">:</span></span><span class="base"><span class="strut" style="height:0.36687em;vertical-align:0em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mopen">{</span><span class="mord"><span class="mord mathrm">m</span><span class="mord mathrm">o</span><span class="mord mathrm">d</span><span class="mord mathrm">u</span><span class="mord mathrm">l</span><span class="mord mathrm">e</span></span><span class="mspace"> </span><span class="mord mathnormal">n</span><span class="mord mathnormal">a</span><span class="mord mathnormal">m</span><span class="mord mathnormal">e</span><span class="mpunct">,</span><span class="mspace" style="margin-right:0.16666666666666666em;"></span><span class="mord"><span class="mord mathrm">n</span><span class="mord mathrm">a</span><span class="mord mathrm">m</span><span class="mord mathrm">e</span></span><span class="mspace"> </span><span class="mord mathnormal">n</span><span class="mord mathnormal">a</span><span class="mord mathnormal">m</span><span class="mord mathnormal">e</span><span class="mpunct">,</span><span class="mspace" style="margin-right:0.16666666666666666em;"></span><span class="mord"><span class="mord mathrm">d</span><span class="mord mathrm">e</span><span class="mord mathrm">s</span><span class="mord mathrm">c</span></span><span class="mspace"> </span><span class="mord mathnormal">i</span><span class="mord mathnormal">m</span><span class="mord mathnormal">p</span><span class="mord mathnormal">o</span><span class="mord mathnormal" style="margin-right:0.02778em;">r</span><span class="mord mathnormal">t</span><span class="mord mathnormal">d</span><span class="mord mathnormal">e</span><span class="mord mathnormal">s</span><span class="mord mathnormal">c</span><span class="mclose">}</span></span></span></span></span></p>
<p class='katex-block katex-error' title='ParseError: KaTeX parse error: Undefined control sequence: \displaylines at position 2: \̲d̲i̲s̲p̲l̲a̲y̲l̲i̲n̲e̲s̲{ importdesc ::…'> \displaylines{ importdesc ::= \mathrm{func}\ typeidx\\
| \mathrm{table}\ tabletype\\
| \mathrm{mem}\ memtype\\
| \mathrm{global}\ globaltype}</p>
<p>每个导入都由两级名称空间标记,该名称空间由<em>模块名称</em>和该模块内<em>实体的名称</em>组成。<br />
可导入的定义为函数,表,内存和全局变量。<br />
每个导入都由一个描述符指定,该描述符的类型与实例化期间提供的定义必须匹配。</p>
<p>每次导入都会在相应的索引空间(index space)中定义一个索引。<br />
在每个索引空间中,导入索引都位于模块本身包含的任何定义的第一个索引之前。</p>
<blockquote>
<p>注意</p>
<p>与导出名称不同,导入名称不一定是唯一的。<br />
可以多次导入同一“模块名::名称”。<br />
这样的导入甚至可能具有不同的类型描述,包括不同种类的实体。<br />
仍然可以实例化具有此类导入的模块,具体取决于<em>嵌入程序</em>如何允许解析和提供导入的细节。<br />
但是,不需要嵌入程序来支持此类重载,并且WebAssembly模块本身无法实现重载名称。</p>
</blockquote>
<h2 id="3-验证"><a class="markdownIt-Anchor" href="#3-验证"></a> 3. 验证</h2>
<h3 id="31-惯例"><a class="markdownIt-Anchor" href="#31-惯例"></a> 3.1. 惯例</h3>
<p>验证将检查WebAssembly模块的格式是否正确,因为只能有效的模块能够被实例化。</p>
<p>有效性是由类型系统根据模块及其内容的抽象语法定义的。<br />
对于每个抽象语法,都有一个键入规则,用于指定适用于它的约束。<br />
所有规则均以两种等效形式给出:</p>
<ul>
<li>用行文,以直观的形式描述含义。</li>
<li>用公式表示法,以数学形式描述规则。[1]</li>
</ul>
<blockquote>
<p>注意</p>
<p>行文和公式规则是等效的,因此阅读本规范不需要理解公式符号。<br />
公式提供了更简洁的符号描述,该符号广泛用于编程语言的语义中,并易于进行数学证明。</p>
</blockquote>
<p>在这两种情况下,规则都是以声明方式制定的。也就是说,它们仅制定约束条件,而没有定义算法。<br />
附录中提供了根据本规范的用于类型检查指令序列的健全完整算法的框架。</p>
<h4 id="311-上下文"><a class="markdownIt-Anchor" href="#311-上下文"></a> 3.1.1. 上下文</h4>
<p>单个定义的有效性被制定为与上下文相关,该上下文收集有关周围模块和范围内定义的相关信息:</p>
<ul>
<li>类型:当前模块中定义的类型列表。</li>
<li>函数:在当前模块中声明的功能列表,以其功能类型表示。</li>
<li>表:在当前模块中声明的表格列表,以表格类型表示。</li>
<li>内存:在当前模块中声明的内存列表,以其内存类型表示。</li>
<li>全局变量:在当前模块中声明的全局变量列表,以其全局类型表示。</li>
<li>局部变量:在当前函数中声明的本地列表(包括参数),以其值类型表示。</li>
<li>标签:从当前位置可访问的标签堆栈,以其结果类型表示。</li>
<li>返回值:当前函数的返回类型,表示为可选结果类型,当不允许返回时(如独立表达式),该结果类型不存在。</li>
</ul>
<p>换句话说,上下文包含每个索引空间的一系列适当类型,描述该空间中的每个定义条目。<br />
局部变量,标签和返回类型仅用于验证函数体中的指令,而在其他地方保留为空。<br />
标签栈是上下文中随指令序列的验证而变化的唯一部分。</p>
<p>更具体地说,上下文被定义为具有抽象语法的记录(records),<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>C</mi></mrow><annotation encoding="application/x-tex">C</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.68333em;vertical-align:0em;"></span><span class="mord mathnormal" style="margin-right:0.07153em;">C</span></span></span></span>:</p>
<p class='katex-block katex-error' title='ParseError: KaTeX parse error: Undefined control sequence: \displaylines at position 2: \̲d̲i̲s̲p̲l̲a̲y̲l̲i̲n̲e̲s̲{C::=\mathrm{ty…'> \displaylines{C::=\mathrm{types}\ functype^*,\\
\mathrm{funcs}\ functype^*,\\
\mathrm{tables}\ tabletype^*,\\
\mathrm{mems}\ memtype^*,\\
\mathrm{globals}\ globaltype^*,\\
\mathrm{locals}\ valtype^*,\\
\mathrm{labels}\ resulttype^*,\\
\mathrm{return}\ resulttype^?}</p>
<p>除了使用<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>C</mi><mi mathvariant="normal">.</mi><mrow><mi mathvariant="normal">f</mi><mi mathvariant="normal">i</mi><mi mathvariant="normal">e</mi><mi mathvariant="normal">l</mi><mi mathvariant="normal">d</mi></mrow></mrow><annotation encoding="application/x-tex">C.\mathrm{field}</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.69444em;vertical-align:0em;"></span><span class="mord mathnormal" style="margin-right:0.07153em;">C</span><span class="mord">.</span><span class="mord"><span class="mord mathrm" style="margin-right:0.07778em;">f</span><span class="mord mathrm">i</span><span class="mord mathrm">e</span><span class="mord mathrm">l</span><span class="mord mathrm">d</span></span></span></span></span>编写的现场访问外,还采用以下表示法来处理上下文:</p>
<ul>
<li>拼写上下文时,将省略空白字段。</li>
<li><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>C</mi><mo separator="true">,</mo><mrow><mi mathvariant="normal">f</mi><mi mathvariant="normal">i</mi><mi mathvariant="normal">e</mi><mi mathvariant="normal">l</mi><mi mathvariant="normal">d</mi></mrow><mtext> </mtext><msup><mi>A</mi><mo>∗</mo></msup></mrow><annotation encoding="application/x-tex">C, \mathrm{field}\ A^*</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8888799999999999em;vertical-align:-0.19444em;"></span><span class="mord mathnormal" style="margin-right:0.07153em;">C</span><span class="mpunct">,</span><span class="mspace" style="margin-right:0.16666666666666666em;"></span><span class="mord"><span class="mord mathrm" style="margin-right:0.07778em;">f</span><span class="mord mathrm">i</span><span class="mord mathrm">e</span><span class="mord mathrm">l</span><span class="mord mathrm">d</span></span><span class="mspace"> </span><span class="mord"><span class="mord mathnormal">A</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.688696em;"><span style="top:-3.063em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mbin mtight">∗</span></span></span></span></span></span></span></span></span></span></span>表示与<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>C</mi></mrow><annotation encoding="application/x-tex">C</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.68333em;vertical-align:0em;"></span><span class="mord mathnormal" style="margin-right:0.07153em;">C</span></span></span></span>相同的上下文,但元素<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msup><mi>A</mi><mo>∗</mo></msup></mrow><annotation encoding="application/x-tex">A^*</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.688696em;vertical-align:0em;"></span><span class="mord"><span class="mord mathnormal">A</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.688696em;"><span style="top:-3.063em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mbin mtight">∗</span></span></span></span></span></span></span></span></span></span></span>附加在其<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi mathvariant="normal">f</mi><mi mathvariant="normal">i</mi><mi mathvariant="normal">e</mi><mi mathvariant="normal">l</mi><mi mathvariant="normal">d</mi></mrow><annotation encoding="application/x-tex">\mathrm{field}</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.69444em;vertical-align:0em;"></span><span class="mord"><span class="mord mathrm" style="margin-right:0.07778em;">f</span><span class="mord mathrm">i</span><span class="mord mathrm">e</span><span class="mord mathrm">l</span><span class="mord mathrm">d</span></span></span></span></span>组件序列之前。</li>
</ul>
<blockquote>
<p>注意</p>
<p>我们使用诸如<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>C</mi><mi mathvariant="normal">.</mi><mi>l</mi><mi>a</mi><mi>b</mi><mi>e</mi><mi>l</mi><mi>s</mi><mo stretchy="false">[</mo><mi>i</mi><mo stretchy="false">]</mo></mrow><annotation encoding="application/x-tex">C.labels[i]</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord mathnormal" style="margin-right:0.07153em;">C</span><span class="mord">.</span><span class="mord mathnormal" style="margin-right:0.01968em;">l</span><span class="mord mathnormal">a</span><span class="mord mathnormal">b</span><span class="mord mathnormal">e</span><span class="mord mathnormal" style="margin-right:0.01968em;">l</span><span class="mord mathnormal">s</span><span class="mopen">[</span><span class="mord mathnormal">i</span><span class="mclose">]</span></span></span></span>之类的索引符号在上下文中的相应索引空间中查找索引。<br />
上下文扩展符号<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>C</mi><mtext>,</mtext><mrow><mi mathvariant="normal">f</mi><mi mathvariant="normal">i</mi><mi mathvariant="normal">e</mi><mi mathvariant="normal">l</mi><mi mathvariant="normal">d</mi></mrow><mtext> </mtext><mi>A</mi></mrow><annotation encoding="application/x-tex">C,\mathrm{field}\ A</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.69444em;vertical-align:0em;"></span><span class="mord mathnormal" style="margin-right:0.07153em;">C</span><span class="mord cjk_fallback">,</span><span class="mord"><span class="mord mathrm" style="margin-right:0.07778em;">f</span><span class="mord mathrm">i</span><span class="mord mathrm">e</span><span class="mord mathrm">l</span><span class="mord mathrm">d</span></span><span class="mspace"> </span><span class="mord mathnormal">A</span></span></span></span>主要用于局部扩展相对索引空间,例如标签索引。<br />
因此,将符号定义为附加在各个序列的前面,引入新的相对索引0并移动现有的相对索引。</p>
</blockquote>
<h4 id="312-行文符号"><a class="markdownIt-Anchor" href="#312-行文符号"></a> 3.1.2. 行文符号</h4>
<p>验证由程式化规则为抽象语法的每个相关部分指定。 这些规则不仅说明定义短语何时有效的约束,而且还使用类型对短语进行分类。 在说明这些规则时采用了以下约定。</p>
<ul>
<li>当且仅当满足相应规则表示的所有约束时,短语A才被称为“对于T型有效”。 T的形式取决于A是什么。</li>
</ul>
<blockquote>
<p>注意</p>
<p>例如,如果<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>A</mi></mrow><annotation encoding="application/x-tex">A</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.68333em;vertical-align:0em;"></span><span class="mord mathnormal">A</span></span></span></span>是一个函数,则<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>T</mi></mrow><annotation encoding="application/x-tex">T</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.68333em;vertical-align:0em;"></span><span class="mord mathnormal" style="margin-right:0.13889em;">T</span></span></span></span>也是一个函数类型。<br />
如果<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>A</mi></mrow><annotation encoding="application/x-tex">A</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.68333em;vertical-align:0em;"></span><span class="mord mathnormal">A</span></span></span></span>是全局类型,则<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>T</mi></mrow><annotation encoding="application/x-tex">T</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.68333em;vertical-align:0em;"></span><span class="mord mathnormal" style="margin-right:0.13889em;">T</span></span></span></span>也是全局类型; 如此类推。</p>
</blockquote>
<ul>
<li>
<p>规则隐式假定给定上下文<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>C</mi></mrow><annotation encoding="application/x-tex">C</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.68333em;vertical-align:0em;"></span><span class="mord mathnormal" style="margin-right:0.07153em;">C</span></span></span></span>。</p>
</li>
<li>
<p>在某些地方,此上下文在本地扩展到带有其他条目的上下文<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msup><mi>C</mi><mo mathvariant="normal" lspace="0em" rspace="0em">′</mo></msup></mrow><annotation encoding="application/x-tex">C'</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.751892em;vertical-align:0em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.07153em;">C</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.751892em;"><span style="top:-3.063em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mtight">′</span></span></span></span></span></span></span></span></span></span></span></span>。措词“<em>在上下文中<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msup><mi>C</mi><mo mathvariant="normal" lspace="0em" rspace="0em">′</mo></msup></mrow><annotation encoding="application/x-tex">C'</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.751892em;vertical-align:0em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.07153em;">C</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.751892em;"><span style="top:-3.063em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mtight">′</span></span></span></span></span></span></span></span></span></span></span></span>,…声明…</em>”用于表示以下声明必须在扩展上下文中包含的假设下适用。</p>
</li>
</ul>
<h4 id="313-正式符号"><a class="markdownIt-Anchor" href="#313-正式符号"></a> 3.1.3. 正式符号</h4>
<blockquote>
<p>注意</p>
<p>本节简要说明了正式指定键入规则的表示法。<br />
对于感兴趣的读者,可以在相应的书中找到更全面的介绍。 [2]</p>
</blockquote>
<p>短语<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>A</mi></mrow><annotation encoding="application/x-tex">A</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.68333em;vertical-align:0em;"></span><span class="mord mathnormal">A</span></span></span></span>具有各自类型<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>T</mi></mrow><annotation encoding="application/x-tex">T</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.68333em;vertical-align:0em;"></span><span class="mord mathnormal" style="margin-right:0.13889em;">T</span></span></span></span>的命题被写为<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>A</mi><mo>:</mo><mi>T</mi></mrow><annotation encoding="application/x-tex">A:T</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.68333em;vertical-align:0em;"></span><span class="mord mathnormal">A</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">:</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:0.68333em;vertical-align:0em;"></span><span class="mord mathnormal" style="margin-right:0.13889em;">T</span></span></span></span>。<br />
但是,总的来说,键入取决于上下文<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>C</mi></mrow><annotation encoding="application/x-tex">C</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.68333em;vertical-align:0em;"></span><span class="mord mathnormal" style="margin-right:0.07153em;">C</span></span></span></span>。<br />
为明确表示这一点,完整的形式为判断<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>C</mi><mo>⊢</mo><mi>A</mi><mo>:</mo><mi>T</mi></mrow><annotation encoding="application/x-tex">C\vdash A:T</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.69444em;vertical-align:0em;"></span><span class="mord mathnormal" style="margin-right:0.07153em;">C</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">⊢</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:0.68333em;vertical-align:0em;"></span><span class="mord mathnormal">A</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">:</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:0.68333em;vertical-align:0em;"></span><span class="mord mathnormal" style="margin-right:0.13889em;">T</span></span></span></span>,它表示<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>A</mi><mo>:</mo><mi>T</mi></mrow><annotation encoding="application/x-tex">A:T</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.68333em;vertical-align:0em;"></span><span class="mord mathnormal">A</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">:</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:0.68333em;vertical-align:0em;"></span><span class="mord mathnormal" style="margin-right:0.13889em;">T</span></span></span></span>在C的假设下成立。</p>
<p>正式的符号规则使用一种标准的方法来指定类型系统,将它们呈现为<em>推理规则</em>。<br />
每个规则具有以下一般形式:</p>
<p class='katex-block'><span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><mfrac><mrow><msub><mrow><mi>p</mi><mi>r</mi><mi>e</mi><mi>m</mi><mi>i</mi><mi>s</mi><mi>e</mi></mrow><mn>1</mn></msub><mspace width="2em"/><msub><mrow><mi>p</mi><mi>r</mi><mi>e</mi><mi>m</mi><mi>i</mi><mi>s</mi><mi>e</mi></mrow><mn>2</mn></msub><mspace width="2em"/><mo>…</mo><mspace width="2em"/><msub><mrow><mi>p</mi><mi>r</mi><mi>e</mi><mi>m</mi><mi>i</mi><mi>s</mi><mi>e</mi></mrow><mi>n</mi></msub></mrow><mrow><mi>c</mi><mi>o</mi><mi>n</mi><mi>c</mi><mi>l</mi><mi>u</mi><mi>s</mi><mi>i</mi><mi>o</mi><mi>n</mi></mrow></mfrac></mrow><annotation encoding="application/x-tex">\frac{
{premise}_1 \qquad {premise}_2 \qquad \dots \qquad {premise}_n
}{
{conclusion}
}</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:2.02252em;vertical-align:-0.686em;"></span><span class="mord"><span class="mopen nulldelimiter"></span><span class="mfrac"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:1.3365200000000002em;"><span style="top:-2.314em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord"><span class="mord mathnormal">c</span><span class="mord mathnormal">o</span><span class="mord mathnormal">n</span><span class="mord mathnormal">c</span><span class="mord mathnormal" style="margin-right:0.01968em;">l</span><span class="mord mathnormal">u</span><span class="mord mathnormal">s</span><span class="mord mathnormal">i</span><span class="mord mathnormal">o</span><span class="mord mathnormal">n</span></span></span></span><span style="top:-3.23em;"><span class="pstrut" style="height:3em;"></span><span class="frac-line" style="border-bottom-width:0.04em;"></span></span><span style="top:-3.6769999999999996em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord"><span class="mord"><span class="mord mathnormal">p</span><span class="mord mathnormal" style="margin-right:0.02778em;">r</span><span class="mord mathnormal">e</span><span class="mord mathnormal">m</span><span class="mord mathnormal">i</span><span class="mord mathnormal">s</span><span class="mord mathnormal">e</span></span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.20696799999999996em;"><span style="top:-2.4558600000000004em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">1</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.24414em;"><span></span></span></span></span></span></span><span class="mspace" style="margin-right:2em;"></span><span class="mord"><span class="mord"><span class="mord mathnormal">p</span><span class="mord mathnormal" style="margin-right:0.02778em;">r</span><span class="mord mathnormal">e</span><span class="mord mathnormal">m</span><span class="mord mathnormal">i</span><span class="mord mathnormal">s</span><span class="mord mathnormal">e</span></span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.20696799999999996em;"><span style="top:-2.4558600000000004em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">2</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.24414em;"><span></span></span></span></span></span></span><span class="mspace" style="margin-right:2em;"></span><span class="mspace" style="margin-right:0.16666666666666666em;"></span><span class="minner">…</span><span class="mspace" style="margin-right:2em;"></span><span class="mspace" style="margin-right:0.16666666666666666em;"></span><span class="mord"><span class="mord"><span class="mord mathnormal">p</span><span class="mord mathnormal" style="margin-right:0.02778em;">r</span><span class="mord mathnormal">e</span><span class="mord mathnormal">m</span><span class="mord mathnormal">i</span><span class="mord mathnormal">s</span><span class="mord mathnormal">e</span></span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.057252em;"><span style="top:-2.4558600000000004em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">n</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.24414em;"><span></span></span></span></span></span></span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.686em;"><span></span></span></span></span></span><span class="mclose nulldelimiter"></span></span></span></span></span></span></p>
<p>这样的规则被认为是一个大含义:如果所有前提都成立,那么结论成立。<br />
有些规则没有前提;它们是其结论无条件成立的<em>公理</em>。<br />
结论始终是判断<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>C</mi><mo>⊢</mo><mi>A</mi><mo>:</mo><mi>T</mi></mrow><annotation encoding="application/x-tex">C \vdash A : T</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.69444em;vertical-align:0em;"></span><span class="mord mathnormal" style="margin-right:0.07153em;">C</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">⊢</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:0.68333em;vertical-align:0em;"></span><span class="mord mathnormal">A</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">:</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:0.68333em;vertical-align:0em;"></span><span class="mord mathnormal" style="margin-right:0.13889em;">T</span></span></span></span>,并且抽象语法的每个相关构造A都有一个相应的规则。</p>
<blockquote>
<p>注意</p>
<p>例如,可以将i32.add指令的输入规则作为一个公理给出:</p>
<p class='katex-block'><span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><mfrac><mrow></mrow><mrow><mi>C</mi><mo>⊢</mo><mi>i</mi><mn>32.</mn><mi>a</mi><mi>d</mi><mi>d</mi><mo>:</mo><mo stretchy="false">[</mo><mi>i</mi><mn>32</mn><mo separator="true">,</mo><mi>i</mi><mn>32</mn><mo stretchy="false">]</mo><mo>→</mo><mo stretchy="false">[</mo><mi>i</mi><mn>32</mn><mo stretchy="false">]</mo></mrow></mfrac></mrow><annotation encoding="application/x-tex">\frac{
}{