8000 Better error handling for FUNCTION/SUB/GOSUB/RETURN clashes + underflow. · Issue #37 · google/wwwbasic · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Better error handling for FUNCTION/SUB/GOSUB/RETURN clashes + underflow. #37

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
flagxor opened this issue Sep 27, 2018 · 3 comments
Open
Labels
good first issue Good for newcomers help wanted Extra attention is needed

Comments

@flagxor
Copy link
Collaborator
flagxor commented Sep 27, 2018

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.

@flagxor flagxor added help wanted Extra attention is needed good first issue Good for newcomers labels Sep 27, 2018
flagxor added a commit that referenced this issue Sep 27, 2018
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
@FellippeHeitor
Copy link
Collaborator

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).

@flagxor
Copy link
Collaborator Author
flagxor commented Sep 28, 2018

Thanks Fellippe.
Labels per function sounds sane.

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.?)

7DD0

@FellippeHeitor
Copy link
Collaborator

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

That prints 0, not 1, as a is now local to mySub.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants
0