PreviousUpNext

15.4.700  src/lib/compiler/toplevel/interact/read-eval-print-loops-g.pkg

## read-eval-print-loops-g.pkg
#
# Here we define the backend interactive-compilation
# facility exported to the front end.
#
# Our generic is invoked (only) by
#
#     src/lib/compiler/toplevel/compiler/mythryl-compiler-g.pkg
#
# Our generic argument is generated by read_eval_print_loop_g in
#
#     src/lib/compiler/toplevel/interact/read-eval-print-loop-g.pkg
#
#
# See also:
#     src/lib/core/init/read-eval-print-hook.pkg
#     src/lib/compiler/toplevel/interact/read-eval-print-loop-g.pkg

# Compiled by:
#     src/lib/compiler/core.sublib





###         "Every society honors its live conformists
###                 and its dead troublemakers."
###
###                         -- Mignon McLaughlin


stipulate
    package cps =  compiler_state;                                                              # compiler_state                is from   src/lib/compiler/toplevel/interact/compiler-state.pkg
    package ctl =  global_controls;                                                             # global_controls               is from   src/lib/compiler/toplevel/main/global-controls.pkg
    package cts =  compiler_mapstack_set;                                                       # compiler_mapstack_set         is from   src/lib/compiler/toplevel/compiler-state/compiler-mapstack-set.pkg
    package err =  error_message;                                                               # error_message                 is from   src/lib/compiler/front/basics/errormsg/error-message.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 pl  =  property_list;                                                               # property_list                 is from   src/lib/src/property-list.pkg
    package wnx =  winix__premicrothread;                                                       # winix__premicrothread         is from   src/lib/std/winix--premicrothread.pkg
    package xns =  exceptions;                                                                  # exceptions                    is from   src/lib/std/exceptions.pkg
herein

    # This generic is invoked from:
    #
    #     src/lib/compiler/toplevel/compiler/mythryl-compiler-g.pkg
    #
    # which constructs the 'rpl' arg via an
    # invocation of read_eval_print_loop_g:                                                     # read_eval_print_loop_g        is from   src/lib/compiler/toplevel/interact/read-eval-print-loop-g.pkg
    #
    generic package   read_eval_print_loops_g   (
        #
        rpl:   Read_Eval_Print_Loop                                                             # Read_Eval_Print_Loop          is from   src/lib/compiler/toplevel/interact/read-eval-print-loop.api
    )
    : (weak)  Read_Eval_Print_Loops                                                             # Read_Eval_Print_Loops         is from   src/lib/compiler/toplevel/interact/read-eval-print-loops.api
    {
        exception CONTROL_C_SIGNAL
            =
            rpl::CONTROL_C_SIGNAL;


        Compiler_Mapstack_Set_Jar
            =
            cps::Compiler_Mapstack_Set_Jar;


        fun read_eval_print_from_script  script_name                                            # 'script_name'  can be "<stdin>" or the filename of the script.
            =
            {   rpl::read_eval_print_from_script  script_name;                                  # rpl::read_eval_print_from_script      is from   src/lib/compiler/toplevel/interact/read-eval-print-loop-g.pkg
                #
                wnx::process::exit  wnx::process::success;
            };

        fun read_eval_print_from_user ()
            =
            {   rpl::read_eval_print_from_user ();
                #
                wnx::process::exit  wnx::process::success;
            };

        parse_string_to_raw_declarations            =  rpl::parse_string_to_raw_declarations;
        compile_raw_declaration_to_package_closure  =  rpl::compile_raw_declaration_to_package_closure;
        link_and_run_package_closure                =  rpl::link_and_run_package_closure;

        with_exception_trapping
            =
            rpl::with_exception_trapping;


        fun read_eval_print_from_file   filename
            =
            {   apply
                    ctl::print::say
                    ["[includIng ", filename, "]\n"];

                rpl::read_eval_print_from_stream
                   (
                     filename,

                     fil::open_for_read filename
                     except
                        e as iox::IO _
                            =
                            {   apply ctl::print::say [ "[include failed: ",
                                                        xns::exception_message e,
                                                        "]\n"
                                                      ];

                                raise exception   err::COMPILE_ERROR;
                            }
                   );
            };
                                                                                                    # file__premicrothread                      is from   src/lib/std/src/posix/file--premicrothread.pkg
        fun read_eval_print_from_stream   stream
            =
            rpl::read_eval_print_from_stream
                ("<Input_Stream>", stream);

        fun evaluate_stream (stream, base_dictionary)
            =
            {   r =  REF  cts::null_compiler_mapstack_set;
                #
                baselevel_pkg_etc_defs_jar
                    =
                    { set_mapstack_set =>  \\ _  =  raise exception DIE "evaluate_stream: base.set",
                      get_mapstack_set =>  \\ () =  base_dictionary
                    };

                top_level_pkg_etc_defs_jar
                    =
                    { set_mapstack_set =>  \\ e  =   r := e,
                      get_mapstack_set =>  \\ () =  *r
                    };

                property_list =  pl::make_property_list ();

                compiler_state
                  =
                  { top_level_pkg_etc_defs_jar,
                    baselevel_pkg_etc_defs_jar,
                    property_list
                  };

                cps::run_thunk_in_compiler_state
                  (
                    \\ ()
                        =
                        {   rpl::read_eval_print_from_stream ("<Input_Stream>", stream);
                            *r;
                        },

                    compiler_state
                  );
            };

        stipulate
            include package   fate;                                                             # fate                  is from   src/lib/std/src/nj/fate.pkg
        herein

            my redump_heap_fate:   Ref( Fate( String ) )                                        # redump_heap_fate      is referenced (only) by redump_heap in   src/app/makelib/main/makelib-g.pkg
                =                                                                               # -- the 'String' is filename_for_heap_image.
                # Here we set 'redump_heap_fate' to a
                # dummy initial fate which simply does
                #
                #     raise exception DIE "redump_heap_fate init";
                #
                # when invoked.
                #
                # Since no code ever sets   redump_heap_fate
                # to a different value, this must be either
                # unfinished work or a trace remnant of code past:                              # XXX SUCKO FIXME.
                #       
                REF (call_with_current_fate                                                     # Value of this  call_with_current_fate  invocation winds up being  exception_raising_fate.
                        (\\ return_fate                                                         # Capture current fate as   return_fate  so we can continue it momentarily.
                            =
                            {   call_with_current_fate                                          # Establish a fate named
                                    (\\ exception_raising_fate                                  # 'exception_raising_fate'   which just does   raise exception DIE "redump_heap_fate init";
                                        =
                                        switch_to_fate  return_fate  exception_raising_fate);   # Resume   return_fate   with new   exception_raising_fate   as its arg, becoming the return value from the outer call_with_current_fate().

                                raise exception DIE "redump_heap called while  redump_heap_fate  still set to dummy initial value.";
                            }
                    )   );
        end;
    };                                                                                          #  generic package   read_eval_print_loops_g
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