SeedV/SeedLang

SingleStep notifications sent at V-tag comments lines when VTagEntered/VTagExited are enabled

Closed this issue · 1 comments

For the following simple bubble sort code:

a = [8, 1, 0]
for i in range(len(a)):
    for j in range(len(a) - i - 1):
        # [[ Compare(j, j+1) ]]
        if a[j] > a[j + 1]:
            # [[ Swap(j, j+1) ]]
            a[j], a[j + 1] = a[j + 1], a[j]

If we only turn on the SingleStep event, everything goes well as below:

dotnet run --project src/SeedLang.Shell -- -v SingleStep -f test.py 
SeedLang.Shell 0.2.1-preview20220507042306
Copyright 2021-2022 The SeedV Lab.

Enabled Visualizers: SingleStep

---------- Source ----------
1     a = [8, 1, 0]
2     for i in range(len(a)):
3         for j in range(len(a) - i - 1):
4             # [[ Compare(j, j+1) ]]
5             if a[j] > a[j + 1]:
6                 # [[ Swap(j, j+1) ]]
7                 a[j], a[j + 1] = a[j + 1], a[j]

---------- Run ----------
1     a = [8, 1, 0]
SingleStep: 1
2     for i in range(len(a)):
SingleStep: 2
3         for j in range(len(a) - i - 1):
SingleStep: 3
5             if a[j] > a[j + 1]:
SingleStep: 5
7                 a[j], a[j + 1] = a[j + 1], a[j]
SingleStep: 7
3         for j in range(len(a) - i - 1):
SingleStep: 3
5             if a[j] > a[j + 1]:
SingleStep: 5
7                 a[j], a[j + 1] = a[j + 1], a[j]
SingleStep: 7
3         for j in range(len(a) - i - 1):
SingleStep: 3
2     for i in range(len(a)):
SingleStep: 2
3         for j in range(len(a) - i - 1):
SingleStep: 3
5             if a[j] > a[j + 1]:
SingleStep: 5
7                 a[j], a[j + 1] = a[j + 1], a[j]
SingleStep: 7
3         for j in range(len(a) - i - 1):
SingleStep: 3
2     for i in range(len(a)):
SingleStep: 2
3         for j in range(len(a) - i - 1):
SingleStep: 3
2     for i in range(len(a)):
SingleStep: 2
7                 a[j], a[j + 1] = a[j + 1], a[j]
SingleStep: 7

But, when the VTagEntered/VTagExited events are enabled, SingleStep events will notify visualizers at the code line of V-tag comments:

dotnet run --project src/SeedLang.Shell -- -v SingleStep,VTagEntered,VTagExited -f test.py
SeedLang.Shell 0.2.1-preview20220507042351
Copyright 2021-2022 The SeedV Lab.

Enabled Visualizers: SingleStep, VTagEntered, VTagExited

---------- Source ----------
1     a = [8, 1, 0]
2     for i in range(len(a)):
3         for j in range(len(a) - i - 1):
4             # [[ Compare(j, j+1) ]]
5             if a[j] > a[j + 1]:
6                 # [[ Swap(j, j+1) ]]
7                 a[j], a[j + 1] = a[j + 1], a[j]

---------- Run ----------
1     a = [8, 1, 0]
SingleStep: 1
2     for i in range(len(a)):
SingleStep: 2
3         for j in range(len(a) - i - 1):
SingleStep: 3
4             # [[ Compare(j, j+1) ]]
5             if a[j] > a[j + 1]:
6                 # [[ Swap(j, j+1) ]]
7                 a[j], a[j + 1] = a[j + 1], a[j]
VTagEntered: Compare(j,j+1)
5             if a[j] > a[j + 1]:
SingleStep: 5
6                 # [[ Swap(j, j+1) ]]
7                 a[j], a[j + 1] = a[j + 1], a[j]
VTagEntered: Swap(j,j+1)
7                 a[j], a[j + 1] = a[j + 1], a[j]
SingleStep: 7
6                 # [[ Swap(j, j+1) ]]
SingleStep: 6
6                 # [[ Swap(j, j+1) ]]
7                 a[j], a[j + 1] = a[j + 1], a[j]
VTagExited: Swap(0,1)
4             # [[ Compare(j, j+1) ]]
SingleStep: 4
4             # [[ Compare(j, j+1) ]]
5             if a[j] > a[j + 1]:
6                 # [[ Swap(j, j+1) ]]
7                 a[j], a[j + 1] = a[j + 1], a[j]
VTagExited: Compare(0,1)
3         for j in range(len(a) - i - 1):
SingleStep: 3
4             # [[ Compare(j, j+1) ]]
5             if a[j] > a[j + 1]:
6                 # [[ Swap(j, j+1) ]]
7                 a[j], a[j + 1] = a[j + 1], a[j]
VTagEntered: Compare(j,j+1)
5             if a[j] > a[j + 1]:
SingleStep: 5
6                 # [[ Swap(j, j+1) ]]
7                 a[j], a[j + 1] = a[j + 1], a[j]
VTagEntered: Swap(j,j+1)
7                 a[j], a[j + 1] = a[j + 1], a[j]
SingleStep: 7
6                 # [[ Swap(j, j+1) ]]
SingleStep: 6
6                 # [[ Swap(j, j+1) ]]
7                 a[j], a[j + 1] = a[j + 1], a[j]
VTagExited: Swap(1,2)
4             # [[ Compare(j, j+1) ]]
SingleStep: 4
4             # [[ Compare(j, j+1) ]]
5             if a[j] > a[j + 1]:
6                 # [[ Swap(j, j+1) ]]
7                 a[j], a[j + 1] = a[j + 1], a[j]
VTagExited: Compare(1,2)
3         for j in range(len(a) - i - 1):
SingleStep: 3
2     for i in range(len(a)):
SingleStep: 2
3         for j in range(len(a) - i - 1):
SingleStep: 3
4             # [[ Compare(j, j+1) ]]
5             if a[j] > a[j + 1]:
6                 # [[ Swap(j, j+1) ]]
7                 a[j], a[j + 1] = a[j + 1], a[j]
VTagEntered: Compare(j,j+1)
5             if a[j] > a[j + 1]:
SingleStep: 5
6                 # [[ Swap(j, j+1) ]]
7                 a[j], a[j + 1] = a[j + 1], a[j]
VTagEntered: Swap(j,j+1)
7                 a[j], a[j + 1] = a[j + 1], a[j]
SingleStep: 7
6                 # [[ Swap(j, j+1) ]]
SingleStep: 6
6                 # [[ Swap(j, j+1) ]]
7                 a[j], a[j + 1] = a[j + 1], a[j]
VTagExited: Swap(0,1)
4             # [[ Compare(j, j+1) ]]
SingleStep: 4
4             # [[ Compare(j, j+1) ]]
5             if a[j] > a[j + 1]:
6                 # [[ Swap(j, j+1) ]]
7                 a[j], a[j + 1] = a[j + 1], a[j]
VTagExited: Compare(0,1)
3         for j in range(len(a) - i - 1):
SingleStep: 3
2     for i in range(len(a)):
SingleStep: 2
3         for j in range(len(a) - i - 1):
SingleStep: 3
2     for i in range(len(a)):
SingleStep: 2
7                 a[j], a[j + 1] = a[j + 1], a[j]
SingleStep: 7

Notice that the code line 4 and 6 are repeatedly reported via the SingleStep event.

It seems the issue is related to the evaluation operation of the V-tag parameters. As a comparison, I tested the following two sources.

Source 1: V-tag without parameters. SingleStep goes well:

a = [8, 1, 0]
for i in range(len(a) - 1):
  # [[ Compare ]]
  if a[i] > a[i + 1]:
    print(a[i])
dotnet run --project src/SeedLang.Shell -- -v SingleStep,VTagEntered,VTagExited -f test1.py 
SeedLang.Shell 0.2.1-preview20220507043742
Copyright 2021-2022 The SeedV Lab.

Enabled Visualizers: SingleStep, VTagEntered, VTagExited

---------- Source ----------
1     a = [8, 1, 0]
2     for i in range(len(a) - 1):
3       # [[ Compare ]]
4       if a[i] > a[i + 1]:
5         print(a[i])

---------- Run ----------
1     a = [8, 1, 0]
SingleStep: 1
2     for i in range(len(a) - 1):
SingleStep: 2
3       # [[ Compare ]]
4       if a[i] > a[i + 1]:
5         print(a[i])
VTagEntered: Compare
4       if a[i] > a[i + 1]:
SingleStep: 4
5         print(a[i])
SingleStep: 5
8
3       # [[ Compare ]]
4       if a[i] > a[i + 1]:
5         print(a[i])
VTagExited: Compare
2     for i in range(len(a) - 1):
SingleStep: 2
3       # [[ Compare ]]
4       if a[i] > a[i + 1]:
5         print(a[i])
VTagEntered: Compare
4       if a[i] > a[i + 1]:
SingleStep: 4
5         print(a[i])
SingleStep: 5
1
3       # [[ Compare ]]
4       if a[i] > a[i + 1]:
5         print(a[i])
VTagExited: Compare
2     for i in range(len(a) - 1):
SingleStep: 2
5         print(a[i])
SingleStep: 5

Source 2: V-tag with parameters. SingleStep sent on comments:

a = [8, 1, 0]
for i in range(len(a) - 1):
  # [[ Compare(i, i+1) ]]
  if a[i] > a[i + 1]:
    print(a[i])
dotnet run --project src/SeedLang.Shell -- -v SingleStep,VTagEntered,VTagExited -f test2.py 
SeedLang.Shell 0.2.1-preview20220507043804
Copyright 2021-2022 The SeedV Lab.

Enabled Visualizers: SingleStep, VTagEntered, VTagExited

---------- Source ----------
1     a = [8, 1, 0]
2     for i in range(len(a) - 1):
3       # [[ Compare(i, i+1) ]]
4       if a[i] > a[i + 1]:
5         print(a[i])

---------- Run ----------
1     a = [8, 1, 0]
SingleStep: 1
2     for i in range(len(a) - 1):
SingleStep: 2
3       # [[ Compare(i, i+1) ]]
4       if a[i] > a[i + 1]:
5         print(a[i])
VTagEntered: Compare(i,i+1)
4       if a[i] > a[i + 1]:
SingleStep: 4
5         print(a[i])
SingleStep: 5
8
3       # [[ Compare(i, i+1) ]]
SingleStep: 3
3       # [[ Compare(i, i+1) ]]
4       if a[i] > a[i + 1]:
5         print(a[i])
VTagExited: Compare(0,1)
2     for i in range(len(a) - 1):
SingleStep: 2
3       # [[ Compare(i, i+1) ]]
4       if a[i] > a[i + 1]:
5         print(a[i])
VTagEntered: Compare(i,i+1)
4       if a[i] > a[i + 1]:
SingleStep: 4
5         print(a[i])
SingleStep: 5
1
3       # [[ Compare(i, i+1) ]]
SingleStep: 3
3       # [[ Compare(i, i+1) ]]
4       if a[i] > a[i + 1]:
5         print(a[i])
VTagExited: Compare(1,2)
2     for i in range(len(a) - 1):
SingleStep: 2
5         print(a[i])
SingleStep: 5

SingleStep events were sent out at code line 3 in the above case.