assemblyscript-ewasm-api
assemblyscript-ewasm-api copied to clipboard
Add all missing ewasm methods
I'm already working on this
Can we merged this though? It is done, just needs to be reviewed :)
It seems addressOffset
, dataOffset
and resultOffset
is actually pointers, so better use usize
type instead i32
I'll review
@MaxGraey good to know, what are the differences? Would usize
be something like C's intptr
? We need to make sure though that usize
always translates to the wasm i32
type.
@axic usize
good to fit pointers in C indeed. Main advantage of usize
type is dependent on target. If target is wasm32
usize equal to u32
(address range 0x0 - 0xFFFFFFFF), if target is wasm64
usize equal to u64
(address range 0x0 - 0xFFFFFFFFFFFFFFFF). i32
can addressed only 0x0 - 0x7FFFFFFF
.
LGTM, back to you @axic. I updated the pointers to use usize
(thanks @dcodeIO).
@axic usize good to fit pointers in C indeed. Main advantage of usize type is dependent on target.
Thanks @MaxGraey that is good to know.
Unfortunately in this case it seems i32
makes more sense because we have to enforce the pointer size is always 32 bit. There is no i64
equivalent methods exported by ewasm and by the nature of blockchain (and actual hard limits) it is ensured a wasm binary will never grow past 4GBs, thus eliminating the need for i64
.
However, perhaps the cleanest way is to force compilation for 32-bit targets only. Is there a way to do that?
Currently wasm support only 32-bit addressing mode. This may change in the future (but there are opinions that it is not in such a near future and will require explicit flag). Anyway unsigned type definitely better for reflect pointer type. AS internally always use usize
for typeless references.