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 / mprogs / mmm.icn < prev    next >
Text File  |  2000-07-29  |  4KB  |  140 lines

  1. ############################################################################
  2. #
  3. #    File:     mmm.icn
  4. #
  5. #    Subject:  Program to show allocation as a miniature "MemMon"
  6. #
  7. #    Author:   Clinton Jeffery
  8. #
  9. #    Date:     August 12, 1994
  10. #
  11. ############################################################################
  12. #
  13. #   This file is in the public domain.
  14. #
  15. ############################################################################
  16. #
  17. #  Displays a tiny rendition of internal heap allocation.
  18. #
  19. ############################################################################
  20. #
  21. #  Requires:  Version 9 graphics
  22. #
  23. ############################################################################
  24. #
  25. #  Links:   evinit, options, optwindw, typebind, colormap, wipe, xcompat
  26. #
  27. ############################################################################
  28. #
  29. #  Includes:  evdefs.icn
  30. #
  31. ############################################################################
  32.  
  33. $include "evdefs.icn"
  34.  
  35. link evinit
  36. link options
  37. link optwindw
  38. link typebind
  39. link colormap
  40. link wipe
  41. link xcompat
  42.  
  43. global Visualization, contexts
  44. global t, sum, threesixty, wid, hei
  45.  
  46. procedure main(av)
  47.    local c_string, lines, mymask, allocstr, blockall, sum1, sum2, row1, row2,
  48.     Regions, c, start, sum2div4, verbose
  49.    if *av>0 then
  50.       EvInit(av) | stop("EvInit() can't load ",av[1])
  51.    else
  52.       EvInit() | stop("can't EvInit()")
  53.  
  54.    threesixty := 360 * 64
  55.    t := options(av)
  56.    /t["W"] := 650
  57.    /t["H"] := 50
  58.    &window := optwindow(t) | stop("no window")
  59.    Visualization := &window
  60.    contexts := itypebind(&window)
  61.    c_string := contexts[E_String] | stop("eh?")
  62.    / contexts[E_Tvsubs] := c_string
  63.  
  64.    wid := WAttrib("width")
  65.    hei := WAttrib("height")
  66.    lines := WAttrib("lines")
  67.  
  68.    mymask := AllocMask ++ cset("\360"||E_Collect||E_BlkDeAlc||E_StrDeAlc)
  69.    allocstr := string(AllocMask)
  70.    blockall := 0
  71.  
  72.    sum1 := 0
  73.    sum2 := 0
  74.    row1 := 0
  75.    row2 := hei/2+1
  76.  
  77.    Regions := []
  78.    every put(Regions,keyword("regions",EventSource))
  79.    pop(Regions)
  80.  
  81.    while EvGet(mymask) do {
  82.       if &eventcode === E_Lelem then &eventcode := E_List
  83.       if &eventcode === (E_Telem|E_Tvtbl|E_Slots) then &eventcode := E_Table
  84.       if &eventcode === E_Selem then &eventcode := E_Set
  85.       if &eventcode === E_Refresh then &eventcode := E_Coexpr
  86.       case &eventcode of {
  87.      E_Collect: {
  88.         wipe(&window)
  89.         sum1 := sum2 := 0
  90.         row1 := 0
  91.         row2 := hei/2+1
  92.         }
  93.      E_EndCollect: {
  94.         }
  95.      E_String: {
  96.         DrawLine(c_string,sum1/4,row1,(sum1+&eventvalue)/4,row1)
  97.         sum1 +:= &eventvalue
  98.         while sum1/4 >= wid do {
  99.            sum1 -:= wid * 4
  100.            row1 +:= 1
  101.            if row1 > hei/2 then {
  102.           EraseArea(0,0,wid,hei/2)
  103.           row1 := 0
  104.           }
  105.            DrawLine(c_string,0,row1,sum1/4,row1)
  106.            }
  107.         }
  108.      !.allocstr: {
  109.         c := \contexts[&eventcode] | stop("what is ",&eventcode)
  110.         start := sum2/4
  111.         sum2 +:= &eventvalue
  112.         sum2div4 := sum2/4
  113.         DrawLine(c,start,row2,sum2div4,row2)
  114.         while sum2div4 >= wid do {
  115.            sum2 -:= wid * 4
  116.            sum2div4 := sum2/4
  117.            row2 +:= 1
  118.            DrawLine(c,0,row2,sum2div4,row2)
  119.            }
  120.         }
  121.      default: {
  122.         if \verbose then write("unknown event code ",&eventcode)
  123.         }
  124.      }
  125.       }
  126.  
  127. end
  128.  
  129. procedure itypebind(z)
  130.   static t
  131.   initial {
  132.       t := table()
  133.   }
  134.   /(t[z]):=typebind(z,E_Integer||E_Real||E_Record||E_Set||E_String||E_Cset||
  135.             E_File||E_List||E_Null||E_Proc||E_Table,table())
  136. #  if type(t[z][E_Proc])=="file" then close(t[z][E_Proc])
  137.   t[z][E_Proc] := XBind(z,"fg=#999")
  138.   return t[z]
  139. end
  140.