Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • doc/user/user.tex

    r421a287 r55f5c59  
    1111%% Created On       : Wed Apr  6 14:53:29 2016
    1212%% Last Modified By : Peter A. Buhr
    13 %% Last Modified On : Fri Jun  2 10:07:51 2017
    14 %% Update Count     : 2128
     13%% Last Modified On : Tue May 30 11:42:47 2017
     14%% Update Count     : 2097
    1515%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    1616
     
    185185While 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}).
    186186
    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.
     187This document is a user manual for the \CFA programming language, targeted at \CFA programmers.
    191188Implementers may refer to the \CFA Programming Language Specification for details about the language syntax and semantics.
     189In its current state, this document covers the intended core features of the language.
    192190Changes to the syntax and additional features are expected to be included in later revisions.
    193191
     
    51665164\Celeven prescribes the following standard header-files~\cite[\S~7.1.2]{C11} and \CFA adds to this list:
    51675165\begin{quote2}
    5168 \lstset{deletekeywords={float}}
     5166\lstset{deletekeywords={float},deletekeywords=[2]{signal}}
    51695167\begin{tabular}{@{}llll|l@{}}
    51705168\multicolumn{4}{c|}{C11} & \multicolumn{1}{c}{\CFA}             \\
     
    52445242\begin{description}
    52455243\item[fill]
    5246 after allocation the storage is filled with a specified character.
     5244after allocation the storage is or is not filled with a specified character.
    52475245\item[resize]
    52485246an existing allocation is decreased or increased in size.
    52495247In 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.
    5250 For an increase in storage size, new storage after the copied data may be filled.
     5248For an increase in storage size, new storage after the copied data may or may not be filled.
    52515249\item[alignment]
    52525250an allocation starts on a specified memory boundary, e.g., an address multiple of 64 or 128 for cache-line purposes.
    52535251\item[array]
    52545252the allocation size is scaled to the specified number of array elements.
    5255 An array may be filled, resized, or aligned.
     5253An array may or not be filled, resized, or aligned.
    52565254\end{description}
    5257 The table shows allocation routines supporting different combinations of storage-management capabilities:
     5255
     5256The following table show the allocation routines supporting different combinations of storage-management capabilities:
    52585257\begin{center}
    5259 \begin{tabular}{@{}lr|l|l|l|l@{}}
    5260                 &                                       & \multicolumn{1}{c|}{fill}     & resize        & alignment     & array \\
     5258\begin{tabular}{@{}r|l|l|l|l@{}}
     5259                                        & fill                          & resize        & alignment     & array \\
    52615260\hline
    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   \\
     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    \\
    52705269\end{tabular}
    52715270\end{center}
     5271% When ©amalloc© resizes and fills, the space after the copied data from the source is set to the fill character.
    52725272It 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.
    52735273
    52745274\leavevmode
    52755275\begin{cfa}[aboveskip=0pt,belowskip=0pt]
    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
     5276// allocation, non-array types
     5277forall( dtype T | sized(T) ) T * malloc( void );§\indexc{malloc}§
     5278forall( dtype T | sized(T) ) T * malloc( char fill );
     5279
     5280// allocation, array types
     5281forall( dtype T | sized(T) ) T * calloc( size_t dim );§\indexc{cmalloc}§
     5282forall( dtype T | sized(T) ) T * amalloc( size_t dim );§\indexc{amalloc}§  // alternate name for calloc
     5283forall( dtype T | sized(T) ) T * amalloc( size_t dim, char fill );
     5284
     5285// resize, non-array types
     5286forall( dtype T | sized(T) ) T * realloc( T * ptr, size_t size );§\indexc{realloc}§
     5287forall( dtype T | sized(T) ) T * realloc( T * ptr, size_t size, char fill );
     5288forall( dtype T | sized(T) ) T * malloc( T * ptr, size_t size );  // alternate name for realloc
     5289forall( dtype T | sized(T) ) T * malloc( T * ptr, size_t size, char fill );
     5290
     5291// resize, array types
     5292forall( dtype T | sized(T) ) T * amalloc( T * ptr, size_t dim );
     5293forall( dtype T | sized(T) ) T * amalloc( T * ptr, size_t dim, char fill );
     5294
     5295// alignment, non-array types
     5296forall( dtype T | sized(T) ) T * memalign( size_t alignment );§\indexc{memalign}§
     5297forall( dtype T | sized(T) ) T * memalign( size_t alignment, char fill );
     5298forall( dtype T | sized(T) ) T * aligned_alloc( size_t alignment );§\indexc{aligned_alloc}§
     5299forall( dtype T | sized(T) ) int posix_memalign( T ** ptr, size_t alignment );§\indexc{posix_memalign}§
     5300
     5301// alignment, array types
     5302forall( dtype T | sized(T) ) T * amemalign( size_t alignment, size_t dim );§\indexc{amemalign}§
     5303forall( dtype T | sized(T) ) T * amemalign( size_t alignment, size_t dim, char fill );
     5304
     5305// data, non-array types
    53145306forall( dtype T | sized(T) ) T * memset( T * dest, char c );§\indexc{memset}§
    53155307forall( dtype T | sized(T) ) T * memcpy( T * dest, const T * src );§\indexc{memcpy}§
    53165308
    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}§
     5309// data, array types
     5310forall( dtype T | sized(T) ) T * amemset( T * dest, size_t dim, char c );§\indexc{amemset}§
     5311forall( dtype T | sized(T) ) T * amemcpy( T * dest, const T * src, size_t dim );§\indexc{amemcpy}§
     5312
     5313// allocation/deallocation and constructor/destructor
     5314forall( dtype T, ttype Params | sized(T) | { void ?{}(T *, Params); } ) T * new( Params p );§\indexc{new}§
    53235315forall( dtype T | { void ^?{}( T * ); } ) void delete( T * ptr );§\indexc{delete}§
    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 );
     5316forall( dtype T, ttype Params | { void ^?{}( T * ); void delete(Params); } ) void delete( T * ptr, Params rest );
    53325317\end{cfa}
    53335318
Note: See TracChangeset for help on using the changeset viewer.