Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

for loops could be supported with a compiler fix #48

Closed
disruptek opened this issue Jan 1, 2021 · 4 comments · May be fixed by #84
Closed

for loops could be supported with a compiler fix #48

disruptek opened this issue Jan 1, 2021 · 4 comments · May be fixed by #84
Labels
bug Something isn't working

Comments

@disruptek
Copy link
Contributor

Here's the test that runs against the almost branch:

https://github.com/disruptek/cps/blob/almost/tests/fors.nim

import testes
import cps

type
  C = ref object of RootObj
    fn*: proc(c: C): C {.nimcall.}

proc trampoline(c: C) =
  var c = c
  while c != nil and c.fn != nil:
    c = c.fn(c)

testes:

  block:
    proc loop() {.cps: C.} =
      for i in 0 .. 3:
        discard
    trampoline loop()

Here's the broken rewrite; CPS doesn't know what to do with the var i statement. I don't even understand how it passes through sem successfully to reach our macro...

 16  proc foo() =
 17    block :tmp:
 18      var i
 19      ## An alias for `countup(a, b, 1)`.
 20           ## 
 21           ## See also:
 22           ## * [..<](#..<.i,T,T)
 23      var res = 0
 24      block :tmp:
 25        while res <= 3:
 26          i = T(res)
 27          discard
 28          inc(res, 1)
@disruptek disruptek added the bug Something isn't working label Jan 1, 2021
@alaviss
Copy link
Contributor

alaviss commented May 3, 2021

#84 has the walkaround

@disruptek disruptek linked a pull request May 3, 2021 that will close this issue
@disruptek
Copy link
Contributor Author

The AST is so very awful that we cannot use getImplTransformed and so this effort is being killed in favor of a more manual transformation. 💀

@zevv
Copy link
Collaborator

zevv commented May 23, 2021

We could always file this as a CPS issue on nim and pass it to Araq

@disruptek
Copy link
Contributor Author

He would tell us that we made our bed when we chose to do this outside the compiler, and now we get to lie in it. And he's not wrong.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants