PreviousUpNext

15.4.602  src/lib/compiler/front/typer-stuff/basics/varhome.pkg

## varhome.pkg  -- Representing where a variable lives and how to access its value at runtime.

# Compiled by:
#     src/lib/compiler/front/typer-stuff/typecheckdata.sublib



stipulate
    package tmp =  highcode_codetemp;                   # highcode_codetemp     is from   src/lib/compiler/back/top/highcode/highcode-codetemp.pkg
    package err =  error_message;                       # error_message         is from   src/lib/compiler/front/basics/errormsg/error-message.pkg
    package ph  =  picklehash;                          # picklehash            is from   src/lib/compiler/front/basics/map/picklehash.pkg
herein 

    package   varhome
    : (weak)  Varhome                                   # Varhome               is from   src/lib/compiler/front/typer-stuff/basics/varhome.api
    {
        fun bug msg
            =
            err::impossible("Bugs in access: " + msg);


        Picklehash        =   ph::Picklehash;


        Varhome                                                 # How to find a variable's value at runtime.
          #
          = HIGHCODE_VARIABLE     tmp::Codetemp                 # A variable in the current compilation module.
          | PATH  (Varhome, Int)                                # A value/variable/fn in some other compilation module.
          | EXTERN  Picklehash                                  # Another module. Usually used in a PATH.
          | NO_VARHOME                                          # Everything else. :-)
          ;



        Valcon_Form                     # Picking representations for data constructors.
          #
          = UNTAGGED                            #  30 bit + 00; a pointer 
          | TAGGED      Int                     #  A pointer; 1st field is the tag 
          | TRANSPARENT                         #  32 bit value 
          | CONSTANT    Int                     #  tagged_int 
          #
          | REFCELL_REP
          | EXCEPTION   Varhome
          | SUSPENSION  Null_Or( (Varhome, Varhome) )
          #
          | LISTCONS                              
          | LISTNIL
          ;
          #


        Valcon_Signature 
          #
          = CONSTRUCTOR_SIGNATURE  (Int, Int)
          | NULLARY_CONSTRUCTOR
          ;

        # ***************************************************************************
        #                    UTILITY FUNCTIONS ON VARHOME                            *
        # ***************************************************************************


        # Print an Varhome value:
        #
        fun print_varhome (HIGHCODE_VARIABLE i) =>  "HIGHCODE_VARIABLE(" + tmp::to_string i + ")";
            print_varhome (PATH (a, i))         =>  "PATH(" + int::to_string i + ", "+ print_varhome a + ")";
            print_varhome (EXTERN pid)          =>  "EXTERN(" + ph::to_hex pid + ")";
            print_varhome (NO_VARHOME)         =>  "NO_VARHOME";
        end;


        # Print a Valcon_Form value: 
        #
        fun print_representation (UNTAGGED)      =>  "UT";
            print_representation (TAGGED i)      =>  "TG(" + int::to_string i + ")";
            print_representation (TRANSPARENT)   =>  "TN";
            print_representation (CONSTANT i)    =>  "CN(" + int::to_string i + ")";
            print_representation (REFCELL_REP)   =>  "RF";
            print_representation (EXCEPTION acc) =>  "EXCEPTION" + print_varhome acc;
            print_representation (LISTCONS)      =>  "LC";
            print_representation (LISTNIL)       =>  "LN";
            print_representation (SUSPENSION _)  =>  "SS";
        end;


        # Print a constructor api value:
        #
        fun print_constructor_api (CONSTRUCTOR_SIGNATURE (i, j))
                =>
                "B" + int::to_string i + "U" + int::to_string j;

            print_constructor_api (NULLARY_CONSTRUCTOR)
                =>
                "CNIL";
        end;


        # Testing whether a Valcon_Form is an exception:
        #
        fun is_exception (EXCEPTION _) =>   TRUE;
            is_exception _             =>   FALSE;
        end;


        # Fetch a component out of a package varhome:
        #
        fun select_varhome (NO_VARHOME, _)
                =>
                NO_VARHOME; #  Bug  "Selecting from a NO_VARHOME !" 

            select_varhome (p, i)
                =>
                PATH (p, i);
        end;


        # Duplicating a varhome variable:
        #
        fun duplicate_varhome (v, make_var)
            =
            HIGHCODE_VARIABLE (make_var (tmp::highcode_codetemp_to_value_symbol (v)));


        fun named_varhome (s, make_var) =  HIGHCODE_VARIABLE (make_var (THE s));
        fun make_varhome (make_var)     =  HIGHCODE_VARIABLE (make_var (NULL));
        fun external_varhome pid        =  EXTERN pid;
        null_varhome                    =  NO_VARHOME;


        fun highcode_variable_or_null (HIGHCODE_VARIABLE v) =>   THE v;
            highcode_variable_or_null _                     =>   NULL;
        end;
    };                                                                                  # package varhome
end;                                                                                    # stipulate


Comments and suggestions to: bugs@mythryl.org

PreviousUpNext