perm filename IOV3.2[EAL,HE]1 blob sn#677501 filedate 1982-09-27 generic text, type C, neo UTF8
C00001 00001
C00002 00002	{$NOMAIN	Individual statement interpreters }
C00026 00003	{ Externally defined routines: }
C00029 00004	procedure doEnable external
C00030 00005	procedure doDisable external
C00032 00006	procedure doAffix external
C00038 00007	procedure doUnfix external
C00045 ENDMK
{$NOMAIN	Individual statement interpreters }

  (* Constants from EDIT *)
  maxLines = 28;          (* smaller on the 11 than on the 10 *)
  maxPPLines = 18;
  maxBpts = 25;
  maxTBpts = 20;  (* max could be exceeded by huge case stmnt *)
  listinglength = 2000;   (* Length of Listingarray *)

(* Random type declarations for OMSI/SAIL compatibility *)


  byte = 0..255;	(* doesn't really belong here, but... *)
  ascii = char; 
  atext = text;

{ Define all the pointer types here }

vectorp = ↑vector;
transp = ↑trans;
strngp = ↑strng;
eventp = ↑event;
framep = ↑frame;
varidefp = ↑varidef;
nodep = ↑node;
identp = ↑ident;
pdbp = ↑pdb;
statementp = ↑statement;
envheaderp = ↑envheader;
enventryp = ↑enventry;
environp = ↑environment;
cmoncbp = ↑cmoncb;

dump = ↑integer;
token = array[1..4] of integer;
cursorp = array[1..4] of integer;

(* datatype definitions *)

datatypes = (pconstype, varitype, svaltype, vectype, rottype, transtype,
	     frametype, eventtype, strngtype, labeltype, proctype, arraytype,
	     reftype, valtype, cmontype, nulltype, undeftype,
	     dimensiontype, mactype, macargtype, freevartype);

scalar = real;

u = (used,free);
vector = record case u of
	   used: (refcnt: integer; val: array [1..3] of real);
	   free: (next: vectorp);

trans = record case u of
	   used: (refcnt: integer; val: array [1..3,1..4] of real);
	   free: (next: transp);

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;

strng = record
	  next: strngp;
	  ch: cstring;

event = record
	  next: eventp;		(* all events are on one big list *)
	  count: integer;
	  waitlist: pdbp;

frame = record
	  vari: varidefp;	(* back pointer to variable name & info *)
	  calcs: nodep;		(* affixment info *)
	  case ftype: boolean of	(* frame = true, device = false *)
  true:	    (valid: integer; val, fdepr: transp; dcntr: integer; dev: framep);
  false:    (mech: integer; case sdev: boolean of
		true: (sdest: real); false: (tdest,appr,depr: transp));
		(* sdev = true for scalar devices, false for frames *)

(* statement definitions *)

stmntypes = (progtype, blocktype, coblocktype, endtype, coendtype,
		fortype, iftype, whiletype, untiltype, casetype,
		calltype, returntype,
		printtype, prompttype, pausetype, aborttype, assigntype,
		signaltype, waittype, enabletype, disabletype, cmtype,
		affixtype, unfixtype,
		movetype, operatetype, opentype, closetype, centertype,
		stoptype, retrytype,
		requiretype, definetype, macrotype, commenttype, dimdeftype,
		setbasetype, wristtype, tovaltype, declaretype, emptytype);
		(* more??? *)

statement = packed record
		next, last: statementp; (* ↑ to lexical tokens? *)
		stlab: varidefp;
		exprs: nodep;	(* any expressions used by this statement *)
		nlines: integer;
		bpt: boolean;
		case stype: stmntypes of

    unfixtype:	    (frame1, frame2, byvar, atexp: nodep; rigid: boolean);
    disabletype:    (cmonlab: varidefp);
    cmtype:	    (oncond: nodep; conclusion: statementp;
			deferCm, exprCm: boolean; cdef: varidefp);

(* auxiliary definitions: variable, etc. *)

varidef = packed record
	    next,dnext: varidefp;
	    name: dump;
	    level: 0..255;	(* environment level *)
	    offset: 0..255;	(* environment offset *)
	    dtype: varidefp;	(* to hold the dimension info *)
	    tbits: 0..15;  (* special type bits: array = 1, proc = 2, ref = 4 & ? *)
	    dbits: 0..15;	(* for use by debugger/interpreter *)
	    case vtype: datatypes of
  arraytype:  (a: nodep);
  proctype:   (p: nodep);
  cmontype:   (s: statementp);
  mactype:    (mdef: dump);
  macargtype: (marg: dump);
  pconstype:  (c: nodep);
  dimensiontype: (dim: nodep);

(* definition of the ubiquitous NODE record *)

nodetypes = (exprnode, leafnode, listnode, clistnode, colistnode, forvalnode,
		deprnode, viaptnode, apprnode, destnode, durnode,
		sfacnode, wobblenode, swtnode, nullingnode, wristnode, cwnode,
		arrivalnode, departingnode,
		ffnode, forcenode, stiffnode, gathernode, cmonnode, errornode,
		calcnode, arraydefnode, bnddefnode, bndvalnode,
		waitlistnode, procdefnode, tlistnode, dimnode, commentnode);

exprtypes =  (	svalop,					(* scalar operators *)
		sltop, sleop, seqop, sgeop, sgtop, sneop,	(* relations *)
		notop, orop, xorop, andop, eqvop,		(* logical *)
		saddop, ssubop, smulop, sdivop, snegop, sabsop, (* scalar ops *)
		sexpop, maxop, minop, intop, idivop, modop,
		sqrtop, logop, expop, timeop,			(* functions *)
		sinop, cosop, tanop, asinop, acosop, atan2op,	(* trig *)
		vdotop, vmagnop, tmagnop,
		vecop,					(* vector operators *)
		vmakeop, unitvop, vaddop, vsubop, crossvop, vnegop,
		svmulop, vsmulop, vsdivop, tvmulop, wrtop,
		tposop, taxisop,
		transop,				(* trans operators *)
		tmakeop, torientop, ttmulop, tvaddop, tvsubop, tinvrtop,
		vsaxwrop, constrop, ftofop, deproachop, fmakeop, vmkfrcop,
		ioop,					(* i/o operators *)
		queryop, inscalarop,
		specop,					(* special operators *)
		arefop, callop, grinchop, macroop, vmop, adcop, dacop,
		addop, subop, negop, mulop, divop, absop); (* for parsing *)

leaftypes = pconstype..strngtype;

reltypes = sltop..sgtop;
forcetypes = (force,absforce,torque,abstorque,angvelocity);

node = record
	next: nodep;
	case ntype: nodetypes of
    exprnode:	(op: exprtypes; arg1, arg2, arg3: nodep; elength: integer);
    leafnode:	(case ltype: leaftypes of
	varitype:  (vari: varidefp; vid: identp);
	pconstype: (cname: varidefp; pcval: nodep);
	svaltype:  (s: scalar; wid: integer);
	vectype:   (v: vectorp);
	transtype: (t: transp);
	strngtype: (length: integer; str: strngp) ); (* also used by commentnodes *)
    listnode:	(lval: nodep);
    clistnode:	(cval: integer; stmnt: dump; clast: nodep);
    colistnode:	(prev: nodep; cstmnt: dump);
    forvalnode:	(fvar: enventryp; fstep: scalar);
    arrivalnode:(evar: varidefp);
    destnode:	(loc: nodep; code: dump);
    viaptnode:	(vlist: boolean; via,duration,velocity: nodep; vcode: dump);
    durnode:	(durrel: reltypes; durval: nodep);
    swtnode:	(clval: nodep);
    cwnode:	(notp: boolean); (* true = nonulling/zero wrist/counter_clockwise *)
    ffnode:	(ff: nodep; csys, pdef: boolean); (* true = world, false = hand *)
    forcenode:	(ftype: forcetypes; frel: reltypes; fval, fvec, fframe: nodep);
    stiffnode:	(fv, mv, coc: nodep);
    gathernode:	(gbits: integer);
    cmonnode:	(cmon: dump; errhandlerp: boolean);
    errornode:	(eexpr: nodep);
    calcnode: 	(rigid, frame1: boolean; other: framep; case tvarp: boolean of 
		    false: (tval: transp); true: (tvar: enventryp) );
    arraydefnode: (numdims: 1..10; bounds: nodep; combnds: boolean);
    bnddefnode:	(lower, upper: nodep);
    bndvalnode:	(lb, ub, mult: integer);
    waitlistnode: (who: pdbp; when: integer);
    procdefnode:(ptype: datatypes; level: 0..255;
		    pname, paramlist: varidefp; body: dump);
    tlistnode:	(tok: dump);
    dimnode:	(time, distance, angle, dforce: integer);

ident = record
	    next: identp;
	    length: integer;
	    name: strngp;
	    predefined: varidefp;

(* process descriptor blocks & environment record definitions *)

queuetypes = (nullqueue,nowrunning,runqueue,inputqueue,eventqueue,sleepqueue,

pdb = packed record
	nextpdb,next: pdbp;	(* for list of all/active pdb's *)
	level: 0..255;		(* lexical level *)
	mode: 0..255;		(* expression/statement/sub-statement *)
	priority: 0..255;
	status: queuetypes;	(* what are we doing *)
	env: envheaderp;
	spc: statementp;	(* current statement *)
	epc: nodep;		(* current expression (if any) *)
	sp: nodep;		(* intermediate value stack *)
	cm: cmoncbp;		(* if we're a cmon point to our definition *)
	mech: framep;		(* current device being used *)
	linenum: integer;	(* used by editor/debugger *)
	 case procp: boolean of	(* true if we're a procedure *)
true:  (opdb: pdbp;		(* pdb to restore when procedure exits *)
	pdef: nodep);		(* procedure definition node *)
false: (evt: eventp;		(* event to signal when process goes away *)
	sdef: dump);	(* first statement where process was defined *)

envheader = packed record
	      parent: envheaderp;
	      env: array [0..4] of environp;
	      varcnt: 0..255;		(* # of variables in use ??? *)
		case procp: boolean of  (* true if we're a procedure *)
	true: (proc: nodep);
	false:(block: dump);

enventry = record
	    case etype: datatypes of
  svaltype:  (s: scalar);
  vectype:   (v: vectorp);
  transtype: (t: transp);
  frametype: (f: framep);
  eventtype: (evt: eventp);
  strngtype: (length: integer; str: strngp);
  cmontype:  (c: cmoncbp);
  proctype:  (p: nodep; penv: envheaderp);
  reftype:   (r: enventryp);
  arraytype: (a: envheaderp; bnds: nodep);

environment = record
		next: environp;
		vals: array [0..9] of enventryp;

cmoncb = record
	   running, enabled: boolean;		(* cmon's status *)
	   cmon: dump;
	   pdb: pdbp;
	   evt: eventp;
	   fbits: integer;			(* bits for force sensing *)
	   oldcmon: cmoncbp;			(* for debugger *)

(* Global variables *)

	(* From ALMAIN *)
    ltime: real;

	(* From PARSE *)
    reswords: array [0..26] of dump;
    idents: array [0..26] of dump;
    macrostack: array [1..10] of dump;
    curmacstack: array [1..10] of varidefp;
    macrodepth: integer;
    curchar, maxchar, curline: integer;
    curBlock,newDeclarations: dump;
    curProc: varidefp;
    pnode: nodep;
    nodim, distancedim, timedim, angledim,
      forcedim, torquedim, veldim, angveldim: varidefp;
    fvstiffdim, mvstiffdim: nodep;
    filedepth: integer;
    curpage: integer;
    sysVars,unVars: varidefp;
    errcount: integer;
    outerBlock: dump;
    curVariable: varidefp;
    curMotion: dump;
    endOk,coendOk: integer;
    moveLevel: integer;
    curErrhandler, curCmon: dump;
    endOfLine, backup, expandmacros, flushcomments, dimCheck: boolean;
    semiseen, shownline: boolean;
    eofError: boolean;
    inMove,inCoblock: boolean;
    curtoken: token;	
    file1,file2,file3,file4,file5: atext;
    line: linestr;

	(* From INTERP *)
    curInt, activeInts, readQueue, allPdbs: pdbp;
    curEnv, sysEnv: envheaderp;
    clkQueue: nodep;
    allEvents: eventp;
    STLevel: integer;		(* set by GO *)
    etime: integer;		(* used by eval *)
    curtime: integer; 		(* Time of day, in ticks *)
    stime: integer;		(* used for clock queue on 10 *)
    msg: dump;			(* for AL-ARM interaction *)
    inputp: integer;		(* current offset into inputLine array above *)
    debugLevel: integer;
    tSingleThreadMode: boolean;
    resched, running, escapeI, singleThreadMode: boolean;
    msgp: boolean;		(* flag set if any messages pending *)
    inputReady: boolean;
    inputLine: array [1..20] of ascii;

	(* From EDIT *)
    lines: array [1..maxLines] of dump; 
    ppLines: array [1..maxPPLines] of dump;	
    marks: array [1..20] of integer;
    cursorStack: array [1..15] of cursorp;
    bpts: array [1..maxBpts] of dump;
    tbpts: array [1..maxTBpts] of dump;
    debugPdbs: array [0..10] of pdbp;
    screenheight,dispHeight: integer;
    ppBufp,oppBufp,ppOffset,ppSize,nmarks: integer;
    lbufp,cursor,ocur,cursorLine,fieldnum,lineNum,findLine,pcLine: integer;
    firstDline,topDline,botDline,firstLine,lastLine: integer;
    freeLines,oldLines: dump;
    findStmnt: dump;
    nbpts,ntbpts: integer;
    eCurInt: pdbp;
    dProg: dump;
    smartTerminal: boolean; 
    setUp,setExpr,setCursor,dontPrint,outFilep,newVarOk,collect: boolean;
    eBackup: boolean;			
    eSingleThreadMode: boolean;	
    listing: packed array [0..listinglength] of ascii;
    lbuf: array [1..160] of ascii;
    ppBuf: array [1..100] of ascii;
    outFile: atext;
    eCurToken: token;				

	(* Various device & variable pointers *)
    speedfactor: enventryp;
    barm: framep;

	(* Various constant pointers *)
    xhat,yhat,zhat,nilvect: vectorp;
    niltrans: transp;
    bpark, ypark, gpark, rpark: transp;		(* arm park positions *)

{ Externally defined routines: }

	(* From ALLOC *)
function newNode: nodep;					external;
procedure relNode(n: nodep);					external;

	(* From IAUX1A *)
function getVar (level, offset: byte): enventryp;		external;
function pop: nodep;						external;
procedure upTrans (var t: transp; tp: transp);			external;
function gtVarn (n: nodep): enventryp;				external;
function feval (f: framep): transp;				external;

	(* From IAUX1B *)
procedure sleep(whenV: integer);				external;
procedure cmonDisable(c: cmoncbp);				external;

	(* From IAUX2A *)
procedure affixaux (f, d: framep; cnt: integer);		external;
function unfixaux (f: framep; cnt: integer): boolean;		external;
procedure unfix (f1,f2: framep);				external;

	(* From IAUX2B *)
procedure cmonEnable(e: enventryp);				external;

	(* Arithmetic Routines *)
function ttmul (t1,t2: transp): transp; 			external;
function tinvrt (t: transp): transp; 				external;

	(* Display-related Routines *)
procedure ppLine; 						external;
procedure ppOutNow; 						external;
procedure ppChar(ch: ascii); 					external;
procedure pp5(ch: c5str; length: integer); 			external;
procedure pp10(ch: cstring; length: integer); 			external;
procedure pp10L(ch: cstring; length: integer);			external;
procedure pp20(ch: c20str; length: integer); 			external;
procedure pp20L(ch: c20str; length: integer); 			external;
procedure ppInt(i: integer); 					external;
procedure ppReal(r: real); 					external;
procedure ppStrng(length: integer; s: strngp); 			external;

procedure doEnable; external;
procedure doEnable;
 with curInt↑ do
  if spc↑.cmonlab = nil then
    if cm <> nil then cm↑.enabled := true	(* re-enabling this cmon *)
      pp20L('No cmon to enable!  ',18); ppLine;
    with spc↑.cmonlab↑.s↑.cdef↑ do
     cmonEnable(getVar(level,offset));		(* enable cmon control block *)
  mode := 0;
  spc := spc↑.next;

procedure doDisable; external;
procedure doDisable;
 var e: enventryp;
 with curInt↑ do
  if spc↑.cmonlab = nil then
    if cm <> nil then cm↑.enabled := false	(* disabling this cmon *)
      pp20L('No cmon to disable! ',19); ppLine;
    with spc↑.cmonlab↑.s↑.cdef↑ do
     e := getVar(level,offset);		(* get cmon control block *)
    if e↑.c↑.running then sleep(30)	(* if running wait for it to finish *)
      cmonDisable(e↑.c);			(* disable it *)
      mode := 0;
      spc := spc↑.next;

procedure doAffix; external;
procedure doAffix;
 var f1, f2: framep; ev: enventryp; c1, c2: nodep; t: transp; b: boolean;
 with curInt↑ do
  begin   (* stack has subscripts for frame1, frame2 & byvar & atexp value *)
  ev := gtVarn(spc↑.frame1);	(* access variable *)
  f1 := ev↑.f;
  ev := gtVarn(spc↑.frame2);	(* access variable *)
  f2 := ev↑.f;
  if spc↑.byvar <> nil then
    ev := gtVarn(spc↑.byvar)	(* access variable *)
   else ev := nil;
  if spc↑.atexp <> nil then
    c1 := pop;			(* get at expression value *)
    t := c1↑.t;			(* save it for later *)
    relNode(c1);		(* release node *)
   else t := ttmul(feval(f1),tinvrt(feval(f2)));	(* need to compute it *)
  c1 := f1↑.calcs;		(* see if frames are already affixed *)
  b := true;
  while b and (c1 <> nil) do
    if c1↑.other = f2 then b := false else c1 := c1↑.next;
  if c1 <> nil then		(* currently affixed *)
    c2 := f2↑.calcs;		(* find its mate *)
    while c2↑.other <> f1 do c2 := c2↑.next;
    if (not c1↑.tvarp) and (spc↑.byvar <> nil) then
      begin	    (* if old affixment was direct and new one isn't *)
      upTrans(c1↑.tval,nil);   (* release old trans values *)
    begin				(* get a pair of calc nodes *)
    c1 := newNode;
    c2 := newNode;
    c1↑.ntype := calcnode;		(* indicate that we're a calc *)
    c2↑.ntype := calcnode;
    c1↑.other := f2;			(* fill in other field *)
    c2↑.other := f1;
    c1↑.next := f1↑.calcs;		(* link us to list of calcs *)
    f1↑.calcs := c1;
    c2↑.next := f2↑.calcs;
    f2↑.calcs := c2;
    c1↑.tval := nil;			(* don't have a value yet *)
    c2↑.tval := nil;
  c1↑.frame1 := true;			(* say who's who *)
  c2↑.frame1 := false;
  c1↑.rigid := spc↑.rigid;		(* remember what type of affixment *)
  c2↑.rigid := spc↑.rigid;
  b := ev <> nil;			(* trans by var given? *)
  c1↑.tvarp := b;
  c2↑.tvarp := b;
  if b then
    begin				(* indirect trans pointer *)
    upTrans(ev↑.t,t);			(* store away relation trans *)
    c1↑.tvar := ev;			(* and pointers to trans var *)
    c2↑.tvar := ev;
    begin				(* direct trans *)
    upTrans(c1↑.tval,t);		(* store away relation trans *)
  b := false;				(* assume no conflict *)
  if not f1↑.ftype then			(* f1 is a device *)
    if not f2↑.ftype then b := f1 <> f2	  (* f2 is also a device! *)
      if f2↑.dev <> nil then b := f2↑.dev <> f1	(* f2 already dynamic *)
       else affixaux(f2,f1,1)			 (* f2 now dynamic *)
   else					(* f1 is a frame *)
    if not f2↑.ftype then		  (* f2 is a device *)
      if f1↑.dev <> nil then b := f1↑.dev <> f2	(* f1 already dynamic *)
       else affixaux(f1,f2,1)			  (* f1 now dynamic *)
     else					(* both frames *)
      if f1↑.dev <> nil then			  (* f1 is dynamic *)
	if f2↑.dev <> nil then b := f1↑.dev <> f2↑.dev (* both dynamic *)
	 else affixaux(f2,f1↑.dev,f1↑.dcntr+1)		(* f2 now dynamic *)
	 if f2↑.dev <> nil then affixaux(f1,f2↑.dev,f2↑.dcntr+1); (* f1 now dynamic *)
  if b then
    pp20L('Can''t have an affixm',20); pp20('ent chain connecting',20);
    pp20(' two devices togethe',20); pp5('r!   ',2); ppLine;
  mode := 0;
  spc := spc↑.next;

procedure doUnfix; external;
procedure doUnfix;
 var f1, f2: framep; ev: enventryp;
 with curInt↑ do
  begin	(* subscripts for frame1 & frame2 on stack *)
  ev := gtVarn(spc↑.frame1);	(* access variable *)
  f1 := ev↑.f;
  ev := gtVarn(spc↑.frame2);	(* access variable *)
  f2 := ev↑.f;
  unfix(f1,f2);			(* now unfix them *)
  mode := 0;
  spc := spc↑.next;