Return array value
See original GitHub issueFeature Request
Overview
Not sure if this is a bug or not, I read through the docs and found no reference to this. Also tried looking through issues.
I can’t return an array. Correct me if i’m off here, but I think it’s because behind the scenes, walt is just grabbing the memory reference for the first element of the array. Similar to C if you print str
(where str is an char[]
), you’d just get the first char.
This is different from the issue about strings.
Impact
Large (if it doesn’t already exist).
Details
Here’s a dumb little example I tried:
const memory: Memory<{ initial: 1}>;
export function sortItems(array: i32[]): i32[] {
let i: i32;
let toReturn: i32[] = 0;
for (i = 0; i < 5; i += 1) {
toReturn[i] = i;
}
return toReturn;
}
I get Inconsistent return value. Expected i32[], received i32
Due Date
¯\(ツ)/¯ 7/20/18 if I missed something, I guess there is no due date.
I’m working on this for a hackday (which is only today), so either way, I’ll unfortunately have to ditch this project. I’m going to just use the C -> WASM compiler. However, I opened this issue because I’d like to experiment more in the future.
Issue Analytics
- State:
- Created 5 years ago
- Comments:8 (4 by maintainers)
Top GitHub Comments
Okay, sorry for the long thread of questions. Now I’ve got the memory object imported from
env
in the walt code, and I have created a DataView with the buffer to read from. But whenever I try to do array operations in walt, I get an out of bounds error. I think I’m just missing something again.~Apologies if this is documented. I searched for it and couldn’t find it here. The WebAssembly docs don’t help much in this case.~
EDIT: It sure is documented, I just missed the part that
initial
actual means the size 😄@ballercat this is an awesome library, thanks for putting it together.
Sure, all I mean is that it needs to be part of the imports to the WASM module. Per wasm spec, a Memory reference in a WebAssembly module is either declared or imported as a regular import with a memory type.
walt source, but really anything that compiles to wasm
MDN reference is a good source of info https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Memory