BackbuttonPassing Parameters to Programs

If a program requires parameters then SegmentZero[S0ExecuteInfoV].ParamCountf (SegZero[6].[7:8]) specifies the number of parameters required.

The Compiler creates a description of the formal parameters in the Program Description, even if NOBINDINFO is set.

In EXTERNALREFERENCE of DOCTOR at 16321440, the Program Description is loaded from the codefile. The Program Description is a part of the BinderInfo, which is located by the descriptor at SegmentZero[S0SepCompileInfoV]. 

The BindInfo fields used by the MCP are described at 16273200.

		DEFINE % BINDINFO STRUCTURE
     	  % (SEE ALSO THE COMMENT AT THE FRONT OF SYMBOL/BINDER)
 		UCF    = [47: 8]#, % UNIVERSAL CLASS
    			UCCF = [45: 5]#, %   CLASS SUBFIELD
    			UCRF = [40: 1]#, %   REFERENCE/NAME (VERSUS VALUE) INDICATOR
  		SCF    = [39:20]#, % SUBCLASS
  		NF     = [19:20]#, % ADDITIONAL INFO (USUALLY LENGTH)
  		UCSCF  = [47:28]#, % COMBINED UC&SC
  		UCSCN(UC,SC,N)=(0 & UC UCF & SC SCF & N NF)#,
  		UCSC (UC,SC)  =UCSCN(UC,SC,0).UCSCF#;

This program receives 3 arrays with lower bounds, by reference.

		$ Set Level 2
		PROCEDURE P(A,B,C);
 		Array A,B,C[*];
 		Begin
 		End.

The parameter definition is located in the Program Description by UCSC(0,3).

Program Description

Attribute Value Comments
Address 3 Sector
Length 19 Words
Block Program False Words
ProcDir Address 0 Sector
ProcDir Length 0 Words

 [0] for 19 Words
 (   0) 120000000012 000000100001 05010101D7FF 000000200001 000000100002 
                                  |?????? ?????? ????P? ?????? ??????|
 (   5) 00000030000B 000000900001 000000000003 070000100002 000000F00001 
                                  |?????? ?????? ?????? ????? ???0??|
 (   10) 000000000001 070000100002 000000F00001 000000000001 070000100002 
                                  |?????? ????? ???0?? ?????? ?????|
 (   15) 000000F00001 000000000001 000001300001 00020000A003              
                                  |???0?? ?????? ?????? ??????|
   
 

[0] for 19 Words ( 0) 120000000012 000000100001 05010101D7FF 000000200001 000000100002 ( 5) 00000030000B 000000900001 000000000003 070000100002 000000F00001 ( 10) 000000000001 070000100002 000000F00001 000000000001 070000100002 ( 15) 000000F00001 000000000001 000001300001 00020000A003

The UCSC(0,9) keyword indicates there are 3 parameters.

Each parameter is a Real Array By Reference(070000100002), with Lower Bounds and  Dimensions(000000F00001) and 1 Dimension (000000000001).

In EXTERNALREFERENCE at 16328000 a call is made to PARAMETERCHECK.

PARAMETERCHECK is at 16451200. This is the same function which is called when a procedure is passed without being specified as FORMAL.

The MCP builds the parameters when the task is initiated. For example, see NORMALBOJ at 15888440.

The TASKPARAMS field of the PIB is used by the MCP for managing parameters. This comment is in the MCP at 15373080.

PIB[TASKPARAMS] IS USED VARIOUSLY ACCORDING TO THE PARAMETERS BEING SPECIFIED FOR THE TASK, THE MEANS OF THEIR SPECIFICATION, AND THE STAGES OF INITIALIZATION OF THE TASK:
  1. A ZERO OPERAND MEANS THERE ARE NO PARAMETERS.
  2. AN ORDINARY TASK INITIATION VIA DELIVERY/INITIATEUSERTASK NOTES THE DISPLACEMENT INTO THE PARENT STACK AND THE NUMBER OF WORDS OF PARAMETERS IN PARAMDISP AND PARAMWORDS OF AN OPERAND. SIMILAR ACTION IS TAKEN BY FORKCONTROLCARD FOR A ZIP.
  3. WITH A KLUDGE INSTALLED IN MARK 31.1, INITIATEUSERTASK NOTICES ARRAY PARAMETERS FROM WFL OR FROM MCS TO SESSION OR TO FOREIGN TASK AND BUILDS AN (MCP) OVERLAYABLE ARRAY IN TASKPARAMS TO PASS THE ARRAY BY VALUE. UNRAVEL RETURNS LENGTH AND TEXT OF THE ARRAY PARAMETER TO HOST SERVICES VIA AD-HOC ATTRIBUTES.
  4. SINCE MARK 31.1, THERE HAS BEEN A FIELD DEFINE (PARAMDESCLINK) AND SOME SKELETAL CODE IN INITIATEUSERTASK FOR AN UNIMPLEMENTED FEATURE: IF THE USER SPECIFIES PARAMETERS VIA MUTATE, TASKPARAMS BECOMES A MOM FOR AN (MCP) OVERLAYABLE ARRAY HOLDING HIS PARAMETER VALUES AND A BINDINFO-FORMAT DESCRIPTION OF HIS PARAMETERS. INITIATEUSERTASK AND/OR EXTERNALREFERENCE OF DOCTOR WILL CHECK THAT THE SUPPLIED PARAMETERS FIT THE CALLED PROCEDURE.
  5. IF A FORK INVOLVES PARAMETERS, THEY ARE COPIED INTO THE GETAREA MESSAGE ENQUEUED FOR ANABOLISM, WHO THEN USES THE SAME MEMORY TO BUILD A PARAMETER ARRAY WITH MOM AT TASKPARAMS.
  6. IF EXTERNALREFERENCE FINDS PARAMETERS ON THE STACK (STATE 2) AND THE PARAMETERS MISMATCH THE EXTERNAL PROCEDURE BUT CAN BE COERCED, A PARAMETER ARRAY (GETAREA) IS BUILT WITH COERCION INSTRUCTIONS IN THE PARAMETER SLOTS. THIS CASE IS DISTINGISHED FROM CASES 3-5 BY RETAINING NON-ZERO PARAMDISP IN PARAMINFO. (IF COERCEABLE MISMATCH IS FOUND FROM STATE 3 OR 4, THE EXISTING TASKPARAMS ARRAY IS ADJUSTED; NO NEW STATE ARISES.)
  7. THE FOLLOWING ACTIONS ARE TAKEN BY THE FIRST PART OF INITIATE (WHEN A STACK NUMBER HAS BEEN OBTAINED): IF TASKPARAMS CONTAINS A NON-ZERO PARAMDISP (STATE 2), TASKPARAMS IS CHANGED TO AN ARRAY (GETAREA) AND THE PARAMETERS ARE COPIED INTO IT FROM THE PARENT STACK. IF TASKPARAMS IS AN ARRAY AND THE PARAMINFO WORD HAS NON-ZERO PARAMDISP (STATE 6), THE PARAMETERS ARE COPIED FROM THE STACK INTO THE ARRAY, WITH ANY REQUIRED ADJUSTMENTS. IF THERE ARE COPY-DESCRIPTOR PARAMETERS IN THE PARAMETER ARRAY, A COPY OF THE TASKPARAMS DESCRIPTOR IS PUT IN THE NEW STACKVECTOR SLOT FOR SEARCHING.
  8. AFTER THE SECOND PART OF INITIATE HAS ACQUIRED STACK SPACE, THE APPROPRIATE WORDS ARE COPIED INTO THE NEW STACK BEING BUILT. UNLESS THERE ARE ARRAYS BY VALUE, THE PARAMETER ARRAY IS DISCARDED AND PARAMINFO SAVED IN TASKPARAMS (FOR STATE 10). IF ANY ARRAY IS BEING PASSED BY VALUE, AN EXTRA BLOCK IS PUT INTO THE NEW STACK BETWEEN THE USER OUTER BLOCK AND THAT OF EOJ, TO HOLD THE MOM(S).
  9. IF THERE IS STILL AN ARRAY AT BOJ TIME, NORMALBOJ SETS UP MOM DESCRIPTORS FOR ANY ARRAYS BEING PASSED BY VALUE AND COPIES THEIR CONTENTS FROM THE TASKPARAMS ARRAY. THE PARAMETER ARRAY IS THEN DISCARDED AND PARAMINFO SAVED IN TASKPARAMS.
  10. BY THE TIME THE USER PROGRAM IS ENTERED, TASKPARAMS IS AN OPERAND CONTAINING PARAMWORDS AND PARAMBLOCK.

For a normal procedure or function at Lex Level 2, the MCP builds the parameters and calls the program's entrypoint, by EXIT from NORMALBOJ.

For an Algol procedure or function at Lex Level 3, the compiler constructs a Lex Level 2 Driver procedure which is entered by the MCP and which calls the Lex Level 3 procedure or function.

In the Algol Compiler, the DRIVER function is at 73211000,

 REAL PROCEDURE DRIVER;                                             
 BEGIN                                                                  
    % THIS PROCEDURE BUILDS A JACKET CODE SEGMENT AT LEX LEVEL 2 TO  
    % BUILD THE STACK FOR AND TO CALL A STAND-ALONE PROCEDURE PROGRAM. 
    % RESULT IS THE VALUE FOR SHEET[6].                          

The Algol compiler creates an overlapping D[2] environment.

The generated Driver procedure is a Lex Level 2 pseudo outer block, which defines a virtual environment which consists of the D[3] PCW for the actual program code at (2,2). A recursive call on the procedure P generates a NAMC on (2,2).

The Program Description describes a program with the given parameters, and a D[2] environment is built by the MCP to match the parameters as described in the Program Description.

The compiler knows that the MCP will build such an environment, and then be entered  by an EXIT into the program code.

The generated Driver procedure which is entered, adds a PCW and SCW to the end of the environment, performs a MKSN on the D[3] code, builds the parameter references, and then just before doing the ENTR, it overwrites the parameter at (2,2) with a copy of the PCW for the D[3] code, so that any recursive call will work. Since the parameter reference has already been generated, there is no conflict overlapping the environments.

This code was generated by the Algol Compiler for the program above,

$ SET LEVEL 3
PROCEDURE P(A,B,C);                                                          
(02,0002) = P
                 Array a,b,c[*];                                                      
(03,0002) = A     
(03,0004) = B     
(03,0006) = C     
                    0004:0000:0  NVLD               FF 
                    0004:0000:1 MKSN               DF 
                    0004:0000:2  NAMC  (02,0008)    5008     
                    0004:0000:4  NAMC  (02,0002)    5002     
                    0004:0001:0  LOAD               BD 
                    0004:0001:1  NAMC  (02,0003)    5003     
                    0004:0001:3  LOAD               BD 
                    0004:0001:4  NAMC  (02,0004)    5004     
                    0004:0002:0  LOAD               BD 
                    0004:0002:1  NAMC  (02,0005)    5005     
                    0004:0002:3  LOAD               BD 
                    0004:0002:4  NAMC  (02,0006)    5006     
                    0004:0003:0  LOAD               BD 
                    0004:0003:1  NAMC  (02,0007)    5007     
                    0004:0003:3  LOAD               BD 
                    0004:0003:4  NAMC  (02,0008)    5008    Fix the PCW at (2,2) 
                    0004:0004:0  LODT               BC 
                    0004:0004:1  NAMC  (02,0002)    5002     
                    0004:0004:3  OVRD               BA 
                    0004:0004:4  ENTR               AB 
(01,0005) = BLOCKEXIT   
                    0004:0004:5  MKSN               DF 
                    0004:0005:0  NAMC  (01,0005)    6005  BLOCKEXIT
                    0004:0005:2  ENTR               AB 
                    0004:0005:3  EXIT               A3 
--ENTRYPOINT---->  0004:0005:4  MPCW               BF 
                    0004:0006         0002:0001:5   000A0010E002   
                    0004:0007:0  PUSH               B4 
                    0004:0007:1  LT16  2048         B30800   
                    0004:0007:4  BSET  47           962F     
                    0004:0008:0  LT8   6            B206     
                    0004:0008:2  STAG               95B4     
                    0004:0008:4  BRUN      0000:1   A22000   

This is the corresponding stack structure.

0030 (03,0008)  6 800000 000000  SCW: Blockexit marker
002F (03,0007)  0 000000 000000     
002E (03,0006)  C D00000 001D18  C (Real array)   Present-copy, 
                                    ASD=00E8C6, Length=1 (Mom @ 001A in this stack)    
002D (03,0005)  0 000000 000000     
002C (03,0004)  C 300000 001D12  B (Real array)   Present-copy,
                                   ASD=00E891, Length=1 (Mom @ 0019 in this stack)    
002B (03,0003)  0 000000 000000     
002A (03,0002)  C 500000 001CC8  A (Real array)   Present-copy,
                                    ASD=00E642, Length=1 
				     (Mom @ [632,24] via offset 000B in the MCP)
0029            7 000095 201D2E  RCW:  ASD=00E970, LL=2, Normal state        
                                       [User segment @ 0004:0004:5]   
                      Segment Descriptor:  C 080000 001D2E   
                      Code:  3 BD5003 BD5004  3 BD5005 BD5006  3 BD5007 BD5008 >3 
					BC5002 BAABDF< 3 6005AB A3BFFF   
0028 -----D[3]=>3 027800 1D0000 *ENVW: D[2] @ 001D in this stack  
0027            1 027800 1C0000 *HISW: Previous HISW @ 001C 

0026 (02,0009)  6 800000 000800  SCW: Blockexit marker: Single-dim Arrays     
0025 (02,0008)  7 000034 301CC8  PCW:  ASD=00E640, LL=3, Segment @ 0002:0001:5, 
                                 Normal state    
0024 (02,0007)  0 000000 000000     
0023 (02,0006)  C D00000 001D18  Desc: Present-copy, ASD=00E8C6, Length=1 
                                 (Mom @ 001A in this stack)  
0022 (02,0005)  0 000000 000000     
0021 (02,0004)  C 300000 001D12  Desc: Present-copy, ASD=00E891, Length=1 
                                (Mom @ 0019 in this stack)  
0020 (02,0003)  0 000000 000000     
001F (02,0002)  7 000034 301CC8  PCW:  ASD=00E640, LL=3, 
                                 Segment @ 0002:0001:5, Normal state    
001E            7 800000 10024B  RCW:  ASD=00125C, LL=1, Normal state 
                                 [MCP segment @ 1060:0000:0 (24507164)]     
                                 Segment Descriptor:  C 880000 00024B   
                                 Code: >3 DF4054 ABA3FF< 3 B1B0B4 200295
001D ---D[2]=>3 027900 070000 *ENVW: D[1] @ 0007 in Segment Dictionary (Stack 0279)     
001C            1 027800 150000 *HISW: Previous HISW @ 0015 

001B (01,0005)  6 800000 000800  SCW: Blockexit marker: Single-dim Arrays     
001A (01,0004)  C C00000 001D18  Desc: Present-mom, ASD=00E8C6, Length=1
        0(0000) 0 C30000 000000                     /C             /    
0019 (01,0003)  C 200000 001D12  Desc: Present-mom, ASD=00E891, Length=1
        0(0000) 0 C20000 000000                     /B             /    
0018 (01,0002)  C 400000 001CC8  Desc: Present-mom, ASD=00E642, Length=1
        0(0000) 0 C10000 000000                     /A             /    
0017            7 415336 20024E  RCW:  ASD=001272, LL=2,
									
		Control state [MCP segment @ 11A6:0A99:5 (16007760)]
		Segment Descriptor:  C 480000 00024E   
		Code:  3 BD9E16 B8B5FE  3 DF4313 ABDF43  3 C61002 B205AB >3 
		DF4312 ABA3B2< 3 34B202 95B8B1   
0016 -----D[1]=>3 001200 090000 *ENVW: D[0] @ 0009 in the MCP     
0015            1 027800 120000 *HISW: Previous HISW @ 0012 

0014            7 000000 002000  RCW:  Dummy (Run)    
0013 -----D[2]=>3 80E6AE 000000 *ENVW: D[1] @ word 00 of PIB @ ASD 00E6AE     
0000 = BOSR  (Absolute memory address = 003763FD)