PreviousUpNext

15.4.42  src/app/heap2asm/heap2asm.pkg

## heap2asm.pkg

# Compiled by:
#     src/app/heap2asm/heap2asm.lib

#   Generating an assembly code file corresponding to a heap image.

package main: (weak) api {
     main: (String, List( String )) -> winix::process::Status;
}
{
    nnn = 20;

    fun one (inf, outf)
        =
        {   my (si, so)
                =
                (   file::open_for_read  inf,
                    file::open_for_write outf
                );

            fun out s
                =
                file::write (so, s);

            fun finish n
                =
                {   out ".text\n\t.align 2\n_lib7_heap_image_len:\n\t.long ";
                    out (int::to_string n);
                    out "\n";
                };

            fun line l
                =
                {   bl = map
                             (int::to_string o char::to_int)
                             (string::explode l);

                    out ("\t.byte " + string::join ", " bl + "\n");
                };

            fun lines n
                =
                case (file::read_n (si, nnn))

                      "" => finish n;

                    l   => {   s = size l;
                                line l;
                                if (s < nnn ) finish (n+s);
                                           else lines  (n+s);fi;
                            }; esac;

           out "\t.globl _lib7_heap_image\n\
               \\t.globl _lib7_heap_image_len\n\
               \.text\n\t.align 2\n\
               \_lib7_heap_image:\n";

           lines 0;

           file::close_input  si;
           file::close_output so;
        };

    fun complain (p, s)
        =
        {    file::write (file::stderr, cat [p, ": ", s, "\n"]);
             winix::process::failure;
        };

    fun main (p, [inf, outf])
            =>
            {   one (inf, outf);
                winix::process::success;
            }
            except
                e =  complain (p, "exception: " + exceptions::exception_message e);


       main (p, _)
            =>
            complain (p, "usage: " + p + " heapfile asmfile");
    end;
};


## Copyright (c) 2005 by The Fellowship of SML/NJ
## Author: Matthias Blume (blume@tti-c.org)
## Subsequent changes by Jeff Prothero Copyright (c) 2010-2011,
## released under Gnu Public Licence version 3.


Comments and suggestions to: bugs@mythryl.org

PreviousUpNext