Changes in / [534d84e:a0c7d5cc]


Ignore:
Files:
18 edited

Legend:

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

    r534d84e ra0c7d5cc  
    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{\rmfamily\fontsize{8bp}{10bp}\selectfont}\else%
     1281  \def\footnotetextfont{\sffamily\fontsize{8bp}{10bp}\selectfont}\else%
    12821282  %%
    1283   \def\footnotetextfont{\rmfamily\fontsize{6bp}{8bp}\selectfont}
     1283  \def\footnotetextfont{\sffamily\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\rmfamily}{\mathrm}
     1296\DeclareOldFontCommand{\rm}{\normalfont\sffamily}{\mathrm}
    12971297\DeclareOldFontCommand{\sf}{\normalfont\sffamily}{\mathsf}
    12981298\DeclareOldFontCommand{\tt}{\normalfont\ttfamily}{\mathtt}
     
    13221322\renewcommand\normalsize{%
    13231323  \if@font@stix%
    1324     \@setfontsize\normalsize{10bp}{13bp}%
     1324    \@setfontsize\normalsize{9bp}{12bp}%
    13251325  \else%
    13261326    \@setfontsize\normalsize{8bp}{13bp}%
     
    14181418%  \def\watermarkfont{\reset@font\fontfamily{\ffdefault}\fontsize{45}{45}\bfseries\selectfont}
    14191419  %
    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}%
     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}%
    14261426  %
    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}%
     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}%
    14431443  %
    1444   \def\boxheadfont{\rmfamily\fontsize{10}{13}\fontseries{b}\selectfont}
    1445   \def\boxtitlefont{\rmfamily\fontsize{10}{13}\bfseries\selectfont}
     1444  \def\boxheadfont{\sffamily\fontsize{10}{13}\fontseries{b}\selectfont}
     1445  \def\boxtitlefont{\sffamily\fontsize{10}{13}\bfseries\selectfont}
    14461446  %
    1447   \def\GnSabsfont{\rmfamily\fontsize{9}{15}\selectfont}%
    1448   \def\GnSabsfootfont{\reset@font\rmfamily\fontsize{14}{0}\bfseries\selectfont}%
     1447  \def\GnSabsfont{\sffamily\fontsize{9}{15}\selectfont}%
     1448  \def\GnSabsfootfont{\reset@font\sffamily\fontsize{14}{0}\bfseries\selectfont}%
    14491449  %
    1450   \def\suppinfofont{\noindent\rmfamily}%
     1450  \def\suppinfofont{\noindent\sffamily}%
    14511451  \def\suppinfoheadfont{\noindent\fontsize{10}{13}\fontseries{b}\selectfont}%
    1452   \def\suppinfocaptionfont{\noindent\rmfamily}%
     1452  \def\suppinfocaptionfont{\noindent\sffamily}%
    14531453  %
    1454   \def\figurenumfont{\rmfamily\fontsize{9bp}{12}\fontseries{b}\selectfont}%
    1455   \def\figurecaptionfont{\rmfamily\fontsize{8.5bp}{12}\selectfont}
     1454  \def\figurenumfont{\sffamily\fontsize{9bp}{12}\fontseries{b}\selectfont}%
     1455  \def\figurecaptionfont{\sffamily\fontsize{8.5bp}{12}\selectfont}
    14561456  \def\bwfiginfofont{\fontfamily{tim}\fontsize{10bp}{10bp}\selectfont}%
    14571457  %
    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}
     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}
    14641464  %
    1465 %%  \def\footnotetextfont{\rmfamily\fontsize{8bp}{10bp}\selectfont}
     1465%%  \def\footnotetextfont{\sffamily\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\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}%
     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}%
    14821482  %
    14831483}%
     
    14881488%  \def\watermarkfont{\reset@font\fontfamily{\ffdefault}\fontsize{45}{45}\bfseries\selectfont}
    14891489  %
    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}%
     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}%
    14961496  %
    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}%
     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}%
    15061506  %
    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}%
     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}%
    15141514  %
    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}%
     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}%
    15221522  %
    1523   \def\boxheadfont{\rmfamily\fontsize{8}{10}\fontseries{b}\selectfont}
    1524   \def\boxtitlefont{\rmfamily\fontsize{8}{10}\bfseries\selectfont}
     1523  \def\boxheadfont{\sffamily\fontsize{8}{10}\fontseries{b}\selectfont}
     1524  \def\boxtitlefont{\sffamily\fontsize{8}{10}\bfseries\selectfont}
    15251525  %
    1526   \def\GnSabsfont{\rmfamily\fontsize{9}{15}\selectfont}%
    1527   \def\GnSabsfootfont{\reset@font\rmfamily\fontsize{14}{0}\bfseries\selectfont}%
     1526  \def\GnSabsfont{\sffamily\fontsize{9}{15}\selectfont}%
     1527  \def\GnSabsfootfont{\reset@font\sffamily\fontsize{14}{0}\bfseries\selectfont}%
    15281528  %
    1529   \def\suppinfofont{\noindent\rmfamily}%
     1529  \def\suppinfofont{\noindent\sffamily}%
    15301530  \def\suppinfoheadfont{\noindent\fontsize{8}{13}\fontseries{b}\selectfont}%
    1531   \def\suppinfocaptionfont{\noindent\rmfamily}%
     1531  \def\suppinfocaptionfont{\noindent\sffamily}%
    15321532  %
    1533   \def\figurenumfont{\rmfamily\fontsize{7bp}{9}\fontseries{b}\selectfont}%
    1534   \def\figurecaptionfont{\rmfamily\fontsize{8bp}{11}\selectfont}
     1533  \def\figurenumfont{\sffamily\fontsize{7bp}{9}\fontseries{b}\selectfont}%
     1534  \def\figurecaptionfont{\sffamily\fontsize{8bp}{11}\selectfont}
    15351535  \def\bwfiginfofont{\fontfamily{tim}\fontsize{10bp}{10bp}\selectfont}%
    15361536  %
    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}
     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}
    15431543  %
    1544 %%  \def\footnotetextfont{\rmfamily\fontsize{8bp}{10bp}\selectfont}
     1544%%  \def\footnotetextfont{\sffamily\fontsize{8bp}{10bp}\selectfont}
    15451545  %
    15461546  \def\listfont{\normalsize}%
  • doc/papers/concurrency/Paper.tex

    r534d84e ra0c7d5cc  
    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`\}}}%
    7472
    7573\makeatletter
     
    246244\maketitle
    247245
    248 
     246% ======================================================================
     247% ======================================================================
    249248\section{Introduction}
     249% ======================================================================
     250% ======================================================================
    250251
    251252This paper provides a minimal concurrency \newterm{Abstract Program Interface} (API) that is simple, efficient and can be used to build other concurrency features.
     
    253254An easier approach for programmers is to support higher-level constructs as the basis of concurrency.
    254255Indeed, for highly productive concurrent programming, high-level approaches are much more popular~\cite{Hochstein05}.
    255 Examples 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}.
     256Examples of high-level approaches are task based~\cite{TBB}, message passing~\cite{Erlang,MPI}, and implicit threading~\cite{OpenMP}.
    256257
    257258This paper uses the following terminology.
     
    271272The 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.
    272273
    273 
     274% ======================================================================
     275% ======================================================================
    274276\section{\CFA Overview}
     277% ======================================================================
     278% ======================================================================
    275279
    276280The following is a quick introduction to the \CFA language, specifically tailored to the features needed to support concurrency.
    277 Extended 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.
     281Most 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.
    280284%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.
    281 Like C, the basics of \CFA revolve around structures and functions.
    282 Virtually all of the code generated by the \CFA translator respects C memory layouts and calling conventions.
    283 While \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}.
     285Like C, the basics of \CFA revolve around structures and routines, which are thin abstractions over machine code.
     286The vast majority of the code produced by the \CFA translator respects memory layouts and calling conventions laid out by C.
     287Interestingly, 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
     288values''~\cite[3.15]{C11}}, most importantly construction and destruction of objects.
    284289
    285290
    286291\subsection{References}
    287292
    288 \CFA provides multi-level rebindable references, as an alternative to pointers, which significantly reduces syntactic noise.
    289 \begin{cfa}
    290 int x = 1, y = 2, z = 3;
    291 int * p1 = &x, ** p2 = &p1,  *** p3 = &p2,      $\C{// pointers to x}$
    292         `&` r1 = x,  `&&` r2 = r1,  `&&&` r3 = r2;      $\C{// references to x}$
    293 int * p4 = &z, `&` r4 = z;
    294 
    295 *p1 = 3; **p2 = 3; ***p3 = 3;       // change x
    296 r1 =  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}
    300 A reference is a handle to an object, like a pointer, but is automatically dereferenced the specified number of levels.
    301 Referencing (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 
    307 Heterogeneous data is often aggregated into a structure/union.
    308 To 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}
    313 struct S { char c; int i; double d; };
    314 struct T { double m, n; };
    315 // multiple aggregate parameters
    316 \end{cfa}
    317 \begin{tabular}{@{}l@{\hspace{\parindentlnth}}|@{\hspace{\parindentlnth}}l@{}}
    318 \begin{cfa}
    319 void 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}
    326 void 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}
    334 Object-oriented programming languages only provide implicit qualification for the receiver.
    335 
    336 In 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}
    341 and may appear as the body of a function or nested within a function body.
    342 Each expression in the expression-list provides a type and object.
    343 The type must be an aggregate type.
    344 (Enumerations are already opened.)
    345 The object is the implicit qualifier for the open structure-fields.
    346 All 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 
     293Like \CC, \CFA introduces rebind-able references providing multiple dereferencing as an alternative to pointers.
     294In 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}
     296int x, y, z;
     297int * 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}$
     304int & ar[3] = {x, y, z};                                        $\C{// initialize array of references}$
     305
     306typeof( ar[1]) p;                                                       $\C{// is int, referenced object type}$
     307typeof(&ar[1]) q;                                                       $\C{// is int \&, reference type}$
     308sizeof( ar[1]) == sizeof(int);                          $\C{// is true, referenced object size}$
     309sizeof(&ar[1]) == sizeof(int *);                        $\C{// is true, reference size}$
     310\end{cfa}
     311The 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% ======================================================================
    349314\subsection{Overloading}
    350315
    351 \CFA maximizes the ability to reuse names via overloading to aggressively address the naming problem.
    352 Both 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}
    361 const short int MIN = -32768;
    362 const int MIN = -2147483648;
    363 const long int MIN = -9223372036854775808L;
    364 \end{cfa}
    365 &
    366 \begin{cfa}
    367 short int si = MIN;
    368 int i = MIN;
    369 long int li = MIN;
    370 \end{cfa}
    371 \end{tabular}
     316Another 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.
     317As well, \CFA uses the return type as part of the selection criteria, as in Ada~\cite{Ada}.
     318For routines with multiple parameters and returns, the selection is complex.
    372319\begin{cfa}
    373320// selection based on type and number of parameters
    374 \end{cfa}
    375 \begin{tabular}{@{}l@{\hspace{1.7\parindentlnth}}|@{\hspace{\parindentlnth}}l@{}}
    376 \begin{cfa}
    377 void f( void );
    378 void f( char );
    379 void f( int, double );
    380 \end{cfa}
    381 &
    382 \begin{cfa}
    383 f();
    384 f( 'a' );
    385 f( 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}
    393 char f( int );
    394 double f( int );
    395 [char, double] f( int );
    396 \end{cfa}
    397 &
    398 \begin{cfa}
    399 char c = f( 3 );
    400 double d = f( 3 );
    401 [d, c] = f( 3 );
    402 \end{cfa}
    403 \end{tabular}
    404 \lstMakeShortInline@%
    405 \end{cquote}
    406 Overloading is important for \CFA concurrency since the runtime system relies on creating different types to represent concurrency objects.
     321void f(void);                   $\C{// (1)}$
     322void f(char);                   $\C{// (2)}$
     323void f(int, double);    $\C{// (3)}$
     324f();                                    $\C{// select (1)}$
     325f('a');                                 $\C{// select (2)}$
     326f(3, 5.2);                              $\C{// select (3)}$
     327
     328// selection based on  type and number of returns
     329char   f(int);                  $\C{// (1)}$
     330double f(int);                  $\C{// (2)}$
     331char   c = f(3);                $\C{// select (1)}$
     332double d = f(4);                $\C{// select (2)}$
     333\end{cfa}
     334This feature is particularly important for concurrency since the runtime system relies on creating different types to represent concurrency objects.
    407335Therefore, overloading is necessary to prevent the need for long prefixes and other naming conventions that prevent name clashes.
    408 As seen in Section~\ref{basics}, function @main@ is heavily overloaded.
    409 
    410 Variable overloading is useful in the parallel semantics of the @with@ statement for fields with the same name:
    411 \begin{cfa}
    412 struct S { int `i`; int j; double m; } s;
    413 struct T { int `i`; int k; int m; } t;
    414 with ( 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}
    424 For parallel semantics, both @s.i@ and @t.i@ are visible with the same type, so only @i@ is ambiguous without qualification.
    425 
    426 
     336As seen in section \ref{basics}, routine @main@ is an example that benefits from overloading.
     337
     338% ======================================================================
    427339\subsection{Operators}
    428 
    429340Overloading also extends to operators.
    430 Operator-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}
    435 int ++? (int op);
    436 int ?++ (int op);
    437 int `?+?` (int op1, int op2);
    438 int ?<=?(int op1, int op2);
    439 int ?=? (int & op1, int op2);
    440 int ?+=?(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}
    453 struct S { int i, j; };
    454 S `?+?`( S op1, S op2) { // add two structures
     341The 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}
     343int ++? (int op);                       $\C{// unary prefix increment}$
     344int ?++ (int op);                       $\C{// unary postfix increment}$
     345int ?+? (int op1, int op2);             $\C{// binary plus}$
     346int ?<=?(int op1, int op2);             $\C{// binary less than}$
     347int ?=? (int & op1, int op2);           $\C{// binary assignment}$
     348int ?+=?(int & op1, int op2);           $\C{// binary plus-assignment}$
     349
     350struct S {int i, j;};
     351S ?+?(S op1, S op2) {                           $\C{// add two structures}$
    455352        return (S){op1.i + op2.i, op1.j + op2.j};
    456353}
    457354S s1 = {1, 2}, s2 = {2, 3}, s3;
    458 s3 = s1 `+` s2;         // compute sum: s3 == {2, 5}
    459 \end{cfa}
    460 \end{tabular}
    461 \lstMakeShortInline@%
    462 \end{cquote}
    463 While concurrency does not use operator overloading directly, it provides an introduction for the syntax of constructors.
    464 
    465 
     355s3 = s1 + s2;                                           $\C{// compute sum: s3 == {2, 5}}$
     356\end{cfa}
     357While 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}
     361Object 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.
     362Since \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}
     364struct S {
     365        size_t size;
     366        int * ia;
     367};
     368void ?{}(S & s, int asize) {    $\C{// constructor operator}$
     369        s.size = asize;                         $\C{// initialize fields}$
     370        s.ia = calloc(size, sizeof(S));
     371}
     372void ^?{}(S & s) {                              $\C{// destructor operator}$
     373        free(ia);                                       $\C{// de-initialization fields}$
     374}
     375int 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}
     383The language guarantees that every object and all their fields are constructed.
     384Like \CC, construction of an object is automatically done on allocation and destruction of the object is done on deallocation.
     385Allocation 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}$
     391struct S * s = new();   $\C{// allocation, call constructor}$
     392...
     393delete(s);                              $\C{// deallocation, call destructor}$
     394\end{cfa}
     395Note 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% ======================================================================
    466398\subsection{Parametric Polymorphism}
    467399\label{s:ParametricPolymorphism}
    468 
    469 The 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.
     400Routines in \CFA can also be reused for multiple types.
     401This capability is done using the @forall@ clauses, which allow separately compiled routines to support generic usage over multiple types.
    470402For example, the following sum function works for any type that supports construction from 0 and addition:
    471403\begin{cfa}
    472 forall( otype T | { void `?{}`( T *, zero_t ); T `?+?`( T, T ); } ) // constraint type, 0 and +
    473 T 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 +}$
     404// constraint type, 0 and +
     405forall(otype T | { void ?{}(T *, zero_t); T ?+?(T, T); })
     406T 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 +}$
    477410        return total;
    478411}
     412
    479413S sa[5];
    480 int 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}
    485 trait `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 & );
     414int i = sum(sa, 5);                             $\C{// use S's 0 construction and +}$
     415\end{cfa}
     416
     417Since writing constraints on types can become cumbersome for more constrained functions, \CFA also has the concept of traits.
     418Traits are named collection of constraints that can be used both instead and in addition to regular constraints:
     419\begin{cfa}
     420trait 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 *);
    491426};
    492 forall( otype T `| sumable( T )` )                      $\C{// use trait}$
    493 T sum( T a[$\,$], size_t size );
    494 \end{cfa}
    495 
    496 Assertions 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 
    500 Using the return type for discrimination, it is possible to write a type-safe @alloc@ based on the C @malloc@:
    501 \begin{cfa}
    502 forall( dtype T | sized(T) ) T * alloc( void ) { return (T *)malloc( sizeof(T) ); }
    503 int * ip = alloc();                                                     $\C{// select type and size from left-hand side}$
    504 double * dp = alloc();
    505 struct S {...} * sp = alloc();
    506 \end{cfa}
    507 where the return type supplies the type/size of the allocation, which is impossible in most type systems.
    508 
    509 
    510 \subsection{Constructors / Destructors}
    511 
    512 Object lifetime is a challenge in non-managed programming languages.
    513 \CFA responds with \CC-like constructors and destructors:
    514 \begin{cfa}
    515 struct VLA { int len, * data; };                        $\C{// variable length array of integers}$
    516 void ?{}( VLA & vla ) with ( vla ) { len = 10;  data = alloc( len ); }  // default constructor
    517 void ?{}( VLA & vla, int size, char fill ) with ( vla ) { len = size;  data = alloc( len, fill ); } // initialization
    518 void ?{}( VLA & vla, VLA other ) { vla.len = other.len;  vla.data = other.data; } // copy, shallow
    519 void ^?{}( 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}
    532 Like \CC, construction is implicit on allocation (stack/heap) and destruction is implicit on deallocation.
    533 The 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}$
    539 struct S * s = new();                                           $\C{// allocation, call constructor}$
    540 ...
    541 delete( 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 
     427forall( otype T | summable(T) ) $\C{// use trait}$
     428T sum(T a[], size_t size);
     429\end{cfa}
     430
     431Note that the type use for assertions can be either an @otype@ or a @dtype@.
     432Types declared as @otype@ refer to ``complete'' objects, \ie objects with a size, a default constructor, a copy constructor, a destructor and an assignment operator.
     433Using @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}
     437Since \CFA lacks the concept of a receiver, certain functions end up needing to repeat variable names often.
     438To remove this inconvenience, \CFA provides the @with@ statement, which opens an aggregate scope making its fields directly accessible (like Pascal).
     439\begin{cfa}
     440struct S { int i, j; };
     441int mem(S & this) with (this)           $\C{// with clause}$
     442        i = 1;                                                  $\C{// this->i}$
     443        j = 2;                                                  $\C{// this->j}$
     444}
     445int 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
     463For more information on \CFA see \cite{cforall-ug,Schluntz17,www-cfa}.
     464
     465% ======================================================================
     466% ======================================================================
    546467\section{Concurrency Basics}\label{basics}
    547 
    548 At its core, concurrency is based on multiple call-stacks and scheduling among threads executing on these stacks.
     468% ======================================================================
     469% ======================================================================
     470
     471At its core, concurrency is based on having multiple call-stacks and scheduling among threads of execution executing on these stacks.
    549472Multiple call stacks (or contexts) and a single thread of execution does \emph{not} imply concurrency.
    550473Execution with a single thread and multiple stacks where the thread is deterministically self-scheduling across the stacks is called \newterm{coroutining};
     
    662585\begin{lstlisting}[aboveskip=0pt,belowskip=0pt]
    663586`coroutine` Fib { int fn; };
    664 void ?{}( Fibonacci & fib ) with( fib ) { fn = 0; }
    665587void main( Fib & f ) with( f ) {
    666588        int f1, f2;
  • doc/papers/general/Paper.tex

    r534d84e ra0c7d5cc  
    7474\setlength{\gcolumnposn}{3.5in}
    7575\setlength{\columnposn}{\gcolumnposn}
    76 
    7776\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}}}}
    7877\newcommand{\CRT}{\global\columnposn=\gcolumnposn}
     
    192191This installation base and the programmers producing it represent a massive software-engineering investment spanning decades and likely to continue for decades more.
    193192Nevertheless, 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
    211212The 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.
    212213This installation base and the programmers producing it represent a massive software-engineering investment spanning decades and likely to continue for decades more.
     
    237238\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.
    238239
    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).
     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).
    240241Ultimately, a compiler is necessary for advanced features and optimal performance.
    241242All features discussed in this paper are working, unless otherwise stated as under construction.
     
    265266Code 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.
    266267As an example:
    267 \begin{cfa}
    268 int max = 2147483647;                                           $\C[4in]{// (1)}$
    269 double max = 1.7976931348623157E+308;           $\C{// (2)}$
     268
     269\begin{cfa}
     270int max = 2147483647;                                   $\C[4in]{// (1)}$
     271double max = 1.7976931348623157E+308;   $\C{// (2)}$
    270272int max( int a, int b ) { return a < b ? b : a; }  $\C{// (3)}$
    271273double max( double a, double b ) { return a < b ? b : a; }  $\C{// (4)}\CRT$
     
    327329A simple example is leveraging the existing type-unsafe (@void *@) C @bsearch@ to binary search a sorted float array:
    328330\begin{cfa}
    329 void * bsearch( const void * key, const void * base, size_t nmemb, size_t size,
    330                                 int (* compar)( const void *, const void * ));
     331void * bsearch( const void * key, const void * base, size_t nmemb, size_t size, int (* compar)( const void *, const void * ));
    331332int comp( const void * t1, const void * t2 ) {
    332333         return *(double *)t1 < *(double *)t2 ? -1 : *(double *)t2 < *(double *)t1 ? 1 : 0;
     
    376377Hence, programmers can easily form local environments, adding and modifying appropriate functions, to maximize reuse of other existing functions and types.
    377378
    378 To 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}
    380 forall( otype `T` ) {                                                   $\C{// distribution block, add forall qualifier to declarations}$
     379Under 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}
     381forall( otype `T` ) {                                                   $\C{// forall block}$
    381382        struct stack { stack_node(`T`) * head; };       $\C{// generic type}$
    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         }
     383        void push( stack(`T`) & s, `T` value ) ...      $\C{// generic operations}$
     384        T pop( stack(`T`) & s ) ...
    386385}
    387386\end{cfa}
     
    391390
    392391\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:
    393 \begin{cquote}
    394 \lstDeleteShortInline@%
    395 \begin{tabular}{@{}l@{\hspace{\parindentlnth}}|@{\hspace{\parindentlnth}}l@{}}
    396 \begin{cfa}
    397 trait `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 & );
     392\begin{cfa}
     393trait `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 * );
    403399};
    404 \end{cfa}
    405 &
    406 \begin{cfa}
    407 forall( otype T `| sumable( T )` ) // use trait
    408 T 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 +
     400forall( 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 +}$
    412403        return total;
    413404}
    414405\end{cfa}
    415 \end{tabular}
    416 \lstMakeShortInline@%
    417 \end{cquote}
    418406
    419407In 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:
     
    478466
    479467A 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@{}}
    483468\begin{cfa}
    484469forall( otype R, otype S ) struct pair {
    485         R first;        S second;
     470        R first;
     471        S second;
    486472};
    487 `forall( otype T )` // dynamic
    488 T value( pair(const char *, T) p ) { return p.second; }
    489 `forall( dtype F, otype T )` // dtype-static (concrete)
    490 T value( pair(F *, T * ) p) { return *p.second; }
    491 \end{cfa}
    492 &
    493 \begin{cfa}
    494 pair(const char *, int) p = {"magic", 42}; // concrete
     473forall( otype T ) T value( pair( const char *, T ) p ) { return p.second; } $\C{// dynamic}$
     474forall( dtype F, otype T ) T value( pair( F *, T * ) p ) { return *p.second; } $\C{// dtype-static (concrete)}$
     475
     476pair( const char *, int ) p = { "magic", 42 }; $\C{// concrete}$
    495477int i = value( p );
    496 pair(void *, int *) q = { 0, &p.second }; // concrete
     478pair( void *, int * ) q = { 0, &p.second }; $\C{// concrete}$
    497479i = value( q );
    498480double d = 1.0;
    499 pair(double *, double *) r = { &d, &d }; // concrete
     481pair( double *, double * ) r = { &d, &d }; $\C{// concrete}$
    500482d = value( r );
    501483\end{cfa}
    502 \end{tabular}
    503 \lstMakeShortInline@%
    504 \end{cquote}
    505484
    506485\CFA classifies generic types as either \newterm{concrete} or \newterm{dynamic}.
     
    589568Another useful pattern enabled by reused dtype-static type instantiations is zero-cost \newterm{tag-structures}.
    590569Sometimes 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@{}}
    594570\begin{cfa}
    595571forall( dtype Unit ) struct scalar { unsigned long value; };
    596572struct metres {};
    597573struct litres {};
     574
    598575forall( dtype U ) scalar(U) ?+?( scalar(U) a, scalar(U) b ) {
    599576        return (scalar(U)){ a.value + b.value };
    600577}
    601 \end{cfa}
    602 &
    603 \begin{cfa}
    604 scalar(metres) half_marathon = { 21_098 };
    605 scalar(litres) pool = { 2_500_000 };
    606 scalar(metres) marathon = half_marathon +
    607                                                         half_marathon;
    608 scalar(litres) two_pools = pool + pool;
    609 `marathon + pool;`      // compilation ERROR
    610 \end{cfa}
    611 \end{tabular}
    612 \lstMakeShortInline@%
    613 \end{cquote}
     578scalar(metres) half_marathon = { 21_093 };
     579scalar(litres) swimming_pool = { 2_500_000 };
     580scalar(metres) marathon = half_marathon + half_marathon;
     581scalar(litres) two_pools = swimming_pool + swimming_pool;
     582marathon + swimming_pool;                                       $\C{// compilation ERROR}$
     583\end{cfa}
    614584@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 @?+?@.
    615585These implementations may even be separately compiled, unlike \CC template functions.
     
    12191189                `LIF:` if ( ... ) {
    12201190                        `LF:` for ( ... ) {
    1221                                 ... break `LC`; ...
    1222                                 ... break `LS`; ...
    1223                                 ... break `LIF`; ...
    1224                                 ... continue `LF;` ...
    1225                                 ... break `LF`; ...
     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
    12261200                        } // for
    12271201                } else {
     
    12391213                if ( ... ) {
    12401214                        for ( ... ) {
    1241                                 ... goto `LC`; ...
    1242                                 ... goto `LS`; ...
    1243                                 ... goto `LIF`; ...
    1244                                 ... goto `LFC`; ...
    1245                                 ... goto `LFB`; ...
     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:` ;
    12461224                          `LFC:` ; } `LFB:` ;
    12471225                } else {
     
    12651243// continue loop
    12661244// terminate loop
     1245// continue loop
     1246// terminate loop
    12671247
    12681248
    12691249
    12701250// terminate if
     1251
     1252
    12711253
    12721254\end{cfa}
     
    14291411\label{s:WithStatement}
    14301412
    1431 Heterogeneous data is often aggregated into a structure/union.
    1432 To 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}
    1437 struct S { char c; int i; double d; };
     1413Grouping 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}
     1415struct S {                                                                      $\C{// aggregate}$
     1416        char c;                                                                 $\C{// fields}$
     1417        int i;
     1418        double d;
     1419};
     1420S s, as[10];
     1421\end{cfa}
     1422However, functions manipulating aggregates must repeat the aggregate name to access its containing fields:
     1423\begin{cfa}
     1424void f( S s ) {
     1425        `s.`c; `s.`i; `s.`d;                                    $\C{// access containing fields}$
     1426}
     1427\end{cfa}
     1428which extends to multiple levels of qualification for nested aggregates.
     1429A similar situation occurs in object-oriented programming, \eg \CC:
     1430\begin{C++}
     1431struct 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++}
     1440Object-oriented nesting of member functions in a \lstinline[language=C++]@class/struct@ allows eliding \lstinline[language=C++]@this->@ because of lexical scoping.
     1441However, for other aggregate parameters, qualification is necessary:
     1442\begin{cfa}
    14381443struct T { double m, n; };
    1439 // multiple aggregate parameters
    1440 \end{cfa}
    1441 \begin{tabular}{@{}l@{\hspace{\parindentlnth}}|@{\hspace{\parindentlnth}}l@{}}
    1442 \begin{cfa}
    1443 void 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}
    1450 void 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}
    1458 Object-oriented programming languages only provide implicit qualification for the receiver.
     1444int 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
     1450To 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.
     1451Hence, the qualified fields become variables with the side-effect that it is easier to optimizing field references in a block.
     1452\begin{cfa}
     1453void 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}
     1457with the generality of opening multiple aggregate-parameters:
     1458\begin{cfa}
     1459void 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}
    14591464
    14601465In detail, the @with@ statement has the form:
     
    14691474The object is the implicit qualifier for the open structure-fields.
    14701475
    1471 All 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.
     1476All expressions in the expression list are open in parallel within the compound statement.
     1477This semantic is different from Pascal, which nests the openings from left to right.
    14721478The difference between parallel and nesting occurs for fields with the same name and type:
    14731479\begin{cfa}
     
    22552261\begin{cfa}
    22562262MIN
    2257 
    22582263MAX
    2259 
    22602264PI
    22612265E
     
    22632267&
    22642268\begin{cfa}
    2265 SCHAR_MIN, CHAR_MIN, SHRT_MIN, INT_MIN, LONG_MIN,
    2266         LLONG_MIN, FLT_MIN, DBL_MIN, LDBL_MIN
    2267 SCHAR_MAX, UCHAR_MAX, SHRT_MAX, INT_MAX, LONG_MAX,
    2268         LLONG_MAX, FLT_MAX, DBL_MAX, LDBL_MAX
     2269SCHAR_MIN, CHAR_MIN, SHRT_MIN, INT_MIN, LONG_MIN, LLONG_MIN, FLT_MIN, DBL_MIN, LDBL_MIN
     2270SCHAR_MAX, UCHAR_MAX, SHRT_MAX, INT_MAX, LONG_MAX, LLONG_MAX, FLT_MAX, DBL_MAX, LDBL_MAX
    22692271M_PI, M_PIl
    22702272M_E, M_El
     
    24392441ip = (int *)malloc( sizeof( int ) ); memset( ip, fill, dim * sizeof( int ) );
    24402442ip = (int *)realloc( ip, 2 * dim * sizeof( int ) );
    2441 ip = (int *)realloc( ip, 4 * dim * sizeof( int ) );
    2442                         memset( ip, fill, 4 * dim * sizeof( int ) );
     2443ip = (int *)realloc( ip, 4 * dim * sizeof( int ) ); memset( ip, fill, 4 * dim * sizeof( int ) );
     2444
    24432445ip = memalign( 16, sizeof( int ) );
    24442446ip = memalign( 16, sizeof( int ) ); memset( ip, fill, sizeof( int ) );
     
    26052607Though \CFA provides significant added functionality over C, these features have a low runtime penalty.
    26062608In fact, \CFA's features for generic programming can enable faster runtime execution than idiomatic @void *@-based C code.
    2607 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:BenchmarkStackImplementations}).
     2609This 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}).
    26082610Since 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.
    26092611A more illustrative comparison measures the costs of idiomatic usage of each language's features.
     
    28222824\appendix
    28232825
    2824 \section{Benchmark Stack Implementations}
    2825 \label{sec:BenchmarkStackImplementations}
    2826 
    2827 Throughout, @/***/@ 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]
    2836 typedef struct node {
     2826\section{Benchmark Stack Implementation}
     2827\label{sec:BenchmarkStackImplementation}
     2828
     2829Throughout, @/***/@ designates a counted redundant type annotation; code reformatted for brevity.
     2830
     2831\smallskip\noindent
     2832C
     2833\begin{cfa}[xleftmargin=2\parindentlnth,aboveskip=0pt,belowskip=0pt]
     2834struct stack_node {
    28372835        void * value;
    2838         struct node * next;
    2839 } node;
    2840 typedef struct stack {
    2841         struct node * head;
    2842 } stack;
    2843 void 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 }
    2853 void 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 );
     2836        struct stack_node * next;
     2837};
     2838struct stack { struct stack_node* head; };
     2839void 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 );
    28592845        }
    28602846        s->head = NULL;
    28612847}
    2862 \end{cfa}
    2863 &
    2864 \begin{cfa}[xleftmargin=0pt,aboveskip=0pt,belowskip=0pt]
    2865 stack new_stack() {
    2866         return (stack){ NULL }; /***/
    2867 }
    2868 stack * assign_stack( stack * s, const stack * t,
    2869                                 void * (*copy_el)( const void * ),
    2870                                 void (*free_el)( void * ) ) {
     2848struct stack new_stack() { return (struct stack){ NULL }; /***/ }
     2849void 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}
     2858struct stack * assign_stack( struct stack * s, const struct stack * t,
     2859                void * (*copy_el)( const void * ), void (*free_el)( void * ) ) {
    28712860        if ( s->head == t->head ) return s;
    28722861        clear_stack( s, free_el ); /***/
     
    28742863        return s;
    28752864}
    2876 _Bool stack_empty( const stack * s ) {
    2877          return s->head == NULL;
    2878 }
    2879 void push_stack( stack * s, void * v ) {
    2880         node * n = malloc(sizeof(node)); /***/
    2881         *n = (node){ v, s->head }; /***/
     2865_Bool stack_empty( const struct stack * s ) { return s->head == NULL; }
     2866void 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 }; /***/
    28822869        s->head = n;
    28832870}
    2884 void * pop_stack( stack * s ) {
    2885         node * n = s->head;
     2871void * pop_stack( struct stack * s ) {
     2872        struct stack_node * n = s->head;
    28862873        s->head = n->next;
    28872874        void * v = n->value;
     
    28902877}
    28912878\end{cfa}
    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]
     2879
     2880\medskip\noindent
     2881\CFA
     2882\begin{cfa}[xleftmargin=2\parindentlnth,aboveskip=0pt,belowskip=0pt]
     2883forall( otype T ) struct stack_node {
     2884        T value;
     2885        stack_node(T) * next;
     2886};
     2887forall( otype T ) struct stack { stack_node(T) * head; };
     2888forall( 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);
     2894        }
     2895        head = 0;
     2896}
     2897forall( otype T ) void ?{}( stack(T) & s ) { (s.head){ 0 }; }
     2898forall( 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}
     2907forall( 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}
     2913forall( otype T ) void ^?{}( stack(T) & s) { clear( s ); }
     2914forall( otype T ) _Bool empty( const stack(T) & s ) { return s.head == 0; }
     2915forall( 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}
     2920forall( 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}
    29042931forall( otype T ) {
    2905         struct node {
     2932        struct stack_node {
    29062933                T value;
    2907                 node(T) * next;
     2934                stack_node(T) * next;
    29082935        };
    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;
    2919         }
     2936        struct stack { stack_node(T) * head; };
    29202937        void clear( stack(T) & s ) with( s ) {
    2921                 for ( node(T) * nx = head; nx; ) {
    2922                         node(T) * cr = nx;
    2923                         nx = cr->next;
    2924                         ^(*cr){};
    2925                         free(cr);
     2938                for ( stack_node(T) * next = head; next; ) {
     2939                        stack_node(T) * crnt = next;
     2940                        next = crnt->next;
     2941                        ^(*crnt){};
     2942                        free(crnt);
    29262943                }
    29272944                head = 0;
    29282945        }
    2929 \end{cfa}
    2930 &
    2931 \begin{cfa}[xleftmargin=0pt,aboveskip=0pt,belowskip=0pt]
    2932         void ^?{}( stack(T) & s) { clear( s ); }
     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        }
    29332956        stack(T) ?=?( stack(T) & s, stack(T) t ) {
    29342957                if ( s.head == t.head ) return s;
     
    29372960                return s;
    29382961        }
    2939         _Bool empty( const stack(T) & s ) {
    2940                 return s.head == 0;
    2941         }
     2962        void ^?{}( stack(T) & s) { clear( s ); }
     2963        _Bool empty( const stack(T) & s ) { return s.head == 0; }
    29422964        void push( stack(T) & s, T value ) with( s ) {
    2943                 node(T) * n = alloc();
     2965                stack_node(T) * n = alloc();
    29442966                (*n){ value, head };
    29452967                head = n;
    29462968        }
    29472969        T pop( stack(T) & s ) with( s ) {
    2948                 node(T) * n = head;
     2970                stack_node(T) * n = head;
    29492971                head = n->next;
    29502972                T v = n->value;
     
    29542976        }
    29552977}
    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]
     2978\end{comment}
     2979
     2980\medskip\noindent
     2981\CC
     2982\begin{cfa}[xleftmargin=2\parindentlnth,aboveskip=0pt,belowskip=0pt]
    29692983template<typename T> struct stack {
    29702984        struct node {
    29712985                T value;
    29722986                node * next;
    2973                 node( const T & v, node * n = nullptr ) :
    2974                         value( v ), next( n ) {}
     2987                node( const T & v, node * n = nullptr ) : value( v ), next( n ) {}
    29752988        };
    29762989        node * head;
    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         }
     2990        stack() : head( nullptr ) {}
     2991        stack( const stack<T> & o ) { copy( o ); }
    29852992        void clear() {
    2986                 for ( node * nx = head; nx; ) {
    2987                         node * cr = nx;
    2988                         nx = cr->next;
    2989                         delete cr;
     2993                for ( node * next = head; next; ) {
     2994                        node * crnt = next;
     2995                        next = crnt->next;
     2996                        delete crnt;
    29902997                }
    29912998                head = nullptr;
    29922999        }
    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 ); }
     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        }
    29983008        ~stack() { clear(); }
    2999         stack & operator=( const stack<T> & o ) {
     3009        stack & operator= ( const stack<T> & o ) {
    30003010                if ( this == &o ) return *this;
    30013011                clear();
     
    30043014        }
    30053015        bool empty() const { return head == nullptr; }
    3006         void push( const T & value ) {
    3007                 head = new node{ value, head };  /***/
    3008         }
     3016        void push( const T & value ) { head = new node{ value, head };  /***/ }
    30093017        T pop() {
    30103018                node * n = head;
     
    30153023        }
    30163024};
    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]
     3025\end{cfa}
     3026
     3027\medskip\noindent
     3028\CCV
     3029\begin{cfa}[xleftmargin=2\parindentlnth,aboveskip=0pt,belowskip=0pt]
    30323030struct stack {
    30333031        struct node {
    30343032                ptr<object> value;
    30353033                node * next;
    3036                 node( const object & v, node * n = nullptr ) :
    3037                                 value( v.new_copy() ), next( n ) {}
     3034                node( const object & v, node * n = nullptr ) : value( v.new_copy() ), next( n ) {}
    30383035        };
    30393036        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         }
    30483037        void clear() {
    3049                 for ( node * nx = head; nx; ) {
    3050                         node * cr = nx;
    3051                         nx = cr->next;
    3052                         delete cr;
     3038                for ( node * next = head; next; ) {
     3039                        node * crnt = next;
     3040                        next = crnt->next;
     3041                        delete crnt;
    30533042                }
    30543043                head = nullptr;
    30553044        }
    3056 \end{cfa}
    3057 &
    3058 \begin{cfa}[xleftmargin=0pt,aboveskip=0pt,belowskip=0pt]
     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        }
    30593053        stack() : head( nullptr ) {}
    30603054        stack( const stack & o ) { copy( o ); }
    30613055        ~stack() { clear(); }
    3062         stack & operator=( const stack & o ) {
     3056        stack & operator= ( const stack & o ) {
    30633057                if ( this == &o ) return *this;
    30643058                clear();
     
    30673061        }
    30683062        bool empty() const { return head == nullptr; }
    3069         void push( const object & value ) {
    3070                 head = new node{ value, head }; /***/
    3071         }
     3063        void push( const object & value ) { head = new node{ value, head }; /***/ }
    30723064        ptr<object> pop() {
    30733065                node * n = head;
     
    30783070        }
    30793071};
    3080 
    3081 
    3082 
    3083 \end{cfa}
    3084 \end{tabular}
    3085 \lstMakeShortInline@%
    3086 \end{flushleft}
     3072\end{cfa}
    30873073
    30883074
  • doc/papers/general/evaluation/c-bench.c

    r534d84e ra0c7d5cc  
    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

    r534d84e ra0c7d5cc  
    22#include "c-pair.h"
    33
    4 pair * new_pair( void * first, void * second ) {
    5         pair * p = malloc( sizeof(pair) ); /***/
    6         *p = (pair){ first, second }; /***/
     4struct pair* new_pair(void* first, void* second) {
     5        struct pair* p = malloc(sizeof(struct pair)); /***/
     6        *p = (struct pair){ first, second }; /***/
    77        return p;
    88}
    99
    10 pair * copy_pair( const pair * src,
    11                 void * (* copy_first)(const void* ), void * (* copy_second)(const void *)) {
     10struct pair* copy_pair(const struct 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( 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(struct 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 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 );
     21int 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);
    2525        return c;
    2626}
  • doc/papers/general/evaluation/c-pair.h

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

    r534d84e ra0c7d5cc  
    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

    r534d84e ra0c7d5cc  
    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

    r534d84e ra0c7d5cc  
    22#include "c-stack.h"
    33
    4 typedef struct node {
     4struct stack_node {
    55        void * value;
    6         struct node * next;
    7 } node;
     6        struct stack_node * next;
     7};
    88
    9 void 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 
    19 void 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 );
     9void 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 );
    2515        }
    2616        s->head = NULL;
    2717}
    2818
    29 stack new_stack() { return (stack){ NULL }; /***/ }
     19struct stack new_stack() { return (struct stack){ NULL }; /***/ }
    3020
    31 stack * assign_stack( stack * s, const stack * t,
     21void 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}
     30struct stack * assign_stack( struct stack * s, const struct stack * t,
    3231                void * (*copy_el)( const void * ), void (*free_el)( void * ) ) {
    3332        if ( s->head == t->head ) return s;
     
    3736}
    3837
    39 _Bool stack_empty( const stack * s ) { return s->head == NULL; }
     38_Bool stack_empty( const struct stack * s ) { return s->head == NULL; }
    4039
    41 void push_stack( stack * s, void * v ) {
    42         node * n = malloc( sizeof(node) ); /***/
    43         *n = (node){ v, s->head }; /***/
     40void 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 }; /***/
    4443        s->head = n;
    4544}
    4645
    47 void * pop_stack( stack * s ) {
    48         node * n = s->head;
     46void * pop_stack( struct stack * s ) {
     47        struct stack_node * n = s->head;
    4948        s->head = n->next;
    5049        void * v = n->value;
  • doc/papers/general/evaluation/c-stack.h

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

    r534d84e ra0c7d5cc  
    22#include "cfa-stack.h"
    33
    4 forall( otype T ) {
    5         struct node {
    6                 T value;
    7                 node(T) * next;
    8         };
     4forall( otype T ) struct stack_node {
     5        T value;
     6        stack_node(T) * next;
     7};
    98
    10         void ?{}( stack(T) & s ) { (s.head){ 0 }; }
     9forall( 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);
     15        }
     16        head = 0;
     17}
    1118
    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;
     19forall( otype T ) void ?{}( stack(T) & s ) { (s.head){ 0 }; }
     20
     21forall( 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;
    2027        }
     28        *crnt = 0;
     29}
    2130
    22         void ^?{}( stack(T) & s) { clear( s ); }
     31forall( 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}
    2337
    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         }
     38forall( otype T ) void ^?{}( stack(T) & s) { clear( s ); }
    3339
    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         }
     40forall( otype T ) _Bool empty( const stack(T) & s ) { return s.head == 0; }
    4041
    41         _Bool empty( const stack(T) & s ) { return s.head == 0; }
     42forall( 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}
    4247
    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         }
     48forall( 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;
    5755}
  • doc/papers/general/evaluation/cfa-stack.h

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

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

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

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

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

    r534d84e ra0c7d5cc  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Apr 28 09:37:03 2018
    13 // Update Count     : 3201
     12// Last Modified On : Tue Apr 17 17:10:30 2018
     13// Update Count     : 3144
    1414//
    1515
     
    133133} // build_postfix_name
    134134
    135 bool forall = false, xxx = false;                                               // aggregate have one or more forall qualifiers ?
     135bool forall = 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 assertion_list_opt
     284%type<decl> assertion 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
    18701868                        $$ = DeclarationNode::newAggregate( $1, $3, nullptr, nullptr, false )->addQualifiers( $2 );
    18711869                }
     
    22372235                { $$ = DeclarationNode::newTypeParam( $1, $2 )->addTypeInitializer( $4 )->addAssertions( $5 ); }
    22382236        | type_specifier identifier_parameter_declarator
    2239         | assertion_list
    2240                 { $$ = DeclarationNode::newTypeParam( DeclarationNode::Dtype, new string( DeclarationNode::anonymous.newName() ) )->addAssertions( $1 ); }
    22412237        ;
    22422238
     
    22552251        // empty
    22562252                { $$ = nullptr; }
    2257         | assertion_list
    2258         ;
    2259 
    2260 assertion_list:                                                                                 // CFA
    2261         assertion
    2262         | assertion_list assertion
     2253        | assertion_list_opt assertion
    22632254                { $$ = $1 ? $1->appendList( $2 ) : $2; }
    22642255        ;
     
    23872378external_definition_list:
    23882379        external_definition
    2389         | external_definition_list { forall = xxx; } push external_definition
    2390                 { $$ = $1 ? $1->appendList( $4 ) : $4; }
     2380        | external_definition_list push external_definition
     2381                { $$ = $1 ? $1->appendList( $3 ) : $3; }
    23912382        ;
    23922383
     
    24202411                        $$ = $2;
    24212412                }
    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                 }
     2413        | type_qualifier_list '{' external_definition_list '}'                  // CFA, namespace
    24632414        ;
    24642415
     
    24862437with_clause_opt:
    24872438        // empty
    2488                 { $$ = nullptr; forall = false; }
     2439                { $$ = nullptr; }
    24892440        | WITH '(' tuple_expression_list ')'
    2490                 { $$ = $3; forall = false; }
     2441                { $$ = $3; }
    24912442        ;
    24922443
  • src/SymTab/Autogen.cc

    r534d84e ra0c7d5cc  
    99// Author           : Rob Schluntz
    1010// Created On       : Thu Mar 03 15:45:56 2016
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Apr 27 14:39:06 2018
    13 // Update Count     : 63
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Fri Jul 14 16:41:00 2017
     13// Update Count     : 62
    1414//
    1515
     
    331331                        definitions.push_back( dcl );
    332332                        indexer.addId( dcl );
    333                 } catch ( SemanticErrorException & ) {
     333                } catch ( SemanticErrorException err ) {
    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.