stat.sa


Generated by gen_html_sa_files from ICSI. Contact gomes@icsi.berkeley.edu for details
 
---------------------------> Sather 1.1 source file <--------------------------
-- collects various integer statistics
-- Statistics are collected with counters. Each counter is 
-- assoziated with a string. This string is used as a label
-- to print out the statistics.
-- Example: To count the functions compiled, you could
-- add
--          stat.incr("functions compiled");
-- at the beginning of the code that compiles a function.


abstract class $STAT < $STR

abstract class $STAT < $STR is incr(K:STR); incr(k:STR,by:INT); str:STR; print; end; -- collect no statistics

class NULL_STAT < $STAT

class NULL_STAT < $STAT is incr(K:STR) is end; incr(k:STR,by:INT) is end; str:STR is return ""; end; print is end; create:NULL_STAT is return new; end; end; -- collect normal statistics

class STAT < $STAT

class STAT < $STAT is include H_MAP{STR,INT}; incr(k:STR) is incr(k,1);-- STAT::incr end; incr(k:STR,by:INT) is v::=[k];-- STAT::aget if v=INT::nil then v:=0; end;-- INT::is_eq INT::nil [k]:=v+by;-- STAT::aset INT::plus end; str:STR is a:ARRAY{STR}:=#(size);-- ARRAY{1}::create STAT::size loop a.set!(ind!+":\t"+elt!);-- ARRAY{1}::set! STAT::ind! STR::plus STR::plus STAT::elt! end; a.sort;-- ARRAY{1}::sort s::=""; if size>0 then-- STAT::size INT::is_lt s:="Statistics:\n"; loop s:=s+a.elt!+"\n"-- STR::plus ARRAY{1}::elt! end;-- STR::plus end; return s; end; print is #OUT+str;-- OUT::create STAT::str end; end