PreviousUpNext

15.4.98  src/app/makelib/portable-graph/format.pkg

## format.pkg
## (C) 2001 Lucent Technologies, Bell Labs
## author: Matthias Blume (blume@research.bell-labs.com)

# Compiled by:
#     src/app/makelib/portable-graph/portable-graph-stuff.lib



# Format the list-of-edges dependency graph
# so it becomes a valid Mythryl program.


stipulate
    package fil =  file__premicrothread;                                # file__premicrothread  is from   src/lib/std/src/posix/file--premicrothread.pkg
herein

    package   format_portable
    #         ===============
    : (weak)
    api {
        output
            :
            ( portable_graph::Graph,
              fil::Output_Stream
            )
            ->
            Void;
    }
    {
        package p= portable_graph;              # portable_graph        is from   src/app/makelib/portable-graph/portable-graph.pkg

        fun output (p::GRAPH { imports, defs, export }, outs)
            =
            {   context = "c";
                #
                fun out l
                    =
                    apply (\\ x => fil::write (outs, x); end ) l;

                fun varlist []  =>  "[]";
                    varlist [x] =>  cat ["[", x, "]"];

                    varlist (h ! t)
                        =>
                        cat ("[" ! h ! fold_backward (\\ (x, a) = ", " ! x ! a)   ["]"]   t);
                end;

                fun cfc (front, args)
                    =
                    {   out [front];
                        apply (\\ x = out [" ", x])
                              (context ! args);
                    };

                fun to_string  s
                    =
                    cat ["\"", string::to_string s, "\""];

                fun tons p::SGN     => "sgn";
                    tons p::PACKAGE => "str";
                    tons p::GENERIC => "fct";
                end;

                fun rhs (p::SYM (ns, n))                 =>  cfc (tons ns, [to_string  n]);
                    rhs (p::SYMS syms)                   =>  cfc ("syms", [varlist syms]);
                    rhs (p::IMPORT { lib, syms } )       =>  cfc ("import", [lib, syms]);
                    rhs (p::MERGE l)                     =>  cfc ("merge", [varlist l]);
                    rhs (p::FILTER { env=>dictionary, syms } ) =>  cfc ("filter", [dictionary, syms]);

                    rhs (p::COMPILE { src => (src, native), env=>dictionary, syms } )
                        =>
                        cfc (if native  "ncompile"; else "compile";fi,
                             [to_string src, dictionary, syms]);

                end;

                fun dodef (p::DEF d)
                    =
                    {   out ["       my (", context, ", ", d.lhs, ") = "];
                        rhs d.rhs;
                        out ["\n"];
                    };

                out ["thelibrary = \\ ", context, " => (\n"];
                out ["\\ ", varlist imports, " => let use PGOps\n"];
                apply dodef defs;
                out ["   in\n       export ", context, " ", export,
                     "\n   end\n\
                     \ | _ => raise exception DIE \"wrong number of input libraries\")\n"];
            };
    };
end;


Comments and suggestions to: bugs@mythryl.org

PreviousUpNext