perm filename CALLER.2[EAL,HE]1 blob sn#676458 filedate 1982-09-27 generic text, type C, neo UTF8
COMMENT ⊗   VALID 00004 PAGES
C REC  PAGE   DESCRIPTION
C00001 00001
C00002 00002	{$NOMAIN	Overlay-transfer calls }
C00004 00003	{ External routines defined elsewhere: }
C00006 00004	procedure i1bPpReal(r: real)  external
C00013 ENDMK
C⊗;
{$NOMAIN	Overlay-transfer calls }

{ These are to be used when an overlay needs to call another overlay which
  occupies the same virtual address space; i.e. the called overlay will replace
  the calling overlay.  The calling overlay needs to be re-read into memory
  before control can be returned to it.  To accomplish this, a routine in CALLER
  is called, the called overlay is read in and executed, and control is returned
  to CALLER; the calling overlay is then restored and control returned to it.

  Notice that all the pointer-type definitions are faked.
}

type
  ascii = char; 

  statementp = ↑integer;
  pdbp = ↑integer;
  varidefp = ↑integer;
  enventryp = ↑integer;

  cstring = packed array [1..10] of ascii;
  c4str = packed array [1..4] of ascii;
  c5str = packed array [1..5] of ascii;
  c20str = packed array [1..20] of ascii;
  linestr = packed array [1..130] of ascii;


{ External routines defined elsewhere: }

	(* From PP *)
procedure ppReal(r: real); 					external;

	(* From IMAIN *)
procedure interp(dLev: integer);				external;

	(* From PMAIN *)
function Parse(fname: c20str; ppn: integer): statementp;	external;
function eStmntParse(var cblk,newDecs: statementp; 
	cproc: varidefp): statementp;				external;

	(* From EEDITS *)
procedure editStmnt;						external;

	(* From EADDST *)
procedure addStmnt(firstTime: boolean);				external;

	(* From EEXPED *)
function eReadLine(var l: linestr): integer;			external;

	(* From IAUX2A *)
procedure killVar(e: enventryp);				external;

	(* From IFLUSH *)
procedure flushAll(p: pdbp; dLev: integer);			external;


	(* Routines used to re-call overlays *)
procedure iAux1bGet;						external;
procedure pTokGet;						external;
procedure pAux1Get;						external;
procedure eAux2aGet;						external;
procedure eAux3aGet;						external;
procedure em1Get;						external;
procedure em3Get;						external;
procedure em4Get;						external;
procedure em6Get;						external;
procedure eDbgGet;						external;

procedure i1bPpReal(r: real);  external;
procedure i1bPpReal; 
  begin ppReal(r); iAux1bGet end;

function p1eReadLine(var l: linestr): integer; external;
function p1eReadLine;
  begin
  p1eReadLine := eReadLine(l);	{Go ahead and read the line.  This changes levels 1 & 2}
  pTokGet;			{Re-read PTOKEN since that called readLine}
  pAux1Get;			{and re-read PAUX1 since that called us}
  end;

procedure e2akillVar(e: enventryp); external;
procedure e2akillVar;
  begin killVar(e); eAux2aGet; end;


{ For e2aInterp, here is the chain of events that led to this call:
	Either edit (main part) or readProg calls setUpStmnt
	setUpStmnt calls initOuterBlock
	initOuterBlock calls Interp
  So when Interp exits, we need to re-call the appropriate overlays in
  each of the cotrees.  If the call was from edit, we only need to read
  back the main part of edit; but if the call was from readProg we need
  to reread the overlay containing readProg and the main part.  In order
  to know which of these two cases occurs, a parameter is passed to
  setUpStmnt which tells it who called it: 0 means the main program
  and 1 (or any nonzero) means readProg.
  We also need to reread EAUX2A so we can return to it.}
	
procedure e2aInterp(dLev,which: integer);	 external;
procedure e2aInterp;	
  begin 
  Interp(dLev); 	{Start by calling interpreter; let it do its thing}
  eAux2aGet; 		{Reread the level 2 overlay we'll be returning to}
  eAux3aGet;		{and the level 3 one that contains setUpStmnt}
  if which=0     	{Who called us?  If called by main program part}
    then em1Get 	  {then re-read the appropriate overlay}
    else em3Get;	  {readProg called us; it was called by EMAIN3}
  end;			{That ought to do it}


procedure e3aFlushAll(p: pdbp; dLev: integer); external;
procedure e3aFlushAll; 
  begin flushAll(p, dLev); eAux3aGet end;

function e3aParse(fname: c20str; ppn: integer): statementp; external;
function e3aParse; 
  begin 
  e3aParse := parse(fname,ppn); 	{Go ahead and parse it}
  eAux3aGet;				{Re-read the calling overlay}
  em3Get;				{readProg was called by EMAIN3}
  end;

procedure edbInterp(dLev,which: integer); external;
procedure edbInterp;
  begin 
  Interp(dLev); 		{Go and interpret it}
  eDbgGet;			{Re-read the EDEBUG overlay that called us}
  if which=3 then em3Get	{Now who called EDEBUG? It's one of the MAINn ones}
   else if which=4 then em4Get
   else if which=6 then em6Get
   else begin writeln('Interp: ',which:1); break(output) end;
  end;

procedure em6EditStmnt; external;
procedure em6EditStmnt;
begin editStmnt; em6Get end;

procedure emAddStmnt(firstTime: boolean; which: integer); external;
procedure emAddStmnt; 
  begin
  addStmnt(firstTime);		{Go ahead and call in EADDST and do it}
  if which=4 then em4Get	{Now re-read the right overlay}
   else if which=6 then em6Get	
   else begin writeln('Loss in emAdd: ',which:1); break(output) end;
  end;

function em4StmntParse(var cblk,newDecs: statementp; cproc: varidefp): statementp; external;
function em4StmntParse;
  begin 
  em4StmntParse := eStmntParse(cblk,newDecs,cproc);
  em4Get;		{EMAIN4 called us}
  end;