         Edinburgh IMP77 Compiler - Version 8.4

    1  
    2  !*   Title      :  V    The IMP  INTEGER  Facilities
    3  !*   Version    :  I
    4  !*   Date       :  12 July 1984
    5  !*   Description:  Tests initialisation, coercion, SIZE OF, precedence.
    6  
    7  %Begin
    8  
    9     %Integer J = 23 + 77 - 50    { i.e. 50
   10     %Integer K = J - 40          { i.e. 10
   11     %Integer M
   12     %Integer N
   13     %Integer R
   14     %Integer P
   15     %Integer NL     { Try to redefine the permanent procedures.
   16     %Integer Spaces
   17  
   18     %Byte  %Integer  B = 'F'
   19     %Short %Integer  S
   20     %Short %Integer  T
   21  
   22  ! The test below fails as initially written because it evaluates 2147483600 * 2 as an integer
   23  ! which is then assigned to the long integer.
   24  
   25  !  %Long  %Integer  L = 2147483600 * 2    { Two to the power of 32.
   26  
   27  ! However this version evaluates 2^^32 correctly:
   28     %Long  %Integer  L = 2147483600 {* 2} ; L = L * 2    { Two to the power of 32.
   29  
   30     %Constant %Byte %Integer  CB1 = 255
   31     %Constant %Byte %Integer  CB2 = 0
   32  
   33     %Constant %Integer  CInt1 = CB1 + 3 * 4
   34     %Constant %Integer  CInt2 = CInt1 + CB2 + 321
   35     %Constant %Integer  CInt4 = 3
   36     %Constant %Integer  MInt1 = M'X'
   37     %Constant %Integer  MInt2 = M'IMP'
   38  
   39  
   40  
   41           
   42  %owninteger failures=0
   43  
   44  %routine pass
   45    printstring("Pass: ")
   46  %end
   47  %routine fail
   48    printstring("FAIL: ")
   49    failures = failures+1
   50  %end
   51  
   52           
   53  
   54        
   55  
   56     %Integer %Function  F
   57  
   58       !*  An extremely simple integer function that merely
   59       !*  returns the number THREE.  Note that this function 
   60       !*  does not presuppose parameter passing or expression
   61       !*  evaluation within functions.  It merely tests the
   62       !*  ability to encorporate functions within expressions. 
   63                                                             
   64       %Result = 3
   65  
   66      %End
   67  
   68  
   69  
   70  
   71  !   Open Output (2, "Journal")
   72  !   Select Output (2)
   73  
   74  
   75  
   76     New Lines(2)
   77     Print String ("INTEGER Arithmetic Validation");   New Line
   78     Print String ("=============================");   New Lines (2)
   79  
   80  
   81     Print String ("Entities:");  New Line
   82     Print String ("-------- ");  New Lines (2)
   83     
   84     Print String ("Constants:                      ");  New Line
   85     Print String ("---------                       ");  New Line
   86     Print String ("%Byte %Integer  CB1 = 255       ");  New Line
   87     Print String ("%Byte %Integer  CB2 = 0         ");  New Lines (2)
   88     Print String ("%Integer  CInt1 = CB1 + 3 * 4      ");  New Line
   89     Print String ("%Integer  CInt2 = CInt1 + CB2 + 321");  New Line
   90     Print String ("%Integer  CInt4 = 3                ");  New Lines (2)
   91     Print String ("%Integer  MInt1 = M'X'             ");  New Line
   92     Print String ("%Integer  MInt2 = M'IMP'           ");  New Lines (2)
   93     
   94     New Lines (3)
   95  
   96     Print String ("Variables:               ");    New Line
   97     Print String ("---------                ");  New Line
   98     Print String ("%Integer J = 23 + 77 - 50");  New Line
   99     Print String ("%Integer K = J - 40      ");  New Line
  100     Print String ("%Integer M               ");  New Line
  101     Print String ("%Integer N               ");  New Line
  102     Print String ("%Integer R               ");  New Line
  103     Print String ("%Integer P               ");  New Lines (2)
  104     Print String ("%Integer NL              ");  New Line
  105     Print String ("%Integer Spaces          ");  New Lines (2)
  106     Print String ("%Byte  %Integer B = 'F'  ");  New Lines (2)
  107     Print String ("%Short %Integer S        ");  New Line
  108     Print String ("%Short %Integer T        ");  New Lines (2)
  109     Print String ("%Long  %Integer L = 2147483600 * 2");  New Lines (2)
  110  
  111  
  112     New Lines (5)
  113  
  114  
  115     Print String ("Test Simple Assignment of Integer Values"); New Line
  116     Print String ("----------------------------------------"); New Lines (2)
  117  
  118  
  119     %If J = 50 %then pass %else fail
  120     Print String ("Initialisation of J = 50")
  121     New Line
  122  
  123  
  124     %If K = 10 %then pass %else fail
  125     Print String ("Initialisation of K = J - 40")
  126     New Line
  127  
  128  
  129     %If CInt1 = 267 %then pass %else fail
  130     Print String ("Value of constant CInt1")
  131     New Line
  132  
  133     %If MInt1 = 'X' %then pass %else fail
  134     Print String ("Value of constant MInt1")
  135     New Line
  136  
  137     %If MInt2 = ((('I' << 8) + 'M') << 8) + 'P' %then pass %else fail
  138     Print String ("Value of constant MInt2   (for Offset = 8).")
  139     New Line
  140  
  141     %If CInt2 = 588 %then pass %else fail
  142     Print String ("Value of constant CInt2")
  143     New Lines (3)
  144  
  145  
  146  
  147  
  148  
  149     Print String ("Test the  SIZE OF  Function.");  New Line
  150     Print String ("----------------------------");  New Lines (2)
  151  
  152     Print String ("Size of %LONG    =");  Write (Size of (L), 1);  New Line
  153     Print String ("Size of %INTEGER =");  Write (Size of (J), 1);  New Line
  154     Print String ("Size of %SHORT   =");  Write (Size of (S), 1);  New Line
  155     Print String ("Size of %BYTE    =");  Write (Size of (B), 1);  New Line
  156  
  157     
  158     New Line
  159     %If L = 4294967200 %then Print String ("Can")   %c
  160+                       %else Print String ("Cannot")
  161     Print String (" hold a %LONG %INTEGER greater than %INTEGER precision.")
  162  
  163  
  164  
  165  
  166  
  167     New Lines (4)
  168   
  169     Print String ("Test Re-Assignment of Predeclared Procedures");  New Line
  170     Print String ("--------------------------------------------");  New Lines (2)
  171   
  172     Print String ("Let:  NL     = 100");  New Line
  173     Print String ("---   Spaces = 50 ");  New Lines (2)
  174  
  175     NL     = 100
  176     Spaces = 50
  177     
  178     %If NL = 100 %then pass %else fail
  179     Print String ("NL = 100")
  180     New Line
  181  
  182     %If Spaces = 50 %then pass %else fail
  183     Print String ("Spaces = 50")
  184  
  185  
  186  
  187     New Lines (6)
  188  
  189     Print String ("Test the Handling of Integer Expressions");  New Line
  190     Print String ("----------------------------------------");  New Lines (3)
  191  
  192     Print String ("Let:    M = 3");   New Line
  193     Print String ("---          ");   New Line
  194  
  195     M = 3
  196  
  197     J = 3 + CInt4 + M + F
  198  
  199     %If J = 12 %then pass %else fail
  200     Print String ("J = 3 + CInt4 + M + F")
  201     New Line
  202  
  203  
  204     
  205     New Lines (2)
  206     Print String ("Let:    J = 3");   New Line
  207     Print String ("---     K = 2");   New Line
  208     Print String ("        M = 30");  New Line
  209     Print String ("        N = 5") ;  New Lines (3)
  210  
  211     J = 3
  212     K = 2
  213     M = 30
  214     N = 5
  215  
  216     
  217  
  218     P = -1 ^^ 3
  219   
  220     %If P = -1 %then pass %else fail
  221     Print String ("P = -1 ^^ 3")
  222     New Line
  223  
  224     P = (-1) ^^ 2
  225  
  226     %If P = 1 %then pass %else fail
  227     Print String ("(-1) ^^ 2")
  228     New Line
  229  
  230     P = 2 ^^ 2 ^^ 3
  231  
  232     %If P = 64 %then pass %else fail
  233     Print String ("P = 2 ^^ 2 ^^ 3")
  234     New Line
  235  
  236     P = 2 + 3 * 5 ^^ 3 - 1
  237  
  238     %If P = 376 %then pass %else fail
  239     Print String ("P = 2 + 3 * 5 ^^ 3 - 1")
  240     New Line
  241  
  242     P = 2 + (-3)
  243  
  244     %If P = -1 %then pass %else fail
  245     Print String ("P = 2 + (-3)")
  246     New Line
  247  
  248     P = J - (-K)
  249  
  250     %If P = 5 %then pass %else fail
  251     Print String ("P = J - (-K)")
  252     New Line
  253  
  254     P = J * K + M // N - 6
  255  
  256     %If P = 6 %then pass %else fail
  257     Print String ("P = J * K + M // N - 6")
  258     New Line
  259  
  260     P = J * (K + M) // N - 6
  261  
  262     %If P = 13 %then pass %else fail
  263     Print String ("P = J * (K + M) // N - 6")
  264     New Line
  265  
  266     P = (J * K) + M // (N - 6)
  267  
  268     %If P = -24 %then pass %else fail
  269     Print String ("P = (J * K) + M // (N - 6)")
  270     New Line
  271  
  272  
  273     P = J * (K + M // N - 6)
  274  
  275     %If P = 6 %then pass %else fail
  276     Print String ("P = J * (K + M // N - 6)")
  277     New Line
  278  
  279     
  280  
  281     
  282     %If (-J) * (-K) = K * J  %then pass %else fail
  283     Print String ("(-J) * (-K) = K * J")
  284     New Line
  285  
  286     %If (((((J * K) + (M // N)) - 6))) = M // N + K * J - 6 %c
  287+            %then pass %else fail
  288     Print String (" (((((J * K) + (M // N)) - 6))) = M // N + K * J - 6")
  289     New Line
  290  
  291    
  292     J = | (CInt4 + F^^3) * (234 - (CInt1 - 500) ^^ K // 30) * 3 - 1000 // (-F) |
  293  
  294     %If J = 141417 %then pass %else fail
  295     Print String ("| (CInt4 + F^^3) * (234 - (CInt1 - 500) ^^ K // 30)")
  296     Print String (" * 3 - 1000 // (-F) |")
  297  
  298  
  299  
  300  
  301  
  302     New Lines (4)
  303   
  304     Print String ("Test Coercion Between the Various Types");  New Line
  305     Print String ("---------------------------------------");  New Lines (2)
  306  
  307     Print String ("Let:  S =  B");   New Line
  308     Print String ("---   T = -B");   New Line
  309     Print String ("      J =  B");   New Line
  310     Print String ("      K = -B");   New Line
  311     Print String ("      M = CB1");  New Line
  312     Print String ("      N = -CB1"); New Line
  313     Print String ("      P =  S");   New Line
  314     Print String ("      R = -S");   New Lines (2)
  315  
  316  
  317     B = 'F'       { Just make sure no corruption.  (ASCII = 70)
  318     S =  B
  319     T = -B
  320     J = B
  321     K = -B
  322     M = CB1
  323     N = -CB1
  324     P = S
  325     R = -S
  326  
  327     %If S = 70 %then pass %else fail
  328     Print String ("S = B")
  329     New Line
  330  
  331     %If T = -70 %then pass %else fail
  332     Print String ("T = -B")
  333     New Line
  334  
  335     %If J = 70 %then pass %else fail
  336     Print String ("J = B")
  337     New Line
  338  
  339     %If K = -70 %then pass %else fail
  340     Print String ("K = -B")
  341     New Line
  342  
  343     %If M = 255 %then pass %else fail
  344     Print String ("M = CB1")
  345     New Line
  346  
  347     %If N = -255 %then pass %else fail
  348     Print String ("N = -CB1")
  349     New Line
  350  
  351     %If P = 70 %then pass %else fail
  352     Print String ("P = S")
  353     New Line
  354  
  355     %If R = -70 %then pass %else fail
  356     Print String ("R = -S")
  357     New Line
  358  
  359  
  360  
  361  select output(0)
  362  write(failures,1);  printstring(" failure(s)");  newline
  363  %End %of %Program

  282 Statements compiled
