         Edinburgh IMP77 Compiler - Version 8.4

    1  !* Program Name : IADD
    2  
    3  !*   Title      :  V.a    The IMP  INTEGER ADDITION  Facilities
    4  !*   Version    :  II
    5  !*   Date       :  24 August 1985
    6  !*   Description:  Tests the integer addition and subtraction (both
    7  !*                 binary and unary) using various representations 
    8  !*                 and combinations of argument.  The arithmetic
    9  !*                 involves mostly binary operations.
   10  
   11  %Begin
   12  
   13     %string(255) param    { Used to get input from CLI}
   14  
   15     %Integer J
   16     %Integer K
   17     %Integer M
   18     %Integer N
   19  
   20     %Constant %Integer  CInt3 = 10
   21     %Constant %Integer  CInt4 = 3
   22           
   23           
   24  %owninteger failures=0
   25  
   26  %routine pass
   27    printstring("Pass")
   28    New Line
   29  %end
   30  %routine fail
   31    printstring("FAIL")
   32    New Line
   33    failures = failures+1
   34  %end
   35  
   36  
   37     %Integer %Function  F
   38  
   39       !*  An extremely simple integer function that merely
   40       !*  returns the number THREE.  Note that this function 
   41       !*  does not presuppose parameter passing or expression
   42       !*  evaluation within functions.  It merely tests the
   43       !*  ability to encorporate functions within expressions. 
   44                                                             
   45       %Result = 3
   46  
   47      %End
   48  
   49  
   50  
   51     ! Code to find out where the output is to be sent
   52     ! -----------------------------------------------
   53     ! Where the output goes to depends on the parameter after the
   54     ! name used to run the program.
   55     !                       Parameter   |   Result
   56     !                       ------------|-------------
   57     !                     No parameter  |  No output
   58     !                          "s"      |  The screen
   59     !                          "j"      |  "journal"
   60     !                     anything else |  file name entered
   61  
   62     ! NOTE THAT THIS CODE USES STRING COMPARISONS, WHICH MAY NOT HAVE BEEN
   63     ! TESTED YET. IF THE PROGRAM FAILS CHECK IT WAS NOT IN THIS PART.
   64  
   65     param=cliparam
   66     %if param = "" %then select output (2) %c
   67+    %else %if param="s" %or param="S" %then select output(1) %c
   68+    %else %if param="j" %or param="J" %then  %c
   69+       open output(2,"journal") %and select output (2) %c
   70+    %else open output(2,param) %and select output (2)
   71     
   72  
   73  
   74  
   75     New Lines(2)
   76     Print String ("INTEGER Arithmetic Validation");   New Line
   77     Print String ("=============================");   New Lines (3)
   78  
   79  
   80  
   81     !*  Test the INTEGER ADDITION 
   82  
   83     !*  Test the ability to be assigned after a expression evaluation.
   84     !*  In each of the following six tests, the destination variable
   85     !*  is the same as one of the expression arguments.  All arguments
   86     !*  are at full %INTEGER precision.
   87  
   88  
   89     Print String ("Test INTEGER ADDITION.");  New Line
   90     Print String ("----------------------");  New Lines (1)
   91  
   92     J = 50
   93     K = 10
   94  
   95     J = J + 10       { J = 60
   96     %If J = 60 %then pass %else fail
   97  
   98     J = 10 + J       { J = 70
   99     %If J = 70 %then pass %else fail
  100  
  101     J = J + CInt3    { J = 80
  102     %If J = 80 %then pass %else fail
  103  
  104     J = CInt3 + J    { J = 90
  105     %If J = 90 %then pass %else fail
  106  
  107     J = J + K       { J = 100
  108     %If J = 100 %then pass %else fail
  109  
  110     J = K + J        { J = 110
  111     %If J = 110 %then pass %else fail
  112  
  113     
  114     !*  Test that assignment after evaluation still works when the
  115     !*  destination variable does not appear in the expression.
  116  
  117     M = J + K    
  118     %If M = 120 %then pass %else fail
  119  
  120     
  121     !*  Now test the values of the two main variables: J and K
  122  
  123     %If J = 110 %and K = 10 %then pass %else fail
  124  
  125  
  126  
  127  
  128  
  129     !*  Test the INTEGER SUBTRACTION 
  130  
  131     !*  Test the ability to be assigned after a expression evaluation.
  132     !*  In each of the following six tests, the destination variable
  133     !*  is the same as one of the expression arguments.  All arguments
  134     !*  are at full %INTEGER precision.
  135  
  136     New Lines (2)
  137  
  138     Print String ("Test INTEGER SUBTRACTION.");   New Line
  139     Print String ("-------------------------");   New Lines (1)
  140  
  141     J = 110
  142     K = 10
  143     
  144     J = J - 10       { J = 100
  145     %If J = 100 %then pass %else fail
  146  
  147     J = 10 - J       { J = -90
  148     %If J = -90 %then pass %else fail
  149  
  150     J = J - CInt3    { J = -100
  151     %If J = -100 %then pass %else fail
  152  
  153     J = CInt3 - J    { J = 110
  154     %If J = 110 %then pass %else fail
  155  
  156     J = J - K       { J = 100
  157     %If J = 100 %then pass %else fail
  158  
  159     J = K - J        { J = -90
  160     %If J = -90 %then pass %else fail
  161  
  162  
  163     !*  Test that assignment after evaluation still works when the
  164     !*  destination variable does not appear in the expression.
  165  
  166     M = J - K    
  167     %If M = -100 %then pass %else fail
  168  
  169  
  170     !*  Now test the values of the two main variables: J and K
  171  
  172     %If J = -90 %and K = 10 %then pass %else fail
  173  
  174  
  175  
  176    
  177  
  178  
  179     !*  Test the UNARY MINUS operation.
  180  
  181     New Lines (2)
  182   
  183     Print String ("Test the UNARY MINUS");   New Line
  184     Print String ("--------------------");   New Lines (1)
  185  
  186     
  187     J = 50
  188     K = 10
  189  
  190     N = -CInt4
  191     M = -J
  192     K = -K
  193     J = -(-(-M))
  194  
  195     %If N = -3 %then pass %else fail
  196     %If M = -50 %then pass %else fail
  197     %If K = -10 %then pass %else fail
  198     %If J = 50 %then pass %else fail
  199  
  200  
  201  select output(1)
  202  write(failures,1);  printstring(" failure(s)");  newline
  203     
  204     
  205  %End %of %Program
?F unused

   91 Statements compiled
