11.07.2015 Views

Advanced Programming Guide

Advanced Programming Guide

Advanced Programming Guide

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

84 • Chapter 3: <strong>Programming</strong> with ModulesThe Package SourceHere is the source code for the package.> coverage := module()> description "a package of utilities for "> "code coverage profiling";> option package;> export profile, covered;> local rprofile, traced;>> # Instrument a procedure or module> # for coverage profiling. Return the> # number of procedures instrumented.> profile := proc()> local arg;> add( rprofile( arg ), arg = [ args ] )> end proc;>> rprofile := proc( s::name )> local e;> if type( s, ’procedure’ ) then> debugopts( ’traceproc’ = s );> 1> elif type( s, ’‘module‘’ ) then> add( procname( e ),> e = select( type,> [ exports( s, ’instance’ ) ],> ’{ ‘module‘, procedure }’ ) )> else> error "only procedures and modules can be profiled"> end if> end proc;>> # Subroutine to recognize an rtable that> # is used to store profiling information,> # based on its name.> traced := proc( s )> evalb( substring( convert( s, ’string’ ),> 1 .. 6 ) = "TRACE/" )> end proc;>> # Determine which procedures have> # coverage information.> covered := proc()> local S;> S := [ anames( ’rtable’ ) ];> S := select( traced, S );> if nargs > 0 and args[ 1 ] = ’nonzero’ then> S := select( s -> evalb( s[1,1] 0 ), S )> elif nargs > 0 then> error "optional argument is the name nonzero"> end if;> map( parse, map( substring,> map( convert, S, ’string’ ), 7 .. -1 ) )> end proc;

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!