home *** CD-ROM | disk | FTP | other *** search
- Determining BASIC Execution Environment
-
- Jim Glass
- Rocketdyne Microcomputer Users Group
-
- Have you ever wondered how you could
- have a BASIC program determine
- automatically whether it was being
- executed by the interpreter or by the
- compiler? Here are some ways to do
- this.
-
- In bytes 2E and 2F of BASIC's work
- space segment (DEF SEG) is the line
- number of the line being executed. I
- found (so far) that this is always
- zero for compiled BASIC! Therefore,
- "IF Peek(&H2E)+256*Peek(&H2F)=0 then
- Compiled else Interpreted" is one
- method for testing the execution
- environment.
-
- Another technique relies upon the
- fact that the interpreter supports
- string lengths of only 255 bytes,
- while the compiler supports strings
- of up to 32,767 bytes.
-
- A$=SPACE$(256) gives an error 5,
- illegal function call under the
- interpreter, and functions cleanly
- when compiled.
-
- The following, or something like it
- should work..
-
- 5 On error go to 9000
- 6 a$ = space$(256)
- 7 interp% = -1
- 10 on error go to 0
- 9000 if err = 5 and erl = 6 then
- interp% = 0
- 9001 resume 10
-
- Remember to compile with the proper
- switches, e.g. Resumes require /e or
- /x.
-
- One other technique is to rely upon a
- fundamental rather than a technical
- difference between interpreted and
- compiled BASIC. Compiled BASIC is
- fundamentally faster than interpreted
- BASIC. Thus, you might choose to time
- a loop during initialization. Based
- upon what should be a significant
- difference in execution times, you
- could set a variable to 'compiled' or
- 'interpreted'. The example may not be
- the best, but a fundamental
- difference is more likely to last the
- life of the software.