LB Booster
« Labels in Subroutines »

Welcome Guest. Please Login or Register.
Apr 1st, 2018, 03:55am



ATTENTION MEMBERS: Conforums will be closing it doors and discontinuing its service on April 15, 2018.
We apologize Conforums does not have any export functions to migrate data.
Ad-Free has been deactivated. Outstanding Ad-Free credits will be reimbursed to respective payment methods.

Thank you Conforums members.
Speed up Liberty BASIC programs by up to ten times!
Compile Liberty BASIC programs to compact, standalone executables!
Overcome many of Liberty BASIC's bugs and limitations!
LB Booster Resources
LB Booster documentation
LB Booster Home Page
LB Booster technical Wiki
Just BASIC forum
BBC BASIC Home Page
Liberty BASIC forum (the original)

« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: Labels in Subroutines  (Read 470 times)
Jack Kelly
Full Member
ImageImageImage


member is offline

Avatar




Homepage PM

Gender: Male
Posts: 106
xx Labels in Subroutines
« Thread started on: Jun 5th, 2016, 08:21am »

Labels do not seem to be local in LBB. They are in JB, and should be in my opinion.

Code:
goto [a]

sub x
[a]
print "sub a"
end sub

[a]
print "main a"

 
User IP Logged

Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 1348
xx Re: Labels in Subroutines
« Reply #1 on: Jun 5th, 2016, 09:15am »

on Jun 5th, 2016, 08:21am, Jack Kelly wrote:
Labels do not seem to be local in LBB. They are in JB, and should be in my opinion.

Labels are local in LBB, for all practical purposes (many programs would not work if that was not the case). Try this:

Code:
call x
goto [a]
end

[a]
print "main a"
call x
end

sub x
goto [a]
exit sub

[a]
print "sub a"
end sub 

It's true that your example doesn't work in LBB, but that's because you're using a GOTO to 'jump over' a SUB, something that no sensible program would ever do.

There's a limit to the extent to which I can emulate the precise behaviour of labels in LBB, because I'm constrained by the way the underlying BBC BASIC works. But apart from 'contrived' examples you should find that local labels work as expected, and my LBB test suite includes programs that wouldn't run otherwise.

Richard.
« Last Edit: Jun 5th, 2016, 09:16am by Richard Russell » User IP Logged

Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 1348
xx Re: Labels in Subroutines
« Reply #2 on: Oct 1st, 2016, 7:17pm »

on Jun 5th, 2016, 09:15am, Richard Russell wrote:
apart from 'contrived' examples you should find that local labels work as expected, and my LBB test suite includes programs that wouldn't run otherwise.

It has been suggested that it would be helpful to provide more details about the circumstances in which LBB differs in the way labels work, which I am happy to do. The specific situation in which LBB won't behave the same as JB/LB is when the following conditions both apply:
  • The program attempts to GOTO or GOSUB a label in the main program that appears after one or more SUB or FUNCTION definitions
  • The destination label happens to be the same as a local label in one of those SUBs or FUNCTIONs.
In that case JB/LB will 'correctly' jump to the label in the main program, ignoring the label of the same name in the SUB/FUNCTION, but LBB will mistakenly jump to the 'local' label.

My assumption has always been that individually these conditions are unlikely, and that together they will virtually never happen. That's why I don't mention this rare special case in the LBB docs. If you want to ensure it never affects you, put all your SUBs and FUNCTIONs at the end, after the 'main program'.

Richard.
« Last Edit: Oct 2nd, 2016, 1:47pm by Richard Russell » User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

| |

This forum powered for FREE by Conforums ©
Terms of Service | Privacy Policy | Conforums Support | Parental Controls