/* Encoding Definitions, X = Y */ -exports("define","snapshot") define(guard,X,Y,Ib,Ie,Db,De,P) { ? guard=="guard", X?={V,Nm,[]}, V=="_var" -> {|| defn_rhs(Y,RY,Ib,Ie,Db,Dm,P), Dm=[add(Nm,[],"defn",RY,F)|De], defn_guard_lhs(Nm,F,P) }, guard=="body", X?={V,Nm,Ss}, V=="_var" -> {|| defn_rhs(Y,RY,Ib,Im,Db,Dm1,P), Dm1=[find(Nm,_,Ty,RX,F)|Dm2], defn_body_lhs(Nm,Ty,RX,F,Ss,RY,Im,Ie,Dm2,De,P) }, default -> {|| Ib=Ie, Db=De, co_coutil:error(["Invalid variable ",X,"=... , in ",P]) } } /* NOTES: 1) X=... X may be the first or subsequent occurrence of a variable. 2) X[Sub]=... X and Sub must be subsequent occurences (preprocessor). Sub has no subscripts (grammer). */ defn_body_lhs(Nm,Ty,RX,F,Ss,RY,Ib,Ie,Db,De,P) { ? Ty=="defn", F=="false", Ss?=[] -> {|| Ib=[build_def(RX),define(RX,RY)|Ie], Db=De }, Ty=="defn", F=="true", Ss?=[] -> {|| Ib=[define(RX,RY)|Ie], Db=De }, Ty=="defn", F=="true", Ss?=[Sub], int(Sub) -> {|| Ib=[put_data(R1,Sub),get_element(R1,RX,R2),define(R2,RY)|Ie], Db=[alloc(1,R1),free(R1),alloc(1,R2),free(R2)|De] }, Ty=="defn", F=="true", Ss?=[{V,SNm,[]}], V=="_var" -> {|| Ib=[get_element(SR,RX,R2),define(R2,RY)|Ie], Db=[find(SNm,SDs,STy,SR,SF),alloc(1,R2),free(R2)|De], chk_sub(SNm,SDs,STy,SF,P) }, default -> {|| Ib=Ie, Db=De, co_coutil:error(["Invalid definition of ",Nm," , in ",P]) } } defn_guard_lhs(Nm,F,P) {? F!="true" -> {|| co_coutil:error(["Invalid definition in guard ",Nm," , in ",P]) } } defn_rhs(Y,RY,Ib,Ie,Db,De,P) { ? Y ?= {E,_}, E=="_exp" -> {|| co_enexp:exp(Y,RY,Ib,Ie,Db,De,P)}, Y ?= {V,Nm,Ss}, V=="_var" -> {|| Db=[find(Nm,Ds,Ty,R,F)|Dm], defn_rhs_var(Nm,Ds,Ty,R,F,Ss,RY,Ib,Ie,Dm,De,P) }, default -> {|| structure(Y,RY,Ib,Ie,Db,De,P) } } /* NOTES = X : defn/mutable = X[Sub] : mutable - Sub contains not subscripts (grammer) = X[Sub] : defn - Sub contains no subscripts (grammer) : - X and Sub must be in registers (preprocessor) */ defn_rhs_var(Nm,Ds,Ty,R,F,Ss,RY,Ib,Ie,Db,De,P) { ? Ty=="defn", F=="false", Ss?=[] -> {|| RY=R, Ib=[build_def(R)|Ie], Db=De }, Ty=="defn", F=="true", Ss?=[] -> {|| RY=R, Ib=Ie, Db=De }, Ty=="defn", F=="true", Ss?=[Sub], int(Sub) -> {|| Ib=[put_data(R1,Sub),get_element(R1,R,RY)|Ie], Db=[alloc(1,R1),free(R1),alloc(1,RY)|De] }, Ty=="defn", F=="true", Ss?=[{V,SNm,[]}], V=="_var" -> {|| Ib=[get_element(SR,R,RY)|Ie], Db=[find(SNm,SDs,STy,SR,SF),alloc(1,RY)|De], chk_sub(SNm,SDs,STy,SF,P) }, Ty!="defn" -> {||snapshot(Nm,Ds,Ty,R,Ss,RY,Ib,Ie,Db,De,P)}, default -> {|| RY=-1, Ib=Ie, Db=De, co_coutil:error(["Illegal definition: ",Nm,Ss,", in ",P]) } } /* Build a structure snapshotting all mutables contained in it. */ structure(A,R,Ib,Ie,Db,De,P) { ? int(A) -> {|| Db=[alloc(1,R)|De], Ib=[put_data(R,A)|Ie] }, double(A) -> {|| Db=[alloc(1,R)|De], Ib=[put_data(R,A)|Ie] }, char(A) -> {|| Db=[alloc(1,R)|De], Ib=[put_data(R,A)|Ie] }, A ?= {V,Nm,[]}, V=="_var" -> {|| Db=[find(Nm,Ds,Ty,RY,F)|Dm], var_in_structure(Nm,Ds,Ty,RY,F,R,Ib,Ie,Dm,De,P) }, A ?= {E,_}, E=="_exp" -> {|| R=-1, Ib=Ie, Db=De, co_coutil:error(["Expression in structure: ",A,", in ",P]) }, A ?= {V,Nm,[_|_]}, V=="_var" -> {|| R=-1, Ib=Ie, Db=De, co_coutil:error(["Subscripted variable in structure: ", A,", in ",P]) }, default -> {|| N=length(A), Db=[alloc(1,R)|Dm], dsargs(N,0,A,Ib,[build_static("tuple",N,R)|Im],Im,Ie,Dm,De,P) } } /* must be a definition or a mutable without subscripts */ var_in_structure(Nm,Ds,Ty,R,F,RY,Ib,Ie,Db,De,P) { ? Ty=="defn", F=="false" -> {|| RY=R, Ib=[build_def(R)|Ie], Db=De }, Ty=="defn", F=="true" -> {|| RY=R, Ib=Ie, Db=De }, Ty!="defn" -> {|| snapshot(Nm,Ds,Ty,R,[],RY,Ib,Ie,Db,De,P)}, default -> {|| RY=-1, Ib=Ie, Db=De, co_coutil:error(["Illegal variable in structure: ", Nm,", in ",P]) } } dsargs(N,M,T,Ib,Ie,Cb,Ce,Db,De,P) { ? N > M -> {|| N1=N-1, Arg=T[N1], dsargs(N1,M,T,Ib,Im,Cb,[put_value(R)|Ce],Db,Dm,P), structure(Arg,R,Im,Ie,Dm,De,P) }, default -> {|| Ib=Ie, Cb=Ce, Db=De } } /* Encoding a snapshot of a mutable variable Nm,...Ss, - describes mutable to access Reg - output register containing a snapshot */ snapshot(Nm,Ds,Ty,RM,Ss,Reg,Ib,Ie,Db,De,P) { ? Ty!="defn", Ss?=[], Ds?=[] -> {|| Ib=[build_static(Ty,1,Reg),copy_mut(RM,Reg)|Ie], Db=[alloc(1,Reg)|De] }, Ty!="defn", Ss?=[], Ds!=[] -> {|| S="length", Ib=[build_static("int",1,SizeR),{S,RM,SizeR}, build_dynamic(Ty,SizeR,Reg),copy_mut(RM,Reg)|Ie], Db=[alloc(1,SizeR),alloc(1,Reg)|De] }, Ty!="defn", Ss?=[Sub], int(Sub) -> {|| Ib=[put_data(R1,Sub),get_element(R1,RM,Reg)|Ie], Db=[alloc(1,Reg),alloc(1,R1),free(R1)|De] }, Ty!="defn",Ss?=[{V,SNm,[]}],V=="_var" -> {|| Ib=[get_element(SR,RM,Reg)|Ie], Db=[find(SNm,SDs,STy,SR,SF),alloc(1,Reg)|De], chk_sub(SNm,SDs,STy,SF,P) }, default -> {|| Ib=Ie, Db=De, co_coutil:error(["Illegal snapshot ",Nm," , in ",P]) } } chk_sub(Nm,Ds,Ty,F,P) { ? Ty=="defn", F=="true" -> {||skip()}, Ty=="int", Ds?=[] -> {||skip()}, default -> {||co_coutil:error(["Invalid subscript ",Nm," , in ",P])} }