Changes in / [a0c7d5cc:534d84e]


Ignore:
Files:
18 edited

Legend:

Unmodified
Added
Removed
  • doc/papers/AMA/AMA-stix/ama/WileyNJD-v2.cls

    ra0c7d5cc r534d84e  
    484484\if@STIXLargeOneCol%
    485485\RequirePackage[not1,notextcomp,lcgreekalpha]{stix}%
    486 \usepackage[scaled]{helvet}
    487 \renewcommand\familydefault{\sfdefault}
     486%\usepackage[scaled]{helvet}
     487%\renewcommand\familydefault{\sfdefault}
    488488\usepackage[T1]{fontenc}
    489489\BXhsize=170mm%
     
    966966% Footnotes
    967967%
    968 %\renewcommand\thefootnote{\@fnsymbol\c@footnote}%
     968%%\renewcommand\thefootnote{\@fnsymbol\c@footnote}%
    969969
    970970
     
    12791279
    12801280\if@font@stix%
    1281   \def\footnotetextfont{\sffamily\fontsize{8bp}{10bp}\selectfont}\else%
     1281  \def\footnotetextfont{\rmfamily\fontsize{8bp}{10bp}\selectfont}\else%
    12821282  %%
    1283   \def\footnotetextfont{\sffamily\fontsize{6bp}{8bp}\selectfont}
     1283  \def\footnotetextfont{\rmfamily\fontsize{6bp}{8bp}\selectfont}
    12841284\fi%
    12851285%
     
    12941294\DeclareRobustCommand\sfitseries{\not@math@alphabet\sfitseries\normalfont\fontseries{m}\fontshape{it}\selectfont}
    12951295\DeclareTextFontCommand{\textsfi}{\sfitseries}
    1296 \DeclareOldFontCommand{\rm}{\normalfont\sffamily}{\mathrm}
     1296\DeclareOldFontCommand{\rm}{\normalfont\rmfamily}{\mathrm}
    12971297\DeclareOldFontCommand{\sf}{\normalfont\sffamily}{\mathsf}
    12981298\DeclareOldFontCommand{\tt}{\normalfont\ttfamily}{\mathtt}
     
    13221322\renewcommand\normalsize{%
    13231323  \if@font@stix%
    1324     \@setfontsize\normalsize{9bp}{12bp}%
     1324    \@setfontsize\normalsize{10bp}{13bp}%
    13251325  \else%
    13261326    \@setfontsize\normalsize{8bp}{13bp}%
     
    14181418%  \def\watermarkfont{\reset@font\fontfamily{\ffdefault}\fontsize{45}{45}\bfseries\selectfont}
    14191419  %
    1420   \def\pagenumfont{\sffamily\fontsize{7}{9}\bfseries\selectfont}%
    1421   \def\cnmpagenumfont{\sffamily\fontsize{7}{9}\selectfont\bfseries}%
    1422 %%%  \def\runningheadfont{\sffamily\fontsize{7}{9}\scshape\selectfont}%
    1423   \def\runningheadfont{\sffamily\fontsize{7}{9}\selectfont}%New updations 19aug2016
    1424   \def\runningfootfont{\sffamily\fontsize{7}{9}\selectfont}%
    1425   \def\titlepageheadfont{\sffamily\fontsize{7}{9}\selectfont}%
     1420  \def\pagenumfont{\rmfamily\fontsize{7}{9}\bfseries\selectfont}%
     1421  \def\cnmpagenumfont{\rmfamily\fontsize{7}{9}\selectfont\bfseries}%
     1422%%%  \def\runningheadfont{\rmfamily\fontsize{7}{9}\scshape\selectfont}%
     1423  \def\runningheadfont{\rmfamily\fontsize{7}{9}\selectfont}%New updations 19aug2016
     1424  \def\runningfootfont{\rmfamily\fontsize{7}{9}\selectfont}%
     1425  \def\titlepageheadfont{\rmfamily\fontsize{7}{9}\selectfont}%
    14261426  %
    1427   \def\BRarttypefont{\reset@font\sffamily\fontsize{18}{18}\fontseries{b}\selectfont}%
    1428   \def\pubheadfont{\reset@font\sffamily\fontsize{7}{9}\fontseries{b}\selectfont}%
    1429   \def\arttypefont{\sffamily\fontsize{9}{9}\fontseries{b}\selectfont}%
    1430   \def\SParttypefont{\sffamily\fontsize{9}{12}\fontseries{b}\selectfont}%
    1431   \def\titlefont{\sffamily\fontsize{18}{23}\bfseries\selectfont\leftskip\z@\rightskip\z@ plus1fil}%
    1432   \def\subtitlefont{\sffamily\fontsize{16}{21}\bfseries\selectfont\leftskip\z@\rightskip\z@ plus1fil}%
    1433   \def\Authorfont{\sffamily\fontsize{12}{18}\selectfont\leftskip\z@\rightskip\z@ plus1fil}%
    1434   \def\absheadfont{\hsize\abs@colii@hsize\sffamily\fontsize{10}{10}\fontseries{b}\selectfont\bfseries\leftskip7\p@\rightskip\leftskip}% LN20FEB2016
    1435   \def\legalstatementfont{\sffamily\fontsize{7}{10}\selectfont\leftskip0\p@\rightskip\leftskip}%
    1436     \def\BRsectionfont{\sffamily\fontsize{10}{16}\fontseries{b}\selectfont\leftskip\z@\rightskip\z@ plus1fil}%
    1437   \def\sectionfont{\sffamily\fontsize{12}{13}\fontseries{b}\selectfont\leftskip\z@\rightskip\z@ plus1fil}%
    1438   \def\subsectionfont{\sffamily\fontsize{12}{13}\bfseries\selectfont\leftskip\z@\rightskip\z@ plus1fil}%
    1439   \def\subsubsectionfont{\sffamily\fontsize{12}{13}\bfseries\selectfont\leftskip\z@\rightskip\z@ plus1fil}%
    1440   \def\paragraphfont{\sffamily\fontsize{10.5}{13}\fontseries{b}\selectfont}%
    1441   \def\subparagraphfont{\sffamily\fontsize{10}{13}\fontseries{b}\selectfont}%
    1442   \def\appsectionfont{\sffamily\fontsize{10}{13}\fontseries{b}\selectfont\leftskip\z@\rightskip\z@ plus1fil}%
     1427  \def\BRarttypefont{\reset@font\rmfamily\fontsize{18}{18}\fontseries{b}\selectfont}%
     1428  \def\pubheadfont{\reset@font\rmfamily\fontsize{7}{9}\fontseries{b}\selectfont}%
     1429  \def\arttypefont{\rmfamily\fontsize{9}{9}\fontseries{b}\selectfont}%
     1430  \def\SParttypefont{\rmfamily\fontsize{9}{12}\fontseries{b}\selectfont}%
     1431  \def\titlefont{\rmfamily\fontsize{18}{23}\bfseries\selectfont\leftskip\z@\rightskip\z@ plus1fil}%
     1432  \def\subtitlefont{\rmfamily\fontsize{16}{21}\bfseries\selectfont\leftskip\z@\rightskip\z@ plus1fil}%
     1433  \def\Authorfont{\rmfamily\fontsize{12}{18}\selectfont\leftskip\z@\rightskip\z@ plus1fil}%
     1434  \def\absheadfont{\hsize\abs@colii@hsize\rmfamily\fontsize{10}{10}\fontseries{b}\selectfont\bfseries\leftskip7\p@\rightskip\leftskip}% LN20FEB2016
     1435  \def\legalstatementfont{\rmfamily\fontsize{7}{10}\selectfont\leftskip0\p@\rightskip\leftskip}%
     1436    \def\BRsectionfont{\rmfamily\fontsize{10}{16}\fontseries{b}\selectfont\leftskip\z@\rightskip\z@ plus1fil}%
     1437  \def\sectionfont{\rmfamily\fontsize{12}{13}\fontseries{b}\selectfont\leftskip\z@\rightskip\z@ plus1fil}%
     1438  \def\subsectionfont{\rmfamily\fontsize{12}{13}\bfseries\selectfont\leftskip\z@\rightskip\z@ plus1fil}%
     1439  \def\subsubsectionfont{\rmfamily\fontsize{12}{13}\bfseries\selectfont\leftskip\z@\rightskip\z@ plus1fil}%
     1440  \def\paragraphfont{\rmfamily\fontsize{10.5}{13}\fontseries{b}\selectfont}%
     1441  \def\subparagraphfont{\rmfamily\fontsize{10}{13}\fontseries{b}\selectfont}%
     1442  \def\appsectionfont{\rmfamily\fontsize{10}{13}\fontseries{b}\selectfont\leftskip\z@\rightskip\z@ plus1fil}%
    14431443  %
    1444   \def\boxheadfont{\sffamily\fontsize{10}{13}\fontseries{b}\selectfont}
    1445   \def\boxtitlefont{\sffamily\fontsize{10}{13}\bfseries\selectfont}
     1444  \def\boxheadfont{\rmfamily\fontsize{10}{13}\fontseries{b}\selectfont}
     1445  \def\boxtitlefont{\rmfamily\fontsize{10}{13}\bfseries\selectfont}
    14461446  %
    1447   \def\GnSabsfont{\sffamily\fontsize{9}{15}\selectfont}%
    1448   \def\GnSabsfootfont{\reset@font\sffamily\fontsize{14}{0}\bfseries\selectfont}%
     1447  \def\GnSabsfont{\rmfamily\fontsize{9}{15}\selectfont}%
     1448  \def\GnSabsfootfont{\reset@font\rmfamily\fontsize{14}{0}\bfseries\selectfont}%
    14491449  %
    1450   \def\suppinfofont{\noindent\sffamily}%
     1450  \def\suppinfofont{\noindent\rmfamily}%
    14511451  \def\suppinfoheadfont{\noindent\fontsize{10}{13}\fontseries{b}\selectfont}%
    1452   \def\suppinfocaptionfont{\noindent\sffamily}%
     1452  \def\suppinfocaptionfont{\noindent\rmfamily}%
    14531453  %
    1454   \def\figurenumfont{\sffamily\fontsize{9bp}{12}\fontseries{b}\selectfont}%
    1455   \def\figurecaptionfont{\sffamily\fontsize{8.5bp}{12}\selectfont}
     1454  \def\figurenumfont{\rmfamily\fontsize{9bp}{12}\fontseries{b}\selectfont}%
     1455  \def\figurecaptionfont{\rmfamily\fontsize{8.5bp}{12}\selectfont}
    14561456  \def\bwfiginfofont{\fontfamily{tim}\fontsize{10bp}{10bp}\selectfont}%
    14571457  %
    1458   \def\tablenumfont{\sffamily\fontsize{9bp}{11.5bp}\fontseries{b}\selectfont}%
    1459   \def\keypointheadfont{\reset@font\sffamily\fontsize{10bp}{13bp}\fontseries{b}\selectfont}%
    1460   \def\tablecaptionfont{\sffamily\fontsize{8.5bp}{12bp}\selectfont}
    1461   \def\tablebodyfont{\sffamily\fontsize{8.5bp}{11.5bp}\selectfont}
    1462   \def\tablecolheadfont{\sffamily\fontsize{8.5bp}{11.5bp}\selectfont\bfseries}
    1463   \def\tablefootnotefont{\sffamily\fontsize{7.5bp}{10.5bp}\selectfont}
     1458  \def\tablenumfont{\rmfamily\fontsize{9bp}{11.5bp}\fontseries{b}\selectfont}%
     1459  \def\keypointheadfont{\reset@font\rmfamily\fontsize{10bp}{13bp}\fontseries{b}\selectfont}%
     1460  \def\tablecaptionfont{\rmfamily\fontsize{8.5bp}{12bp}\selectfont}
     1461  \def\tablebodyfont{\rmfamily\fontsize{8.5bp}{11.5bp}\selectfont}
     1462  \def\tablecolheadfont{\rmfamily\fontsize{8.5bp}{11.5bp}\selectfont\bfseries}
     1463  \def\tablefootnotefont{\rmfamily\fontsize{7.5bp}{10.5bp}\selectfont}
    14641464  %
    1465 %%  \def\footnotetextfont{\sffamily\fontsize{8bp}{10bp}\selectfont}
     1465%%  \def\footnotetextfont{\rmfamily\fontsize{8bp}{10bp}\selectfont}
    14661466  %
    14671467  \def\listfont{\normalsize}%
     
    14731473  %
    14741474  \def\ackheadfont{\fontsize{10}{13}\selectfont\fontseries{b}\selectfont}
    1475   \def\addressfont{\hsize\abs@coli@hsize\sffamily\fontsize{8}{11}\selectfont\leftskip\z@\rightskip\z@ plus1fil}%
    1476   \def\corresfont{\hsize\abs@coli@hsize\sffamily\fontsize{8}{11}\selectfont\leftskip\z@\rightskip\z@ plus1fil}%
    1477   \def\FIfont{\hsize\abs@coli@hsize\sffamily\fontsize{8}{11}\selectfont\leftskip\z@\rightskip\z@ plus1fil}%
    1478   \def\JELfont{\hsize\abs@coli@hsize\sffamily\fontsize{8}{11}\selectfont\leftskip\z@\rightskip\z@ plus1fil}%
    1479   \def\keywordsheadfont{\hsize\abs@colii@hsize\sffamily\fontsize{8}{8}\selectfont\ifAbstractexist\leftskip7\p@\rightskip\leftskip\fi}%
    1480   \def\abstractfont{\hsize\abs@colii@hsize\sffamily\fontsize{9}{14}\selectfont\leftskip7\p@\rightskip\leftskip}%
    1481   \def\keywordsfont{\sffamily\fontsize{8}{13}\selectfont\ifAbstractexist\leftskip7\p@\rightskip\leftskip\fi}%
     1475  \def\addressfont{\hsize\abs@coli@hsize\rmfamily\fontsize{8}{11}\selectfont\leftskip\z@\rightskip\z@ plus1fil}%
     1476  \def\corresfont{\hsize\abs@coli@hsize\rmfamily\fontsize{8}{11}\selectfont\leftskip\z@\rightskip\z@ plus1fil}%
     1477  \def\FIfont{\hsize\abs@coli@hsize\rmfamily\fontsize{8}{11}\selectfont\leftskip\z@\rightskip\z@ plus1fil}%
     1478  \def\JELfont{\hsize\abs@coli@hsize\rmfamily\fontsize{8}{11}\selectfont\leftskip\z@\rightskip\z@ plus1fil}%
     1479  \def\keywordsheadfont{\hsize\abs@colii@hsize\rmfamily\fontsize{8}{8}\selectfont\ifAbstractexist\leftskip7\p@\rightskip\leftskip\fi}%
     1480  \def\abstractfont{\hsize\abs@colii@hsize\rmfamily\fontsize{10}{15}\selectfont\leftskip7\p@\rightskip\leftskip}%
     1481  \def\keywordsfont{\rmfamily\fontsize{8}{13}\selectfont\ifAbstractexist\leftskip7\p@\rightskip\leftskip\fi}%
    14821482  %
    14831483}%
     
    14881488%  \def\watermarkfont{\reset@font\fontfamily{\ffdefault}\fontsize{45}{45}\bfseries\selectfont}
    14891489  %
    1490   \def\pagenumfont{\sffamily\fontsize{7}{9}\bfseries\selectfont}%
    1491   \def\cnmpagenumfont{\sffamily\fontsize{7}{9}\selectfont\bfseries}%
    1492 %%%  \def\runningheadfont{\sffamily\fontsize{7}{9}\scshape\selectfont}%
    1493   \def\runningheadfont{\sffamily\fontsize{7}{9}\selectfont}%New updations 19aug2016
    1494   \def\runningfootfont{\sffamily\fontsize{7}{9}\selectfont}%
    1495   \def\titlepageheadfont{\sffamily\fontsize{7}{9}\selectfont}%
     1490  \def\pagenumfont{\rmfamily\fontsize{7}{9}\bfseries\selectfont}%
     1491  \def\cnmpagenumfont{\rmfamily\fontsize{7}{9}\selectfont\bfseries}%
     1492%%%  \def\runningheadfont{\rmfamily\fontsize{7}{9}\scshape\selectfont}%
     1493  \def\runningheadfont{\rmfamily\fontsize{7}{9}\selectfont}%New updations 19aug2016
     1494  \def\runningfootfont{\rmfamily\fontsize{7}{9}\selectfont}%
     1495  \def\titlepageheadfont{\rmfamily\fontsize{7}{9}\selectfont}%
    14961496  %
    1497   \def\BRarttypefont{\reset@font\sffamily\fontsize{18}{18}\fontseries{b}\selectfont}%
    1498   \def\pubheadfont{\reset@font\sffamily\fontsize{7}{9}\fontseries{b}\selectfont}%
    1499   \def\arttypefont{\sffamily\fontsize{9}{9}\fontseries{b}\selectfont}%
    1500   \def\SParttypefont{\sffamily\fontsize{9}{12}\fontseries{b}\selectfont}%
    1501   \def\titlefont{\sffamily\fontsize{18}{23}\bfseries\selectfont\leftskip\z@\rightskip\z@ plus1fil\let\mathbcal\titmathbcal}%
    1502   \def\subtitlefont{\sffamily\fontsize{16}{21}\bfseries\selectfont\leftskip\z@\rightskip\z@ plus1fil}%
    1503   \def\Authorfont{\sffamily\fontsize{12}{18}\selectfont\bfseries\leftskip\z@\rightskip\z@ plus1fil}%
    1504   \def\addressfont{\hsize\abs@coli@hsize\sffamily\fontsize{7}{10}\selectfont\leftskip\z@\rightskip\z@ plus1fil}%
    1505   \def\corresfont{\hsize\abs@coli@hsize\sffamily\fontsize{7}{10}\selectfont\leftskip\z@\rightskip\z@ plus1fil}%
     1497  \def\BRarttypefont{\reset@font\rmfamily\fontsize{18}{18}\fontseries{b}\selectfont}%
     1498  \def\pubheadfont{\reset@font\rmfamily\fontsize{7}{9}\fontseries{b}\selectfont}%
     1499  \def\arttypefont{\rmfamily\fontsize{9}{9}\fontseries{b}\selectfont}%
     1500  \def\SParttypefont{\rmfamily\fontsize{9}{12}\fontseries{b}\selectfont}%
     1501  \def\titlefont{\rmfamily\fontsize{18}{23}\bfseries\selectfont\leftskip\z@\rightskip\z@ plus1fil\let\mathbcal\titmathbcal}%
     1502  \def\subtitlefont{\rmfamily\fontsize{16}{21}\bfseries\selectfont\leftskip\z@\rightskip\z@ plus1fil}%
     1503  \def\Authorfont{\rmfamily\fontsize{12}{18}\selectfont\bfseries\leftskip\z@\rightskip\z@ plus1fil}%
     1504  \def\addressfont{\hsize\abs@coli@hsize\rmfamily\fontsize{7}{10}\selectfont\leftskip\z@\rightskip\z@ plus1fil}%
     1505  \def\corresfont{\hsize\abs@coli@hsize\rmfamily\fontsize{7}{10}\selectfont\leftskip\z@\rightskip\z@ plus1fil}%
    15061506  %
    1507   \def\FIfont{\hsize\abs@coli@hsize\sffamily\fontsize{7}{10}\selectfont\leftskip\z@\rightskip\z@ plus1fil}%
    1508   \def\JELfont{\hsize\abs@coli@hsize\sffamily\fontsize{7}{10}\selectfont\leftskip\z@\rightskip\z@ plus1fil}%
    1509   \def\abstractfont{\hsize\abs@colii@hsize\sffamily\fontsize{8}{13}\selectfont\leftskip7\p@\rightskip\leftskip}%
    1510   \def\keywordsheadfont{\hsize\abs@colii@hsize\sffamily\fontsize{7}{7}\selectfont\ifAbstractexist\leftskip7\p@\rightskip\leftskip\fi}%
    1511   \def\absheadfont{\hsize\abs@colii@hsize\sffamily\fontsize{10}{10}\fontseries{b}\selectfont\bfseries\leftskip7\p@\rightskip\leftskip}% LN20FEB2016
    1512   \def\keywordsfont{\sffamily\fontsize{8}{13}\selectfont\ifAbstractexist\leftskip7\p@\rightskip\leftskip\fi}%
    1513   \def\legalstatementfont{\sffamily\fontsize{7}{10}\selectfont\leftskip0\p@\rightskip\leftskip}%
     1507  \def\FIfont{\hsize\abs@coli@hsize\rmfamily\fontsize{7}{10}\selectfont\leftskip\z@\rightskip\z@ plus1fil}%
     1508  \def\JELfont{\hsize\abs@coli@hsize\rmfamily\fontsize{7}{10}\selectfont\leftskip\z@\rightskip\z@ plus1fil}%
     1509  \def\abstractfont{\hsize\abs@colii@hsize\rmfamily\fontsize{8}{13}\selectfont\leftskip7\p@\rightskip\leftskip}%
     1510  \def\keywordsheadfont{\hsize\abs@colii@hsize\rmfamily\fontsize{7}{7}\selectfont\ifAbstractexist\leftskip7\p@\rightskip\leftskip\fi}%
     1511  \def\absheadfont{\hsize\abs@colii@hsize\rmfamily\fontsize{10}{10}\fontseries{b}\selectfont\bfseries\leftskip7\p@\rightskip\leftskip}% LN20FEB2016
     1512  \def\keywordsfont{\rmfamily\fontsize{8}{13}\selectfont\ifAbstractexist\leftskip7\p@\rightskip\leftskip\fi}%
     1513  \def\legalstatementfont{\rmfamily\fontsize{7}{10}\selectfont\leftskip0\p@\rightskip\leftskip}%
    15141514  %
    1515   \def\BRsectionfont{\sffamily\fontsize{10}{16}\fontseries{b}\selectfont\leftskip\z@\rightskip\z@ plus1fil}%
    1516   \def\sectionfont{\sffamily\fontsize{10}{13}\fontseries{b}\selectfont\leftskip\z@\rightskip\z@ plus1fil}%
    1517   \def\subsectionfont{\sffamily\fontsize{10}{14}\bfseries\selectfont\leftskip\z@\rightskip\z@ plus1fil}%
    1518   \def\subsubsectionfont{\sffamily\fontsize{9}{12.5}\bfseries\selectfont\leftskip\z@\rightskip\z@ plus1fil}%
    1519   \def\paragraphfont{\sffamily\fontsize{8.5}{13}\fontseries{b}\selectfont}%
    1520   \def\subparagraphfont{\sffamily\fontsize{8.5}{13}\fontseries{b}\selectfont}%
    1521   \def\appsectionfont{\sffamily\fontsize{8}{11}\fontseries{b}\selectfont\leftskip\z@\rightskip\z@ plus1fil}%
     1515  \def\BRsectionfont{\rmfamily\fontsize{10}{16}\fontseries{b}\selectfont\leftskip\z@\rightskip\z@ plus1fil}%
     1516  \def\sectionfont{\rmfamily\fontsize{10}{13}\fontseries{b}\selectfont\leftskip\z@\rightskip\z@ plus1fil}%
     1517  \def\subsectionfont{\rmfamily\fontsize{10}{14}\bfseries\selectfont\leftskip\z@\rightskip\z@ plus1fil}%
     1518  \def\subsubsectionfont{\rmfamily\fontsize{9}{12.5}\bfseries\selectfont\leftskip\z@\rightskip\z@ plus1fil}%
     1519  \def\paragraphfont{\rmfamily\fontsize{8.5}{13}\fontseries{b}\selectfont}%
     1520  \def\subparagraphfont{\rmfamily\fontsize{8.5}{13}\fontseries{b}\selectfont}%
     1521  \def\appsectionfont{\rmfamily\fontsize{8}{11}\fontseries{b}\selectfont\leftskip\z@\rightskip\z@ plus1fil}%
    15221522  %
    1523   \def\boxheadfont{\sffamily\fontsize{8}{10}\fontseries{b}\selectfont}
    1524   \def\boxtitlefont{\sffamily\fontsize{8}{10}\bfseries\selectfont}
     1523  \def\boxheadfont{\rmfamily\fontsize{8}{10}\fontseries{b}\selectfont}
     1524  \def\boxtitlefont{\rmfamily\fontsize{8}{10}\bfseries\selectfont}
    15251525  %
    1526   \def\GnSabsfont{\sffamily\fontsize{9}{15}\selectfont}%
    1527   \def\GnSabsfootfont{\reset@font\sffamily\fontsize{14}{0}\bfseries\selectfont}%
     1526  \def\GnSabsfont{\rmfamily\fontsize{9}{15}\selectfont}%
     1527  \def\GnSabsfootfont{\reset@font\rmfamily\fontsize{14}{0}\bfseries\selectfont}%
    15281528  %
    1529   \def\suppinfofont{\noindent\sffamily}%
     1529  \def\suppinfofont{\noindent\rmfamily}%
    15301530  \def\suppinfoheadfont{\noindent\fontsize{8}{13}\fontseries{b}\selectfont}%
    1531   \def\suppinfocaptionfont{\noindent\sffamily}%
     1531  \def\suppinfocaptionfont{\noindent\rmfamily}%
    15321532  %
    1533   \def\figurenumfont{\sffamily\fontsize{7bp}{9}\fontseries{b}\selectfont}%
    1534   \def\figurecaptionfont{\sffamily\fontsize{8bp}{11}\selectfont}
     1533  \def\figurenumfont{\rmfamily\fontsize{7bp}{9}\fontseries{b}\selectfont}%
     1534  \def\figurecaptionfont{\rmfamily\fontsize{8bp}{11}\selectfont}
    15351535  \def\bwfiginfofont{\fontfamily{tim}\fontsize{10bp}{10bp}\selectfont}%
    15361536  %
    1537   \def\tablenumfont{\sffamily\fontsize{7bp}{9bp}\fontseries{b}\selectfont}%
    1538   \def\keypointheadfont{\reset@font\sffamily\fontsize{9bp}{11bp}\fontseries{b}\selectfont}%
    1539   \def\tablecaptionfont{\sffamily\fontsize{8bp}{9bp}\selectfont}
    1540   \def\tablebodyfont{\sffamily\fontsize{7.5bp}{9bp}\selectfont}
    1541   \def\tablecolheadfont{\sffamily\fontsize{7.5bp}{9bp}\selectfont\bfseries}
    1542   \def\tablefootnotefont{\sffamily\fontsize{7.5bp}{9bp}\selectfont}
     1537  \def\tablenumfont{\rmfamily\fontsize{7bp}{9bp}\fontseries{b}\selectfont}%
     1538  \def\keypointheadfont{\reset@font\rmfamily\fontsize{9bp}{11bp}\fontseries{b}\selectfont}%
     1539  \def\tablecaptionfont{\rmfamily\fontsize{8bp}{9bp}\selectfont}
     1540  \def\tablebodyfont{\rmfamily\fontsize{7.5bp}{9bp}\selectfont}
     1541  \def\tablecolheadfont{\rmfamily\fontsize{7.5bp}{9bp}\selectfont\bfseries}
     1542  \def\tablefootnotefont{\rmfamily\fontsize{7.5bp}{9bp}\selectfont}
    15431543  %
    1544 %%  \def\footnotetextfont{\sffamily\fontsize{8bp}{10bp}\selectfont}
     1544%%  \def\footnotetextfont{\rmfamily\fontsize{8bp}{10bp}\selectfont}
    15451545  %
    15461546  \def\listfont{\normalsize}%
  • doc/papers/concurrency/Paper.tex

    ra0c7d5cc r534d84e  
    2222\captionsetup{justification=raggedright,singlelinecheck=false}
    2323\usepackage{siunitx}
    24 \sisetup{ binary-units=true }
     24\sisetup{binary-units=true}
    2525
    2626\hypersetup{breaklinks=true}
     
    3232\renewcommand{\linenumberfont}{\scriptsize\sffamily}
    3333
    34 \renewcommand{\textfraction}{0.0}       % the entire page maybe devoted to floats with no text on the page at all
     34\renewcommand{\textfraction}{0.0}                       % the entire page maybe devoted to floats with no text on the page at all
    3535
    3636\lefthyphenmin=3                                                        % hyphen only after 4 characters
     
    7070%\DeclareTextCommandDefault{\textunderscore}{\leavevmode\makebox[1.2ex][c]{\rule{1ex}{0.1ex}}}
    7171\renewcommand{\textunderscore}{\leavevmode\makebox[1.2ex][c]{\rule{1ex}{0.075ex}}}
     72%\def\myCHarFont{\fontencoding{T1}\selectfont}%
     73% \def\{{\ttfamily\upshape\myCHarFont \char`\}}}%
    7274
    7375\makeatletter
     
    244246\maketitle
    245247
    246 % ======================================================================
    247 % ======================================================================
     248
    248249\section{Introduction}
    249 % ======================================================================
    250 % ======================================================================
    251250
    252251This paper provides a minimal concurrency \newterm{Abstract Program Interface} (API) that is simple, efficient and can be used to build other concurrency features.
     
    254253An easier approach for programmers is to support higher-level constructs as the basis of concurrency.
    255254Indeed, for highly productive concurrent programming, high-level approaches are much more popular~\cite{Hochstein05}.
    256 Examples of high-level approaches are task based~\cite{TBB}, message passing~\cite{Erlang,MPI}, and implicit threading~\cite{OpenMP}.
     255Examples of high-level approaches are task (work) based~\cite{TBB}, implicit threading~\cite{OpenMP}, monitors~\cite{Java}, channels~\cite{CSP,Go}, and message passing~\cite{Erlang,MPI}.
    257256
    258257This paper uses the following terminology.
     
    272271The paper discusses how the language features are added to the \CFA translator with respect to parsing, semantic, and type checking, and the corresponding high-perforamnce runtime-library to implement the concurrency features.
    273272
    274 % ======================================================================
    275 % ======================================================================
     273
    276274\section{\CFA Overview}
    277 % ======================================================================
    278 % ======================================================================
    279275
    280276The following is a quick introduction to the \CFA language, specifically tailored to the features needed to support concurrency.
    281 Most of the following code examples can be found on the \CFA website~\cite{Cforall}.
    282 
    283 \CFA is an extension of ISO-C, and therefore, supports all of the same paradigms as C.
     277Extended versions of the following code examples are available at the \CFA website~\cite{Cforall} or Moss~\etal~\cite{XXX}.
     278
     279\CFA is an extension of ISO-C, and hence, supports all C paradigms.
    284280%It is a non-object-oriented system-language, meaning most of the major abstractions have either no runtime overhead or can be opted out easily.
    285 Like C, the basics of \CFA revolve around structures and routines, which are thin abstractions over machine code.
    286 The vast majority of the code produced by the \CFA translator respects memory layouts and calling conventions laid out by C.
    287 Interestingly, while \CFA is not an object-oriented language, lacking the concept of a receiver (\eg @this@) and inheritance, it does have some notion of objects\footnote{C defines the term objects as : ``region of data storage in the execution environment, the contents of which can represent
    288 values''~\cite[3.15]{C11}}, most importantly construction and destruction of objects.
     281Like C, the basics of \CFA revolve around structures and functions.
     282Virtually all of the code generated by the \CFA translator respects C memory layouts and calling conventions.
     283While \CFA is not an object-oriented language, lacking the concept of a receiver (\eg @this@) and nominal inheritance-relationships, C does have a notion of objects: ``region of data storage in the execution environment, the contents of which can represent values''~\cite[3.15]{C11}.
    289284
    290285
    291286\subsection{References}
    292287
    293 Like \CC, \CFA introduces rebind-able references providing multiple dereferencing as an alternative to pointers.
    294 In regards to concurrency, the semantic difference between pointers and references are not particularly relevant, but since this document uses mostly references, here is a quick overview of the semantics:
    295 \begin{cfa}
    296 int x, y, z;
    297 int * p1 = &x, ** p2 = &p1, *** p3 = &p2,       $\C{// pointers to x}$
    298         & r1 = x,   && r2 = r1, &&& r3 = r2;    $\C{// references to x}$
    299 
    300 *p1 = 3; **p2 = 3; ***p3 = 3;                           $\C{// change x}$
    301   r1 = 3;    r2 = 3;      r3 = 3;                       $\C{// change x}$
    302 **p3 = &y; *p3 = &z;                                            $\C{// change p1, p2}$
    303 &&r3 = &y; &r3 = &z;                                            $\C{// change p1, p2}$
    304 int & ar[3] = {x, y, z};                                        $\C{// initialize array of references}$
    305 
    306 typeof( ar[1]) p;                                                       $\C{// is int, referenced object type}$
    307 typeof(&ar[1]) q;                                                       $\C{// is int \&, reference type}$
    308 sizeof( ar[1]) == sizeof(int);                          $\C{// is true, referenced object size}$
    309 sizeof(&ar[1]) == sizeof(int *);                        $\C{// is true, reference size}$
    310 \end{cfa}
    311 The important take away from this code example is that a reference offers a handle to an object, much like a pointer, but which is automatically dereferenced for convenience.
    312 
    313 % ======================================================================
     288\CFA provides multi-level rebindable references, as an alternative to pointers, which significantly reduces syntactic noise.
     289\begin{cfa}
     290int x = 1, y = 2, z = 3;
     291int * p1 = &x, ** p2 = &p1,  *** p3 = &p2,      $\C{// pointers to x}$
     292        `&` r1 = x,  `&&` r2 = r1,  `&&&` r3 = r2;      $\C{// references to x}$
     293int * p4 = &z, `&` r4 = z;
     294
     295*p1 = 3; **p2 = 3; ***p3 = 3;       // change x
     296r1 =  3;     r2 = 3;      r3 = 3;        // change x: implicit dereferences *r1, **r2, ***r3
     297**p3 = &y; *p3 = &p4;                // change p1, p2
     298`&`r3 = &y; `&&`r3 = &`&`r4;             // change r1, r2: cancel implicit deferences (&*)**r3, (&(&*)*)*r3, &(&*)r4
     299\end{cfa}
     300A reference is a handle to an object, like a pointer, but is automatically dereferenced the specified number of levels.
     301Referencing (address-of @&@) a reference variable cancels one of the implicit dereferences, until there are no more implicit references, after which normal expression behaviour applies.
     302
     303
     304\subsection{\texorpdfstring{\protect\lstinline{with} Statement}{with Statement}}
     305\label{s:WithStatement}
     306
     307Heterogeneous data is often aggregated into a structure/union.
     308To reduce syntactic noise, \CFA provides a @with@ statement (see Pascal~\cite[\S~4.F]{Pascal}) to elide aggregate field-qualification by opening a scope containing the field identifiers.
     309\begin{cquote}
     310\vspace*{-\baselineskip}%???
     311\lstDeleteShortInline@%
     312\begin{cfa}
     313struct S { char c; int i; double d; };
     314struct T { double m, n; };
     315// multiple aggregate parameters
     316\end{cfa}
     317\begin{tabular}{@{}l@{\hspace{\parindentlnth}}|@{\hspace{\parindentlnth}}l@{}}
     318\begin{cfa}
     319void f( S & s, T & t ) {
     320        `s.`c; `s.`i; `s.`d;
     321        `t.`m; `t.`n;
     322}
     323\end{cfa}
     324&
     325\begin{cfa}
     326void f( S & s, T & t ) `with ( s, t )` {
     327        c; i; d;                // no qualification
     328        m; n;
     329}
     330\end{cfa}
     331\end{tabular}
     332\lstMakeShortInline@%
     333\end{cquote}
     334Object-oriented programming languages only provide implicit qualification for the receiver.
     335
     336In detail, the @with@ statement has the form:
     337\begin{cfa}
     338$\emph{with-statement}$:
     339        'with' '(' $\emph{expression-list}$ ')' $\emph{compound-statement}$
     340\end{cfa}
     341and may appear as the body of a function or nested within a function body.
     342Each expression in the expression-list provides a type and object.
     343The type must be an aggregate type.
     344(Enumerations are already opened.)
     345The object is the implicit qualifier for the open structure-fields.
     346All expressions in the expression list are open in parallel within the compound statement, which is different from Pascal, which nests the openings from left to right.
     347
     348
    314349\subsection{Overloading}
    315350
    316 Another important feature of \CFA is function overloading as in Java and \CC, where routines with the same name are selected based on the number and type of the arguments.
    317 As well, \CFA uses the return type as part of the selection criteria, as in Ada~\cite{Ada}.
    318 For routines with multiple parameters and returns, the selection is complex.
     351\CFA maximizes the ability to reuse names via overloading to aggressively address the naming problem.
     352Both variables and functions may be overloaded, where selection is based on types, and number of returns (as in Ada~\cite{Ada}) and arguments.
     353\begin{cquote}
     354\vspace*{-\baselineskip}%???
     355\lstDeleteShortInline@%
     356\begin{cfa}
     357// selection based on type
     358\end{cfa}
     359\begin{tabular}{@{}l@{\hspace{\parindentlnth}}|@{\hspace{\parindentlnth}}l@{}}
     360\begin{cfa}
     361const short int MIN = -32768;
     362const int MIN = -2147483648;
     363const long int MIN = -9223372036854775808L;
     364\end{cfa}
     365&
     366\begin{cfa}
     367short int si = MIN;
     368int i = MIN;
     369long int li = MIN;
     370\end{cfa}
     371\end{tabular}
    319372\begin{cfa}
    320373// selection based on type and number of parameters
    321 void f(void);                   $\C{// (1)}$
    322 void f(char);                   $\C{// (2)}$
    323 void f(int, double);    $\C{// (3)}$
    324 f();                                    $\C{// select (1)}$
    325 f('a');                                 $\C{// select (2)}$
    326 f(3, 5.2);                              $\C{// select (3)}$
    327 
    328 // selection based on  type and number of returns
    329 char   f(int);                  $\C{// (1)}$
    330 double f(int);                  $\C{// (2)}$
    331 char   c = f(3);                $\C{// select (1)}$
    332 double d = f(4);                $\C{// select (2)}$
    333 \end{cfa}
    334 This feature is particularly important for concurrency since the runtime system relies on creating different types to represent concurrency objects.
     374\end{cfa}
     375\begin{tabular}{@{}l@{\hspace{1.7\parindentlnth}}|@{\hspace{\parindentlnth}}l@{}}
     376\begin{cfa}
     377void f( void );
     378void f( char );
     379void f( int, double );
     380\end{cfa}
     381&
     382\begin{cfa}
     383f();
     384f( 'a' );
     385f( 3, 5.2 );
     386\end{cfa}
     387\end{tabular}
     388\begin{cfa}
     389// selection based on type and number of returns
     390\end{cfa}
     391\begin{tabular}{@{}l@{\hspace{\parindentlnth}}|@{\hspace{\parindentlnth}}l@{}}
     392\begin{cfa}
     393char f( int );
     394double f( int );
     395[char, double] f( int );
     396\end{cfa}
     397&
     398\begin{cfa}
     399char c = f( 3 );
     400double d = f( 3 );
     401[d, c] = f( 3 );
     402\end{cfa}
     403\end{tabular}
     404\lstMakeShortInline@%
     405\end{cquote}
     406Overloading is important for \CFA concurrency since the runtime system relies on creating different types to represent concurrency objects.
    335407Therefore, overloading is necessary to prevent the need for long prefixes and other naming conventions that prevent name clashes.
    336 As seen in section \ref{basics}, routine @main@ is an example that benefits from overloading.
    337 
    338 % ======================================================================
     408As seen in Section~\ref{basics}, function @main@ is heavily overloaded.
     409
     410Variable overloading is useful in the parallel semantics of the @with@ statement for fields with the same name:
     411\begin{cfa}
     412struct S { int `i`; int j; double m; } s;
     413struct T { int `i`; int k; int m; } t;
     414with ( s, t ) {
     415        j + k;                                                                  $\C{// unambiguous, s.j + t.k}$
     416        m = 5.0;                                                                $\C{// unambiguous, t.m = 5.0}$
     417        m = 1;                                                                  $\C{// unambiguous, s.m = 1}$
     418        int a = m;                                                              $\C{// unambiguous, a = s.i }$
     419        double b = m;                                                   $\C{// unambiguous, b = t.m}$
     420        int c = `s.i` + `t.i`;                                  $\C{// unambiguous, qualification}$
     421        (double)m;                                                              $\C{// unambiguous, cast}$
     422}
     423\end{cfa}
     424For parallel semantics, both @s.i@ and @t.i@ are visible with the same type, so only @i@ is ambiguous without qualification.
     425
     426
    339427\subsection{Operators}
     428
    340429Overloading also extends to operators.
    341 The syntax for denoting operator-overloading is to name a routine with the symbol of the operator and question marks where the arguments of the operation appear, \eg:
    342 \begin{cfa}
    343 int ++? (int op);                       $\C{// unary prefix increment}$
    344 int ?++ (int op);                       $\C{// unary postfix increment}$
    345 int ?+? (int op1, int op2);             $\C{// binary plus}$
    346 int ?<=?(int op1, int op2);             $\C{// binary less than}$
    347 int ?=? (int & op1, int op2);           $\C{// binary assignment}$
    348 int ?+=?(int & op1, int op2);           $\C{// binary plus-assignment}$
    349 
    350 struct S {int i, j;};
    351 S ?+?(S op1, S op2) {                           $\C{// add two structures}$
     430Operator-overloading syntax names a routine with the operator symbol and question marks for the operands:
     431\begin{cquote}
     432\lstDeleteShortInline@%
     433\begin{tabular}{@{}ll@{\hspace{\parindentlnth}}|@{\hspace{\parindentlnth}}l@{}}
     434\begin{cfa}
     435int ++? (int op);
     436int ?++ (int op);
     437int `?+?` (int op1, int op2);
     438int ?<=?(int op1, int op2);
     439int ?=? (int & op1, int op2);
     440int ?+=?(int & op1, int op2);
     441\end{cfa}
     442&
     443\begin{cfa}
     444// unary prefix increment
     445// unary postfix increment
     446// binary plus
     447// binary less than
     448// binary assignment
     449// binary plus-assignment
     450\end{cfa}
     451&
     452\begin{cfa}
     453struct S { int i, j; };
     454S `?+?`( S op1, S op2) { // add two structures
    352455        return (S){op1.i + op2.i, op1.j + op2.j};
    353456}
    354457S s1 = {1, 2}, s2 = {2, 3}, s3;
    355 s3 = s1 + s2;                                           $\C{// compute sum: s3 == {2, 5}}$
    356 \end{cfa}
    357 While concurrency does not use operator overloading directly, this feature is more important as an introduction for the syntax of constructors.
    358 
    359 % ======================================================================
    360 \subsection{Constructors/Destructors}
    361 Object lifetime is often a challenge in concurrency. \CFA uses the approach of giving concurrent meaning to object lifetime as a means of synchronization and/or mutual exclusion.
    362 Since \CFA relies heavily on the lifetime of objects, constructors and destructors is a core feature required for concurrency and parallelism. \CFA uses the following syntax for constructors and destructors:
    363 \begin{cfa}
    364 struct S {
    365         size_t size;
    366         int * ia;
    367 };
    368 void ?{}(S & s, int asize) {    $\C{// constructor operator}$
    369         s.size = asize;                         $\C{// initialize fields}$
    370         s.ia = calloc(size, sizeof(S));
    371 }
    372 void ^?{}(S & s) {                              $\C{// destructor operator}$
    373         free(ia);                                       $\C{// de-initialization fields}$
    374 }
    375 int main() {
    376         S x = {10}, y = {100};          $\C{// implicit calls: ?\{\}(x, 10), ?\{\}(y, 100)}$
    377         ...                                                     $\C{// use x and y}$
    378         ^x{};  ^y{};                            $\C{// explicit calls to de-initialize}$
    379         x{20};  y{200};                         $\C{// explicit calls to reinitialize}$
    380         ...                                                     $\C{// reuse x and y}$
    381 }                                                               $\C{// implicit calls: \^?\{\}(y), \^?\{\}(x)}$
    382 \end{cfa}
    383 The language guarantees that every object and all their fields are constructed.
    384 Like \CC, construction of an object is automatically done on allocation and destruction of the object is done on deallocation.
    385 Allocation and deallocation can occur on the stack or on the heap.
    386 \begin{cfa}
    387 {
    388         struct S s = {10};      $\C{// allocation, call constructor}$
    389         ...
    390 }                                               $\C{// deallocation, call destructor}$
    391 struct S * s = new();   $\C{// allocation, call constructor}$
    392 ...
    393 delete(s);                              $\C{// deallocation, call destructor}$
    394 \end{cfa}
    395 Note that like \CC, \CFA introduces @new@ and @delete@, which behave like @malloc@ and @free@ in addition to constructing and destructing objects, after calling @malloc@ and before calling @free@, respectively.
    396 
    397 % ======================================================================
     458s3 = s1 `+` s2;         // compute sum: s3 == {2, 5}
     459\end{cfa}
     460\end{tabular}
     461\lstMakeShortInline@%
     462\end{cquote}
     463While concurrency does not use operator overloading directly, it provides an introduction for the syntax of constructors.
     464
     465
    398466\subsection{Parametric Polymorphism}
    399467\label{s:ParametricPolymorphism}
    400 Routines in \CFA can also be reused for multiple types.
    401 This capability is done using the @forall@ clauses, which allow separately compiled routines to support generic usage over multiple types.
     468
     469The signature feature of \CFA is parametric-polymorphic functions~\cite{} with functions generalized using a @forall@ clause (giving the language its name), which allow separately compiled routines to support generic usage over multiple types.
    402470For example, the following sum function works for any type that supports construction from 0 and addition:
    403471\begin{cfa}
    404 // constraint type, 0 and +
    405 forall(otype T | { void ?{}(T *, zero_t); T ?+?(T, T); })
    406 T sum(T a[ ], size_t size) {
    407         T total = 0;                            $\C{// construct T from 0}$
    408         for(size_t i = 0; i < size; i++)
    409                 total = total + a[i];   $\C{// select appropriate +}$
     472forall( otype T | { void `?{}`( T *, zero_t ); T `?+?`( T, T ); } ) // constraint type, 0 and +
     473T sum( T a[$\,$], size_t size ) {
     474        `T` total = { `0` };                                    $\C{// initialize by 0 constructor}$
     475        for ( size_t i = 0; i < size; i += 1 )
     476                total = total `+` a[i];                         $\C{// select appropriate +}$
    410477        return total;
    411478}
    412 
    413479S sa[5];
    414 int i = sum(sa, 5);                             $\C{// use S's 0 construction and +}$
    415 \end{cfa}
    416 
    417 Since writing constraints on types can become cumbersome for more constrained functions, \CFA also has the concept of traits.
    418 Traits are named collection of constraints that can be used both instead and in addition to regular constraints:
    419 \begin{cfa}
    420 trait summable( otype T ) {
    421         void ?{}(T *, zero_t);          $\C{// constructor from 0 literal}$
    422         T ?+?(T, T);                            $\C{// assortment of additions}$
    423         T ?+=?(T *, T);
    424         T ++?(T *);
    425         T ?++(T *);
     480int i = sum( sa, 5 );                                           $\C{// use S's 0 construction and +}$
     481\end{cfa}
     482
     483\CFA provides \newterm{traits} to name a group of type assertions, where the trait name allows specifying the same set of assertions in multiple locations, preventing repetition mistakes at each function declaration:
     484\begin{cfa}
     485trait `sumable`( otype T ) {
     486        void `?{}`( T &, zero_t );                              $\C{// 0 literal constructor}$
     487        T `?+?`( T, T );                                                $\C{// assortment of additions}$
     488        T ?+=?( T &, T );
     489        T ++?( T & );
     490        T ?++( T & );
    426491};
    427 forall( otype T | summable(T) ) $\C{// use trait}$
    428 T sum(T a[], size_t size);
    429 \end{cfa}
    430 
    431 Note that the type use for assertions can be either an @otype@ or a @dtype@.
    432 Types declared as @otype@ refer to ``complete'' objects, \ie objects with a size, a default constructor, a copy constructor, a destructor and an assignment operator.
    433 Using @dtype@, on the other hand, has none of these assumptions but is extremely restrictive, it only guarantees the object is addressable.
    434 
    435 % ======================================================================
    436 \subsection{with Clause/Statement}
    437 Since \CFA lacks the concept of a receiver, certain functions end up needing to repeat variable names often.
    438 To remove this inconvenience, \CFA provides the @with@ statement, which opens an aggregate scope making its fields directly accessible (like Pascal).
    439 \begin{cfa}
    440 struct S { int i, j; };
    441 int mem(S & this) with (this)           $\C{// with clause}$
    442         i = 1;                                                  $\C{// this->i}$
    443         j = 2;                                                  $\C{// this->j}$
    444 }
    445 int foo() {
    446         struct S1 { ... } s1;
    447         struct S2 { ... } s2;
    448         with (s1)                                               $\C{// with statement}$
    449         {
    450                 // access fields of s1 without qualification
    451                 with (s2)                                       $\C{// nesting}$
    452                 {
    453                         // access fields of s1 and s2 without qualification
    454                 }
    455         }
    456         with (s1, s2)                                   $\C{// scopes open in parallel}$
    457         {
    458                 // access fields of s1 and s2 without qualification
    459         }
    460 }
    461 \end{cfa}
    462 
    463 For more information on \CFA see \cite{cforall-ug,Schluntz17,www-cfa}.
    464 
    465 % ======================================================================
    466 % ======================================================================
     492forall( otype T `| sumable( T )` )                      $\C{// use trait}$
     493T sum( T a[$\,$], size_t size );
     494\end{cfa}
     495
     496Assertions can be @otype@ or @dtype@.
     497@otype@ refers to a ``complete'' object, \ie an object has a size, default constructor, copy constructor, destructor and an assignment operator.
     498@dtype@ only guarantees an object has a size and alignment.
     499
     500Using the return type for discrimination, it is possible to write a type-safe @alloc@ based on the C @malloc@:
     501\begin{cfa}
     502forall( dtype T | sized(T) ) T * alloc( void ) { return (T *)malloc( sizeof(T) ); }
     503int * ip = alloc();                                                     $\C{// select type and size from left-hand side}$
     504double * dp = alloc();
     505struct S {...} * sp = alloc();
     506\end{cfa}
     507where the return type supplies the type/size of the allocation, which is impossible in most type systems.
     508
     509
     510\subsection{Constructors / Destructors}
     511
     512Object lifetime is a challenge in non-managed programming languages.
     513\CFA responds with \CC-like constructors and destructors:
     514\begin{cfa}
     515struct VLA { int len, * data; };                        $\C{// variable length array of integers}$
     516void ?{}( VLA & vla ) with ( vla ) { len = 10;  data = alloc( len ); }  // default constructor
     517void ?{}( VLA & vla, int size, char fill ) with ( vla ) { len = size;  data = alloc( len, fill ); } // initialization
     518void ?{}( VLA & vla, VLA other ) { vla.len = other.len;  vla.data = other.data; } // copy, shallow
     519void ^?{}( VLA & vla ) with ( vla ) { free( data ); } $\C{// destructor}$
     520{
     521        VLA  x,            y = { 20, 0x01 },     z = y; $\C{// z points to y}$
     522        //    ?{}( x );   ?{}( y, 20, 0x01 );   ?{}( z, y );
     523        ^x{};                                                                   $\C{// deallocate x}$
     524        x{};                                                                    $\C{// reallocate x}$
     525        z{ 5, 0xff };                                                   $\C{// reallocate z, not pointing to y}$
     526        ^y{};                                                                   $\C{// deallocate y}$
     527        y{ x };                                                                 $\C{// reallocate y, points to x}$
     528        x{};                                                                    $\C{// reallocate x, not pointing to y}$
     529        // ^?{}(z);  ^?{}(y);  ^?{}(x);
     530}
     531\end{cfa}
     532Like \CC, construction is implicit on allocation (stack/heap) and destruction is implicit on deallocation.
     533The object and all their fields are constructed/destructed.
     534\CFA also provides @new@ and @delete@, which behave like @malloc@ and @free@, in addition to constructing and destructing objects:
     535\begin{cfa}
     536{       struct S s = {10};                                              $\C{// allocation, call constructor}$
     537        ...
     538}                                                                                       $\C{// deallocation, call destructor}$
     539struct S * s = new();                                           $\C{// allocation, call constructor}$
     540...
     541delete( s );                                                            $\C{// deallocation, call destructor}$
     542\end{cfa}
     543\CFA concurrency uses object lifetime as a means of synchronization and/or mutual exclusion.
     544
     545
    467546\section{Concurrency Basics}\label{basics}
    468 % ======================================================================
    469 % ======================================================================
    470 
    471 At its core, concurrency is based on having multiple call-stacks and scheduling among threads of execution executing on these stacks.
     547
     548At its core, concurrency is based on multiple call-stacks and scheduling among threads executing on these stacks.
    472549Multiple call stacks (or contexts) and a single thread of execution does \emph{not} imply concurrency.
    473550Execution with a single thread and multiple stacks where the thread is deterministically self-scheduling across the stacks is called \newterm{coroutining};
     
    585662\begin{lstlisting}[aboveskip=0pt,belowskip=0pt]
    586663`coroutine` Fib { int fn; };
     664void ?{}( Fibonacci & fib ) with( fib ) { fn = 0; }
    587665void main( Fib & f ) with( f ) {
    588666        int f1, f2;
  • doc/papers/general/Paper.tex

    ra0c7d5cc r534d84e  
    7474\setlength{\gcolumnposn}{3.5in}
    7575\setlength{\columnposn}{\gcolumnposn}
     76
    7677\newcommand{\C}[2][\@empty]{\ifx#1\@empty\else\global\setlength{\columnposn}{#1}\global\columnposn=\columnposn\fi\hfill\makebox[\textwidth-\columnposn][l]{\lst@basicstyle{\LstCommentStyle{#2}}}}
    7778\newcommand{\CRT}{\global\columnposn=\gcolumnposn}
     
    191192This installation base and the programmers producing it represent a massive software-engineering investment spanning decades and likely to continue for decades more.
    192193Nevertheless, C, first standardized over thirty years ago, lacks many features that make programming in more modern languages safer and more productive.
    193 
    194194The goal of the \CFA project is to create an extension of C that provides modern safety and productivity features while still ensuring strong backwards compatibility with C and its programmers.
    195195Prior projects have attempted similar goals but failed to honour C programming-style; for instance, adding object-oriented or functional programming with garbage collection is a non-starter for many C developers.
     
    209209
    210210\section{Introduction}
    211 
    212211The C programming language is a foundational technology for modern computing with millions of lines of code implementing everything from commercial operating-systems to hobby projects.
    213212This installation base and the programmers producing it represent a massive software-engineering investment spanning decades and likely to continue for decades more.
     
    238237\CC is used similarly, but has the disadvantages of multiple legacy design-choices that cannot be updated and active divergence of the language model from C, requiring significant effort and training to incrementally add \CC to a C-based project.
    239238
    240 \CFA is currently implemented as a source-to-source translator from \CFA to the gcc-dialect of C~\cite{GCCExtensions}, allowing it to leverage the portability and code optimizations provided by gcc, meeting goals (1)--(3).
     239\CFA is an \emph{open-source} project implemented as an source-to-source translator from \CFA to the gcc-dialect of C~\cite{GCCExtensions}, allowing it to leverage the portability and code optimizations provided by gcc, meeting goals (1)--(3).
    241240Ultimately, a compiler is necessary for advanced features and optimal performance.
    242241All features discussed in this paper are working, unless otherwise stated as under construction.
     
    266265Code generation for these overloaded functions and variables is implemented by the usual approach of mangling the identifier names to include a representation of their type, while \CFA decides which overload to apply based on the same ``usual arithmetic conversions'' used in C to disambiguate operator overloads.
    267266As an example:
    268 
    269 \begin{cfa}
    270 int max = 2147483647;                                   $\C[4in]{// (1)}$
    271 double max = 1.7976931348623157E+308;   $\C{// (2)}$
     267\begin{cfa}
     268int max = 2147483647;                                           $\C[4in]{// (1)}$
     269double max = 1.7976931348623157E+308;           $\C{// (2)}$
    272270int max( int a, int b ) { return a < b ? b : a; }  $\C{// (3)}$
    273271double max( double a, double b ) { return a < b ? b : a; }  $\C{// (4)}\CRT$
     
    329327A simple example is leveraging the existing type-unsafe (@void *@) C @bsearch@ to binary search a sorted float array:
    330328\begin{cfa}
    331 void * bsearch( const void * key, const void * base, size_t nmemb, size_t size, int (* compar)( const void *, const void * ));
     329void * bsearch( const void * key, const void * base, size_t nmemb, size_t size,
     330                                int (* compar)( const void *, const void * ));
    332331int comp( const void * t1, const void * t2 ) {
    333332         return *(double *)t1 < *(double *)t2 ? -1 : *(double *)t2 < *(double *)t1 ? 1 : 0;
     
    377376Hence, programmers can easily form local environments, adding and modifying appropriate functions, to maximize reuse of other existing functions and types.
    378377
    379 Under construction is a mechanism to distribute @forall@ over routines/types, where each block declaration is prefixed with the initial @forall@ clause significantly reducing duplication (see @stack@ examples in Section~\ref{sec:eval}):
    380 \begin{cfa}
    381 forall( otype `T` ) {                                                   $\C{// forall block}$
     378To reducing duplication, it is possible to distribute a group of @forall@ (and storage-class qualifiers) over functions/types, so each block declaration is prefixed by the group (see example in Appendix~\ref{s:CforallStack}).
     379\begin{cfa}
     380forall( otype `T` ) {                                                   $\C{// distribution block, add forall qualifier to declarations}$
    382381        struct stack { stack_node(`T`) * head; };       $\C{// generic type}$
    383         void push( stack(`T`) & s, `T` value ) ...      $\C{// generic operations}$
    384         T pop( stack(`T`) & s ) ...
     382        inline {                                                                        $\C{// nested distribution block, add forall/inline to declarations}$
     383                void push( stack(`T`) & s, `T` value ) ...      $\C{// generic operations}$
     384                T pop( stack(`T`) & s ) ...
     385        }
    385386}
    386387\end{cfa}
     
    390391
    391392\CFA provides \newterm{traits} to name a group of type assertions, where the trait name allows specifying the same set of assertions in multiple locations, preventing repetition mistakes at each function declaration:
    392 \begin{cfa}
    393 trait `summable`( otype T ) {
    394         void ?{}( T *, zero_t );                                $\C{// constructor from 0 literal}$
    395         T ?+?( T, T );                                                  $\C{// assortment of additions}$
    396         T ?+=?( T *, T );
    397         T ++?( T * );
    398         T ?++( T * );
     393\begin{cquote}
     394\lstDeleteShortInline@%
     395\begin{tabular}{@{}l@{\hspace{\parindentlnth}}|@{\hspace{\parindentlnth}}l@{}}
     396\begin{cfa}
     397trait `sumable`( otype T ) {
     398        void `?{}`( T &, zero_t ); // 0 literal constructor
     399        T ?+?( T, T );                   // assortment of additions
     400        T `?+=?`( T &, T );
     401        T ++?( T & );
     402        T ?++( T & );
    399403};
    400 forall( otype T `| summable( T )` ) T sum( T a[$\,$], size_t size ) {$\C{// use trait}$
    401         `T` total = { `0` };                                    $\C{// instantiate T from 0 by calling its constructor}$
    402         for ( unsigned int i = 0; i < size; i += 1 ) total `+=` a[i]; $\C{// select appropriate +}$
     404\end{cfa}
     405&
     406\begin{cfa}
     407forall( otype T `| sumable( T )` ) // use trait
     408T sum( T a[$\,$], size_t size ) {
     409        `T` total = { `0` };  // initialize by 0 constructor
     410        for ( size_t i = 0; i < size; i += 1 )
     411                total `+=` a[i]; // select appropriate +
    403412        return total;
    404413}
    405414\end{cfa}
     415\end{tabular}
     416\lstMakeShortInline@%
     417\end{cquote}
    406418
    407419In fact, the set of @summable@ trait operators is incomplete, as it is missing assignment for type @T@, but @otype@ is syntactic sugar for the following implicit trait:
     
    466478
    467479A generic type can be declared by placing a @forall@ specifier on a @struct@ or @union@ declaration, and instantiated using a parenthesized list of types after the type name:
     480\begin{cquote}
     481\lstDeleteShortInline@%
     482\begin{tabular}{@{}l@{\hspace{2\parindentlnth}}l@{}}
    468483\begin{cfa}
    469484forall( otype R, otype S ) struct pair {
    470         R first;
    471         S second;
     485        R first;        S second;
    472486};
    473 forall( otype T ) T value( pair( const char *, T ) p ) { return p.second; } $\C{// dynamic}$
    474 forall( dtype F, otype T ) T value( pair( F *, T * ) p ) { return *p.second; } $\C{// dtype-static (concrete)}$
    475 
    476 pair( const char *, int ) p = { "magic", 42 }; $\C{// concrete}$
     487`forall( otype T )` // dynamic
     488T value( pair(const char *, T) p ) { return p.second; }
     489`forall( dtype F, otype T )` // dtype-static (concrete)
     490T value( pair(F *, T * ) p) { return *p.second; }
     491\end{cfa}
     492&
     493\begin{cfa}
     494pair(const char *, int) p = {"magic", 42}; // concrete
    477495int i = value( p );
    478 pair( void *, int * ) q = { 0, &p.second }; $\C{// concrete}$
     496pair(void *, int *) q = { 0, &p.second }; // concrete
    479497i = value( q );
    480498double d = 1.0;
    481 pair( double *, double * ) r = { &d, &d }; $\C{// concrete}$
     499pair(double *, double *) r = { &d, &d }; // concrete
    482500d = value( r );
    483501\end{cfa}
     502\end{tabular}
     503\lstMakeShortInline@%
     504\end{cquote}
    484505
    485506\CFA classifies generic types as either \newterm{concrete} or \newterm{dynamic}.
     
    568589Another useful pattern enabled by reused dtype-static type instantiations is zero-cost \newterm{tag-structures}.
    569590Sometimes information is only used for type-checking and can be omitted at runtime, \eg:
     591\begin{cquote}
     592\lstDeleteShortInline@%
     593\begin{tabular}{@{}l@{\hspace{2\parindentlnth}}l@{}}
    570594\begin{cfa}
    571595forall( dtype Unit ) struct scalar { unsigned long value; };
    572596struct metres {};
    573597struct litres {};
    574 
    575598forall( dtype U ) scalar(U) ?+?( scalar(U) a, scalar(U) b ) {
    576599        return (scalar(U)){ a.value + b.value };
    577600}
    578 scalar(metres) half_marathon = { 21_093 };
    579 scalar(litres) swimming_pool = { 2_500_000 };
    580 scalar(metres) marathon = half_marathon + half_marathon;
    581 scalar(litres) two_pools = swimming_pool + swimming_pool;
    582 marathon + swimming_pool;                                       $\C{// compilation ERROR}$
    583 \end{cfa}
     601\end{cfa}
     602&
     603\begin{cfa}
     604scalar(metres) half_marathon = { 21_098 };
     605scalar(litres) pool = { 2_500_000 };
     606scalar(metres) marathon = half_marathon +
     607                                                        half_marathon;
     608scalar(litres) two_pools = pool + pool;
     609`marathon + pool;`      // compilation ERROR
     610\end{cfa}
     611\end{tabular}
     612\lstMakeShortInline@%
     613\end{cquote}
    584614@scalar@ is a dtype-static type, so all uses have a single structure definition, containing @unsigned long@, and can share the same implementations of common functions like @?+?@.
    585615These implementations may even be separately compiled, unlike \CC template functions.
     
    11891219                `LIF:` if ( ... ) {
    11901220                        `LF:` for ( ... ) {
    1191                                 `LW:` while ( ... ) {
    1192                                         ... break `LC`; ...
    1193                                         ... break `LS`; ...
    1194                                         ... break `LIF`; ...
    1195                                         ... continue `LF;` ...
    1196                                         ... break `LF`; ...
    1197                                         ... continue `LW`; ...
    1198                                         ... break `LW`; ...
    1199                                 } // while
     1221                                ... break `LC`; ...
     1222                                ... break `LS`; ...
     1223                                ... break `LIF`; ...
     1224                                ... continue `LF;` ...
     1225                                ... break `LF`; ...
    12001226                        } // for
    12011227                } else {
     
    12131239                if ( ... ) {
    12141240                        for ( ... ) {
    1215                                 while ( ... ) {
    1216                                         ... goto `LC`; ...
    1217                                         ... goto `LS`; ...
    1218                                         ... goto `LIF`; ...
    1219                                         ... goto `LFC`; ...
    1220                                         ... goto `LFB`; ...
    1221                                         ... goto `LWC`; ...
    1222                                         ... goto `LWB`; ...
    1223                                   `LWC`: ; } `LWB:` ;
     1241                                ... goto `LC`; ...
     1242                                ... goto `LS`; ...
     1243                                ... goto `LIF`; ...
     1244                                ... goto `LFC`; ...
     1245                                ... goto `LFB`; ...
    12241246                          `LFC:` ; } `LFB:` ;
    12251247                } else {
     
    12431265// continue loop
    12441266// terminate loop
    1245 // continue loop
    1246 // terminate loop
    12471267
    12481268
    12491269
    12501270// terminate if
    1251 
    1252 
    12531271
    12541272\end{cfa}
     
    14111429\label{s:WithStatement}
    14121430
    1413 Grouping heterogeneous data into \newterm{aggregate}s (structure/union) is a common programming practice, and an aggregate can be further organized into more complex structures, such as arrays and containers:
    1414 \begin{cfa}
    1415 struct S {                                                                      $\C{// aggregate}$
    1416         char c;                                                                 $\C{// fields}$
    1417         int i;
    1418         double d;
    1419 };
    1420 S s, as[10];
    1421 \end{cfa}
    1422 However, functions manipulating aggregates must repeat the aggregate name to access its containing fields:
    1423 \begin{cfa}
    1424 void f( S s ) {
    1425         `s.`c; `s.`i; `s.`d;                                    $\C{// access containing fields}$
    1426 }
    1427 \end{cfa}
    1428 which extends to multiple levels of qualification for nested aggregates.
    1429 A similar situation occurs in object-oriented programming, \eg \CC:
    1430 \begin{C++}
    1431 struct S {
    1432         char c;                                                                 $\C{// fields}$
    1433         int i;
    1434         double d;
    1435         void f() {                                                              $\C{// implicit ``this'' aggregate}$
    1436                 `this->`c; `this->`i; `this->`d;        $\C{// access containing fields}$
    1437         }
    1438 }
    1439 \end{C++}
    1440 Object-oriented nesting of member functions in a \lstinline[language=C++]@class/struct@ allows eliding \lstinline[language=C++]@this->@ because of lexical scoping.
    1441 However, for other aggregate parameters, qualification is necessary:
    1442 \begin{cfa}
     1431Heterogeneous data is often aggregated into a structure/union.
     1432To reduce syntactic noise, \CFA provides a @with@ statement (see Pascal~\cite[\S~4.F]{Pascal}) to elide aggregate field-qualification by opening a scope containing the field identifiers.
     1433\begin{cquote}
     1434\vspace*{-\baselineskip}%???
     1435\lstDeleteShortInline@%
     1436\begin{cfa}
     1437struct S { char c; int i; double d; };
    14431438struct T { double m, n; };
    1444 int S::f( T & t ) {                                                     $\C{// multiple aggregate parameters}$
    1445         c; i; d;                                                                $\C{\color{red}// this--{\textgreater}.c, this--{\textgreater}.i, this--{\textgreater}.d}$
    1446         `t.`m; `t.`n;                                                   $\C{// must qualify}$
    1447 }
    1448 \end{cfa}
    1449 
    1450 To simplify the programmer experience, \CFA provides a @with@ statement (see Pascal~\cite[\S~4.F]{Pascal}) to elide aggregate qualification to fields by opening a scope containing the field identifiers.
    1451 Hence, the qualified fields become variables with the side-effect that it is easier to optimizing field references in a block.
    1452 \begin{cfa}
    1453 void f( S & this ) `with ( this )` {            $\C{// with statement}$
    1454         c; i; d;                                                                $\C{\color{red}// this.c, this.i, this.d}$
    1455 }
    1456 \end{cfa}
    1457 with the generality of opening multiple aggregate-parameters:
    1458 \begin{cfa}
    1459 void f( S & s, T & t ) `with ( s, t )` {                $\C{// multiple aggregate parameters}$
    1460         c; i; d;                                                                $\C{\color{red}// s.c, s.i, s.d}$
    1461         m; n;                                                                   $\C{\color{red}// t.m, t.n}$
    1462 }
    1463 \end{cfa}
     1439// multiple aggregate parameters
     1440\end{cfa}
     1441\begin{tabular}{@{}l@{\hspace{\parindentlnth}}|@{\hspace{\parindentlnth}}l@{}}
     1442\begin{cfa}
     1443void f( S & s, T & t ) {
     1444        `s.`c; `s.`i; `s.`d;
     1445        `t.`m; `t.`n;
     1446}
     1447\end{cfa}
     1448&
     1449\begin{cfa}
     1450void f( S & s, T & t ) `with ( s, t )` {
     1451        c; i; d;                // no qualification
     1452        m; n;
     1453}
     1454\end{cfa}
     1455\end{tabular}
     1456\lstMakeShortInline@%
     1457\end{cquote}
     1458Object-oriented programming languages only provide implicit qualification for the receiver.
    14641459
    14651460In detail, the @with@ statement has the form:
     
    14741469The object is the implicit qualifier for the open structure-fields.
    14751470
    1476 All expressions in the expression list are open in parallel within the compound statement.
    1477 This semantic is different from Pascal, which nests the openings from left to right.
     1471All expressions in the expression list are open in parallel within the compound statement, which is different from Pascal, which nests the openings from left to right.
    14781472The difference between parallel and nesting occurs for fields with the same name and type:
    14791473\begin{cfa}
     
    22612255\begin{cfa}
    22622256MIN
     2257
    22632258MAX
     2259
    22642260PI
    22652261E
     
    22672263&
    22682264\begin{cfa}
    2269 SCHAR_MIN, CHAR_MIN, SHRT_MIN, INT_MIN, LONG_MIN, LLONG_MIN, FLT_MIN, DBL_MIN, LDBL_MIN
    2270 SCHAR_MAX, UCHAR_MAX, SHRT_MAX, INT_MAX, LONG_MAX, LLONG_MAX, FLT_MAX, DBL_MAX, LDBL_MAX
     2265SCHAR_MIN, CHAR_MIN, SHRT_MIN, INT_MIN, LONG_MIN,
     2266        LLONG_MIN, FLT_MIN, DBL_MIN, LDBL_MIN
     2267SCHAR_MAX, UCHAR_MAX, SHRT_MAX, INT_MAX, LONG_MAX,
     2268        LLONG_MAX, FLT_MAX, DBL_MAX, LDBL_MAX
    22712269M_PI, M_PIl
    22722270M_E, M_El
     
    24412439ip = (int *)malloc( sizeof( int ) ); memset( ip, fill, dim * sizeof( int ) );
    24422440ip = (int *)realloc( ip, 2 * dim * sizeof( int ) );
    2443 ip = (int *)realloc( ip, 4 * dim * sizeof( int ) ); memset( ip, fill, 4 * dim * sizeof( int ) );
    2444 
     2441ip = (int *)realloc( ip, 4 * dim * sizeof( int ) );
     2442                        memset( ip, fill, 4 * dim * sizeof( int ) );
    24452443ip = memalign( 16, sizeof( int ) );
    24462444ip = memalign( 16, sizeof( int ) ); memset( ip, fill, sizeof( int ) );
     
    26072605Though \CFA provides significant added functionality over C, these features have a low runtime penalty.
    26082606In fact, \CFA's features for generic programming can enable faster runtime execution than idiomatic @void *@-based C code.
    2609 This claim is demonstrated through a set of generic-code-based micro-benchmarks in C, \CFA, and \CC (see stack implementations in Appendix~\ref{sec:BenchmarkStackImplementation}).
     2607This claim is demonstrated through a set of generic-code-based micro-benchmarks in C, \CFA, and \CC (see stack implementations in Appendix~\ref{sec:BenchmarkStackImplementations}).
    26102608Since all these languages share a subset essentially comprising standard C, maximal-performance benchmarks should show little runtime variance, differing only in length and clarity of source code.
    26112609A more illustrative comparison measures the costs of idiomatic usage of each language's features.
     
    28242822\appendix
    28252823
    2826 \section{Benchmark Stack Implementation}
    2827 \label{sec:BenchmarkStackImplementation}
    2828 
    2829 Throughout, @/***/@ designates a counted redundant type annotation; code reformatted for brevity.
    2830 
    2831 \smallskip\noindent
    2832 C
    2833 \begin{cfa}[xleftmargin=2\parindentlnth,aboveskip=0pt,belowskip=0pt]
    2834 struct stack_node {
     2824\section{Benchmark Stack Implementations}
     2825\label{sec:BenchmarkStackImplementations}
     2826
     2827Throughout, @/***/@ designates a counted redundant type annotation; code reformatted slightly for brevity.
     2828
     2829
     2830\subsection{C}
     2831
     2832\begin{flushleft}
     2833\lstDeleteShortInline@%
     2834\begin{tabular}{@{}l@{\hspace{1.8\parindentlnth}}|@{\hspace{\parindentlnth}}l@{}}
     2835\begin{cfa}[xleftmargin=0pt,aboveskip=0pt,belowskip=0pt]
     2836typedef struct node {
    28352837        void * value;
    2836         struct stack_node * next;
    2837 };
    2838 struct stack { struct stack_node* head; };
    2839 void clear_stack( struct stack * s, void (*free_el)( void * ) ) {
    2840         for ( struct stack_node * next = s->head; next; ) {
    2841                 struct stack_node * crnt = next;
    2842                 next = crnt->next;
    2843                 free_el( crnt->value );
    2844                 free( crnt );
     2838        struct node * next;
     2839} node;
     2840typedef struct stack {
     2841        struct node * head;
     2842} stack;
     2843void copy_stack( stack * s, const stack * t,
     2844                                void * (*copy)( const void * ) ) {
     2845        node ** cr = &s->head;
     2846        for (node * nx = t->head; nx; nx = nx->next) {
     2847                *cr = malloc( sizeof(node) ); /***/
     2848                (*cr)->value = copy( nx->value );
     2849                cr = &(*cr)->next;
     2850        }
     2851        *cr = NULL;
     2852}
     2853void clear_stack( stack * s, void (* free_el)( void * ) ) {
     2854        for ( node * nx = s->head; nx; ) {
     2855                node * cr = nx;
     2856                nx = cr->next;
     2857                free_el( cr->value );
     2858                free( cr );
    28452859        }
    28462860        s->head = NULL;
    28472861}
    2848 struct stack new_stack() { return (struct stack){ NULL }; /***/ }
    2849 void copy_stack( struct stack * s, const struct stack * t, void * (*copy)( const void * ) ) {
    2850         struct stack_node ** crnt = &s->head;
    2851         for ( struct stack_node * next = t->head; next; next = next->next ) {
    2852                 *crnt = malloc( sizeof(struct stack_node) ); /***/
    2853                 (*crnt)->value = copy( next->value );
    2854                 crnt = &(*crnt)->next;
    2855         }
    2856         *crnt = NULL;
    2857 }
    2858 struct stack * assign_stack( struct stack * s, const struct stack * t,
    2859                 void * (*copy_el)( const void * ), void (*free_el)( void * ) ) {
     2862\end{cfa}
     2863&
     2864\begin{cfa}[xleftmargin=0pt,aboveskip=0pt,belowskip=0pt]
     2865stack new_stack() {
     2866        return (stack){ NULL }; /***/
     2867}
     2868stack * assign_stack( stack * s, const stack * t,
     2869                                void * (*copy_el)( const void * ),
     2870                                void (*free_el)( void * ) ) {
    28602871        if ( s->head == t->head ) return s;
    28612872        clear_stack( s, free_el ); /***/
     
    28632874        return s;
    28642875}
    2865 _Bool stack_empty( const struct stack * s ) { return s->head == NULL; }
    2866 void push_stack( struct stack * s, void * v ) {
    2867         struct stack_node * n = malloc( sizeof(struct stack_node) ); /***/
    2868         *n = (struct stack_node){ v, s->head }; /***/
     2876_Bool stack_empty( const stack * s ) {
     2877         return s->head == NULL;
     2878}
     2879void push_stack( stack * s, void * v ) {
     2880        node * n = malloc(sizeof(node)); /***/
     2881        *n = (node){ v, s->head }; /***/
    28692882        s->head = n;
    28702883}
    2871 void * pop_stack( struct stack * s ) {
    2872         struct stack_node * n = s->head;
     2884void * pop_stack( stack * s ) {
     2885        node * n = s->head;
    28732886        s->head = n->next;
    28742887        void * v = n->value;
     
    28772890}
    28782891\end{cfa}
    2879 
    2880 \medskip\noindent
    2881 \CFA
    2882 \begin{cfa}[xleftmargin=2\parindentlnth,aboveskip=0pt,belowskip=0pt]
    2883 forall( otype T ) struct stack_node {
    2884         T value;
    2885         stack_node(T) * next;
    2886 };
    2887 forall( otype T ) struct stack { stack_node(T) * head; };
    2888 forall( otype T ) void clear( stack(T) & s ) with( s ) {
    2889         for ( stack_node(T) * next = head; next; ) {
    2890                 stack_node(T) * crnt = next;
    2891                 next = crnt->next;
    2892                 ^(*crnt){};
    2893                 free(crnt);
     2892\end{tabular}
     2893\lstMakeShortInline@%
     2894\end{flushleft}
     2895
     2896
     2897\subsection{\CFA}
     2898\label{s:CforallStack}
     2899
     2900\begin{flushleft}
     2901\lstDeleteShortInline@%
     2902\begin{tabular}{@{}l|@{\hspace{\parindentlnth}}l@{}}
     2903\begin{cfa}[xleftmargin=0pt,aboveskip=0pt,belowskip=0pt]
     2904forall( otype T ) {
     2905        struct node {
     2906                T value;
     2907                node(T) * next;
     2908        };
     2909        struct stack { node(T) * head; };
     2910        void ?{}( stack(T) & s ) { (s.head){ 0 }; }
     2911        void ?{}( stack(T) & s, stack(T) t ) {
     2912                node(T) ** cr = &s.head;
     2913                for ( node(T) * nx = t.head; nx; nx = nx->next ) {
     2914                        *cr = alloc();
     2915                        ((*cr)->value){ nx->value };
     2916                        cr = &(*cr)->next;
     2917                }
     2918                *cr = 0;
    28942919        }
    2895         head = 0;
    2896 }
    2897 forall( otype T ) void ?{}( stack(T) & s ) { (s.head){ 0 }; }
    2898 forall( otype T ) void ?{}( stack(T) & s, stack(T) t ) {
    2899         stack_node(T) ** crnt = &s.head;
    2900         for ( stack_node(T) * next = t.head; next; next = next->next ) {
    2901                 *crnt = alloc();
    2902                 ((*crnt)->value){ next->value };
    2903                 crnt = &(*crnt)->next;
    2904         }
    2905         *crnt = 0;
    2906 }
    2907 forall( otype T ) stack(T) ?=?( stack(T) & s, stack(T) t ) {
    2908         if ( s.head == t.head ) return s;
    2909         clear( s );
    2910         s{ t };
    2911         return s;
    2912 }
    2913 forall( otype T ) void ^?{}( stack(T) & s) { clear( s ); }
    2914 forall( otype T ) _Bool empty( const stack(T) & s ) { return s.head == 0; }
    2915 forall( otype T ) void push( stack(T) & s, T value ) with( s ) {
    2916         stack_node(T) * n = alloc();
    2917         (*n){ value, head };
    2918         head = n;
    2919 }
    2920 forall( otype T ) T pop( stack(T) & s ) with( s ) {
    2921         stack_node(T) * n = head;
    2922         head = n->next;
    2923         T v = n->value;
    2924         ^(*n){};
    2925         free( n );
    2926         return v;
    2927 }
    2928 \end{cfa}
    2929 
    2930 \begin{comment}
    2931 forall( otype T ) {
    2932         struct stack_node {
    2933                 T value;
    2934                 stack_node(T) * next;
    2935         };
    2936         struct stack { stack_node(T) * head; };
    29372920        void clear( stack(T) & s ) with( s ) {
    2938                 for ( stack_node(T) * next = head; next; ) {
    2939                         stack_node(T) * crnt = next;
    2940                         next = crnt->next;
    2941                         ^(*crnt){};
    2942                         free(crnt);
     2921                for ( node(T) * nx = head; nx; ) {
     2922                        node(T) * cr = nx;
     2923                        nx = cr->next;
     2924                        ^(*cr){};
     2925                        free(cr);
    29432926                }
    29442927                head = 0;
    29452928        }
    2946         void ?{}( stack(T) & s ) { (s.head){ 0 }; }
    2947         void ?{}( stack(T) & s, stack(T) t ) {
    2948                 stack_node(T) ** crnt = &s.head;
    2949                 for ( stack_node(T) * next = t.head; next; next = next->next ) {
    2950                         *crnt = alloc();
    2951                         ((*crnt)->value){ next->value };
    2952                         crnt = &(*crnt)->next;
    2953                 }
    2954                 *crnt = 0;
    2955         }
     2929\end{cfa}
     2930&
     2931\begin{cfa}[xleftmargin=0pt,aboveskip=0pt,belowskip=0pt]
     2932        void ^?{}( stack(T) & s) { clear( s ); }
    29562933        stack(T) ?=?( stack(T) & s, stack(T) t ) {
    29572934                if ( s.head == t.head ) return s;
     
    29602937                return s;
    29612938        }
    2962         void ^?{}( stack(T) & s) { clear( s ); }
    2963         _Bool empty( const stack(T) & s ) { return s.head == 0; }
     2939        _Bool empty( const stack(T) & s ) {
     2940                return s.head == 0;
     2941        }
    29642942        void push( stack(T) & s, T value ) with( s ) {
    2965                 stack_node(T) * n = alloc();
     2943                node(T) * n = alloc();
    29662944                (*n){ value, head };
    29672945                head = n;
    29682946        }
    29692947        T pop( stack(T) & s ) with( s ) {
    2970                 stack_node(T) * n = head;
     2948                node(T) * n = head;
    29712949                head = n->next;
    29722950                T v = n->value;
     
    29762954        }
    29772955}
    2978 \end{comment}
    2979 
    2980 \medskip\noindent
    2981 \CC
    2982 \begin{cfa}[xleftmargin=2\parindentlnth,aboveskip=0pt,belowskip=0pt]
     2956
     2957\end{cfa}
     2958\end{tabular}
     2959\lstMakeShortInline@%
     2960\end{flushleft}
     2961
     2962
     2963\subsection{\CC}
     2964
     2965\begin{flushleft}
     2966\lstDeleteShortInline@%
     2967\begin{tabular}{@{}l|@{\hspace{\parindentlnth}}l@{}}
     2968\begin{cfa}[xleftmargin=0pt,aboveskip=0pt,belowskip=0pt]
    29832969template<typename T> struct stack {
    29842970        struct node {
    29852971                T value;
    29862972                node * next;
    2987                 node( const T & v, node * n = nullptr ) : value( v ), next( n ) {}
     2973                node( const T & v, node * n = nullptr ) :
     2974                        value( v ), next( n ) {}
    29882975        };
    29892976        node * head;
    2990         stack() : head( nullptr ) {}
    2991         stack( const stack<T> & o ) { copy( o ); }
     2977        void copy( const stack<T> & o ) {
     2978                node ** cr = &head;
     2979                for ( node * nx = o.head; nx; nx = nx->next ) {
     2980                        *cr = new node{ nx->value }; /***/
     2981                        cr = &(*cr)->next;
     2982                }
     2983                *cr = nullptr;
     2984        }
    29922985        void clear() {
    2993                 for ( node * next = head; next; ) {
    2994                         node * crnt = next;
    2995                         next = crnt->next;
    2996                         delete crnt;
     2986                for ( node * nx = head; nx; ) {
     2987                        node * cr = nx;
     2988                        nx = cr->next;
     2989                        delete cr;
    29972990                }
    29982991                head = nullptr;
    29992992        }
    3000         void copy( const stack<T> & o ) {
    3001                 node ** crnt = &head;
    3002                 for ( node * next = o.head; next; next = next->next ) {
    3003                         *crnt = new node{ next->value }; /***/
    3004                         crnt = &(*crnt)->next;
    3005                 }
    3006                 *crnt = nullptr;
    3007         }
     2993\end{cfa}
     2994&
     2995\begin{cfa}[xleftmargin=0pt,aboveskip=0pt,belowskip=0pt]
     2996        stack() : head( nullptr ) {}
     2997        stack( const stack<T> & o ) { copy( o ); }
    30082998        ~stack() { clear(); }
    3009         stack & operator= ( const stack<T> & o ) {
     2999        stack & operator=( const stack<T> & o ) {
    30103000                if ( this == &o ) return *this;
    30113001                clear();
     
    30143004        }
    30153005        bool empty() const { return head == nullptr; }
    3016         void push( const T & value ) { head = new node{ value, head };  /***/ }
     3006        void push( const T & value ) {
     3007                head = new node{ value, head };  /***/
     3008        }
    30173009        T pop() {
    30183010                node * n = head;
     
    30233015        }
    30243016};
    3025 \end{cfa}
    3026 
    3027 \medskip\noindent
    3028 \CCV
    3029 \begin{cfa}[xleftmargin=2\parindentlnth,aboveskip=0pt,belowskip=0pt]
     3017
     3018
     3019
     3020\end{cfa}
     3021\end{tabular}
     3022\lstMakeShortInline@%
     3023\end{flushleft}
     3024
     3025
     3026\subsection{\CCV}
     3027
     3028\begin{flushleft}
     3029\lstDeleteShortInline@%
     3030\begin{tabular}{@{}l|@{\hspace{\parindentlnth}}l@{}}
     3031\begin{cfa}[xleftmargin=0pt,aboveskip=0pt,belowskip=0pt]
    30303032struct stack {
    30313033        struct node {
    30323034                ptr<object> value;
    30333035                node * next;
    3034                 node( const object & v, node * n = nullptr ) : value( v.new_copy() ), next( n ) {}
     3036                node( const object & v, node * n = nullptr ) :
     3037                                value( v.new_copy() ), next( n ) {}
    30353038        };
    30363039        node * head;
     3040        void copy( const stack & o ) {
     3041                node ** cr = &head;
     3042                for ( node * nx = o.head; nx; nx = nx->next ) {
     3043                        *cr = new node{ *nx->value }; /***/
     3044                        cr = &(*cr)->next;
     3045                }
     3046                *cr = nullptr;
     3047        }
    30373048        void clear() {
    3038                 for ( node * next = head; next; ) {
    3039                         node * crnt = next;
    3040                         next = crnt->next;
    3041                         delete crnt;
     3049                for ( node * nx = head; nx; ) {
     3050                        node * cr = nx;
     3051                        nx = cr->next;
     3052                        delete cr;
    30423053                }
    30433054                head = nullptr;
    30443055        }
    3045         void copy( const stack & o ) {
    3046                 node ** crnt = &head;
    3047                 for ( node * next = o.head; next; next = next->next ) {
    3048                         *crnt = new node{ *next->value }; /***/
    3049                         crnt = &(*crnt)->next;
    3050                 }
    3051                 *crnt = nullptr;
    3052         }
     3056\end{cfa}
     3057&
     3058\begin{cfa}[xleftmargin=0pt,aboveskip=0pt,belowskip=0pt]
    30533059        stack() : head( nullptr ) {}
    30543060        stack( const stack & o ) { copy( o ); }
    30553061        ~stack() { clear(); }
    3056         stack & operator= ( const stack & o ) {
     3062        stack & operator=( const stack & o ) {
    30573063                if ( this == &o ) return *this;
    30583064                clear();
     
    30613067        }
    30623068        bool empty() const { return head == nullptr; }
    3063         void push( const object & value ) { head = new node{ value, head }; /***/ }
     3069        void push( const object & value ) {
     3070                head = new node{ value, head }; /***/
     3071        }
    30643072        ptr<object> pop() {
    30653073                node * n = head;
     
    30703078        }
    30713079};
    3072 \end{cfa}
     3080
     3081
     3082
     3083\end{cfa}
     3084\end{tabular}
     3085\lstMakeShortInline@%
     3086\end{flushleft}
    30733087
    30743088
  • doc/papers/general/evaluation/c-bench.c

    ra0c7d5cc r534d84e  
    55#include "c-stack.h"
    66
    7 char* new_char( char c ) {
    8         char* q = malloc(sizeof(char)); /***/
     7char * new_char( char c ) {
     8        char* q = malloc( sizeof(char) ); /***/
    99        *q = c;
    1010        return q;
    1111}
    1212
    13 short* new_short( short s ) {
    14         short* q = malloc(sizeof(short)); /***/
     13short * new_short( short s ) {
     14        short* q = malloc( sizeof(short) ); /***/
    1515        *q = s;
    1616        return q;
     
    1818
    1919int* new_int( int i ) {
    20         int* q = malloc(sizeof(int)); /***/
     20        int* q = malloc( sizeof(int) ); /***/
    2121        *q = i;
    2222        return q;
    2323}
    2424
    25 void* copy_char( const void* p ) { return new_char( *(const char*)p ); } /***/
    26 void* copy_short( const void* p ) { return new_short( *(const short*)p ); } /***/
    27 void* copy_int( const void* p ) { return new_int( *(const int*)p ); } /***/
    28 void* copy_pair_short_char( const void* p ) { return copy_pair( p, copy_short, copy_char ); } /***/
    29 void free_pair_short_char( void* p ) { free_pair( p, free, free ); } /***/
     25void * copy_char( const void * p ) { return new_char( *(const char*)p ); } /***/
     26void * copy_short( const void * p ) { return new_short( *(const short*)p ); } /***/
     27void * copy_int( const void * p ) { return new_int( *(const int*)p ); } /***/
     28void * copy_pair_short_char( const void * p ) { return copy_pair( p, copy_short, copy_char ); } /***/
     29void free_pair_short_char( void * p ) { free_pair( p, free, free ); } /***/
    3030
    3131int cmp_char( const void* a, const void* b ) { /***/
     
    3737}
    3838
    39 int main(int argc, char** argv) {
     39int main(int argc, char * argv[] ) {
    4040        int maxi = 0, vali = 42;
    4141        struct stack si = new_stack(), ti;
  • doc/papers/general/evaluation/c-pair.c

    ra0c7d5cc r534d84e  
    22#include "c-pair.h"
    33
    4 struct pair* new_pair(void* first, void* second) {
    5         struct pair* p = malloc(sizeof(struct pair)); /***/
    6         *p = (struct pair){ first, second }; /***/
     4pair * new_pair( void * first, void * second ) {
     5        pair * p = malloc( sizeof(pair) ); /***/
     6        *p = (pair){ first, second }; /***/
    77        return p;
    88}
    99
    10 struct pair* copy_pair(const struct pair* src,
    11                 void* (*copy_first)(const void*), void* (*copy_second)(const void*)) {
     10pair * copy_pair( const pair * src,
     11                void * (* copy_first)(const void* ), void * (* copy_second)(const void *)) {
    1212        return new_pair( copy_first(src->first), copy_second(src->second) );
    1313}
    1414
    15 void free_pair(struct pair* p, void (*free_first)(void*), void (*free_second)(void*)) {
    16         free_first(p->first);
    17         free_second(p->second);
    18         free(p);
     15void free_pair( pair * p, void (* free_first)(void *), void (* free_second)(void *)) {
     16        free_first( p->first );
     17        free_second( p->second );
     18        free( p );
    1919}
    2020
    21 int cmp_pair(const struct pair* a, const struct pair* b,
    22                 int (*cmp_first)(const void*, const void*), int (*cmp_second)(const void*, const void*)) {
    23         int c = cmp_first(a->first, b->first);
    24         if ( c == 0 ) c = cmp_second(a->second, b->second);
     21int cmp_pair( const pair * a, const pair * b,
     22                int (* cmp_first)(const void *, const void *), int (* cmp_second)(const void *, const void *)) {
     23        int c = cmp_first( a->first, b->first );
     24        if ( c == 0 ) c = cmp_second( a->second, b->second );
    2525        return c;
    2626}
  • doc/papers/general/evaluation/c-pair.h

    ra0c7d5cc r534d84e  
    11#pragma once
    22
    3 struct pair {
    4         void* first;
    5         void* second;
    6 };
     3typedef struct pair {
     4        void * first;
     5        void * second;
     6} pair;
    77
    8 struct pair* new_pair(void* first, void* second);
     8pair * new_pair( void * first, void * second );
    99
    10 struct pair* copy_pair(const struct pair* src,
    11         void* (*copy_first)(const void*), void* (*copy_second)(const void*));
     10pair * copy_pair( const pair * src,
     11        void * (* copy_first)(const void *), void * (* copy_second)(const void *));
    1212
    13 void free_pair(struct pair* p, void (*free_first)(void*), void (*free_second)(void*));
     13void free_pair( pair * p, void (* free_first)(void *), void (* free_second)(void *));
    1414
    15 int cmp_pair(const struct pair* a, const struct pair* b,
    16         int (*cmp_first)(const void*, const void*), int (*cmp_second)(const void*, const void*));
     15int cmp_pair( const pair * a, const pair * b,
     16        int (* cmp_first)(const void *, const void *), int (* cmp_second)(const void *, const void *));
  • doc/papers/general/evaluation/c-print.c

    ra0c7d5cc r534d84e  
    44#include "c-print.h"
    55
    6 void print_string(FILE* out, const char* x) { fprintf(out, "%s", x); }
     6void print_string( FILE * out, const char * x ) { fprintf( out, "%s", x ); }
    77
    8 void print_bool(FILE* out, _Bool x) { fprintf(out, "%s", x ? "true" : "false"); }
     8void print_bool( FILE * out, _Bool x ) { fprintf( out, "%s", x ? "true" : "false" ); }
    99
    10 void print_char(FILE* out, char x) {
    11         if ( 0x20 <= x && x <= 0x7E ) { fprintf(out, "'%c'", x); }
    12         else { fprintf(out, "'\\%x'", x); }
     10void print_char( FILE * out, char x ) {
     11        if ( 0x20 <= x && x <= 0x7E ) { fprintf( out, "'%c'", x ); }
     12        else { fprintf( out, "'\\%x'", x ); }
    1313}
    1414
    15 void print_int(FILE* out, int x) { fprintf(out, "%d", x); }
     15void print_int( FILE * out, int x ) { fprintf( out, "%d", x ); }
    1616
    17 void print_fmt(FILE* out, char fmt, void* p) {
     17void print_fmt( FILE * out, char fmt, void * p ) {
    1818        switch( fmt ) {
    19         case 's': print_string(out, (const char*)p); break; /***/
    20         case 'b': print_bool(out, *(_Bool*)p); break; /***/
    21         case 'c': print_char(out, *(char*)p); break; /***/
    22         case 'd': print_int(out, *(int*)p); break; /***/
     19        case 's': print_string( out, (const char*)p ); break; /***/
     20        case 'b': print_bool( out, *(_Bool*)p ); break; /***/
     21        case 'c': print_char( out, *(char*)p ); break; /***/
     22        case 'd': print_int( out, *(int*)p ); break; /***/
    2323        }
    2424}
    2525
    26 void print(FILE* out, const char* fmt, ...) {
     26void print( FILE * out, const char * fmt, ... ) {
    2727        va_list args;
    2828        va_start(args, fmt);
    29         for (const char* it = fmt; *it; ++it) {
     29        for ( const char * it = fmt; *it; ++it ) {
    3030                switch( *it ) {
    31                 case 's': print_string(out, va_arg(args, const char*)); break; /***/
    32                 case 'b': print_bool(out, va_arg(args, int)); break; /***/
    33                 case 'c': print_char(out, va_arg(args, int)); break; /***/
    34                 case 'd': print_int(out, va_arg(args, int)); break; /***/
     31                case 's': print_string( out, va_arg( args, const char * ) ); break; /***/
     32                case 'b': print_bool( out, va_arg( args, int ) ); break; /***/
     33                case 'c': print_char( out, va_arg( args, int ) ); break; /***/
     34                case 'd': print_int( out, va_arg( args, int ) ); break; /***/
    3535                case 'p': {
    36                         const struct pair x = va_arg(args, const struct pair); /***/
    37                         fprintf(out, "[");
    38                         print_fmt(out, *++it, x.first); /***/
    39                         fprintf(out, ", ");
    40                         print_fmt(out, *++it, x.second); /***/
    41                         fprintf(out, "]");
     36                        const struct pair x = va_arg( args, const struct pair ); /***/
     37                        fprintf( out, "[" );
     38                        print_fmt( out, *++it, x.first ); /***/
     39                        fprintf( out, ", " );
     40                        print_fmt( out, *++it, x.second ); /***/
     41                        fprintf( out, "]" );
    4242                        break;
    4343                }
    4444                }
    4545        }
    46         va_end(args);
     46        va_end( args );
    4747}
  • doc/papers/general/evaluation/c-print.h

    ra0c7d5cc r534d84e  
    22#include <stdio.h>
    33
    4 void print_string(FILE* out, const char* x);
    5 void print_bool(FILE* out, _Bool x);
    6 void print_char(FILE* out, char x);
    7 void print_int(FILE* out, int x);
     4void print_string( FILE * out, const char * x );
     5void print_bool( FILE * out, _Bool x );
     6void print_char( FILE * out, char x );
     7void print_int( FILE * out, int x );
    88
    9 void print(FILE* out, const char* fmt, ...);
     9void print( FILE * out, const char * fmt, ... );
  • doc/papers/general/evaluation/c-stack.c

    ra0c7d5cc r534d84e  
    22#include "c-stack.h"
    33
    4 struct stack_node {
     4typedef struct node {
    55        void * value;
    6         struct stack_node * next;
    7 };
     6        struct node * next;
     7} node;
    88
    9 void clear_stack( struct stack * s, void (*free_el)( void * ) ) {
    10         for ( struct stack_node * next = s->head; next; ) {
    11                 struct stack_node * crnt = next;
    12                 next = crnt->next;
    13                 free_el( crnt->value );
    14                 free( crnt );
     9void copy_stack( stack * s, const stack * t, void * (*copy)( const void * ) ) {
     10        node ** cr = &s->head;
     11        for ( node * nx = t->head; nx; nx = nx->next ) {
     12                *cr = malloc( sizeof(node) ); /***/
     13                (*cr)->value = copy( nx->value );
     14                cr = &(*cr)->next;
     15        }
     16        *cr = NULL;
     17}
     18
     19void clear_stack( stack * s, void (* free_el)( void * ) ) {
     20        for ( node * nx = s->head; nx; ) {
     21                node * cr = nx;
     22                nx = cr->next;
     23                free_el( cr->value );
     24                free( cr );
    1525        }
    1626        s->head = NULL;
    1727}
    1828
    19 struct stack new_stack() { return (struct stack){ NULL }; /***/ }
     29stack new_stack() { return (stack){ NULL }; /***/ }
    2030
    21 void copy_stack( struct stack * s, const struct stack * t, void * (*copy)( const void * ) ) {
    22         struct stack_node ** crnt = &s->head;
    23         for ( struct stack_node * next = t->head; next; next = next->next ) {
    24                 *crnt = malloc( sizeof(struct stack_node) ); /***/
    25                 (*crnt)->value = copy( next->value );
    26                 crnt = &(*crnt)->next;
    27         }
    28         *crnt = NULL;
    29 }
    30 struct stack * assign_stack( struct stack * s, const struct stack * t,
     31stack * assign_stack( stack * s, const stack * t,
    3132                void * (*copy_el)( const void * ), void (*free_el)( void * ) ) {
    3233        if ( s->head == t->head ) return s;
     
    3637}
    3738
    38 _Bool stack_empty( const struct stack * s ) { return s->head == NULL; }
     39_Bool stack_empty( const stack * s ) { return s->head == NULL; }
    3940
    40 void push_stack( struct stack * s, void * v ) {
    41         struct stack_node * n = malloc( sizeof(struct stack_node) ); /***/
    42         *n = (struct stack_node){ v, s->head }; /***/
     41void push_stack( stack * s, void * v ) {
     42        node * n = malloc( sizeof(node) ); /***/
     43        *n = (node){ v, s->head }; /***/
    4344        s->head = n;
    4445}
    4546
    46 void * pop_stack( struct stack * s ) {
    47         struct stack_node * n = s->head;
     47void * pop_stack( stack * s ) {
     48        node * n = s->head;
    4849        s->head = n->next;
    4950        void * v = n->value;
  • doc/papers/general/evaluation/c-stack.h

    ra0c7d5cc r534d84e  
    11#pragma once
    22
    3 struct stack_node;
    4 struct stack {
    5         struct stack_node* head;
    6 };
     3struct node;
     4typedef struct stack {
     5        struct node * head;
     6} stack;
    77
    8 struct stack new_stack();
    9 void copy_stack(struct stack* dst, const struct stack* src, void* (*copy)(const void*));
    10 struct stack* assign_stack(struct stack* dst, const struct stack* src,
    11         void* (*copy_el)(const void*), void (*free_el)(void*));
    12 void clear_stack(struct stack* s, void (*free_el)(void*));
     8stack new_stack();
     9void copy_stack(stack * dst, const stack * src, void * (* copy)(const void *));
     10stack * assign_stack( stack * dst, const stack * src,
     11        void * (* copy_el)(const void *), void (* free_el)(void *));
     12void clear_stack(stack * s, void (*free_el)(void *));
    1313
    14 _Bool stack_empty(const struct stack* s);
    15 void push_stack(struct stack* s, void* value);
    16 void* pop_stack(struct stack* s);
     14_Bool stack_empty( const stack * s );
     15void push_stack( stack * s, void * value );
     16void * pop_stack( stack * s );
  • doc/papers/general/evaluation/cfa-stack.c

    ra0c7d5cc r534d84e  
    22#include "cfa-stack.h"
    33
    4 forall( otype T ) struct stack_node {
    5         T value;
    6         stack_node(T) * next;
    7 };
     4forall( otype T ) {
     5        struct node {
     6                T value;
     7                node(T) * next;
     8        };
    89
    9 forall( otype T ) void clear( stack(T) & s ) with( s ) {
    10         for ( stack_node(T) * next = head; next; ) {
    11                 stack_node(T) * crnt = next;
    12                 next = crnt->next;
    13                 ^(*crnt){};
    14                 free(crnt);
     10        void ?{}( stack(T) & s ) { (s.head){ 0 }; }
     11
     12        void ?{}( stack(T) & s, stack(T) t ) {
     13                node(T) ** cr = &s.head;
     14                for ( node(T) * nx = t.head; nx; nx = nx->next ) {
     15                        *cr = alloc();
     16                        ((*cr)->value){ nx->value };
     17                        cr = &(*cr)->next;
     18                }
     19                *cr = 0;
    1520        }
    16         head = 0;
     21
     22        void ^?{}( stack(T) & s) { clear( s ); }
     23
     24    void clear( stack(T) & s ) with( s ) {
     25                for ( node(T) * nx = head; nx; ) {
     26                        node(T) * cr = nx;
     27                        nx = cr->next;
     28                        ^(*cr){};
     29                        free(cr);
     30                }
     31                head = 0;
     32        }
     33
     34        stack(T) ?=?( stack(T) & s, stack(T) t ) {
     35                if ( s.head == t.head ) return s;
     36                clear( s );
     37                s{ t };
     38                return s;
     39        }
     40
     41        _Bool empty( const stack(T) & s ) { return s.head == 0; }
     42
     43        void push( stack(T) & s, T value ) with( s ) {
     44                node(T) * n = alloc();
     45                (*n){ value, head };
     46                head = n;
     47        }
     48
     49        T pop( stack(T) & s ) with( s ) {
     50                node(T) * n = head;
     51                head = n->next;
     52                T v = n->value;
     53                ^(*n){};
     54                free( n );
     55                return v;
     56        }
    1757}
    18 
    19 forall( otype T ) void ?{}( stack(T) & s ) { (s.head){ 0 }; }
    20 
    21 forall( otype T ) void ?{}( stack(T) & s, stack(T) t ) {
    22         stack_node(T) ** crnt = &s.head;
    23         for ( stack_node(T) * next = t.head; next; next = next->next ) {
    24                 *crnt = alloc();
    25                 ((*crnt)->value){ next->value };
    26                 crnt = &(*crnt)->next;
    27         }
    28         *crnt = 0;
    29 }
    30 
    31 forall( otype T ) stack(T) ?=?( stack(T) & s, stack(T) t ) {
    32         if ( s.head == t.head ) return s;
    33         clear( s );
    34         s{ t };
    35         return s;
    36 }
    37 
    38 forall( otype T ) void ^?{}( stack(T) & s) { clear( s ); }
    39 
    40 forall( otype T ) _Bool empty( const stack(T) & s ) { return s.head == 0; }
    41 
    42 forall( otype T ) void push( stack(T) & s, T value ) with( s ) {
    43         stack_node(T) * n = alloc();
    44         (*n){ value, head };
    45         head = n;
    46 }
    47 
    48 forall( otype T ) T pop( stack(T) & s ) with( s ) {
    49         stack_node(T) * n = head;
    50         head = n->next;
    51         T v = n->value;
    52         ^(*n){};
    53         free( n );
    54         return v;
    55 }
  • doc/papers/general/evaluation/cfa-stack.h

    ra0c7d5cc r534d84e  
    11#pragma once
    22
    3 forall( otype T ) struct stack_node;
    4 forall( otype T ) struct stack {
    5         stack_node(T) * head;
    6 };
     3forall( otype T ) {
     4        struct node;
     5        struct stack {
     6                node(T) * head;
     7        };
    78
    8 forall( otype T ) void ?{}( stack(T) & s );
    9 forall( otype T ) void ?{}( stack(T) & s, stack(T) t );
    10 forall( otype T ) stack(T) ?=?( stack(T) & s, stack(T) t );
    11 forall( otype T ) void ^?{}( stack(T) & s);
     9        void ?{}( stack(T) & s );
     10        void ?{}( stack(T) & s, stack(T) t );
     11        void ^?{}( stack(T) & s);
     12        void clear( stack(T) & s );
    1213
    13 forall( otype T ) _Bool empty( const stack(T) & s );
    14 forall( otype T ) void push( stack(T) & s, T value );
    15 forall( otype T ) T pop( stack(T) & s );
    16 forall( otype T ) void clear( stack(T) & s );
     14        stack(T) ?=?( stack(T) & s, stack(T) t );
     15        _Bool empty( const stack(T) & s );
     16        void push( stack(T) & s, T value );
     17        T pop( stack(T) & s );
     18}
  • doc/papers/general/evaluation/cpp-stack.hpp

    ra0c7d5cc r534d84e  
    1414
    1515        void clear() {
    16                 for ( node * next = head; next; ) {
    17                         node * crnt = next;
    18                         next = crnt->next;
    19                         delete crnt;
     16                for ( node * nx = head; nx; ) {
     17                        node * cr = nx;
     18                        nx = cr->next;
     19                        delete cr;
    2020                }
    2121                head = nullptr;
     
    2323
    2424        void copy( const stack<T> & o ) {
    25                 node ** crnt = &head;
    26                 for ( node * next = o.head; next; next = next->next ) {
    27                         *crnt = new node{ next->value }; /***/
    28                         crnt = &(*crnt)->next;
     25                node ** cr = &head;
     26                for ( node * nx = o.head; nx; nx = nx->next ) {
     27                        *cr = new node{ nx->value }; /***/
     28                        cr = &(*cr)->next;
    2929                }
    30                 *crnt = nullptr;
     30                *cr = nullptr;
    3131        }
    3232
  • doc/papers/general/evaluation/cpp-vstack.cpp

    ra0c7d5cc r534d84e  
    55
    66void stack::clear() {
    7         for ( node * next = head; next; ) {
    8                 node * crnt = next;
    9                 next = crnt->next;
    10                 delete crnt;
     7        for ( node * nx = head; nx; ) {
     8                node * cr = nx;
     9                nx = cr->next;
     10                delete cr;
    1111        }
    1212        head = nullptr;
     
    1414
    1515void stack::copy( const stack & o ) {
    16         node ** crnt = &head;
    17         for ( node * next = o.head; next; next = next->next ) {
    18                 *crnt = new node{ *next->value }; /***/
    19                 crnt = &(*crnt)->next;
     16        node ** cr = &head;
     17        for ( node * nx = o.head; nx; nx = nx->next ) {
     18                *cr = new node{ *nx->value }; /***/
     19                cr = &(*cr)->next;
    2020        }
    21         *crnt = nullptr;
     21        *cr = nullptr;
    2222}
    2323
  • src/Parser/DeclarationNode.cc

    ra0c7d5cc r534d84e  
    1010// Created On       : Sat May 16 12:34:05 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Apr 20 22:37:20 2018
    13 // Update Count     : 1063
     12// Last Modified On : Thu Apr 26 13:45:10 2018
     13// Update Count     : 1064
    1414//
    1515
     
    783783DeclarationNode * DeclarationNode::addPointer( DeclarationNode * p ) {
    784784        if ( p ) {
    785                 assert( p->type->kind == TypeData::Pointer || TypeData::Reference );
     785                assert( p->type->kind == TypeData::Pointer || p->type->kind == TypeData::Reference );
    786786                setBase( p->type );
    787787                p->type = nullptr;
  • src/Parser/TypeData.cc

    ra0c7d5cc r534d84e  
    1010// Created On       : Sat May 16 15:12:51 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Apr 17 23:00:52 2018
    13 // Update Count     : 602
     12// Last Modified On : Thu Apr 26 13:46:07 2018
     13// Update Count     : 603
    1414//
    1515
     
    6262                enumeration.constants = nullptr;
    6363                enumeration.body = false;
     64                break;
    6465          case Aggregate:
    6566                // aggregate = new Aggregate_t;
  • src/Parser/parser.yy

    ra0c7d5cc r534d84e  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Apr 17 17:10:30 2018
    13 // Update Count     : 3144
     12// Last Modified On : Sat Apr 28 09:37:03 2018
     13// Update Count     : 3201
    1414//
    1515
     
    133133} // build_postfix_name
    134134
    135 bool forall = false;                                                                    // aggregate have one or more forall qualifiers ?
     135bool forall = false, xxx = false;                                               // aggregate have one or more forall qualifiers ?
    136136
    137137// https://www.gnu.org/software/bison/manual/bison.html#Location-Type
     
    282282%type<decl> aggregate_type aggregate_type_nobody
    283283
    284 %type<decl> assertion assertion_list_opt
     284%type<decl> assertion assertion_list assertion_list_opt
    285285
    286286%type<en>   bit_subrange_size_opt bit_subrange_size
     
    18661866                {
    18671867                        typedefTable.makeTypedef( *$3 );
     1868                        if ( forall ) typedefTable.changeKind( *$3, TypedefTable::TG ); // possibly update
     1869                        forall = false;                                                         // reset
    18681870                        $$ = DeclarationNode::newAggregate( $1, $3, nullptr, nullptr, false )->addQualifiers( $2 );
    18691871                }
     
    22352237                { $$ = DeclarationNode::newTypeParam( $1, $2 )->addTypeInitializer( $4 )->addAssertions( $5 ); }
    22362238        | type_specifier identifier_parameter_declarator
     2239        | assertion_list
     2240                { $$ = DeclarationNode::newTypeParam( DeclarationNode::Dtype, new string( DeclarationNode::anonymous.newName() ) )->addAssertions( $1 ); }
    22372241        ;
    22382242
     
    22512255        // empty
    22522256                { $$ = nullptr; }
    2253         | assertion_list_opt assertion
     2257        | assertion_list
     2258        ;
     2259
     2260assertion_list:                                                                                 // CFA
     2261        assertion
     2262        | assertion_list assertion
    22542263                { $$ = $1 ? $1->appendList( $2 ) : $2; }
    22552264        ;
     
    23782387external_definition_list:
    23792388        external_definition
    2380         | external_definition_list push external_definition
    2381                 { $$ = $1 ? $1->appendList( $3 ) : $3; }
     2389        | external_definition_list { forall = xxx; } push external_definition
     2390                { $$ = $1 ? $1->appendList( $4 ) : $4; }
    23822391        ;
    23832392
     
    24112420                        $$ = $2;
    24122421                }
    2413         | type_qualifier_list '{' external_definition_list '}'                  // CFA, namespace
     2422        | type_qualifier_list
     2423                {
     2424                        if ( $1->type->forall ) xxx = forall = true; // remember generic type
     2425                }
     2426          push '{' external_definition_list '}'                         // CFA, namespace
     2427                {
     2428                        for ( DeclarationNode * iter = $5; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) {
     2429                                iter->addQualifiers( $1->clone() );
     2430                        } // for
     2431                        xxx = false;
     2432                        delete $1;
     2433                        $$ = $5;
     2434                }
     2435        | declaration_qualifier_list
     2436                {
     2437                        if ( $1->type->forall ) xxx = forall = true; // remember generic type
     2438                }
     2439          push '{' external_definition_list '}'                         // CFA, namespace
     2440                {
     2441                        for ( DeclarationNode * iter = $5; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) {
     2442                                iter->addQualifiers( $1->clone() );
     2443                        } // for
     2444                        xxx = false;
     2445                        delete $1;
     2446                        $$ = $5;
     2447                }
     2448        | declaration_qualifier_list type_qualifier_list
     2449                {
     2450                        if ( $1->type->forall ) xxx = forall = true; // remember generic type
     2451                }
     2452          push '{' external_definition_list '}'                         // CFA, namespace
     2453                {
     2454                        for ( DeclarationNode * iter = $6; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) {
     2455                                iter->addQualifiers( $1->clone() );
     2456                                iter->addQualifiers( $2->clone() );
     2457                        } // for
     2458                        xxx = false;
     2459                        delete $1;
     2460                        delete $2;
     2461                        $$ = $6;
     2462                }
    24142463        ;
    24152464
     
    24372486with_clause_opt:
    24382487        // empty
    2439                 { $$ = nullptr; }
     2488                { $$ = nullptr; forall = false; }
    24402489        | WITH '(' tuple_expression_list ')'
    2441                 { $$ = $3; }
     2490                { $$ = $3; forall = false; }
    24422491        ;
    24432492
  • src/SymTab/Autogen.cc

    ra0c7d5cc r534d84e  
    99// Author           : Rob Schluntz
    1010// Created On       : Thu Mar 03 15:45:56 2016
    11 // Last Modified By : Andrew Beach
    12 // Last Modified On : Fri Jul 14 16:41:00 2017
    13 // Update Count     : 62
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Fri Apr 27 14:39:06 2018
     13// Update Count     : 63
    1414//
    1515
     
    331331                        definitions.push_back( dcl );
    332332                        indexer.addId( dcl );
    333                 } catch ( SemanticErrorException err ) {
     333                } catch ( SemanticErrorException & ) {
    334334                        // okay if decl does not resolve - that means the function should not be generated
    335335                        delete dcl;
Note: See TracChangeset for help on using the changeset viewer.