DenialAdams / roland

Roland programming language
https://www.brick.codes/roland
Apache License 2.0
46 stars 0 forks source link

lower for loops to loop loops before the backend #79

Closed DenialAdams closed 1 year ago

DenialAdams commented 1 year ago
for j in START..END {
  // ...
}

should become (roughly)

t1 = START;
t2 = END;
j = t1;
loop {
  if j >= t2 {
    break;
  }
  // ...
  j = j + 1;
}
DenialAdams commented 1 year ago

Whoops, this is more complicated than I remembered because when we "continue" we still need to increment the counter.

The lowering is still possible, just needs to take that into account

DenialAdams commented 1 year ago

If we do this, can also remove a block in wasm backend

DenialAdams commented 1 year ago

Seems like this should be possible now that we have defer.

for i in 1..10 {
  ...;
}

becomes

let i = 1; // (but in right scope)
loop {
  if i >= 10 {
    break;
  } 
  defer i = i + 1;
  ...
}

however, we can't currently defer statements

DenialAdams commented 1 year ago

We can now defer assignment statements, so this lowering should be possible

DenialAdams commented 1 year ago

Oh, we do this now