         Edinburgh IMP77 Compiler - Version 8.4

    1  !* Program name : SADD
    2  
    3  !*   Title      :  V.d    The IMP  SHORT ADDITION  Facilities
    4  !*   Version    :  II
    5  !*   Date       :  24 August 1985
    6  !*   Description:  Tests the short 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     %Short %Integer J
   16     %Short %Integer K
   17     %Short %Integer M
   18     %Short %Integer N
   19  
   20     %Constant %Short %Integer  CInt3 = 10
   21     %Constant %Short %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 short 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 ("SHORT INTEGER Arithmetic Validation");   New Line
   77     Print String ("===================================");   New Lines (3)
   78  
   79  
   80  
   81     !*  Test the SHORT 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.
   86  
   87  
   88     Print String ("Test SHORT INTEGER ADDITION.");  New Line
   89     Print String ("----------------------------");  New Line
   90  
   91     J = 50
   92     K = 10
   93  
   94     J = J + 10       { J = 60
   95     %If J = 60 %then pass %else fail
   96  
   97     J = 10 + J       { J = 70
   98     %If J = 70 %then pass %else fail
   99  
  100     J = J + CInt3    { J = 80
  101     %If J = 80 %then pass %else fail
  102  
  103     J = CInt3 + J    { J = 90
  104     %If J = 90 %then pass %else fail
  105  
  106     J = J + K       { J = 100
  107     %If J = 100 %then pass %else fail
  108  
  109     J = K + J        { J = 110
  110     %If J = 110 %then pass %else fail
  111  
  112     
  113     !*  Test that assignment after evaluation still works when the
  114     !*  destination variable does not appear in the expression.
  115  
  116     M = J + K    
  117     %If M = 120 %then pass %else fail
  118  
  119     
  120     !*  Now test the values of the two main variables: J and K
  121  
  122     %If J = 110 %and K = 10 %then pass %else fail
  123  
  124  
  125  
  126  
  127  
  128     !*  Test the SHORT INTEGER SUBTRACTION 
  129  
  130     !*  Test the ability to be assigned after a expression evaluation.
  131     !*  In each of the following six tests, the destination variable
  132     !*  is the same as one of the expression arguments.
  133  
  134     New Lines (2)
  135  
  136     Print String ("Test SHORT INTEGER SUBTRACTION.");   New Line
  137     Print String ("-------------------------------");   New Line
  138  
  139     J = 110
  140     K = 10
  141     
  142     J = J - 10       { J = 100
  143     %If J = 100 %then pass %else fail
  144  
  145     J = 10 - J       { J = -90
  146     %If J = -90 %then pass %else fail
  147  
  148     J = J - CInt3    { J = -100
  149     %If J = -100 %then pass %else fail
  150  
  151     J = CInt3 - J    { J = 110
  152     %If J = 110 %then pass %else fail
  153  
  154     J = J - K       { J = 100
  155     %If J = 100 %then pass %else fail
  156  
  157     J = K - J        { J = -90
  158     %If J = -90 %then pass %else fail
  159  
  160  
  161     !*  Test that assignment after evaluation still works when the
  162     !*  destination variable does not appear in the expression.
  163  
  164     M = J - K    
  165     %If M = -100 %then pass %else fail
  166  
  167  
  168     !*  Now test the values of the two main variables: J and K
  169  
  170     %If J = -90 %and K = 10 %then pass %else fail
  171  
  172  
  173  
  174    
  175  
  176  
  177     !*  Test the UNARY MINUS operation.
  178  
  179     New Lines (2)
  180   
  181     Print String ("Test the UNARY MINUS");   New Line
  182     Print String ("--------------------");   New Lines (1)
  183  
  184     
  185     J = 50
  186     K = 10
  187  
  188     N = -CInt4
  189     M = -J
  190     K = -K
  191     J = -(-(-M))
  192  
  193     %If N = -3 %then pass %else fail
  194     %If M = -50 %then pass %else fail
  195     %If K = -10 %then pass %else fail
  196     %If J = 50 %then pass %else fail
  197  
  198  
  199  select output(1)
  200  write(failures,1);  printstring(" failure(s)");  newline
  201     
  202     
  203  %End %of %Program
?F unused

   91 Statements compiled
