Changeset 8f67d44


Ignore:
Timestamp:
Feb 13, 2018, 6:16:56 PM (6 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
cd310f7
Parents:
9c75137
Message:

more text on new declaration syntax, start library section with stream I/O

File:
1 edited

Legend:

Unmodified
Added
Removed
  • doc/papers/general/Paper.tex

    r9c75137 r8f67d44  
    44\usepackage{epic,eepic}
    55\usepackage{xspace,calc,comment}
    6 \usepackage{upquote}                                                                    % switch curled `'" to straight
    7 \usepackage{listings}                                                                   % format program code
     6\usepackage{upquote}                                            % switch curled `'" to straight
     7\usepackage{listings}                                           % format program code
     8\usepackage[flushmargin]{footmisc}                      % support label/reference in footnote
    89\usepackage{rotating}
    910\usepackage[usenames]{color}
    10 \usepackage{pslatex}                                    % reduce size of san serif font
     11\usepackage{pslatex}                                            % reduce size of san serif font
    1112\usepackage[plainpages=false,pdfpagelabels,pdfpagemode=UseNone,pagebackref=true,breaklinks=true,colorlinks=true,linkcolor=blue,citecolor=blue,urlcolor=blue]{hyperref}
    1213
    1314\setlength{\textheight}{9in}
    1415%\oddsidemargin 0.0in
    15 \renewcommand{\topfraction}{0.8}                % float must be greater than X of the page before it is forced onto its own page
    16 \renewcommand{\bottomfraction}{0.8}             % float must be greater than X of the page before it is forced onto its own page
    17 \renewcommand{\floatpagefraction}{0.8}  % float must be greater than X of the page before it is forced onto its own page
    18 \renewcommand{\textfraction}{0.0}               % the entire page maybe devoted to floats with no text on the page at all
    19 
    20 \lefthyphenmin=4                                                % hyphen only after 4 characters
     16\renewcommand{\topfraction}{0.8}                        % float must be greater than X of the page before it is forced onto its own page
     17\renewcommand{\bottomfraction}{0.8}                     % float must be greater than X of the page before it is forced onto its own page
     18\renewcommand{\floatpagefraction}{0.8}          % float must be greater than X of the page before it is forced onto its own page
     19\renewcommand{\textfraction}{0.0}                       % the entire page maybe devoted to floats with no text on the page at all
     20
     21\lefthyphenmin=4                                                        % hyphen only after 4 characters
    2122\righthyphenmin=4
    2223
     
    2425
    2526\newcommand{\CFAIcon}{\textsf{C}\raisebox{\depth}{\rotatebox{180}{\textsf{A}}}\xspace} % Cforall symbolic name
    26 \newcommand{\CFA}{\protect\CFAIcon} % safe for section/caption
    27 \newcommand{\CFL}{\textrm{Cforall}\xspace} % Cforall symbolic name
    28 \newcommand{\Celeven}{\textrm{C11}\xspace} % C11 symbolic name
     27\newcommand{\CFA}{\protect\CFAIcon}             % safe for section/caption
     28\newcommand{\CFL}{\textrm{Cforall}\xspace}      % Cforall symbolic name
     29\newcommand{\Celeven}{\textrm{C11}\xspace}      % C11 symbolic name
    2930\newcommand{\CC}{\textrm{C}\kern-.1em\hbox{+\kern-.25em+}\xspace} % C++ symbolic name
    3031\newcommand{\CCeleven}{\textrm{C}\kern-.1em\hbox{+\kern-.25em+}11\xspace} % C++11 symbolic name
     
    5657\newcommand{\LstCommentStyle}[1]{{\lst@basicstyle{\lst@commentstyle{#1}}}}
    5758
    58 \newlength{\gcolumnposn}                                % temporary hack because lstlisting does not handle tabs correctly
     59\newlength{\gcolumnposn}                                        % temporary hack because lstlisting does not handle tabs correctly
    5960\newlength{\columnposn}
    6061\setlength{\gcolumnposn}{2.75in}
     
    7273
    7374% Latin abbreviation
    74 \newcommand{\abbrevFont}{\textit}       % set empty for no italics
     75\newcommand{\abbrevFont}{\textit}                       % set empty for no italics
    7576\newcommand{\EG}{\abbrevFont{e}.\abbrevFont{g}.}
    7677\newcommand*{\eg}{%
     
    11161117\CFA disallows the declaration of local variable, \eg @z@, directly within the @switch@ body, because a declaration cannot occur immediately after a @case@ since a label can only be attached to a statement, and the use of @z@ is undefined in @case 1@ as neither storage allocation nor initialization may have occurred.
    11171118
    1118 C @switch@ provides multiple entry points into the statement body, but once an entry point is selected, control continues across \emph{all} @case@ clauses until the end of the @switch@ body, called \newterm{fall through}.
     1119C @switch@ provides multiple entry points into the statement body, but once an entry point is selected, control continues across \emph{all} @case@ clauses until the end of the @switch@ body, called \newterm{fall through};
    11191120@case@ clauses are made disjoint by the @break@ statement.
    11201121While the ability to fall through \emph{is} a useful form of control flow, it does not match well with programmer intuition, resulting in many errors from missing @break@ statements.
     
    15381539Therefore, a programmer has the option of either continuing to use traditional C declarations or take advantage of the new style.
    15391540Clearly, both styles need to be supported for some time due to existing C-style header-files, particularly for UNIX-like systems.
     1541
     1542The syntax of the new routine prototype declaration follows directly from the new routine definition syntax;
     1543as well, parameter names are optional, \eg:
     1544\begin{cfa}
     1545[ int x ] f ();                                                 $\C{// returning int with no parameters}$
     1546[ * int ] g (int y);                                    $\C{// returning pointer to int with int parameter}$
     1547[ ] h ( int, char );                                    $\C{// returning no result with int and char parameters}$
     1548[ * int, int ] j ( int );                               $\C{// returning pointer to int and int, with int parameter}$
     1549\end{cfa}
     1550This syntax allows a prototype declaration to be created by cutting and pasting source text from the routine definition header (or vice versa).
     1551Like C, it is possible to declare multiple routine-prototypes in a single declaration, where the return type is distributed across \emph{all} routine names in the declaration list, \eg:
     1552\begin{cquote}
     1553\lstDeleteShortInline@%
     1554\begin{tabular}{@{}l@{\hspace{3em}}l@{}}
     1555\multicolumn{1}{c@{\hspace{3em}}}{\textbf{\CFA}}        & \multicolumn{1}{c}{\textbf{C}}        \\
     1556\begin{cfa}
     1557[double] foo(), foo( int ), foo( double ) {...}
     1558\end{cfa}
     1559&
     1560\begin{cfa}
     1561double foo1(), foo2( int ), foo3( double );
     1562\end{cfa}
     1563\end{tabular}
     1564\lstMakeShortInline@%
     1565\end{cquote}
     1566\CFA allows the last routine in the list to define its body.
     1567
     1568Declaration qualifiers can only appear at the start of a \CFA routine declaration,\footref{StorageClassSpecifier} \eg:
     1569\begin{cfa}
     1570extern [ int ] f ( int );
     1571static [ int ] g ( int );
     1572\end{cfa}
     1573
     1574The syntax for pointers to \CFA routines specifies the pointer name on the right, \eg:
     1575\begin{cfa}
     1576* [ int x ] () fp;                                              $\C{// pointer to routine returning int with no parameters}$
     1577* [ * int ] (int y) gp;                                 $\C{// pointer to routine returning pointer to int with int parameter}$
     1578* [ ] (int,char) hp;                                    $\C{// pointer to routine returning no result with int and char parameters}$
     1579* [ * int,int ] ( int ) jp;                             $\C{// pointer to routine returning pointer to int and int, with int parameter}$
     1580\end{cfa}
     1581While parameter names are optional, \emph{a routine name cannot be specified};
     1582for example, the following is incorrect:
     1583\begin{cfa}
     1584* [ int x ] f () fp;                                    $\C{// routine name "f" is not allowed}$
     1585\end{cfa}
    15401586
    15411587
     
    17641810\end{cfa}
    17651811}%
     1812
     1813
     1814\section{Libraries}
     1815
     1816\subsection{I/O}
     1817\label{s:IOLibrary}
     1818
     1819The goal of \CFA I/O is to simplify the common cases, while fully supporting polymorphism and user defined types in a consistent way.
     1820The approach combines ideas from \CC and Python.
     1821The \CFA header file for the I/O library is @fstream@.
     1822
     1823The common case is printing out a sequence of variables separated by whitespace.
     1824\begin{cquote}
     1825\lstDeleteShortInline@%
     1826\begin{tabular}{@{}l@{\hspace{3em}}l@{}}
     1827\multicolumn{1}{c@{\hspace{3em}}}{\textbf{\CFA}}        & \multicolumn{1}{c}{\textbf{\CC}}      \\
     1828\begin{cfa}
     1829int x = 1, y = 2, z = 3;
     1830sout | x `|` y `|` z | endl;
     1831\end{cfa}
     1832&
     1833\begin{cfa}
     1834
     1835cout << x `<< " "` << y `<< " "` << z << endl;
     1836\end{cfa}
     1837\\
     1838\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
     18391` `2` `3
     1840\end{cfa}
     1841&
     1842\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
     18431 2 3
     1844\end{cfa}
     1845\end{tabular}
     1846\lstMakeShortInline@%
     1847\end{cquote}
     1848The \CFA form has half the characters of the \CC form, and is similar to Python I/O with respect to implicit separators.
     1849Similar simplification occurs for tuple I/O, which prints all tuple values separated by ``\lstinline[showspaces=true]@, @''.
     1850\begin{cfa}
     1851[int, [ int, int ] ] t1 = [ 1, [ 2, 3 ] ], t2 = [ 4, [ 5, 6 ] ];
     1852sout | t1 | t2 | endl;                                  $\C{// print tuples}$
     1853\end{cfa}
     1854\begin{cfa}[showspaces=true,aboveskip=0pt]
     18551`, `2`, `3 4`, `5`, `6
     1856\end{cfa}
     1857Finally, \CFA uses the logical-or operator for I/O as it is the lowest-priority overloadable operator, other than assignment.
     1858Therefore, fewer output expressions require parenthesis.
     1859\begin{cquote}
     1860\lstDeleteShortInline@%
     1861\begin{tabular}{@{}ll@{}}
     1862\textbf{\CFA:}
     1863&
     1864\begin{cfa}
     1865sout | x * 3 | y + 1 | z << 2 | x == y | (x | y) | (x || y) | (x > z ? 1 : 2) | endl;
     1866\end{cfa}
     1867\\
     1868\textbf{\CC:}
     1869&
     1870\begin{cfa}
     1871cout << x * 3 << y + 1 << `(`z << 2`)` << `(`x == y`)` << (x | y) << (x || y) << (x > z ? 1 : 2) << endl;
     1872\end{cfa}
     1873\\
     1874\textbf{output:}
     1875&
     1876\begin{cfa}[showspaces=true,aboveskip=0pt]
     18773 3 12 0 3 1 2
     1878\end{cfa}
     1879\end{tabular}
     1880\lstMakeShortInline@%
     1881\end{cquote}
     1882There is a weak similarity between the \CFA logical-or operator and the Shell pipe-operator for moving data, where data flows in the correct direction for input but the opposite direction for output.
     1883
     1884The implicit separator character (space/blank) is a separator not a terminator.
     1885The rules for implicitly adding the separator are:
     1886\begin{list}{\footnotesize$\bullet$}{\itemsep=2pt\parsep=0pt}
     1887\item
     1888A separator does not appear at the start or end of a line.
     1889\item
     1890A separator does not appear before or after a character literal or variable.
     1891\item
     1892A separator does not appear before or after a null (empty) C string, which is a local mechanism to disable insertion of the separator character.
     1893\item
     1894A separator does not appear before a C string starting with the characters: \lstinline[mathescape=off,basicstyle=\tt]@([{=$@
     1895\item
     1896A seperator does not appear after a C string ending with the characters: \lstinline[basicstyle=\tt]@,.;!?)]}%@
     1897\item
     1898{\lstset{language=CFA,deletedelim=**[is][]{`}{`}}
     1899A seperator does not appear before or after a C string begining/ending with the quote or whitespace characters: \lstinline[basicstyle=\tt,showspaces=true]@`'": \t\v\f\r\n@
     1900}%
     1901\item
     1902There are routines to set and get the separator string, and manipulators to toggle separation on and off in the middle of output.
     1903\end{list}
     1904
    17661905
    17671906\section{Evaluation}
Note: See TracChangeset for help on using the changeset viewer.