PreviousUpNext

15.4.54  src/app/makelib/compile/thawedlib-tome–to–compiledfile-contents–map-g.pkg

## thawedlib-tome--to--compiledfile-contents--map-g.pkg
## (C) 1999 Lucent Technologies, Bell Laboratories
## Author: Matthias Blume (blume@kurims.kyoto-u.ac.jp)

# Compiled by:
#     src/app/makelib/makelib.sublib



# A mechanism for keeping .compiled files for short periods of time.
#
#   This is used in "freeze" and in "make" where first there is a
#   "compile" dagwalk that produces certain compiledfile contents, and
#   then there is a "link" dagwalk that uses the compiledfile contents.
#
#   No error checking is done -- the "get" operation assumes that the
#   stuff is either in its cache or in the file system.
#
#   Moreover, the symbol table cannot be used (COMPILEDFILE::senvOf will fail
#   if the compiledfile had to be reloaded from disk).
#
#
#
#
# GENERIC INVOCATION
#
#     This facility is used by both the standard and bootstrap compilers,
#     which is to say that our generic is invoked in both of:
#
#         src/app/makelib/mythryl-compiler-compiler/mythryl-compiler-compiler-g.pkg
#         src/app/makelib/main/makelib-g.pkg


###                     "Though I'll admit readability suffers slightly..."
###
###                               -- Larry Wall in <2969@jato.Jpl.Nasa.Gov>


stipulate
    package cf  =  compiledfile;                                                                # compiledfile                  is from   src/lib/compiler/execution/compiledfile/compiledfile.pkg
    package tc  =  thawedlib_tome;                                                              # thawedlib_tome                is from   src/app/makelib/compilable/thawedlib-tome.pkg
herein

    api Thawedlib_Tome__To__Compiledfile__Map {
        #

        Component_Bytesizes
          =
          { symbolmapstack_bytesize:    Int,
            inlinables_bytesize:        Int,
            data_bytesize:              Int,
            code_bytesize:              Int
          };

        make__thawedlib_tome__to__compiledfile__map:
            Void
            ->
            { set__compiledfile__for__thawedlib_tome
                  :
                  { key:    tc::Thawedlib_Tome,
                    #
                    value:  { compiledfile:  cf::Compiledfile,
                              component_bytesizes:    Component_Bytesizes
                            }
                  }
                  ->
                  Void,

              get__compiledfile__for__thawedlib_tome
                  :
                  tc::Thawedlib_Tome
                  ->
                  { compiledfile:  cf::Compiledfile,
                    component_bytesizes:    Component_Bytesizes
                  }
            };


        get_compiledfile_from_freezefile
           :
           { freezefile_name:  String,
             offset:            Int,
             description:       String
           }
           ->
           cf::Compiledfile;
    };
end;

# We are invoked from:
#
#     src/app/makelib/main/makelib-g.pkg
#     src/app/makelib/mythryl-compiler-compiler/mythryl-compiler-compiler-g.pkg

stipulate
    package cf  =  compiledfile;                                                                # compiledfile                  is from   src/lib/compiler/execution/compiledfile/compiledfile.pkg
    package mcv =  mythryl_compiler_version;                                                    # mythryl_compiler_version      is from   src/lib/core/internal/mythryl-compiler-version.pkg
    package sa  =  supported_architectures;                                                     # supported_architectures       is from   src/lib/compiler/front/basics/main/supported-architectures.pkg
    package tc  =  thawedlib_tome;                                                              # thawedlib_tome                is from   src/app/makelib/compilable/thawedlib-tome.pkg
    package ttm =  thawedlib_tome_map;                                                          # thawedlib_tome_map            is from   src/app/makelib/compilable/thawedlib-tome-map.pkg
herein

    generic package   thawedlib_tome__to__compiledfile__map_g   (
        #             =======================================
        #
        architecture:   sa::Supported_Architectures;                                            # PWRPC32/SPARC32/INTEL32.
    )
    : Thawedlib_Tome__To__Compiledfile__Map                                                     # Thawedlib_Tome__To__Compiledfile__Map         is from   src/app/makelib/compile/thawedlib-tome--to--compiledfile-contents--map-g.pkg
    {

        Component_Bytesizes
            =
            { symbolmapstack_bytesize:  Int,
               inlinables_bytesize:     Int,
                     data_bytesize:     Int,
                     code_bytesize:     Int
            };

        compiler_version_id =  mcv::mythryl_compiler_version.compiler_version_id;               # Something like:       [110, 58, 3, 0, 2]


        fun make__thawedlib_tome__to__compiledfile__map ()
            =
            {   cache =  REF  ttm::empty;

                fun set__compiledfile__for__thawedlib_tome { key, value }
                    =
                    cache :=   ttm::set (*cache, key, value);


                fun get__compiledfile__for__thawedlib_tome   (key: tc::Thawedlib_Tome)
                    =
                    case (ttm::get (*cache, key))
                        #
                        THE value =>   value;
                        #
                        NULL =>
                            {   compiledfile_name
                                    =
                                    tc::make_compiledfile_name  key;

                                safely::do                                                                      # safely        is from   src/lib/std/safely.pkg
                                  {
                                    open_it    =>   {. data_file__premicrothread::open_for_read  compiledfile_name; },
                                    close_it   =>      data_file__premicrothread::close_input,
                                    cleanup    =>      \\ _ =  ()
                                  }
                                   {.   value =   cf::read_compiledfile
                                                  {
                                                    architecture,
                                                    compiler_version_id,                                        # Something like:  [110, 58, 3, 0, 2].  We get an error if first two don't match compiler version that made the file.
                                                    stream => #stream
                                                  };
                                        #
                                        set__compiledfile__for__thawedlib_tome { key, value };
                                        #
                                        value;
                                    };
                            };
                    esac;

                { set__compiledfile__for__thawedlib_tome,
                  get__compiledfile__for__thawedlib_tome
                };
            };

        fun get_compiledfile_from_freezefile
              {
                freezefile_name,
                offset,
                description
              }
            =
            {   safely::do
                    {
                      open_it  =>  {. data_file__premicrothread::open_for_read  freezefile_name; },
                      close_it =>     data_file__premicrothread::close_input,
                      cleanup  =>     \\ _ = ()
                    }
                   {.   # stream = #stream;

                        seek::seek ( #stream, file_position::from_int offset);

                        # We can use an empty symbol table
                        # because no unpickling will be done:
                        #
                        .compiledfile
                            (cf::read_compiledfile
                              {
                                architecture,
                                compiler_version_id,                                    # Something like:  [110, 58, 3, 0, 2].  We get an error back if first two don't match compiler version that generated the file.
                                stream => #stream
                              }
                            );
                    };
            };
    };
end;


Comments and suggestions to: bugs@mythryl.org

PreviousUpNext