Better error handling for FUNCTION/SUB/GOSUB/RETURN clashes + underflow. · Issue #37 · google/wwwbasic · GitHub
More Web Proxy on the site http://driver.im/
You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The current implementation of FUNCTION/SUB/GOSUB/RETURN assumes that they are only
used in the correct order and never underflow.
Someone needs to investigate what the "correct" behavior in various canonical BASICs is when mixing GOTO / GOSUB / RETURN with FUNCTION/SUB.
I.e. can you do:
FUNCTION Foo(x)
GOTO Yikes
END FUNCTION
FUNCTION Bar(x)
Yikes:
Bar = 3
END FUNCTION
And if so, what does it do?
Same question with GOSUB/RETURN.
It may be even if allowed in interpreters, that this is just too weird and we should scream with an error.
But it would be good to know what's canonical and document if we deviate.
We should probably also check for under/overflow.
The text was updated successfully, but these errors were encountered:
On the functions branch had changed rstack to use shared
stack. This didn't merge right with the on-gosub change.
This highlights that RETURN mixed with SUB/FUNCTION calls
could have odd behavior. It might make more sense to keep them
separate. Though ideally maybe still in memory.
Filed issue to track:
#37
Labels are scope-dependant in QuickBASIC. The code above will yield a "Label not defined" error in Function Foo(x). If you had another Yikes label in FUNCTION Foo(x) that would be valid too - no duplicate if different scope.
Only case of cross-procedure GOTO is with ON ERROR GOTO, which always requires a label in the main module (unless you consider ON LOCAL ERROR GOTO, which is about another type of BASIC, not historical ones).
Do you know offhand how names work in terms of different types of objects?
Are variables, subroutines, functions, and labels all in one namespace, or is there some separation?
(Things easily answered for one version, but figure QB64 folks have a better sense of over multiple versions etc.?)
I couldn't answer about multiple versions. We QB64 folks are all about QBasic/QuickBASIC 4.5 only.
The answer here is: same namespace.
The exception is for SHARED variables. You can have a variable DIM SHARED in the main module, which makes it accessible in sub/functions, but then you can override it and have a local variable of the same name/type that is local to a procedure.
DIM SHARED a AS LONG
a = 1
mySub
SUB mySub
DIM a AS LONG
PRINT a
END SUB
The current implementation of FUNCTION/SUB/GOSUB/RETURN assumes that they are only
used in the correct order and never underflow.
Someone needs to investigate what the "correct" behavior in various canonical BASICs is when mixing GOTO / GOSUB / RETURN with FUNCTION/SUB.
I.e. can you do:
FUNCTION Foo(x)
GOTO Yikes
END FUNCTION
FUNCTION Bar(x)
Yikes:
Bar = 3
END FUNCTION
And if so, what does it do?
Same question with GOSUB/RETURN.
It may be even if allowed in interpreters, that this is just too weird and we should scream with an error.
But it would be good to know what's canonical and document if we deviate.
We should probably also check for under/overflow.
The text was updated successfully, but these errors were encountered: