PreviousUpNext

15.4.91  src/app/make7/pgraph/format.pkg

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

# Compiled by:
#     src/app/make7/pgraph/pgraph-util.make6



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



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

    fun output (p::GRAPH { imports, defs, export }, outs)
        =
        {   context = "c";

            fun out l
                =
                apply (fn x => file::write (outs, x); end ) l;

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

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

            fun cfc (front, args)
                =
                {   out [front];
                    apply (fn 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 = fn ", context, " => (\n"];
            out ["fn ", varlist imports, " => let use PGOps\n"];
            apply dodef defs;
            out ["   in\n       export ", context, " ", export,
                 "\n   end\n\
                 \ | _ => raise exception FAIL \"wrong number of input libraries\")\n"];
        };
};


Comments and suggestions to: bugs@mythryl.org

PreviousUpNext