PreviousUpNext

15.4.554  src/lib/compiler/front/basics/source/sourcecode-info.pkg

## sourcecode-info.pkg
#
# Here we record where the source code
# for a given compilation unit came from.
#
# Typically this will be a "foo.pkg" file
# in the host filesystem, but it might have
# been typed in interactively at the Mythryl
# prompt or such.
#
# We also track some related useful information
# such as where to send error messages generated
# while compiling the source code.

# Compiled by:
#     src/lib/compiler/front/basics/basics.sublib




###                     "Trust the Source, Luke."


stipulate
    package cp  =  control_print;                                       # control_print                 is from   src/lib/compiler/front/basics/print/control-print.pkg
    package fil =  file__premicrothread;                                # file__premicrothread          is from   src/lib/std/src/posix/file--premicrothread.pkg
    package iox =  io_exceptions;                                       # io_exceptions                 is from   src/lib/std/src/io/io-exceptions.pkg
    package lnd =  line_number_db;                                      # line_number_db                is from   src/lib/compiler/front/basics/source/line-number-db.pkg
    package pp  =  standard_prettyprinter;                              # standard_prettyprinter        is from   src/lib/prettyprint/big/src/standard-prettyprinter.pkg
herein

    package   sourcecode_info
    : (weak)  Sourcecode_Info                                           # Sourcecode_Info               is from   src/lib/compiler/front/basics/source/sourcecode-info.api
    {
        Sourcecode_Info
          =
          { line_number_db:     lnd::Sourcemap,
            file_opened:        String,
            saw_errors:         Ref( Bool ),
            #
            error_consumer:     pp::Prettyprint_Output_Stream,
            is_interactive:     Bool,                                   # 
            source_stream:      fil::Input_Stream                       # 
          };

        fun say (msg:  String)
            =
            cp::say msg;


        lexer_initial_position
            =
            2;                                                          #  Position of first char according to mythryl-lex :(

        fun make_sourcecode_info
              {
                file_name,                                              # Filename for source_stream, else "<Input_Stream>" or such.
                line_num,
                source_stream,
                is_interactive,
                error_consumer
              }
            =
            { source_stream,
              is_interactive,
              error_consumer,
              file_opened =>  file_name,
              saw_errors  =>  REF FALSE,
              line_number_db  =>  lnd::newmap (   lexer_initial_position, 
                                                     { file_name,
                                                       line   =>  line_num,
                                                       column =>  1
                                                      }
                                                 )
            };

        fun close_source ( { is_interactive=>TRUE, ... }: Sourcecode_Info)
                =>
                ();

            close_source ( { source_stream, ... } )
                =>
                {   fil::close_input  source_stream
                    except
                        iox::IO _ =  ();
                };
        end;

        fun filepos ( { line_number_db, ... }: Sourcecode_Info)  pos
            = 
            {   (lnd::filepos line_number_db  pos)
                    ->
                    { file_name, line, column };

                (file_name, line, column);
            };

    };                                      #  package sourcecode_info 
end;


## COPYRIGHT (c) 1996 Bell Laboratories.
## Subsequent changes by Jeff Prothero Copyright (c) 2010-2015,
## released per terms of SMLNJ-COPYRIGHT.


Comments and suggestions to: bugs@mythryl.org

PreviousUpNext