Open simonsan opened 1 year ago
Encountering the same issue: need to perform a non-trivial operation on each element of an array, but I can't figure out how to create an empty one to store the results.
I've been fiddling around and I finally managed to get the pattern language to do what I want:
#include <std/mem.pat>
fn to_u16(s8 i) {
return u16((u8(i)-127)%0x100);
};
#define GAIN 50
fn toAudio(u64 location, u64 length) {
s8 data[length] @ location;
std::mem::Section scratch = std::mem::create_section("scratch");
u16 result[length] @ 0x0 in scratch;
// are there better ways of doing these?
for (u64 i = 0, i < length, i = i + 1) {
result[i] = to_u16(data[i]) * GAIN;
}
return result;
};
Turns out passing arrays around as-is is a little janky. I created a new array by placing it in a new section, but I'm not sure if this is the expected thing to do or not.
Hi simonsan, could you elaborate in more detail on what you would like the docs to describe? You specifically asked about std::Array, but EnronEvolved's snippet uses C-like arrays.
Trying to figure out, how arrays are being constructed exactly?
https://github.com/WerWolv/Documentation/blob/master/pattern_language/libraries/std/array.pat.md
And what methods are existing for them?