Adds Memory.IndexByte and memory grow example (#489)

This adds Memory.IndexByte which allows efficent scanning for a
delimiter, ex NUL(0) in null-terminated strings.

This also adds an ad-hoc test to ensure we can export memory functions
such as grow. While this is implicitly in the spectests, it is easier to
find in the ad-hoc tests.

Signed-off-by: Adrian Cole <adrian@tetrate.io>
This commit is contained in:
Crypt Keeper
2022-04-20 20:33:15 +08:00
committed by GitHub
parent 043f67ab84
commit d238a004a8
7 changed files with 165 additions and 23 deletions

View File

@@ -58,6 +58,24 @@ func TestCompile(t *testing.T) {
Signature: &wasm.FunctionType{Params: []wasm.ValueType{wasm.ValueTypeI32}, Results: []wasm.ValueType{wasm.ValueTypeI32}},
},
},
{
name: "memory.grow", // Ex to expose ops to grow memory
module: requireModuleText(t, `(module
(func (param $delta i32) (result (;previous_size;) i32) local.get 0 memory.grow)
)`),
expected: &CompilationResult{
Operations: []Operation{ // begin with params: [$delta]
&OperationPick{Depth: 0}, // [$delta, $delta]
&OperationMemoryGrow{}, // [$delta, $old_size]
&OperationDrop{Depth: &InclusiveRange{Start: 1, End: 1}}, // [$old_size]
&OperationBr{Target: &BranchTarget{}}, // return!
},
LabelCallers: map[string]uint32{},
Types: []*wasm.FunctionType{{Params: []wasm.ValueType{i32}, Results: []wasm.ValueType{i32}}},
Functions: []uint32{0},
Signature: &wasm.FunctionType{Params: []wasm.ValueType{wasm.ValueTypeI32}, Results: []wasm.ValueType{wasm.ValueTypeI32}},
},
},
}
for _, tt := range tests {