The footer of the instructions to the exercise states the following:
Reserved Addresses
All input is provided as parameters, so no addresses in the linear memory are reserved.
But the input digits are provided as a contiguous sequence of 4-byte Integers in linear memory starting at the offset of 64 bytes, so I’m somewhat confused by what reserved really means here?
Furthermore, it took me some digging to convince myself that the input digits are indeed 4-bytes Integers, and that the arrLength argument denotes the number of digits and not the size in bytes of the memory used. It might seem silly in retrospect, but I initially worried the digits might be 1 byte each, especially since all test samples only feature small numbers.
The structure of the inputs does seem quite obvious looking back, so I’m wondering whether you think it makes sense to add some more details to the instructions about it?
@dreig, looking at this now. The note seems absolutely incorrect!
;; Returns offset and length of resulting u32[] and a return status code
(func (export "convert") (param $arrOffset i32) (param $arrLength i32) (param $inputBase i32) (param $outputBase i32) (result i32 i32 i32)
The JS side is definitely copying values in the linear memory based on the signature. The term “reserved” is intended to warn the student about what ranges of addresses they should avoid writing to.
It makes sense that you’d be confused about the fixed-width of the numbers here. There is a u32[] comment in the source, but it only references the result.
The (i32,i32,i32) return signature is also confusing.
I’ll take a crack at a PR improving this later this weekend. I’ll try to sanity check the other exercises as well.
Thanks for the clarification and for taking on the PR! all-your-base was my first exercise in the Wasm track that dealt with arrays of integers. I’ve since solved a few more exercises with arrays, and I can see that it’s a matter of convention to use offset + length to refer to a contiguous sequence of 4-byte Integers, both for inputs as well as for the result.
I think in the future a concept problem would be the perfect place to introduce students to this convention.
Also, thank you for all your work on the WebAssembly track, it’s been fun to work through!
PR is linked below. I expect it to merge when Eric begins his work week.
In retrospect, I do concur that it’s surprising that this is a sequence of u32s for digits as opposed to a sequence of u8s. I’m a bit hesitant to make changes that break existing solutions though.