Skip to content

Commit

Permalink
add further fix for ON 2 GOTO 10, plus a test for it
Browse files Browse the repository at this point in the history
  • Loading branch information
robhagemans committed Nov 6, 2021
1 parent c42e32b commit 104e77f
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 6 deletions.
7 changes: 3 additions & 4 deletions pcbasic/basic/interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,15 +350,14 @@ def on_jump_(self, args):
i = -1
for i, jumpnum in enumerate(args):
if i == onvar-1:
# we counted the right number of commas, then didn't find a line number
if jumpnum is None:
raise error.BASICError(error.STX)
if jump_type == tk.GOTO:
self.jump(jumpnum)
elif jump_type == tk.GOSUB:
self.jump_sub(jumpnum)
return
# no jump args is a syntax error
# but *only* if the selector equals 1
if i == -1 and onvar == 1:
raise error.BASICError(error.STX)

###########################################################################
# loops
Expand Down
2 changes: 0 additions & 2 deletions pcbasic/basic/parser/statements.py
Original file line number Diff line number Diff line change
Expand Up @@ -1473,8 +1473,6 @@ def _parse_on_jump(self, ins):
yield ins.require_read((tk.GOTO, tk.GOSUB))
while True:
num = self._parse_optional_jumpnum(ins)
if num is None:
break
yield num
if not ins.skip_blank_read_if((b',',)):
break
Expand Down
4 changes: 4 additions & 0 deletions tests/basic/gwbasic/ON_x_GOTO_GOSUB_comma/PCBASIC.INI
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[pcbasic]
font=freedos
quit=True
run=TEST.BAS
30 changes: 30 additions & 0 deletions tests/basic/gwbasic/ON_x_GOTO_GOSUB_comma/TEST.BAS
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
10 REM PC-BASIC test
20 REM calculated jumps
30 open "output.txt" for output as 1
40 on error goto 1000
50 print#1, 50
60 a = 0: gosub 500
61 a = 1: gosub 500
62 a = 2: gosub 500
69 a = -1: gosub 500
70 a = 255: gosub 500
71 a = 256: gosub 500
72 a = 32767: gosub 500
73 a = 65535: gosub 500
160 a = 0: gosub 600
161 a = 1: gosub 600
162 a = 2: gosub 600
169 a = -1: gosub 600
170 a = 255: gosub 600
171 a = 256: gosub 600
172 a = 32767: gosub 600
173 a = 65535: gosub 600
490 end
500 on a goto,
510 print#1, 510: return
600 on a gosub,
610 print#1, 610: return
1000 print#1, err, erl, a
1010 resume next


30 changes: 30 additions & 0 deletions tests/basic/gwbasic/ON_x_GOTO_GOSUB_comma/model/OUTPUT.TXT
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
50
510
2 500 1
510
2 500 2
510
5 500 -1
510
510
5 500 256
510
5 500 32767
510
6 500 65535
510
610
2 600 1
610
2 600 2
610
5 600 -1
610
610
5 600 256
610
5 600 32767
610
6 600 65535
610


0 comments on commit 104e77f

Please sign in to comment.