4 ms·
Is it unusual for a VM not to have a string (or at least a bytes) type? I have little experience in the space, but it seems clunky. Curious why WASM went this
by tyingq 7y ago
Is it unusual for a VM not to have a string (or at least a bytes) type? I have little experience in the space, but it seems clunky. Curious why WASM went this direction.
- kbumsik 7y agoWASM just reached MVP. The design goal of the MVP seems to be a small spec that includes the minimum amount of requirements. I guess that is the reason why all four major browsers cloud adopt it almost in the same time, without having many proposal ping-pongs between Google vs Mozilla vs Apple vs Microsoft.
- tyingq 7y agoThis article, and proposals for reference types, though, make it sound like working around the lack of strings/bytes/chars might have been more work in the end. Sort of like a unicycle isn't really a bicycle MVP :)
- kbumsik 7y agoRight, but it is better than having to wait more years until browsers reach consensus. I'm not sure but specifying a WASM-native string representation might be more favorable to a specific JS engine than the others, depending on its existing JS string implementation. This might cause disagreements.
- AndrewDucker 7y agoThe problem is that WebAssembly exists for other languages to be compiled into. And those other languages don't agree what a string looks like. So do you have a Rust string? Or a C string? Or a C# string? Or one of the other representations? By just giving you a bunch of bytes to play with, and letting different languages use them differently, WebAssembly stays out of the way and lets the compiler decide how it wants to make strings.
- tyingq 7y ago"By just giving you a bunch of bytes to play with" It doesn't appear to do even that though. You get i32, i64, f32, and f64. The linear memory is some multiple of the 64KiB page size.
- AndrewDucker 7y agoAn i32 is a byte.
- kaoD 7y agoThe common definition of byte nowadays is an octet.
- kbumsik 7y agoIn WASM i32 can be treated like a 8-bit byte too.
- kaoD 7y agoCan you elaborate? I'm not well-versed in WASM internals and I might be missing something. I mean, any integer with 8+ bits can be treated like an octet, but memory layout is very different (e.g. an array of i8 and an array of i32 look very different even if they represent the same values).
- kbumsik 7y agoAlthough WASM types only have 32/64 bits it has 8/16 bit operations too. So it won't matter much: https://webassembly.org/docs/semantics/ https://webassembly.org/docs/semantics/
- kaoD 7y agoAnd linear memory, which is just an array of bytes.