// MICSTATS -- statistics for Micro
// last edited February 5, 1981  11:34 AM
// Copyright Xerox Corporation 1979, 1981

	get "micdecl.d"

external	// defined here
[	symstats
]

external
[		// O.S.
	Zero
]


let symstats() be
[	let lc = lchan
	lchan = erlchan
	scinit(0, 0, 0)
	let ns, nw = vec maxtype, vec maxtype
	Zero(ns, maxtype+1)
	Zero(nw, maxtype+1)
	let nm, macw = 0, 0
	[ let ep = scnext()
	  if ep eq 0 break
	  let j = ep!stype
	  test j ls 0 ifso j = adrtype
	  ifnot if j gr maxtype then j = mactype
	  ns!j = ns!j+1
	  nw!j = nw!j+typesizes!j+1+lenname(ep)/2+1
	  if j ne mactype loop
	  let dp = fstop-ep!stype
	  let di = 2
	  until dp>>bytes↑di eq Aend do
	   di = selecton dp>>bytes↑di into
	  [ case Aargn: case symc: case numc: case num6c: 2
	    case symc+200b: case numc+200b: case num6c+200b: 3
	    default: 1
	  ] + di
	  let w = (di rshift 1) + 1
	  nm, macw = nm+1, macw+w
	] repeat
	let stot, wtot = 0, 0
	for i = 0 to maxtype do stot, wtot = stot+ns!i, wtot+nw!i
	symspace("*NTotal of ", stot, wtot)
	for i = 0 to maxtype do
	[ llstr(typenames!i); symspace(": ", ns!i, nw!i)
	]
	llstr("*NMacro defs: "); ldec(nm)
	llstr(", words: "); ldec(macw)
	lcrlf()
	lchan = lc
]

and symspace(str, n, nw) be
[	llstr(str)
	ldec(n)
	llstr(" symbols, ")
	ldec(nw)
	llstr(" words*N")
]