PreviousUpNext

15.4.305  src/lib/compiler/back/low/main/nextcode/per-codetemp-heapcleaner-info.pkg

# per-codetemp-heapcleaner-info.pkg
#
# Here we define info to be attached to codetemps
# for the benefit of the heapcleaner.
#
# This appears to be another project started but never finished;
# activation is controlled by the always-FALSE
#
#     lowhalf_track_heapcleaner_type_info
#
# flag in
#
#     src/lib/compiler/back/low/main/main/translate-nextcode-to-treecode-g.pkg
#
# The other relevant files are:
#
#     src/lib/compiler/back/low/heapcleaner-safety/per-codetemp-heapcleaner-info-template.api
#     src/lib/compiler/back/low/main/nextcode/per-codetemp-heapcleaner-info.api
#     src/lib/compiler/back/low/heapcleaner-safety/codetemps-with-heapcleaner-info.api
#     src/lib/compiler/back/low/heapcleaner-safety/codetemps-with-heapcleaner-info-g.pkg

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



#DO set_control "compiler::trap_int_overflow" "TRUE";

stipulate
    package ncf =   nextcode_form;                                                              # nextcode_form                 is from   src/lib/compiler/back/top/nextcode/nextcode-form.pkg
herein

    # This package is used (only) in:
    #
    #     src/lib/compiler/back/low/main/main/translate-nextcode-to-treecode-g.pkg
    #
    # where it is passed as argument to the generic package
    #
    #     src/lib/compiler/back/low/heapcleaner-safety/codetemps-with-heapcleaner-info-g.pkg
    #
    package   per_codetemp_heapcleaner_info
    : (weak)  Per_Codetemp_Heapcleaner_Info                                                     # Per_Codetemp_Heapcleaner_Info is from   src/lib/compiler/back/low/main/nextcode/per-codetemp-heapcleaner-info.api
    {
        Type = Int;

        Heapcleaner_Info
          = CONST   multiword_int::Int                                          # Integer constant.
          | NONREF  Ref( ncf::Type )                                    # Non-reference value.
          | HC_REF  Ref( ncf::Type )                                    # A reference, pointer to a heapchunk(?).
          | PLUS    (Type, Heapcleaner_Info, Heapcleaner_Info)          # Address arithmetic +
          | MINUS   (Type, Heapcleaner_Info, Heapcleaner_Info)          # Address arithmetic -
          | HEAP_ALLOCATION_POINTER                                     # We allot heap memory by advancing this pointer.
          | HEAP_ALLOCATION_LIMIT                                       # We may not allot memory beyond this point.
          | BOT
          | TOP
          ;

        const = CONST;
        bot   = BOT;
        top   = TOP;

        fun to_string BOT       => "bot";
            to_string TOP       => "top";
            to_string (CONST i) => multiword_int::to_string i;
            #
            to_string (NONREF (REF chunk)) =>  ncf::cty_to_string chunk;
            to_string (HC_REF (REF chunk)) =>  ncf::cty_to_string chunk;
            to_string (PLUS  (type, a, b)) =>  "(" + to_string a + "+" + to_string b + ")";
            to_string (MINUS (type, a, b)) =>  "(" + to_string a + "-" + to_string b + ")";
            #
            to_string HEAP_ALLOCATION_POINTER => "heap_allocation_pointer";
            to_string HEAP_ALLOCATION_LIMIT   => "heap_allocation_limit";
        end;

        fun ==== (x: Heapcleaner_Info, y: Heapcleaner_Info)
            =
            x == y;

        fun join (BOT, x) => x;
            join (x, BOT) => x;
            join (TOP, x) => TOP;
            join (x, TOP) => TOP;
            join (x, y)   => x;
        end;                                    # XXX

        fun meet (BOT, x) => BOT; 
            meet (x, BOT) => BOT; 
            meet (TOP, x) => x; 
            meet (x, TOP) => x; 
            meet (x, y)   => x;
        end;                                    # XXX

        i31_type =  NONREF (REF ncf::typ::INT);                                 #   Tagged integers.
        i32_type =  NONREF (REF ncf::typ::INT1);                                # Untagged integers.
        f64_type =  NONREF (REF ncf::typ::FLOAT64);                             # Untagged floats.

        ptr_type =  HC_REF (REF (ncf::typ::POINTER ncf::VPT));                  # Boxed chunks (pointers).
        int_type =  i32_type;                                                   # Untagged integer.
        f32_type =  TOP;                                                        # Unused in Mythryl.

        fun add (_, TOP, x) => TOP;
            add(_, x, TOP) => TOP;
            add (type, CONST i, CONST j) => (CONST (multiword_int::(+) (i, j)) except OVERFLOW = int_type);
      #     add (type, CONST 0, b) = b
      #     add (type, b, CONST 0) = b
            add (type, CONST _, NONREF _) => int_type;
            add (type, NONREF _, CONST _) => int_type;
            add (type, x as NONREF a, y as NONREF b) =>  if (a == b)  x;
                                                         else         int_type;
                                                         fi;
            add (type, x, y)  => PLUS (type, x, y);
        end;

        fun sub (_, TOP, x) => TOP;
            sub(_, x, TOP) => TOP;
            sub (type, CONST i, CONST j) => (CONST (multiword_int::(+) (i, j)) except OVERFLOW = int_type);
        #   sub (type, a, CONSTS 0) = a;
            sub (type, CONST _, NONREF _) => int_type;
            sub (type, NONREF _, CONST _) => int_type;
            sub (type, x as NONREF a, y as NONREF b) => if (a == b)  x;
                                                        else         int_type;
                                                        fi;
            sub (type, x, y)  => MINUS (type, x, y);
        end;

        fun is_recoverable TOP =>  FALSE;
            is_recoverable BOT =>  FALSE;                               # XXX
            is_recoverable _   =>  TRUE;
        end;

        exception HCTYPE  Heapcleaner_Info;

        cleaner_type
            =
            note::make_notekind'
              {
                to_string,
                #
                x_to_note   =>  HCTYPE,
                #
                get         =>  \\ HCTYPE x => x;
                                   e        => raise exception e;
                                end
              };
    };
end;


Comments and suggestions to: bugs@mythryl.org

PreviousUpNext