Ignore:
Timestamp:
Dec 22, 2024, 4:48:21 PM (4 weeks ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
master
Children:
a5e2786f
Parents:
50cad32
Message:

respond to Andrew's comments about intro chapter

File:
1 edited

Legend:

Unmodified
Added
Removed
  • doc/theses/fangren_yu_MMath/intro.tex

    r50cad32 r5a02308  
    11\chapter{Introduction}
    22
    3 This thesis is exploratory work I did to understand, fix, and extend the \CFA type-system, specifically, the type resolver used to select polymorphic types among overloaded names.
     3This thesis is exploratory work I did to understand, fix, and extend the \CFA type-system, specifically, the \newterm{type-resolver} used to satisfy call-site assertions among overloaded variable and function names to allow polymorphic routine calls.
     4Assertions are the operations a function uses within its body to perform its computation.
     5For example, a polymorphic function summing an array needs a size, zero, assignment, and plus for the array element-type, and a subscript operation for the array type.
     6\begin{cfa}
     7T sum( T a[$\,$], size_t size ) {
     8        @T@ total = { @0@ };  // size, 0 for type T
     9        for ( size_t i = 0; i < size; i += 1 )
     10                total @+=@ a@[@i@]@; // + and subscript for T
     11        return total;
     12}
     13\end{cfa}
     14In certain cases, if the resolver fails to find an exact assertion match, it attempts to find a \emph{best} match using reasonable type conversions.
     15Hence, \CFA follows the current trend of replacing nominal inheritance with traits composed of assertions for type matching.
     16The over-arching goal is to push the boundary on localized assertion matching, with advanced overloading resolution and type conversions that match programmer expectations in the C programming language.
     17Together, the resulting \CFA type-system has a number of unique features making it different from other programming languages with expressive, static, type-systems.
     18
     19
     20\section{Types}
     21
     22All computers have multiple types because computer architects optimize the hardware around a few basic types with well defined (mathematical) operations: boolean, integral, floating-point, and occasionally strings.
     23A programming language and its compiler present ways to declare types that ultimately map into the ones provided by the underlying hardware.
     24These language types are thrust upon programmers, with their syntactic and semantic rules and restrictions.
     25These rules are used to transform a language expression to a hardware expression.
     26Modern programming-languages allow user-defined types and generalize across multiple types using polymorphism.
     27Type systems can be static, where each variable has a fixed type during execution and an expression's type is determined once at compile time, or dynamic, where each variable can change type during execution and so an expression's type is reconstructed on each evaluation.
     28Expressibility, generalization, and safety are all bound up in a language's type system, and hence, directly affect the capability, build time, and correctness of program development.
     29
     30
     31\section{Overloading}
     32
    433Overloading allows programmers to use the most meaningful names without fear of name clashes within a program or from external sources, like include files.
    534\begin{quote}
     
    1039Depending on the language, any ambiguous cases are resolved using some form of qualification and/or casting.
    1140
    12 Therefore, one of the key goals in \CFA is to push the boundary on overloading, and hence, overload resolution.
    13 As well, \CFA follows the current trend of replacing nominal inheritance with traits.
    14 Together, the resulting \CFA type-system has a number of unique features making it different from other programming languages with expressive, static type-systems.
    15 
    16 
    17 \section{Types}
    18 
    19 \begin{quote}
    20 Some are born great, some achieve greatness, and some have greatness thrust upon them. Twelfth Night, Act II Scene 5, William Shakespeare
    21 \end{quote}
    22 
    23 All computers have multiple types because computer architects optimize the hardware around a few basic types with well defined (mathematical) operations: boolean, integral, floating-point, and occasionally strings.
    24 A programming language and its compiler present ways to declare types that ultimately map into the ones provided by the underlying hardware.
    25 These language types are \emph{thrust} upon programmers, with their syntactic and semantic rules and restrictions.
    26 These rules are used to transform a language expression to a hardware expression.
    27 Modern programming-languages allow user-defined types and generalize across multiple types using polymorphism.
    28 Type systems can be static, where each variable has a fixed type during execution and an expression's type is determined once at compile time, or dynamic, where each variable can change type during execution and so an expression's type is reconstructed on each evaluation.
    29 Expressibility, generalization, and safety are all bound up in a language's type system, and hence, directly affect the capability, build time, and correctness of program development.
    30 
    31 
    32 \section{Operator Overloading}
     41
     42\subsection{Operator Overloading}
    3343
    3444Virtually all programming languages overload the arithmetic operators across the basic computational types using the number and type of parameters and returns.
    35 Like \CC, \CFA also allows these operators to be overloaded with user-defined types.
     45Like \CC, \CFA maps operators to named functions and allows these operators to be overloaded with user-defined types.
    3646The syntax for operator names uses the @'?'@ character to denote a parameter, \eg left and right unary operators: @?++@ and @++?@, and binary operators @?+?@ and @?<=?@.
    3747Here, a user-defined type is extended with an addition operation with the same syntax as builtin types.
     
    5060
    5161
    52 \section{Function Overloading}
     62\subsection{Function Overloading}
    5363
    5464Both \CFA and \CC allow function names to be overloaded, as long as their prototypes differ in the number and type of parameters and returns.
     
    8393
    8494
    85 \section{Variable Overloading}
     95\subsection{Variable Overloading}
    8696
    8797Unlike most programming languages, \CFA has variable overloading within a scope, along with shadow overloading in nested scopes.
     
    125135
    126136
    127 \section{Constant Overloading}
    128 
    129 \CFA is unique in providing restricted constant overloading for the values @0@ and @1@, which have special status in C, \eg the value @0@ is both an integer and a pointer literal, so its meaning depends on context.
     137\subsection{Constant Overloading}
     138
     139\CFA is unique in providing restricted constant overloading for the values @0@ and @1@, which have special status in C.
     140For example, the value @0@ is both an integer and a pointer literal, so its meaning depends on context.
    130141In addition, several operations are defined in terms of values @0@ and @1@.
    131 For example, every @if@ and iteration statement in C compares the condition with @0@, and every increment and decrement operator is semantically equivalent to adding or subtracting the value @1@ and storing the result.
     142For example, @if@ and iteration statements in C compare the condition with @0@, and the increment and decrement operators are semantically equivalent to adding or subtracting the value @1@.
    132143\begin{cfa}
    133144if ( x ) ++x;        =>    if ( x @!= 0@ ) x @+= 1@;
     
    138149\begin{cfa}
    139150struct S { int i, j; };
    140 void ?{}( S & s, zero_t ) { s.[i,j] = 0; } $\C{// constructors}$
     151void ?{}( S & s, zero_t ) { s.[i,j] = 0; } $\C{// constant constructors}$
    141152void ?{}( S & s, one_t ) { s.[i,j] = 1; }
    142 S ?=?( S & dst, zero_t ) { dst.[i,j] = 0; return dst; } $\C{// assignment}$
     153S ?=?( S & dst, zero_t ) { dst.[i,j] = 0; return dst; } $\C{// constant assignments}$
    143154S ?=?( S & dst, one_t ) { dst.[i,j] = 1; return dst; }
    144155S ?+=?( S & s, one_t ) { s.[i,j] += 1; return s; } $\C{// increment/decrement each field}$
    145156S ?-=?( S & s, one_t ) { s.[i,j] -= 1; return s; }
    146 int ?!=?( S s, zero_t ) { return s.i != 0 && s.j != 0; } $\C{// comparison}$
     157int ?!=?( S s, zero_t ) { return s.i != 0 && s.j != 0; } $\C{// constant comparison}$
    147158S s = @0@;                      $\C{// initialization}$
    148159s = @0@;                        $\C{// assignments}$
    149160s = @1@;
    150 if ( @s@ ) @++s@;       $\C{// special, unary ++/-\,- come implicitly from +=/-=}$
     161if ( @s@ ) @++s@;       $\C{// unary ++/-\,- come implicitly from +=/-=}$
    151162\end{cfa}
    152163Here, type @S@ is first-class with respect to the basic types, working with all existing implicit C mechanisms.
     
    169180Note, type inferencing is different from type conversion: type inferencing \emph{discovers} a variable's type before setting its value, whereas conversion has two typed values and performs a (possibly lossy) action to convert one value to the type of the other variable.
    170181Finally, for assignment, the current variable and expression types may not agree.
     182Discovering a variable or function type is complex and has limitations.
     183The following covers these issues, and why some schemes are not amenable with the \CFA type system.
    171184
    172185One of the first and powerful type-inferencing system is Hindley--Milner~\cite{Damas82}.
     
    248261
    249262
    250 \section{Type-Inferencing Issues}
     263\subsection{Type-Inferencing Issues}
    251264
    252265Each kind of type-inferencing system has its own set of issues that flow onto the programmer in the form of convenience, restrictions, or confusions.
     
    311324\end{cfa}
    312325This @identity@ function can be applied to an \newterm{object type}, \ie a type with a known size and alignment, which is sufficient to stack allocate, default or copy initialize, assign, and delete.
    313 The \CFA implementation passes the size and alignment for each type parameter, as well as any implicit/explicit constructor, copy constructor, assignment operator, and destructor.
     326The \CFA implementation passes the size and alignment for each type parameter, as well as auto-generated default and copy constructors, assignment operator, and destructor.
    314327For an incomplete \newterm{data type}, \eg pointer/reference types, this information is not needed.
    315328\begin{cfa}
     
    420433\end{cfa}
    421434The implicit routines are used by the @sumable@ operator @?+=?@ for the right side of @?+=?@ and return.
     435
     436If the array type is not a builtin type, an extra type parameter and assertions are required, like subscripting.
     437This case is generalized in polymorphic container-types, such as a list with @insert@ and @remove@ operations, and an element type with copy and assignment.
    422438
    423439
Note: See TracChangeset for help on using the changeset viewer.