官术网_书友最值得收藏!

  • Learn WebAssembly
  • Mike Rourke
  • 322字
  • 2021-08-13 15:38:53

Module sections

A module is made up of several sections, some of which you'll be interacting with through the JavaScript API:

  • Imports (import) are elements that can be accessed within the module and can be one of the following:
    • Function, which can be called inside the module using the call operator
    • Global, which can be accessed inside the module via the global operators
    • Linear Memory, which can be accessed inside the module via the memory operators
    • Table, which can be accessed inside the module using call_indirect
  • Exports (export) are elements that can be accessed by the consuming API (that is, called by a JavaScript function)
  • Module start function (start) is called after the module instance is initialized
  • Global (global) contains the internal definition of global variables
  • Linear memory (memory) contains the internal definition of linear memory with an initial memory size and optional maximum size
  • Data (data) contains an array of data segments which specify the initial contents of fixed ranges of a given memory
  • Table (table) is a linear memory whose elements are opaque values of a particular table element type:
    • In the MVP, its primary purpose is to implement indirect function calls in C/C++
  • Elements (elements) is a section that allows a module to initialize the elements of any import or internally defined table with any other definition in the module
  • Function and code:
    • The function section declares the signatures of each internal function defined in the module
    • The code section contains the function body of each function declared by the function section

Some of the keywords (import, export, and so on) should look familiar; they're present in the contents of the Wat file in the previous section. WebAssembly's components follow a logical mapping that directly correspond to the APIs  (for example, you pass a memory and table instance into JavaScript's WebAssembly.instantiate() function). Your primary interaction with a module in binary format will be through these APIs.

主站蜘蛛池模板: 新兴县| 澎湖县| 兰溪市| 株洲县| 锡林浩特市| 郎溪县| 藁城市| 汕尾市| 泰安市| 晋州市| 汤阴县| 牙克石市| 遵化市| 玉林市| 迁安市| 长沙县| 石嘴山市| 闽清县| 台前县| 兴义市| 大田县| 天长市| 遂平县| 南丹县| 乐陵市| 京山县| 金乡县| 浦北县| 枣庄市| 广东省| 科尔| 嘉义县| 固安县| 高淳县| 金坛市| 花莲市| 平南县| 安徽省| 康平县| 崇州市| 微山县|