RTP5 and RTP51
Published By | Date | Version | Knowledge Level | Keywords |
---|---|---|---|---|
Sprezzatura Ltd | 01 DEC 1991 | 2.1+ | EXPERT | RTP5, RTP51, ERROR.LIST, COMPILE, SYS.MESSAGES, REVERROR |
A Compuserve subscriber has asked how a program can compile another program and know if it failed? This spurred investigation into both RTP5 (the compiler) and RTP51 (the AREV ROS BFS) - the results of which are documented below. The RBASIC compiler is front-ended by RTP5 (REVMEDIA passim) and the calling syntax for this is documented by Revelation Technologies as
call RTP5("", CODE, PARAMS, STATUS, TYPE)
where
CODE | is the source code to be compiled |
PARAMS | is a dynamic array containing two fields, < 1 > title to be displayed whilst compiling < 2 > list of compile options C - cut off Symbol Table, E - for return reasons for failure (note not compilation errors) in @FILE.ERROR instead of displaying an error message I - display Insert Message even if S set N - Ignore freespace check S - for Suppress informational message display (Compiling *'s, Source Code Approaching Maximum Size etc) U - Do not buffer compiler |
STATUS | is a result flag (True or False) |
TYPE | is the type of compilation, M (code) or D (dictionary). |
When RTP5 is called, the compiler attempts to compile the code in CODE and if it fails, it returns a list of errors in CODE which would have the following structure
<1> | ERROR.LIST (a literal) |
<2,1> | Line number of error |
<2,2> | Error number |
<2,3> et seq | Error Parameters |
<3,et seq…..> | Repeat < 2 > |
with the second field repeating for each compilation error. Thus if a program compiled with two bad statements, one on line 10 and one on line 35, CODE would contain ERROR.LIST : @FM : 10 : @VM : B102 : @FM : 35 : @VM : B102.
The codes stored in the SYS.MESSAGES file are not the codes used by RTP5 to indicate errors. For example, the compiler error B105 means "Variable has not been dimensioned or declared as a function", but the entry in SYS.MESSAGES for B105 is "The dBase file already exists - Do you wish to overwrite it?". Rather the codes and their meanings are stored in the operating system file REVERROR.000 which is in AREV ROS format. However as there is no ROS media map for REVBOOT accessing this proves difficult.
Whilst it is possible to setvolume to REVBOOT and create an artificial REVMEDIA entry for REVERROR, this is cumbersome. It is far easier to simply construct a file handle for the REVERROR file and then to read directly from the file using this file handle. Unfortunately if this is attempted the system falls over with an RTP51 VNAV message. To prevent this it is necessary to first ensure that RTP51 is correctly installed by calling it directly with an install code. Once this has been done it is possible to read the error messages directly from file and then interpret the messages accordingly.
Note however that to people who have never been exposed to Rev G2.B the format of these error message records can be a little peculiar. Essentially the first character of each error message field is an instruction, H means output the following text without a terminating line feed, E means the same with a line feed, A means insert a variable here, L means insert a line feed. Using this short guide, a simple compile and syntax check program could be created as follows :-
/* Author AMcA Date Nov 1991 Purpose To compile programs and display error messages where appropriate Copyright Sprezzatura Ltd 1991. All Rights Reserved */ CODE = "" * Firstly prompt for code to be compiled call msg("Enter Code & or ; Delimited", "R", CODE, "") convert "&;" to @FM : @FM in CODE /* RTP5 objects to the lack of an END statement so ensure that there is one there! */ CODE<-1> = "END" * Compile the code call rtp5("", CODE, "Demo" : @FM : "S" , STATUS, "M") /* If status is not set then the compile has failed and the reason will be returned in CODE. NB this erases whatever was in CODE! */ if STATUS else * Ensure that RTP51 is available by calling with and install (22) code call RTP51(22, "RTP51", "", "", "", "", STATUS) /* Now construct an RTP51 file variable. These comprise the filing system, a value mark and the full dos file specification with an extension equal to the modulo, with a special modulo of 0 for dictionary files */ REV_ERR_FILE = "RTP5ýC:\AREV2_1\REVERROR.0" * Remember, the first error is a literal not an error ERR_CNT = count(CODE, @FM) + 1 ERR_MSG = "" for ERR = 2 to ERR_CNT LINE = CODE<ERR, 1> ERR_NO = CODE<ERR, 2> read ERR_REC from REV_ERR_FILE, ERR_NO then MARK = 0 ; POS = 0 ; VAR = 3 loop remove NL from ERR_REC at POS setting MARK * Now see how to interpret line if NL then FIRST_CHAR = NEXT_LINE[1,1] begin case case FIRST_CHAR = "E" ERR_MSG<-1> = NEXT_LINE[2,99] case FIRST_CHAR = "A" /* Note, MV 3 onwards contains variables to include in the message */ ERR_MSG := CODE<ERR, VAR> VAR += 1 case FIRST_CHAR = "H" ERR_MSG := NEXT_LINE[2,99] case FIRST_CHAR = "L" ERR_MSG := @FM end case end while MARK do repeat end next * And finally display the assembled error message call msg(ERR_MSG, "", "", "") end
(Volume 3, Issue 7, Pages 5-7)