- Timestamp:
- Jun 2, 2017, 5:42:10 PM (8 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- 0db6fc0
- Parents:
- 2164637 (diff), 2c6c893 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)links above to see all the changes relative to each parent. - Location:
- doc
- Files:
-
- 8 edited
-
bibliography/cfa.bib (modified) (1 diff)
-
refrat/Makefile (modified) (2 diffs)
-
refrat/refrat.bib (modified) (4 diffs)
-
refrat/refrat.tex (modified) (30 diffs)
-
user/user.tex (modified) (3 diffs)
-
working/exception/impl/except.c (modified) (3 diffs)
-
working/exception/impl/main.c (modified) (5 diffs)
-
working/exception/reference.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
doc/bibliography/cfa.bib
r2164637 rf94ca7e 4424 4424 keywords = {Plan 9}, 4425 4425 contributer = {pabuhr@plg}, 4426 title = {A New CCompiler},4426 title = {A New {C} Compiler}, 4427 4427 author = {Ken Thompson}, 4428 4428 booktitle = {Proceedings of the Summer 1990 UKUUG Conference}, 4429 4429 year = 1990, 4430 4430 pages = {41--51}, 4431 url = {http://doc.cat-v.org/bell_labs/new_c_compilers/new_c_compiler.pdf}4431 note = {\href{http://doc.cat-v.org/bell_labs/new_c_compilers/new_c_compiler.pdf}{http://\-doc.cat-v.org/\-bell\_labs/\-new\_c\_compilers/\-new\_c\_compiler.pdf}}, 4432 4432 } 4433 4433 -
doc/refrat/Makefile
r2164637 rf94ca7e 44 44 45 45 ${basename ${DOCUMENT}}.dvi : Makefile ${GRAPHS} ${PROGRAMS} ${PICTURES} ${FIGURES} ${SOURCES} ${basename ${DOCUMENT}}.tex \ 46 ../LaTeXmacros/common.tex ../LaTeXmacros/ indexstyle ../bibliography/cfa.bib46 ../LaTeXmacros/common.tex ../LaTeXmacros/lstlang.sty ../LaTeXmacros/indexstyle ../bibliography/cfa.bib 47 47 # Conditionally create an empty *.ind (index) file for inclusion until makeindex is run. 48 48 if [ ! -r ${basename $@}.ind ] ; then touch ${basename $@}.ind ; fi … … 70 70 fig2dev -L ps $< > $@ 71 71 72 %.pstex : %.fig 73 fig2dev -L pstex $< > $@ 74 fig2dev -L pstex_t -p $@ $< > $@_t 75 72 76 # Local Variables: # 73 77 # compile-command: "make" # -
doc/refrat/refrat.bib
r2164637 rf94ca7e 2 2 3 3 @manual{ANS:C, 4 keywords = {ANSI C},5 contributer = {gjditchfield@msg},6 title = {American National Standard for Information Systems --4 keywords = {ANSI C}, 5 contributer = {gjditchfield@msg}, 6 title = {American National Standard for Information Systems -- 7 7 Programming Language -- {C}}, 8 organization = {American National Standards Institute},9 address = {1430 Broadway, New York, New York 10018},10 month = dec, year= 1989,11 note = {X3.159-1989}8 organization= {American National Standards Institute}, 9 address = {1430 Broadway, New York, New York 10018}, 10 month = dec, year = 1989, 11 note = {X3.159-1989} 12 12 } 13 13 14 14 @manual{ANS:C11, 15 keywords = {ANS:C11},16 contributer = {gjditchfield@acm.org},17 title = {American National Standard Information Systems --15 keywords = {ANS:C11}, 16 contributer = {gjditchfield@acm.org}, 17 title = {American National Standard Information Systems -- 18 18 Programming languages -- {C}}, 19 organization = {American National Standards Institute},20 address = {25 West 43rd Street, New York, New York 10036},21 month = may, year= 2012,22 note = {INCITS/ISO/IEC 9899-2011[2012]}19 organization= {American National Standards Institute}, 20 address = {25 West 43rd Street, New York, New York 10036}, 21 month = may, year = 2012, 22 note = {INCITS/ISO/IEC 9899-2011[2012]} 23 23 } 24 24 25 25 @book{c++, 26 keywords = {C++, ANSI},27 author = {Margaret A. Ellis and Bjarne Stroustrup},28 title = {The Annotated {C}{\tt ++} Reference Manual},29 publisher = {Addison Wesley},30 year = 1990,31 edition = {first}26 keywords = {C++, ANSI}, 27 author = {Margaret A. Ellis and Bjarne Stroustrup}, 28 title = {The Annotated {C}{\tt ++} Reference Manual}, 29 publisher = {Addison Wesley}, 30 year = 1990, 31 edition = {first} 32 32 } 33 33 34 34 @Unpublished{Ditchfield96:Overview, 35 author ="Glen Ditchfield",36 title ="An Overview of Cforall",37 note ="in preparation",38 year =199635 author = "Glen Ditchfield", 36 title = "An Overview of Cforall", 37 note = "in preparation", 38 year = 1996 39 39 } 40 40 41 41 @article{Bak:overload, 42 keywords = {compilation},43 contributer = {gjditchfield@msg},44 author = {T. P. Baker},45 title = {A One-Pass Algorithm for Overload Resolution in {Ada}},46 journal = toplas,47 year = 1982,48 month = oct, volume = 4, number = 4, pages= {601--614},49 abstract = {42 keywords = {compilation}, 43 contributer = {gjditchfield@msg}, 44 author = {T. P. Baker}, 45 title = {A One-Pass Algorithm for Overload Resolution in {Ada}}, 46 journal = toplas, 47 year = 1982, 48 month = oct, volume = 4, number = 4, pages = {601--614}, 49 abstract = { 50 50 A simple method is presented for detecting ambiguities and finding 51 51 the correct interpretations of expressions in the programming … … 56 56 approach is demonstrated by a brief formal argument. 57 57 }, 58 comment = {58 comment = { 59 59 See also \cite{D:overload}. 60 60 } … … 77 77 78 78 @book{clu, 79 keywords = {CLU},80 contributer = {gjditchfield@msg},81 author = {Barbara Liskov and Russell Atkinson and Toby Bloom and Eliot79 keywords = {CLU}, 80 contributer = {gjditchfield@msg}, 81 author = {Barbara Liskov and Russell Atkinson and Toby Bloom and Eliot 82 82 Moss and J. Craig Schaffert and Robert Scheifler and Alan Snyder}, 83 title = {CLU Reference Manual},84 publisher = {Springer-Verlag},85 year = 1981,86 volume = 114,87 series = {Lecture Notes in Computer Science}83 title = {CLU Reference Manual}, 84 publisher = {Springer-Verlag}, 85 year = 1981, 86 volume = 114, 87 series = {Lecture Notes in Computer Science} 88 88 } 89 89 90 90 @manual{SIMULA87, 91 keywords = {Simula standard},92 contributer = {gjditchfield@msg},93 title = {Databehandling -- Programspr{\aa}k -- {SIMULA}},94 organization = {Standardiseringskommissionen i Sverige},95 note = {Svensk Standard SS 63 61 14},96 year = 1987,97 abstract = {91 keywords = {Simula standard}, 92 contributer = {gjditchfield@msg}, 93 title = {Databehandling -- Programspr{\aa}k -- {SIMULA}}, 94 organization = {Standardiseringskommissionen i Sverige}, 95 note = {Svensk Standard SS 63 61 14}, 96 year = 1987, 97 abstract = { 98 98 Standard for the programming language SIMULA. Written in English. 99 99 } … … 112 112 113 113 @inproceedings{Thompson90new, 114 title = {A New CCompiler},115 author= {Ken Thompson},116 booktitle= {Proceedings of the Summer 1990 UKUUG Conference},117 year= 1990,118 pages= {41--51}114 title = {A New {C} Compiler}, 115 author = {Ken Thompson}, 116 booktitle = {Proceedings of the Summer 1990 UKUUG Conference}, 117 year = 1990, 118 pages = {41--51} 119 119 } -
doc/refrat/refrat.tex
r2164637 rf94ca7e 11 11 %% Created On : Wed Apr 6 14:52:25 2016 12 12 %% Last Modified By : Peter A. Buhr 13 %% Last Modified On : Wed Apr 5 23:23:28201714 %% Update Count : 7913 %% Last Modified On : Fri Jun 2 10:43:14 2017 14 %% Update Count : 83 15 15 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 16 16 … … 29 29 \usepackage{epic,eepic} 30 30 \usepackage{upquote} % switch curled `'" to straight 31 \usepackage{calc} 31 32 \usepackage{xspace} 32 33 \usepackage{varioref} % extended references … … 62 63 % Names used in the document. 63 64 \newcommand{\Version}{\input{../../version}} 64 65 65 \newcommand{\Textbf}[2][red]{{\color{#1}{\textbf{#2}}}} 66 66 \newcommand{\Emph}[2][red]{{\color{#1}\textbf{\emph{#2}}}} … … 97 97 \renewcommand{\chaptermark}[1]{\markboth{\thechapter\quad #1}{\thechapter\quad #1}} 98 98 \renewcommand{\sectionmark}[1]{\markboth{\thesection\quad #1}{\thesection\quad #1}} 99 \renewcommand{\subsectionmark}[1]{\markboth{\thesubsection\quad #1}{\thesubsection\quad #1}} 99 100 \pagenumbering{roman} 100 101 \linenumbers % comment out to turn off line numbering … … 121 122 122 123 This document is a reference manual and rationale for \CFA, a polymorphic extension of the C programming language. 123 It makes frequent reference to the {\c11} standard \cite{C11}, and occasionally compares \CFA to {\CC} \cite{C++}. 124 125 The manual deliberately imitates the ordering of the {\c11} standard (although the section numbering differs). 126 Unfortunately, this means the manual contains more ``forward references'' than usual, making it harder to follow if the reader does not have a copy of the {\c11} standard. 124 It covers low-level syntactic and semantic details of the language to address complex language issues for programmers, and provide language implementers with a precise language description. 125 It makes frequent reference to the \Celeven standard~\cite{C11}, and occasionally compares \CFA to \CC~\cite{C++}. 126 Changes to the syntax and additional features are expected to be included in later revisions. 127 128 The manual deliberately imitates the ordering of the \Celeven standard (although the section numbering differs). 129 Unfortunately, this means the manual contains more ``forward references'' than usual, making it harder to follow if the reader does not have a copy of the \Celeven standard. 127 130 For a simple introduction to \CFA, see the companion document ``An Overview of \CFA'' 128 131 \cite{Ditchfield96:Overview}. … … 139 142 \chapter{Terms, definitions, and symbols} 140 143 141 Terms from the {\c11} standard used in this document have the same meaning as in the {\c11}standard.144 Terms from the \Celeven standard used in this document have the same meaning as in the \Celeven standard. 142 145 143 146 % No ``Conformance'' or ``Environment'' chapters yet. … … 149 152 150 153 \section{Notation} 151 The syntax notation used in this document is the same as in the {\c11} standard, with one exception: ellipsis in the definition of a nonterminal, as in ``\emph{declaration:} \ldots'', indicates that these rules extend a previous definition, which occurs in this document or in the {\c11}standard.154 The syntax notation used in this document is the same as in the \Celeven standard, with one exception: ellipsis in the definition of a nonterminal, as in ``\emph{declaration:} \ldots'', indicates that these rules extend a previous definition, which occurs in this document or in the \Celeven standard. 152 155 153 156 … … 162 165 \begin{rationale} 163 166 Hence, a \CFA program can declare an ©int v© and a ©float v© in the same scope; 164 a {\CC}program can not.167 a \CC program can not. 165 168 \end{rationale} 166 169 … … 285 288 286 289 \begin{rationale} 287 Note that {\c11}does not include conversion from \Index{real type}s to \Index{complex type}s in the usual arithmetic conversions, and \CFA does not include them as safe conversions.290 Note that \Celeven does not include conversion from \Index{real type}s to \Index{complex type}s in the usual arithmetic conversions, and \CFA does not include them as safe conversions. 288 291 \end{rationale} 289 292 … … 370 373 \begin{rationale} 371 374 As in C, there is an implicit conversion from ©void *© to any pointer type. 372 This is clearly dangerous, and {\CC}does not have this implicit conversion.375 This is clearly dangerous, and \CC does not have this implicit conversion. 373 376 \CFA\index{deficiencies!void * conversion} keeps it, in the interest of remaining as pure a superset of C as possible, but discourages it by making it unsafe. 374 377 \end{rationale} … … 608 611 609 612 There are two notable differences between \CFA's overload resolution rules and the rules for 610 {\CC}defined in \cite{C++}.613 \CC defined in \cite{C++}. 611 614 First, the result type of a function plays a role. 612 In {\CC}, a function call must be completely resolved based on the arguments to the call in most circumstances.615 In \CC, a function call must be completely resolved based on the arguments to the call in most circumstances. 613 616 In \CFA, a function call may have several interpretations, each with a different result type, and the interpretations of the containing context choose among them. 614 617 Second, safe conversions are used to choose among interpretations of all sorts of functions; 615 in {\CC}, the ``usual arithmetic conversions'' are a separate set of rules that apply only to the built-in operators.618 in \CC, the ``usual arithmetic conversions'' are a separate set of rules that apply only to the built-in operators. 616 619 \end{rationale} 617 620 … … 637 640 638 641 \begin{rationale} 639 Expression syntax is quoted from the {\c11}standard.642 Expression syntax is quoted from the \Celeven standard. 640 643 The syntax itself defines the precedence and associativity of operators. 641 644 The sections are arranged in decreasing order of precedence, with all operators in a section having the same precedence. … … 665 668 The \Index{valid interpretation} of an \nonterm{identifier} are given by the visible\index{visible} declarations of the identifier. 666 669 667 A \nonterm{constant} or \nonterm{string-literal} has one valid interpretation, which has the type and value defined by {\c11}.670 A \nonterm{constant} or \nonterm{string-literal} has one valid interpretation, which has the type and value defined by \Celeven. 668 671 The predefined integer identifiers ``©1©'' and ``©0©'' have the integer values 1 and 0, respectively. 669 672 The other two predefined ``©0©'' identifiers are bound to polymorphic pointer values that, when specialized\index{specialization} with a data type or function type respectively, produce a null pointer of that type. … … 1113 1116 forall( otype T ) T restrict * ?++( T restrict *restrict volatile * ); 1114 1117 \end{lstlisting} with ©T© inferred to be ©float *©. 1115 This looks odd, because {\c11}contains a constraint that requires restrict-qualified types to be pointer-to-object types, and ©T© is not syntactically a pointer type. \CFA loosens the constraint.1118 This looks odd, because \Celeven contains a constraint that requires restrict-qualified types to be pointer-to-object types, and ©T© is not syntactically a pointer type. \CFA loosens the constraint. 1116 1119 \end{enumerate} 1117 1120 \end{rationale} … … 1477 1480 1478 1481 \begin{rationale} 1479 {\c11}does not include conversions from the \Index{real type}s to \Index{complex type}s in the \Index{usual arithmetic conversion}s. Instead it specifies conversion of the result of binary operations on arguments from mixed type domains. \CFA's predefined operators match that pattern.1482 \Celeven does not include conversions from the \Index{real type}s to \Index{complex type}s in the \Index{usual arithmetic conversion}s. Instead it specifies conversion of the result of binary operations on arguments from mixed type domains. \CFA's predefined operators match that pattern. 1480 1483 \end{rationale} 1481 1484 … … 1506 1509 1507 1510 \begin{rationale} 1508 {\c11}defines most arithmetic operations to apply an \Index{integer promotion} to any argument that belongs to a type that has an \Index{integer conversion rank} less than that of ©int©.1511 \Celeven defines most arithmetic operations to apply an \Index{integer promotion} to any argument that belongs to a type that has an \Index{integer conversion rank} less than that of ©int©. 1509 1512 If ©s© is a ©short int©, ``©s *s©'' does not have type ©short int©; 1510 1513 it is treated as ``©( (int)s ) * ( (int)s )©'', and has type ©int©. \CFA matches that pattern; … … 1519 1522 \end{lstlisting} 1520 1523 Since \CFA does not define a multiplication operator for ©short int©, ©square( s )© is treated as ©square( (int)s )©, and the result has type ©int©. 1521 This is mildly surprising, but it follows the {\c11}operator pattern.1524 This is mildly surprising, but it follows the \Celeven operator pattern. 1522 1525 1523 1526 A more troubling example is … … 1617 1620 ©ptrdiff_t© is an implementation-defined identifier defined in ©<stddef.h>© that is synonymous with a signed integral type that is large enough to hold the difference between two pointers. 1618 1621 It seems reasonable to use it for pointer addition as well. (This is technically a difference between \CFA and C, which only specifies that pointer addition uses an \emph{integral} argument.) Hence it is also used for subscripting, which is defined in terms of pointer addition. 1619 The {\c11}standard uses ©size_t© in several cases where a library function takes an argument that is used as a subscript, but ©size_t© is unsuitable here because it is an unsigned type.1622 The \Celeven standard uses ©size_t© in several cases where a library function takes an argument that is used as a subscript, but ©size_t© is unsuitable here because it is an unsigned type. 1620 1623 \end{rationale} 1621 1624 … … 1930 1933 \end{lstlisting} 1931 1934 The logical expression calls the ©Rational© inequality operator, passing it ©*rp© and the ©Rational 0©, and getting a 1 or 0 as a result. 1932 In contrast, {\CC}would apply a programmer-defined ©Rational©-to-©int© conversion to ©*rp© in the equivalent situation.1935 In contrast, \CC would apply a programmer-defined ©Rational©-to-©int© conversion to ©*rp© in the equivalent situation. 1933 1936 The conversion to ©int© would produce a general integer value, which is unfortunate, and possibly dangerous if the conversion was not written with this situation in mind. 1934 1937 \end{rationale} … … 2626 2629 \begin{itemize} 2627 2630 \item a typedef name may be redefined to denote the same type as it currently does, provided that type is not a variably modified type; 2628 \item tags may be redeclared as specified in section 6.7.2.3 of the {\c11}standard.2631 \item tags may be redeclared as specified in section 6.7.2.3 of the \Celeven standard. 2629 2632 \end{itemize} 2630 2633 \begin{rationale} 2631 This constraint adds the phrase ``with compatible types'' to the {\c11}constraint, to allow overloading.2634 This constraint adds the phrase ``with compatible types'' to the \Celeven constraint, to allow overloading. 2632 2635 \end{rationale} 2633 2636 2634 2637 An identifier declared by a type declaration shall not be redeclared as a parameter in a function definition whose declarator includes an identifier list. 2635 2638 \begin{rationale} 2636 This restriction echos {\c11}'s ban on the redeclaration of typedef names as parameters.2639 This restriction echos \Celeven's ban on the redeclaration of typedef names as parameters. 2637 2640 This avoids an ambiguity between old-style function declarations and new-style function prototypes: 2638 2641 \begin{lstlisting} … … 2661 2664 2662 2665 \semantics 2663 \CFA extends the {\c11} definition of \define{anonymous structure} to include structure specifiers with tags, and extends the {\c11}definition of \define{anonymous union} to include union specifiers with tags.2666 \CFA extends the \Celeven definition of \define{anonymous structure} to include structure specifiers with tags, and extends the \Celeven definition of \define{anonymous union} to include union specifiers with tags. 2664 2667 \begin{rationale} 2665 2668 This extension imitates an extension in the Plan 9 C compiler \cite{Thompson90new}. … … 2854 2857 2855 2858 \begin{rationale} 2856 ©lvalue© provides some of the functionality of {\CC}'s ``©T&©'' ( reference to object of type ©T©) type.2857 Reference types have four uses in {\CC}.2859 ©lvalue© provides some of the functionality of \CC's ``©T&©'' ( reference to object of type ©T©) type. 2860 Reference types have four uses in \CC. 2858 2861 \begin{itemize} 2859 2862 \item … … 2862 2865 \item 2863 2866 A reference can be used to define an alias for a complicated lvalue expression, as a way of getting some of the functionality of the Pascal ©with© statement. 2864 The following {\CC}code gives an example.2867 The following \CC code gives an example. 2865 2868 \begin{lstlisting} 2866 2869 { … … 2874 2877 A reference parameter can be used to allow a function to modify an argument without forcing the caller to pass the address of the argument. 2875 2878 This is most useful for user-defined assignment operators. 2876 In {\CC}, plain assignment is done by a function called ``©operator=©'', and the two expressions2879 In \CC, plain assignment is done by a function called ``©operator=©'', and the two expressions 2877 2880 \begin{lstlisting} 2878 2881 a = b; … … 2887 2890 \item 2888 2891 References to \Index{const-qualified} types can be used instead of value parameters. Given the 2889 {\CC}function call ``©fiddle( a_thing )©'', where the type of ©a_thing© is2892 \CC function call ``©fiddle( a_thing )©'', where the type of ©a_thing© is 2890 2893 ©Thing©, the type of ©fiddle© could be either of 2891 2894 \begin{lstlisting} … … 3216 3219 The Simula class \cite{SIMULA87} is essentially a record type. 3217 3220 Since the only operations on a record are member selection and assignment, which can not be overloaded, there is never any ambiguity as to whether the abstraction or the implementation view is being used. 3218 In {\CC}3221 In \CC 3219 3222 \cite{C++}, operations on class instances include assignment and ``©&©'', which can be overloaded. 3220 3223 A ``scope resolution'' operator can be used inside the class to specify whether the abstract or implementation version of the operation should be used. … … 3548 3551 \subsection{Predefined macro names} 3549 3552 3550 The implementation shall define the macro names ©__LINE__©, ©__FILE__©, ©__DATE__©, and ©__TIME__©, as in the {\c11}standard.3553 The implementation shall define the macro names ©__LINE__©, ©__FILE__©, ©__DATE__©, and ©__TIME__©, as in the \Celeven standard. 3551 3554 It shall not define the macro name ©__STDC__©. 3552 3555 … … 3634 3637 \subsection{Pointer and array types} 3635 3638 3636 Array types can barely be said to exist in {\c11}, since in most cases an array name is treated as a constant pointer to the first element of the array, and the subscript expression ``©a[i]©'' is equivalent to the dereferencing expression ``©(*( a+( i )))©''.3639 Array types can barely be said to exist in \Celeven, since in most cases an array name is treated as a constant pointer to the first element of the array, and the subscript expression ``©a[i]©'' is equivalent to the dereferencing expression ``©(*( a+( i )))©''. 3637 3640 Technically, pointer arithmetic and pointer comparisons other than ``©==©'' and ``©!=©'' are only defined for pointers to array elements, but the type system does not enforce those restrictions. 3638 3641 Consequently, there is no need for a separate ``array type'' specification. … … 3712 3715 Different operators often have related meanings; 3713 3716 for instance, in C, ``©+©'', ``©+=©'', and the two versions of ``©++©'' perform variations of addition. 3714 Languages like {\CC}and Ada allow programmers to define operators for new types, but do not require that these relationships be preserved, or even that all of the operators be implemented.3717 Languages like \CC and Ada allow programmers to define operators for new types, but do not require that these relationships be preserved, or even that all of the operators be implemented. 3715 3718 Completeness and consistency is left to the good taste and discretion of the programmer. 3716 3719 It is possible to encourage these attributes by providing generic operator functions, or member functions of abstract classes, that are defined in terms of other, related operators. … … 3823 3826 \end{theindex} 3824 3827 3828 3825 3829 \end{document} 3826 3830 -
doc/user/user.tex
r2164637 rf94ca7e 11 11 %% Created On : Wed Apr 6 14:53:29 2016 12 12 %% Last Modified By : Peter A. Buhr 13 %% Last Modified On : Tue May 30 11:45:46201714 %% Update Count : 2 09813 %% Last Modified On : Fri Jun 2 10:07:51 2017 14 %% Update Count : 2128 15 15 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 16 16 … … 185 185 While the \CFA I/O looks similar to the \Index*[C++]{\CC{}} output style, there are important differences, such as automatic spacing between variables as in \Index*{Python} (see~\VRef{s:IOLibrary}). 186 186 187 This document is a user manual for the \CFA programming language, targeted at \CFA programmers. 187 This document is a programmer reference-manual for the \CFA programming language. 188 The manual covers the core features of the language and runtime-system, with simple examples illustrating syntax and semantics of each feature. 189 The manual does not teach programming, i.e., how to combine the new constructs to build complex programs. 190 A reader should already have an intermediate knowledge of control flow, data structures, and concurrency issues to understand the ideas presented as well as some experience programming in C/\CC. 188 191 Implementers may refer to the \CFA Programming Language Specification for details about the language syntax and semantics. 189 In its current state, this document covers the intended core features of the language.190 192 Changes to the syntax and additional features are expected to be included in later revisions. 191 193 … … 5242 5244 \begin{description} 5243 5245 \item[fill] 5244 after allocation the storage is or is notfilled with a specified character.5246 after allocation the storage is filled with a specified character. 5245 5247 \item[resize] 5246 5248 an existing allocation is decreased or increased in size. 5247 5249 In either case, new storage may or may not be allocated and, if there is a new allocation, as much data from the existing allocation is copied. 5248 For an increase in storage size, new storage after the copied data may or may notbe filled.5250 For an increase in storage size, new storage after the copied data may be filled. 5249 5251 \item[alignment] 5250 5252 an allocation starts on a specified memory boundary, e.g., an address multiple of 64 or 128 for cache-line purposes. 5251 5253 \item[array] 5252 5254 the allocation size is scaled to the specified number of array elements. 5253 An array may or notbe filled, resized, or aligned.5255 An array may be filled, resized, or aligned. 5254 5256 \end{description} 5255 5256 The following table show the allocation routines supporting different combinations of storage-management capabilities: 5257 The table shows allocation routines supporting different combinations of storage-management capabilities: 5257 5258 \begin{center} 5258 \begin{tabular}{@{} r|l|l|l|l@{}}5259 & fill& resize & alignment & array \\5259 \begin{tabular}{@{}lr|l|l|l|l@{}} 5260 & & \multicolumn{1}{c|}{fill} & resize & alignment & array \\ 5260 5261 \hline 5261 ©malloc© & no/yes & no/yes& no & no \\5262 ©amalloc© & no/copy data/yes & no/yes& no & yes \\5263 ©calloc© & yes (0 only) & no & no & yes\\5264 ©realloc© & no/copy data & yes & no& no \\5265 ©memalign© & no/yes& no & yes & no \\5266 ©amemalign© & no/yes & no & yes & yes\\5267 ©align_alloc© & no & no & yes & no\\5268 ©posix_memalign© & no & no & yes & no\\5262 C & ©malloc© & no & no & no & no \\ 5263 & ©calloc© & yes (0 only) & no & no & yes \\ 5264 & ©realloc© & no/copy & yes & no & no \\ 5265 & ©memalign© & no & no & yes & no \\ 5266 & ©posix_memalign© & no & no & yes & no \\ 5267 C11 & ©aligned_alloc© & no & no & yes & no \\ 5268 \CFA & ©alloc© & no/copy/yes & no/yes & no & yes \\ 5269 & ©align_alloc© & no/yes & no & yes & yes \\ 5269 5270 \end{tabular} 5270 5271 \end{center} 5271 % When ©amalloc© resizes and fills, the space after the copied data from the source is set to the fill character.5272 5272 It is impossible to resize with alignment because the underlying ©realloc© allocates storage if more space is needed, and it does not honour alignment from the original allocation. 5273 5273 5274 5274 \leavevmode 5275 5275 \begin{cfa}[aboveskip=0pt,belowskip=0pt] 5276 // allocation, non-array types 5277 forall( dtype T | sized(T) ) T * malloc( void );§\indexc{malloc}§ 5278 forall( dtype T | sized(T) ) T * malloc( char fill ); 5279 5280 // allocation, array types 5281 forall( dtype T | sized(T) ) T * calloc( size_t dim );§\indexc{cmalloc}§ 5282 forall( dtype T | sized(T) ) T * amalloc( size_t dim );§\indexc{amalloc}§ // alternate name for calloc 5283 forall( dtype T | sized(T) ) T * amalloc( size_t dim, char fill ); 5284 5285 // resize, non-array types 5286 forall( dtype T | sized(T) ) T * realloc( T * ptr, size_t size );§\indexc{realloc}§ 5287 forall( dtype T | sized(T) ) T * realloc( T * ptr, size_t size, char fill ); 5288 forall( dtype T | sized(T) ) T * malloc( T * ptr, size_t size ); // alternate name for realloc 5289 forall( dtype T | sized(T) ) T * malloc( T * ptr, size_t size, char fill ); 5290 5291 // resize, array types 5292 forall( dtype T | sized(T) ) T * amalloc( T * ptr, size_t dim ); 5293 forall( dtype T | sized(T) ) T * amalloc( T * ptr, size_t dim, char fill ); 5294 5295 // alignment, non-array types 5296 forall( dtype T | sized(T) ) T * memalign( size_t alignment );§\indexc{memalign}§ 5297 forall( dtype T | sized(T) ) T * memalign( size_t alignment, char fill ); 5298 forall( dtype T | sized(T) ) T * aligned_alloc( size_t alignment );§\indexc{aligned_alloc}§ 5299 forall( dtype T | sized(T) ) int posix_memalign( T ** ptr, size_t alignment );§\indexc{posix_memalign}§ 5300 5301 // alignment, array types 5302 forall( dtype T | sized(T) ) T * amemalign( size_t alignment, size_t dim );§\indexc{amemalign}§ 5303 forall( dtype T | sized(T) ) T * amemalign( size_t alignment, size_t dim, char fill ); 5304 5305 // data, non-array types 5276 // C unsafe allocation 5277 extern "C" { 5278 void * mallac( size_t size );§\indexc{memset}§ 5279 void * calloc( size_t dim, size_t size );§\indexc{calloc}§ 5280 void * realloc( void * ptr, size_t size );§\indexc{realloc}§ 5281 void * memalign( size_t align, size_t size );§\indexc{memalign}§ 5282 int posix_memalign( void ** ptr, size_t align, size_t size );§\indexc{posix_memalign}§ 5283 } 5284 5285 // §\CFA§ safe equivalents, i.e., implicit size specification 5286 forall( dtype T | sized(T) ) T * malloc( void ); 5287 forall( dtype T | sized(T) ) T * calloc( size_t dim ); 5288 forall( dtype T | sized(T) ) T * realloc( T * ptr, size_t size ); 5289 forall( dtype T | sized(T) ) T * memalign( size_t align ); 5290 forall( dtype T | sized(T) ) T * aligned_alloc( size_t align ); 5291 forall( dtype T | sized(T) ) int posix_memalign( T ** ptr, size_t align ); 5292 5293 // §\CFA§ safe general allocation, fill, resize, array 5294 forall( dtype T | sized(T) ) T * alloc( void );§\indexc{alloc}§ 5295 forall( dtype T | sized(T) ) T * alloc( char fill ); 5296 forall( dtype T | sized(T) ) T * alloc( size_t dim ); 5297 forall( dtype T | sized(T) ) T * alloc( size_t dim, char fill ); 5298 forall( dtype T | sized(T) ) T * alloc( T ptr[], size_t dim ); 5299 forall( dtype T | sized(T) ) T * alloc( T ptr[], size_t dim, char fill ); 5300 5301 // §\CFA§ safe general allocation, align, fill, array 5302 forall( dtype T | sized(T) ) T * align_alloc( size_t align ); 5303 forall( dtype T | sized(T) ) T * align_alloc( size_t align, char fill ); 5304 forall( dtype T | sized(T) ) T * align_alloc( size_t align, size_t dim ); 5305 forall( dtype T | sized(T) ) T * align_alloc( size_t align, size_t dim, char fill ); 5306 5307 // C unsafe initialization/copy 5308 extern "C" { 5309 void * memset( void * dest, int c, size_t size ); 5310 void * memcpy( void * dest, const void * src, size_t size ); 5311 } 5312 5313 // §\CFA§ safe initialization/copy 5306 5314 forall( dtype T | sized(T) ) T * memset( T * dest, char c );§\indexc{memset}§ 5307 5315 forall( dtype T | sized(T) ) T * memcpy( T * dest, const T * src );§\indexc{memcpy}§ 5308 5316 5309 // data, array types5310 forall( dtype T | sized(T) ) T * amemset( T * dest, size_t dim, char c );§\indexc{amemset}§5311 forall( dtype T | sized(T) ) T * amemcpy( T * dest, const T * src, size_t dim );§\indexc{amemcpy}§5312 5313 // allocation/deallocation and constructor/destructor5314 forall( dtype T , ttype Params | sized(T) | { void ?{}(T *, Params); } ) T * new( Params p );§\indexc{new}§5317 // §\CFA§ safe initialization/copy array 5318 forall( dtype T | sized(T) ) T * memset( T dest[], size_t dim, char c ); 5319 forall( dtype T | sized(T) ) T * memcpy( T dest[], const T src[], size_t dim ); 5320 5321 // §\CFA§ allocation/deallocation and constructor/destructor 5322 forall( dtype T | sized(T), ttype Params | { void ?{}( T *, Params ); } ) T * new( Params p );§\indexc{new}§ 5315 5323 forall( dtype T | { void ^?{}( T * ); } ) void delete( T * ptr );§\indexc{delete}§ 5316 forall( dtype T, ttype Params | { void ^?{}( T * ); void delete(Params); } ) void delete( T * ptr, Params rest ); 5324 forall( dtype T, ttype Params | { void ^?{}( T * ); void delete( Params ); } ) 5325 void delete( T * ptr, Params rest ); 5326 5327 // §\CFA§ allocation/deallocation and constructor/destructor, array 5328 forall( dtype T | sized(T), ttype Params | { void ?{}( T *, Params ); } ) T * anew( size_t dim, Params p );§\indexc{anew}§ 5329 forall( dtype T | sized(T) | { void ^?{}( T * ); } ) void adelete( size_t dim, T arr[] );§\indexc{adelete}§ 5330 forall( dtype T | sized(T) | { void ^?{}( T * ); }, ttype Params | { void adelete( Params ); } ) 5331 void adelete( size_t dim, T arr[], Params rest ); 5317 5332 \end{cfa} 5318 5333 -
doc/working/exception/impl/except.c
r2164637 rf94ca7e 4 4 5 5 #include "lsda.h" 6 7 // This macro should be the only thing that needs to change across machines. 8 // struct _Unwind_Context * -> _Unwind_Reason_Code(*)() 9 #define MATCHER_FROM_CONTEXT(ptr_to_context) \ 10 (*(_Unwind_Reason_Code(**)())(_Unwind_GetCFA(ptr_to_context) + 8)) 11 6 12 7 13 //Global which defines the current exception … … 17 23 struct _Unwind_Exception* unwind_exception, struct _Unwind_Context* context) 18 24 { 25 printf("CFA: 0x%lx\n", _Unwind_GetCFA(context)); 26 19 27 //DEBUG 20 28 printf("Personality function (%d, %x, %llu, %p, %p):", version, actions, exceptionClass, unwind_exception, context); … … 111 119 112 120 //Get a function pointer from the relative offset and call it 113 _Unwind_Reason_Code (*matcher)() = (_Unwind_Reason_Code (*)())lsd_info.LPStart + imatcher; 121 // _Unwind_Reason_Code (*matcher)() = (_Unwind_Reason_Code (*)())lsd_info.LPStart + imatcher; 122 123 _Unwind_Reason_Code (*matcher)() = 124 MATCHER_FROM_CONTEXT(context); 114 125 _Unwind_Reason_Code ret = matcher(); 115 126 -
doc/working/exception/impl/main.c
r2164637 rf94ca7e 1 1 #include <stdio.h> 2 2 #include "except.h" 3 4 // Requires -fexceptions to work. 3 5 4 6 #define EXCEPTION 2 … … 26 28 extern int this_exception; 27 29 _Unwind_Reason_Code foo_try_match() { 28 return this_exception == 3 ? _URC_HANDLER_FOUND : _URC_CONTINUE_UNWIND; 30 printf(" (foo_try_match called)"); 31 return this_exception == EXCEPTION ? _URC_HANDLER_FOUND : _URC_CONTINUE_UNWIND; 29 32 } 30 33 … … 34 37 //for details 35 38 __attribute__((noinline)) 36 void try( void (*try_block)(), void (*catch_block)() ) 39 void try( void (*try_block)(), void (*catch_block)(), 40 _Unwind_Reason_Code (*match_block)() ) 37 41 { 42 volatile int xy = 0; 43 printf("%p %p %p %p\n", &try_block, &catch_block, &match_block, &xy); 44 38 45 //Setup statments 39 46 //These 2 statments won't actually result in any code, … … 95 102 " .uleb128 .CATCH-try\n" //Hanlder landing pad adress (relative to start of function) 96 103 " .uleb128 1\n" //Action code, gcc seems to use always 0 97 //Beyond this point we don't match gcc data'98 " .uleb128 foo_try_match-try\n" //Handler routine to check if the exception is matched99 104 ".LLSDACSECFA2:\n" //BODY end 100 105 " .text\n" //TABLE footer … … 122 127 123 128 //Actual call to the try block 124 try( foo_try_block, foo_catch_block );129 try( foo_try_block, foo_catch_block, foo_try_match ); 125 130 126 131 printf( "Foo exited normally\n" ); 127 132 } 128 133 134 // Not in main.cfa 135 void fy() { 136 // Currently not destroyed if the exception is caught in fee. 137 raii_t a = { "Fy dtor" }; 138 139 void fy_try_block() { 140 raii_t b = { "Fy try dtor" }; 141 142 throw( 3 ); 143 } 144 145 void fy_catch_block() { 146 printf("Fy caught exception\n"); 147 } 148 149 _Unwind_Reason_Code fy_match_block() { 150 return this_exception == 2 ? _URC_HANDLER_FOUND : _URC_CONTINUE_UNWIND; 151 } 152 153 try(fy_try_block, fy_catch_block, fy_match_block); 154 155 printf( "Fy exited normally\n" ); 156 } 157 158 void fee() { 159 raii_t a = { "Fee dtor" }; 160 161 void fee_try_block() { 162 raii_t b = { "Fee try dtor" }; 163 164 fy(); 165 166 printf("fy returned\n"); 167 } 168 169 void fee_catch_block() { 170 printf("Fee caught exception\n"); 171 } 172 173 _Unwind_Reason_Code fee_match_block() { 174 return this_exception == 3 ? _URC_HANDLER_FOUND : _URC_CONTINUE_UNWIND; 175 } 176 177 try(fee_try_block, fee_catch_block, fee_match_block); 178 179 printf( "Fee exited normally\n" ); 180 } 181 // End not in main.cfa 182 129 183 int main() { 130 184 raii_t a = { "Main dtor" }; 131 185 132 for (unsigned int i = 0 ; i < 100000000 ; ++i) foo(); 186 //for (unsigned int i = 0 ; i < 100000000 ; ++i) 187 foo(); 188 fee(); 133 189 134 190 printf("End of program reached\n"); -
doc/working/exception/reference.c
r2164637 rf94ca7e 114 114 // __builtin_eh_return_data_regno(^) ^=[0..3]? gives index. 115 115 116 // Locally we also seem to have: 117 _Unwind_Word _Unwind_GetCFA (struct _Unwind_Context *); 116 118 117 119 // GCC (Dwarf2 ?) Frame Layout Macros 118 // https://gcc.gnu.org/onlinedocs/gccint/Frame-Layout.html 120 // See: https://gcc.gnu.org/onlinedocs/gccint/Frame-Layout.html 121 // Include from: ??? 119 122 120 123 FIRST_PARAM_OFFSET(fundecl)
Note:
See TracChangeset
for help on using the changeset viewer.