TCOMP.DOC - Tiny Basic Compiler by Mike Weiblen 72506,2072 4/1/85 TCOMP is a Tiny Basic compiler program written in Model 100 Basic. It converts a Basic program into machine language instructions which perform the same functions as their Basic counterparts. The idea is that you can develop and debug a program using the forgiving environment of M100 BASIC and then compile it so it will run like lightning! Please note, though, that you can not take just any Basic program and compile it. This compiler does not support all the features of M100 Basic, but rather a subset usually refered to as Tiny Basic. A list of the valid statements for Tiny Basic appears below. When writing programs to be compiled, be sure to use only those statements that appear on the list and use the exact syntax shown. Variables & Constants: All variables, constants and math operators use integer values. There are 26 numeric variables, A to Z. Constants must be expressed as values from 0 to 65535, although those values over 32767 will be treated as negative numbers. Values are stored and printed in the range -32768 to 32767. Valid Statements for TCOMP: Key: v = Variable name only (A to Z). n = Numeric constant only (0 to 65535). e = Either a variable name OR a numeric constant. Items enclosed in [ ] are optional. [LET] v=e GOTO n [LET] v=e+e GOSUB n [LET] v=e-e RETURN [LET] v=e*e END [LET] v=e [LET] v=e/e (Allowed) CLS [LET] v=e MOD e PRINT [@e,] e; [LET] v=PEEK(e) PRINT [@e,] CHR$(e); [LET] v=INP(n) PRINT [@e,] "string"; [LET] v$=INKEY$ (See note below) POKE e,e IF e=e THEN n OUT n,e IF ee THEN n PRESET (e,e) BEEP CALL n[,e[,e]] MENU The following statments cause the compiler to skip to the next line: REM ' DEFINT Special Considerations: Since string values are not supported by this compiler, the statement Q$=INKEY$ does not assign a character to the variable Q$, but rather assigns the ASCII value of the character to the variable Q. When writing your Basic programs, use the following statements: 500 Q=0:Q$=INKEY$:IFQ$<>""THENQ=ASC(Q$) This will ensure that TCOMP and M100 Basic will perform the same operation. TCOMP will ignore the rest of the line after the INKEY$. Be sure to put an END statement as the last line in your program. The compiled program will not end the same way the interpreter does when it runs out of program. Using TCOMP: After your program is written and debugged, run TCOMP. The first thing you must enter is the address at which you want to put the compiled code. The compiler sets HIMEM to this value. You may have to guess at this until you get a feel for how much space your program requires. Nothing keeps you from compiling it again at another location. Next, you are asked to enter the limit above which you do not want code to go. This protects any other machine language programs you may have in high memory. If you hit , it will use MAXRAM as the upper limit. Now you can enter the name of your Basic program. It uses the actual .BA version, not a .DO copy. You do not have to enter the .BA. Finally, you are asked for a name to save the compiled code under. If you just press ENTER, it will not be saved in a .CO file, but will remain in high memory. At this point, the compiler takes over. It begins by loading in five support routines that are used by the compiled code. Next, your Basic program is compiled. Each line number and it's respective memory location is displayed. When the compilation is complete, a second pass is made to adjust the GOTO and GOSUB statements. Finally, the starting, ending and execution addresses are displayed. Error Messages: If the compiler has any trouble understanding your program, you will get an error message that appears as: Compiler Error: XX, where XX is one of the following: OM - The compiled program will exceed your upper memory limit. UL - A non-existent line number has been referenced. TM - A variable was used where only a constant was allowed or visa versa. OV - A constant is outside the range of 0 to 65535. SN - Invalid syntax was used. TCOMP.110 (A supplement to TCOMP.DOC) NEW FEATURES: VARIABLE NAMES: TCOMP no longer restricts your variable names to A-Z. You may use any variable name that M100 BASIC will accept. ARRAYS: You can now define single dimension arrays. They also may be any name you want. An array can be used anywhere TCOMP syntax will allow you to use a variable. All arrays must be explicitly DIMed and the DIM must appear before any references to that array are compiled. VARIABLE CLEARING: All variables & arrays are initialized to zero by the compiler. READ/DATA/RESTORE: These statements are now supported, but there are a few rules that you must follow. All DATA lines must be at the end of your program (after all the executable statments). RESTORE must have a line number pointing to a DATA line and you must RESTORE before you try to read any DATA. Also, be sure that program control can not "fall" into the DATA statements or you'll be begging for a cold start. NUMERIC COMPARISON: TCOMP now understands that negative numbers are less than positive numbers. PRINT WITHOUT ";": The semicolon at the end of a PRINT statement is optional. If left off, you'll get the familiar CR/LF. NUMERIC CONSTANTS: Constants may be declared in the range of -32768 to 65535. RANDOM VALUES: While RND is not yet supported by TCOMP, PEEK(63791) will return a fairly random value between 0 and 125. STRANGE POINTER PROBLEM: I've heard tell of a problem compiling .BA files that have been loaded from disk. It seems that the internal line pointers that TCOMP uses are not updated after such a load. To take care of this, go into BASIC and load the .BA file into memory. That should update the pointers and TCOMP should work just fine. IMPROVED MEMORY ALLOCATION: TCOMP.110 will now allocate space for only the variables and Support Routines that your program actually uses. This can result in a considerable space saving, since the library of SR's is constantly growing. In order to implement these features, the memory map for TCOMP had to be changed to something like this: Starting Address Compiled BASIC Program DATA Statement tables (if any) Support Routines . . Variables & Arrays Ending Address As you can see, the program area starts at the Starting Address and climbs upward, while the Variable Table starts at the Ending Address and creeps down. Since that leaves the possibility of wasted space in between the two areas, TCOMP will report the number of free bytes caught in the middle so you can adjust the memory addresses and keep the wasted space to a minimum. Because of these changes to the memory map, the definition of an OM error has been modified (see below). MORE VALID STATEMENTS FOR TCOMP: [LET] v=e OR e RESTORE n [LET] v=e AND e READ v [LET] v=e XOR e DATA n[,n,n,...,n] [LET] v=e ^ e DIM v(n)[,v(n),...,v(n)] SOUND e,e NEW ERROR CODES: OM - Program & Variable areas have overlapped. BC - Bad CALL; Addresses below 15 are reserved for TCOMP use. ND - Array has not been DIMed. DD - Attempt to DIM array again. DT - Attempt to put executable statements after DATA. Many thanks to Peter Fox, Mark Lutton, Rick Perry and all the others who've been filling my Emailbox. Keep that feedback coming! - Mike Weiblen 72506,2072 4/23/85 TCOMP.121 (A supplement to TCOMP.DOC & TCOMP.110) NEW FEATURES: MATH EXPRESSIONS: You are no longer restricted to the rigid syntax of the earlier Tcomp versions. TCOMP.121 allows you to use ANY math expression consisting of the following operators: + - * / This means that everywhere an "e" term (meaning ither variable or numeric) was allowed, you may now use a math xpression. Example: A=-(J+1)*PEEK(Q+(A=>5)) PRINT CHAINING: The PRINT statement will now allow any number of items to be printed in a single statement by separating them with semicolons. Example: PRINT @A*5+1,"The CHR$ of";J;"is ";CHR$(J) OTHER IMPROVEMENTS: A RESTORE is no longer mandatory before any READs. It still requires a line number if you do use it. The strange pointer problem described in TCDOC.DO2 has been worked around & should no longer appear. All variables are now cleared to zero at the beginning of the compiled program rather than by the compiler. NEW STATEMENTS: [LET] v=e (general form) IF e THEN n ON e GOTO n[,n,...,n] IF e THEN more statements ON e GOSUB n[,n,...,n] LINE (e,e)-(e,e)[,e] FOR v=e TO e [STEP e] NEXT v[,v,...,v] [LET] v=RND(e)*e (Please note the specific syntax regarding the RND function.) Regarding FOR/NEXT: Tcomp is currently setup to handle 5 levels of FOR/NEXT nesting. You can expand/reduce this number by adjusting line 7071 where is says VT=VT-38. Replace the "38" using the following formula: 8 * (# of levels) - 2 Array table: This version of Tcomp makes use of several rather large arrays. I have arbitrarily sized them to suit my needs. If you should get a subscript out of range error or you just want to free up a bit of space, feel free to adjust these sizes. The DIM statement is in line 7021 and the meanings of the arrays are as follows: L & M: Line number/Memory address lookup table. S% & S: Support Routine address table (DO NOT ADJUST). U% & U: Expression processor stack. V$ & V: Variable name & address lookup table. A% & A: Address adjustment table. X: Control variable internal to Tcomp (DO NOT ADJUST). A final thought: As Tcomp grows, it needs more space. Please keep this in mind when you download programs from the database that were compiled by earlier versions. Adjust the starting & ending memory locations accordingly. Thanks again to everyone for all the expert help. PS: Strings are on the way! - Mike Weiblen 72506,2072 7/23/85