lys-lang / lys

⚜︎ A language that compiles to WebAssembly
https://lys-lang.dev
Apache License 2.0
420 stars 8 forks source link

Consider a pointer size integer type #50

Open Serentty opened 4 years ago

Serentty commented 4 years ago

Right now, lengths and sizes seem to be stored using a u32. At the moment, this is fine for all existing WebAssembly code. However, given that there will be 64-bit linear memories in the future, I think it would make sense to abstract this detail away to allow the same code to be recompiled for such larger linear memories.

menduz commented 4 years ago

Hi there, thanks for commenting.

I didn't think much about sizes and lengths >32bit so far. What you say makes a lot of sense.

Did you think about a way to do it already? I can think about a couple of ways but those either generate a ton of wasm code to cast back and forth 32<>64bit numbers when interacting with lengths and sizes or are specialized "big strings" "big lists" which are unpleasant to think about..

Regarding pointers, even though Lys is wasm32, the memory layout of pointers is ready for wasm64. To get the memory address of a reference (64bit) we take the first 32bits

https://github.com/lys-lang/lys/blob/133a5b15d47fb148f8cc0ebf9720738de9381102/stdlib/system/core/native.lys#L9-L11

Serentty commented 4 years ago

Well, I expect that even after multiple memories, WebAssembly modules will still generally have a “home” address space, and I would expect usize to the be same number of bits as that address space.