Is there an official way to convert an argument passed by reference to a pointer to the exact same type? I know that during the CodeGen phase of compilation that ref int
becomes int *
, and I know that you can do so with extern for C interoperability sake, but what about for the sake of writing Chapel abstractions? Furthermore, what about the case of wide references and wide pointers? How would you handle something like that.
For those curious, I'm experimenting with some PGAS-STM (Partitioned Global Address Space - Software Transactional Memory) and one of the things I need to do is to allow semantics as follows...
Prepend to list using STM:
// Global variables
var head : node(eltType);
// Local variables
var newHead = new node(eltType);
var retry = false;
var stm = manager.getDescriptor();
do {
retry = false;
try! {
stm.begin();
// Takes pointer of 'head' via its reference...
// What happens if its a wide reference???
var h = stm.read(head);
newHead.next = h;
stm.write(head, nextHead);
stm.commit();
} catch retry : STMRetry {
retry = true;
}
} while retry;
Yes it is currently ugly, but it is a very early prototype.
Edit: Changed naming for STMBegin
to begin