The following code currently does not work:
var x = [(1, 1), (2, 2), (3, 3)];
fun init() {
x[0].0 = 5;
print(x[0].0); // prints 1 still
}
This is because we are still using intermediary temporaries when we compile this expression.
Perhaps the best way to do this is to get rid of SetIndex and GetIndex entirely, and then make part of the Set/Get chain's be an optional Index expression? Then we would basically compile the whole thing "at once."
Of course that doesn't quite work, because we need to use temporaries to ensure the bounds checking is memory safe, but it would be on the right track.
The fundamental thing is, for the last array index in the chain, we need to compile something like arr[i].x.y into:
ps_array_1 *tmp = ...;
tmp->contents[i].v_0.v_1 = ...
The other thing to keep in mind is this: if we ever do have a value type that is indexable, it will have to remain as part of the chain. So for example, if we support indexing a tuple of all the same type, and we have:
var tup = ((1, 1), (2, 2));
tup[0][0] = 5;
then we have to somehow compile that so that tup[0] is actually changed.
The following code currently does not work:
This is because we are still using intermediary temporaries when we compile this expression.
Perhaps the best way to do this is to get rid of SetIndex and GetIndex entirely, and then make part of the Set/Get
chain's be an optional Index expression? Then we would basically compile the whole thing "at once."Of course that doesn't quite work, because we need to use temporaries to ensure the bounds checking is memory safe, but it would be on the right track.
The fundamental thing is, for the last array index in the chain, we need to compile something like arr[i].x.y into:
The other thing to keep in mind is this: if we ever do have a value type that is indexable, it will have to remain as part of the chain. So for example, if we support indexing a tuple of all the same type, and we have:
then we have to somehow compile that so that tup[0] is actually changed.