Skip to content
This repository has been archived by the owner on Jul 27, 2021. It is now read-only.

Can't nest loops even when only one of them is unrolled #2

Open
schneiderfelipe opened this issue Jul 6, 2021 · 0 comments
Open

Can't nest loops even when only one of them is unrolled #2

schneiderfelipe opened this issue Jul 6, 2021 · 0 comments
Labels
bug Something isn't working help wanted Extra attention is needed
Milestone

Comments

@schneiderfelipe
Copy link
Owner

This affects these examples, for instance

unrolled/tests/tests.nim

Lines 48 to 79 in a18ab5a

# BUG: !!!
# suite "Nested for-loops over slices":
# test "unroll works in inner nested loops":
# expandMacros:
# var total: int
# for i in 1..3:
# unroll for j in 1..3:
# total += i + j
# check total == (1 + 1) + (1 + 2) + (1 + 3) +
# (2 + 1) + (2 + 2) + (2 + 3) +
# (3 + 1) + (3 + 2) + (3 + 3)
# test "unroll works in outer nested loops":
# expandMacros:
# var total: int
# unroll for i in 1..3:
# for j in 1..3:
# total += i + j
# check total == (1 + 1) + (1 + 2) + (1 + 3) +
# (2 + 1) + (2 + 2) + (2 + 3) +
# (3 + 1) + (3 + 2) + (3 + 3)
# test "unroll works with multiple nested loops":
# expandMacros:
# var total: int
# unroll:
# for i in 1..3:
# for j in 1..3:
# total += i + j
# check total == (1 + 1) + (1 + 2) + (1 + 3) +
# (2 + 1) + (2 + 2) + (2 + 3) +
# (3 + 1) + (3 + 2) + (3 + 3)

Again (see #1), all three tests pass if we accept an untyped parameter in

unrolled/src/unrolled.nim

Lines 117 to 118 in a18ab5a

macro unroll*(x: typed): auto =
## Unroll for-loops.

Below the expanded code for the first example:

var total: int
block:
  for j in 1 .. 3:
    total += 1 + j
block:
  for j in 1 .. 3:
    total += 2 + j
block:
  for j in 1 .. 3:
    total += 3 + j
@schneiderfelipe schneiderfelipe added bug Something isn't working help wanted Extra attention is needed labels Jul 6, 2021
@schneiderfelipe schneiderfelipe added this to the 0.1 milestone Jul 6, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant