rolandshacks / vs64

C64 Development Environment for Visual Studio Code
Other
103 stars 18 forks source link

undefined label #75

Closed blongden closed 1 day ago

blongden commented 2 months ago

First of all, thanks for the extension - this is a much nicer experience than what you got on the OG hardware!!

I'm just getting back into C64 basic and I thought I'd try a couple of sample bits of code that I know work (and have verified in VICE), however the well known 'POKE ALL THE COLOURS' demo fails to compile in bc and I cannot work out why.

B=53280 : P=53281 : V=53265 : T=646 : R=128
PRINT "{clear}"
30 C=C+1
IF C>15 THEN C=0
FOR W=1 to 15:WAIT V,R:NEXT W
POKE B,C : POKE P, PEEK (B)
POKE T, C
PRINT " POKE ALL THE COLOURS ";
GOTO 30

Above is the code. The bc error is on line 5, undefined label, 'C'. Is there something I need to do to either declare the variable for the bc compiler, or a setting to make it less strict (and truer to how basic 2 runs in the emulator)?

rolandshacks commented 2 months ago

Hi. Just had a quick look and it seems like you found a bug. Please give a little bit to analyze and fix.

Cheers! Roland

rolandshacks commented 2 months ago

Found it. Bug / problem is the "THEN C=0": 'C' is incorrectly taken as label, not as variable because there wasn't a lookahead for '='. This is now fixed.

Whenever I find some time, I will do a few quick tests and if everything is fine, publish an update release.

Thanks for reporting, Ben!

Roland

blongden commented 2 months ago

I dug into the code a little and came to the same conclusion! Thanks for taking a look so quick and your work on this (I'm super impressed there's a full parser for BASIC2.0 embedded in this thing..!)

rolandshacks commented 2 months ago

Hi. I published the fix to github - maybe you want to give it a try by manually downloading the vsix and updating.

https://github.com/rolandshacks/vs64/releases/latest https://github.com/rolandshacks/vs64/releases/download/v2.5.11/vs64-2.5.11.vsix

holo-deck commented 1 month ago

Hi there,

unfortunately, it seems it is still not fixed, at least not for me. I've installed the latest Version today (2.5.11) and tried this code:

10 n$ = ""
20 if n$ = "" then n$ = "zero"

and it returned an undefined label n error. I am running VSCodium on Linux and installed the vsix manually, but this should'nt make a difference in this case.

edit: It seems, that this problem only occurs, if the variables have a suffix/type identifier (%, $ etc.) or is an array like n(1) When i use letters only, it does work.

Greetings Michael

rolandshacks commented 1 month ago

Hi Michael, Thanks for reporting. I promise to have a look as soon as possible to fix that - hopefully it's what you suspect. Roland

rolandshacks commented 1 month ago

Hi. There's a new version 2.5.12 on github now, maybe you want to give it a try by manually downloading and installing the .vsix file to vscode.

https://github.com/rolandshacks/vs64/releases/latest

(that BASIC interpreter internals are a nightmare, I hope this time I figured out how to avoid those glitches).

holo-deck commented 1 month ago

Hello Roland,

i can confirm that it is working now. I tested it with some expressions and didn't run in any problems now. :+1:

And don't worry about timely pressure and obligations you may feel. I've used a temporary workaround in the meantime, where i've put the conditional assignment on another line like this:

10 n = 0
20 if n = 0 then gosub 1000
30 rem code 
50 end
1000 rem workaround line 20
1010 n$(0) = "zero"
1020 return

All in all, many thanks for the quick Resolution :-)

Greetings Michael

holo-deck commented 1 month ago

Hello again Roland,

well, i thought all is good in that regard, but, now GOSUB requires a space after it else it is part of a label. This happened, after i loaded some converted code from a game, which was tighten up and was directly prompted with that error again.

To replicate it i tried this

10 if x=0thengosub 100
20 print "world"
30 end
100 print "hello"
110 return

which works fine, but, If i change it to

10 if x=0thengosub100

the compiler throws

error: undefined label 'gosub100'

Thanks for the good work, btw. :-)

Greetings Michael

rolandshacks commented 1 month ago

Ahh. Thanks for the feedback and example. I think I found the problem, fixed it and added some more regression tests. I hope to find some time soon to build 2.5.13 ...

Just fyi, these are the use cases I had in mind, and I used to test:

LABEL1:
GOSUB LABEL1:GOTO LABEL1:GOSUB1:GOTO1
IF 1 THEN GET#1,X$
IF 1 THEN X=1
IF 1 THEN X = 1
IF 1 THEN X$ = "AA"
IF 1 THEN X% = 12.3
IF 1 THEN X(1) = 1
IF 1 THEN 1
IF 1 THEN LABEL1
IF 1 THEN GOTO1
IF 1 THEN GOTO 1
IF 1 THEN GOTO LABEL1
IF 1 THEN GOSUB1
IF 1 THEN GOSUB 1
IF 1 THEN GOSUB LABEL1
IF 1 THEN GO1
IF 1 THEN GO 1
IF 1 THEN GO LABEL1
IF 1 THEN GO TO1
IF 1 THEN GO TO 1
IF 1 THEN GO TO LABEL1
IF 1 THEN GO SUB 1
IF 1 THEN GO SUB LABEL1
IF 1 THEN PRINT
IF 1 THEN PRINT:GOTO 1
IF 1 THEN PRINT:GOTO LABEL1
IF 1 THEN PRINTA
IF 1 THEN PRINTA:GOTO 1
GOTO 1
GOTO LABEL1
3vi1 commented 1 month ago

I'm seeing what I believe to be the same thing with 2.5.13:

When I open the included basic examples directory, modern.bas is highlighting line 24 ("IF B%>15 THEN B%=0"), and the following is seen in build output in the terminal:

FAILED: /home/evil/src/vs64/examples/basic/build/basic_example.prg /home/evil/src/vs64/examples/basic/build/basic_example.bmap 
python3 /home/evil/.vscode-insiders/extensions/rosc.vs64-2.5.9/tools/bc.py --map "/home/evil/src/vs64/examples/basic/build/basic_example.bmap" -I /home/evil/src/vs64/examples/basic -I /home/evil/src/vs64/examples/basic/build -o /home/evil/src/vs64/examples/basic/build/basic_example.prg /home/evil/src/vs64/examples/basic/src/modern.bas
/home/evil/src/vs64/examples/basic/src/modern.bas(24): error: undefined label 'B'
ninja: build stopped: subcommand failed.
failed with exit code 1
rolandshacks commented 1 month ago

Hi. I just checked with 2.5.13 - works perfectly fine here. Both Linux and Windows. Are you sure you uninstalled the old version and installed v2.5.13.vsix?

3vi1 commented 1 month ago

Hi. I just checked with 2.5.13 - works perfectly fine here. Both Linux and Windows. Are you sure you uninstalled the old version and installed v2.5.13.vsix?

Doh... switching back and forth between normal vscode and insiders build, I was on the one with older build. You are correct - it works fine when you're using the right version. :)