If a BASIC program is to become faster, then one seizes simply to the basic compiler. But how such a acceleration miracle functions?
Some applications require more speeds, than pure BASIC programs have to offer. Then one writes time-critical routines either in machine language or uses a compiler, which converts a BASIC program into machine language. The latter is naturally many simpler and more comfortable, since it only handling the compiler vorraussetzt. In addition the compiling does not need much time. The Compilat cannot by the way be worked on no more from basic. We turn now to the function mode of the turbo-basic compiler.
If you type a BASIC program, for example the program line "100?3*4
", the computer understands this line first only as a consequence of indications in the ATASCII format. By the term ATASCII one understands the special Atari version of the ASCII character set (ASCII is the abbreviation for: American standard code for information inter-CHANGE). The interpreter converts the entered text into tokens. At the same time it examines still the syntax, thus whether the instruction sequence is also permissible. This task must take over mostly also a compiler. Fig. 1 shows, like the program line "100?3*4
"looks translated into tokens.
The program line is then sorted on the basis its number. By this transformation in tokens and simultaneous syntax check the task of the compiler becomes somewhat simpler. One stores a BASIC program with that SAVE
Instruction, also the tokens are stored. With CUNNING
however it is present in the text form. The turbo-basic compiler can only "SAVE
Execution "translate. A transfer of the text form would be also in principle possible, however the compiler would need for this more time. Finally it must know the instruction names and store the variable names. This would decrease further the maximum length that programs which can be compiled. Or intermediate files on disk would have to be put on, which with the relatively slow Atari floppy disk drives is very time-consuming.
Before you compile a basic or a turbo- basic XL program, you should guarantee that it runs error free. It is not yet ensured then that the program can be duly compiled and implemented afterwards at first attempt. At least is void however syntax error, which would have as a consequence that you would have to correct your BASIC program, in order to compile it afterwards again. Also the structure of your BASIC programs must be correct. In addition that is offered CUNNING
Instruction under turbo-basic XL on, that as well known FOR
-NEXT ONE
Loops and IF
-ELSE
-ENDIF
Inquiries engages.
Atari basic and turbo-basic Xl-$lSAVE
Files consist of one link up with the variable names and unite other information for the interpreter. These are therefore overlooked before reading in either (like the variable names) or, in an adapted form, stored. This concerns the variable types primarily. The type of variable cannot however only be defined from the variable number, which is stored in the program. For example the dollar character ($), which marks the stringer variables, is not stored by the interpreter in the actual program.
With long programs with many variables one can recognize this phase of the Compilation clearly. In the info. line (the third character row of the turbo-basic compiler) then only the word line without line number is located. As soon as the first line is translated, also the announcement of the appropriate line number appears.
Now the actual compiling begins. It consists of two passages. In the first passage (passport 1) the program line for line and instruction for instruction is loaded and translated into machine code. Use the second passage (passport 2) still the open branch addresses are then inserted. In addition become in the passport 1 GOTO
Jumps in the code by an invalid machine instruction marked by attached line number. In the second passage then 6502 finally replacesJMP
Instructions (code $4C
the invalid machine instructions.
Something similar applies to numbers and text constants. They are stored in a block behind the actual BASIC program. The final addresses are then only certain after the translation. Following the second compiling passage then still another control follows whether open loops are present. Thus whether NEXT ONE
to one FOR
is missing or TURN
to one WHILE
etc. This applies, appears a message on the screen. Then still the examination follows after missing ENDIF
s. By this allocation of the error check (most errors are already determined in the first passage) the incorrect line numbers are not completely sorted spent, but if necessary in four individual groups.
Most work is carried out in the first passage, the remainder takes only few seconds. Reading the program in takes place line for line. First to the line number: If the line number is larger than 32767, then passport 1 is terminated (the interpreter by the way uses the line number 32768 as end characteristic). Then the second passage attaches. Otherwise the line number is indicated and the line instruction for instruction is read in and translated.
The compiler on one should CUNNING
- or ENTER
Instruction push, simply an error message with line number one spends, and the next instruction comes to the row.
No problems prepare REM
- or "--
"- lines. These instructions are simply overlooked and ignored, since they do not affect the program sequence.
Instructions without parameters (how END
POP
or CLR
are compiled simply to an appropriate subroutine reference.
With one DATA
Instruction is registered the text with line number and length in a table following the program. It takes up the still following information:
These information is shifted if necessary also in the memory, if the program or one of the tables which can be compiled increases. Therefore also the compiling speed decreases with long programs toward end; above all if many DATA
s at the beginning of the program stand. This slowing down concerns only the actual compiling and not the program sequence.
All instructions, which require parameters, are substantially more difficult to translate. Fig. 2 shows only one instruction with only one parameter.
The transformation of the instruction from step 1 after step 2 already settled the interpreter. The compiler reads that command tokens $03
for COLOR
and branches out to the appropriate Compilationsroutine. This calls again the routine for the translation of an expression, which is to return the delivery an integer. Then becomes only "STA $$C8
"attached, and thus the compiling of the instruction is already settled. With the instruction GRAPHICS
became "JSR @Graphics
"to be attached. The commercial at (@) by the way marks a routine in the run time library.
A large progress was not registered up to now yet. The instructions are compiled to the fact, change however unfortunately nothing in principle now that with the appropriate parameter, like in our example the 1 passed, still nothing.
The routine needed for it is divided into several sections:
P-CODE (pseudo code) resembles the machine language of a hypothetical (meant) processor. Some compilers produce only one P-CODE, which is then implemented by a small interpreter. The processing speed of such a code is faster than a conventional BASIC program, however from the speed of a "correct" machine language still far. But P-CODE is more space-saving compared with fully compiled basic. Genuine machine language is to be exceeded however from no compiler to.
Fig. 3 shows a more complicated example "03
"corresponds again to the token for COLOR
"46
"stands for PEEK
"Á
"for the open clip,"2c
"for the right parenthesis,"35
"stands for the addition (+),"16
"means line end or also a colon, which separates basic instructions in a line. The value "OE
"finally still another number in the internal representation marks (six byte correspond).
Tokens "03
"is already identified in our example. It begins now the test, in which order the operations must run off. The interpreter has to accomplish thereby nearly the same tests, each time, if he reaches this line. The compiler translates each line only once with the compiling. Thus the programs run off faster.
In the case of the translation in P-CODE the compiler avails itself of a table, in which the priorities of all operators are noted. By the way it concerns here nearly the same table, which also the interpreter uses. From it then the following P-CODE results. In fig. 4 the individual values are only represented in short form. The compiler regards it naturally as numbers.
Now theoretically already the routine could be called, the machine code produced. However then in the compiled program the same computations would run off, which the interpreter normally also accomplishes. Finally stands now much time for the optimization of the P-CODE for order, since the program lines only one only once in machine code are converted.
2 parte