perm filename EAUX1C.2[EAL,HE] blob
sn#714827 filedate 1983-06-06 generic text, type C, neo UTF8
COMMENT ⊗ VALID 00006 PAGES
C REC PAGE DESCRIPTION
C00001 00001
C00002 00002 {$NOMAIN Editor auxilliary routines }
C00027 00003 { Externally defined routines from elsewhere: }
C00029 00004 (* routine to show where error occurred: errprnt *)
C00031 00005 (* auxiliary expression mungers: relExpr & evalOrder, ppFlush *)
C00041 00006 (* aux routines for dimension checking: matchdim, getdim *)
C00048 ENDMK
C⊗;
{$NOMAIN Editor auxilliary routines }
(* definition of record types & global variables used by AL *)
const
maxLines = 28;
maxPPLines = 18;
maxBpts = 25;
maxTBpts = 20; (* max could be exceeded by huge case stmnt *)
listinglength = 2000; (* Length of Listingarray *)
type
(* random type declarations for OMSI/SAIL compatibility *)
ascii = char;
atext = text;
byte = 0..255;
(* Here are all the pointer-type definitions. Since the various *)
(* records reference each other so much, we have to put them all here. *)
vectorp = ↑vector;
transp = ↑trans;
strngp = ↑strng;
eventp = ↑event;
framep = ↑frame;
statementp = ↑statement;
varidefp = ↑varidef;
nodep = ↑node;
identp = ↑ident;
tokenp = ↑token;
reswordp = ↑resword;
pdbp = ↑pdb;
envheaderp = ↑envheader;
enventryp = ↑enventry;
environp = ↑environment;
cmoncbp = ↑cmoncb;
messagep = ↑message;
linerecp = ↑linerec;
(* 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;
vector = record refcnt: integer; val: array [1..3] of real end;
trans = record refcnt: integer; val: array [1..3,1..4] of real end;
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;
end;
event = record
next: eventp; (* all events are on one big list *)
count: integer;
waitlist: pdbp;
end;
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 *)
end;
(* 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,jtmovetype,operatetype,opentype,closetype,centertype,
floattype, stoptype, retrytype,
requiretype, definetype, macrotype, commenttype, dimdeftype,
setbasetype, wristtype, saytype, declaretype, emptytype,
evaltype, armmagictype);
(* more??? *)
statement = packed record
next, last: statementp;
stlab: varidefp;
exprs: nodep; (* any expressions used by this statement *)
nlines: integer;
bpt,bad: boolean;
case stype: stmntypes of
progtype: (pcode: statementp; errors: integer);
blocktype,
declaretype,
endtype,
coendtype: (bcode, bparent: statementp; blkid: identp;
level, numvars: 0..255; variables: varidefp);
coblocktype: (threads: nodep; nthreads: integer; cblkid: identp);
signaltype,
waittype: (event: nodep);
end;
(* auxiliary definitions: variable, etc. *)
varidef = packed record
next,dnext: varidefp;
name: identp;
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);
labeltype,
cmontype: (s: statementp);
mactype: (mdef: statementp);
macargtype: (marg: tokenp);
pconstype: (c: nodep);
dimensiontype: (dim: nodep);
end;
(* definition of the ubiquitous NODE record *)
nodetypes = (exprnode, leafnode, listnode, clistnode, colistnode, forvalnode,
deprnode, viaptnode, apprnode, destnode, byptnode, durnode,
sfacnode, wobblenode, swtnode, nullingnode, wristnode, cwnode,
arrivalnode, departingnode,
ffnode, forcenode, stiffnode, gathernode, cmonnode, errornode,
calcnode, arraydefnode, bnddefnode, bndvalnode,
waitlistnode, procdefnode, tlistnode, dimnode, commentnode,
linearnode, elbownode, shouldernode, flipnode, wrtnode,
loadnode,velocitynode);
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, jointop,
badop,
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: statementp; clast: nodep);
colistnode: (prev: nodep; cstmnt: statementp);
ffnode: (ff,cf: nodep; csys, pdef: boolean); (* true = world, false = hand *)
forcenode: (ftype: forcetypes; frel: reltypes; fval, fvec, fframe: nodep);
arraydefnode: (numdims: 1..10; bounds: nodep; combnds: boolean);
bnddefnode: (lower, upper: nodep);
swtnode: (clval: nodep);
byptnode,
viaptnode: (vlist: boolean; via,vclauses: nodep; vcode: statementp);
destnode: (loc: nodep; code: statementp);
durnode: (durrel: reltypes; durval: nodep);
procdefnode:(ptype: datatypes; level: 0..255;
pname, paramlist: varidefp; body: statementp);
dimnode: (time, distance, angle, dforce: integer);
end;
(* records for parser: ident, token, resword *)
ident = record
next: identp;
length: integer;
name: strngp;
predefined: varidefp;
end;
tokentypes = (reswdtype, identtype, constype, comnttype, delimtype, labeldeftype,
macpartype);
constypes = svaltype..strngtype;
reswdtypes = (stmnttype, filtype, clsetype, decltype, optype, edittype);
filtypes = (abouttype,alongtype,attype,bytype,defertype,dotype,elsetype,
errmodestype,fromtype,handtype,intype,nonrigidlytype,rigidlytype,
sourcefiletype,steptype,thentype,totype,untltype,viatype,
withtype,worldtype,zeroedtype,oftype,wheretype,nowaittype,
ontype,offtype,ppsizetype,collecttype,alltype,lextype,
notype,righttype,lefttype,uptype,downtype,motiontype);
clsetypes = (approachtype,arrivaltype,departuretype,departingtype,durationtype,
errortype,forcetype,forceframetype,forcewristtype,gathertype,
nildeproachtype,nullingtype,stiffnesstype,
torquetype,velocitytype,wobbletype,
cwtype,ccwtype,stopwaittimetype,angularvelocitytype,
respecttype,elbowtype,shouldertype,fliptype,lineartype,
jointspacetype,loadtype);
edittypes = (getcmd,savecmd,insertcmd,renamecmd,startcmd,gocmd,proceedcmd,
stepcmd,sstepcmd,nstepcmd,gstepcmd,executecmd,setcmd,tracecmd,
breakcmd,unbreakcmd,tbreakcmd,definecmd,markcmd,unmarkcmd,
popcmd,atcmd,calibratecmd);
token = record
next: tokenp;
case ttype: tokentypes of
constype: (cons: nodep);
comnttype: (len: integer; str: strngp);
delimtype: (ch: ascii);
reswdtype: (case rtype: reswdtypes of
stmnttype: (stmnt: stmntypes);
filtype: (filler: filtypes);
clsetype: (clause: clsetypes);
decltype: (decl: datatypes);
optype: (op: exprtypes);
edittype: (ed: edittypes) );
identtype: (id: identp);
labeldeftype: (lab: varidefp);
macpartype: (mpar: varidefp);
end;
resword = record
next: reswordp;
length: integer;
name: strngp;
case rtype: reswdtypes of
stmnttype: (stmnt: stmntypes);
filtype: (filler: filtypes);
clsetype: (clause: clsetypes);
decltype: (decl: datatypes);
optype: (op: exprtypes);
edittype: (ed: edittypes);
end;
(* process descriptor blocks & environment record definitions *)
queuetypes = (nullqueue,nowrunning,runqueue,inputqueue,eventqueue,sleepqueue,
forcewait,devicewait,joinwait,proccall);
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; (* probably never greater than 3? *)
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: statementp); (* first statement where process was defined *)
end;
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: statementp);
end;
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);
end;
environment = record
next: environp;
vals: array [0..9] of enventryp;
end;
cmoncb = record
running, enabled: boolean; (* cmon's status *)
cmon: statementp;
pdb: pdbp;
evt: eventp;
fbits: integer; (* bits for force sensing *)
oldcmon: cmoncbp; (* for debugger *)
end;
(* definition of AL-ARM messages *)
msgtypes = (initarmscmd,calibcmd,killarmscmd,wherecmd,
abortcmd,stopcmd,movehdrcmd,movesegcmd,
centercmd,operatecmd,movedonecmd,signalcmd,
setccmd,forcesigcmd,forceoffcmd,biasoncmd,biasoffcmd,setstiffcmd,
zerowristcmd,wristcmd,gathercmd,getgathercmd,readadccmd,writedaccmd,
errorcmd,floatcmd,setloadcmd,
armmagiccmd,realcmd,vectorcmd,transcmd);
errortypes = (noerror,noarmsol,timerr,durerr,toolong,featna,
unkmess,srvdead,adcdead,nozind,exjtfc,paslim,nopower,badpot,devbusy,
baddev,timout,panicb,nocart,cbound,badparm);
message = record
cmd: msgtypes;
ok: boolean;
case integer of
1: (dev, bits, n: integer;
(* (dev, bits, n, evt: integer; (* for arm code version *)
evt: eventp;
dur: real;
case integer of
1: (v1,v2,v3: real);
2: (sfac,wobble,pos: real);
3: (val,angle,mag: real);
4: (max,min: real);
5: (error: errortypes));
2: (fv1,fv2,fv3,mv1,mv2,mv3: real); (* may never use these... *)
3: (t: array [1..6] of real);
end;
interr = record
case integer of
0: (i: integer);
1: (err,foo: errortypes);
end;
(* print related records: *)
cursorp = record
cline,ind: integer;
case stmntp: boolean of
true: (st: statementp);
false: (nd: nodep);
end;
linerec = record
next: linerecp;
start,length: integer
end;
listingarray = packed array [0..listinglength] of ascii;
(* global variables *)
var
(* from EDIT *)
listing: listingarray; (* first 150 chars are used by expression editor *)
(* next 40 by header & trailer lines *)
{*} cursorStack: array [1..15] of cursorp; {These are BIG records! }
lbuf: array [1..160] of ascii;
ppBuf: array [1..100] of ascii;
lines: array [1..maxLines] of linerecp; (* what's on the screen + some *)
ppLines: array [1..maxPPLines] of linerecp; (* for page printer *)
marks: array [1..20] of integer;
reswords: array [0..26] of reswordp;
idents: array [0..26] of identp;
macrostack: array [1..10] of tokenp;
curmacstack: array [1..10] of varidefp;
screenheight,dispHeight: integer;
ppBufp,oppBufp,ppOffset,ppSize,nmarks: integer;
lbufp,cursor,ocur,cursorLine,fieldnum,lineNum,findLine,pcLine: integer;
firstDline,topDline,botDline,firstLine,lastLine,curLine: integer;
freeLines,oldLines: linerecp;
sysVars: varidefp;
dProg: statementp;
curBlock, newDeclarations, findStmnt: statementp;
macrodepth: integer;
filedepth, errCount, sCursor: integer;
curChar, maxChar, curFLine, curPage: integer;
nodim, distancedim, timedim, angledim,
forcedim, torquedim, veldim, angveldim: varidefp;
fvstiffdim, mvstiffdim: nodep;
pnode: nodep;
smartTerminal: boolean; (* true = insert/delete, false = redraw line *)
setUp,setExpr,setCursor,dontPrint,outFilep,collect,fParse,sParse,
eofError,endOfLine,backup,expandmacros,flushcomments,checkDims,
shownLine: boolean;
curtoken: token;
file1,file2,file3,file4,file5,outFile: atext;
bpts: array [1..maxBpts] of statementp; (* debugging crap *)
tbpts: array [1..maxTBpts] of statementp;
debugPdbs: array [0..10] of pdbp;
nbpts,ntbpts,debugLevel: integer;
eCurInt: pdbp;
STLevel: integer; (* set by GO *)
singleThreadMode,tSingleThreadMode: boolean;
(* from INTERP *)
inputLine: array [1..20] of ascii;
talk: text; (* for using the speech synthesizer *)
curInt, activeInts, readQueue, allPdbs: pdbp;
sysEnv: envheaderp;
clkQueue: nodep;
allEvents: eventp;
etime: integer; (* used by eval *)
curtime: integer; (* who knows where this will get updated - an ast? *)
stime: integer; (* used for clock queue on 10 *)
msg: messagep; (* for AL-ARM interaction *)
inputp: integer; (* current offset into inputLine array above *)
resched, running, escapeI, iSingleThreadMode: boolean;
msgp: boolean; (* flag set if any messages pending *)
inputReady: boolean;
(* various constant pointers *)
xhat,yhat,zhat,nilvect: vectorp;
niltrans: transp;
gpark, rpark: transp; (* arm park positions *)
(* various device & variable pointers *)
speedfactor: enventryp;
garm: framep;
{ Externally defined routines from elsewhere: }
(* From ALLOC *)
procedure relVector(v: vectorp); external;
procedure relTrans(t: transp); external;
function newNode: nodep; external;
procedure relNode(n: nodep); external;
procedure relStrng(n: strngp); 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 ppStrng(length: integer; s: strngp); external;
(* routine to show where error occurred: errprnt *)
procedure errprnt; external; (* Also appears in eaux1b *)
procedure errprnt;
var i: integer; s: strngp;
begin
errcount := errcount + 1; (* keep track of how many errors we've reported *)
ppLine;
if fparse then
begin
if (not (sParse or shownline)) and
((filedepth > 0) or (macrodepth > 0)) then
begin (* tell where error occured *)
ppChar('p'); ppInt(curPage); pp5(', l ',3); ppInt(curFLine);
if macrodepth > 0 then
begin
pp20(' while expanding mac',20); pp5('ro: ',4);
with curmacstack[macrodepth]↑.name↑ do
ppStrng(length,name);
end;
ppLine;
for i := 1 to maxchar do ppChar(listing[i]); (* show line *)
ppLine;
shownline := true;
end;
for i := 1 to curchar-1 do ppChar(' '); (* show where in line *)
ppChar('↑'); ppLine;
end;
end;
(* auxiliary expression mungers: relExpr & evalOrder, ppFlush *)
procedure relExpr(n: nodep); external;
procedure relExpr;
var b: boolean; st,stp: strngp;
begin
b := true;
if n = nil then b := false
else
with n↑ do
case ntype of
exprnode: begin
relExpr(arg1);
relExpr(arg2);
relExpr(arg3);
end;
leafnode: case ltype of
vectype: if v↑.refcnt <= 1 then relVector(v)
else v↑.refcnt := v↑.refcnt - 1;
transtype: if t↑.refcnt <= 1 then relTrans(t)
else t↑.refcnt := t↑.refcnt - 1;
strngtype: if (length <> 2) or (str↑.ch[1] <> chr(15B)) or
(str↑.ch[2] <> chr(12B)) then
begin
st := str;
while st <> nil do
begin stp := st↑.next; relStrng(st); st := stp end;
end
else b := false;
otherwise {do nothing};
end;
listnode: begin
relExpr(lval);
relExpr(next);
end;
ffnode: begin
if pdef and ((ff↑.ntype <> exprnode) or (ff↑.op <> vmkfrcop)) then
relNode(ff)
else relExpr(ff);
end;
forcenode:begin
relExpr(fval);
relExpr(fvec);
relExpr(fframe);
end;
arraydefnode: relExpr(bounds);
bnddefnode:begin
relExpr(lower);
relExpr(upper);
relExpr(next);
end;
otherwise {do nothing};
end;
if b then relNode(n);
end;
function evalOrder(what,last: nodep; pcons: boolean): nodep; external;
function evalOrder;
var vp: varidefp; n,nv: nodep; tbits: integer;
begin
if what <> nil then
with what↑ do
case ntype of
exprnode:
if (op < ioop) or (op = adcop) or (op = dacop) then
begin (* regular ops are easy to handle *)
next := last;
last := evalOrder(arg1,what,false); (* all ops have at least one arg *)
if arg2 <> nil then last := evalOrder(arg2,last,false);
if arg3 <> nil then last := evalOrder(arg3,last,false);
end
else if (op = grinchop) then last := evalOrder(arg1,last,true)
else if op < specop then (* query or inscalar *)
begin
what↑.next := last;
if op = inscalarop then last := what (* inscalar has no args *)
else if arg2 = nil then last := what (* query has no print list *)
else last := evalOrder(arg2,what,false); (* handle query's print list *)
end
else if op = arefop then
begin
arg1↑.next := last;
last := evalOrder(arg2,arg1,true); (* need to push constants too *)
end
else if op = jointop then
begin
next := last;
last := evalOrder(arg2↑.lval,what,false); (* ** only one subscript for now ** *)
end
else if op = callop then
begin
what↑.next := last;
last := what;
if arg2 <> nil then
begin
with arg1↑.vari↑ do
if p <> nil then vp := p↑.paramlist else vp := nil;
n := arg2;
while n <> nil do
begin (* evaluate parameters *)
if vp <> nil then
begin
tbits := vp↑.tbits;
vp := vp↑.next;
end
else tbits := 0;
with n↑.lval↑ do
begin
if (tbits = 4) then (* call by reference *)
if ((ntype = exprnode) and (op <> arefop)) or (* expression *)
((ntype = leafnode) and (ltype <> varitype)) (* constant *)
then tbits := 0; (* change to call by value *)
if tbits = 0 then last := evalOrder(n↑.lval,last,false)
else if (tbits = 4) and (ntype = exprnode) then
last := evalOrder(arg2,last,true); (* push subscripts *)
end;
n := n↑.next;
end
end
end
else if op = badop then (* stick default value node so it goes on stack *)
begin
arg2↑.next := last;
last := arg2;
end;
listnode:
begin
last := evalOrder(lval,last,pcons); (* set up this list element's value *)
if next <> nil then
last := evalOrder(next,last,pcons); (* now move down the list *)
end;
bnddefnode:
begin
last := evalOrder(lower,last,false); (* set up this subscript's values *)
last := evalOrder(upper,last,false);
if next <> nil then
last := evalOrder(next,last,false); (* now move down the list *)
end;
leafnode:
if pcons or (ltype = varitype) then
begin (* get variable's value or if asked push constants *)
next := last;
last := what;
end;
durnode:
last := evalOrder(durval,last,false); (* evaluate duration value *)
deprnode,
apprnode,
destnode:
begin
last := evalOrder(loc,last,false); (* evaluate location *)
if code <> nil then
if code↑.stype = signaltype then
if code↑.event↑.ntype <> leafnode then
last := evalOrder(code↑.event↑.arg2,last,true);
end;
viaptnode,
byptnode:
begin
last := evalOrder(via,last,false); (* evaluate location *)
nv := vclauses;
while nv <> nil do (* check for any specified duration *)
if nv↑.ntype = durnode then
begin
last := evalOrder(nv,last,false); (* evaluate duration *)
nv := nil;
end
else nv := nv↑.next;
nv := vclauses;
while nv <> nil do (* now check for any specified velocity *)
if nv↑.ntype = velocitynode then
begin
last := evalOrder(nv↑.clval,last,false); (* evaluate velocity vector *)
nv := nil;
end
else nv := nv↑.next;
if vcode <> nil then
if vcode↑.stype = signaltype then
if vcode↑.event↑.ntype <> leafnode then
last := evalOrder(vcode↑.event↑.arg2,last,true);
end;
forcenode:
begin
last := evalOrder(fval,last,false); (* evaluate force value *)
end;
otherwise {do nothing};
end;
evalOrder := last;
end;
procedure ppFlush; external;
procedure ppFlush;
begin pp20(' Will flush statemen',20); ppChar('t'); end;
(* aux routines for dimension checking: matchdim, getdim *)
function matchdim(d1,d2: nodep; exactp: boolean): boolean; external;
function matchdim;
var b: boolean;
begin
with d1↑ do
b := (time = d2↑.time) and (distance = d2↑.distance) and
(angle = d2↑.angle) and (dforce = d2↑.dforce);
if not (b or exactp) then
begin (* see if we can coerce d1 or d2, i.e. one is dimensionless *)
with d1↑ do
if (time = 0) and (distance = 0) and (angle = 0) and (dforce = 0) then
b := true;
if not b then (* see if d2 is dimensionless *)
with d2↑ do
if (time = 0) and (distance = 0) and (angle = 0) and (dforce = 0) then
b := true;
end;
matchdim := b;
end;
function getdim(n: nodep; var d: nodep): nodep; external;
function getdim;
var vdim: varidefp; d1: nodep;
procedure dimCopy(dp: nodep);
begin
with d↑ do
begin
time := dp↑.time;
distance := dp↑.distance;
angle := dp↑.angle;
dforce := dp↑.dforce;
end
end;
procedure dimMod(d1,d2: nodep; i: real);
begin
with d↑ do
begin
time := d1↑.time + round(i * d2↑.time);
distance := d1↑.distance + round(i * d2↑.distance);
angle := d1↑.angle + round(i * d2↑.angle);
dforce := d1↑.dforce + round(i * d2↑.dforce);
end
end;
begin
if d = nil then
begin
d := newNode; (* need to make up a new dimension node to hold result *)
d↑.ntype := dimnode;
end;
if n = nil then dimCopy(nodim↑.dim)
else
with n↑ do
if (ntype = leafnode) or (ntype = procdefnode) then
begin
if ntype = procdefnode then vdim := pname
else if ltype = varitype then vdim := vari
else if ltype = pconstype then vdim := cname
else vdim := nil;
if vdim <> nil then (* see if there's an associated dimension *)
with vdim↑ do
if dtype <> nil then vdim := dtype (* yes - use it *)
else
if (vtype = transtype) or (vtype = frametype) then vdim := distancedim
else if vtype = rottype then vdim := angledim else vdim := nil;
if vdim <> nil then dimCopy(vdim↑.dim) else dimCopy(nodim↑.dim)
end
else (* see what type of expression it is *)
begin
d1 := nil;
if (op <= eqvop) or ((sinop <= op) and (op <= tanop)) or (op = sexpop) or
(op = logop) or (op = expop) or (op = unitvop) or (op = taxisop) or
(op = queryop) or (op = inscalarop) or (op = adcop) or (op = vmop) then
dimCopy(nodim↑.dim)
else if op = timeop then dimCopy(timedim↑.dim)
else if ((asinop <= op) and (op <= atan2op)) or (op = torientop) or
(op = vsaxwrop) then dimCopy(angledim↑.dim)
else if (op = constrop) or (op = fmakeop) or (op = deproachop) or
(op = grinchop) then dimCopy(distancedim↑.dim)
else if (op = tmakeop) or (op = tvmulop) or (op = ttmulop) then
d := getdim(arg2,d)
else if (op = smulop) or (op = svmulop) or (op = vsmulop) or
(op = vdotop) or (op = crossvop) then
dimMod(getdim(arg1,d),getdim(arg2,d1),1.0)
else if (op = sdivop) or (op = idivop) or (op = vsdivop) then
dimMod(getdim(arg1,d),getdim(arg2,d1),-1.0)
else if (op = sqrtop) then dimMod(nodim↑.dim,getdim(arg1,d),0.5)
else if (op = negop) then dimMod(nodim↑.dim,getdim(arg1,d),-1.0)
(* special - used by dimension statement *)
else if (op = jointop) then dimCopy(angledim↑.dim)
(* ** the above is only true for arms like the PUMA ** *)
(* ** with no prismatic joints ** *)
else d := getdim(arg1,d); (* sadd,ssub,sneg,sabs,max,min,int,mod,vmagn,
tmagn,vmake,vadd,vsub,vneg,tpos,tvadd,tvsub,
tinvrt,ftof,aref,call,bad *)
if d1 <> nil then relNode(d1);
end;
getdim := d;
end;