PreviousUpNext

15.4.287  src/lib/compiler/back/low/main/main/heap-tags.pkg

## heap-tags.pkg

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


# The encoding of heap-chunk description headers.
#
# This is a Mythryl-level version of
#
#     src/c/h/heap-tags.h
#
# WARNING: The following definitions must
#          stay in sync with those in:
#
#              src/c/h/heap-tags.h
#              src/lib/std/src/unsafe/unsafe-chunk.pkg
#              src/lib/core/init/core.pkg

stipulate
    package un  =  unt;         # unt           is from   src/lib/std/unt.pkg
    package lu  =  large_unt;   # large_unt     is from   src/lib/std/large-unt.pkg
herein

    package   heap_tags
    :         Heap_Tags                         # Heap_Tags     is from   src/lib/compiler/back/low/main/main/heap-tags.api
    {
        Btag = Unt;                             # Exported as opaque type to client packages.


        tag_width = 7;                          #  5 minor tag bits plus 2 major tag bits 
            #
            # WARNING: Above must track the
            #     src/c/h/heap-tags.h 
            # definition of
            #     TAGWORD_LENGTH_FIELD_SHIFT


        # 'max_length' is max value storable in
        # a tagword 'length' field, plus one.
        # (Sign should be 0.) 
        #
        max_length    = un::to_int (un::(<<) (0u1, un::(-) (0u31, un::from_int tag_width)));    # 64-BIT-ISSUE
        pow_tag_width = un::to_int (un::(<<) (0u1, un::from_int tag_width));                    # 1 << tag_width  ==  2**tag_width  ==   1 << 7  ==  0b10000000  ==  0x80.

        # Btag values:
        #
        stipulate
            fun make_btag t = un::bitwise_or (un::(<<) (t, 0u2), 0u2);
        herein
            # Note that our btags here are pre-shifted (and a-tagged)
            # relative to those in  src/c/h/heap-tags.h
            #
            pairs_and_records_btag                      = make_btag 0u0;
            ro_vector_header_btag                       = make_btag 0u1;
            rw_vector_header_btag                       = make_btag 0u2;
            rw_vector_data_btag                         = make_btag 0u3;
            four_byte_aligned_nonpointer_data_btag      = make_btag 0u4;
            eight_byte_aligned_nonpointer_data_btag     = make_btag 0u5;
            weak_pointer_or_suspension_btag             = make_btag 0u6;
            #
            ro_vector_data_btag =  pairs_and_records_btag;                                      # The cleaner does not need to distinguish read-only vector data records from other records.
            refcell_btag        =  rw_vector_data_btag;                                         # To the cleaner, a refcell is just a one-element vector.
        end;
            #
            # WARNING: The above must track the
            #     src/c/h/heap-tags.h
            # definitions
            #    #define PAIRS_AND_RECORDS_BTAG                         HEXLIT(  0 )            # Records (including pairs).
            #    #define RO_VECTOR_HEADER_BTAG                          HEXLIT(  1 )            # ro_vector header: length is C-tag.
            #    #define RW_VECTOR_HEADER_BTAG                          HEXLIT(  2 )            # rw_vector header: length is C-tag.
            #    #define RW_VECTOR_DATA_BTAG                            HEXLIT(  3 )            # typeagnostic rw_vector data.
            #    #define FOUR_BYTE_ALIGNED_NONPOINTER_DATA_BTAG         HEXLIT(  4 )            # 32-bit aligned non-pointer data.
            #    #define EIGHT_BYTE_ALIGNED_NONPOINTER_DATA_BTAG        HEXLIT(  5 )            # 64-bit aligned non-pointer data.
            #    #define WEAK_POINTER_OR_SUSPENSION_BTAG                HEXLIT(  6 )            # "Special chunk" (weak pointer or suspension): C-tag is stored in 'length' field.




        # Build a tagword from a B-tag and a length:                                            # The A-tag on a tagword is always 2.
        #
        fun make_tagword (len, btag)
            = 
            lu::bitwise_or (lu::(<<) (lu::from_int len, un::from_int tag_width), un::to_large_unt btag);

        # Codes for rw_vector/vector headers.
        #
        typeagnostic_vector_ctag = 0;
        vector_of_one_byte_unts_ctag     = 1;
        unt16_vector_ctag        = 2;
        tagged_int_vector_ctag   = 3;
        int1_vector_ctag         = 4;
        vector_of_four_byte_floats_ctag  = 5;
        vector_of_eight_byte_floats_ctag         = 6;
            #
            # WARNING: The above must track the
            #     src/c/h/heap-tags.h
            # definitions
            #   #define TYPEAGNOSTIC_VECTOR_CTAG                HEXLIT( 0 )
            #   #define VECTOR_OF_ONE_BYTE_UNTS_CTAG            HEXLIT( 1 )
            #   #define UNT16_VECTOR_CTAG                       HEXLIT( 2 )
            #   #define TAGGED_INT_VECTOR_CTAG                  HEXLIT( 3 )
            #   #define INT1_VECTOR_CTAG                        HEXLIT( 4 )     // Never used.
            #   #define VECTOR_OF_FOUR_BYTE_FLOATS_CTAG         HEXLIT( 5 )
            #   #define VECTOR_OF_EIGHT_BYTE_FLOATS_CTAG        HEXLIT( 6 )

        # Fixed descriptors:                                    length  / c-tag             b-tag
        #                                                     -----------------------  ------------------------------------------
        pair_tagword                        =  make_tagword (                       2, pairs_and_records_btag                   );
        refcell_tagword                     =  make_tagword (                       1, refcell_btag                             );
        float64_tagword                     =  make_tagword (                       2, eight_byte_aligned_nonpointer_data_btag  );
        typeagnostic_ro_vector_tagword      =  make_tagword (typeagnostic_vector_ctag, ro_vector_header_btag                    );
        typeagnostic_rw_vector_tagword      =  make_tagword (typeagnostic_vector_ctag, rw_vector_header_btag                    );
        weak_pointer_or_suspension_tagword  =  make_tagword (                       0, weak_pointer_or_suspension_btag          );


        # "Special" (everything-else) descriptors.
        #
        unevaluated_lazy_suspension_ctag =  0;
        evaluated_lazy_suspension_ctag   =  1;
        weak_pointer_ctag                =  2;
        nulled_weak_pointer_ctag         =  3;
            #
            # The above must track the
            #     src/c/h/heap-tags.h
            # definitions
            #     #define UNEVALUATED_LAZY_SUSPENSION_CTAG      0
            #     #define   EVALUATED_LAZY_SUSPENSION_CTAG      1
            #     #define                WEAK_POINTER_CTAG      2
            #     #define         NULLED_WEAK_POINTER_CTAG      3
            # and the
            #     src/lib/core/init/core.pkg
            # definitions
            #     unevaluated_lazy_suspension_ctag =  0;
            #       evaluated_lazy_suspension_ctag =  1;
            # and the
            #     src/lib/std/src/nj/weak-reference.pkg
            # definition
            #     weak_pointer_ctag = 2;
    };
end;



## COPYRIGHT (c) 1998 Bell Labs, Lucent Technologies.
## Subsequent changes by Jeff Prothero Copyright (c) 2010-2015,
## released per terms of SMLNJ-COPYRIGHT.


Comments and suggestions to: bugs@mythryl.org

PreviousUpNext