PreviousUpNext

15.4.625  src/lib/compiler/front/typer-stuff/types/core-type-types.pkg

## core-type-types.pkg
#
# Define some really basic bool/int/string/... type stuff.
# Later this gets expanded upon in
#
#     src/lib/compiler/front/typer/types/type-types.pkg

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



# a generic part of type-types.pkg (not Mythryl-specific)

stipulate
    package ip  =  inverse_path;                                        # inverse_path                  is from   src/lib/compiler/front/typer-stuff/basics/symbol-path.pkg
    package ptn =  core_basetype_numbers;                               # core_basetype_numbers         is from   src/lib/compiler/front/typer-stuff/basics/core-basetype-numbers.pkg
    package sta =  stamp;                                               # stamp                         is from   src/lib/compiler/front/typer-stuff/basics/stamp.pkg
    package sy  =  symbol;                                              # symbol                        is from   src/lib/compiler/front/basics/map/symbol.pkg
    package ty  =  types;                                               # types                         is from   src/lib/compiler/front/typer-stuff/types/types.pkg
    package vh  =  varhome;                                             # varhome                       is from   src/lib/compiler/front/typer-stuff/basics/varhome.pkg
herein

    package core_type_types: (weak)  api {

        arrow_stamp:            sta::Stamp;
        arrow_typ:              ty::Typ;
        --> :                   (ty::Type,   ty::Type) -> ty::Type;

        ref_stamp:              sta::Stamp;

        ref_typ_sym:            sy::Symbol;
        ref_con_sym:            sy::Symbol;

        ref_typ:                ty::Typ;
        ref_dcon:               ty::Valcon;
        ref_pattern_type:       ty::Type;

        bool_stamp:             sta::Stamp;
        bool_sym:               sy::Symbol;
        false_sym:              sy::Symbol;
        true_sym:               sy::Symbol;

        bool_signature: vh::Valcon_Signature;


        void_symbol:            sy::Symbol;

        # The Typ/Type distinction below is purely technical.
        # Essentially, 'Typ' covers what one usually thinks of as types,
        # while 'Type' contains 'Typ' plus stuff like wildcard types,
        # type variables and type schemes.  Depending on code context,
        # sometimes we need one and sometimes the other, so we provide both.
        # For details see:
        #
        #     src/lib/compiler/front/typer-stuff/types/types.pkg

        void_typ:               ty::Typ;
        void_type:              ty::Type;

        bool_typ:               ty::Typ;
        bool_type:              ty::Type;

        false_dcon:             ty::Valcon;
        true_dcon:              ty::Valcon;

        int_typ:                ty::Typ;
        int_type:               ty::Type;

        string_typ:             ty::Typ;
        string_type:            ty::Type;

        char_typ:               ty::Typ;
        char_type:              ty::Type;

        float64_typ:            ty::Typ;
        float64_type:           ty::Type;

        exception_typ:          ty::Typ;
        exception_type:         ty::Type;

        rw_vector_typ:          ty::Typ;
        vector_typ:             ty::Typ;

        tuple_type:             List( ty::Type ) -> ty::Type;
        record_type:            List( (ty::Label, ty::Type) ) -> ty::Type;
    }

    {

        arrow_stamp     =  sta::make_stale_stamp "->";
        ref_stamp       =  sta::make_stale_stamp "REF";
        bool_stamp      =  sta::make_stale_stamp "Bool";

        void_symbol     =  sy::make_type_symbol "Void";
        ref_typ_sym     =  sy::make_type_symbol "Ref";
        ref_con_sym     =  sy::make_value_symbol "REF";

        bool_sym        = sy::make_type_symbol  "Bool";
        false_sym       = sy::make_value_symbol "FALSE";
        true_sym        = sy::make_value_symbol "TRUE";

        fun tc2t typ
            =
            ty::TYPCON_TYPE (typ, []);

        void_typ
            =
            ty::DEFINED_TYP {
                stamp        => sta::make_stale_stamp "Void",
                strict       => [],
                path         => ip::INVERSE_PATH [void_symbol],
                type_scheme => ty::TYPE_SCHEME { arity => 0,
                                                 body  => ty::TYPCON_TYPE (tuples::make_tuple_typ 0, [])
                                               }
            };

        void_type   =   tc2t void_typ;

        fun pt2tc (symbol, arity, equality_property, ptn)
            =
            ty::PLAIN_TYP
              {
                stamp   =>  sta::make_stale_stamp symbol,
                path    =>  ip::INVERSE_PATH [sy::make_type_symbol symbol],
                arity,
                #
                eqtype_info =>  REF equality_property,
                kind    =>  ty::BASE ptn,
                stub    =>  NULL
              };

        fun pt2tct args
            =
            {   typ = pt2tc args;

                (typ, tc2t typ);
            };

        # This stuff is duplicated here and   src/lib/compiler/front/typer-stuff/types/core-basic-types.pkg
        # -- can't we factor the duplication out somehow?   XXX BUGGO FIXME

        my (      int_typ,      int_type)  =  pt2tct ("Int",       0, ty::eq_type::YES, ptn::basetype_number_int        );
        my (   string_typ,    string_type) =  pt2tct ("String",    0, ty::eq_type::YES, ptn::basetype_number_string     );
        my (     char_typ,      char_type) =  pt2tct ("Char",      0, ty::eq_type::YES, ptn::basetype_number_int        );
        my (  float64_typ,   float64_type) =  pt2tct ("Float",     0, ty::eq_type::NO,  ptn::basetype_number_float64  );
        my (exception_typ, exception_type) =  pt2tct ("Exception", 0, ty::eq_type::NO,  ptn::basetype_number_exn        );

        rw_vector_typ =  pt2tc ("Rw_Vector",  1, ty::eq_type::CHUNK, ptn::basetype_number_rw_vector );
        vector_typ    =  pt2tc ("Vector",     1, ty::eq_type::YES,   ptn::basetype_number_vector);

        arrow_typ
            =
            ty::PLAIN_TYP
              {
                stamp   =>  arrow_stamp,
                path    =>  ip::INVERSE_PATH [sy::make_type_symbol "->"],
                arity   =>  2,
                #
                eqtype_info =>  REF ty::eq_type::NO,
                kind    =>  ty::BASE  ptn::basetype_number_arrow,
                stub    =>  NULL
              };

        infix my  --> ;

        fun t1 --> t2
            =
            ty::TYPCON_TYPE (arrow_typ, [t1, t2]);

        fun record_type (fields: List( (ty::Label, ty::Type)) )
            =
            ty::TYPCON_TYPE (tuples::make_record_typ (map #1 fields), map #2 fields);

        fun tuple_type types
            =
            ty::TYPCON_TYPE (tuples::make_tuple_typ (length types), types);

        my (ref_typ, ref_pattern_type, ref_dcon)
            =
            {   eq_ref   = REF ty::eq_type::CHUNK;
                alpha    = ty::TYPE_SCHEME_ARG_I 0;
                ref_dom  = alpha;
                refsign  = vh::CONSTRUCTOR_SIGNATURE (1, 0);

                ref_typ = ty::PLAIN_TYP
                              {
                                stub    =>  NULL,
                                stamp   =>  ref_stamp,
                                path    =>  ip::INVERSE_PATH [ ref_typ_sym ],
                                #
                                arity   =>  1,
                                eqtype_info =>  eq_ref,
                                kind    =>  ty::DATATYPE
                                              {
                                                index    => 0,
                                                stamps   => #[ref_stamp],
                                                free_typs => [],
                                                root     => NULL,
                                                family   =>   { property_list => property_list::make_property_list (),
                                                                mkey          => ref_stamp,
                                                                members       =>   #[ { typ_name =>  ref_typ_sym,
                                                                                        eqtype_info  =>  eq_ref,
                                                                                        is_lazy  =>  FALSE,
                                                                                        arity    =>  1,
                                                                                        an_api   =>  vh::CONSTRUCTOR_SIGNATURE (1, 0),
                                                                                        #       
                                                                                        constructor_list => [  { name   =>  ref_con_sym,
                                                                                                                 form   =>  vh::REFCELL_REP,
                                                                                                                 domain =>  THE ref_dom
                                                                                                               }
                                                                                                            ]
                                                                                      }
                                                                                    ]


                                                           }
                                        }
                              };

                ref_tyfun
                    =
                    ty::TYPE_SCHEME { arity => 1, body => alpha --> ty::TYPCON_TYPE (ref_typ, [alpha]) };

                ref_pattern_type
                    =
                    ty::TYPE_SCHEME_TYPE {
                        type_scheme_arg_eq_properties => [FALSE],
                        type_scheme => ref_tyfun
                    };

                ref_dcon = ty::VALCON
                            {
                              name        =>  ref_con_sym,
                              is_constant =>  FALSE,
                              is_lazy     =>  FALSE,
                              form        =>  vh::REFCELL_REP,
                              type        =>  ref_pattern_type,
                              signature   =>  refsign
                            };

                (ref_typ, ref_pattern_type, ref_dcon);
            };

        bool_signature = vh::CONSTRUCTOR_SIGNATURE (0, 2);

        my (bool_typ, bool_type, false_dcon, true_dcon)
            =
            {   booleq = REF ty::eq_type::YES;

                bool_typ
                    =
                    ty::PLAIN_TYP
                      {
                        stamp   =>  bool_stamp,
                        path    =>  ip::INVERSE_PATH [bool_sym],
                        arity   =>  0,
                        #
                        eqtype_info =>  booleq,
                        stub    =>  NULL,
                        kind    =>  ty::DATATYPE
                                      {
                                        index     =>  0,
                                        stamps    =>  #[ bool_stamp ],
                                        free_typs =>  [],
                                        root      =>  NULL,
                                        family    =>  { property_list =>  property_list::make_property_list (),
                                                        mkey          =>  bool_stamp,
                                                        #
                                                        members       => #[   { typ_name =>  bool_sym,
                                                                                eqtype_info  =>  booleq,
                                                                                is_lazy  =>  FALSE,
                                                                                arity    =>  0,
                                                                                an_api   =>  bool_signature,
                                                                                #
                                                                                constructor_list =>   [  { name   => false_sym,
                                                                                                           form   => vh::CONSTANT 0,
                                                                                                           domain => NULL
                                                                                                         },
                                                                                                         { name   => true_sym,
                                                                                                           form   => vh::CONSTANT 1,
                                                                                                           domain => NULL
                                                                                                         }
                                                                                                     ]
                                                                         }
                                                                     ]


                                                   }
                                }
                    };

                bool_type = ty::TYPCON_TYPE (bool_typ, []);

                false_dcon = ty::VALCON
                               {
                                 name             => false_sym,
                                 is_constant      => TRUE,
                                 is_lazy          => FALSE,
                                 form             => vh::CONSTANT 0,
                                 type => bool_type,
                                 signature        => bool_signature
                               };

                true_dcon = ty::VALCON
                              {
                                name             => true_sym,
                                is_constant      => TRUE,
                                is_lazy          => FALSE,
                                form             => vh::CONSTANT 1,
                                type             => bool_type,
                                signature        => bool_signature
                              };

                (bool_typ, bool_type, false_dcon, true_dcon);
            };
    };
end;



Comments and suggestions to: bugs@mythryl.org

PreviousUpNext