From e5f144369f53c6fd44f94a7cc2edbc3837591615 Mon Sep 17 00:00:00 2001 From: Andreas Rossberg Date: Tue, 27 Feb 2018 09:16:35 +0100 Subject: [PATCH] [spec] Rename memory instructions --- document/core/appendix/index-instructions.rst | 4 +- document/core/binary/instructions.rst | 10 ++--- document/core/exec/instructions.rst | 28 +++++++------- document/core/syntax/instructions.rst | 8 ++-- document/core/text/instructions.rst | 8 ++-- document/core/util/macros.def | 4 +- document/core/valid/instructions.rst | 14 +++---- interpreter/README.md | 4 +- interpreter/binary/decode.ml | 4 +- interpreter/binary/encode.ml | 38 +++++++++---------- interpreter/exec/eval.ml | 4 +- interpreter/runtime/memory.ml | 18 ++++----- interpreter/runtime/memory.mli | 8 ++-- interpreter/syntax/ast.ml | 8 ++-- interpreter/syntax/operators.ml | 34 ++++++++--------- interpreter/text/arrange.ml | 16 ++++---- interpreter/text/lexer.mll | 4 +- interpreter/text/parser.mly | 6 +-- interpreter/valid/valid.ml | 8 ++-- test/Todo.md | 6 +-- test/core/binary.wast | 12 +++--- test/core/br.wast | 6 +-- test/core/br_table.wast | 6 +-- test/core/imports.wast | 2 +- test/core/linking.wast | 2 +- test/core/memory.wast | 10 ++--- test/core/memory_trap.wast | 8 ++-- test/core/nop.wast | 12 +++--- test/core/resizing.wast | 8 ++-- test/core/return.wast | 6 +-- test/core/typecheck.wast | 4 +- test/core/unreachable.wast | 6 +-- test/harness/wasm-constants.js | 2 +- 33 files changed, 159 insertions(+), 159 deletions(-) diff --git a/document/core/appendix/index-instructions.rst b/document/core/appendix/index-instructions.rst index f5811e024f..a8f51ad388 100644 --- a/document/core/appendix/index-instructions.rst +++ b/document/core/appendix/index-instructions.rst @@ -70,8 +70,8 @@ Instruction Binary Opcode Type :math:`\I64.\STORE\K{8}~\memarg` :math:`\hex{3C}` :math:`[\I32~\I64] \to []` :ref:`validation ` :ref:`execution ` :math:`\I64.\STORE\K{16}~\memarg` :math:`\hex{3D}` :math:`[\I32~\I64] \to []` :ref:`validation ` :ref:`execution ` :math:`\I64.\STORE\K{32}~\memarg` :math:`\hex{3E}` :math:`[\I32~\I64] \to []` :ref:`validation ` :ref:`execution ` -:math:`\CURRENTMEMORY` :math:`\hex{3F}` :math:`[] \to [\I32]` :ref:`validation ` :ref:`execution ` -:math:`\GROWMEMORY` :math:`\hex{40}` :math:`[\I32] \to [\I32]` :ref:`validation ` :ref:`execution ` +:math:`\MEMORYSIZE` :math:`\hex{3F}` :math:`[] \to [\I32]` :ref:`validation ` :ref:`execution ` +:math:`\MEMORYGROW` :math:`\hex{40}` :math:`[\I32] \to [\I32]` :ref:`validation ` :ref:`execution ` :math:`\I32.\CONST~\i32` :math:`\hex{41}` :math:`[] \to [\I32]` :ref:`validation ` :ref:`execution ` :math:`\I64.\CONST~\i64` :math:`\hex{42}` :math:`[] \to [\I64]` :ref:`validation ` :ref:`execution ` :math:`\F32.\CONST~\f32` :math:`\hex{43}` :math:`[] \to [\F32]` :ref:`validation ` :ref:`execution ` diff --git a/document/core/binary/instructions.rst b/document/core/binary/instructions.rst index faf5411de8..7e4fbbb325 100644 --- a/document/core/binary/instructions.rst +++ b/document/core/binary/instructions.rst @@ -124,8 +124,8 @@ Each variant of :ref:`memory instruction ` is encoded with .. _binary-loadn: .. _binary-store: .. _binary-storen: -.. _binary-current_memory: -.. _binary-grow_memory: +.. _binary-memory.size: +.. _binary-memory.grow: .. math:: \begin{array}{llclll} @@ -155,12 +155,12 @@ Each variant of :ref:`memory instruction ` is encoded with \hex{3C}~~m{:}\Bmemarg &\Rightarrow& \I64.\STORE\K{8}~m \\ &&|& \hex{3D}~~m{:}\Bmemarg &\Rightarrow& \I64.\STORE\K{16}~m \\ &&|& \hex{3E}~~m{:}\Bmemarg &\Rightarrow& \I64.\STORE\K{32}~m \\ &&|& - \hex{3F}~~\hex{00} &\Rightarrow& \CURRENTMEMORY \\ &&|& - \hex{40}~~\hex{00} &\Rightarrow& \GROWMEMORY \\ + \hex{3F}~~\hex{00} &\Rightarrow& \MEMORYSIZE \\ &&|& + \hex{40}~~\hex{00} &\Rightarrow& \MEMORYGROW \\ \end{array} .. note:: - In future versions of WebAssembly, the additional zero bytes occurring in the encoding of the |CURRENTMEMORY| and |GROWMEMORY| instructions may be used to index additional memories. + In future versions of WebAssembly, the additional zero bytes occurring in the encoding of the |MEMORYSIZE| and |MEMORYGROW| instructions may be used to index additional memories. .. index:: numeric instruction diff --git a/document/core/exec/instructions.rst b/document/core/exec/instructions.rst index f0990ad26f..8a8a228cf4 100644 --- a/document/core/exec/instructions.rst +++ b/document/core/exec/instructions.rst @@ -533,18 +533,18 @@ Memory Instructions \end{array} -.. _exec-current_memory: +.. _exec-memory.size: -:math:`\CURRENTMEMORY` -...................... +:math:`\MEMORYSIZE` +................... 1. Let :math:`F` be the :ref:`current ` :ref:`frame `. -2. Assert: due to :ref:`validation `, :math:`F.\AMODULE.\MIMEMS[0]` exists. +2. Assert: due to :ref:`validation `, :math:`F.\AMODULE.\MIMEMS[0]` exists. 3. Let :math:`a` be the :ref:`memory address ` :math:`F.\AMODULE.\MIMEMS[0]`. -4. Assert: due to :ref:`validation `, :math:`S.\SMEMS[a]` exists. +4. Assert: due to :ref:`validation `, :math:`S.\SMEMS[a]` exists. 5. Let :math:`\X{mem}` be the :ref:`memory instance ` :math:`S.\SMEMS[a]`. @@ -555,31 +555,31 @@ Memory Instructions .. math:: \begin{array}{l} \begin{array}{lcl@{\qquad}l} - S; F; \CURRENTMEMORY &\stepto& S; F; (\I32.\CONST~\X{sz}) + S; F; \MEMORYSIZE &\stepto& S; F; (\I32.\CONST~\X{sz}) \end{array} \\ \qquad (\iff |S.\SMEMS[F.\AMODULE.\MIMEMS[0]].\MIDATA| = \X{sz}\cdot64\,\F{Ki}) \\ \end{array} -.. _exec-grow_memory: +.. _exec-memory.grow: -:math:`\GROWMEMORY` +:math:`\MEMORYGROW` ................... 1. Let :math:`F` be the :ref:`current ` :ref:`frame `. -2. Assert: due to :ref:`validation `, :math:`F.\AMODULE.\MIMEMS[0]` exists. +2. Assert: due to :ref:`validation `, :math:`F.\AMODULE.\MIMEMS[0]` exists. 3. Let :math:`a` be the :ref:`memory address ` :math:`F.\AMODULE.\MIMEMS[0]`. -4. Assert: due to :ref:`validation `, :math:`S.\SMEMS[a]` exists. +4. Assert: due to :ref:`validation `, :math:`S.\SMEMS[a]` exists. 5. Let :math:`\X{mem}` be the :ref:`memory instance ` :math:`S.\SMEMS[a]`. 6. Let :math:`\X{sz}` be the length of :math:`S.\SMEMS[a]` divided by the :ref:`page size `. -7. Assert: due to :ref:`validation `, a value of :ref:`value type ` |I32| is on the top of the stack. +7. Assert: due to :ref:`validation `, a value of :ref:`value type ` |I32| is on the top of the stack. 8. Pop the value :math:`\I32.\CONST~n` from the stack. @@ -595,7 +595,7 @@ Memory Instructions ~\\[-1ex] \begin{array}{l} \begin{array}{lcl@{\qquad}l} - S; F; (\I32.\CONST~n)~\GROWMEMORY &\stepto& S'; F; (\I32.\CONST~\X{sz}) + S; F; (\I32.\CONST~n)~\MEMORYGROW &\stepto& S'; F; (\I32.\CONST~\X{sz}) \end{array} \\ \qquad \begin{array}[t]{@{}r@{~}l@{}} @@ -605,12 +605,12 @@ Memory Instructions \end{array} \\[1ex] \begin{array}{lcl@{\qquad}l} - S; F; (\I32.\CONST~n)~\GROWMEMORY &\stepto& S; F; (\I32.\CONST~{-1}) + S; F; (\I32.\CONST~n)~\MEMORYGROW &\stepto& S; F; (\I32.\CONST~{-1}) \end{array} \end{array} .. note:: - The |GROWMEMORY| instruction is non-deterministic. + The |MEMORYGROW| instruction is non-deterministic. It may either succeed, returning the old memory size :math:`\X{sz}`, or fail, returning :math:`{-1}`. Failure *must* occur if the referenced memory instance has a maximum size defined that would be exceeded. diff --git a/document/core/syntax/instructions.rst b/document/core/syntax/instructions.rst index 060933bf7f..1b8e195db2 100644 --- a/document/core/syntax/instructions.rst +++ b/document/core/syntax/instructions.rst @@ -240,8 +240,8 @@ Instructions in this group are concerned with linear :ref:`memory `. \K{i}\X{nn}\K{.}\STORE\K{8}~\memarg ~|~ \K{i}\X{nn}\K{.}\STORE\K{16}~\memarg ~|~ \K{i64.}\STORE\K{32}~\memarg \\&&|& - \CURRENTMEMORY \\&&|& - \GROWMEMORY \\ + \MEMORYSIZE \\&&|& + \MEMORYGROW \\ \end{array} Memory is accessed with |LOAD| and |STORE| instructions for the different :ref:`value types `. @@ -256,8 +256,8 @@ A :ref:`trap ` results if any of the accessed memory bytes lies outside th .. note:: Future version of WebAssembly might provide memory instructions with 64 bit address ranges. -The |CURRENTMEMORY| instruction returns the current size of a memory. -The |GROWMEMORY| instruction grows memory by a given delta and returns the previous size, or :math:`-1` if enough memory cannot be allocated. +The |MEMORYSIZE| instruction returns the current size of a memory. +The |MEMORYGROW| instruction grows memory by a given delta and returns the previous size, or :math:`-1` if enough memory cannot be allocated. Both instructions operate in units of :ref:`page size `. .. note:: diff --git a/document/core/text/instructions.rst b/document/core/text/instructions.rst index dadd435b07..7a0eadda2b 100644 --- a/document/core/text/instructions.rst +++ b/document/core/text/instructions.rst @@ -173,8 +173,8 @@ Memory Instructions .. _text-loadn: .. _text-store: .. _text-storen: -.. _text-current_memory: -.. _text-grow_memory: +.. _text-memory.size: +.. _text-memory.grow: The offset and alignment immediates to memory instructions are optional. The offset defaults to :math:`\T{0}`, the alignment to the storage size of the respective memory access, which is its *natural alignment*. @@ -214,8 +214,8 @@ Lexically, an |Toffset| or |Talign| phrase is considered a single :ref:`keyword \text{i64.store8}~~m{:}\Tmemarg_1 &\Rightarrow& \I64.\STORE\K{8}~m \\ &&|& \text{i64.store16}~~m{:}\Tmemarg_2 &\Rightarrow& \I64.\STORE\K{16}~m \\ &&|& \text{i64.store32}~~m{:}\Tmemarg_4 &\Rightarrow& \I64.\STORE\K{32}~m \\ &&|& - \text{current\_memory} &\Rightarrow& \CURRENTMEMORY \\ &&|& - \text{grow\_memory} &\Rightarrow& \GROWMEMORY \\ + \text{memory.size} &\Rightarrow& \MEMORYSIZE \\ &&|& + \text{memory.grow} &\Rightarrow& \MEMORYGROW \\ \end{array} diff --git a/document/core/util/macros.def b/document/core/util/macros.def index 2216694b13..ea5be82d8c 100644 --- a/document/core/util/macros.def +++ b/document/core/util/macros.def @@ -325,8 +325,8 @@ .. |LOAD| mathdef:: \xref{syntax/instructions}{syntax-instr-memory}{\K{load}} .. |STORE| mathdef:: \xref{syntax/instructions}{syntax-instr-memory}{\K{store}} -.. |CURRENTMEMORY| mathdef:: \xref{syntax/instructions}{syntax-instr-memory}{\K{current\_memory}} -.. |GROWMEMORY| mathdef:: \xref{syntax/instructions}{syntax-instr-memory}{\K{grow\_memory}} +.. |MEMORYSIZE| mathdef:: \xref{syntax/instructions}{syntax-instr-memory}{\K{memory.size}} +.. |MEMORYGROW| mathdef:: \xref{syntax/instructions}{syntax-instr-memory}{\K{memory.grow}} .. |CONST| mathdef:: \xref{syntax/instructions}{syntax-instr-numeric}{\K{const}} .. |EQZ| mathdef:: \xref{syntax/instructions}{syntax-instr-numeric}{\K{eqz}} diff --git a/document/core/valid/instructions.rst b/document/core/valid/instructions.rst index ffc308ff29..9ef152bad9 100644 --- a/document/core/valid/instructions.rst +++ b/document/core/valid/instructions.rst @@ -389,10 +389,10 @@ Memory Instructions } -.. _valid-current_memory: +.. _valid-memory.size: -:math:`\CURRENTMEMORY` -...................... +:math:`\MEMORYSIZE` +................... * The memory :math:`C.\CMEMS[0]` must be defined in the context. @@ -402,13 +402,13 @@ Memory Instructions \frac{ C.\CMEMS[0] = \memtype }{ - C \vdashinstr \CURRENTMEMORY : [] \to [\I32] + C \vdashinstr \MEMORYSIZE : [] \to [\I32] } -.. _valid-grow_memory: +.. _valid-memory.grow: -:math:`\GROWMEMORY` +:math:`\MEMORYGROW` ................... * The memory :math:`C.\CMEMS[0]` must be defined in the context. @@ -419,7 +419,7 @@ Memory Instructions \frac{ C.\CMEMS[0] = \memtype }{ - C \vdashinstr \GROWMEMORY : [\I32] \to [\I32] + C \vdashinstr \MEMORYGROW : [\I32] \to [\I32] } diff --git a/interpreter/README.md b/interpreter/README.md index af0ba20423..e414429b4b 100644 --- a/interpreter/README.md +++ b/interpreter/README.md @@ -225,8 +225,8 @@ op: set_global .load((8|16|32)_)? ? ? .store(8|16|32)? ? ? - current_memory - grow_memory + memory.size + memory.grow .const . . diff --git a/interpreter/binary/decode.ml b/interpreter/binary/decode.ml index 68a8d9c4c9..76bbaa0594 100644 --- a/interpreter/binary/decode.ml +++ b/interpreter/binary/decode.ml @@ -289,10 +289,10 @@ let rec instr s = | 0x3f -> expect 0x00 s "zero flag expected"; - current_memory + memory_size | 0x40 -> expect 0x00 s "zero flag expected"; - grow_memory + memory_grow | 0x41 -> i32_const (at vs32 s) | 0x42 -> i64_const (at vs64 s) diff --git a/interpreter/binary/encode.ml b/interpreter/binary/encode.ml index adbf418a44..696dac418e 100644 --- a/interpreter/binary/encode.ml +++ b/interpreter/binary/encode.ml @@ -171,27 +171,27 @@ let encode m = | Load ({ty = I64Type; sz = None; _} as mo) -> op 0x29; memop mo | Load ({ty = F32Type; sz = None; _} as mo) -> op 0x2a; memop mo | Load ({ty = F64Type; sz = None; _} as mo) -> op 0x2b; memop mo - | Load ({ty = I32Type; sz = Some (Mem8, SX); _} as mo) -> + | Load ({ty = I32Type; sz = Some (Pack8, SX); _} as mo) -> op 0x2c; memop mo - | Load ({ty = I32Type; sz = Some (Mem8, ZX); _} as mo) -> + | Load ({ty = I32Type; sz = Some (Pack8, ZX); _} as mo) -> op 0x2d; memop mo - | Load ({ty = I32Type; sz = Some (Mem16, SX); _} as mo) -> + | Load ({ty = I32Type; sz = Some (Pack16, SX); _} as mo) -> op 0x2e; memop mo - | Load ({ty = I32Type; sz = Some (Mem16, ZX); _} as mo) -> + | Load ({ty = I32Type; sz = Some (Pack16, ZX); _} as mo) -> op 0x2f; memop mo - | Load {ty = I32Type; sz = Some (Mem32, _); _} -> + | Load {ty = I32Type; sz = Some (Pack32, _); _} -> assert false - | Load ({ty = I64Type; sz = Some (Mem8, SX); _} as mo) -> + | Load ({ty = I64Type; sz = Some (Pack8, SX); _} as mo) -> op 0x30; memop mo - | Load ({ty = I64Type; sz = Some (Mem8, ZX); _} as mo) -> + | Load ({ty = I64Type; sz = Some (Pack8, ZX); _} as mo) -> op 0x31; memop mo - | Load ({ty = I64Type; sz = Some (Mem16, SX); _} as mo) -> + | Load ({ty = I64Type; sz = Some (Pack16, SX); _} as mo) -> op 0x32; memop mo - | Load ({ty = I64Type; sz = Some (Mem16, ZX); _} as mo) -> + | Load ({ty = I64Type; sz = Some (Pack16, ZX); _} as mo) -> op 0x33; memop mo - | Load ({ty = I64Type; sz = Some (Mem32, SX); _} as mo) -> + | Load ({ty = I64Type; sz = Some (Pack32, SX); _} as mo) -> op 0x34; memop mo - | Load ({ty = I64Type; sz = Some (Mem32, ZX); _} as mo) -> + | Load ({ty = I64Type; sz = Some (Pack32, ZX); _} as mo) -> op 0x35; memop mo | Load {ty = F32Type | F64Type; sz = Some _; _} -> assert false @@ -200,16 +200,16 @@ let encode m = | Store ({ty = I64Type; sz = None; _} as mo) -> op 0x37; memop mo | Store ({ty = F32Type; sz = None; _} as mo) -> op 0x38; memop mo | Store ({ty = F64Type; sz = None; _} as mo) -> op 0x39; memop mo - | Store ({ty = I32Type; sz = Some Mem8; _} as mo) -> op 0x3a; memop mo - | Store ({ty = I32Type; sz = Some Mem16; _} as mo) -> op 0x3b; memop mo - | Store {ty = I32Type; sz = Some Mem32; _} -> assert false - | Store ({ty = I64Type; sz = Some Mem8; _} as mo) -> op 0x3c; memop mo - | Store ({ty = I64Type; sz = Some Mem16; _} as mo) -> op 0x3d; memop mo - | Store ({ty = I64Type; sz = Some Mem32; _} as mo) -> op 0x3e; memop mo + | Store ({ty = I32Type; sz = Some Pack8; _} as mo) -> op 0x3a; memop mo + | Store ({ty = I32Type; sz = Some Pack16; _} as mo) -> op 0x3b; memop mo + | Store {ty = I32Type; sz = Some Pack32; _} -> assert false + | Store ({ty = I64Type; sz = Some Pack8; _} as mo) -> op 0x3c; memop mo + | Store ({ty = I64Type; sz = Some Pack16; _} as mo) -> op 0x3d; memop mo + | Store ({ty = I64Type; sz = Some Pack32; _} as mo) -> op 0x3e; memop mo | Store {ty = F32Type | F64Type; sz = Some _; _} -> assert false - | CurrentMemory -> op 0x3f; u8 0x00 - | GrowMemory -> op 0x40; u8 0x00 + | MemorySize -> op 0x3f; u8 0x00 + | MemoryGrow -> op 0x40; u8 0x00 | Const {it = I32 c; _} -> op 0x41; vs32 c | Const {it = I64 c; _} -> op 0x42; vs64 c diff --git a/interpreter/exec/eval.ml b/interpreter/exec/eval.ml index a6bc8f3971..eb48e33d18 100644 --- a/interpreter/exec/eval.ml +++ b/interpreter/exec/eval.ml @@ -214,11 +214,11 @@ let rec step (c : config) : config = vs', [] with exn -> vs', [Trapping (memory_error e.at exn) @@ e.at]); - | CurrentMemory, vs -> + | MemorySize, vs -> let mem = memory frame.inst (0l @@ e.at) in I32 (Memory.size mem) :: vs, [] - | GrowMemory, I32 delta :: vs' -> + | MemoryGrow, I32 delta :: vs' -> let mem = memory frame.inst (0l @@ e.at) in let old_size = Memory.size mem in let result = diff --git a/interpreter/runtime/memory.ml b/interpreter/runtime/memory.ml index fd9783d934..d1f2bce982 100644 --- a/interpreter/runtime/memory.ml +++ b/interpreter/runtime/memory.ml @@ -7,7 +7,7 @@ type size = int32 (* number of pages *) type address = int64 type offset = int32 -type mem_size = Mem8 | Mem16 | Mem32 +type pack_size = Pack8 | Pack16 | Pack32 type extension = SX | ZX type memory' = (int, int8_unsigned_elt, c_layout) Array1.t @@ -22,10 +22,10 @@ exception OutOfMemory let page_size = 0x10000L (* 64 KiB *) -let mem_size = function - | Mem8 -> 1 - | Mem16 -> 2 - | Mem32 -> 4 +let packed_size = function + | Pack8 -> 1 + | Pack16 -> 2 + | Pack32 -> 4 let within_limits n = function | None -> true @@ -126,8 +126,8 @@ let extend x n = function | SX -> let sh = 64 - 8 * n in Int64.(shift_right (shift_left x sh) sh) let load_packed sz ext mem a o t = - assert (mem_size sz <= Types.size t); - let n = mem_size sz in + assert (packed_size sz <= Types.size t); + let n = packed_size sz in let x = extend (loadn mem a o n) n ext in match t with | I32Type -> I32 (Int64.to_int32 x) @@ -135,8 +135,8 @@ let load_packed sz ext mem a o t = | _ -> raise Type let store_packed sz mem a o v = - assert (mem_size sz <= Types.size (Values.type_of v)); - let n = mem_size sz in + assert (packed_size sz <= Types.size (Values.type_of v)); + let n = packed_size sz in let x = match v with | I32 x -> Int64.of_int32 x diff --git a/interpreter/runtime/memory.mli b/interpreter/runtime/memory.mli index c5586e7b9e..2a2b8ae47a 100644 --- a/interpreter/runtime/memory.mli +++ b/interpreter/runtime/memory.mli @@ -8,7 +8,7 @@ type size = int32 (* number of pages *) type address = int64 type offset = int32 -type mem_size = Mem8 | Mem16 | Mem32 +type pack_size = Pack8 | Pack16 | Pack32 type extension = SX | ZX exception Type @@ -18,7 +18,7 @@ exception SizeLimit exception OutOfMemory val page_size : int64 -val mem_size : mem_size -> int +val packed_size : pack_size -> int val alloc : memory_type -> memory (* raises SizeOverflow, OutOfMemory *) val type_of : memory -> memory_type @@ -37,8 +37,8 @@ val load_value : val store_value : memory -> address -> offset -> value -> unit (* raises Bounds *) val load_packed : - mem_size -> extension -> memory -> address -> offset -> value_type -> value + pack_size -> extension -> memory -> address -> offset -> value_type -> value (* raises Type, Bounds *) val store_packed : - mem_size -> memory -> address -> offset -> value -> unit + pack_size -> memory -> address -> offset -> value -> unit (* raises Type, Bounds *) diff --git a/interpreter/syntax/ast.ml b/interpreter/syntax/ast.ml index e2efa7ee89..3099f4a0b1 100644 --- a/interpreter/syntax/ast.ml +++ b/interpreter/syntax/ast.ml @@ -57,8 +57,8 @@ type cvtop = (I32Op.cvtop, I64Op.cvtop, F32Op.cvtop, F64Op.cvtop) Values.op type 'a memop = {ty : value_type; align : int; offset : Memory.offset; sz : 'a option} -type loadop = (Memory.mem_size * Memory.extension) memop -type storeop = Memory.mem_size memop +type loadop = (Memory.pack_size * Memory.extension) memop +type storeop = Memory.pack_size memop (* Expressions *) @@ -89,8 +89,8 @@ and instr' = | SetGlobal of var (* write global variable *) | Load of loadop (* read memory at address *) | Store of storeop (* write memory at address *) - | CurrentMemory (* size of linear memory *) - | GrowMemory (* grow linear memory *) + | MemorySize (* size of linear memory *) + | MemoryGrow (* grow linear memory *) | Const of literal (* constant *) | Test of testop (* numeric test *) | Compare of relop (* numeric comparison *) diff --git a/interpreter/syntax/operators.ml b/interpreter/syntax/operators.ml index b207b193db..158aad17ec 100644 --- a/interpreter/syntax/operators.ml +++ b/interpreter/syntax/operators.ml @@ -36,40 +36,40 @@ let i64_load align offset = Load {ty = I64Type; align; offset; sz = None} let f32_load align offset = Load {ty = F32Type; align; offset; sz = None} let f64_load align offset = Load {ty = F64Type; align; offset; sz = None} let i32_load8_s align offset = - Load {ty = I32Type; align; offset; sz = Some (Mem8, SX)} + Load {ty = I32Type; align; offset; sz = Some (Pack8, SX)} let i32_load8_u align offset = - Load {ty = I32Type; align; offset; sz = Some (Mem8, ZX)} + Load {ty = I32Type; align; offset; sz = Some (Pack8, ZX)} let i32_load16_s align offset = - Load {ty = I32Type; align; offset; sz = Some (Mem16, SX)} + Load {ty = I32Type; align; offset; sz = Some (Pack16, SX)} let i32_load16_u align offset = - Load {ty = I32Type; align; offset; sz = Some (Mem16, ZX)} + Load {ty = I32Type; align; offset; sz = Some (Pack16, ZX)} let i64_load8_s align offset = - Load {ty = I64Type; align; offset; sz = Some (Mem8, SX)} + Load {ty = I64Type; align; offset; sz = Some (Pack8, SX)} let i64_load8_u align offset = - Load {ty = I64Type; align; offset; sz = Some (Mem8, ZX)} + Load {ty = I64Type; align; offset; sz = Some (Pack8, ZX)} let i64_load16_s align offset = - Load {ty = I64Type; align; offset; sz = Some (Mem16, SX)} + Load {ty = I64Type; align; offset; sz = Some (Pack16, SX)} let i64_load16_u align offset = - Load {ty = I64Type; align; offset; sz = Some (Mem16, ZX)} + Load {ty = I64Type; align; offset; sz = Some (Pack16, ZX)} let i64_load32_s align offset = - Load {ty = I64Type; align; offset; sz = Some (Mem32, SX)} + Load {ty = I64Type; align; offset; sz = Some (Pack32, SX)} let i64_load32_u align offset = - Load {ty = I64Type; align; offset; sz = Some (Mem32, ZX)} + Load {ty = I64Type; align; offset; sz = Some (Pack32, ZX)} let i32_store align offset = Store {ty = I32Type; align; offset; sz = None} let i64_store align offset = Store {ty = I64Type; align; offset; sz = None} let f32_store align offset = Store {ty = F32Type; align; offset; sz = None} let f64_store align offset = Store {ty = F64Type; align; offset; sz = None} let i32_store8 align offset = - Store {ty = I32Type; align; offset; sz = Some Mem8} + Store {ty = I32Type; align; offset; sz = Some Pack8} let i32_store16 align offset = - Store {ty = I32Type; align; offset; sz = Some Mem16} + Store {ty = I32Type; align; offset; sz = Some Pack16} let i64_store8 align offset = - Store {ty = I64Type; align; offset; sz = Some Mem8} + Store {ty = I64Type; align; offset; sz = Some Pack8} let i64_store16 align offset = - Store {ty = I64Type; align; offset; sz = Some Mem16} + Store {ty = I64Type; align; offset; sz = Some Pack16} let i64_store32 align offset = - Store {ty = I64Type; align; offset; sz = Some Mem32} + Store {ty = I64Type; align; offset; sz = Some Pack32} let i32_clz = Unary (I32 I32Op.Clz) let i32_ctz = Unary (I32 I32Op.Ctz) @@ -199,6 +199,6 @@ let i64_reinterpret_f64 = Convert (I64 I64Op.ReinterpretFloat) let f32_reinterpret_i32 = Convert (F32 F32Op.ReinterpretInt) let f64_reinterpret_i64 = Convert (F64 F64Op.ReinterpretInt) -let current_memory = CurrentMemory -let grow_memory = GrowMemory +let memory_size = MemorySize +let memory_grow = MemoryGrow diff --git a/interpreter/text/arrange.ml b/interpreter/text/arrange.ml index c12d268b82..66ff6dfb57 100644 --- a/interpreter/text/arrange.ml +++ b/interpreter/text/arrange.ml @@ -187,10 +187,10 @@ let testop = oper (IntOp.testop, FloatOp.testop) let relop = oper (IntOp.relop, FloatOp.relop) let cvtop = oper (IntOp.cvtop, FloatOp.cvtop) -let mem_size = function - | Memory.Mem8 -> "8" - | Memory.Mem16 -> "16" - | Memory.Mem32 -> "32" +let pack_size = function + | Memory.Pack8 -> "8" + | Memory.Pack16 -> "16" + | Memory.Pack32 -> "32" let extension = function | Memory.SX -> "_s" @@ -204,12 +204,12 @@ let memop name {ty; align; offset; _} = let loadop op = match op.sz with | None -> memop "load" op - | Some (sz, ext) -> memop ("load" ^ mem_size sz ^ extension ext) op + | Some (sz, ext) -> memop ("load" ^ pack_size sz ^ extension ext) op let storeop op = match op.sz with | None -> memop "store" op - | Some sz -> memop ("store" ^ mem_size sz) op + | Some sz -> memop ("store" ^ pack_size sz) op (* Expressions *) @@ -244,8 +244,8 @@ let rec instr e = | SetGlobal x -> "set_global " ^ var x, [] | Load op -> loadop op, [] | Store op -> storeop op, [] - | CurrentMemory -> "current_memory", [] - | GrowMemory -> "grow_memory", [] + | MemorySize -> "memory.size", [] + | MemoryGrow -> "memory.grow", [] | Const lit -> constop lit ^ " " ^ value lit, [] | Test op -> testop op, [] | Compare op -> relop op, [] diff --git a/interpreter/text/lexer.mll b/interpreter/text/lexer.mll index 2a41d8cfe7..3b67da7ce1 100644 --- a/interpreter/text/lexer.mll +++ b/interpreter/text/lexer.mll @@ -314,8 +314,8 @@ rule token = parse | "i32.reinterpret/f32" { CONVERT i32_reinterpret_f32 } | "i64.reinterpret/f64" { CONVERT i64_reinterpret_f64 } - | "current_memory" { CURRENT_MEMORY } - | "grow_memory" { GROW_MEMORY } + | "memory.size" { MEMORY_SIZE } + | "memory.grow" { MEMORY_GROW } | "type" { TYPE } | "func" { FUNC } diff --git a/interpreter/text/parser.mly b/interpreter/text/parser.mly index 685a05b0ca..fc5e2a0e40 100644 --- a/interpreter/text/parser.mly +++ b/interpreter/text/parser.mly @@ -151,7 +151,7 @@ let inline_type_explicit (c : context) x ft at = %token GET_LOCAL SET_LOCAL TEE_LOCAL GET_GLOBAL SET_GLOBAL %token LOAD STORE OFFSET_EQ_NAT ALIGN_EQ_NAT %token CONST UNARY BINARY TEST COMPARE CONVERT -%token UNREACHABLE CURRENT_MEMORY GROW_MEMORY +%token UNREACHABLE MEMORY_SIZE MEMORY_GROW %token FUNC START TYPE PARAM RESULT LOCAL GLOBAL %token TABLE ELEM MEMORY DATA OFFSET IMPORT EXPORT TABLE %token MODULE BIN QUOTE @@ -317,8 +317,8 @@ plain_instr : | SET_GLOBAL var { fun c -> set_global ($2 c global) } | LOAD offset_opt align_opt { fun c -> $1 $3 $2 } | STORE offset_opt align_opt { fun c -> $1 $3 $2 } - | CURRENT_MEMORY { fun c -> current_memory } - | GROW_MEMORY { fun c -> grow_memory } + | MEMORY_SIZE { fun c -> memory_size } + | MEMORY_GROW { fun c -> memory_grow } | CONST literal { fun c -> fst (literal $1 $2) } | TEST { fun c -> $1 } | COMPARE { fun c -> $1 } diff --git a/interpreter/valid/valid.ml b/interpreter/valid/valid.ml index 3bdb5e2823..5b0c491b94 100644 --- a/interpreter/valid/valid.ml +++ b/interpreter/valid/valid.ml @@ -143,9 +143,9 @@ let check_memop (c : context) (memop : 'a memop) get_sz at = match get_sz memop.sz with | None -> size memop.ty | Some sz -> - require (memop.ty = I64Type || sz <> Memory.Mem32) at + require (memop.ty = I64Type || sz <> Memory.Pack32) at "memory size too big"; - Memory.mem_size sz + Memory.packed_size sz in require (1 lsl memop.align <= size) at "alignment must not be larger than natural" @@ -254,11 +254,11 @@ let rec check_instr (c : context) (e : instr) (s : infer_stack_type) : op_type = check_memop c memop (fun sz -> sz) e.at; [I32Type; memop.ty] --> [] - | CurrentMemory -> + | MemorySize -> ignore (memory c (0l @@ e.at)); [] --> [I32Type] - | GrowMemory -> + | MemoryGrow -> ignore (memory c (0l @@ e.at)); [I32Type] --> [I32Type] diff --git a/test/Todo.md b/test/Todo.md index b98f989ec4..4a2831d70e 100644 --- a/test/Todo.md +++ b/test/Todo.md @@ -4,11 +4,11 @@ have a link to an open issue/PR, or be obvious. Comments/corrections/additions welcome. Linear memory semantics: - - test that newly allocated memory (program start and `grow_memory`) is zeroed - - test that `grow_memory` does a full 32-bit unsigned check for page-size divisibility + - test that newly allocated memory (program start and `memory.grow`) is zeroed + - test that `memory.grow` does a full 32-bit unsigned check for page-size divisibility - test that load/store addreses are full int32 (or int64), and not OCaml int - test that when allocating 4GiB, accessing index -1 fails - - test that too-big `grow_memory` fails appropriately + - test that too-big `memory.grow` fails appropriately - test that too-big linear memory initial allocation fails - test that one can clobber the entire contents of the linear memory without corrupting: call stack, local variables, program execution. - test that an i64 store with 4-byte alignment that's 4 bytes out of bounds traps without storing anything. diff --git a/test/core/binary.wast b/test/core/binary.wast index 8cfeed46f7..159c9c2c7a 100644 --- a/test/core/binary.wast +++ b/test/core/binary.wast @@ -62,7 +62,7 @@ "zero flag expected" ) -;; grow_memory reserved byte equal to zero. +;; memory.grow reserved byte equal to zero. (assert_malformed (module binary "\00asm" "\01\00\00\00" @@ -74,15 +74,15 @@ ;; function 0 "\07\00" "\41\00" ;; i32.const 0 - "\40" ;; grow_memory - "\01" ;; grow_memory reserved byte is not equal to zero! + "\40" ;; memory.grow + "\01" ;; memory.grow reserved byte is not equal to zero! "\1a" ;; drop "\0b" ;; end ) "zero flag expected" ) -;; current_memory reserved byte equal to zero. +;; memory.size reserved byte equal to zero. (assert_malformed (module binary "\00asm" "\01\00\00\00" @@ -93,8 +93,8 @@ ;; function 0 "\05\00" - "\3f" ;; current_memory - "\01" ;; current_memory reserved byte is not equal to zero! + "\3f" ;; memory.size + "\01" ;; memory.size reserved byte is not equal to zero! "\1a" ;; drop "\0b" ;; end ) diff --git a/test/core/br.wast b/test/core/br.wast index 5e99209c78..e801a1b471 100644 --- a/test/core/br.wast +++ b/test/core/br.wast @@ -238,8 +238,8 @@ (block (result i32) (i32.wrap/i64 (br 0 (i32.const 41)))) ) - (func (export "as-grow_memory-size") (result i32) - (block (result i32) (grow_memory (br 0 (i32.const 40)))) + (func (export "as-memory.grow-size") (result i32) + (block (result i32) (memory.grow (br 0 (i32.const 40)))) ) (func (export "nested-block-value") (result i32) @@ -398,7 +398,7 @@ (assert_return (invoke "as-convert-operand") (i32.const 41)) -(assert_return (invoke "as-grow_memory-size") (i32.const 40)) +(assert_return (invoke "as-memory.grow-size") (i32.const 40)) (assert_return (invoke "nested-block-value") (i32.const 9)) (assert_return (invoke "nested-br-value") (i32.const 9)) diff --git a/test/core/br_table.wast b/test/core/br_table.wast index 9860892392..81259caccb 100644 --- a/test/core/br_table.wast +++ b/test/core/br_table.wast @@ -1098,8 +1098,8 @@ ) ) - (func (export "as-grow_memory-size") (result i32) - (block (result i32) (grow_memory (br_table 0 (i32.const 40) (i32.const 0)))) + (func (export "as-memory.grow-size") (result i32) + (block (result i32) (memory.grow (br_table 0 (i32.const 40) (i32.const 0)))) ) (func (export "nested-block-value") (param i32) (result i32) @@ -1363,7 +1363,7 @@ (assert_return (invoke "as-convert-operand") (i32.const 41)) -(assert_return (invoke "as-grow_memory-size") (i32.const 40)) +(assert_return (invoke "as-memory.grow-size") (i32.const 40)) (assert_return (invoke "nested-block-value" (i32.const 0)) (i32.const 19)) (assert_return (invoke "nested-block-value" (i32.const 1)) (i32.const 17)) diff --git a/test/core/imports.wast b/test/core/imports.wast index 7c17f805bc..ee26a8e0b4 100644 --- a/test/core/imports.wast +++ b/test/core/imports.wast @@ -478,7 +478,7 @@ (module (import "spectest" "memory" (memory 0 3)) ;; actual has max size 2 - (func (export "grow") (param i32) (result i32) (grow_memory (get_local 0))) + (func (export "grow") (param i32) (result i32) (memory.grow (get_local 0))) ) (assert_return (invoke "grow" (i32.const 0)) (i32.const 1)) (assert_return (invoke "grow" (i32.const 1)) (i32.const 1)) diff --git a/test/core/linking.wast b/test/core/linking.wast index 898d5a215f..e75c9ec899 100644 --- a/test/core/linking.wast +++ b/test/core/linking.wast @@ -274,7 +274,7 @@ (memory (import "Mm" "mem") 1 8) (func (export "grow") (param $a i32) (result i32) - (grow_memory (get_local 0)) + (memory.grow (get_local 0)) ) ) diff --git a/test/core/memory.wast b/test/core/memory.wast index c6f8cd5d4f..ee35e1ee32 100644 --- a/test/core/memory.wast +++ b/test/core/memory.wast @@ -8,11 +8,11 @@ (assert_invalid (module (memory 0) (memory 0)) "multiple memories") (assert_invalid (module (memory (import "spectest" "memory") 0) (memory 0)) "multiple memories") -(module (memory (data)) (func (export "memsize") (result i32) (current_memory))) +(module (memory (data)) (func (export "memsize") (result i32) (memory.size))) (assert_return (invoke "memsize") (i32.const 0)) -(module (memory (data "")) (func (export "memsize") (result i32) (current_memory))) +(module (memory (data "")) (func (export "memsize") (result i32) (memory.size))) (assert_return (invoke "memsize") (i32.const 0)) -(module (memory (data "x")) (func (export "memsize") (result i32) (current_memory))) +(module (memory (data "x")) (func (export "memsize") (result i32) (memory.size))) (assert_return (invoke "memsize") (i32.const 1)) (assert_invalid (module (data (i32.const 0))) "unknown memory") @@ -36,11 +36,11 @@ "unknown memory" ) (assert_invalid - (module (func (drop (current_memory)))) + (module (func (drop (memory.size)))) "unknown memory" ) (assert_invalid - (module (func (drop (grow_memory (i32.const 0))))) + (module (func (drop (memory.grow (i32.const 0))))) "unknown memory" ) diff --git a/test/core/memory_trap.wast b/test/core/memory_trap.wast index 5fd193de23..b79627d7c5 100644 --- a/test/core/memory_trap.wast +++ b/test/core/memory_trap.wast @@ -2,7 +2,7 @@ (memory 1) (func $addr_limit (result i32) - (i32.mul (current_memory) (i32.const 0x10000)) + (i32.mul (memory.size) (i32.const 0x10000)) ) (func (export "store") (param $i i32) (param $v i32) @@ -13,8 +13,8 @@ (i32.load (i32.add (call $addr_limit) (get_local $i))) ) - (func (export "grow_memory") (param i32) (result i32) - (grow_memory (get_local 0)) + (func (export "memory.grow") (param i32) (result i32) + (memory.grow (get_local 0)) ) ) @@ -30,7 +30,7 @@ (assert_trap (invoke "load" (i32.const 0)) "out of bounds memory access") (assert_trap (invoke "store" (i32.const 0x80000000) (i32.const 13)) "out of bounds memory access") (assert_trap (invoke "load" (i32.const 0x80000000)) "out of bounds memory access") -(assert_return (invoke "grow_memory" (i32.const 0x10001)) (i32.const -1)) +(assert_return (invoke "memory.grow" (i32.const 0x10001)) (i32.const -1)) (module (memory 1) diff --git a/test/core/nop.wast b/test/core/nop.wast index 2862315587..02b402816a 100644 --- a/test/core/nop.wast +++ b/test/core/nop.wast @@ -172,11 +172,11 @@ (nop) (get_local 0) (nop) (nop) (get_local 0) (nop) (nop) (i32.le_s) ) - (func (export "as-grow_memory-last") (param i32) (result i32) - (get_local 0) (nop) (grow_memory) + (func (export "as-memory.grow-last") (param i32) (result i32) + (get_local 0) (nop) (memory.grow) ) - (func (export "as-grow_memory-everywhere") (param i32) (result i32) - (nop) (nop) (get_local 0) (nop) (nop) (grow_memory) + (func (export "as-memory.grow-everywhere") (param i32) (result i32) + (nop) (nop) (get_local 0) (nop) (nop) (memory.grow) ) ) @@ -243,8 +243,8 @@ (assert_return (invoke "as-compare-last" (i32.const 3)) (i32.const 0)) (assert_return (invoke "as-compare-everywhere" (i32.const 3)) (i32.const 1)) -(assert_return (invoke "as-grow_memory-last" (i32.const 2)) (i32.const 1)) -(assert_return (invoke "as-grow_memory-everywhere" (i32.const 12)) (i32.const 3)) +(assert_return (invoke "as-memory.grow-last" (i32.const 2)) (i32.const 1)) +(assert_return (invoke "as-memory.grow-everywhere" (i32.const 12)) (i32.const 3)) (assert_invalid (module (func $type-i32 (result i32) (nop))) diff --git a/test/core/resizing.wast b/test/core/resizing.wast index 80d20b56a2..183332efd3 100644 --- a/test/core/resizing.wast +++ b/test/core/resizing.wast @@ -7,8 +7,8 @@ (func (export "load_at_page_size") (result i32) (i32.load (i32.const 0x10000))) (func (export "store_at_page_size") (i32.store (i32.const 0x10000) (i32.const 3))) - (func (export "grow") (param $sz i32) (result i32) (grow_memory (get_local $sz))) - (func (export "size") (result i32) (current_memory)) + (func (export "grow") (param $sz i32) (result i32) (memory.grow (get_local $sz))) + (func (export "size") (result i32) (memory.size)) ) (assert_return (invoke "size") (i32.const 0)) @@ -35,7 +35,7 @@ (module (memory 0) - (func (export "grow") (param i32) (result i32) (grow_memory (get_local 0))) + (func (export "grow") (param i32) (result i32) (memory.grow (get_local 0))) ) (assert_return (invoke "grow" (i32.const 0)) (i32.const 0)) @@ -47,7 +47,7 @@ (module (memory 0 10) - (func (export "grow") (param i32) (result i32) (grow_memory (get_local 0))) + (func (export "grow") (param i32) (result i32) (memory.grow (get_local 0))) ) (assert_return (invoke "grow" (i32.const 0)) (i32.const 0)) diff --git a/test/core/return.wast b/test/core/return.wast index d483b5e511..727680a17b 100644 --- a/test/core/return.wast +++ b/test/core/return.wast @@ -196,8 +196,8 @@ (i32.wrap/i64 (return (i32.const 41))) ) - (func (export "as-grow_memory-size") (result i32) - (grow_memory (return (i32.const 40))) + (func (export "as-memory.grow-size") (result i32) + (memory.grow (return (i32.const 40))) ) ) @@ -278,7 +278,7 @@ (assert_return (invoke "as-convert-operand") (i32.const 41)) -(assert_return (invoke "as-grow_memory-size") (i32.const 40)) +(assert_return (invoke "as-memory.grow-size") (i32.const 40)) (assert_invalid (module (func $type-value-empty-vs-num (result f64) (return))) diff --git a/test/core/typecheck.wast b/test/core/typecheck.wast index b322b526fd..0ac0c75e26 100644 --- a/test/core/typecheck.wast +++ b/test/core/typecheck.wast @@ -421,5 +421,5 @@ (assert_invalid (module (func (f64.promote/f32 (i32.const 0)))) "type mismatch") (assert_invalid (module (func (f64.reinterpret/i64 (i32.const 0)))) "type mismatch") -;; grow_memory -(assert_invalid (module (memory 1) (func (grow_memory (f32.const 0)))) "type mismatch") +;; memory.grow +(assert_invalid (module (memory 1) (func (memory.grow (f32.const 0)))) "type mismatch") diff --git a/test/core/unreachable.wast b/test/core/unreachable.wast index f7fe4030f4..f9b888e02d 100644 --- a/test/core/unreachable.wast +++ b/test/core/unreachable.wast @@ -203,8 +203,8 @@ (i32.wrap/i64 (unreachable)) ) - (func (export "as-grow_memory-size") (result i32) - (grow_memory (unreachable)) + (func (export "as-memory.grow-size") (result i32) + (memory.grow (unreachable)) ) ) @@ -286,5 +286,5 @@ (assert_trap (invoke "as-convert-operand") "unreachable") -(assert_trap (invoke "as-grow_memory-size") "unreachable") +(assert_trap (invoke "as-memory.grow-size") "unreachable") diff --git a/test/harness/wasm-constants.js b/test/harness/wasm-constants.js index 9e06985990..17bbedfff0 100644 --- a/test/harness/wasm-constants.js +++ b/test/harness/wasm-constants.js @@ -194,7 +194,7 @@ let kExprI64StoreMem8 = 0x3c; let kExprI64StoreMem16 = 0x3d; let kExprI64StoreMem32 = 0x3e; let kExprMemorySize = 0x3f; -let kExprGrowMemory = 0x40; +let kExprMemoryGrow = 0x40; let kExprI32Eqz = 0x45; let kExprI32Eq = 0x46; let kExprI32Ne = 0x47;