home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / MISC / TNH_PC.ZIP / GLASS.NL < prev    next >
Encoding:
Text File  |  1987-01-14  |  1.8 KB  |  63 lines

  1. Determining BASIC Execution Environment
  2.  
  3.                Jim Glass
  4.  Rocketdyne Microcomputer Users Group
  5.  
  6. Have you ever wondered how you could
  7. have a BASIC program determine
  8. automatically whether it was being
  9. executed by the interpreter or by the
  10. compiler? Here are some ways to do
  11. this.
  12.  
  13. In bytes 2E and 2F of BASIC's work
  14. space segment (DEF SEG) is the line
  15. number of the line being executed. I
  16. found (so far) that this is always
  17. zero for compiled BASIC! Therefore,
  18. "IF Peek(&H2E)+256*Peek(&H2F)=0 then
  19. Compiled else Interpreted" is one
  20. method for testing the execution
  21. environment.
  22.  
  23. Another technique relies upon the
  24. fact that the interpreter  supports
  25. string lengths of only 255 bytes,
  26. while the compiler supports strings
  27. of up to 32,767 bytes.
  28.  
  29. A$=SPACE$(256) gives an error 5,
  30. illegal function call under the
  31. interpreter, and functions cleanly
  32. when compiled.
  33.  
  34. The following, or something like it
  35. should work..
  36.  
  37. 5 On error go to 9000
  38. 6 a$ = space$(256)
  39. 7 interp% = -1
  40. 10 on error go to 0
  41. 9000 if err = 5 and erl = 6 then
  42.      interp% = 0
  43. 9001 resume 10
  44.  
  45. Remember to compile with the proper
  46. switches, e.g. Resumes require /e or
  47. /x.
  48.  
  49. One other technique is to rely upon a
  50. fundamental rather than a technical
  51. difference between interpreted and
  52. compiled BASIC.  Compiled BASIC is
  53. fundamentally faster than interpreted
  54. BASIC. Thus, you might choose to time
  55. a loop during initialization. Based
  56. upon what should be a significant
  57. difference in execution times, you
  58. could set a variable to 'compiled' or
  59. 'interpreted'. The example may not be
  60. the best, but a fundamental
  61. difference is more likely to last the
  62. life of the software.
  63.