#include <perms.h>

                                                                //      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
int main(int argc, char **argv) {
  _imp_initialise(argc, argv);
                                                                //     12  
                                                                //     13     %string(255) param    { Used to get input from CLI}
_imp_string /*%string(255)*/ PARAM;
                                                                //     14  
                                                                //     15     %Integer J
int J;
                                                                //     16     %Integer K
int K;
                                                                //     17     %Integer M
int M;
                                                                //     18     %Integer N
int N;
                                                                //     19  
                                                                //     20     %Constant %Integer  CInt3 = 10
                                                                //     21     %Constant %Integer  CInt4 = 3
                                                                //     22           
                                                                //     23           
                                                                //     24  %owninteger failures=0
static int FAILURES = 0;
                                                                //     25  
                                                                //     26  %routine pass
void PASS( void )
{
                                                                //     27    printstring("Pass")
_imp_PRINTSTRING(_imp_str_literal("Pass"));
                                                                //     28    New Line
_imp_NEWLINE();
                                                                //     29  %end
/* Remove %on %event handler here if present for this block */
return;
} // End of block PASS at level 2
                                                                //     30  %routine fail
void FAIL( void )
{
                                                                //     31    printstring("FAIL")
_imp_PRINTSTRING(_imp_str_literal("FAIL"));
                                                                //     32    New Line
_imp_NEWLINE();
                                                                //     33    failures = failures+1
FAILURES = (((int)(FAILURES)) + (1));
                                                                //     34  %end
/* Remove %on %event handler here if present for this block */
return;
} // End of block FAIL at level 2
                                                                //     35  
                                                                //     36  
                                                                //     37     %Integer %Function  F
int F( void )
{
                                                                //     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
/* Remove %on %event handler here if present for this block */
return 3;
                                                                //     46  
                                                                //     47      %End
} // End of block F at level 2
                                                                //     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
PARAM = _imp_CLIPARAM();
                                                                //     66     %if param = "" %then select output (2) %c
if ((_imp_strcmp(PARAM, _imp_str_literal("")) != 0)) goto L_0002;
_imp_SELECTOUTPUT(2);
goto L_0003;
L_0002:;
if ((_imp_strcmp(PARAM, _imp_str_literal("s")) == 0)) goto L_0004;
if ((_imp_strcmp(PARAM, _imp_str_literal("S")) != 0)) goto L_0005;
L_0004:;
_imp_SELECTOUTPUT(1);
goto L_0003;
L_0005:;
if ((_imp_strcmp(PARAM, _imp_str_literal("j")) == 0)) goto L_0006;
if ((_imp_strcmp(PARAM, _imp_str_literal("J")) != 0)) goto L_0007;
L_0006:;
_imp_OPENOUTPUT(2, _imp_str_literal("journal"));
_imp_SELECTOUTPUT(2);
goto L_0003;
L_0007:;
_imp_OPENOUTPUT(2, PARAM);
_imp_SELECTOUTPUT(2);
L_0003:;
                                                                //     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)
_imp_NEWLINES(2);
                                                                //     76     Print String ("INTEGER Arithmetic Validation");   New Line
_imp_PRINTSTRING(_imp_str_literal("INTEGER Arithmetic Validation"));
_imp_NEWLINE();
                                                                //     77     Print String ("=============================");   New Lines (3)
_imp_PRINTSTRING(_imp_str_literal("============================="));
_imp_NEWLINES(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
_imp_PRINTSTRING(_imp_str_literal("Test INTEGER ADDITION."));
_imp_NEWLINE();
                                                                //     90     Print String ("----------------------");  New Lines (1)
_imp_PRINTSTRING(_imp_str_literal("----------------------"));
_imp_NEWLINES(1);
                                                                //     91  
                                                                //     92     J = 50
J = 50;
                                                                //     93     K = 10
K = 10;
                                                                //     94  
                                                                //     95     J = J + 10       { J = 60
J = (((int)(J)) + (10));
                                                                //     96     %If J = 60 %then pass %else fail
if (((J) != (60))) goto L_0008;
PASS();
goto L_0009;
L_0008:;
FAIL();
L_0009:;
                                                                //     97  
                                                                //     98     J = 10 + J       { J = 70
J = (((int)(10)) + (J));
                                                                //     99     %If J = 70 %then pass %else fail
if (((J) != (70))) goto L_000a;
PASS();
goto L_000b;
L_000a:;
FAIL();
L_000b:;
                                                                //    100  
                                                                //    101     J = J + CInt3    { J = 80
J = (((int)(J)) + (10));
                                                                //    102     %If J = 80 %then pass %else fail
if (((J) != (80))) goto L_000c;
PASS();
goto L_000d;
L_000c:;
FAIL();
L_000d:;
                                                                //    103  
                                                                //    104     J = CInt3 + J    { J = 90
J = (((int)(10)) + (J));
                                                                //    105     %If J = 90 %then pass %else fail
if (((J) != (90))) goto L_000e;
PASS();
goto L_000f;
L_000e:;
FAIL();
L_000f:;
                                                                //    106  
                                                                //    107     J = J + K       { J = 100
J = (((int)(J)) + (K));
                                                                //    108     %If J = 100 %then pass %else fail
if (((J) != (100))) goto L_0010;
PASS();
goto L_0011;
L_0010:;
FAIL();
L_0011:;
                                                                //    109  
                                                                //    110     J = K + J        { J = 110
J = (((int)(K)) + (J));
                                                                //    111     %If J = 110 %then pass %else fail
if (((J) != (110))) goto L_0012;
PASS();
goto L_0013;
L_0012:;
FAIL();
L_0013:;
                                                                //    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    
M = (((int)(J)) + (K));
                                                                //    118     %If M = 120 %then pass %else fail
if (((M) != (120))) goto L_0014;
PASS();
goto L_0015;
L_0014:;
FAIL();
L_0015:;
                                                                //    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
if (((J) != (110))) goto L_0016;
if (((K) != (10))) goto L_0016;
PASS();
goto L_0017;
L_0016:;
FAIL();
L_0017:;
                                                                //    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)
_imp_NEWLINES(2);
                                                                //    137  
                                                                //    138     Print String ("Test INTEGER SUBTRACTION.");   New Line
_imp_PRINTSTRING(_imp_str_literal("Test INTEGER SUBTRACTION."));
_imp_NEWLINE();
                                                                //    139     Print String ("-------------------------");   New Lines (1)
_imp_PRINTSTRING(_imp_str_literal("-------------------------"));
_imp_NEWLINES(1);
                                                                //    140  
                                                                //    141     J = 110
J = 110;
                                                                //    142     K = 10
K = 10;
                                                                //    143     
                                                                //    144     J = J - 10       { J = 100
J = (((int)(J)) - (10));
                                                                //    145     %If J = 100 %then pass %else fail
if (((J) != (100))) goto L_0018;
PASS();
goto L_0019;
L_0018:;
FAIL();
L_0019:;
                                                                //    146  
                                                                //    147     J = 10 - J       { J = -90
J = (((int)(10)) - (J));
                                                                //    148     %If J = -90 %then pass %else fail
if (((J) != ((-90)))) goto L_001a;
PASS();
goto L_001b;
L_001a:;
FAIL();
L_001b:;
                                                                //    149  
                                                                //    150     J = J - CInt3    { J = -100
J = (((int)(J)) - (10));
                                                                //    151     %If J = -100 %then pass %else fail
if (((J) != ((-100)))) goto L_001c;
PASS();
goto L_001d;
L_001c:;
FAIL();
L_001d:;
                                                                //    152  
                                                                //    153     J = CInt3 - J    { J = 110
J = (((int)(10)) - (J));
                                                                //    154     %If J = 110 %then pass %else fail
if (((J) != (110))) goto L_001e;
PASS();
goto L_001f;
L_001e:;
FAIL();
L_001f:;
                                                                //    155  
                                                                //    156     J = J - K       { J = 100
J = (((int)(J)) - (K));
                                                                //    157     %If J = 100 %then pass %else fail
if (((J) != (100))) goto L_0020;
PASS();
goto L_0021;
L_0020:;
FAIL();
L_0021:;
                                                                //    158  
                                                                //    159     J = K - J        { J = -90
J = (((int)(K)) - (J));
                                                                //    160     %If J = -90 %then pass %else fail
if (((J) != ((-90)))) goto L_0022;
PASS();
goto L_0023;
L_0022:;
FAIL();
L_0023:;
                                                                //    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    
M = (((int)(J)) - (K));
                                                                //    167     %If M = -100 %then pass %else fail
if (((M) != ((-100)))) goto L_0024;
PASS();
goto L_0025;
L_0024:;
FAIL();
L_0025:;
                                                                //    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
if (((J) != ((-90)))) goto L_0026;
if (((K) != (10))) goto L_0026;
PASS();
goto L_0027;
L_0026:;
FAIL();
L_0027:;
                                                                //    173  
                                                                //    174  
                                                                //    175  
                                                                //    176    
                                                                //    177  
                                                                //    178  
                                                                //    179     !*  Test the UNARY MINUS operation.
                                                                //    180  
                                                                //    181     New Lines (2)
_imp_NEWLINES(2);
                                                                //    182   
                                                                //    183     Print String ("Test the UNARY MINUS");   New Line
_imp_PRINTSTRING(_imp_str_literal("Test the UNARY MINUS"));
_imp_NEWLINE();
                                                                //    184     Print String ("--------------------");   New Lines (1)
_imp_PRINTSTRING(_imp_str_literal("--------------------"));
_imp_NEWLINES(1);
                                                                //    185  
                                                                //    186     
                                                                //    187     J = 50
J = 50;
                                                                //    188     K = 10
K = 10;
                                                                //    189  
                                                                //    190     N = -CInt4
N = (-3);
                                                                //    191     M = -J
M = (-(J));
                                                                //    192     K = -K
K = (-(K));
                                                                //    193     J = -(-(-M))
J = (-((-((-(M))))));
                                                                //    194  
                                                                //    195     %If N = -3 %then pass %else fail
if (((N) != ((-3)))) goto L_0028;
PASS();
goto L_0029;
L_0028:;
FAIL();
L_0029:;
                                                                //    196     %If M = -50 %then pass %else fail
if (((M) != ((-50)))) goto L_002a;
PASS();
goto L_002b;
L_002a:;
FAIL();
L_002b:;
                                                                //    197     %If K = -10 %then pass %else fail
if (((K) != ((-10)))) goto L_002c;
PASS();
goto L_002d;
L_002c:;
FAIL();
L_002d:;
                                                                //    198     %If J = 50 %then pass %else fail
if (((J) != (50))) goto L_002e;
PASS();
goto L_002f;
L_002e:;
FAIL();
L_002f:;
                                                                //    199  
                                                                //    200  
                                                                //    201  select output(1)
_imp_SELECTOUTPUT(1);
                                                                //    202  write(failures,1);  printstring(" failure(s)");  newline
_imp_WRITE(FAILURES, 1);
_imp_PRINTSTRING(_imp_str_literal(" failure(s)"));
_imp_NEWLINE();
                                                                //    203     
                                                                //    204     
                                                                //    205  %End %of %Program
/* Remove %on %event handler here if present for this block */
return 0;
} // End of block _imp_main at level 1
// End of file
