home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / historic / v941.tgz / icon.v941src.tar / icon.v941src / ipl / progs / gftrace.icn < prev    next >
Text File  |  2000-07-29  |  3KB  |  95 lines

  1. ############################################################################
  2. #
  3. #    File:     gftrace.icn
  4. #
  5. #    Subject:  Program for generating function tracing procedures
  6. #
  7. #    Author:   Gregg M. Townsend
  8. #
  9. #    Date:     August 8, 1997
  10. #
  11. ############################################################################
  12. #
  13. #   This file is in the public domain.
  14. #
  15. ############################################################################
  16. #  
  17. #     This program writes a set of procedures to standard output.  Those
  18. #  procedures can be linked with an Icon program to enable the tracing of
  19. #  calls to built-in functions.  See the comments in the generated code
  20. #  for details.
  21. #
  22. #     The set of generated functions reflects the built-in functions of
  23. #  the version of Icon under which this generator is run.
  24. #  
  25. ############################################################################
  26.  
  27.  
  28. procedure main()
  29.    local s
  30.  
  31.    header()
  32.  
  33.    write()
  34.    write("procedure _func(a[]); _func:=proc(\"proc\",0); ",
  35.       "proc:=_proc; return _func!a; end")
  36.    write("procedure _proc(a[]); static p; initial p:=_func(\"proc\",0); ",
  37.       "suspend p!a; end")
  38.    write()
  39.  
  40.    every s := function() do
  41.       if s ~== "proc" then
  42.          write("procedure ", s, "(a[]); static p; initial p:=_func(\"",
  43.         s, "\",0); suspend p!a; end")
  44. end
  45.  
  46.  
  47. procedure header()
  48.    local divider, date
  49.  
  50.    divider := repl("#", 76)
  51.  
  52.    &dateline ? {
  53.       tab(upto(',') + 1)
  54.       tab(many(' '))
  55.       date := tab(upto(',') + 6)
  56.       }
  57.  
  58.    every write(![
  59.       divider,
  60.       "#",
  61.       "#\tFile:     ftrace.icn",
  62.       "#",
  63.       "#\tSubject:  Procedures for tracing calls to built-in functions",
  64.       "#",
  65.       "#\tAuthor:   Gregg M. Townsend",
  66.       "#",
  67.       "#\tDate:     " || date,
  68.       "#",
  69.       divider
  70.       ])
  71.  
  72.    every write ("#  ", ![
  73.       "",
  74.       "   These procedures, when linked with an Icon program, cause calls of",
  75.       "built-in functions to be traced (along with calls of user procedures)",
  76.       "when &trace is nonzero.  This is accomplished by interposing a level of",
  77.       "Icon procedures between the user program and the built-in functions.",
  78.       "",
  79.       "   In the trace output, function arguments are shown as a list.  The",
  80.       "very first function call produces two extra trace lines showing a call",
  81.       "to \"_func\".  Calls to \"proc\" are reported as calls to \"_proc\".",
  82.       "",
  83.       "   If the user program overloads any built-in function, linking fails",
  84.       "due to an \"inconsistent redeclaration\".",
  85.       ""])
  86.  
  87.    write(divider)
  88.    write("#")
  89.    write("#  Generated under:  ", &version)
  90.    write("#")
  91.    write(divider)
  92.  
  93.    return
  94. end
  95.