def insertAppend(C6, v, e) : """appends e to the end of array/list v in the heap. Does the same actions as an insertAssign to an indexed array, but preserves more heap info since the append does not produce any aliases within v params : C6; v - a vartee; e - an etree """ sigma = C6["store"] heap = C6["heap"] vname = v[1] vold = Parse.makeOldVar(v) if lookupType(C6, vname) != "array" : error("cannot append to a non-list/array") else : loc = PE.peToTuple(sigma[vname]) length = heap[loc][0] newlength = PE.add(length, PE.make(1)) vector = heap[loc][1] # assign original to v_old: sigma[vold[1]] = sigma[vname] # make copy for the new value of v: copy = {} for k in vector : copy[k] = vector[k] newloc = PE.make(PE.makeSym()) rhs = PE.evall(C6, e) copy[ PE.peToTuple(length) ] = rhs sigma[vname] = newloc heap[ PE.peToTuple(newloc) ] = (newlength, copy)
def insertAssign(C6, v, etree): """updates the store of C6 with an assignment. If v already exists in C6's store, saves former value as v_old for later use in proof reasoning. params: v - has form, ["var", s] or ["index", ["var", s], etree] etree - another etree, to be assigned to the var. """ sigma = C6["store"] heap = C6["heap"] badvars = C6["novars"] if v[0] == "var" : vtree = v elif v[0] == "index" : vtree = v[1] vold = Parse.makeOldVar(vtree) # ["var", vname_old] # first, check if we are allowed to update v: if (vtree in badvars) : error("you may not update a protected global var outside of its maintenance function") return # if possible, rename current value of var v as v_old: if v[0] == "var" and v[1] in sigma : # and lookupType(C6, v[1]) != "array": sigma[vold[1]] = sigma[v[1]] # assign v's current value to v_old elif v[0] == "index" and lookupType(C6, v[1][1]) == "array": vname = v[1][1] loc = PE.peToTuple(sigma[vname]) length = heap[loc][0] vector = heap[loc][1] # make copy: copy = {} for k in vector : copy[k] = vector[k] # assign original to v_old and copy to v : sigma[vold[1]] = sigma[vname] newloc = PE.make(PE.makeSym()) sigma[vname] = newloc heap[ PE.peToTuple(newloc) ] = (length, copy) # (later, vold will be erased from sigma....) # now, eval assignment's rhs and store it into v: rhs = PE.evall(C6, etree) if v[0] == "var": # simple var sigma[v[1]] = rhs elif v[0] == "index": # an array/list reference # eval index expression (NOTE: no nested indexing allowed): indexpe = PE.evall(C6, v[2]) # save values in sigma[vname][1] provably distinct from vname[index]: vname = v[1][1] if vname not in sigma or lookupType(C6, vname) != "array" : error(vname + " is not an array in the store") #sigma[vname] = PE.makeArray() else : vmap = heap[PE.peToTuple(sigma[vname])][1] saveDistinctElements(C6, vmap, indexpe) vmap[PE.peToTuple(indexpe)] = rhs