assemblyscript-ewasm-api icon indicating copy to clipboard operation
assemblyscript-ewasm-api copied to clipboard

Add all missing ewasm methods

Open axic opened this issue 6 years ago • 9 comments

axic avatar Jun 29 '18 17:06 axic

I'm already working on this

lrettig avatar Jun 29 '18 17:06 lrettig

Can we merged this though? It is done, just needs to be reviewed :)

axic avatar Jun 29 '18 17:06 axic

It seems addressOffset, dataOffset and resultOffset is actually pointers, so better use usize type instead i32

MaxGraey avatar Jun 29 '18 17:06 MaxGraey

I'll review

lrettig avatar Jun 29 '18 17:06 lrettig

@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 avatar Jun 29 '18 17:06 axic

@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.

MaxGraey avatar Jun 29 '18 17:06 MaxGraey

LGTM, back to you @axic. I updated the pointers to use usize (thanks @dcodeIO).

lrettig avatar Jun 29 '18 20:06 lrettig

@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?

axic avatar Jun 29 '18 22:06 axic

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.

MaxGraey avatar Jun 29 '18 22:06 MaxGraey