Support WebAssembly Memory
Opened this issue · 0 comments
veewee commented
See:
- https://developer.mozilla.org/en-US/docs/WebAssembly/JavaScript_interface/Memory
- https://wasmerio.github.io/wasmer-python/api/wasmer/wasmer.html#MemoryType
$memory = new Wasm\Memory(
minimumPages: 1
maximulPages: null,
shared: true
);
$instance = Wasm\InstanceBuilder::fromWat($wat)
->withImports(['env' => ['someMemory' => $memory]])
->build();
$memory = $instance->someMemory();
// settings
$sizeInBytes = $memory->bytes();
$sizeInPages = $memory->pages();
$memory->grow(2);
// views
// TODO: possibly add an ArrayWrapper or Buffer that allows both read and write
$str = pack('C*', ...$memory->view()); // TODO : separate int[n] vs float[n] views
// Buffer Resource
$resource = $memory->buffer();
fseek($resource, 0);
fread($resource, $memory->bytes());
fwrite($resource, $data);