link options global verbose, memory, stlimit, stcount procedure main(args) opt_tbl := options(args, "-verbose-memory-trace+-dump-stlimit+") if \opt_tbl["verbose"] then verbose := TRUE if \opt_tbl["memory"] then memory := TRUE stlimit := \opt_tbl["stlimit"] | 50000 stcount := 0 &trace := \opt_tbl["trace"] | 0 &dump := \opt_tbl["dump"] | 0 if \verbose then { write(&dateline) write("Host = ",&host) write("Icon Version = ",&version) } ......... if \memory then { notestor() notereg() notealloc() notecol() } write("CPU time ", &time, " milliseconds") write("stcount = ", stcount) return end procedure notereg() local reg reg := [] write("Regions:") every put(reg, ®ions) # write("static: ", reg[1]) write("string: ", reg[1]) write("block: ", reg[2]) write("total: ", reg[3]) return end procedure notestor() local stor stor := [] write("Storage:") every put(stor, &storage) # write("static: ", stor[1]) write("string: ", stor[1]) write("block: ", stor[2]) write("total: ", stor[3]) return end procedure notealloc() local alloc alloc := [] write("Allocated:") every put(alloc, &storage) # write("static: ", alloc[1]) write("string: ", alloc[1]) write("block: ", alloc[2]) write("total: ", alloc[3]) return end procedure notecol() local coll coll := [] write("Collections:") every put(coll, &collections) write("static: ", coll[1]) write("string: ", coll[2]) write("block: ", coll[3]) write("total: ", coll[4]) return end procedure chk_stlimit(filename, lineno) # stlimit and stcount are globals set with options # not true statement count - serves to limit loops etc. # set to -2 for no limit # call this in any suspicious loop or recursion # as "chk_stlimit(&file, &line)" if stlimit > -1 then { stcount +:= 1 if (stlimit - stcount) < 0 then { stop("stlimit ", stlimit, " exceeded in ", filename, " at line ", lineno) } } return end procedure dump_anything(nam, it, filename, lineno, traversed) # dump_anything called with traversed as [] $include "defs2.icn"