         Edinburgh IMP77 Compiler - Version 8.4

    1  !* Program name : SMULT
    2  
    3  !*   Title      :  VI.d    The IMP  SHORT  Facilities
    4  !*   Version    :  II
    5  !*   Date       :  24 August 1985
    6  !*   Description:  Tests the Multiplication, Division, Exponentiation and
    7  !*                 the REM function.
    8  
    9  %Begin
   10  
   11     %string(255) param    { Used to get input from CLI}
   12  
   13     %Short %Integer J 
   14     %Short %Integer K 
   15     %Short %Integer M
   16     %Short %Integer P
   17     %Short %Integer Q
   18  
   19     %Constant %Short %Integer  CInt3 = 10
   20     %Constant %Short %Integer  CInt4 = 3
   21  
   22  %owninteger failures=0
   23  
   24  %routine pass
   25    printstring("Pass")
   26    New Line
   27  %end
   28  %routine fail
   29    printstring("FAIL")
   30    New Line
   31    failures = failures+1
   32  %end
   33  
   34  
   35        
   36  
   37     %Short %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 open output(2, "journal") %and select output (2) %c
   69+    %else                                   open output(2, param)     %and select output (2)
   70     
   71  
   72  
   73  
   74     New Lines(2)
   75     Print String ("SHORT INTEGER Arithmetic Validation");   New Line
   76     Print String ("===================================");   New Lines (3)
   77  
   78  
   79  
   80     Print String ("Test the SHORT INTEGER Arithmetic Operators");  New Line
   81     Print String ("-------------------------------------------");  New Line
   82  
   83  
   84  
   85  
   86     !*   Test the SHORT INTEGER MULTIPLICATION 
   87            
   88     !*  Test the ability to be assigned after a expression evaluation.
   89     !*  In each of the following six tests, the destination variable
   90     !*  is the same as one of the expression arguments. 
   91  
   92     New Lines (2)
   93  
   94     Print String ("Test SHORT INTEGER MULTIPLICATION.");   New Line
   95     Print String ("----------------------------------");   New Line
   96  
   97  
   98     J = 50
   99     K = 10
  100  
  101     J = J * 10       { J = 500
  102     %If J = 500 %then pass %else fail
  103  
  104     J = 10 * J       { J = 5000
  105     %If J = 5000 %then pass %else fail
  106  
  107     J = 5
  108  
  109     J = J * CInt3    { J = 50
  110     %If J = 50 %then pass %else fail
  111  
  112     J = CInt3 * J    { J = 500
  113     %If J = 500 %then pass %else fail
  114  
  115     J = J * K       { J = 5000
  116     %If J = 5000 %then pass %else fail
  117  
  118     
  119     !*  Test that assignment after evaluation still works when the
  120     !*  destination variable does not appear in the expression.
  121  
  122     J = 5
  123  
  124     M = J * K    
  125     %If M = 50 %then pass %else fail
  126  
  127     
  128     !*  Now test the values of the two main variables: J and K
  129  
  130     %If J = 5 %and K = 10 %then pass %else fail
  131  
  132  
  133  
  134  
  135  
  136     !*    SHORT INTEGER EXPONENTIATION
  137  
  138     New Lines (2)
  139  
  140     Print String ("Test SHORT INTEGER EXPONENTIATION.");  New Line
  141     Print String ("----------------------------------");  New Line
  142  
  143     K = 3
  144     M = 5
  145  
  146     J = K ^^ 0
  147     %If J = 1 %then pass %else fail
  148  
  149     J = K ^^ M
  150     %If J = 243 %then pass %else fail
  151  
  152     J = K ^^ CInt4
  153     %If J = 27 %then pass %else fail
  154  
  155     J = 3 ^^ 0
  156     %If J = 1 %then pass %else fail
  157  
  158     J = 3 ^^ M
  159     %If J = 243 %then pass %else fail
  160  
  161     J = 3 ^^ CInt4
  162     %If J = 27 %then pass %else fail
  163  
  164     J = CInt4 ^^ 0
  165     %If J = 1 %then pass %else fail
  166  
  167     J = CInt4 ^^ M
  168     %If J = 243 %then pass %else fail
  169  
  170     J = CInt3 ^^ CInt4
  171     %If J = 1000 %then pass %else fail
  172     
  173  
  174     New Line
  175     Print String ("Let:  J = 3  before every test with J as argument."); New Line
  176     Print String ("---") ; New Line
  177  
  178     J = 3
  179     J = J ^^ 0
  180     %If J = 1 %then pass %else fail
  181  
  182     J = 3
  183     J = J ^^ M
  184     %If J = 243 %then pass %else fail
  185  
  186     J = 3
  187     J = J ^^ Cint4
  188     %If J = 27 %then pass %else fail
  189  
  190     J = 3
  191     J = J ^^ J
  192     %If J = 27 %then pass %else fail
  193  
  194     J = M ^^ M
  195     %If J = 3125 %then pass %else fail
  196  
  197   
  198   
  199  
  200     !*    SHORT INTEGER Division
  201  
  202     New Lines (2)
  203  
  204     Print String ("Test SHORT INTEGER Division.");  New Line
  205     Print String ("----------------------------");  New Line
  206  
  207     K = 30
  208     M = 5
  209  
  210     
  211     J = K // M
  212     %If J = 6 %then pass %else fail
  213  
  214     J = K // CInt4
  215     %If J = 10 %then pass %else fail
  216  
  217     J = 30 // M
  218     %If J = 6 %then pass %else fail
  219  
  220     J = 30 // CInt4
  221     %If J = 10 %then pass %else fail
  222  
  223     J = CInt3 // M
  224     %If J = 2 %then pass %else fail
  225  
  226     J = CInt3 // CInt4
  227     %If J = 3 %then pass %else fail
  228     
  229     New Line
  230     Print String ("Let:  J = 30  before every test with J as argument."); New Line
  231     Print String ("---")
  232     New Line
  233  
  234     J = 30
  235     J = J // M
  236     %If J = 6 %then pass %else fail
  237  
  238     J = 30
  239     J = J // Cint4
  240     %If J = 10 %then pass %else fail
  241  
  242     J = 30
  243     J = J // J
  244     %If J = 1 %then pass %else fail
  245  
  246     J = M // M
  247     %If J = 1 %then pass %else fail
  248  
  249  
  250  
  251  
  252     New Lines (2)
  253  
  254     Print String ("Test the Modulus Operator");  New Line
  255     Print String ("-------------------------");  New Line
  256     
  257     K = 0
  258     M = -3
  259     P = 3
  260  
  261     J = |-3|
  262     Q = |3|
  263     %if J = 3 %then pass %else fail
  264     %if Q = 3 %then pass %else fail
  265     
  266     J = |CInt4|
  267     %if J = 3 %then pass %else fail
  268  
  269     J = |K|
  270     %if J = 0 %then pass %else fail
  271  
  272     J = |M|
  273     %if J = 3 %then pass %else fail
  274  
  275     J = |P|
  276     %if J = 3 %then pass %else fail
  277  
  278     P = |P|
  279     %if P = 3 %then pass %else fail
  280  
  281     J = |F|
  282     %if J = 3 %then pass %else fail
  283  
  284     J = |(|M|)|
  285     %if J = 3 %then pass %else fail
  286  
  287     J = |(-P) + K - (|F * M|)|
  288     %if J = 12 %then pass %else fail
  289  
  290     
  291  select output(1)
  292  write(failures,1);  printstring(" failure(s)");  newline
  293  
  294  %End %of %Program

  167 Statements compiled
