HP 3000 Manuals

Switch to NM Sequence [ Switch Programming User's Guide ] MPE/iX 5.0 Documentation


Switch Programming User's Guide

Switch to NM Sequence 

Examples 4-3 through 4-8 are a series of routines, intended to illustrate
the partial recompilation migration level, using a CM--> NM switch.

In these examples the target procedure migrates to Native Mode while the
calling routine remains in Compatibility Mode.

A possible reason for moving the target procedure to Native Mode is that
it has a feature that is no longer available on MPE XL and an attractive
alternative exists in the NM environment.  Example 4-3 is a Pascal/V
source with a procedure call to the PTAPE intrinsic (deleted on MPE XL).

Example 4-3.  Pascal/V Program Calling Routine With Deleted Featur 

     PROGRAM XAMPL43(input,output);

     TYPE
        pac37    = packed array [1..37] of char;
        logical  = 0..65535;
        shortint = -32768..32767;

     VAR
        fname1     : pac37;
        fname2     : pac37;
        filenum1   : shortint;
        filenum2   : shortint;
        foptions1  : logical;
        foptions2  : logical;
        aoptions1  : logical;
        aoptions2  : logical;
        recsize1   : shortint;
        recsize2   : shortint;
        dev1       : shortint;
        dev2       : shortint;

     function fopen : shortint; intrinsic;
     procedure ptape (fnum1, fnum2 : shortint); external;

     BEGIN
        fname1 := '$STDIN ';
        foptions1 := 0;
        aoptions1 := 0;
        recsize1 := 0;
        dev1 := 0;
        filenum1 := FOPEN(fname1, foptions1, aoptions1,
                          recsize1, dev1);
        writeln('fopen ',fname,'ccode is ',ccode);

        fname2 := 'XMPLA ';
        foptions2 := 0;
        aoptions2 := 0;
        recsize2 := 0;
        dev2 :=0;
        filenum2 := FOPEN(fname2, foptions2, aoptions2,
                          recsize2, dev2);
        writeln('fopen ',fname2,'ccode is ',ccode);

Example 4-3.  Pascal/V Program, continued 

        PTAPE(filenum1,filenum2);
        writeln('ptape result: ');
        case ccode of
           0 : writeln('CCE');
           1 : writeln('CCG');
           2 : writeln('CCL');
        end;
     END.

     {end Example 4-3}

Example 4-4 is an SPL procedure incorporating the call to the PTAPE
intrinsic.

Example 4-4.  SPL Procedure With Feature Deleted on MPE XL 

     $CONTROL USLINIT,SUBPROGRAM,SEGMENT=XAMPL43
     BEGIN
        EQUATE BASE = 10;
        DEFINE D'MININT = -214748256D#;
        EQUATE OFFSET = 48;
        EQUATE PLACES = 9;    << size of maxint, 32-bits >>

     INTRINSIC FREAD, FWRITE;

     PROCEDURE PTAPE(FILE1, FILE2);
        VALUE FILE1, FILE2;
        INTEGER FILE1, FILE2;
     << PTAPE replaces the deleted MPE/V intrinsic of the    >>
     << same name.  This routine transfers records from      >>
     << FILE1 to FILE2.                                      >>
     BEGIN
        INTEGER RECLEN, LEN;
        LOGICAL ARRAY BUFFER(1:256);
        RECLEN := 256;
        DO
           BEGIN
              LEN := FREAD(FILE1, BUFFER, RECLEN);
              IF = THEN FWRITE(FILE2, BUFFER, LEN, 0);
           END
        UNTIL <>;
     END;

     END.

     {end Example 4-4}

To replace the deleted feature, you may want to write your own NM
procedure.  Example 4-5 is an HP Pascal/XL procedure replacing the call
to the deleted PTAPE intrinsic with an MPE XL feature.  This procedure
will replace the SPL procedure.

Example 4-5.  Pascal/XL Procedure Replacing Deleted Feature 

     $standard_level 'ext_modcal'$
     $subprogram$

     PROGRAM XAMPL45 (input,output);

     TYPE
        pac256 = packed array [1..256] of char;

     FUNCTION FREAD : SHORTINT; INTRINSIC;
     PROCEDURE FWRITE; INTRINSIC;

     PROCEDURE PTAPE(FILE1, FILE2 : integer);

     { PTAPE replaces the deleted MPE/V intrinsic of the  }
     { same name.  This routine transfers records from    }
     { FILE1 to FILE2.                                    }

     VAR
        reclen : shortint;
        len : shortint;
        buffer : pac256;

     BEGIN
        reclen := 256;
        repeat
           begin
              len := FREAD(file1, buffer, reclen);
              if ccode = 2 then FWRITE(file2, buffer, len, 0);
           end
        until (ccode <> 2);
     END;

     begin
     end.

     {end Example 4-5}

It is advisable to test one thing at a time.  You can test the NM
replacement procedure separately from a Switch stub or in-line Switch
that calls the appropriate intrinsic to invoke the target.  Example 4-6
is an NM driver to test the HP Pascal/XL procedure.

Example 4-6.  NM Driver 

     $standard_level 'ext_modcal'$

     PROGRAM XAMPL46(input,output);

     TYPE
        pac37    = packed array [1..37] of char;
        logical  = 0..65535;

     VAR
        fname1     : pac37;
        fname2     : pac37;
        filenum1   : shortint;
        filenum2   : shortint;
        foptions1  : logical;
        foptions2  : logical;
        aoptions1  : logical;
        aoptions2  : logical;
        recsize1   : shortint;
        recsize2   : shortint;
        dev1       : shortint;
        dev2       : shortint;

     FUNCTION FOPEN : SHORTINT; INTRINSIC;

     PROCEDURE ptape (filenum1, filenum2 : shortint); external;

     BEGIN
        fname1 := '$STDIN ';
        foptions1 := 0;
        aoptions1 := 0;
        recsize1 := 0;
        dev1 := 0;
        filenum1 := FOPEN(fname1, foptions1, aoptions1,
                          recsize1, dev1);
        writeln('fopen ',fname1,'ccode is ',ccode);

        fname2 := 'PTAPE ';
        foptions2 := 0;
        aoptions2 := 0;
        recsize2 := 0;
        dev2 := 0;
        filenum2 := FOPEN(fname2, foptions2, aoptions2,
                          recsize2, dev2);
        writeln('fopen ',fname2,'ccode is ',ccode);

Example 4-6.  NM Driver, continued 

        ptape(filenum1,filenum2);
        writeln('ptape result: ');
        case ccode of
           0 : writeln('CCE');
           1 : writeln('CCG');
           2 : writeln('CCL');
        end;
     END.

     {end Example 4-6}

As it stands, the HP Pascal/XL procedure represents an unresolvable
external reference to the CM routine that must call it.  Again, you can
use either a Switch stub or an in-line Switch to enable the CM caller to
access the NM target.  Example 4-7 is a Pascal/V Switch stub enabling
access to the HP Pascal/XL procedure.

Example 4-7.  Pascal/V Switch Stub 

     $standard_level 'HP3000'$

     PROGRAM XAMPL47(input, output);

     TYPE
        shortint = -32768..32767;

     FUNCTION HPSWTONMNAME : integer; intrinsic;

     PROCEDURE ptape(file1, file2 : shortint);

     TYPE
        pac256 = packed array [1..256] of char;
        pac16 = packed array [1..16] of char;
        shr_ary32 = packed array [1..32] of shortint;

     VAR
        proc_name   : pac16;
        proc_len    : shortint;
        lib_name    : pac16;
        lib_len     : shortint;
        nparms      : shortint;
        arglist     : shr_ary32;
        argdesc     : shr_ary32;
        fct_type    : shortint;
        rtn_st      : integer;

Example 4-7.  Pascal/V Switch Stub, continued 

     BEGIN
        proc_name   := 'PTAPE           ';
        proc_len    := 5;
        lib_name    := 'SL              ';
        lib_len     := 2;

        nparms      := 2;

        arglist[1]  := file1;
        arglist[2]  := file2;

        argdesc[1]  := 02;          { 16-bit value }
        argdesc[2]  := 02;          { 16-bit value }
        fct_type     := 0;           {not a function }

        rtn_st := HPSWTONMNAME(proc_name, proc_len, lib_name,
                               lib_len, nparms, arglist,
                               argdesc, fct_type);
     END;

     BEGIN
     END.

     {end Example 4-7}

To compile the Switch stub in Example 4-7, use the :PASCAL command.  For
complete information, refer to the MPE XL Commands Reference Manual 
(32650-90003).

On the CM side, you must use the MPE Segmenter to put the stub into the
CM SL in place of the SPL target procedure.  Example 4-8 illustrates an
MPE Segmenter session to replace the SPL procedure with the Switch stub
in Example 4-7.

Example 4-8.  Segmenter Session 

     :SEGMENTER
     HP32050A.02.00 SEGMENTER/3000 (C) HEWLETT-PACKARD CO 1985
     -SL SL
     -LISTSL

     SL FILE SL.SWITCH.EXAMPLE

     SEGMENT   0 SWCMLIB         LENGTH  706

        ENTRY POINTS    CHECK CAL STT ADR
        PTAPE             3    C    1   13

        EXTERNALS       CHECK STT SEG
        FWRITE            0    13    ?
        FREAD             0    12    ?

     USED     4600(23.0)  AVAILABLE 2334200(11565.0)

     -PURGESL PTAPE
     -USL $OLDPASS
     -ADDSL PTAPE
     -EXIT

     END OF SUBSYSTEM

     :


MPE/iX 5.0 Documentation