-
That is interesting information. So my theory about it working from storage isn't so complete. I further compared upload as "test.js" and used load("test.js") to call it. It doesnt' work there, the example where it works is when I load the file by renaming it to
test.boot.js
.I checked the alignment of the address, and it seems related to what you describe. Somehow code loaded at boot.js stage is more aligned? crazy.
Unrelated...
>let f = new Float32Array(1); =new Float32Array(1) >f[0] = 0.5 =0.5 >E.getAddressOf(f.buffer,true) =195582 >peek32(E.getAddressOf(f.buffer,true)).toString(16) ="4"
This is similar to your code above, but in the Emulator. I get weird output always "4".
Also this might sound stupid, but how can it store the float in 1 block(16bits). I print the float with :
>trace(f) #4452[r1,l1] Float32Array (offs 0, len 1) #5210[r1,l0] ArrayBuffer (offs 0, len 4) #2358[r1,l0] String [1 blocks] "\0>\x1CF" =undefined >peek32(r).toString(16) ="461c3e00" >f[0] =9999.5
Its using 24 bits, 0x46, 0x1c,0x3e. Yet 1 block? How is that possible?
process.memory().blocksize
prints14
E.getSizeOf()
for the flat string was 4. ( One block for the Float32Array view, One block for the ArrayBuffer view, 2 block for the backing flatstring data )for the normal string backed example, it was 3. ( One block for the Flaot32Array view, One block for the ArrayBuffer view, 1 block for the backing string data ).
Is my understanding correct of the above?
Maybe. It returns address if it makes sense = data is stored in one block, even normal short string can have the data in one block
https://github.com/espruino/Espruino/blob/5f6ad65e8c8bd51a2c1be17fe68ee162ce4e8c88/src/jsvar.c#L1745
This is also the case for your array
It can be seen the float array is backed by short string that takes up single block so it is makes sense to get the address of it.
However you can see that in my case the address is not aligned (ends with 5) so reading or writing float value from/to FPU register with such pointer will crash on unaligned memory access.
see also https://stackoverflow.com/questions/63834136/how-to-avoid-unaligned-access-exceptions-with-float-on-cortex-m4