PreviousUpNext

15.4.604  src/lib/compiler/front/typer-stuff/deep-syntax/deep-syntax.pkg

## deep-syntax.pkg
## (C) 2001 Lucent Technologies, Bell Labs

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



# Deep syntax.  The typechecker accepts a raw syntax
# expression and returns a deep syntax expression.
#
# Raw syntax is defined in
#     src/lib/compiler/front/parser/raw-syntax/raw-syntax.api
#     src/lib/compiler/front/parser/raw-syntax/raw-syntax.pkg
#
# Deep syntax differs from raw syntax primarily in
# that (surprise) everything now has an associated
# type.
#
# Deep syntax, per se, is also much simpler, since
# much of the complexity of raw syntax relates to
# type declarations etc, which stuff is handed off
# to module.{ sig|sml }, types.api etc.


###                  A gift of great utility
###                    is common copability:
###                  the knack of getting
###                    each thing done
###                  before the grind
###                    has spoiled the fun.
###       
###                             -- Piet Hein



stipulate
    package fix =  fixity;                                                      # fixity                        is from   src/lib/compiler/front/basics/map/fixity.pkg
    package mld =  module_level_declarations;                                   # module_level_declarations     is from   src/lib/compiler/front/typer-stuff/modules/module-level-declarations.pkg
    package sp  =  symbol_path;                                                 # symbol_path                   is from   src/lib/compiler/front/typer-stuff/basics/symbol-path.pkg
    package sxe =  symbolmapstack_entry;                                        # symbolmapstack_entry          is from   src/lib/compiler/front/typer-stuff/symbolmapstack/symbolmapstack-entry.pkg
    package sy  =  symbol;                                                      # symbol                        is from   src/lib/compiler/front/basics/map/symbol.pkg
    package vac =  variables_and_constructors;                                  # variables_and_constructors    is from   src/lib/compiler/front/typer-stuff/deep-syntax/variables-and-constructors.pkg
    package ty  =  types;                                                       # types                         is from   src/lib/compiler/front/typer-stuff/types/types.pkg
herein

    package   deep_syntax
    : (weak)  Deep_Syntax                                                       # Deep_Syntax           is from   src/lib/compiler/front/typer-stuff/deep-syntax/deep-syntax.api
    {
        Source_Code_Region =   raw_syntax::Source_Code_Region;                  #  = Int * Int 



        Numbered_Label
            =
            NUMBERED_LABEL
              { name:   sy::Symbol,
                number: Int
              };



        Deep_Expression
          #
          = VARIABLE_IN_EXPRESSION             (Ref( vac::Variable ), List( ty::Type ))
          | VALCON_IN_EXPRESSION             (ty::Valcon, List( ty::Type ))
          | INT_CONSTANT_IN_EXPRESSION         (multiword_int::Int, ty::Type)
          | UNT_CONSTANT_IN_EXPRESSION         (multiword_int::Int, ty::Type)
          | FLOAT_CONSTANT_IN_EXPRESSION       String
          | STRING_CONSTANT_IN_EXPRESSION      String
          | CHAR_CONSTANT_IN_EXPRESSION        String
          | RECORD_IN_EXPRESSION                  List ((Numbered_Label, Deep_Expression))
          | RECORD_SELECTOR_EXPRESSION         (Numbered_Label, Deep_Expression)           #  record selections 
          | VECTOR_IN_EXPRESSION                  (List( Deep_Expression ), ty::Type)        
          | ABSTRACTION_PACKING_EXPRESSION     (Deep_Expression, ty::Type, List( ty::Typ ))          #  Abstraction packing 
          | APPLY_EXPRESSION                   (Deep_Expression, Deep_Expression)
          | EXCEPT_EXPRESSION                  (Deep_Expression, Fnrules)
          | RAISE_EXPRESSION                   (Deep_Expression, ty::Type)              
          | CASE_EXPRESSION                    (Deep_Expression, List( Case_Rule ), Bool)     # TRUE: match (fun/fn); FALSE: bind (my (...)=...)        This should be a separate datatype for readability:  Case_Context = DOING_MATCH | DOING_BIND;   XXX SUCKO FIXME.
          | AND_EXPRESSION                     (Deep_Expression, Deep_Expression)
          | OR_EXPRESSION                      (Deep_Expression, Deep_Expression)
          | FN_EXPRESSION                      Fnrules
          | LET_EXPRESSION                     (Declaration, Deep_Expression)
          | SEQUENTIAL_EXPRESSIONS             List( Deep_Expression )
          | TYPE_CONSTRAINT_EXPRESSION         (Deep_Expression, ty::Type)         

          | WHILE_EXPRESSION  {   test:       Deep_Expression,
                                  expression: Deep_Expression
                              }

          | IF_EXPRESSION     {   test_case: Deep_Expression,
                                  then_case: Deep_Expression,
                                  else_case: Deep_Expression
                              }

          | SOURCE_CODE_REGION_FOR_EXPRESSION  (Deep_Expression, Source_Code_Region)



        also
        Case_Rule
          #
          = CASE_RULE  (Case_Pattern, Deep_Expression)



        also
        Case_Pattern 
          #
          = WILDCARD_PATTERN
          | VARIABLE_IN_PATTERN            vac::Variable
          | INT_CONSTANT_IN_PATTERN       (multiword_int::Int, ty::Type)
          | UNT_CONSTANT_IN_PATTERN       (multiword_int::Int, ty::Type)
          | FLOAT_CONSTANT_IN_PATTERN      String
          | STRING_CONSTANT_IN_PATTERN     String
          | CHAR_CONSTANT_IN_PATTERN       String
          | CONSTRUCTOR_PATTERN            (ty::Valcon, List( ty::Type ))
          | APPLY_PATTERN                  (ty::Valcon, List( ty::Type ), Case_Pattern)
          | TYPE_CONSTRAINT_PATTERN        (Case_Pattern, ty::Type)
          | AS_PATTERN                     (Case_Pattern, Case_Pattern)
          | OR_PATTERN                     (Case_Pattern, Case_Pattern)
          | VECTOR_PATTERN                 (List( Case_Pattern ), ty::Type)       
          | NO_PATTERN
          | RECORD_PATTERN                 { fields:         List( (ty::Label, Case_Pattern) ),
                                             is_incomplete:  Bool,
                                             type_ref:       Ref( ty::Type )
                                           }



        also
        Declaration     
          #
          = VALUE_DECLARATIONS               List( Named_Value )                 #  Always a single element list 
          | RECURSIVE_VALUE_DECLARATIONS     List( Named_Recursive_Values )
          | TYPE_DECLARATIONS                List( ty::Typ )
          #
          | EXCEPTION_DECLARATIONS           List( Named_Exception )
          | PACKAGE_DECLARATIONS             List( Named_Package )
          | GENERIC_DECLARATIONS             List( Named_Generic )
          #
          | API_DECLARATIONS                 List( mld::Api )
          | GENERIC_API_DECLARATIONS         List( mld::Generic_Api )
          #
          | INCLUDE_DECLARATIONS             List ((sp::Symbol_Path, mld::Package))
          | LOCAL_DECLARATIONS               (Declaration, Declaration)
          | SEQUENTIAL_DECLARATIONS          List( Declaration )
          #
          | OVERLOADED_VARIABLE_DECLARATION  vac::Variable
          #
          | FIXITY_DECLARATION               { fixity: fix::Fixity,
                                               ops:    List( sy::Symbol )
                                             } 
          #
          | ENUM_DECLARATIONS                { datatyps:  List( ty::Typ ),
                                               with_typs: List( ty::Typ )
                                             }
          #
          | ABSTRACT_TYPE_DECLARATION        { abstract_typs: List( ty::Typ ),
                                               with_typs:     List( ty::Typ ),
                                               body:                       Declaration
                                             }
          #
          | SOURCE_CODE_REGION_FOR_DECLARATION  (Declaration, Source_Code_Region)



        # The "parameter_types" field in COMPUTED_PACKAGE
        # is used to record the list of macro expanded
        # higher order type constructors passed to generic
        # during the generic application.
        #
        also
        Package_Expression 
          #
          = PACKAGE_BY_NAME     mld::Package 
          | PACKAGE_DEFINITION  List( sxe::Symbolmapstack_Entry )
          #
          | PACKAGE_LET         { declaration:       Declaration,
                                  expression:        Package_Expression
                                }
          | COMPUTED_PACKAGE    { a_generic:         mld::Generic,
                                  generic_argument:  mld::Package,
                                  parameter_types:   List( ty::Typ_Path )
                                }
          | SOURCE_CODE_REGION_FOR_PACKAGE  (Package_Expression, Source_Code_Region)



        # For typing purpose, a generic is viewed as a high-order type constructor 
        # (hotyc) that accepts a list of hotyps and returns another list of hotyps.
        # The "parameter_types" field in GENERIC_DEFINITION records the list of formal hotyc parameters.
        #
        also
        Generic_Expression 
          #
          = GENERIC_BY_NAME     mld::Generic
          | GENERIC_LET         (Declaration, Generic_Expression)
          | GENERIC_DEFINITION  { parameter:       mld::Package,
                                  parameter_types: List( ty::Typ_Path ),
                                  definition:      Package_Expression
                                }
          | SOURCE_CODE_REGION_FOR_GENERIC  (Generic_Expression, Source_Code_Region)



        # Each value naming Named_Value only binds one variable identifier.
        # That is,  pattern is always a simple VARIABLE_IN_PATTERN
        # (with type constraints) or it simply does not contain any
        # variable patterns; bound_typevar_refs gives the list of
        # type variables that are being generalized at this binding. 
        #
        also
        Named_Value
            #
            = NAMED_VALUE  { pattern:              Case_Pattern,
                             expression:           Deep_Expression,
                             bound_typevar_refs:   List( ty::Typevar_Ref ),
                             ref_typevar_refs:     Ref(  List( ty::Typevar_Ref ) )
                           }



        # Like value naming Named_Value, bound_typevar_refs gives a list of type variables 
        # being generalized at this binding. However, the mutually recursive
        # list of recursive value bindings could share type variables,
        # that is, the bound_typevar_refs sets used in these RVBs
        # could contain overlapping set of type variables.
        #
        also
        Named_Recursive_Values
            #
            = NAMED_RECURSIVE_VALUES  { variable:             vac::Variable,
                                        expression:           Deep_Expression,
                                        bound_typevar_refs:   List( ty::Typevar_Ref ),
                                        null_or_type:         Null_Or( ty::Type ),
                                        ref_typevar_refs:     Ref( List( ty::Typevar_Ref ) )
                                      }



        also
        Named_Exception
            #
            = NAMED_EXCEPTION  { exception_constructor:   ty::Valcon,
                                 exception_type:          Null_Or( ty::Type ),
                                 name_string:             Deep_Expression
                               }

            | DUPLICATE_NAMED_EXCEPTION  { exception_constructor:  ty::Valcon,
                                           equal_to:               ty::Valcon
                                         }



        also
        Named_Package
            #
            = NAMED_PACKAGE  { name_symbol:   sy::Symbol,
                               a_package:     mld::Package,
                               definition:    Package_Expression
                             } 



        also
        Named_Generic
            #
            = NAMED_GENERIC  { name_symbol:   sy::Symbol,
                               a_generic:     mld::Generic,
                               definition:    Generic_Expression
                             }

        withtype Fnrules = (List( Case_Rule ), types::Type);

    };
end;                                                                                            # stipulate


Comments and suggestions to: bugs@mythryl.org

PreviousUpNext