


## deep-syntax.api
## (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:
#
# src/lib/compiler/front/semantic/typecheck/translate-raw-syntax-to-deep-syntax.pkg#
# 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
# src/lib/compiler/front/typer-stuff/types/types.api# src/lib/compiler/front/typer-stuff/types/types.pkg# src/lib/compiler/front/typer-stuff/modules/module-level-declarations.api# src/lib/compiler/front/typer-stuff/modules/module-level-declarations.pkg# etc.
#
# Deep syntax gets translated into A-Normal form using
# a polymorphically typed lambda calculus as a stepping
# stone:
#
# src/lib/compiler/back/top/lambdacode/lambdacode-form.api# src/lib/compiler/back/top/anormcode/anormcode-form.api# src/lib/compiler/back/top/translate/translate-deep-syntax-to-lambdacode.pkg### "One word in the wrong place
### ruins the most precious thought."
###
### -- Voltaire
stipulate
package fix = fixity; # fixity is from src/lib/compiler/front/basics/map/fixity.pkg package int = multiword_int; # multiword_int is from src/lib/std/multiword-int.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 ty = types; # types is from src/lib/compiler/front/typer-stuff/types/types.pkg package vac = variables_and_constructors; # variables_and_constructors is from src/lib/compiler/front/typer-stuff/deep-syntax/variables-and-constructors.pkgherein
api Deep_Syntax {
#
#
Source_Code_Region;
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 (int::Int, ty::Type)
| UNT_CONSTANT_IN_EXPRESSION (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)
| VECTOR_IN_EXPRESSION (List( Deep_Expression ), ty::Type)
| ABSTRACTION_PACKING_EXPRESSION (Deep_Expression, ty::Type, List( ty::Typ ))
| 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.
| OR_EXPRESSION (Deep_Expression, Deep_Expression)
| AND_EXPRESSION (Deep_Expression, Deep_Expression)
| FN_EXPRESSION Fnrules
| SEQUENTIAL_EXPRESSIONS List( Deep_Expression )
| LET_EXPRESSION (Declaration, 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
| NO_PATTERN
| TYPE_CONSTRAINT_PATTERN (Case_Pattern, ty::Type)
| AS_PATTERN (Case_Pattern, Case_Pattern)
| OR_PATTERN (Case_Pattern, Case_Pattern)
| VARIABLE_IN_PATTERN vac::Variable
| INT_CONSTANT_IN_PATTERN (int::Int, ty::Type)
| UNT_CONSTANT_IN_PATTERN (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)
| VECTOR_PATTERN (List( Case_Pattern ), ty::Type)
| RECORD_PATTERN { fields: List( (ty::Label, Case_Pattern)),
is_incomplete: Bool,
type_ref: Ref( ty::Type )
}
also
Declaration
#
= EXCEPTION_DECLARATIONS List( Named_Exception )
| RECURSIVE_VALUE_DECLARATIONS List( Named_Recursive_Values )
| VALUE_DECLARATIONS List( Named_Value )
| TYPE_DECLARATIONS List( ty::Typ )
| 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
| 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
}
| FIXITY_DECLARATION { fixity: fix::Fixity,
ops: List( sy::Symbol )
}
| SOURCE_CODE_REGION_FOR_DECLARATION (Declaration, Source_Code_Region)
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)
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)
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 ) )
}
# bound_typevar_refs:
# List of generalized type variables.
# This gets generated in src/lib/compiler/front/typer/types/unify-and-generalize-types-g.pkg # and later used in src/lib/compiler/back/top/translate/translate-deep-syntax-to-lambdacode.pkg #
# ref_typevar_refs:
# List of explicit user type variabls X, Y, Z ...
# found in patterns in function arguments etc.
# This is the list of candidates for let-polymormphic
# type generalization. This gets used in
# src/lib/compiler/front/typer/types/unify-and-generalize-types-g.pkg # in generalize_pattern() (where it is called 'userbound') and
# in generalize_type() (where it is called 'user_typevar_refs').
#
# Both of the above should be renamed to something clearer
# once I understand them better. XXX BUGGO FIXEME.
also
Named_Recursive_Values
#
= NAMED_RECURSIVE_VALUES { variable: vac::Variable,
expression: Deep_Expression,
null_or_type: Null_Or( ty::Type ),
bound_typevar_refs: List( ty::Typevar_Ref ),
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 ), ty::Type);
}; # Api Deep_Syntax
end; # stipulate


