home *** CD-ROM | disk | FTP | other *** search
- ############################################################################
- #
- # File: iftrace.icn
- #
- # Subject: Procedures to trace Icon function calls
- #
- # Author: Stephen B. Wampler
- #
- # Date: July 12, 1991
- #
- ###########################################################################
- #
- # These procedures provide tracing for Icon functions by using procedure
- # wrappers to call the functions.
- #
- # trace_options(args) sets options for tracing given in the list args,
- # typically provided via the command line as an argument to main().
- # The values can be
- #
- # -trace turn on tracing (sets &trace to -1)
- # -Fs enable tracing for the function named s.
- #
- # set_trace(vf) sets tracing for vf (used by trace_options).
- #
- ############################################################################
- #
- # Note: The functions that can be traced and their procedure wrappers should
- # be organized and coordinated to assure consistency and to allow for
- # extended function repertoire.
- #
- ############################################################################
- #
- # Links: ifncs
- #
- ############################################################################
-
- link ifncs
-
- procedure trace_options(args)
- local nextarg, arg
-
- #
- # Check arguments for tracing parameters
- #
- # trace built-in functions, e.g.:
- #
- # -Ftab
- #
- # will trace tab()
- #
-
- every arg := !args do {
- if map(arg) == "-trace" then
- &trace := -1
- else if match("-F",arg) then { # trace a built-in function
- set_trace(arg[3:0])
- }
- }
-
- return
- end
-
- procedure set_trace(vf)
- local traceset, vp
-
- #
- # trace the built-in function 'vf', if possible
- #
-
- if not find("Version 8",&version) then {
- write(&errout,"You are running ",&version,", which doesn't support")
- write(&errout," this package. You need version 8.")
- stop()
- }
-
- # Here's the standard Version 8.x set. It's easy to add others.
-
- traceset := set([
- "acos",
- "any",
- "args",
- "asin",
- "atan",
- "bal",
- "center",
- "char",
- "chdir",
- "close",
- "collect",
- "copy",
- "cos",
- "cset",
- "delay",
- "delete",
- "detab",
- "display",
- "dtor",
- "entab",
- "errorclear",
- "exit",
- "exp",
- "find",
- "flush",
- "get",
- "getenv",
- "iand",
- "icom",
- "image",
- "insert",
- "integer",
- "ior",
- "ishift",
- "ixor",
- "key",
- "left",
- "list",
- "log",
- "many",
- "map",
- "match",
- "member",
- "mmout",
- "mmpause",
- "mmshow",
- "move",
- "name",
- "numeric",
- "open",
- "ord",
- "pop",
- "pos",
- "proc",
- "pull",
- "push",
- "put",
- "read",
- "reads",
- "real",
- "remove",
- "rename",
- "repl",
- "reverse",
- "right",
- "rtod",
- "runerr",
- "seek",
- "seq",
- "set",
- "sin",
- "sort",
- "sqrt",
- "stop",
- "string",
- "system",
- "tab",
- "table",
- "tan",
- "trim",
- "type",
- "upto",
- "variable",
- "where",
- "write",
- "writes"
- ])
-
- if member(traceset,vf) then {
- &trace := -1 # have to also trace all procedures!
- vp := vf
- vp[1] := map(vp[1],&lcase,&ucase)
- variable(vp) :=: variable(vf)
- return
- }
- else
- fail
-
- end
-