=                                                              =









                     IMP8 INTERPRETER USER'S GUIDE


    The IMP8 INTERPRETER is an interactive IMP compiler with editing
    facilities,  which  runs under the EDINBURGH MULTI-ACCESS SYSTEM
    on the ICL 4/75.

    IMP statements are read in from the console, compiled,  executed
    immediately,  and  then  discarded.    Compound  statements  and
    complete procedures are saved pending later execution.




                        CALLING THE INTERPRETER

    Before using the interpreter for the first time, it is necessary
    to connect the interpreter library.

    This is done by
    command:     APPENDLIB(CONLIB.IMPILIB)


    Provided that this has been done, the interpreter can be  called
    by the command:              IMPI


                         USING THE INTERPRETER

       When it has been called, the interpreter identifies itself on
    the  console  and  waits  for  input.   The user may type an IMP
    statement (see facilities available).  In general, the statement
    typed  in  is  executed  immediatly; in relation to questions of
    scope these statements are effectively executed at main  program
    level (the initial %BEGIN is provided by the interpreter).   The
    'execution' of declarations introduces names and assigns storage
    for  use in subsequent statements.   Allocation and deallocation
    of storage follows the normal rules, which means that  variables
    declared   at  the  outermost  (basic)  level  remain  available
    throughout the session.

    However, if the statement typed is the first line of a  compound
    statement  (start/finish  group  or  cycle/repeat  group),  or a
    procedure (routine, function or  map),  the  interpreter  enters
    storage mode.   In this mode statements are not executed as they
    are typed in, but stored for subsequent use.    The  interpreter
    remains  in storage mode until it has read the group terminating
    statement  or  procedure  end  statement.   At  this  point  the
    complete  text  is either executed and then discarded, (compound
    statement) or retained for  use  through  the  normal  procedure
    calling mechanism (routine, function, map).

     The interpreter is terminated with the statement
                             %ENDOFPROGRAM
    #CLOSE is output to show that the interpreter has stopped.




                                 1

=                                                              =






                               INTERRUPTS

    The interpreter recognises three interrupts:

       INT:Q  returns control to the interpreter  from  the  running
              program, by forcing the run-time fault
              OPERATOR TERMINATION


       INT:H  returns  control  to  the interpreter from the running
              program without giving diagnostics.


       INT:NO turns off listing by forcing %ENDOFLIST

    Other  interrupts  have  the  meanings  assigned  to them by the
    sub-system.




                                PROMPTS

    During the running of the interpreter, input is requested by the
    following types of prompt:-

              :  the interpreter is  expecting  a  command  at  main
                 program level.

              C  the last line ended with '%C'.

              '  the  last  line  contained  an  unterminated string
                 constant.

             n:  this is statement number 'n' of the  present  block
                 (storage mode).

          DATA:  the running program requires data.
                 This prompt may be changed by the intrinsic routine
                 PROMPT (see facilities available).

             E:  the final %END of a procedure has been edited away,
                 so subsequent text will be taken from the console.
                 This text will be echoed if listing is enabled.


















                                 2

=                                                              =






                                EDITING

       Having typed in the text of a routine, function or  map,  the
    user  may  well  realise,  possibly  after  testing  it, that it
    contains  an  error.    Accordingly  the  interpreter   provides
    facilities  for editing any stored procedure.   These facilities
    are provided by the  COMPATIBLE  CONTEXT  EDITOR  (see  separate
    documentation  for a description of the command language).   The
    editor is called by the statement:-
                           $EDIT routine name
    When the editing operation is terminated (by %C) the new version
    of the procedure is compiled (see prompt 'E:').   If it contains
    any faults, the prompt EDIT NEW FILE ? is given.

    There are three valid replies:

              YES      causes the editor to be recalled to edit  the
                       new  version  of the text (as if the previous
                       '%C' used to close the editor had been 'M-0')


               NO      causes  the  new  version  of  the text to be
                       destroyed and leaves the process in the  same
                       state   as  prior  to  the  original  '$EDIT'
                       command which invoked the editor.

              LET      causes the old version of the procedure to be
                       destroyed  and  replaced  by the new (faulty)
                       version. (see FAULTS and ERROR REPORTS)


    When a version of the procedure has been produced which is found
    to have no faults (or LET has been specified), it  replaces  the
    old version, which is destroyed.


    During the compilation of the block, a line-numbered listing  is
    produced  on  the  console.    The commands %LIST and %ENDOFLIST
    respectively enable and disable this listing (see INT:NO).


       NOTE:  the  first statement of any stored procedure must be a
              valid procedure head. e.g. %ROUTINE FRED

              If other statements are  inserted  in  front  of  this
              head, or the head is made syntactically incorrect, the
              compilation will be abandoned with the prompt
              EDIT NEW FILE ?
              as above.


    If the whole of the file is deleted (eg. using K0) the procedure
    is destroyed.  This is indicated by the message

    PROCEDURE name DELETED







                                 3

=                                                              =






                          FACILITIES AVAILABLE

    The interpreter will accept the majority of statements  accepted
    by the IMPS VERSION 8 compiler on EMAS.

    Statements not accepted include:

       1.     machine code instructions

       2.     fault trapping

       3.     %OWN records (coming shortly)

       4.     %EXTERNAL  variables (these are treated as if the were
                       %OWN variables)


    The interpreter is terminated by the statement %ENDOFPROGRAM


    %EXTERNAL and %SYSTEM routines are compiled as normal routines.

    Inside comments a semi-colon is not treated as a separator, i.e.
    it forms part of the comment text.


    As statements at basic level are thrown  away  after  execution,
    labels and jump statements can have no meaning.   Hence they are
    only allowed inside procedures.

       In  addition  the  following  non-standard   facilities   are
    provided:

       1.     %ROUTINE PROMPT(%STRING(15) S)

                       is provided as an intrinsic routine.


       2.     the string function SNL

                       equivalent to TOSTRING(NL)

       3.     DRAIN

                       This  intrinsic  routine  will   remove   any
                       pending input.

       4.     %CONTINUE

                       This  statement  is  similar  to  %EXIT,  but
                       causes a jump to the %REPEAT of the enclosing
                       %CYCLE/%REPEAT group.

       5.     %FOR

                       This  can  be  used  to control a %CYCLE in a
                       similar way to
                             %CYCLE J=1,1,5
                       e.g.
                         A(J) = 0 FOR J=1, 1, 6


                                 4

=                                                              =












                   LIMITATIONS OF THE IMPLEMENTATION

    In order to ensure good  response,  the  following  restrictions
    have had to be imposed:

              1. No more than 512 distinct names.


              2. No more than 127 routines (including externals).


              3. The  total  space  allocated to basic level arrays,
                 strings and records is  limited  to  a  maximum  of
                 about 48K bytes.
                 This limit can be raised by specifying  the  number
                 of  extra  segments  (0  <=  n <= 9) to be used for
                 arrays and routines when the interpreter is called.
                 e.g.  IMPI(4)

                 If  the  space allocated to routines (text+code) is
                 filled FAULT 110 (BUFFER OVERFLOW) is given.


              4. Streams  77,  78,  79  are  reserved for use by the
                 interpreter.































                                 5

=                                                              =






                         INTERPRETER DIRECTIVES

    These are special commands used to control the operation of  the
    interpreter.

              1. $EDIT rtname

                       see EDITING

              2. $COMPILE filename

                       will  compile  statements from the given file
                       (which must be terminated by  %ENDOFFILE).  a
                       block  map will be produced on the console if
                       listing is enabled.

              3. $SENDTO filename

                       outputs the text of  all  previously  defined
                       procedures  and  all basic level declarations
                       to the given file.   The routines are  output
                       in   the  order  in  which  they  were  first
                       presented to the interpreter.   The statement
                       %ENDOFFILE is added to the end of this file.

              4. $RESTART

                       will  restart  the  interpreter  from scratch
                       without the  need  for  returning  to  system
                       command level and reloading.

              5. $NOSYNTAX

                       Listings     of    syntactically    incorrect
                       statements and descriptions of fault  numbers
                       are inhibited.

              6. $SYNTAX

                       The inverse of 1.

              7. $DELETE name

                       the  specified  named entity is destroyed and
                       can  therefore  be  redefined   (useful   for
                       removing faulty external specs).
                       This command should be used with care, as the
                       space   allocated   to  the  name  cannot  be
                       reclaimed.

              8. $MLEVEL N

                       Limits to 'n' the number  of  routine  levels
                       which  will  be  unwound  as  a  result of an
                       implicit/explicit %MONITOR.

                       $MLEVEL * will reset full monitoring.

              9. $CANCEL



                                 6

=                                                              =






                       This  command  closes  off  any   outstanding
                       textual  blocks  and  returns  to basic level
                       without executing any of the code. e.g.
                            %CYCLE J = 1,1,5
                                A(J) = 0
                                $ CANCEL
                       It can also be used to  abandon  an  external
                       routine   following   a  break  (see  PROGRAM
                       MONITORING).

              10.#EXPRESSION

                       The value of the (integer,  real  or  string)
                       expression  is  output  to  the console (only
                       valid at basic level). e.g.
                                #J-K*17
                       A list of expressions may be given  separated
                       by commas. e.g.
                      #J$3, FROMSTRING(S,1,7), $/3











































                                 7

=                                                              =






              11..ROUTINE CALL

                       The dot supplies an  external  spec  for  the
                       routine,  with  either  no parameters, or the
                       single  parameter  (%STRING(63)   S).     The
                       routine is then called, and remains available
                       for calling through  the  normal  mechanisms.
                       If  the statement is at basic level, the text
                       of the %SPEC will be output  with  the  other
                       declarations following a %SEND %TO.
                       e.g.
                            .LIST('SS#LIST')
                       FAULT 40 will be given if there are any other
                       statements on the same line.

              12.$LIST name

                       A   line-numbered   listing   of   the  named
                       procedure will be output.   This listing will
                       be  inhibited  by  %ENDOFLIST  and  hence  an
                       INT:NO will terminate the listing.  The given
                       name  not  corresponding  to  the  name  of a
                       stored procedure will cause the message:
                          * CANNOT LIST 'NAME'

              13.$FIND name:nn

                       will  list the three lines nn-1, nn, and nn+1
                       of the routine 'name'.

                       This is useful for discovering the  statement
                       identified by a monitor message.
                       NOTE: that in order  to  find  a  line  in  a
                       nested  routine  the  name must correspond to
                       that of the outermost routine.



























                                 8

=                                                              =






                           PROGRAM MONITORING


       The   Interpreter   contains  facilities  for  examining  and
    modifying the scalar variables of IMP programs.   These programs
    must  first  have  been  compiled  under  the  IMPS  compiler in
    diagnostic mode, and then called from the interpreter.

       To prepare the program (or file of external  routines),  each
    group  of lines at which the user may wish to suspend to program
    must first be enclosed in the two statements:

                          %CONTROL X'FFFFFF3F'
                                   &
                          %CONTROL X'FFFFFF1F'

    After compilation, the program (or routines) may be called  from
    outside the interpreter in the usual way.   However, from inside
    the Interpreter, the user can specify that the program is to  be
    suspended,  and  control  is  to be returned to the interpreter,
    when the execution reaches a predetermined line.

       When the program  has  been  interrupted,  the  local  scalar
    variables can be accessed via the built-in name 'MON', which may
    be thought of as a %RECORDNAME which has sub-names corresponding
    to  the  scalar variables local to the block being executed when
    the suspension occured.
    e.g.
                 WRITE(MON_FRED, 3);  MON_JIM = 'GREEN'

    NOTE:     When the interpreter is called at  the  suspension  of
              the  program,  routines  can  neither  be  defined nor
              edited.  Also all furthur calls for suspension will be
              inhibited   until  the  current  suspension  has  been
              resolved.
              Any  interrupt  (e.g.   OPERATOR TERMINATION) during a
              suspension, causes the program to  be  abandoned,  and
              the interpreter is returned to basic level.
























                                 9

=                                                              =






       The commands available are:

    $TRAP nn     Execution of the program is to  be  suspended  when
                 line  'nn'  is  reached ( before it is executed !).
                 If a previous trap has been  set  for  a  different
                 line,  the  old  trap  is  removed,  producing  the
                 message:
                 LINE nn RELEASED


                    It is possible for the execution of a program to
                 pass line 'nn' in more than one routine.   For this
                 reason, the TRAP can be qualified with the starting
                 line number of the exclosing 'block'. e.g.
                              $TRAP 74, 60
                 which  means:  trap  the  program at line 74 of the
                 'block' starting at line 60.
                 When a trap is reached and control is passed to the
                 interpreter, the point of  the  trap  is  indicated
                 with the message:

            BREAK: LINE 74 OF R/F/M FRED STARTING AT LINE 60

                 for example.

    $IGNORE      Any trap is removed, and so the program will not be
                 suspended.

    $MONITOR     The  system  monitor  (MDIAG)  will  be  called  to
                 monitor  the  state of the block in which execution
                 was suspended.

    $RESUME      Continue execution of the program.   If no trap has
                 been  made  this  will  have  no  effect other than
                 producing the message:

                           NOTHING TO RESUME


    $UP          Change  the  apparent  break point to the line from
                 which the current block was entered.

    $DOWN        Has the effect  of  nullifying  the  previous  **UP
                 command.

                 There  is a limit of 8 blocks for the scope of **UP
                 & **DOWN, and any attempt to exceed this limit,  or
                 to  move past the ends of the program's stack, will
                 be ignored.













                                 10

=                                                              =






                                 FAULTS
    COMPILE TIME

       Syntax  faults  cause  the  faulty statement to be completely
       ignored.

       At basic level all faults cause the faulty  statement  to  be
       completely  ignored.   At other levels the fault will inhibit
       the execution of a  block  and  mark  a  procedure  as  being
       faulty.  This is indicated by the message

       * ROUTINE FAULTY

       An  attempt  to call such a procedure (before the faults have
       been edited out) will result in the monitor being called with
       the run-time fault

       ROUTINE FAULTY


    RUN TIME

       An execution error will  cause  the  interpreter  to  give  a
       diagnostic trace of the execution path leading to the error.






































                                 11

=                                                              =






                             ERROR REPORTS

       1.     * CANNOT LOAD NAME
                       A  spec has been given for an external entity
                       which cannot be loaded.   The reason for  the
                       failure will have been given by the loader.

       2.     * CANNOT EDIT NAME / * CANNOT LIST NAME
                       'NAME' does not refer to a stored procedure.

       3.     CANNOT DEFINE PROCEDURE
                       A  routine has been so badly corrupted by the
                       editing operation just performed that  it  is
                       unsafe to allow 'LET' as a reply to
                       EDIT NEW FILE ?

       4.     * FAULT 2nn (COMPILER OVERWORKED) DISASTER
                       These  fault messages are usually produced by
                       giving the interpreter  excessively  long  or
                       complex  statements,  and  can  therefore  be
                       removed by splitting the offending  statement
                       into  two or more statements.   Corruption of
                       compiler tables will also cause these faults.

       5.     INT:Q IGNORED
                       An  INT:Q has been given when the interpreter
                       was not in a position to accept it safely.


       6.     * SIGNAL WT ww
                       The interpreter has received an interrupt for
                       which  there  is  not  an  IMP fault message.
                       Usually the interrupts  have  come  from  the
                       input/output routines in the sub-system.   If
                       the message is postfixed by 'IN COMPILER'  it
                       means  that  a  serious  error  has  occurred
                       during compilation.   This is  nearly  always
                       caused by the user giving an 'INT:Q' and will
                       almost certainly lead to  corruption  of  the
                       compiler tables.

       7.     *********** CATASTROPHIC FAILURE NN ***********
                       An  interrupt  has  been  given   while   the
                       interpreter   was  dealing  with  a  previous
                       interrupt.

       8.     ******* ABORT ******* ABORT *******
                       The   interpreter  has  discovered  that  its
                       tables  are  corrupted  beyond  repair.   All
                       stored  procedures  are  sent  to a temporary
                       file 'II#ABORT', and the user is returned  to
                       command level.  The chances of this happening
                       are very remote  but  can  be  attributed  to
                       misuse of 'INT:Q'








                                 12

=                                                              =






    Error reports (with  evidence  please)  and/or  suggestions  for
    improving the interpreter will be received with thanks from:


                          PETER S. ROBERTSON
                       C/O COMPUTER SCIENCE DEPT.
























































                                 13