basic/doc/
appendix_c.rs

1/*!
2# Limits and Internals
3
4ROM BASIC was interpreted from slightly tokenized strings. Lexical
5analysis was a simple scan for keywords which would be collapsed
6to the unprintable ASCII characters below 32. These tokenized
7strings would be parsed as they were executed. There was no
8syntax tree or any opportunities for optimization. BASIC was
9notorious for being slow.
10
1164K BASIC is a compiler. Lexical analysis is crippled to mimic
12ROM BASIC but after that it parses to a nice abstract syntax tree.
13The syntax tree is compiled into link objects. The link objects
14contain opcodes which are resolved into a program for a virtual
15machine. The virtual machine is custom for 64K BASIC.
16
17All compilation happens behind the scenes. Big programs compile
18in a few milliseconds so you won't notice any delay. Direct mode
19opcodes are appended to the end of the indirect mode opcodes.
20The program is not compiled for every direct mode statement, instead
21the opcodes from previous direct mode statements are dropped and
22the new opcodes are linked to the end of the existing program.
23
24Each of the following is its own independent memory pool. Since
25ROM BASIC typically has about 40K bytes for everything, old programs
26will never come close to a limit in 64K BASIC.
27
28Source code is UTF-8. There is a maximum of 65530 lines (0-65529).
29Each line is limited to 1024 characters (not bytes).
30
31Compiled code is limited to 64K instructions (not bytes).
32This is what the virtual machine executes.
33
34Data is limited to 64K values (not bytes).
35These are from `DATA` statements.
36
37Stack is limited to 64K values (not bytes). In addition to the usual
38values like numbers and strings, the stack contains information about
39`FOR` loops and `GOSUB` calls.
40
41Variables are limited to 64K allocated values (not bytes). Zeros and
42empty strings are not allocated. Arrays are variables and therefore
43part of this 64K pool.
44
45Now you know why it's called 64K BASIC.
46
47*/