Boriel Basic Forum
Print42 library throws error with --explicit option - Printable Version

+- Boriel Basic Forum (https://forum.boriel.com)
+-- Forum: Compilers and Computer Languages (https://forum.boriel.com/forumdisplay.php?fid=12)
+--- Forum: ZX Basic Compiler (https://forum.boriel.com/forumdisplay.php?fid=11)
+---- Forum: Help & Support (https://forum.boriel.com/forumdisplay.php?fid=16)
+---- Thread: Print42 library throws error with --explicit option (/showthread.php?tid=1042)



Print42 library throws error with --explicit option - georgeo - 2021-03-13

Hi everyone,

I'd like to use --explicit to force me to define all variables before using them, to reduce the risk of bugs. However, I see an issue because my program uses the Print42 library and it contains a definition that seems to violate the --explicit option.

Specifically, if you try to compile a program that includes Print42 library, using --explicit, you will see an error something like:

Code:
C:/opt/zxbasic-1.14.0/zxbasic/src/arch/zx48k/library/print42.bas:16: error: Undeclared variable "printAt42Coords"
C:/opt/zxbasic-1.14.0/zxbasic/src/arch/zx48k/library/print42.bas:17: error: Undeclared variable "printAt42Coords"

I considered updating the library source, so that printAt42Coords is defined. However, printAt42Coords is a code label, not a normal variable. The compiler complains because the label is dereferenced with an @printAt42Coords operation to work out the address at which to store the current coordinates:

Code:
SUB printat42 (y as uByte, x as uByte)
    POKE @printAt42Coords,x
    POKE @printAt42Coords+1,y
END SUB

...

printAt42Coords:

...

I don't know what type of variable printAt42Coords is, so can't add a 'dim' statement to define it. I tried defining it as a 'uinteger', but then the compiler complains when it tries to use as a label "error: identifier 'printAt42Coords' is a var, not a function"

Anyone know how to work around this?

Thanks in advance,


RE: Print42 library throws error with --explicit option - boriel - 2021-03-14

(2021-03-13, 11:59 AM)georgeo Wrote: Hi everyone,

I'd like to use --explicit to force me to define all variables before using them, to reduce the risk of bugs. However, I see an issue because my program uses the Print42 library and it contains a definition that seems to violate the --explicit option.

Specifically, if you try to compile a program that includes Print42 library, using --explicit, you will see an error something like:

Code:
C:/opt/zxbasic-1.14.0/zxbasic/src/arch/zx48k/library/print42.bas:16: error: Undeclared variable "printAt42Coords"
C:/opt/zxbasic-1.14.0/zxbasic/src/arch/zx48k/library/print42.bas:17: error: Undeclared variable "printAt42Coords"

I considered updating the library source, so that printAt42Coords is defined. However, printAt42Coords is a code label, not a normal variable. The compiler complains because the label is dereferenced with an @printAt42Coords operation to work out the address at which to store the current coordinates:

Code:
SUB printat42 (y as uByte, x as uByte)
    POKE @printAt42Coords,x
    POKE @printAt42Coords+1,y
END SUB

...

printAt42Coords:

...

I don't know what type of variable printAt42Coords is, so can't add a 'dim' statement to define it. I tried defining it as a 'uinteger', but then the compiler complains when it tries to use as a label "error: identifier 'printAt42Coords' is a var, not a function"

Anyone know how to work around this?

Thanks in advance,

This might be a bug, because --explicit was never considered with labels.
I'll check it.


RE: Print42 library throws error with --explicit option - boriel - 2021-03-23

(2021-03-14, 06:12 PM)boriel Wrote:
(2021-03-13, 11:59 AM)georgeo Wrote: Hi everyone,

I'd like to use --explicit to force me to define all variables before using them, to reduce the risk of bugs. However, I see an issue because my program uses the Print42 library and it contains a definition that seems to violate the --explicit option.

Specifically, if you try to compile a program that includes Print42 library, using --explicit, you will see an error something like:

Code:
C:/opt/zxbasic-1.14.0/zxbasic/src/arch/zx48k/library/print42.bas:16: error: Undeclared variable "printAt42Coords"
C:/opt/zxbasic-1.14.0/zxbasic/src/arch/zx48k/library/print42.bas:17: error: Undeclared variable "printAt42Coords"

I considered updating the library source, so that printAt42Coords is defined. However, printAt42Coords is a code label, not a normal variable. The compiler complains because the label is dereferenced with an @printAt42Coords operation to work out the address at which to store the current coordinates:

Code:
SUB printat42 (y as uByte, x as uByte)
    POKE @printAt42Coords,x
    POKE @printAt42Coords+1,y
END SUB

...

printAt42Coords:

...

I don't know what type of variable printAt42Coords is, so can't add a 'dim' statement to define it. I tried defining it as a 'uinteger', but then the compiler complains when it tries to use as a label "error: identifier 'printAt42Coords' is a var, not a function"

Anyone know how to work around this?

Thanks in advance,

This might be a bug, because --explicit was never considered with labels.
I'll check it.

Ok, I think I've fixed it.
Please, download this new beta version and tell me if it works (with --explicit):
http://www.boriel.com/files/zxb/zxbasic-1.15.0-beta13.tar.gz
http://www.boriel.com/files/zxb/zxbasic-1.15.0-beta13.zip
http://www.boriel.com/files/zxb/zxbasic-1.15.0-beta13-win32.zip
http://www.boriel.com/files/zxb/zxbasic-1.15.0-beta13-linux64.tar.gz
http://www.boriel.com/files/zxb/zxbasic-1.15.0-beta13-macos.tar.gz

Thx Rolleyes


RE: Print42 library throws error with --explicit option - georgeo - 2021-03-25

Hi Boriel,

Thanks. I'll give it a try tomorrow, and report back.

Speak to you soon,
Georgeo.


RE: Print42 library throws error with --explicit option - georgeo - 2021-03-25

Hi Boriel,

Based on a quick test, the fix looks to work. I no longer see errors when I reference labels from within my code, plus the print42 library doesn't cause an error.

Thanks again. Looks good,
Georgeo.


RE: Print42 library throws error with --explicit option - boriel - 2021-03-25

(2021-03-25, 07:02 PM)georgeo Wrote: Hi Boriel,

Based on a quick test, the fix looks to work. I no longer see errors when I reference labels from within my code, plus the print42 library doesn't cause an error.

Thanks again. Looks good,
Georgeo.

Good to know!