Changeset c459f99
- Timestamp:
- May 2, 2023, 11:11:34 AM (19 months ago)
- Branches:
- ADT, ast-experimental, master
- Children:
- 21d1c9c
- Parents:
- d1c51b1
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/theses/colby_parsons_MMAth/text/CFA_intro.tex
rd1c51b1 rc459f99 6 6 7 7 \section{Overview} 8 The following serves as an introduction to \CFA. 9 \CFA is a layer over C, is transpiled\footnote{Source to source translator.} to C, and is largely considered to be an extension of C. 10 Beyond C, it adds productivity features, extended libraries, an advanced type system, and many control-flow/concurrency constructions.11 However, \CFA stays true to the C programming style, with most code revolving around @struct@'s and routines, and respects the same rules as C. 12 \CFA is not object oriented as it has no notion of @this@ (receiver) and no structures with methods, but supports some object oriented ideas including constructors, destructors, and limited containment inheritance. 8 The following serves as an introduction to \CFA. 9 \CFA is a layer over C, is transpiled\footnote{Source to source translator.} to C, and is largely considered to be an extension of C. 10 Beyond C, it adds productivity features, extended libraries, an advanced type-system, and many control-flow/concurrency constructions. 11 However, \CFA stays true to the C programming style, with most code revolving around @struct@'s and routines, and respects the same rules as C. 12 \CFA is not object oriented as it has no notion of @this@ (receiver) and no structures with methods, but supports some object oriented ideas including constructors, destructors, and limited containment inheritance. 13 13 While \CFA is rich with interesting features, only the subset pertinent to this work is discussed. 14 14 15 15 \section{References} 16 References in \CFA are similar to references in \CC; however \CFA references are rebindable, and support multi-level referencing.17 References in \CFA are a layer of syntactic sugar over pointers to reduce the number of ref/deref operations needed with pointer usage. 16 References in \CFA are similar to references in \CC; however \CFA references are \emph{rebindable}, and support multi-level referencing. 17 References in \CFA are a layer of syntactic sugar over pointers to reduce the number of ref/deref operations needed with pointer usage. 18 18 Another difference is the use of @0p@ instead of C's @NULL@ or \CC's @nullptr@. 19 Examples of references are shown in \VRef[Listing]{l:cfa_ref}. 19 Examples of references are shown in \VRef[Listing]{l:cfa_ref}. 20 20 21 21 \begin{cfa}[caption={Example of \CFA references},label={l:cfa_ref}] … … 37 37 38 38 \section{Overloading}\label{s:Overloading} 39 \CFA routines can be overloaded on parameter type, number of parameters, and \emph{return type}. 40 Variables can also be overloaded on type, meaning that two variables can have the same name so long as they have different types. 39 \CFA routines can be overloaded on parameter type, number of parameters, and \emph{return type}. 40 Variables can also be overloaded on type, meaning that two variables can have the same name so long as they have different types. 41 41 A routine or variable is disambiguated at each usage site via its type and surrounding expression context. 42 A cast is used to disambiguate any conflicting usage. 43 Examples of overloading are shown in \VRef[Listing]{l:cfa_overload}. 42 A cast is used to disambiguate any conflicting usage. 43 Examples of overloading are shown in \VRef[Listing]{l:cfa_overload}. 44 44 45 45 \begin{cfa}[caption={Example of \CFA overloading},label={l:cfa_overload}] … … 60 60 61 61 62 \section{ WithStatement}62 \section{\lstinline{with} Statement} 63 63 The \CFA @with@ statement is for exposing fields of an aggregate type within a scope, allowing field names without qualification. 64 This feature is also implemented in Pascal~\cite{Pascal}. 65 It can exist as a stand-alone statement or wrap a routine body to expose aggregate fields. 66 Examples of the @with@ statement are shown in \VRef[Listing]{l:cfa_with}. 64 This feature is also implemented in Pascal~\cite{Pascal}. 65 It can exist as a stand-alone statement or wrap a routine body to expose aggregate fields. 66 Examples of the @with@ statement are shown in \VRef[Listing]{l:cfa_with}. 67 67 68 68 \begin{cfa}[caption={Example of \CFA \lstinline{with} statement},label={l:cfa_with}] … … 83 83 84 84 \section{Operators} 85 Operators can be overloaded in \CFA with operator routines. 85 Operators can be overloaded in \CFA with operator routines. 86 86 Operators in \CFA are named using an operator symbol and '@?@' to represent operands. 87 Examples of \CFA operators are shown in \VRef[Listing]{l:cfa_operate}. 87 Examples of \CFA operators are shown in \VRef[Listing]{l:cfa_operate}. 88 88 89 89 \begin{cfa}[caption={Example of \CFA operators},label={l:cfa_operate}] … … 102 102 103 103 \section{Constructors and Destructors} 104 Constructors and destructors in \CFA are special operator routines used for creation and destruction of objects. 105 The default constructor and destructor for a type are called implicitly upon creation and deletion, respectively. 106 Examples of \CFA constructors and destructors are shown in \VRef[Listing]{l:cfa_ctor}. 104 Constructors and destructors in \CFA are special operator routines used for creation and destruction of objects. 105 The default constructor and destructor for a type are called implicitly upon creation and deletion, respectively. 106 Examples of \CFA constructors and destructors are shown in \VRef[Listing]{l:cfa_ctor}. 107 107 108 108 \begin{cfa}[caption={Example of \CFA constructors and destructors},label={l:cfa_ctor}] … … 128 128 \section{Polymorphism}\label{s:poly} 129 129 C supports limited polymorphism, often requiring users to implement polymorphism using a @void *@ (type erasure) approach. 130 \CFA extends C with generalized overloading polymorphism (see \VRef{s:Overloading}), as well as, parametric polymorphism and nominalinheritance.130 \CFA extends C with generalized overloading polymorphism (see \VRef{s:Overloading}), as well as, parametric polymorphism and limited containment inheritance. 131 131 132 132 \subsection{Parametric Polymorphism} 133 \CFA provides parametric polymorphism in the form of @forall@, and @trait@s. 134 A @forall@ takes in a set of types and a list of constraints. 135 The declarations that follow the @forall@ are parameterized over the types listed that satisfy the constraints. 136 A list of @forall@ constraints can be refactored into a named @trait@ and reused in @forall@s. 137 Examples of \CFA parametric polymorphism are shown in \VRef[Listing]{l:cfa_poly}. 133 \CFA provides parametric polymorphism in the form of @forall@, and @trait@s. 134 A @forall@ takes in a set of types and a list of constraints. 135 The declarations that follow the @forall@ are parameterized over the types listed that satisfy the constraints. 136 A list of @forall@ constraints can be refactored into a named @trait@ and reused in @forall@s. 137 Examples of \CFA parametric polymorphism are shown in \VRef[Listing]{l:cfa_poly}. 138 138 139 139 \begin{cfa}[caption={Example of \CFA parametric polymorphism},label={l:cfa_poly}] … … 180 180 181 181 \subsection{Inheritance} 182 Inheritance in \CFA is taken from Plan-9 C's containment inheritance. 183 In \CFA, @struct@s can @inline@ another struct type to gain its fields and masquerade as that type. 184 Examples of \CFA containment inheritance are shown in \VRef[Listing]{l:cfa_inherit}. 182 Inheritance in \CFA is taken from Plan-9 C's containment inheritance. 183 In \CFA, @struct@s can @inline@ another struct type to gain its fields and masquerade as that type. 184 Examples of \CFA containment inheritance are shown in \VRef[Listing]{l:cfa_inherit}. 185 185 186 186 \begin{cfa}[caption={Example of \CFA containment inheritance},label={l:cfa_inherit}] 187 187 struct one_d { double x; }; 188 struct two_d { 188 struct two_d { 189 189 @inline@ one_d; 190 190 double y; 191 191 }; 192 struct three_d { 192 struct three_d { 193 193 @inline@ two_d; 194 194 double z;
Note: See TracChangeset
for help on using the changeset viewer.