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

Computed gotos: bad codegen, label collision with if/statement in the while body #9276

Closed
mratsim opened this issue Oct 10, 2018 · 0 comments

Comments

Projects
None yet
3 participants
@mratsim
Copy link
Collaborator

commented Oct 10, 2018

When using computed gotos we can't use inline if statements before or after the main case statement (within it's OK).

Wrapping those in a proc is fine.

Test case:

type Op = enum
  opAdd
  opHalt

func next(code:seq[Op], i: var int): Op =
  result = code[i]
  inc i

proc execute(code: seq[Op]) =
  var i = 0
  var val = 0
  while true:
    {.computedGoto.} # Comment this and it compiles
    case code.next(i):
    of opAdd: inc val
    of opHalt: break
    if i == 0: # Comment this and it compiles
      echo val

let code = @[opAdd, opHalt]
code.execute()

@LemonBoy LemonBoy added the Codegen label Oct 10, 2018

krux02 added a commit to krux02/Nim that referenced this issue Oct 11, 2018

krux02 added a commit to krux02/Nim that referenced this issue Oct 20, 2018

@krux02 krux02 self-assigned this Oct 22, 2018

krux02 added a commit to krux02/Nim that referenced this issue Oct 23, 2018

@Araq Araq closed this in #9317 Oct 24, 2018

Araq added a commit that referenced this issue Oct 24, 2018

narimiran added a commit to narimiran/Nim that referenced this issue Oct 31, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.