HP 3000 Manuals

Example of a Simple Pascal ANYPARM Procedure [ HP Business BASIC/XL Reference Manual ] MPE/iX 5.0 Documentation


HP Business BASIC/XL Reference Manual

Example of a Simple Pascal ANYPARM Procedure 

This section contains a Pascal procedure that can be called from HP
Business BASIC/XL using the ANYPARM call interface.  This procedure shows
how to define the actual parameter table that the ANYPARM call requires.
It also contains an example procedure that accepts the actual parameter
table as a formal parameter.

     $title 'SIMPLE_ANYPARM_PROGRAM / SIMPLE_EXAMPLE with
        INTEGER and SHORT INTEGER'$
     $subprogram$
     $tables on$
     $code_offsets on$
     $range off$

     {*******************************************************************}
     {*                                                                 *}
     {*                         SIMPLE_ANYPARM_PROGRAM                  *}
     {*                                                                 *}
     {*Definition of the actual parameter table and the                 *}
     {*constants and types required to process                          *}
     {*Business BASIC/XL's SHORT INTEGER                                *}
     {*and INTEGER data types. The addresses of the SHORT INTEGER       *}
     {*and INTEGER values are passed in the actual parameter table      *}
     {*to the procedure, SIMPLE_EXAMPLE.  SIMPLE_EXAMPLE prints the     *}
     {*values of SHORT INTEGER and INTEGER values.                      *}
     {*                                                                 *}
     {*******************************************************************}
     program simple_anyparm_program;

     {-------------------------------------------------------------------}
     {Machine constants and types specific for the MPE XL based HP3000.  }
     {-------------------------------------------------------------------}
     const
        c_min_mchn_wrd_int = minint;
        c_max_mchn_wrd_int = maxint;

     type
        t_mchn_wrd_int = integer;
        t_half_mchn_wrd_int = shortint;

     {-------------------------------------------------------------------}
     {Constants representing Actual Parameter Types                      }
     {The values in the actual parameter table that define the           }
     {type of the parameter.                                             }
     {-------------------------------------------------------------------}
     const
        c_sinteger_type        = 5;
        c_integer_type         = 11;

        {----------------------------------------------------------------}
        {Scalar_value                                                    }
        {The pointer and associated variant record defining the HP       }
        {Business BASIC/XL value's storage format in memory.             }
        {----------------------------------------------------------------}
     type
        tp_scalar_value = ^t_scalar_value;
        t_scalar_value = record
                            case integer of
                               1: ( sinteger_value : shortint);
                               2: ( integer_value  : integer     );
                            end;

     {-------------------------------------------------------------------}
     {The Actual Parameter Table                                         }
     {An array of records describing the address, type and dimensionality}
     {of each of the actual parameters.                                  }
     {-------------------------------------------------------------------}
     const
        c_max_num_parameters = 50;

     type
        t_parameter_record = packed record
                             param_address       : tp_scalar_value;
                             param_type          : shortint;
                             number_of_dimensions: shortint;
                             end;

        t_actual_parameter_array = array [1..c_max_num_parameters] of
                                      t_parameter_record;

        tp_actual_parameter_array = ^t_actual_parameter_array;

     {*******************************************************************}
     {*                                                                  }
     {*                           SIMPLE_EXAMPLE                         }
     {*                                                                  }
     {*SIMPLE_EXAMPLE is a procedure written to accept an actual         }
     {*parameter table as the formal parameter to the procedure.  The    }
     {*purpose of the procedure is to write to a file the values of      }
     {*all scalar actual parameters that have either an INTEGER or       }
     {*SHORT INTEGER BASIC data type format.                             }
     {*Actual parameters are processed in a for loop in which            }
     {*the value of each valid parameter is written to $STDLIST.         }
     {*******************************************************************}
     procedure simple_example(
        num_params           : integer;
        p_actual_param_table : tp_actual_parameter_array
                             );

     var
        param_index : integer;
                {references entry in actual parameter table }
        tstfil      : text;
                {text file to which output is to be written }

     begin  {procedure_example }

     {-------------------------------------------------------------------}
     {TESTFILE is opened in append mode so that information written to   }
     { the file by previous calls is not overwritten.                    }
     {-------------------------------------------------------------------}
     append( tstfil, '$STDLIST' );

     writeln( tstfil
            , 'Number of parameters passed to SIMPLE EXAMPLE is: '
            , num_params:2
            );

     {-------------------------------------------------------------------}
     {Check to ensure that the number of actual parameters passed can be }
     {processed by the external.                                         }
     {-------------------------------------------------------------------}
     if num_params > c_max_num_parameters then
        begin  {too many parameters to process }
        writeln( tstfil, '   Too many actual parameters passed to SIMPLE EXAMPLE.' );
        writeln( tstfil, '   Maximum number is: ',
                             c_max_num_parameters:1 )
        end    {too many parameters to process }
     else

        begin  {simple_example's parameter array is large enough }

     {-----------------------------------------------------------}
     {Process each of the entries in the actual parameter table       }
     {referenced by the formal parameter, p_actual_parameter_array.}
     {-----------------------------------------------------------}
        for param_index := 1 to num_params do
           begin  {for loop processing of the actual parameters }

           write( tstfil, param_index:3, '   ' );
           if p_actual_param_table^[param_index].number_of_dimensions
      = 0 then
           begin  {process scalar actual parameters }
           with p_actual_param_table^[param_index].param_address^ do
                                                   {sinteger_value}
     {integer_value }
         case p_actual_param_table^[param_index].param_type of
            c_sinteger_type:
               writeln( tstfil, 'SHORT INTEGER ', sinteger_value:1 );
            c_integer_type:
               writeln( tstfil, 'INTEGER       ', integer_value:1 );
            otherwise
               write( tstfil, 'Actual parameter to SIMPLE EXAMPLE has an');
               writeln( tstfil, 'invalid data type.');
         end    {case }

        end    {process scalar actual parameters }

     else
        begin  {process actual parameters that are arrays }
        write( tstfil, 'Actual parameter to SIMPLE EXAMPLE must ');
        writeln( tstfil, 'be a scalar.')
        end    {process actual parameters that are arrays }

        end    {for loop processing of the actual parameters }

        end    {simple_example's parameter array is large enough }

     end;   {procedure simple_example }

     begin  {simple_anyparm_program }
     end.   {simple_anyparm_program }

Example of a Simple ANYPARM Call 

Assume that the Pascal program presented above is in the file, PASPROG.
To add the SIMPLE_EXAMPLE procedure to the local executable library named
XL, do the following:

     :pasxl pasprog
     :linkeditor
     linked>buildxl xl
     linked>addxl from=$oldpass; to=xl
     linked>exit
     :

Consult the HPLink Editor/XL Reference Manual for more information.

Enter the HP Business BASIC/XL interpreter, specifying your group
executable library.  (Refer to "The Interpreter" in chapter 2).  Within
the interpreter, enter and execute the following program:

     >list
      !  testany
          10 ANYPARM EXTERNAL Example ALIAS "simple_example"
          20 INTEGER Int1,Int2          ! variable declarations
          30 SHORT INTEGER Sint1,Sint2
          40 REAL Real1
          50 DIM INTEGER Int_arr(2,2)
          60 CALL Example               ! a call with no parameters
          70 Int1=-2147483648
          80 Int2=2147483647
          90 CALL Example(Int1,Int2)    ! a call with two integer parameters
         100 Sint1=-32768
         110 Sint2=32767
         120 CALL Example(Sint1,Sint2)
         121                      ! a call with two short integer parameters
         130 CALL Example(Real1,Int_arr(*,*))
         131                      ! invalid real and array parameters
         140 Int_arr(2,2)=100000
         150 CALL Example(Int_arr(2,2))
         151                      ! a call with an array element parameter
         160 CALL Example(Sint1,Int_arr(1,1),Int2,Sint2,Int1,&
              (Sint1),(Sint1+Sint2),&
             Int_arr(2,2),(Int1+Sint2),"Beginning of invalid parameters",&
             Str$,Real1,Int_arr(*,*))

     >run
     Number of parameters passed to SIMPLE EXAMPLE is:  0
     Number of parameters passed to SIMPLE EXAMPLE is:  2
     1   INTEGER       -2147483648
     2   INTEGER       2147483647
     Number of parameters passed to SIMPLE EXAMPLE is:  2
     1   SHORT INTEGER -32768
     2   SHORT INTEGER 32767
     Number of parameters passed to SIMPLE EXAMPLE is:  2
     1   Actual parameter to SIMPLE EXAMPLE has an invalid data type.
     2   Actual parameter to SIMPLE EXAMPLE must be a scalar.
     Number of parameters passed to SIMPLE EXAMPLE is:  1
     1   INTEGER       1000000
     Number of parameters passed to SIMPLE EXAMPLE is: 13
     1   SHORT INTEGER -32768
     2   INTEGER       0
     3   INTEGER       2147483647
     4   SHORT INTEGER 32767
     5   INTEGER       -2147483648
     6   SHORT INTEGER -32768
     7   INTEGER       -1
     8   INTEGER       1000000
     9   INTEGER       -2147450881
     10  Actual parameter to SIMPLE EXAMPLE has an invalid data type.
     11  Actual parameter to SIMPLE EXAMPLE has an invalid data type.
     12  Actual parameter to SIMPLE EXAMPLE has an invalid data type.
     13  Actual parameter to SIMPLE EXAMPLE must be a scalar.
     >



MPE/iX 5.0 Documentation