PreviousUpNext

15.4.237  src/lib/compiler/back/low/display/graph-viewer-g.pkg

## graph-viewer-g.pkg
#
# This module starts a graph viewer.
#
# -- Allen Leung 

# Compiled by:
#     src/lib/compiler/back/low/lib/visual.lib


stipulate
#   package gl  =  graph_layout;                                        # graph_layout          is from   src/lib/compiler/back/low/display/graph-layout.pkg
    package odg =  oop_digraph;                                         # oop_digraph   is from   src/lib/graph/oop-digraph.pkg
    package fs  =  winix::file;                                         # winix                 is from   src/lib/std/winix.pkg
herein

    # This generic is invoked various places, most notably:
    #
    #     src/lib/compiler/back/low/main/main/backend-lowhalf-g.pkg
    #
    generic package   graph_viewer_g   (
        #             ==============
        #
        gd:  Graph_Display                                              # Graph_Display         is from   src/lib/compiler/back/low/display/graph-display.api
    )
    : (weak)  Graph_Viewer                                              # Graph_Viewer          is from   src/lib/compiler/back/low/display/graph-viewer.api
    {
       tmp_name
           =
           lowhalf_control::get_string
               "tmp_name";

       fun display exec (layout as odg::DIGRAPH l) filename
           = 
           {   filename  = filename + gd::suffix();

               print("[ " + l.name + ": " + 
                                 gd::program() + " " + filename + 
                                 " " + int::to_string (l.order ()) + " nodes"  + 
                                 " " + int::to_string (l.size ()) + " edges");

               file  =  file::open_for_write filename;
               out   =  fn s = file::write (file, s);
               gd::visualize out layout;
               file::close_output file;
               print(" ]\n");

               exec filename;

               ();
          }
          except
              e =  {   print("[Uncaught exception in " + exception_name e + " graph viewer]\n");
                       raise exception e;
                   };

       fun system filename = { winix::process::system 
                               ((gd::program()) + " " + filename);
                              fs::remove_file filename;};

       fun fork filename = (winix::process::system(
                              "(" + (gd::program()) + " " + filename + 
                                  "; /bin/rm " + filename + ") &"));

       fun get_tmp_name ()
           =
           if (*tmp_name == "")   fs::tmp_name ();
           else                   *tmp_name;
           fi;

       fun view layout
           =
           display system layout (get_tmp_name());
    };
end;


Comments and suggestions to: bugs@mythryl.org

PreviousUpNext