You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Will AS have support for pointers and references? #1228
I was just curious about this and I wanted to hear your thoughts.
Do you guys intend to add support for * and & to the language?
I understand that this might have consequences with the GC implementation and to TS Portability, but there are situations in which we need to call another application ABI and they take pointers as parameters.
One aspect there is that AssemblyScript doesn't have a stack on its own (in linear memory) but exclusively relies on Wasm's execution stack, which one can't take an address of / into. So, typically, one would either make a heap allocation or reserve some space in static memory to reuse for this purpose, as Max pointed out. Open to suggestions on how to improve this :)
WebAssembly hasn't shadow stack. It means only heap or objects in static sections could be interpret as references. In this case only objects could reference and dereference via ptr = changetype<usize>(obj) / obj = changetype<Obj>(ptr). That's quite sufficient for all unsafe stuffs.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Activity
MaxGraey commentedon Apr 16, 2020
Refs / pointers could be emulated via arrays
other solution:
dcodeIO commentedon Apr 16, 2020
One aspect there is that AssemblyScript doesn't have a stack on its own (in linear memory) but exclusively relies on Wasm's execution stack, which one can't take an address of / into. So, typically, one would either make a heap allocation or reserve some space in static memory to reuse for this purpose, as Max pointed out. Open to suggestions on how to improve this :)
dcodeIO commentedon Apr 18, 2020
Related: #1233 Might be useful here since it works very much like
staticin C/C++.mpmartins commentedon Apr 28, 2020
Well, I had something like this in my mind. But, to be honest, I don't really understand all the implications...
Add the following global functions:
After that, * and & could be syntactic sugar that calls these functions in the background.
MaxGraey commentedon Apr 28, 2020
WebAssembly hasn't shadow stack. It means only heap or objects in static sections could be interpret as references. In this case only objects could reference and dereference via
ptr = changetype<usize>(obj)/obj = changetype<Obj>(ptr). That's quite sufficient for all unsafe stuffs.MaxGraey commentedon Apr 28, 2020
Btw if you want more high-level and safe pointer (and zero-cost btw) you may interested in this experiment: https://github.com/AssemblyScript/assemblyscript/blob/master/tests/compiler/std/pointer.ts#L3
stale commentedon May 29, 2020
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.