PreviousUpNext

15.4.229  src/lib/compiler/back/low/control/lowhalf-control.pkg

## lowhalf-control.pkg

# Compiled by:
#     src/lib/compiler/back/low/lib/control.lib



###         "One man's constant is another man's variable."
###
###                               -- Alan Perlis


stipulate
    package ci  =  global_control_index;                                # global_control_index          is from   src/lib/global-controls/global-control-index.pkg
    package cst =  global_control_set;                                  # global_control_set            is from   src/lib/global-controls/global-control-set.pkg
    package ctl =  global_control;                                      # global_control                is from   src/lib/global-controls/global-control.pkg
    package fil =  file__premicrothread;                                # file__premicrothread          is from   src/lib/std/src/posix/file--premicrothread.pkg
herein

    api Lowhalf_Control {
        #
        registry:  ci::Global_Control_Index;
        prefix:    String;
        menu_slot: ctl::Menu_Slot;

        Cpu_Time = { gc: time::Time, usr: time::Time, sys: time::Time };

        lowhalf:         Ref( Bool );                                   # Use the lowhalf optimizer? 
        lowhalf_phases:  Ref(  List(  String ) );                       # the optimization phases 
        debug_stream:    Ref( fil::Output_Stream );                     # Debugging output goes here 

        Global_Control_Set(X) = cst::Global_Control_Set( X, Ref(X)  ); 

        # Bools and counters:
        # 
        counters:     Global_Control_Set(  Int );
        ints:         Global_Control_Set(  Int );
        bools:        Global_Control_Set(  Bool );
        floats:       Global_Control_Set(  Float );
        strings:      Global_Control_Set(  String );
        string_lists: Global_Control_Set(  List(  String ) );
        timings:      Global_Control_Set(  Cpu_Time );

        make_counter:     (String, String) -> Ref( Int );
        make_int:         (String, String) -> Ref( Int );
        make_bool:        (String, String) -> Ref( Bool );
        make_float:       (String, String) -> Ref( Float );
        make_string:      (String, String) -> Ref( String );
        make_string_list: (String, String) -> Ref( List( String ) );
        make_timing:      (String, String) -> Ref( Cpu_Time );

        counter:       String -> Ref( Int );
        int:           String -> Ref( Int );
        bool:          String -> Ref( Bool );
        float:         String -> Ref( Float );
        string:        String -> Ref( String );
        string_list:   String -> Ref( List( String ) );
        timing:        String -> Ref( Cpu_Time );

        # The following is the old interface.  Its use is deprecated
        # since it does not provide documentation strings:
        #
        get_counter:      String -> Ref( Int );
        get_int:          String -> Ref( Int );
        get_bool:         String -> Ref( Bool );
        get_float:        String -> Ref( Float );
        get_string:       String -> Ref( String );
        get_string_list:  String -> Ref( List( String ) );
        get_timing:       String -> Ref( Cpu_Time );

    };
end;

stipulate
    package ci  =  global_control_index;                                # global_control_index          is from   src/lib/global-controls/global-control-index.pkg
    package cj  =  global_control_junk;                                 # global_control_junk           is from   src/lib/global-controls/global-control-junk.pkg
    package cst =  global_control_set;                                  # global_control_set            is from   src/lib/global-controls/global-control-set.pkg
    package ctl =  global_control;                                      # global_control                is from   src/lib/global-controls/global-control.pkg
    package fil =  file__premicrothread;                                # file__premicrothread          is from   src/lib/std/src/posix/file--premicrothread.pkg
    package qs  =  quickstring__premicrothread;                         # quickstring__premicrothread   is from   src/lib/src/quickstring--premicrothread.pkg
herein

    package   lowhalf_control
    : (weak)  Lowhalf_Control                                           # Lowhalf_Control               is from   src/lib/compiler/back/low/control/lowhalf-control.pkg
    {
        menu_slot =  [10, 3];
        obscurity =  3;
        prefix    =  "lowhalf";

        registry  =   ci::make { help => "LOWHALF" };

        Cpu_Time
            =
            { gc:  time::Time,
              usr: time::Time,
              sys: time::Time
            };

        Global_Control_Set(X) =   cst::Global_Control_Set( X, Ref(X) ); 

        counters      = cst::make_control_set (): Global_Control_Set( Int );
        ints          = cst::make_control_set (): Global_Control_Set( Int );
        bools         = cst::make_control_set (): Global_Control_Set( Bool );
        floats        = cst::make_control_set (): Global_Control_Set( Float );
        strings       = cst::make_control_set (): Global_Control_Set( String );
        string_lists  = cst::make_control_set (): Global_Control_Set( List(String) );
        timings       = cst::make_control_set (): Global_Control_Set( Cpu_Time );

        stipulate
            timing =  { name_of_type   =>  "timing",
                        from_string =>  \\ _ =  (NULL:  Null_Or( Cpu_Time )),
                        to_string   =>  \\ _ =  "<timing>"
                      };

            fun no  x =   NULL;
            fun yes x =   THE (cj::dn::to_upper "LOWHALF_" (ctl::name x));

            next_menu_slot = REF 0;

            fun make (set, convert, fallback, en) (stem, description)
                =
                case (cst::find (set, qs::from_string stem))
                    #              
                    THE { control, info => cell }
                        =>
                        cell;

                    NULL =>
                        {   cell      =   REF fallback;
                            menu_slot =  *next_menu_slot;

                            control   = ctl::make_control
                                            { name      =>  stem,
                                              menu_slot =>  [menu_slot],
                                              obscurity,
                                              help      =>  description,
                                              control   =>  cell
                                            };

                            next_menu_slot :=  menu_slot + 1;

                            ci::note_control
                                registry
                                {
                                  control         =>  ctl::make_string_control  convert  control,
                                  dictionary_name =>  en control
                                };

                            cst::set (set, control, cell);
                            cell;
                       };
                esac;

        herein

            fun make_counter x =   make (counters, cj::cvt::int,    0,     no ) x;
            fun make_int     x =   make (ints,     cj::cvt::int,    0,     yes) x;
            fun make_bool    x =   make (bools,    cj::cvt::bool,   FALSE, yes) x;
            fun make_float   x =   make (floats,   cj::cvt::float,  0.0,   yes) x;
            fun make_string  x =   make (strings,  cj::cvt::string, "",    yes) x;

            fun make_string_list x
                =
                make (string_lists, cj::cvt::string_list, [], yes) x;

            fun make_timing x
                =
                make (
                    timings,
                    timing,
                    { gc =>time::zero_time,
                      usr=>time::zero_time,
                      sys=>time::zero_time
                    },
                    no
                )
                x;

            lowhalf        =  make_bool ("lowhalf", "?");
            lowhalf_phases =  make_string_list ("phases", "LOWHALF phases");
            debug_stream   =  REF fil::stdout;

        end;

        stipulate
            fun find set stem
                =
                case (cst::find (set, qs::from_string stem))
                    #
                    THE { control, info => cell } =>   cell;
                    NULL                          =>   raise exception DIE ("controls::lowhalf: no such control: " + stem);
                esac;
        herein

            counter = find counters;
            int     = find ints;
            bool    = find bools;
            float   = find floats;
            string  = find strings;
            timing  = find timings;

            string_list = find string_lists;
        end;


        stipulate
            fun old_for  make_foo  s
                =
                make_foo (s, s + " setting");
        herein

            get_counter = old_for make_counter;
            get_int     = old_for make_int;
            get_bool    = old_for make_bool;
            get_float   = old_for make_float;
            get_string  = old_for make_string;
            get_timing  = old_for make_timing;

            get_string_list = old_for make_string_list;
        end;
    };
end;


Comments and suggestions to: bugs@mythryl.org

PreviousUpNext