Changeset dafbde8
- Timestamp:
- Jan 20, 2021, 4:49:40 PM (5 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- 454f478
- Parents:
- 92bfda0 (diff), fd54fef (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. - Files:
-
- 2 added
- 141 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/bibliography/pl.bib
r92bfda0 rdafbde8 688 688 title = {Asynchronous Exception Propagation in Blocked Tasks}, 689 689 booktitle = {4th International Workshop on Exception Handling (WEH.08)}, 690 o rganization= {16th International Symposium on the Foundations of Software Engineering (FSE 16)},690 optorganization= {16th International Symposium on the Foundations of Software Engineering (FSE 16)}, 691 691 address = {Atlanta, U.S.A}, 692 692 month = nov, … … 7246 7246 7247 7247 @inproceedings{Edelson92, 7248 keywords = {persistence, pointers},7248 keywords = {persistence, smart pointers}, 7249 7249 contributer = {pabuhr@plg}, 7250 7250 author = {Daniel R. Edelson}, … … 7256 7256 year = 1992, 7257 7257 pages = {1-19}, 7258 } 7259 7260 @incollection{smartpointers, 7261 keywords = {smart pointers}, 7262 contributer = {pabuhr@plg}, 7263 author = {Andrei Alexandrescu}, 7264 title = {Smart Pointers}, 7265 booktitle = {Modern C++ Design: Generic Programming and Design Patterns Applied}, 7266 publisher = {Addison-Wesley}, 7267 year = 2001, 7268 chapter = 7, 7269 optpages = {?-?}, 7258 7270 } 7259 7271 … … 8245 8257 } 8246 8258 8259 @misc{vistorpattern, 8260 keywords = {visitor pattern}, 8261 contributer = {pabuhr@plg}, 8262 key = {vistor pattern}, 8263 title = {vistor pattern}, 8264 year = 2020, 8265 note = {WikipediA}, 8266 howpublished= {\href{https://en.wikipedia.org/wiki/Visitor\_pattern} 8267 {https://\-en.wikipedia.org/\-wiki/\-Visitor\_pattern}}, 8268 } 8269 8247 8270 % W 8248 8271 -
doc/theses/fangren_yu_COOP_F20/Report.tex
r92bfda0 rdafbde8 76 76 \renewcommand{\subsectionmark}[1]{\markboth{\thesubsection\quad #1}{\thesubsection\quad #1}} 77 77 \pagenumbering{roman} 78 \linenumbers % comment out to turn off line numbering78 %\linenumbers % comment out to turn off line numbering 79 79 80 80 \maketitle 81 81 \pdfbookmark[1]{Contents}{section} 82 \tableofcontents 83 84 \clearpage 82 85 83 \thispagestyle{plain} 86 84 \pagenumbering{arabic} 87 85 88 86 \begin{abstract} 89 90 \CFA is an evolutionary extension to the C programming language, featuring a parametric type system, and is currently under active development. The reference compiler for \CFA language, @cfa-cc@, has some of its major components dated back to early 2000s, and is based on inefficient data structures and algorithms. Some improvements targeting the expression resolution algorithm, suggested by a recent prototype experiment on a simplified model, are implemented in @cfa-cc@ to support the full \CFA language. These optimizations speed up the compiler significantly by a factor of 20 across the existing \CFA codebase, bringing the compilation time of a mid-sized \CFA source file down to 10-second level. A few cases derived from realistic code examples that causes trouble to the compiler are analyzed in detail, with proposed solutions. This step of \CFA project development is critical to its eventual goal to be used alongside C for large software systems. 91 87 \CFA is an evolutionary, non-object-oriented extension of the C programming language, featuring a parametric type-system, and is currently under active development. The reference compiler for the \CFA language, @cfa-cc@, has some of its major components dated back to the early 2000s, which are based on inefficient data structures and algorithms. This report introduces improvements targeting the expression resolution algorithm, suggested by a recent prototype experiment on a simplified model, which are implemented in @cfa-cc@ to support the full \CFA language. These optimizations speed up the compiler by a factor of 20 across the existing \CFA codebase, bringing the compilation time of a mid-sized \CFA source file down to the 10-second level. A few problem cases derived from realistic code examples are analyzed in detail, with proposed solutions. This work is a critical step in the \CFA project development to achieve its eventual goal of being used alongside C for large software systems. 92 88 \end{abstract} 93 89 90 \clearpage 91 \section*{Acknowledgements} 92 \begin{sloppypar} 93 I would like to thank everyone in the \CFA team for their contribution towards this project. Programming language design and development is a tough subject and requires a lot of teamwork. Without the collaborative efforts from the team, this project could not have been a success. Specifically, I would like to thank Andrew Beach for introducing me to the \CFA codebase, Thierry Delisle for maintaining the test and build automation framework, Michael Brooks for providing example programs of various experimental language and type system features, and most importantly, Professor Martin Karsten for recommending me to the \CFA team, and my supervisor, Professor Peter Buhr for encouraging me to explore deeply into intricate compiler algorithms. Finally, I gratefully acknowledge the help from Aaron Moss, former graduate from the team and the author of the precedent thesis work, to participate in the \CFA team's virtual conferences and email correspondence, and provide many critical arguments and suggestions. 2020 had been an unusually challenging year for everyone and we managed to keep a steady pace. 94 \end{sloppypar} 95 96 \clearpage 97 \tableofcontents 98 99 \clearpage 94 100 \section{Introduction} 95 101 96 \CFA language, developed by the Programming Language Group at University of Waterloo, has a long history, with the first proof-of-concept compiler built in 2003 by Richard Bilson~\cite{Bilson03}. Many new features are added to the language over time, but the core of \CFA, parametric functions introduced by the @forall@ clause (hence the name of the language), with the type system supporting parametric overloading, remains mostly unchanged.97 98 The current \CFA reference compiler @cfa-cc@ still includes many parts taken directly from the original Bilson's implementation, and serves as a starting point for the enhancement work to the type system. Unfortunately, it does not provide the efficiency required for the language to be used practically: a \CFA source file of approximately 1000 lines of code can take a few minutes to compile. The cause of the problem is that the old compiler used inefficient data structures and algorithms for expression resolution, which involved a lot of copying and redundant work.99 100 This paper presents a series of optimizations to the performance-critical parts of the resolver, with a major rework of the data structure used by the compiler, using a functional programming approach to reduce memory complexity. Subsequent improvements are mostly suggested by running the compiler builds with a performance profiler against the \CFA standard library sourcecode and a test suite to find the most underperforming components in the compiler algorithm.101 102 The \CFA team endorses a pragmatic philosophy in work that mostly focuses on practical implications of language design and implementation, rather than the theoretical limits. In particular, the compiler is designed to work on production \CFA code efficiently and keep type safety, while sometimes making compromises to expressiveness in extreme corner cases. However, when these corner cases do appear in actual usage, they need to be thoroughly investigated. Analysis presented in this paper, therefore, are conducted on a case-by-case basis. Some of them eventually point to certain weaknesses in the language design and solutions areproposed based on experimental results.103 104 \section{ Completed work}102 \CFA language, developed by the Programming Language Group at the University of Waterloo, has a long history, with the initial language design in 1992 by Glen Ditchfield~\cite{Ditchfield92} and the first proof-of-concept compiler built in 2003 by Richard Bilson~\cite{Bilson03}. Many new features have been added to the language over time, but the core of \CFA's type-system --- parametric functions introduced by the @forall@ clause (hence the name of the language) providing parametric overloading --- remains mostly unchanged. 103 104 The current \CFA reference compiler, @cfa-cc@, is designed using the visitor pattern~\cite{vistorpattern} over an abstract syntax tree (AST), where multiple passes over the AST modify it for subsequent passes. @cfa-cc@ still includes many parts taken directly from the original Bilson implementation, which served as the starting point for this enhancement work to the type system. Unfortunately, the prior implementation did not provide the efficiency required for the language to be practical: a \CFA source file of approximately 1000 lines of code can take a multiple minutes to compile. The cause of the problem is that the old compiler used inefficient data structures and algorithms for expression resolution, which involved significant copying and redundant work. 105 106 This report presents a series of optimizations to the performance-critical parts of the resolver, with a major rework of the compiler data-structures using a functional-programming approach to reduce memory complexity. The improvements were suggested by running the compiler builds with a performance profiler against the \CFA standard-library source-code and a test suite to find the most underperforming components in the compiler algorithm. 107 108 The \CFA team endorses a pragmatic philosophy that focuses on practical implications of language design and implementation rather than theoretical limits. In particular, the compiler is designed to be expressive with respect to code reuse while maintaining type safety, but compromise theoretical soundness in extreme corner cases. However, when these corner cases do appear in actual usage, they need to be thoroughly investigated. A case-by-case analysis is presented for several of these corner cases, some of which point to certain weaknesses in the language design with solutions proposed based on experimental results. 109 110 \section{AST restructuring} 105 111 106 112 \subsection{Memory model with sharing} 107 113 108 A major rework of the abstract syntax tree (AST) data structure in the compiler is completed as the first step of the project. The majority of work were documented in the reference manual of the compiler~\cite{cfa-cc}. To summarize: 109 \begin{itemize} 110 \item 111 AST nodes (and therefore subtrees) can be shared without copying when reused. 112 \item 113 Modifications apply the functional programming principle, making copies for local changes without affecting the original data shared by other owners. In-place mutations are permitted as a special case when sharing does not happen. The logic is implemented by reference counting. 114 \item 115 Memory allocation and freeing are performed automatically using smart pointers. 116 \end{itemize} 117 The resolver algorithm designed for overload resolution naturally introduces a significant amount of reused intermediate representations, especially in the following two places: 118 \begin{itemize} 119 \item 120 Function overload candidates are computed by combining the argument candidates bottom-up, with many of them being a common term. For example, if $n$ overloads of a function @f@ all take an integer for the first parameter but different types for the second (@f( int, int )@, @f( int, double )@, etc.) the first term is reused $n$ times for each of the generated candidate expressions. This effect is particularly bad for deep expression trees. 121 \item 122 In the unification algorithm and candidate elimination step, actual types are obtained by substituting the type parameters by their bindings. Let $n$ be the complexity (\ie number of nodes in representation) of the original type, $m$ be the complexity of bound type for parameters, and $k$ be the number of occurrences of type parameters in the original type. If everything needs to be deep-copied, the substitution step takes $O(n+mk)$ time and memory, while using shared nodes it is reduced to $O(n)$ time and $O(k)$ memory. 123 \end{itemize} 124 One of the worst examples for the old compiler is a long chain of I/O operations 125 \begin{cfa} 126 sout | 1 | 2 | 3 | 4 | ... 127 \end{cfa} 128 The pipe operator is overloaded by \CFA I/O library for every primitive type in C language, as well as I/O manipulators defined by the library. In total there are around 50 overloads for the output stream operation. On resolving the $n$-th pipe operator in the sequence, the first term, which is the result of sub-expression containing $n-1$ pipe operators, is reused to resolve every overload. Therefore at least $O(n^2)$ copies of expression nodes are made during resolution, not even counting type unification cost; combined with two large factors from number of overloads of pipe operators, and that the ``output stream type'' in \CFA is a trait with 27 assertions (which adds to complexity of the pipe operator's type) this makes compiling a long output sequence extremely slow. In new AST representation only $O(n)$ copies are required and type of pipe operator is not copied at all. 129 130 Reduction in space complexity is especially important, as preliminary profiling result on the old compiler build shows that over half of time spent in expression resolution are on memory allocations. 131 114 A major rework of the AST data-structure in the compiler was completed as the first step of the project. The majority of this work is documented in my prior report documenting the compiler reference-manual~\cite{cfa-cc}. To summarize: 115 \begin{itemize} 116 \item 117 AST nodes (and therefore subtrees) can be shared without copying. 118 \item 119 Modifications are performed using functional-programming principles, making copies for local changes without affecting the original data shared by other owners. In-place mutations are permitted as a special case when there is no sharing. The logic is implemented by reference counting. 120 \item 121 Memory allocation and freeing are performed automatically using smart pointers~\cite{smartpointers}. 122 \end{itemize} 123 124 The resolver algorithm, designed for overload resolution, uses a significant amount of reused, and hence copying, for the intermediate representations, especially in the following two places: 125 \begin{itemize} 126 \item 127 Function overload candidates are computed by combining the argument candidates bottom-up, with many being a common term. For example, if $n$ overloads of a function @f@ all take an integer for the first parameter but different types for the second, \eg @f( int, int )@, @f( int, double )@, etc., the first term is copied $n$ times for each of the generated candidate expressions. This copying is particularly bad for deep expression trees. 128 \item 129 In the unification algorithm and candidate elimination step, actual types are obtained by substituting the type parameters by their bindings. Let $n$ be the complexity (\ie number of nodes in representation) of the original type, $m$ be the complexity of the bound type for parameters, and $k$ be the number of occurrences of type parameters in the original type. If every substitution needs to be deep-copied, these copy step takes $O(n+mk)$ time and memory, while using shared nodes it is reduced to $O(n)$ time and $O(k)$ memory. 130 \end{itemize} 131 One of the worst examples for the old compiler is a long chain of I/O operations: 132 \begin{cfa} 133 sout | 1 | 2 | 3 | 4 | ...; // print integer constants 134 \end{cfa} 135 The pipe operator is overloaded by the \CFA I/O library for every primitive type in the C language, as well as I/O manipulators defined by the library. In total, there are around 50 overloads for the output stream operation. On resolving the $n$-th pipe operator in the sequence, the first term, which is the result of sub-expression containing $n-1$ pipe operators, is reused to resolve every overload. Therefore at least $O(n^2)$ copies of expression nodes are made during resolution, not even counting type unification cost; combined with the two large factors from number of overloads of pipe operators, and that the ``output stream type'' in \CFA is a trait with 27 assertions (which adds to complexity of the pipe operator's type) this makes compiling a long output sequence extremely slow. In the new AST representation, only $O(n)$ copies are required and the type of the pipe operator is not copied at all. 136 Reduction in space complexity is especially important, as preliminary profiling results on the old compiler build showed over half of the time spent in expression resolution is on memory allocations. 137 138 Since the compiler codebase is large and the new memory model mostly benefits expression resolution, some of the old data structures are still kept, and a conversion pass happens before and after the general resolve phase. Rewriting every compiler module will take longer, and whether the new model is correct was unknown when this project started, therefore only the resolver is currently implemented with the new data structure. 139 132 140 133 141 \subsection{Merged resolver calls} 134 142 135 The pre-resolve phase of compilation, ina dequately called ``validate'' in the compiler source code, does more than just simple syntax validation, as it also normalizes input program. Some of them, however, requires type information on expressions and therefore needsto call the resolver before the general resolve phase. There are three notable places where the resolver is invoked:136 \begin{itemize} 137 \item 138 Attempt to generate default constructor, copy constructor and destructor for user-defined @struct@ types 139 \item 140 Resolve @with@ statements (the same as in P ython, which introduces fields of a structure directly in scope)143 The pre-resolve phase of compilation, inappropriately called ``validate'' in the compiler source code, has a number of passes that do more than simple syntax and semantic validation; some passes also normalizes the input program. A few of these passes require type information for expressions, and therefore, need to call the resolver before the general resolve phase. There are three notable places where the resolver is invoked: 144 \begin{itemize} 145 \item 146 Generate default constructor, copy constructor and destructor for user-defined @struct@ types. 147 \item 148 Resolve @with@ statements (the same as in Pascal~\cite{pascal}), which introduces fields of a structure directly into a scope. 141 149 \item 142 150 Resolve @typeof@ expressions (cf. @decltype@ in \CC); note that this step may depend on symbols introduced by @with@ statements. 143 151 \end{itemize} 144 Since the compiler codebase is large and the new memory model mostly only benefits expression resolution, the old data structure is still kept, and a conversion pass happens before and after resolve phase. Rewriting every compiler module will take a long time, and whether the new model is correct is still unknown when started, therefore only the resolver is implemented with the new data structure. 145 146 Since the constructor calls were one of the most expensive to resolve (reason will be shown in the next section), pre-resolve phase were taking more time after resolver moves to the more efficient new implementation. To better facilitate the new resolver, every step that requires type information are reintegrated as part of resolver. 147 148 A by-product of this work is that the reversed dependence of @with@ statement and @typeof@ can now be handled. Previously, the compiler is unable to handle cases such as 152 153 Since the constructor calls are one of the most expensive to resolve (reason given in~\VRef{s:SpecialFunctionLookup}), this pre-resolve phase was taking a large amount of time even after the resolver was changed to the more efficient new implementation. The problem is that multiple resolutions repeat a significant amount of work. Therefore, to better facilitate the new resolver, every step that requires type information should be integrated as part of the general resolver phase. 154 155 A by-product of this work is that reversed dependence between @with@ statement and @typeof@ can now be handled. Previously, the compiler was unable to handle cases such as: 149 156 \begin{cfa} 150 157 struct S { int x; }; 151 158 S foo(); 152 159 typeof( foo() ) s; // type is S 153 with (s) { 160 with (s) { 154 161 x; // refers to s.x 155 162 } 156 163 \end{cfa} 157 since t ype of @s@ is still unresolved when handling @with@ expressions. Instead, the new (and correct) approach is to evaluate @typeof@ expressions when the declaration is first seen, and it suffices because of the declaration-before-use rule.164 since the type of @s@ is unresolved when handling @with@ expressions because the @with@ pass follows the @typeof@ pass (interchanging passes only interchanges the problem). Instead, the new (and correct) approach is to evaluate @typeof@ expressions when the declaration is first seen during resolution, and it suffices because of the declaration-before-use rule. 158 165 159 166 160 167 \subsection{Special function lookup} 161 162 Reducing the number of functions looked up for overload resolution is an effective way to gain performance when there are many overloads but most of them are trivially wrong. In practice, most functions have few (if any) overloads but there are notable exceptions. Most importantly, constructor @?{}@, destructor @^?{}@, and assignment @?=?@ are generated for every user-defined type, and in a large source file there can be hundreds of them. Furthermore, many calls to them are generated for initializing variables and passing arguments. This fact makes them the most overloaded and most called functions. 163 164 In an object-oriented programming language, object has methods declared with their types, so a call such as @obj.f()@ only needs to perform lookup in the method table corresponding to type of @obj@. \CFA on the other hand, does not have methods, and all types are open (\ie new operations can be defined on them), so a similar approach will not work in general. However, the ``big 3'' operators have a unique property enforced by the language rules, such that the first parameter must have a reference type. Since \CFA does not have class inheritance, reference type must always match exactly. Therefore, argument-dependent lookup can be implemented for these operators, by using a dedicated symbol table. 165 166 The lookup key used for the special functions is the mangled type name of the first parameter, which acts as the @this@ parameter in an object-oriented language. To handle generic types, the type parameters are stripped off, and only the base type is matched. Note that a constructor (destructor, assignment operator) taking arbitrary @this@ argument, for example @forall( dtype T ) void ?{}( T & );@ is not allowed, and it guarantees that if the @this@ type is known, all possible overloads can be found by searching with the given type. In case that the @this@ argument itself is overloaded, it is resolved first and all possible result types are used for lookup. 167 168 Note that for the generated expressions, the particular variable for @this@ argument is fully known, without overloads, so the majority of constructor call resolutions only need to check for one given object type. Explicit constructor calls and assignment statements sometimes may require lookup for multiple types. In the extremely rare case that type of @this@ argument is yet unbound, everything will have to be checked, just like without the argument-dependent lookup algorithm; fortunately, this case almost never happens in practice. An example is found in the library function @new@: 168 \label{s:SpecialFunctionLookup} 169 170 Reducing the number of function looked ups for overload resolution is an effective way to gain performance when there are many overloads but most of them are trivially wrong. In practice, most functions have few (if any) overloads but there are notable exceptions. Most importantly, constructor @?{}@, destructor @^?{}@, and assignment @?=?@ are generated for every user-defined type (@struct@ and @union@ in C), and in a large source file there can be hundreds of them. Furthermore, many calls are generated for initializing variables, passing arguments and copying values. This fact makes them the most overloaded and most called functions. 171 172 In an object-oriented programming language, the object-method types are scoped within a class, so a call such as @obj.f()@ only needs to perform lookup in the method table corresponding to the type of @obj@. \CFA on the other hand, does not have methods, and all types are open, \ie new operations can be defined on them without inheritance; at best a \CFA type can be constrained by a translation unit. However, the ``big 3'' operators have a unique property enforced by the language rules: the first parameter must be a reference to its associated type, which acts as the @this@ parameter in an object-oriented language. Since \CFA does not have class inheritance, the reference type must always match exactly. Therefore, argument-dependent lookup can be implemented for these operators by using a dedicated, fast symbol-table. 173 174 The lookup key for the special functions is the mangled type name of the first parameter. To handle generic types, the type parameters are stripped off, and only the base type is matched. Note a constructor (destructor, assignment operator) may not take an arbitrary @this@ argument, \eg @forall( dtype T ) void ?{}( T & )@, thus guaranteeing that if the @this@ type is known, all possible overloads can be found by searching with this given type. In the case where the @this@ argument itself is overloaded, it is resolved first and all possible result types are used for lookup. 175 176 Note that for a generated expression, the particular variable for the @this@ argument is fully known, without overloads, so the majority of constructor-call resolutions only need to check for one given object type. Explicit constructor calls and assignment statements sometimes require lookup for multiple types. In the extremely rare case that the @this@-argument type is unbound, all necessary types are guaranteed to be checked, as for the previous lookup without the argument-dependent lookup; fortunately, this complex case almost never happens in practice. An example is found in the library function @new@: 169 177 \begin{cfa} 170 178 forall( dtype T | sized( T ), ttype TT | { void ?{}( T &, TT ); } ) 171 179 T * new( TT p ) { return &(*malloc()){ p }; } 172 180 \end{cfa} 173 as @malloc@ may return a pointer to any type, depending on context. 174 175 Interestingly, this particular line of code actually caused another complicated issue, where the unusually massive work of checking every constructor in presence makes the case even worse. Section~\ref{s:TtypeResolutionInfiniteRecursion} presents a detailed analysis for theproblem.176 177 The ``callable'' operator @?()@ (cf. @operator()@ in \CC) c ould also be included in the special operator list, as it is usually only on user-defined types, and the restriction that first argument must be a reference seems reasonable in this case.181 as @malloc@ may return a pointer to any type, depending on context. 182 183 Interestingly, this particular declaration actually causes another complicated issue, making the complex checking of every constructor even worse. \VRef[Section]{s:TtypeResolutionInfiniteRecursion} presents a detailed analysis of this problem. 184 185 The ``callable'' operator @?()@ (cf. @operator()@ in \CC) can also be included in this special operator list, as it is usually only on user-defined types, and the restriction that the first argument must be a reference seems reasonable in this case. 178 186 179 187 180 188 \subsection{Improvement of function type representation} 181 189 182 Since substituting type parameters with their bound types is one fundamental operation in many parts of resolver algorithm (particularly unification and environment binding), making as few copies of type nodes as possible helps reducing memory complexity. Even with the new memory management model, allocation is still a significant factor of resolver performance. Conceptually, operations on type nodes of AST should be performed in functional programming style, treating the data structure as immutable and only copy when necessary. The in-place mutation is a mere optimization that does not change logic of operations. 183 The model was broken on function types by an inappropriate design. Function types require some special treatment due to the existence of assertions. In particular, it must be able to distinguish two different kinds of type parameter usage: 190 Since substituting type parameters with their bound types is one fundamental operation in many parts of resolver algorithm (particularly unification and environment binding), making as few copies of type nodes as possible helps reducing memory complexity. Even with the new memory management model, allocation is still a significant factor of resolver performance. Conceptually, operations on type nodes of the AST should be performed in functional-programming style, treating the data structure as immutable and only copying when necessary. The in-place mutation is a mere optimization that does not change the logic for operations. 191 192 However, the model was broken for function types by an inappropriate design. Function types require special treatment due to the existence of assertions that constrain the types it supports. Specifically, it must be possible to distinguish two different kinds of type parameter usage: 184 193 \begin{cfa} 185 194 forall( dtype T ) void foo( T * t ) { 186 forall( dtype U ) void bar( T * t, U* u ) { ... }187 } 188 \end{cfa} 189 Here, only @U@ is a free parameter in declaration of @bar@, as it appears in the function's own forall clause; while @T@ is not free.190 191 Moreover, the resolution algorithm also has to distinguish type bindings of multiple calls to the same function, for example with195 forall( dtype U ) void bar( @T@ * t, @U@ * u ) { ... } 196 } 197 \end{cfa} 198 Here, only @U@ is a free parameter in the nested declaration of function @bar@, as @T@ must be bound at the call site when resolving @bar@. 199 200 Moreover, the resolution algorithm also has to distinguish type bindings of multiple calls to the same function, \eg: 192 201 \begin{cfa} 193 202 forall( dtype T ) int foo( T x ); 194 foo( foo( 1.0 ) );195 \end{cfa} 196 The inner call has binding (T: double) while the outer call has binding (T: int). Therefore a unique representation of free parameters in each expression is required. This was previously done by creating a copy of the parameter declarations inside function type, and fixing references afterwards. However, fixing references is an inherently deep operation that does not work well with functional programming model, as it must be evaluated eagerlyon the entire syntax tree representing the function type.197 198 The revised approach generates a unique ID value for each function call expression instance and represents an occurrence of free parameter type with a pair of generated ID and the original parameter declaration, so that references do not need to be fixed, and a shallow copy of function type is possible.199 200 Note that after the change, all declaration nodes in syntax tree representation maps one-to-one with the actual declarations in the program, and therefore are guaranteed to be unique. Such property can potentially enable more optimizations, and some related ideas are presented after Section~\ref{s:SharedSub-ExpressionCaseUniqueExpressions}.203 int i = foo( foo( 1.0 ) ); 204 \end{cfa} 205 The inner call has binding (T: double) while the outer call has binding (T: int). Therefore a unique representation for the free parameters is required in each expression. This type binding was previously done by creating a copy of the parameter declarations inside the function type and fixing references afterwards. However, fixing references is an inherently deep operation that does not work well with the functional-programming style, as it forces eager evaluation on the entire syntax tree representing the function type. 206 207 The revised approach generates a unique ID value for each function call expression instance and represents an occurrence of a free-parameter type with a pair of generated ID and original parameter declaration, so references are unique and a shallow copy of the function type is possible. 208 209 Note that after the change, all declaration nodes in the syntax-tree representation now map one-to-one with the actual declarations in the program, and therefore are guaranteed to be unique. This property can potentially enable more optimizations, and some related ideas are presented at the end of \VRef{s:SharedSub-ExpressionCaseUniqueExpressions}. 201 210 202 211 203 212 \subsection{Improvement of pruning steps} 204 213 205 A minor improvement for candidate elimination is to skip the step on the function overloads themselves and only perform on results of function application. As function calls are usually by name, the name resolution rule dictates that every function candidate necessarily has a different type; indirect function calls are rare, and when they do appear, they usually will not have many possible interpretations, and those rarely matches exactly in argument type. Since function types have a much more complex representation than data types (with multiple parameters and assertions), checking equality on them also takes longer.206 207 A brief test of this approach shows that the number of function overloads considered in expression resolution increases by a negligible amount of less than 1 percent, while type comparisons in candidate elimination are cut by more than half. Improvement is consistent over all \CFA source files in the test suite.214 A minor improvement for candidate elimination is to skip the step on the function overloads and only check the results of function application. As function calls are usually by name (versus pointers to functions), the name resolution rule dictates that every function candidate necessarily has a different type; indirect function calls are rare, and when they do appear, there are even fewer cases with multiple interpretations, and these rarely match exactly in argument type. Since function types have a much more complex representation (with multiple parameters and assertions) than data types, checking equality on them also takes longer. 215 216 A brief test of this approach shows that the number of function overloads considered in expression resolution increases by an amount of less than 1 percent, while type comparisons in candidate elimination are reduced by more than half. This improvement is consistent over all \CFA source files in the test suite. 208 217 209 218 … … 211 220 \label{s:SharedSub-ExpressionCaseUniqueExpressions} 212 221 213 Unique expression denotes an expression that must be evaluated only once, to prevent unwanted side effects. It is currently only a compiler artifact, generated on tuple member expression of the form222 Unique expression denotes an expression evaluated only once to prevent unwanted side effects. It is currently only a compiler artifact, generated for tuple-member expression of the form: 214 223 \begin{cfa} 215 224 struct S { int a; int b; }; … … 217 226 s.[a, b]; // tuple member expression, type is [int, int] 218 227 \end{cfa} 219 If the aggregate expression contains function calls, it cannot be evaluated multiple times:228 If the aggregate expression is function call, it cannot be evaluated multiple times: 220 229 \begin{cfa} 221 230 S makeS(); 222 makeS().[a, b]; // this should only make one S231 makeS().[a, b]; // this should only generate a unique S 223 232 \end{cfa} 224 233 Before code generation, the above expression is internally represented as … … 237 246 \end{cfa} 238 247 at code generation, where @_unique_var@ and @_unique_var_evaluated@ are generated variables whose scope covers all appearances of the same expression. 239 240 Note that although the unique expression is only used for tuple expansion now, it is a generally useful construction, and can be seen in other languages, such as Scala's @lazy val@~\cite{Scala}; therefore it could be worthwhile to introduce the unique expression to a broader context in \CFA and even make it directly available to programmers. 241 242 In the compiler's visitor pattern, however, this creates a problem where multiple paths to a logically unique expression exist, so it may be modified more than once and become ill-formed; some specific intervention is required to ensure that unique expressions are only visited once. Furthermore, a unique expression appearing in more than one places will be copied on mutation so its representation is no longer unique. Some hacks are required to keep it in sync, and the methods are different when mutating the unique expression instance itself or its underlying expression. 243 244 Example when mutating the underlying expression (visit-once guard) 248 The conditional check ensures a single call to @makeS()@ even though there are logically multiple calls because of the tuple field expansion. 249 250 Note that although the unique expression is only used for tuple expansion now, it is a generally useful construction, and is seen in other programming languages, such as Scala's @lazy val@~\cite{Scala}; therefore it may be worthwhile to introduce the unique expression to a broader context in \CFA and even make it directly available to programmers. 251 252 In the compiler's visitor pattern, however, this creates a problem where multiple paths to a logically unique expression exist, so it may be modified more than once and become ill-formed; some specific intervention is required to ensure unique expressions are only visited once. Furthermore, a unique expression appearing in more than one places is copied on mutation so its representation is no longer unique. 253 254 Currently, special cases are required to keep everything synchronized, and the methods are different when mutating the unique expression instance itself or its underlying expression: 255 \begin{itemize} 256 \item 257 When mutating the underlying expression (visit-once guard) 245 258 \begin{cfa} 246 259 void InsertImplicitCalls::previsit( const ast::UniqueExpr * unqExpr ) { 247 if ( visitedIds.count( unqExpr->id ) ) visit_children = false;260 @if ( visitedIds.count( unqExpr->id ) ) visit_children = false;@ 248 261 else visitedIds.insert( unqExpr->id ); 249 262 } 250 263 \end{cfa} 251 Example when mutating the unique instance itself, which actually creates copies 264 \item 265 When mutating the unique instance itself, which actually creates copies 252 266 \begin{cfa} 253 267 auto mutExpr = mutate( unqExpr ); // internally calls copy when shared 254 if ( ! unqMap.count( unqExpr->id ) ) { 268 @if ( ! unqMap.count( unqExpr->id ) ) {@ 255 269 ... 256 270 } else { … … 259 273 } 260 274 \end{cfa} 261 Such workaround seems difficult to be fit into a common visitor template. This suggests the memory model may need different kinds of nodes to accurately represent the syntax tree. 262 263 Together with the fact that declaration nodes are always unique, it is possible that AST nodes can be classified by three different types: 264 \begin{itemize} 265 \item 266 \textbf{Strictly unique} with only one owner (declarations); 267 \item 268 \textbf{Logically unique} with (possibly) many owners but should not be copied (unique expression example presented here); 269 \item 270 \textbf{Shared} by functional programming model, which assume immutable data structure and are copied on mutation. 275 \end{itemize} 276 Such workarounds are difficult to fit into the common visitor pattern, which suggests the memory model may need different kinds of nodes to accurately represent this feature in the AST. 277 278 Given that declaration nodes are unique, it is possible for AST nodes to be divided into three different types: 279 \begin{itemize} 280 \item 281 \textbf{Singleton} with only one owner (declarations); 282 \item 283 \textbf{No-copy} with multiple owners but cannot be copied (unique expression example presented here); 284 \item 285 \textbf{Copy} by functional-programming style, which assumes immutable data structures that are copied on mutation. 271 286 \end{itemize} 272 287 The boilerplate code can potentially handle these three cases differently. … … 275 290 \section{Analysis of resolver algorithm complexity} 276 291 277 The focus of this chapter is to identify and analyze some realistic cases that cause resolver algorithm to have an exponential run time. As previous work has shown [3], the overload resolution problem in \CFA has worst-case exponential complexity; however, only few specific patterns can trigger the exponential complexity in practice. Implementing heuristic-based optimization for those selected cases is helpful to alleviate the problem.292 The focus of this section is to identify and analyze some realistic cases that cause the resolver algorithm to have an exponential runtime. As previous work has shown~\cite[\S~4.2.1]{Moss19}, the overload resolution problem in \CFA has worst-case exponential complexity; however, only few specific patterns can trigger the exponential complexity in practice. Implementing heuristic-based optimization for those selected cases is helpful to alleviate the problem. 278 293 279 294 … … 281 296 \label{s:UnboundReturnType} 282 297 283 The interaction of return type overloading and polymorphic functions creates this problem of function calls with unbound returntype, and is further complicated by the presence of assertions.298 The interaction of return-type overloading and polymorphic functions creates function calls with unbounded return-type, and is further complicated by the presence of assertions. 284 299 The prime example of a function with unbound return type is the type-safe version of C @malloc@: 285 300 \begin{cfa} 286 // size deduced from type, so no need to provide the size argument 287 forall( dtype T | sized( T ) ) T * malloc( void ); 288 \end{cfa} 289 Unbound return type can be problematic in resolver algorithm complexity because a single match of function call with unbound return type may create multiple candidates. In the worst case, consider a function declared to return any @otype@: 301 forall( dtype T | sized( T ) ) 302 T * malloc( void ) { return (T *)malloc( sizeof(T) ); } // call C malloc 303 int * i = malloc(); // type deduced from left-hand size $\Rightarrow$ no size argument or return cast 304 \end{cfa} 305 An unbound return-type is problematic in resolver complexity because a single match of a function call with an unbound return type may create multiple candidates. In the worst case, consider a function declared that returns any @otype@ (defined \VPageref{otype}): 290 306 \begin{cfa} 291 307 forall( otype T ) T anyObj( void ); 292 308 \end{cfa} 293 As the resolver attempts to satisfy the otype constraint on @T@, a single call to @anyObj()@ without the result type known creates at least as many candidates as the number of complete types currently in scope; with generic types it becomes even worse, for example, assuming a declaration of generic pairis available at that point:309 As the resolver attempts to satisfy the otype constraint on @T@, a call to @anyObj()@ in an expression, without the result type known, creates at least as many candidates as the number of complete types currently in scope; with generic types it becomes even worse, \eg assuming a declaration of a generic @pair@ is available at that point: 294 310 \begin{cfa} 295 311 forall( otype T, otype U ) struct pair { T first; U second; }; 296 312 \end{cfa} 297 Then an @anyObj()@ call can result in arbitrarily complex types, such as @pair( pair( int, int ), pair( int,int ) )@, and the depth can grow indefinitely until the specified parameter depth limit, thus creating exponentially many candidates. However, the expected types allowed by parent expressions are practically very few, so most of those interpretations are invalid; if the result type is never bound up to top level, by the semantic rules it is ambiguous if there are more than one valid bindings, and resolution can fail fast. It is therefore reasonable to delay resolving assertions on an unbound parameter in return type; however, with the current cost model, such behavior may further cause irregularities in candidate selection, such that the presence of assertions can change the preferred candidate, even when order of expression costs are supposed to stay the same. Detailed analysis of this issue will be presented later, in the correctness part.313 Then an @anyObj()@ call can result in arbitrarily complex types, such as @pair( pair( int, int ), pair( int, int ) )@, and the depth can grow indefinitely until a specified parameter-depth limit, thus creating exponentially many candidates. However, the expected types allowed by parent expressions are practically very few, so most of those interpretations are invalid; if the result type is never bound up to the top level, by the semantic rules it is ambiguous if there is more than one valid binding and resolution fails quickly. It is therefore reasonable to delay resolving assertions on an unbound parameter in a return type; however, with the current cost model, such behavior may further cause irregularities in candidate selection, such that the presence of assertions can change the preferred candidate, even when order of expression costs are supposed to stay the same. A detailed analysis of this issue is presented in \VRef{s:AnalysisTypeSystemCorrectness}. 298 314 299 315 … … 301 317 \label{s:TtypeResolutionInfiniteRecursion} 302 318 303 @ttype@ (``tuple type'') is a relatively new addition to the language that attempts to provide type-safe variadic argument semantics. Unlike regular @dtype@ parameters, @ttype@ is only valid in function parameter list, and may only appear once as the type of last parameter. At the call site, a @ttype@ parameter is bound to the tuple type of all remaining functioncall arguments.319 @ttype@ (``tuple type'') is a relatively new addition to the language that attempts to provide type-safe variadic argument semantics. Unlike regular @dtype@ parameters, @ttype@ is only valid in a function parameter-list, and may only appear once as the last parameter type. At the call site, a @ttype@ parameter is bound to the tuple type of all remaining function-call arguments. 304 320 305 321 There are two kinds of idiomatic @ttype@ usage: one is to provide flexible argument forwarding, similar to the variadic template in \CC (\lstinline[language=C++]|template<typename... args>|), as shown below in the implementation of @unique_ptr@ … … 309 325 T * data; 310 326 }; 311 forall( dtype T | sized( T ), ttype Args| { void ?{}( T &, Args ); })312 void ?{}( unique_ptr( T ) & this, Args args) {313 this.data = new( args );314 } 315 \end{cfa} 316 the other is to implement structural recursion in the first-rest manner:317 \begin{cfa} 318 forall( otype T, ttype Params| { void process( T ); void func( Params ); })327 forall( dtype T | sized( T ), @ttype Args@ | { void ?{}( T &, Args ); }) 328 void ?{}( unique_ptr( T ) & this, Args @args@ ) { 329 this.data = new( @args@ ); // forward constructor arguments to dynamic allocator 330 } 331 \end{cfa} 332 The other usage is to implement structural recursion in the first-rest pattern: 333 \begin{cfa} 334 forall( otype T, @ttype Params@ | { void process( T ); void func( Params ); }) 319 335 void func( T arg1, Params p ) { 320 336 process( arg1 ); 321 func( p ); 322 } 323 \end{cfa} 324 For the second use case, it is important that the number of parameters in the recursive call go down, since the call site must deduce all assertion candidates, and that is only possible if by just looking at argument types (and not their values), the recursion is known to be completed in a finite number of steps. 325 326 In recent experiments, however, some flaw in the type binding rules can lead to the first kind of @ttype@ use case produce an invalid candidate that the resolver enters an infinite loop. 327 328 This bug was discovered in an attempt to raise assertion recursive depth limit and one of the library program takes exponentially longer time to compile. The cause of the problem is identified to be the following set of functions. 329 File @memory.cfa@ contains 330 \begin{cfa} 331 #include "memory.hfa" 332 #include "stdlib.hfa" 333 \end{cfa} 334 where file @memory.hfa@ contains the @unique_ptr@ declaration above, and two other similar functions with @ttype@ parameter: 335 \begin{cfa} 336 forall( dtype T | sized( T ), ttype Args | { void ?{}( T &, Args ); }) { 337 func( @p@ ); // recursive call until base case of one argument 338 } 339 \end{cfa} 340 For the second use case, it is imperative the number of parameters in the recursive call goes down, since the call site must deduce all assertion candidates, and that is only possible if by observation of the argument types (and not their values), the recursion is known to be completed in a finite number of steps. 341 342 In recent experiments, however, a flaw in the type-binding rules can lead to the first kind of @ttype@ use case producing an invalid candidate and the resolver enters an infinite loop. 343 This bug was discovered in an attempt to raise the assertion recursive-depth limit and one of the library programs took exponentially longer to compile. The cause of the problem is the following set of functions: 344 \begin{cfa} 345 // unique_ptr declaration from above 346 347 forall( dtype T | sized( T ), ttype Args | { void ?{}( T &, Args ); } ) { // distribute forall clause 337 348 void ?{}( counter_data( T ) & this, Args args ); 338 349 void ?{}( counter_ptr( T ) & this, Args args ); 339 350 void ?{}( unique_ptr( T ) & this, Args args ); 340 351 } 341 \end{cfa} 342 File @stdlib.hfa@ contains 343 \begin{cfa} 352 344 353 forall( dtype T | sized( T ), ttype TT | { void ?{}( T &, TT ); } ) 345 T * new( TT p ) { return &(*malloc()){ p }; } 346 \end{cfa} 347 348 In the expression @(*malloc()){p}@, the type of object being constructed is yet unknown, since the return type information is not immediately provided. That caused every constructor to be searched, and while normally a bound @ttype@ cannot be unified with any free parameter, it is possible with another free @ttype@. Therefore in addition to the correct option provided by assertion, 3 wrong options are examined, each of which again requires the same assertion, for an unknown base type T and @ttype@ arguments, and that becomes an infinite loop, until the specified recursion limit and resolution is forced to fail. Moreover, during the recursion steps, number of candidates grows exponentially, since there are always 3 options at each step. 349 350 Unfortunately, @ttype@ to @ttype@ binding is necessary, to allow calling the function provided by assertion indirectly. 351 \begin{cfa} 352 forall( dtype T | sized( T ), ttype Args | { void ?{}( T &, Args ); }) 353 void ?{}( unique_ptr( T ) & this, Args args ) { this.data = (T * )new( args ); } 354 \end{cfa} 355 Here the constructor assertion is used for the @new( args )@ call. 354 T * new( TT p ) { return @&(*malloc()){ p };@ } 355 \end{cfa} 356 In the expression @(*malloc()){p}@, the type of the object being constructed is unknown, since the return-type information is not immediately available. That causes every constructor to be searched, and while normally a bound @ttype@ cannot be unified with any free parameter, it is possible with another free @ttype@. Therefore, in addition to the correct option provided by the assertion, 3 wrong options are examined, each of which again requires the same assertion, for an unknown base-type @T@ and @ttype@ argument, which becomes an infinite loop until the specified recursion limit and resolution is fails. Moreover, during the recursion steps, the number of candidates grows exponentially, since there are always 3 options at each step. 357 358 Unfortunately, @ttype@ to @ttype@ binding is necessary, to allow indirectly calling a function provided in an assertion. 359 \begin{cfa} 360 forall( dtype T | sized( T ), ttype Args | { @void ?{}( T &, Args );@ }) 361 void ?{}( unique_ptr( T ) & this, Args args ) { this.data = (T *)@new( args )@; } // constructor call 362 \end{cfa} 363 Here the constructor assertion is used by the @new( args )@ call to indirectly call the constructor on the allocated storage. 356 364 Therefore, it is hard, perhaps impossible, to solve this problem by tweaking the type binding rules. An assertion caching algorithm can help improve this case by detecting cycles in recursion. 357 365 358 Meanwhile, without the caching algorithm implemented, some changes in the \CFA source code are enough to eliminate this problem, at least in the current codebase. Note that the issue only happens with an overloaded variadic function, which rarely appears in practice, since the idiomatic use cases are for argument forwarding and self-recursion. The only overloaded @ttype@ function so far discovered in all of \CFA standard library code is the constructor, and by utilizing the argument-dependent lookup process described in Section~\ref{s:UnboundReturnType}, adding a cast before constructor call gets rid of the issue.359 \begin{cfa} 360 T * new( TT p ) { return &(* (T * )malloc()){ p }; }366 Meanwhile, without a caching algorithm implemented, some changes in the \CFA source code are enough to eliminate this problem, at least in the current codebase. Note that the issue only happens with an overloaded variadic function, which rarely appears in practice, since the idiomatic use cases are for argument forwarding and self-recursion. The only overloaded @ttype@ function so far discovered in all of \CFA standard library is the constructor, and by utilizing the argument-dependent lookup process described in \VRef{s:UnboundReturnType}, adding a cast before the constructor call removes the issue. 367 \begin{cfa} 368 T * new( TT p ) { return &(*@(T * )@malloc()){ p }; } 361 369 \end{cfa} 362 370 … … 364 372 \subsection{Reused assertions in nested generic type} 365 373 366 The following test of deeply nested dynamic generic type reveals that locally caching reused assertions is necessary, rather than just a resolver optimization, because recomputing assertions can result in bloated generated code size:374 The following test of deeply nested, dynamic generic type reveals that locally caching reused assertions is necessary, rather than just a resolver optimization, because recomputing assertions can result in bloated generated code size: 367 375 \begin{cfa} 368 376 struct nil {}; … … 372 380 int main() { 373 381 #if N==0 374 nil x;382 nil @x@; 375 383 #elif N==1 376 cons( size_t, nil ) x;384 cons( size_t, nil ) @x@; 377 385 #elif N==2 378 cons( size_t, cons( size_t, nil ) ) x;386 cons( size_t, cons( size_t, nil ) ) @x@; 379 387 #elif N==3 380 cons( size_t, cons( size_t, cons( size_t, nil ) ) ) x;388 cons( size_t, cons( size_t, cons( size_t, nil ) ) ) @x@; 381 389 // similarly for N=4,5,6 382 390 #endif 383 391 } 384 392 \end{cfa} 385 At the declaration of @x@, it is implicitly initialized by generated constructor call, w hose signature is given by393 At the declaration of @x@, it is implicitly initialized by generated constructor call, with signature: 386 394 \begin{cfa} 387 395 forall( otype L, otype R ) void ?{}( cons( L, R ) & ); 388 396 \end{cfa} 389 Note that the @otype@ constraint contains 4 assertions: 397 where the @otype@ constraint contains the 4 assertions:\label{otype} 390 398 \begin{cfa} 391 399 void ?{}( L & ); // default constructor … … 394 402 L & ?=?( L &, L & ); // assignment 395 403 \end{cfa} 396 Now since the right hand side of outermost cons is again a cons, recursive assertions are required. When the compiler cannot cache and reuse already resolved assertions, it becomes a problem, as each of those 4 pending assertions again asks for 4 more assertions one level below. Without any caching, number of resolved assertions grows exponentially, while that is obviously unnecessary since there are only $n+1$ different types involved. Even worse, this causes exponentially many wrapper functions generated later at the codegen step, and results in huge compiled binary. 397 398 \ begin{table}[h]404 405 \begin{table}[htb] 406 \centering 399 407 \caption{Compilation results of nested cons test} 408 \label{t:NestedConsTest} 400 409 \begin{tabular}{|r|r|r|} 401 410 \hline … … 413 422 \end{table} 414 423 415 As the local functions are implemented by emitting executable code on the stack~\cite{gcc-nested-func}, it eventually means that compiled code also has exponential run time. This problem has evident practical implications, as nested collection types are frequently used in real production code. 416 424 Now since the right hand side of outermost cons is again a cons, recursive assertions are required. \VRef[Table]{t:NestedConsTest} shows when the compiler does not cache and reuse already resolved assertions, it becomes a problem, as each of these 4 pending assertions again asks for 4 more assertions one level below. Without caching, the number of resolved assertions grows exponentially, which is unnecessary since there are only $n+1$ different types involved. Even worse, this problem causes exponentially many wrapper functions to be generated at the backend, resulting in a huge binary. As the local functions are implemented by emitting executable code on the stack~\cite{gcc-nested-func}, it means that compiled code also has exponential run time. This problem has practical implications, as nested collection types are frequently used in real production code. 417 425 418 426 \section{Analysis of type system correctness} 427 \label{s:AnalysisTypeSystemCorrectness} 419 428 420 429 In Moss' thesis~\cite[\S~4.1.2,~p.~45]{Moss19}, the author presents the following example: … … 433 442 From the set of candidates whose parameter and argument types have been unified and whose assertions have been satisfied, those whose sub-expression interpretations have the smallest total cost of conversion are selected ... The total cost of conversion for each of these candidates is then calculated based on the implicit conversions and polymorphism involved in adapting the types of the sub-expression interpretations to the formal parameter types. 434 443 \end{quote} 435 With this model, the algorithm picks @g1@ in resolving the @f( g( 42 ) )@ call, which seems to be undesirable. 436 437 There are further evidence that shows the Bilson model is fundamentally incorrect, following the discussion of unbound return type in Section~\ref{s:UnboundReturnType}. By the conversion cost specification, a binding from a polymorphic type parameter to a concrete type incurs a polymorphic cost of 1. It remains unspecified \emph{when} the type parameters should become bound. When the parameterized types appear in the function parameters, they can be deduced from the argument type, and there is no ambiguity. In the unbound return case, however, the binding may happen at any stage in expression resolution, therefore it is impossible to define a unique local conversion cost. Note that type binding happens exactly once per parameter in resolving the entire expression, so the global binding cost is unambiguously 1. 438 439 As per the current compiler implementation, it does have a notable inconsistency in handling such case. For any unbound parameter that does \emph{not} come with an associated assertion, it remains unbound to the parent expression; for those that does however, they are immediately bound in the assertion resolution step, and concrete result types are used in the parent expressions. 440 444 With this model, the algorithm picks @g1@ in resolving the @f( g( 42 ) )@ call, which is undesirable. 445 446 There is further evidence that shows the Bilson model is fundamentally incorrect, following the discussion of unbound return type in \VRef{s:UnboundReturnType}. By the conversion-cost specification, a binding from a polymorphic type-parameter to a concrete type incurs a polymorphic cost of 1. It remains unspecified \emph{when} the type parameters should become bound. When the parameterized types appear in function parameters, they can be deduced from the argument type, and there is no ambiguity. In the unbound return case, however, the binding may happen at any stage in expression resolution, therefore it is impossible to define a unique local conversion cost. Note that type binding happens exactly once per parameter in resolving the entire expression, so the global binding cost is unambiguously 1. 447 448 In the current compiler implementation, there is a notable inconsistency in handling this case. For any unbound parameter that does \emph{not} come with an associated assertion, it remains unbound to the parent expression; for those that do, however, they are immediately bound in the assertion resolution step, and concrete result types are used in the parent expressions. 441 449 Consider the following example: 442 450 \begin{cfa} … … 444 452 void h( int * ); 445 453 \end{cfa} 446 The expression @h( f() )@ eventually has a total cost of 1 from binding (T: int), but in the eager resolution model, the cost of 1 may occur either atcall to @f@ or at call to @h@, and with the assertion resolution triggering a binding, the local cost of @f()@ is (0 poly, 0 spec) with no assertions, but (1 poly, -1 spec) with an assertion:447 \begin{cfa} 448 forall( dtype T | { void g( T * ); }) T * f( void );454 The expression @h( f() )@ eventually has a total cost of 1 from binding (T: int), but in the eager-resolution model, the cost of 1 may occur either at the call to @f@ or at call to @h@, and with the assertion resolution triggering a binding, the local cost of @f()@ is (0 poly, 0 spec) with no assertions, but (1 poly, -1 spec) with an assertion: 455 \begin{cfa} 456 forall( dtype T | @{ void g( T * ); }@ ) T * f( void ); 449 457 void g( int * ); 450 458 void h( int * ); 451 459 \end{cfa} 452 and that contradicts the principle that adding assertions should make expression cost lower. Furthermore, the time at which type binding and assertion resolution happens is an implementation detail of the compiler, but not a part of language definition. That means two compliant \CFA compilers, one performing immediate assertion resolution at each step, and one delaying assertion resolution on unbound types, can produce different expression costs and therefore different candidate selection, making the language rule itself partially undefined and thereforeunsound. By the above reasoning, the updated cost model using global sum of costs should be accepted as the standard. It also allows the compiler to freely choose when to resolve assertions, as the sum of total costs is independent of that choice; more optimizations regarding assertion resolution can also be implemented.460 and that contradicts the principle that adding assertions should make expression cost lower. Furthermore, the time at which type binding and assertion resolution happens is an implementation detail of the compiler, not part of the language definition. That means two compliant \CFA compilers, one performing immediate assertion resolution at each step, and one delaying assertion resolution on unbound types, can produce different expression costs and therefore different candidate selection, making the language rule itself partially undefined, and therefore, unsound. By the above reasoning, the updated cost model using global sum of costs should be accepted as the standard. It also allows the compiler to freely choose when to resolve assertions, as the sum of total costs is independent of that choice; more optimizations regarding assertion resolution can also be implemented. 453 461 454 462 455 463 \section{Timing results} 456 464 457 For the timing results presented here, the \CFA compiler is built with gcc 9.3.0, and tested on a server machine running Ubuntu 20.04, 64GB RAM and 32-core 2.2 GHz CPU, results reported by the time command, and using only 8 cores in parallel such that the time is close to the case with 100\% CPU utilization on a single thread. 458 459 On the most recent build, the \CFA standard library (~1.3 MB of source code) compiles in 4 minutes 47 seconds total processor time (single thread equivalent), with the slowest file taking 13 seconds. The test suite (178 test cases, ~2.2MB of source code) completes within 25 minutes total processor time,\footnote{Including a few runtime tests; total time spent in compilation is approximately 21 minutes.} with the slowest file taking 23 seconds. In contrast, the library build on old compiler takes 85 minutes total, 5 minutes for the slowest file. Full test suite takes too long with old compiler build and is therefore not run, but the slowest test cases take approximately 5 minutes. Overall, the most recent build compared to old build in April 2020, before the project started, is consistently faster by a factor of 20. 460 461 Additionally, 6 selected \CFA source files with distinct features from library and test suite are used to test compiler performance after each of the optimizations are implemented. Test files are from the most recent build and run through C preprocessor to eliminate the factor of header file changes. The selected tests are: 462 \begin{itemize} 463 \item 464 @lib/fstream@ (112 KB)\footnote{File sizes are after preprocessing, with no line information (\lstinline|gcc -E -P|).}: implementation of I/O library 465 For the timing results presented here, the \CFA compiler is built with gcc 9.3.0, and tested on a server machine running Ubuntu 20.04, 64GB RAM and 32-core 2.2 GHz CPU. 466 Timing is reported by the @time@ command and an experiment is run using 8 cores, where each core is at 100\% CPU utilization. 467 468 On the most recent build, the \CFA standard library ($\approx$1.3 MB of source code) compiles in 4 minutes 47 seconds total processor time (single thread equivalent), with the slowest file taking 13 seconds. The test suite (178 test cases, $\approx$2.2MB of source code) completes within 25 minutes total processor time, 469 % PAB: I do not understand this footnote. 470 %\footnote{Including a few runtime tests; total time spent in compilation is approximately 21 minutes.} 471 with the slowest file taking 23 seconds. In contrast, the library build with the old compiler takes 85 minutes total, 5 minutes for the slowest file. The full test-suite takes too long with old compiler build and is therefore not run, but the slowest test cases take approximately 5 minutes. Overall, the most recent build compared to an old build is consistently faster by a factor of 20. 472 473 Additionally, 6 selected \CFA source files with distinct features from the library and test suite are used to illustrate the compiler performance change after each of the implemented optimizations. Test files are from the most recent build and run through the C preprocessor to expand header file, perform macro expansions, but no line number information (@gcc -E -P@). 474 \VRef[Table]{t:SelectedFileByCompilerBuild} shows the selected tests: 475 \begin{itemize} 476 \item 477 @lib/fstream@ (112 KB) 465 478 \item 466 479 @lib/mutex@ (166 KB): implementation of concurrency primitive … … 470 483 @lib/stdlib@ (64 KB): type-safe wrapper to @void *@-based C standard library functions 471 484 \item 472 @test/ ISO2@ (55 KB): application of I/O library485 @test/io2@ (55 KB): application of I/O library 473 486 \item 474 487 @test/thread@ (188 KB): application of threading library 475 488 \end{itemize} 476 477 The \CFA compiler builds are picked from git commit history that passed the test suite, and implement the optimizations incrementally: 478 \begin{itemize} 479 \item 480 \#0 is the first working build of new AST data structure 489 versus \CFA compiler builds picked from the git commit history that implement the optimizations incrementally: 490 \begin{itemize} 491 \item 492 old resolver 493 \item 494 \#0 is the first working build of the new AST data structure 481 495 \item 482 496 \#1 implements special symbol table and argument-dependent lookup 483 497 \item 484 \#2 implements late assertion satisfaction 485 \item 486 \#3 implements revised function type representation 487 \item 488 \#4 skips pruning on expressions with function type (most recent build) 489 \end{itemize} 490 The old resolver with no memory sharing and none of the optimizations above is also tested. 491 \begin{table} 498 \#2 implements late assertion-satisfaction 499 \item 500 \#3 implements revised function-type representation 501 \item 502 \#4 skips pruning on expressions for function types (most recent build) 503 \end{itemize} 504 Reading left to right for a test shows the benefit of each optimization on the cost of compilation. 505 506 \begin{table}[htb] 507 \centering 492 508 \caption{Compile time of selected files by compiler build, in seconds} 509 \label{t:SelectedFileByCompilerBuild} 493 510 \begin{tabular}{|l|r|r|r|r|r|r|} 494 511 \hline … … 513 530 \end{table} 514 531 515 516 532 \section{Conclusion} 517 533 518 Over the course of 8 months of active research and development in \CFA type system and compiler algorithm, performance of the reference \CFA compiler, cfa-cc, has been greatly improved, allowing mid-sized \CFA programs to be compiled and built reasonably fast. As there are also ongoing efforts in the team on building a standard library, evaluating the runtime performance, and attempting to incorporate \CFA with existing software written in C, this project is especially meaningful forpractical purposes.519 520 A nalysis conducted in the project were based significantly on heuristics and practical evidence, as the theoretical bounds and average cases for the expression resolution problem differ. This approach was difficult at start to follow, with an unacceptably slow compiler, since running the program through debugger and validation tools (\eg @gdb@, @valgrind@) adds another order of magnitude to run time, which was already in minutes. However, near the end of the project, many significant improvements have already been made and new optimizations can be tested immediately. The positive feedback in development cycle benefits the \CFA team as a whole, more than just for the compiler optimizations.521 522 Some potential issues of the language that may happen frequently in practice have been identified. Due to the time constraint and complex nature of these problems, a handful of them remain unsolved, but some constructive proposals are made. Notably, introducing a local assertion cache in the resolver is a common solution for a few remaining problems, so that should be the focus of work soon.523 524 The \CFA team are planning on a public alpha release of the language as the compiler performance becomes promising, and other parts of the system, such as a standard library, are also being enhanced. Ideally, the remaining problems should be resolved before release, and the solutions will also be integral to drafting a formal specification.534 Over the course of 8 months of active research and development of the \CFA type system and compiler algorithms, performance of the reference \CFA compiler, cfa-cc, has been greatly improved. Now, mid-sized \CFA programs are compiled reasonably fast. Currently, there are ongoing efforts by the \CFA team to augment the standard library and evaluate its runtime performance, and incorporate \CFA with existing software written in C; therefore this project is especially meaningful for these practical purposes. 535 536 Accomplishing this work was difficult. Analysis conducted in the project is based significantly on heuristics and practical evidence, as the theoretical bounds and average cases for the expression resolution problem differ. As well, the slowness of the initial compiler made attempts to understand why and where problems exist extremely difficult because both debugging and validation tools (\eg @gdb@, @valgrind@, @pref@) further slowed down compilation time. However, by the end of the project, I had found and fixed several significant problems and new optimizations are easier to introduce and test. The reduction in the development cycle benefits the \CFA team as a whole. 537 538 Some potential issues of the language, which happen frequently in practice, have been identified. Due to the time constraint and complex nature of these problems, a handful of them remain unsolved, but some constructive proposals are made. Notably, introducing a local assertion cache in the resolver is a reasonable solution for a few remaining problems, so that should be the focus of future work. 539 540 The \CFA team are planning on a public alpha release of the language as the compiler performance, given my recent improvements, is now useable. Other parts of the system, such as the standard library, have made significant gains due to the speed up in the development cycle. Ideally, the remaining problems should be resolved before release, and the solutions will also be integral to drafting a formal specification. 525 541 526 542 \addcontentsline{toc}{section}{\refname} -
driver/cfa.cc
r92bfda0 rdafbde8 10 10 // Created On : Tue Aug 20 13:44:49 2002 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Nov 17 14:27:28 202013 // Update Count : 44 012 // Last Modified On : Sat Jan 16 07:30:19 2021 13 // Update Count : 442 14 14 // 15 15 … … 499 499 args[nargs++] = "-no-integrated-cpp"; 500 500 args[nargs++] = "-Wno-deprecated"; 501 args[nargs++] = "-Wno-strict-aliasing"; // casting from one type to another 501 502 #ifdef HAVE_CAST_FUNCTION_TYPE 502 503 args[nargs++] = "-Wno-cast-function-type"; -
libcfa/prelude/builtins.c
r92bfda0 rdafbde8 18 18 // type that wraps a pointer and a destructor-like function - used in generating implicit destructor calls for struct members in user-defined functions 19 19 // Note: needs to occur early, because it is used to generate destructor calls during code generation 20 forall( dtype T)20 forall(T &) 21 21 struct __Destructor { 22 22 T * object; … … 25 25 26 26 // defined destructor in the case that non-generated code wants to use __Destructor 27 forall( dtype T)27 forall(T &) 28 28 static inline void ^?{}(__Destructor(T) & x) { 29 29 if (x.object && x.dtor) { … … 34 34 // easy interface into __Destructor's destructor for easy codegen purposes 35 35 extern "C" { 36 forall( dtype T)36 forall(T &) 37 37 static inline void __destroy_Destructor(__Destructor(T) * dtor) { 38 38 ^(*dtor){}; … … 51 51 void abort( const char fmt[], ... ) __attribute__ (( format(printf, 1, 2), __nothrow__, __leaf__, __noreturn__ )); 52 52 53 forall( dtype T)53 forall(T &) 54 54 static inline T & identity(T & i) { 55 55 return i; … … 64 64 static inline void ^?{}($generator &) {} 65 65 66 trait is_generator( dtype T) {66 trait is_generator(T &) { 67 67 void main(T & this); 68 68 $generator * get_generator(T & this); 69 69 }; 70 70 71 forall( dtype T| is_generator(T))71 forall(T & | is_generator(T)) 72 72 static inline T & resume(T & gen) { 73 73 main(gen); … … 78 78 79 79 static inline { 80 forall( dtype DT| { DT & ?+=?( DT &, one_t ); } )80 forall( DT & | { DT & ?+=?( DT &, one_t ); } ) 81 81 DT & ++?( DT & x ) { return x += 1; } 82 82 83 forall( dtype DT| sized(DT) | { void ?{}( DT &, DT ); void ^?{}( DT & ); DT & ?+=?( DT &, one_t ); } )83 forall( DT & | sized(DT) | { void ?{}( DT &, DT ); void ^?{}( DT & ); DT & ?+=?( DT &, one_t ); } ) 84 84 DT & ?++( DT & x ) { DT tmp = x; x += 1; return tmp; } 85 85 86 forall( dtype DT| { DT & ?-=?( DT &, one_t ); } )86 forall( DT & | { DT & ?-=?( DT &, one_t ); } ) 87 87 DT & --?( DT & x ) { return x -= 1; } 88 88 89 forall( dtype DT| sized(DT) | { void ?{}( DT &, DT ); void ^?{}( DT & ); DT & ?-=?( DT &, one_t ); } )89 forall( DT & | sized(DT) | { void ?{}( DT &, DT ); void ^?{}( DT & ); DT & ?-=?( DT &, one_t ); } ) 90 90 DT & ?--( DT & x ) { DT tmp = x; x -= 1; return tmp; } 91 91 92 forall( dtype DT| { int ?!=?( const DT &, zero_t ); } )92 forall( DT & | { int ?!=?( const DT &, zero_t ); } ) 93 93 int !?( const DT & x ) { return !( x != 0 ); } 94 94 } // distribution 95 95 96 96 // universal typed pointer constant 97 static inline forall( dtype DT) DT * intptr( uintptr_t addr ) { return (DT *)addr; }97 static inline forall( DT & ) DT * intptr( uintptr_t addr ) { return (DT *)addr; } 98 98 static inline forall( ftype FT ) FT * intptr( uintptr_t addr ) { return (FT *)addr; } 99 99 … … 156 156 #define __CFA_EXP_OVERFLOW__() 157 157 158 static inline forall( otypeOT | { void ?{}( OT & this, one_t ); OT ?*?( OT, OT ); } ) {158 static inline forall( OT | { void ?{}( OT & this, one_t ); OT ?*?( OT, OT ); } ) { 159 159 OT ?\?( OT ep, unsigned int y ) { __CFA_EXP__(); } 160 160 OT ?\?( OT ep, unsigned long int y ) { __CFA_EXP__(); } -
libcfa/prelude/prelude-gen.cc
r92bfda0 rdafbde8 159 159 int main() { 160 160 cout << "# 2 \"prelude.cfa\" // needed for error messages from this file" << endl; 161 cout << "trait sized( dtype T) {};" << endl;161 cout << "trait sized(T &) {};" << endl; 162 162 163 163 cout << "//////////////////////////" << endl; … … 264 264 for (auto cvq : qualifiersPair) { 265 265 for (auto is_vol : { " ", "volatile" }) { 266 cout << "forall( dtype DT) void ?{}(" << cvq.first << type << " * " << is_vol << " &, " << cvq.second << "DT *);" << endl;266 cout << "forall(DT &) void ?{}(" << cvq.first << type << " * " << is_vol << " &, " << cvq.second << "DT *);" << endl; 267 267 } 268 268 } … … 279 279 for (auto cvq : qualifiersSingle) { 280 280 for (auto is_vol : { " ", "volatile" }) { 281 cout << "forall( dtype DT) void ?{}(" << cvq << " DT" << " * " << is_vol << " &);" << endl;281 cout << "forall(DT &) void ?{}(" << cvq << " DT" << " * " << is_vol << " &);" << endl; 282 282 } 283 283 for (auto is_vol : { " ", "volatile" }) { 284 cout << "forall( dtype DT) void ^?{}(" << cvq << " DT" << " * " << is_vol << " &);" << endl;284 cout << "forall(DT &) void ^?{}(" << cvq << " DT" << " * " << is_vol << " &);" << endl; 285 285 } 286 286 } … … 290 290 for (auto is_vol : { " ", "volatile" }) { 291 291 for (auto cvq : qualifiersSingle) { 292 cout << "forall( dtype DT) void ?{}( " << cvq << type << " * " << is_vol << " &, zero_t);" << endl;292 cout << "forall(DT &) void ?{}( " << cvq << type << " * " << is_vol << " &, zero_t);" << endl; 293 293 } 294 294 } … … 317 317 for (auto op : pointerOperators) { 318 318 auto forall = [&op]() { 319 cout << "forall( dtype DT" << op.sized << ") ";319 cout << "forall(DT &" << op.sized << ") "; 320 320 }; 321 321 for (auto type : { "DT"/*, "void"*/ } ) { … … 408 408 for (auto is_vol : { " ", "volatile" }) { 409 409 for (auto cvq : qualifiersPair) { 410 cout << "forall( dtype DT) " << cvq.first << "void * ?=?( " << cvq.first << "void * " << is_vol << " &, " << cvq.second << "DT *);" << endl;410 cout << "forall(DT &) " << cvq.first << "void * ?=?( " << cvq.first << "void * " << is_vol << " &, " << cvq.second << "DT *);" << endl; 411 411 } 412 412 for (auto cvq : qualifiersSingle) { 413 cout << "forall( dtype DT) " << cvq << " DT * ?=?( " << cvq << " DT * " << is_vol << " &, zero_t);" << endl;413 cout << "forall(DT &) " << cvq << " DT * ?=?( " << cvq << " DT * " << is_vol << " &, zero_t);" << endl; 414 414 } 415 415 } -
libcfa/prelude/prelude.old.cf
r92bfda0 rdafbde8 23 23 // ------------------------------------------------------------ 24 24 25 trait sized( dtype T) {};25 trait sized(T &) {}; 26 26 27 27 // ------------------------------------------------------------ … … 68 68 long double _Complex ?--( long double _Complex & ), ?--( volatile long double _Complex & ); 69 69 70 forall( dtype T| sized(T) ) T * ?++( T *& );71 forall( dtype T| sized(T) ) const T * ?++( const T *& );72 forall( dtype T| sized(T) ) volatile T * ?++( volatile T *& );73 forall( dtype T| sized(T) ) const volatile T * ?++( const volatile T *& );74 forall( dtype T| sized(T) ) T * ?--( T *& );75 forall( dtype T| sized(T) ) const T * ?--( const T *& );76 forall( dtype T| sized(T) ) volatile T * ?--( volatile T *& );77 forall( dtype T| sized(T) ) const volatile T * ?--( const volatile T *& );78 79 forall( dtype T| sized(T) ) T & ?[?]( T *, ptrdiff_t );80 forall( dtype T| sized(T) ) const T & ?[?]( const T *, ptrdiff_t );81 forall( dtype T| sized(T) ) volatile T & ?[?]( volatile T *, ptrdiff_t );82 forall( dtype T| sized(T) ) const volatile T & ?[?]( const volatile T *, ptrdiff_t );83 forall( dtype T| sized(T) ) T & ?[?]( ptrdiff_t, T * );84 forall( dtype T| sized(T) ) const T & ?[?]( ptrdiff_t, const T * );85 forall( dtype T| sized(T) ) volatile T & ?[?]( ptrdiff_t, volatile T * );86 forall( dtype T| sized(T) ) const volatile T & ?[?]( ptrdiff_t, const volatile T * );70 forall( T & | sized(T) ) T * ?++( T *& ); 71 forall( T & | sized(T) ) const T * ?++( const T *& ); 72 forall( T & | sized(T) ) volatile T * ?++( volatile T *& ); 73 forall( T & | sized(T) ) const volatile T * ?++( const volatile T *& ); 74 forall( T & | sized(T) ) T * ?--( T *& ); 75 forall( T & | sized(T) ) const T * ?--( const T *& ); 76 forall( T & | sized(T) ) volatile T * ?--( volatile T *& ); 77 forall( T & | sized(T) ) const volatile T * ?--( const volatile T *& ); 78 79 forall( T & | sized(T) ) T & ?[?]( T *, ptrdiff_t ); 80 forall( T & | sized(T) ) const T & ?[?]( const T *, ptrdiff_t ); 81 forall( T & | sized(T) ) volatile T & ?[?]( volatile T *, ptrdiff_t ); 82 forall( T & | sized(T) ) const volatile T & ?[?]( const volatile T *, ptrdiff_t ); 83 forall( T & | sized(T) ) T & ?[?]( ptrdiff_t, T * ); 84 forall( T & | sized(T) ) const T & ?[?]( ptrdiff_t, const T * ); 85 forall( T & | sized(T) ) volatile T & ?[?]( ptrdiff_t, volatile T * ); 86 forall( T & | sized(T) ) const volatile T & ?[?]( ptrdiff_t, const volatile T * ); 87 87 88 88 // ------------------------------------------------------------ … … 107 107 long double _Complex ++?( long double _Complex & ), --?( long double _Complex & ); 108 108 109 forall( dtype T| sized(T) ) T * ++?( T *& );110 forall( dtype T| sized(T) ) const T * ++?( const T *& );111 forall( dtype T| sized(T) ) volatile T * ++?( volatile T *& );112 forall( dtype T| sized(T) ) const volatile T * ++?( const volatile T *& );113 forall( dtype T| sized(T) ) T * --?( T *& );114 forall( dtype T| sized(T) ) const T * --?( const T *& );115 forall( dtype T| sized(T) ) volatile T * --?( volatile T *& );116 forall( dtype T| sized(T) ) const volatile T * --?( const volatile T *& );117 118 forall( dtype T| sized(T) ) T & *?( T * );119 forall( dtype T| sized(T) ) const T & *?( const T * );120 forall( dtype T| sized(T) ) volatile T & *?( volatile T * );121 forall( dtype T| sized(T) ) const volatile T & *?( const volatile T * );109 forall( T & | sized(T) ) T * ++?( T *& ); 110 forall( T & | sized(T) ) const T * ++?( const T *& ); 111 forall( T & | sized(T) ) volatile T * ++?( volatile T *& ); 112 forall( T & | sized(T) ) const volatile T * ++?( const volatile T *& ); 113 forall( T & | sized(T) ) T * --?( T *& ); 114 forall( T & | sized(T) ) const T * --?( const T *& ); 115 forall( T & | sized(T) ) volatile T * --?( volatile T *& ); 116 forall( T & | sized(T) ) const volatile T * --?( const volatile T *& ); 117 118 forall( T & | sized(T) ) T & *?( T * ); 119 forall( T & | sized(T) ) const T & *?( const T * ); 120 forall( T & | sized(T) ) volatile T & *?( volatile T * ); 121 forall( T & | sized(T) ) const volatile T & *?( const volatile T * ); 122 122 forall( ftype FT ) FT & *?( FT * ); 123 123 … … 142 142 !?( float _Complex ), !?( double _Complex ), !?( long double _Complex ); 143 143 144 forall( dtype DT) int !?( DT * );145 forall( dtype DT) int !?( const DT * );146 forall( dtype DT) int !?( volatile DT * );147 forall( dtype DT) int !?( const volatile DT * );144 forall( DT & ) int !?( DT * ); 145 forall( DT & ) int !?( const DT * ); 146 forall( DT & ) int !?( volatile DT * ); 147 forall( DT & ) int !?( const volatile DT * ); 148 148 forall( ftype FT ) int !?( FT * ); 149 149 … … 191 191 long double _Complex ?+?( long double _Complex, long double _Complex ), ?-?( long double _Complex, long double _Complex ); 192 192 193 forall( dtype T| sized(T) ) T * ?+?( T *, ptrdiff_t );194 forall( dtype T| sized(T) ) T * ?+?( ptrdiff_t, T * );195 forall( dtype T| sized(T) ) const T * ?+?( const T *, ptrdiff_t );196 forall( dtype T| sized(T) ) const T * ?+?( ptrdiff_t, const T * );197 forall( dtype T| sized(T) ) volatile T * ?+?( volatile T *, ptrdiff_t );198 forall( dtype T| sized(T) ) volatile T * ?+?( ptrdiff_t, volatile T * );199 forall( dtype T| sized(T) ) const volatile T * ?+?( const volatile T *, ptrdiff_t );200 forall( dtype T| sized(T) ) const volatile T * ?+?( ptrdiff_t, const volatile T * );201 forall( dtype T| sized(T) ) T * ?-?( T *, ptrdiff_t );202 forall( dtype T| sized(T) ) const T * ?-?( const T *, ptrdiff_t );203 forall( dtype T| sized(T) ) volatile T * ?-?( volatile T *, ptrdiff_t );204 forall( dtype T| sized(T) ) const volatile T * ?-?( const volatile T *, ptrdiff_t );205 forall( dtype T| sized(T) ) ptrdiff_t ?-?( const volatile T *, const volatile T * );193 forall( T & | sized(T) ) T * ?+?( T *, ptrdiff_t ); 194 forall( T & | sized(T) ) T * ?+?( ptrdiff_t, T * ); 195 forall( T & | sized(T) ) const T * ?+?( const T *, ptrdiff_t ); 196 forall( T & | sized(T) ) const T * ?+?( ptrdiff_t, const T * ); 197 forall( T & | sized(T) ) volatile T * ?+?( volatile T *, ptrdiff_t ); 198 forall( T & | sized(T) ) volatile T * ?+?( ptrdiff_t, volatile T * ); 199 forall( T & | sized(T) ) const volatile T * ?+?( const volatile T *, ptrdiff_t ); 200 forall( T & | sized(T) ) const volatile T * ?+?( ptrdiff_t, const volatile T * ); 201 forall( T & | sized(T) ) T * ?-?( T *, ptrdiff_t ); 202 forall( T & | sized(T) ) const T * ?-?( const T *, ptrdiff_t ); 203 forall( T & | sized(T) ) volatile T * ?-?( volatile T *, ptrdiff_t ); 204 forall( T & | sized(T) ) const volatile T * ?-?( const volatile T *, ptrdiff_t ); 205 forall( T & | sized(T) ) ptrdiff_t ?-?( const volatile T *, const volatile T * ); 206 206 207 207 // ------------------------------------------------------------ … … 255 255 ?>?( long double, long double ), ?>=?( long double, long double ); 256 256 257 forall( dtype DT) signed int ?<?( DT *, DT * );258 forall( dtype DT) signed int ?<?( const DT *, const DT * );259 forall( dtype DT) signed int ?<?( volatile DT *, volatile DT * );260 forall( dtype DT) signed int ?<?( const volatile DT *, const volatile DT * );261 262 forall( dtype DT) signed int ?>?( DT *, DT * );263 forall( dtype DT) signed int ?>?( const DT *, const DT * );264 forall( dtype DT) signed int ?>?( volatile DT *, volatile DT * );265 forall( dtype DT) signed int ?>?( const volatile DT *, const volatile DT * );266 267 forall( dtype DT) signed int ?<=?( DT *, DT * );268 forall( dtype DT) signed int ?<=?( const DT *, const DT * );269 forall( dtype DT) signed int ?<=?( volatile DT *, volatile DT * );270 forall( dtype DT) signed int ?<=?( const volatile DT *, const volatile DT * );271 272 forall( dtype DT) signed int ?>=?( DT *, DT * );273 forall( dtype DT) signed int ?>=?( const DT *, const DT * );274 forall( dtype DT) signed int ?>=?( volatile DT *, volatile DT * );275 forall( dtype DT) signed int ?>=?( const volatile DT *, const volatile DT * );257 forall( DT & ) signed int ?<?( DT *, DT * ); 258 forall( DT & ) signed int ?<?( const DT *, const DT * ); 259 forall( DT & ) signed int ?<?( volatile DT *, volatile DT * ); 260 forall( DT & ) signed int ?<?( const volatile DT *, const volatile DT * ); 261 262 forall( DT & ) signed int ?>?( DT *, DT * ); 263 forall( DT & ) signed int ?>?( const DT *, const DT * ); 264 forall( DT & ) signed int ?>?( volatile DT *, volatile DT * ); 265 forall( DT & ) signed int ?>?( const volatile DT *, const volatile DT * ); 266 267 forall( DT & ) signed int ?<=?( DT *, DT * ); 268 forall( DT & ) signed int ?<=?( const DT *, const DT * ); 269 forall( DT & ) signed int ?<=?( volatile DT *, volatile DT * ); 270 forall( DT & ) signed int ?<=?( const volatile DT *, const volatile DT * ); 271 272 forall( DT & ) signed int ?>=?( DT *, DT * ); 273 forall( DT & ) signed int ?>=?( const DT *, const DT * ); 274 forall( DT & ) signed int ?>=?( volatile DT *, volatile DT * ); 275 forall( DT & ) signed int ?>=?( const volatile DT *, const volatile DT * ); 276 276 277 277 // ------------------------------------------------------------ … … 302 302 signed int ?==?( one_t, one_t ), ?!=?( one_t, one_t ); 303 303 304 forall( dtype DT) signed int ?==?( DT *, DT * );305 forall( dtype DT) signed int ?==?( const DT *, const DT * );306 forall( dtype DT) signed int ?==?( volatile DT *, volatile DT * );307 forall( dtype DT) signed int ?==?( const volatile DT *, const volatile DT * );304 forall( DT & ) signed int ?==?( DT *, DT * ); 305 forall( DT & ) signed int ?==?( const DT *, const DT * ); 306 forall( DT & ) signed int ?==?( volatile DT *, volatile DT * ); 307 forall( DT & ) signed int ?==?( const volatile DT *, const volatile DT * ); 308 308 forall( ftype FT ) signed int ?==?( FT *, FT * ); 309 forall( dtype DT) signed int ?!=?( DT *, DT * );310 forall( dtype DT) signed int ?!=?( const DT *, const DT * );311 forall( dtype DT) signed int ?!=?( volatile DT *, volatile DT * );312 forall( dtype DT) signed int ?!=?( const volatile DT *, const volatile DT * );309 forall( DT & ) signed int ?!=?( DT *, DT * ); 310 forall( DT & ) signed int ?!=?( const DT *, const DT * ); 311 forall( DT & ) signed int ?!=?( volatile DT *, volatile DT * ); 312 forall( DT & ) signed int ?!=?( const volatile DT *, const volatile DT * ); 313 313 forall( ftype FT ) signed int ?!=?( FT *, FT * ); 314 314 … … 376 376 377 377 forall( ftype FT ) FT * ?=?( FT *&, FT * ); 378 forall( fty peFT ) FT * ?=?( FT * volatile &, FT * );379 380 forall( dtype DT) DT * ?=?( DT * &, DT * );381 forall( dtype DT) DT * ?=?( DT * volatile &, DT * );382 forall( dtype DT) const DT * ?=?( const DT * &, DT * );383 forall( dtype DT) const DT * ?=?( const DT * volatile &, DT * );384 forall( dtype DT) const DT * ?=?( const DT * &, const DT * );385 forall( dtype DT) const DT * ?=?( const DT * volatile &, const DT * );386 forall( dtype DT) volatile DT * ?=?( volatile DT * &, DT * );387 forall( dtype DT) volatile DT * ?=?( volatile DT * volatile &, DT * );388 forall( dtype DT) volatile DT * ?=?( volatile DT * &, volatile DT * );389 forall( dtype DT) volatile DT * ?=?( volatile DT * volatile &, volatile DT * );390 391 forall( dtype DT) const volatile DT * ?=?( const volatile DT * &, DT * );392 forall( dtype DT) const volatile DT * ?=?( const volatile DT * volatile &, DT * );393 forall( dtype DT) const volatile DT * ?=?( const volatile DT * &, const DT * );394 forall( dtype DT) const volatile DT * ?=?( const volatile DT * volatile &, const DT * );395 forall( dtype DT) const volatile DT * ?=?( const volatile DT * &, volatile DT * );396 forall( dtype DT) const volatile DT * ?=?( const volatile DT * volatile &, volatile DT * );397 forall( dtype DT) const volatile DT * ?=?( const volatile DT * &, const volatile DT * );398 forall( dtype DT) const volatile DT * ?=?( const volatile DT * volatile &, const volatile DT * );399 400 forall( dtype DT) void * ?=?( void * &, DT * );401 forall( dtype DT) void * ?=?( void * volatile &, DT * );402 forall( dtype DT) const void * ?=?( const void * &, DT * );403 forall( dtype DT) const void * ?=?( const void * volatile &, DT * );404 forall( dtype DT) const void * ?=?( const void * &, const DT * );405 forall( dtype DT) const void * ?=?( const void * volatile &, const DT * );406 forall( dtype DT) volatile void * ?=?( volatile void * &, DT * );407 forall( dtype DT) volatile void * ?=?( volatile void * volatile &, DT * );408 forall( dtype DT) volatile void * ?=?( volatile void * &, volatile DT * );409 forall( dtype DT) volatile void * ?=?( volatile void * volatile &, volatile DT * );410 forall( dtype DT) const volatile void * ?=?( const volatile void * &, DT * );411 forall( dtype DT) const volatile void * ?=?( const volatile void * volatile &, DT * );412 forall( dtype DT) const volatile void * ?=?( const volatile void * &, const DT * );413 forall( dtype DT) const volatile void * ?=?( const volatile void * volatile &, const DT * );414 forall( dtype DT) const volatile void * ?=?( const volatile void * &, volatile DT * );415 forall( dtype DT) const volatile void * ?=?( const volatile void * volatile &, volatile DT * );416 forall( dtype DT) const volatile void * ?=?( const volatile void * &, const volatile DT * );417 forall( dtype DT) const volatile void * ?=?( const volatile void * volatile &, const volatile DT * );378 forall( ftyep FT ) FT * ?=?( FT * volatile &, FT * ); 379 380 forall( DT & ) DT * ?=?( DT * &, DT * ); 381 forall( DT & ) DT * ?=?( DT * volatile &, DT * ); 382 forall( DT & ) const DT * ?=?( const DT * &, DT * ); 383 forall( DT & ) const DT * ?=?( const DT * volatile &, DT * ); 384 forall( DT & ) const DT * ?=?( const DT * &, const DT * ); 385 forall( DT & ) const DT * ?=?( const DT * volatile &, const DT * ); 386 forall( DT & ) volatile DT * ?=?( volatile DT * &, DT * ); 387 forall( DT & ) volatile DT * ?=?( volatile DT * volatile &, DT * ); 388 forall( DT & ) volatile DT * ?=?( volatile DT * &, volatile DT * ); 389 forall( DT & ) volatile DT * ?=?( volatile DT * volatile &, volatile DT * ); 390 391 forall( DT & ) const volatile DT * ?=?( const volatile DT * &, DT * ); 392 forall( DT & ) const volatile DT * ?=?( const volatile DT * volatile &, DT * ); 393 forall( DT & ) const volatile DT * ?=?( const volatile DT * &, const DT * ); 394 forall( DT & ) const volatile DT * ?=?( const volatile DT * volatile &, const DT * ); 395 forall( DT & ) const volatile DT * ?=?( const volatile DT * &, volatile DT * ); 396 forall( DT & ) const volatile DT * ?=?( const volatile DT * volatile &, volatile DT * ); 397 forall( DT & ) const volatile DT * ?=?( const volatile DT * &, const volatile DT * ); 398 forall( DT & ) const volatile DT * ?=?( const volatile DT * volatile &, const volatile DT * ); 399 400 forall( DT & ) void * ?=?( void * &, DT * ); 401 forall( DT & ) void * ?=?( void * volatile &, DT * ); 402 forall( DT & ) const void * ?=?( const void * &, DT * ); 403 forall( DT & ) const void * ?=?( const void * volatile &, DT * ); 404 forall( DT & ) const void * ?=?( const void * &, const DT * ); 405 forall( DT & ) const void * ?=?( const void * volatile &, const DT * ); 406 forall( DT & ) volatile void * ?=?( volatile void * &, DT * ); 407 forall( DT & ) volatile void * ?=?( volatile void * volatile &, DT * ); 408 forall( DT & ) volatile void * ?=?( volatile void * &, volatile DT * ); 409 forall( DT & ) volatile void * ?=?( volatile void * volatile &, volatile DT * ); 410 forall( DT & ) const volatile void * ?=?( const volatile void * &, DT * ); 411 forall( DT & ) const volatile void * ?=?( const volatile void * volatile &, DT * ); 412 forall( DT & ) const volatile void * ?=?( const volatile void * &, const DT * ); 413 forall( DT & ) const volatile void * ?=?( const volatile void * volatile &, const DT * ); 414 forall( DT & ) const volatile void * ?=?( const volatile void * &, volatile DT * ); 415 forall( DT & ) const volatile void * ?=?( const volatile void * volatile &, volatile DT * ); 416 forall( DT & ) const volatile void * ?=?( const volatile void * &, const volatile DT * ); 417 forall( DT & ) const volatile void * ?=?( const volatile void * volatile &, const volatile DT * ); 418 418 419 419 //forall( dtype DT ) DT * ?=?( DT * &, zero_t ); 420 420 //forall( dtype DT ) DT * ?=?( DT * volatile &, zero_t ); 421 forall( dtype DT) const DT * ?=?( const DT * &, zero_t );422 forall( dtype DT) const DT * ?=?( const DT * volatile &, zero_t );421 forall( DT & ) const DT * ?=?( const DT * &, zero_t ); 422 forall( DT & ) const DT * ?=?( const DT * volatile &, zero_t ); 423 423 //forall( dtype DT ) volatile DT * ?=?( volatile DT * &, zero_t ); 424 424 //forall( dtype DT ) volatile DT * ?=?( volatile DT * volatile &, zero_t ); 425 forall( dtype DT) const volatile DT * ?=?( const volatile DT * &, zero_t );426 forall( dtype DT) const volatile DT * ?=?( const volatile DT * volatile &, zero_t );425 forall( DT & ) const volatile DT * ?=?( const volatile DT * &, zero_t ); 426 forall( DT & ) const volatile DT * ?=?( const volatile DT * volatile &, zero_t ); 427 427 428 428 forall( ftype FT ) FT * ?=?( FT * &, zero_t ); 429 429 forall( ftype FT ) FT * ?=?( FT * volatile &, zero_t ); 430 430 431 forall( dtype T| sized(T) ) T * ?+=?( T * &, ptrdiff_t );432 forall( dtype T| sized(T) ) T * ?+=?( T * volatile &, ptrdiff_t );433 forall( dtype T| sized(T) ) const T * ?+=?( const T * &, ptrdiff_t );434 forall( dtype T| sized(T) ) const T * ?+=?( const T * volatile &, ptrdiff_t );435 forall( dtype T| sized(T) ) volatile T * ?+=?( volatile T * &, ptrdiff_t );436 forall( dtype T| sized(T) ) volatile T * ?+=?( volatile T * volatile &, ptrdiff_t );437 forall( dtype T| sized(T) ) const volatile T * ?+=?( const volatile T * &, ptrdiff_t );438 forall( dtype T| sized(T) ) const volatile T * ?+=?( const volatile T * volatile &, ptrdiff_t );439 forall( dtype T| sized(T) ) T * ?-=?( T * &, ptrdiff_t );440 forall( dtype T| sized(T) ) T * ?-=?( T * volatile &, ptrdiff_t );441 forall( dtype T| sized(T) ) const T * ?-=?( const T * &, ptrdiff_t );442 forall( dtype T| sized(T) ) const T * ?-=?( const T * volatile &, ptrdiff_t );443 forall( dtype T| sized(T) ) volatile T * ?-=?( volatile T * &, ptrdiff_t );444 forall( dtype T| sized(T) ) volatile T * ?-=?( volatile T * volatile &, ptrdiff_t );445 forall( dtype T| sized(T) ) const volatile T * ?-=?( const volatile T * &, ptrdiff_t );446 forall( dtype T| sized(T) ) const volatile T * ?-=?( const volatile T * volatile &, ptrdiff_t );431 forall( T & | sized(T) ) T * ?+=?( T * &, ptrdiff_t ); 432 forall( T & | sized(T) ) T * ?+=?( T * volatile &, ptrdiff_t ); 433 forall( T & | sized(T) ) const T * ?+=?( const T * &, ptrdiff_t ); 434 forall( T & | sized(T) ) const T * ?+=?( const T * volatile &, ptrdiff_t ); 435 forall( T & | sized(T) ) volatile T * ?+=?( volatile T * &, ptrdiff_t ); 436 forall( T & | sized(T) ) volatile T * ?+=?( volatile T * volatile &, ptrdiff_t ); 437 forall( T & | sized(T) ) const volatile T * ?+=?( const volatile T * &, ptrdiff_t ); 438 forall( T & | sized(T) ) const volatile T * ?+=?( const volatile T * volatile &, ptrdiff_t ); 439 forall( T & | sized(T) ) T * ?-=?( T * &, ptrdiff_t ); 440 forall( T & | sized(T) ) T * ?-=?( T * volatile &, ptrdiff_t ); 441 forall( T & | sized(T) ) const T * ?-=?( const T * &, ptrdiff_t ); 442 forall( T & | sized(T) ) const T * ?-=?( const T * volatile &, ptrdiff_t ); 443 forall( T & | sized(T) ) volatile T * ?-=?( volatile T * &, ptrdiff_t ); 444 forall( T & | sized(T) ) volatile T * ?-=?( volatile T * volatile &, ptrdiff_t ); 445 forall( T & | sized(T) ) const volatile T * ?-=?( const volatile T * &, ptrdiff_t ); 446 forall( T & | sized(T) ) const volatile T * ?-=?( const volatile T * volatile &, ptrdiff_t ); 447 447 448 448 _Bool ?=?( _Bool &, _Bool ), ?=?( volatile _Bool &, _Bool ); … … 723 723 forall( ftype FT ) void ?{}( FT * volatile &, FT * ); 724 724 725 forall( dtype DT) void ?{}( DT * &, DT * );726 forall( dtype DT) void ?{}( const DT * &, DT * );727 forall( dtype DT) void ?{}( const DT * &, const DT * );728 forall( dtype DT) void ?{}( volatile DT * &, DT * );729 forall( dtype DT) void ?{}( volatile DT * &, volatile DT * );730 forall( dtype DT) void ?{}( const volatile DT * &, DT * );731 forall( dtype DT) void ?{}( const volatile DT * &, const DT * );732 forall( dtype DT) void ?{}( const volatile DT * &, volatile DT * );733 forall( dtype DT) void ?{}( const volatile DT * &, const volatile DT * );734 735 forall( dtype DT) void ?{}( void * &, DT * );736 forall( dtype DT) void ?{}( const void * &, DT * );737 forall( dtype DT) void ?{}( const void * &, const DT * );738 forall( dtype DT) void ?{}( volatile void * &, DT * );739 forall( dtype DT) void ?{}( volatile void * &, volatile DT * );740 forall( dtype DT) void ?{}( const volatile void * &, DT * );741 forall( dtype DT) void ?{}( const volatile void * &, const DT * );742 forall( dtype DT) void ?{}( const volatile void * &, volatile DT * );743 forall( dtype DT) void ?{}( const volatile void * &, const volatile DT * );725 forall( DT & ) void ?{}( DT * &, DT * ); 726 forall( DT & ) void ?{}( const DT * &, DT * ); 727 forall( DT & ) void ?{}( const DT * &, const DT * ); 728 forall( DT & ) void ?{}( volatile DT * &, DT * ); 729 forall( DT & ) void ?{}( volatile DT * &, volatile DT * ); 730 forall( DT & ) void ?{}( const volatile DT * &, DT * ); 731 forall( DT & ) void ?{}( const volatile DT * &, const DT * ); 732 forall( DT & ) void ?{}( const volatile DT * &, volatile DT * ); 733 forall( DT & ) void ?{}( const volatile DT * &, const volatile DT * ); 734 735 forall( DT & ) void ?{}( void * &, DT * ); 736 forall( DT & ) void ?{}( const void * &, DT * ); 737 forall( DT & ) void ?{}( const void * &, const DT * ); 738 forall( DT & ) void ?{}( volatile void * &, DT * ); 739 forall( DT & ) void ?{}( volatile void * &, volatile DT * ); 740 forall( DT & ) void ?{}( const volatile void * &, DT * ); 741 forall( DT & ) void ?{}( const volatile void * &, const DT * ); 742 forall( DT & ) void ?{}( const volatile void * &, volatile DT * ); 743 forall( DT & ) void ?{}( const volatile void * &, const volatile DT * ); 744 744 745 745 //forall( dtype DT ) void ?{}( DT * &, zero_t ); 746 746 //forall( dtype DT ) void ?{}( DT * volatile &, zero_t ); 747 forall( dtype DT) void ?{}( const DT * &, zero_t );747 forall( DT & ) void ?{}( const DT * &, zero_t ); 748 748 //forall( dtype DT ) void ?{}( volatile DT * &, zero_t ); 749 749 //forall( dtype DT ) void ?{}( volatile DT * volatile &, zero_t ); 750 forall( dtype DT) void ?{}( const volatile DT * &, zero_t );750 forall( DT & ) void ?{}( const volatile DT * &, zero_t ); 751 751 752 752 forall( ftype FT ) void ?{}( FT * &, zero_t ); … … 755 755 forall( ftype FT ) void ?{}( FT * & ); 756 756 757 forall( dtype DT) void ?{}( DT * &);758 forall( dtype DT) void ?{}( const DT * &);759 forall( dtype DT) void ?{}( volatile DT * &);760 forall( dtype DT) void ?{}( const volatile DT * &);757 forall( DT & ) void ?{}( DT * &); 758 forall( DT & ) void ?{}( const DT * &); 759 forall( DT & ) void ?{}( volatile DT * &); 760 forall( DT & ) void ?{}( const volatile DT * &); 761 761 762 762 void ?{}( void * &); … … 768 768 forall( ftype FT ) void ^?{}( FT * & ); 769 769 770 forall( dtype DT) void ^?{}( DT * &);771 forall( dtype DT) void ^?{}( const DT * &);772 forall( dtype DT) void ^?{}( volatile DT * &);773 forall( dtype DT) void ^?{}( const volatile DT * &);770 forall( DT & ) void ^?{}( DT * &); 771 forall( DT & ) void ^?{}( const DT * &); 772 forall( DT & ) void ^?{}( volatile DT * &); 773 forall( DT & ) void ^?{}( const volatile DT * &); 774 774 775 775 void ^?{}( void * &); -
libcfa/prelude/sync-builtins.cf
r92bfda0 rdafbde8 206 206 _Bool __sync_bool_compare_and_swap(volatile unsigned __int128 *, unsigned __int128, unsigned __int128,...); 207 207 #endif 208 forall( dtype T) _Bool __sync_bool_compare_and_swap(T * volatile *, T *, T*, ...);208 forall(T &) _Bool __sync_bool_compare_and_swap(T * volatile *, T *, T*, ...); 209 209 210 210 char __sync_val_compare_and_swap(volatile char *, char, char,...); … … 223 223 unsigned __int128 __sync_val_compare_and_swap(volatile unsigned __int128 *, unsigned __int128, unsigned __int128,...); 224 224 #endif 225 forall( dtype T) T * __sync_val_compare_and_swap(T * volatile *, T *, T*,...);225 forall(T &) T * __sync_val_compare_and_swap(T * volatile *, T *, T*,...); 226 226 227 227 char __sync_lock_test_and_set(volatile char *, char,...); … … 326 326 void __atomic_exchange(volatile unsigned __int128 *, volatile unsigned __int128 *, volatile unsigned __int128 *, int); 327 327 #endif 328 forall( dtype T) T * __atomic_exchange_n(T * volatile *, T *, int);329 forall( dtype T) void __atomic_exchange(T * volatile *, T * volatile *, T * volatile *, int);328 forall(T &) T * __atomic_exchange_n(T * volatile *, T *, int); 329 forall(T &) void __atomic_exchange(T * volatile *, T * volatile *, T * volatile *, int); 330 330 331 331 _Bool __atomic_load_n(const volatile _Bool *, int); … … 359 359 void __atomic_load(const volatile unsigned __int128 *, volatile unsigned __int128 *, int); 360 360 #endif 361 forall( dtype T) T * __atomic_load_n(T * const volatile *, int);362 forall( dtype T) void __atomic_load(T * const volatile *, T **, int);361 forall(T &) T * __atomic_load_n(T * const volatile *, int); 362 forall(T &) void __atomic_load(T * const volatile *, T **, int); 363 363 364 364 _Bool __atomic_compare_exchange_n(volatile char *, char *, char, _Bool, int, int); … … 390 390 _Bool __atomic_compare_exchange (volatile unsigned __int128 *, unsigned __int128 *, unsigned __int128 *, _Bool, int, int); 391 391 #endif 392 forall( dtype T) _Bool __atomic_compare_exchange_n (T * volatile *, T **, T*, _Bool, int, int);393 forall( dtype T) _Bool __atomic_compare_exchange (T * volatile *, T **, T**, _Bool, int, int);392 forall(T &) _Bool __atomic_compare_exchange_n (T * volatile *, T **, T*, _Bool, int, int); 393 forall(T &) _Bool __atomic_compare_exchange (T * volatile *, T **, T**, _Bool, int, int); 394 394 395 395 void __atomic_store_n(volatile _Bool *, _Bool, int); … … 423 423 void __atomic_store(volatile unsigned __int128 *, unsigned __int128 *, int); 424 424 #endif 425 forall( dtype T) void __atomic_store_n(T * volatile *, T *, int);426 forall( dtype T) void __atomic_store(T * volatile *, T **, int);425 forall(T &) void __atomic_store_n(T * volatile *, T *, int); 426 forall(T &) void __atomic_store(T * volatile *, T **, int); 427 427 428 428 char __atomic_add_fetch (volatile char *, char, int); -
libcfa/src/bitmanip.hfa
r92bfda0 rdafbde8 100 100 unsigned long long int floor2( unsigned long long int n, unsigned long long int align ) { verify( is_pow2( align ) ); return n & -align; } 101 101 102 // forall( otypeT | { T ?&?( T, T ); T -?( T ); } )102 // forall( T | { T ?&?( T, T ); T -?( T ); } ) 103 103 // T floor2( T n, T align ) { verify( is_pow2( align ) ); return n & -align; } 104 104 … … 115 115 unsigned long long int ceiling2( unsigned long long int n, unsigned long long int align ) { verify( is_pow2( align ) ); return -floor2( -n, align ); } 116 116 117 // forall( otypeT | { T floor2( T, T ); T -?( T ); } )117 // forall( T | { T floor2( T, T ); T -?( T ); } ) 118 118 // T ceiling2( T n, T align ) { verify( is_pow2( align ) ); return -floor2( -n, align ); } 119 119 } // distribution -
libcfa/src/bits/algorithm.hfa
r92bfda0 rdafbde8 17 17 18 18 #ifdef SAFE_SORT 19 forall( otypeT | { int ?<?( T, T ); int ?>?( T, T ); } ) static inline void __libcfa_small_sort2( T * arr );20 forall( otypeT | { int ?<?( T, T ); int ?>?( T, T ); } ) static inline void __libcfa_small_sort3( T * arr );21 forall( otypeT | { int ?<?( T, T ); int ?>?( T, T ); } ) static inline void __libcfa_small_sort4( T * arr );22 forall( otypeT | { int ?<?( T, T ); int ?>?( T, T ); } ) static inline void __libcfa_small_sort5( T * arr );23 forall( otypeT | { int ?<?( T, T ); int ?>?( T, T ); } ) static inline void __libcfa_small_sort6( T * arr );24 forall( otypeT | { int ?<?( T, T ); int ?>?( T, T ); } ) static inline void __libcfa_small_sortN( T * arr, size_t dim );19 forall( T | { int ?<?( T, T ); int ?>?( T, T ); } ) static inline void __libcfa_small_sort2( T * arr ); 20 forall( T | { int ?<?( T, T ); int ?>?( T, T ); } ) static inline void __libcfa_small_sort3( T * arr ); 21 forall( T | { int ?<?( T, T ); int ?>?( T, T ); } ) static inline void __libcfa_small_sort4( T * arr ); 22 forall( T | { int ?<?( T, T ); int ?>?( T, T ); } ) static inline void __libcfa_small_sort5( T * arr ); 23 forall( T | { int ?<?( T, T ); int ?>?( T, T ); } ) static inline void __libcfa_small_sort6( T * arr ); 24 forall( T | { int ?<?( T, T ); int ?>?( T, T ); } ) static inline void __libcfa_small_sortN( T * arr, size_t dim ); 25 25 26 forall( otypeT | { int ?<?( T, T ); int ?>?( T, T ); } )26 forall( T | { int ?<?( T, T ); int ?>?( T, T ); } ) 27 27 static inline void __libcfa_small_sort( T * arr, size_t dim ) { 28 28 switch( dim ) { … … 41 41 #define SWAP(x,y) { T a = min(arr[x], arr[y]); T b = max(arr[x], arr[y]); arr[x] = a; arr[y] = b;} 42 42 43 forall( otypeT | { int ?<?( T, T ); int ?>?( T, T ); } )43 forall( T | { int ?<?( T, T ); int ?>?( T, T ); } ) 44 44 static inline void __libcfa_small_sort2( T * arr ) { 45 45 SWAP(0, 1); 46 46 } 47 47 48 forall( otypeT | { int ?<?( T, T ); int ?>?( T, T ); } )48 forall( T | { int ?<?( T, T ); int ?>?( T, T ); } ) 49 49 static inline void __libcfa_small_sort3( T * arr ) { 50 50 SWAP(1, 2); … … 53 53 } 54 54 55 forall( otypeT | { int ?<?( T, T ); int ?>?( T, T ); } )55 forall( T | { int ?<?( T, T ); int ?>?( T, T ); } ) 56 56 static inline void __libcfa_small_sort4( T * arr ) { 57 57 SWAP(0, 1); … … 62 62 } 63 63 64 forall( otypeT | { int ?<?( T, T ); int ?>?( T, T ); } )64 forall( T | { int ?<?( T, T ); int ?>?( T, T ); } ) 65 65 static inline void __libcfa_small_sort5( T * arr ) { 66 66 SWAP(0, 1); … … 75 75 } 76 76 77 forall( otypeT | { int ?<?( T, T ); int ?>?( T, T ); } )77 forall( T | { int ?<?( T, T ); int ?>?( T, T ); } ) 78 78 static inline void __libcfa_small_sort6( T * arr ) { 79 79 SWAP(1, 2); … … 91 91 } 92 92 93 forall( otypeT | { int ?<?( T, T ); int ?>?( T, T ); } )93 forall( T | { int ?<?( T, T ); int ?>?( T, T ); } ) 94 94 static inline void __libcfa_small_sortN( T * arr, size_t dim ) { 95 95 int i, j; … … 112 112 static inline void __libcfa_small_sortN( void* * arr, size_t dim ); 113 113 114 forall( dtype T)114 forall( T & ) 115 115 static inline void __libcfa_small_sort( T* * arr, size_t dim ) { 116 116 switch( dim ) { -
libcfa/src/bits/collection.hfa
r92bfda0 rdafbde8 31 31 32 32 // // wrappers to make Collection have T 33 // forall( dtype T) {33 // forall( T & ) { 34 34 // T *& Next( T * n ) { 35 35 // return (T *)Next( (Colable *)n ); … … 38 38 } // distribution 39 39 40 forall( dtype T| { T *& Next ( T * ); } ) {40 forall( T & | { T *& Next ( T * ); } ) { 41 41 bool listed( T * n ) { 42 42 return Next( n ) != 0p; … … 76 76 } // post: elts = null 77 77 78 forall( dtype T) {78 forall( T & ) { 79 79 T * Curr( ColIter & ci ) with( ci ) { 80 80 return (T *)curr; -
libcfa/src/bits/containers.hfa
r92bfda0 rdafbde8 23 23 24 24 #ifdef __cforall 25 forall( dtype T)25 forall(T &) 26 26 #else 27 27 #define T void … … 40 40 41 41 #ifdef __cforall 42 // forall( otypeT | sized(T))42 // forall(T | sized(T)) 43 43 // static inline void ?{}(__small_array(T) & this) {} 44 44 45 forall( dtype T| sized(T))45 forall(T & | sized(T)) 46 46 static inline T & ?[?]( __small_array(T) & this, __lock_size_t idx ) { 47 47 return ((typeof(this.data))this.data)[idx]; 48 48 } 49 49 50 forall( dtype T| sized(T))50 forall(T & | sized(T)) 51 51 static inline T & ?[?]( const __small_array(T) & this, __lock_size_t idx ) { 52 52 return ((typeof(this.data))this.data)[idx]; 53 53 } 54 54 55 forall( dtype T)55 forall(T &) 56 56 static inline T * begin( const __small_array(T) & this ) { 57 57 return ((typeof(this.data))this.data); 58 58 } 59 59 60 forall( dtype T| sized(T))60 forall(T & | sized(T)) 61 61 static inline T * end( const __small_array(T) & this ) { 62 62 return ((typeof(this.data))this.data) + this.size; … … 69 69 70 70 #ifdef __cforall 71 trait is_node( dtype T) {71 trait is_node(T &) { 72 72 T *& get_next( T & ); 73 73 }; … … 78 78 //----------------------------------------------------------------------------- 79 79 #ifdef __cforall 80 forall( dtype TYPE)80 forall(TYPE &) 81 81 #define T TYPE 82 82 #else … … 95 95 96 96 #ifdef __cforall 97 forall( dtype T)97 forall(T &) 98 98 static inline void ?{}( __stack(T) & this ) { 99 99 (this.top){ 0p }; 100 100 } 101 101 102 static inline forall( dtype T| is_node(T) ) {102 static inline forall( T & | is_node(T) ) { 103 103 void push( __stack(T) & this, T * val ) { 104 104 verify( !get_next( *val ) ); … … 126 126 //----------------------------------------------------------------------------- 127 127 #ifdef __cforall 128 forall( dtype TYPE)128 forall(TYPE &) 129 129 #define T TYPE 130 130 #else … … 144 144 145 145 #ifdef __cforall 146 static inline forall( dtype T| is_node(T) ) {146 static inline forall( T & | is_node(T) ) { 147 147 void ?{}( __queue(T) & this ) with( this ) { 148 148 (this.head){ 1p }; … … 215 215 //----------------------------------------------------------------------------- 216 216 #ifdef __cforall 217 forall( dtype TYPE)217 forall(TYPE &) 218 218 #define T TYPE 219 219 #define __getter_t * [T * & next, T * & prev] ( T & ) … … 237 237 238 238 #ifdef __cforall 239 forall( dtype T)239 forall(T & ) 240 240 static inline [void] ?{}( __dllist(T) & this, * [T * & next, T * & prev] ( T & ) __get ) { 241 241 (this.head){ 0p }; … … 245 245 #define next 0 246 246 #define prev 1 247 static inline forall( dtype T) {247 static inline forall(T &) { 248 248 void push_front( __dllist(T) & this, T & node ) with( this ) { 249 249 verify(__get); -
libcfa/src/bits/queue.hfa
r92bfda0 rdafbde8 9 9 // instead of being null. 10 10 11 forall( dtype T| { T *& Next ( T * ); } ) {11 forall( T & | { T *& Next ( T * ); } ) { 12 12 struct Queue { 13 13 inline Collection; // Plan 9 inheritance … … 151 151 } // distribution 152 152 153 forall( dtype T| { T *& Next ( T * ); } ) {153 forall( T & | { T *& Next ( T * ); } ) { 154 154 struct QueueIter { 155 155 inline ColIter; // Plan 9 inheritance -
libcfa/src/bits/sequence.hfa
r92bfda0 rdafbde8 29 29 30 30 // // wrappers to make Collection have T 31 // forall( dtype T) {31 // forall( T & ) { 32 32 // T *& Back( T * n ) { 33 33 // return (T *)Back( (Seqable *)n ); … … 43 43 // and the back field of the last node points at the first node (circular). 44 44 45 forall( dtype T| { T *& Back ( T * ); T *& Next ( T * ); } ) {45 forall( T & | { T *& Back ( T * ); T *& Next ( T * ); } ) { 46 46 struct Sequence { 47 47 inline Collection; // Plan 9 inheritance … … 231 231 } // distribution 232 232 233 forall( dtype T| { T *& Back ( T * ); T *& Next ( T * ); } ) {233 forall( T & | { T *& Back ( T * ); T *& Next ( T * ); } ) { 234 234 // SeqIter(T) is used to iterate over a Sequence(T) in head-to-tail order. 235 235 struct SeqIter { -
libcfa/src/bits/stack.hfa
r92bfda0 rdafbde8 9 9 // instead of being null. 10 10 11 forall( dtype T| { T *& Next ( T * ); } ) {11 forall( T & | { T *& Next ( T * ); } ) { 12 12 struct Stack { 13 13 inline Collection; // Plan 9 inheritance … … 67 67 // order returned by drop(). 68 68 69 forall( dtype T| { T *& Next ( T * ); } ) {69 forall( T & | { T *& Next ( T * ); } ) { 70 70 struct StackIter { 71 71 inline ColIter; // Plan 9 inheritance -
libcfa/src/common.cfa
r92bfda0 rdafbde8 23 23 [ long int, long int ] div( long int num, long int denom ) { ldiv_t qr = ldiv( num, denom ); return [ qr.quot, qr.rem ]; } 24 24 [ long long int, long long int ] div( long long int num, long long int denom ) { lldiv_t qr = lldiv( num, denom ); return [ qr.quot, qr.rem ]; } 25 forall( otypeT | { T ?/?( T, T ); T ?%?( T, T ); } )25 forall( T | { T ?/?( T, T ); T ?%?( T, T ); } ) 26 26 [ T, T ] div( T num, T denom ) { return [ num / denom, num % denom ]; } 27 27 -
libcfa/src/common.hfa
r92bfda0 rdafbde8 21 21 [ long int, long int ] div( long int num, long int denom ); 22 22 [ long long int, long long int ] div( long long int num, long long int denom ); 23 forall( otypeT | { T ?/?( T, T ); T ?%?( T, T ); } )23 forall( T | { T ?/?( T, T ); T ?%?( T, T ); } ) 24 24 [ T, T ] div( T num, T demon ); 25 25 … … 61 61 } // distribution 62 62 63 forall( otypeT | { void ?{}( T &, zero_t ); int ?<?( T, T ); T -?( T ); } )63 forall( T | { void ?{}( T &, zero_t ); int ?<?( T, T ); T -?( T ); } ) 64 64 T abs( T ); 65 65 … … 70 70 intptr_t min( intptr_t t1, intptr_t t2 ) { return t1 < t2 ? t1 : t2; } // optimization 71 71 uintptr_t min( uintptr_t t1, uintptr_t t2 ) { return t1 < t2 ? t1 : t2; } // optimization 72 forall( otypeT | { int ?<?( T, T ); } )72 forall( T | { int ?<?( T, T ); } ) 73 73 T min( T t1, T t2 ) { return t1 < t2 ? t1 : t2; } 74 74 … … 76 76 intptr_t max( intptr_t t1, intptr_t t2 ) { return t1 > t2 ? t1 : t2; } // optimization 77 77 uintptr_t max( uintptr_t t1, uintptr_t t2 ) { return t1 > t2 ? t1 : t2; } // optimization 78 forall( otypeT | { int ?>?( T, T ); } )78 forall( T | { int ?>?( T, T ); } ) 79 79 T max( T t1, T t2 ) { return t1 > t2 ? t1 : t2; } 80 80 81 forall( otypeT | { T min( T, T ); T max( T, T ); } )81 forall( T | { T min( T, T ); T max( T, T ); } ) 82 82 T clamp( T value, T min_val, T max_val ) { return max( min_val, min( value, max_val ) ); } 83 83 84 forall( otypeT )84 forall( T ) 85 85 void swap( T & v1, T & v2 ) { T temp = v1; v1 = v2; v2 = temp; } 86 86 } // distribution -
libcfa/src/concurrency/coroutine.cfa
r92bfda0 rdafbde8 46 46 47 47 //----------------------------------------------------------------------------- 48 FORALL_DATA_INSTANCE(CoroutineCancelled, ( dtype coroutine_t), (coroutine_t))49 50 forall( dtype T)48 FORALL_DATA_INSTANCE(CoroutineCancelled, (coroutine_t &), (coroutine_t)) 49 50 forall(T &) 51 51 void mark_exception(CoroutineCancelled(T) *) {} 52 52 53 forall( dtype T)53 forall(T &) 54 54 void copy(CoroutineCancelled(T) * dst, CoroutineCancelled(T) * src) { 55 55 dst->virtual_table = src->virtual_table; … … 58 58 } 59 59 60 forall( dtype T)60 forall(T &) 61 61 const char * msg(CoroutineCancelled(T) *) { 62 62 return "CoroutineCancelled(...)"; … … 64 64 65 65 // This code should not be inlined. It is the error path on resume. 66 forall( dtype T| is_coroutine(T))66 forall(T & | is_coroutine(T)) 67 67 void __cfaehm_cancelled_coroutine( T & cor, $coroutine * desc ) { 68 68 verify( desc->cancellation ); … … 148 148 // Part of the Public API 149 149 // Not inline since only ever called once per coroutine 150 forall( dtype T| is_coroutine(T))150 forall(T & | is_coroutine(T)) 151 151 void prime(T& cor) { 152 152 $coroutine* this = get_coroutine(cor); -
libcfa/src/concurrency/coroutine.hfa
r92bfda0 rdafbde8 22 22 //----------------------------------------------------------------------------- 23 23 // Exception thrown from resume when a coroutine stack is cancelled. 24 FORALL_DATA_EXCEPTION(CoroutineCancelled, ( dtype coroutine_t), (coroutine_t)) (24 FORALL_DATA_EXCEPTION(CoroutineCancelled, (coroutine_t &), (coroutine_t)) ( 25 25 coroutine_t * the_coroutine; 26 26 exception_t * the_exception; 27 27 ); 28 28 29 forall( dtype T)29 forall(T &) 30 30 void copy(CoroutineCancelled(T) * dst, CoroutineCancelled(T) * src); 31 31 32 forall( dtype T)32 forall(T &) 33 33 const char * msg(CoroutineCancelled(T) *); 34 34 … … 37 37 // Anything that implements this trait can be resumed. 38 38 // Anything that is resumed is a coroutine. 39 trait is_coroutine( dtype T| IS_RESUMPTION_EXCEPTION(CoroutineCancelled, (T))) {39 trait is_coroutine(T & | IS_RESUMPTION_EXCEPTION(CoroutineCancelled, (T))) { 40 40 void main(T & this); 41 41 $coroutine * get_coroutine(T & this); … … 60 60 //----------------------------------------------------------------------------- 61 61 // Public coroutine API 62 forall( dtype T| is_coroutine(T))62 forall(T & | is_coroutine(T)) 63 63 void prime(T & cor); 64 64 … … 72 72 void __cfactx_invoke_coroutine(void (*main)(void *), void * this); 73 73 74 forall( dtype T)74 forall(T &) 75 75 void __cfactx_start(void (*main)(T &), struct $coroutine * cor, T & this, void (*invoke)(void (*main)(void *), void *)); 76 76 … … 129 129 } 130 130 131 forall( dtype T| is_coroutine(T))131 forall(T & | is_coroutine(T)) 132 132 void __cfaehm_cancelled_coroutine( T & cor, $coroutine * desc ); 133 133 134 134 // Resume implementation inlined for performance 135 forall( dtype T| is_coroutine(T))135 forall(T & | is_coroutine(T)) 136 136 static inline T & resume(T & cor) { 137 137 // optimization : read TLS once and reuse it -
libcfa/src/concurrency/future.hfa
r92bfda0 rdafbde8 19 19 #include "monitor.hfa" 20 20 21 forall( otypeT ) {21 forall( T ) { 22 22 struct future { 23 23 inline future_t; … … 58 58 } 59 59 60 forall( otypeT ) {60 forall( T ) { 61 61 monitor multi_future { 62 62 inline future_t; -
libcfa/src/concurrency/io/setup.cfa
r92bfda0 rdafbde8 113 113 114 114 static struct { 115 pthread_t thrd; // pthread handle to io poller thread 116 void * stack; // pthread stack for io poller thread 117 int epollfd; // file descriptor to the epoll instance 118 volatile bool run; // Whether or not to continue 119 volatile size_t epoch; // Epoch used for memory reclamation 115 pthread_t thrd; // pthread handle to io poller thread 116 void * stack; // pthread stack for io poller thread 117 int epollfd; // file descriptor to the epoll instance 118 volatile bool run; // Whether or not to continue 119 volatile bool stopped; // Whether the poller has finished running 120 volatile uint64_t epoch; // Epoch used for memory reclamation 120 121 } iopoll; 121 122 … … 130 131 __cfadbg_print_safe(io_core, "Kernel : Starting io poller thread\n" ); 131 132 132 iopoll.run = true; 133 iopoll.stack = __create_pthread( &iopoll.thrd, iopoll_loop, 0p ); 134 iopoll.epoch = 0; 133 iopoll.stack = __create_pthread( &iopoll.thrd, iopoll_loop, 0p ); 134 iopoll.run = true; 135 iopoll.stopped = false; 136 iopoll.epoch = 0; 135 137 } 136 138 … … 205 207 } 206 208 } 209 210 __atomic_store_n(&iopoll.stopped, true, __ATOMIC_SEQ_CST); 207 211 208 212 __cfadbg_print_safe(io_core, "Kernel : IO poller thread stopping\n" ); … … 536 540 537 541 // Wait for the next epoch 538 while(curr == __atomic_load_n(&iopoll.epoch, __ATOMIC_RELAXED)) yield();542 while(curr == iopoll.epoch && !iopoll.stopped) Pause(); 539 543 } 540 544 -
libcfa/src/concurrency/locks.cfa
r92bfda0 rdafbde8 7 7 //----------------------------------------------------------------------------- 8 8 // info_thread 9 forall( dtype L| is_blocking_lock(L)) {9 forall(L & | is_blocking_lock(L)) { 10 10 struct info_thread { 11 11 // used to put info_thread on a dl queue (aka sequence) … … 195 195 //----------------------------------------------------------------------------- 196 196 // alarm node wrapper 197 forall( dtype L| is_blocking_lock(L)) {197 forall(L & | is_blocking_lock(L)) { 198 198 struct alarm_node_wrap { 199 199 alarm_node_t alarm_node; … … 239 239 //----------------------------------------------------------------------------- 240 240 // condition variable 241 forall( dtype L| is_blocking_lock(L)) {241 forall(L & | is_blocking_lock(L)) { 242 242 243 243 void ?{}( condition_variable(L) & this ){ -
libcfa/src/concurrency/locks.hfa
r92bfda0 rdafbde8 13 13 //----------------------------------------------------------------------------- 14 14 // is_blocking_lock 15 trait is_blocking_lock( dtype L| sized(L)) {15 trait is_blocking_lock(L & | sized(L)) { 16 16 // For synchronization locks to use when acquiring 17 17 void on_notify( L &, struct $thread * ); … … 31 31 // the info thread is a wrapper around a thread used 32 32 // to store extra data for use in the condition variable 33 forall( dtype L| is_blocking_lock(L)) {33 forall(L & | is_blocking_lock(L)) { 34 34 struct info_thread; 35 35 … … 120 120 //----------------------------------------------------------------------------- 121 121 // Synchronization Locks 122 forall( dtype L| is_blocking_lock(L)) {122 forall(L & | is_blocking_lock(L)) { 123 123 struct condition_variable { 124 124 // Spin lock used for mutual exclusion -
libcfa/src/concurrency/monitor.cfa
r92bfda0 rdafbde8 50 50 static inline [$thread *, int] search_entry_queue( const __waitfor_mask_t &, $monitor * monitors [], __lock_size_t count ); 51 51 52 forall( dtype T| sized( T ))52 forall(T & | sized( T )) 53 53 static inline __lock_size_t insert_unique( T * array [], __lock_size_t & size, T * val ); 54 54 static inline __lock_size_t count_max ( const __waitfor_mask_t & mask ); … … 949 949 } 950 950 951 forall( dtype T| sized( T ))951 forall(T & | sized( T )) 952 952 static inline __lock_size_t insert_unique( T * array [], __lock_size_t & size, T * val ) { 953 953 if( !val ) return size; -
libcfa/src/concurrency/monitor.hfa
r92bfda0 rdafbde8 22 22 #include "stdlib.hfa" 23 23 24 trait is_monitor( dtype T) {24 trait is_monitor(T &) { 25 25 $monitor * get_monitor( T & ); 26 26 void ^?{}( T & mutex ); … … 59 59 void ^?{}( monitor_dtor_guard_t & this ); 60 60 61 static inline forall( dtype T| sized(T) | { void ^?{}( T & mutex ); } )61 static inline forall( T & | sized(T) | { void ^?{}( T & mutex ); } ) 62 62 void delete( T * th ) { 63 63 ^(*th){}; -
libcfa/src/concurrency/mutex.cfa
r92bfda0 rdafbde8 164 164 } 165 165 166 forall( dtype L| is_lock(L))166 forall(L & | is_lock(L)) 167 167 void wait(condition_variable & this, L & l) { 168 168 lock( this.lock __cfaabi_dbg_ctx2 ); … … 176 176 //----------------------------------------------------------------------------- 177 177 // Scopes 178 forall( dtype L| is_lock(L))178 forall(L & | is_lock(L)) 179 179 void lock_all ( L * locks[], size_t count) { 180 180 // Sort locks based on addresses … … 188 188 } 189 189 190 forall( dtype L| is_lock(L))190 forall(L & | is_lock(L)) 191 191 void unlock_all( L * locks[], size_t count) { 192 192 // Lock all -
libcfa/src/concurrency/mutex.hfa
r92bfda0 rdafbde8 70 70 void unlock(recursive_mutex_lock & this) __attribute__((deprecated("use concurrency/locks.hfa instead"))); 71 71 72 trait is_lock( dtype L| sized(L)) {72 trait is_lock(L & | sized(L)) { 73 73 void lock (L &); 74 74 void unlock(L &); … … 94 94 void wait(condition_variable & this) __attribute__((deprecated("use concurrency/locks.hfa instead"))); 95 95 96 forall( dtype L| is_lock(L))96 forall(L & | is_lock(L)) 97 97 void wait(condition_variable & this, L & l) __attribute__((deprecated("use concurrency/locks.hfa instead"))); 98 98 99 99 //----------------------------------------------------------------------------- 100 100 // Scopes 101 forall( dtype L| is_lock(L)) {101 forall(L & | is_lock(L)) { 102 102 #if !defined( __TUPLE_ARRAYS_EXIST__ ) 103 103 void lock ( L * locks [], size_t count); -
libcfa/src/concurrency/thread.cfa
r92bfda0 rdafbde8 62 62 } 63 63 64 FORALL_DATA_INSTANCE(ThreadCancelled, ( dtype thread_t), (thread_t))64 FORALL_DATA_INSTANCE(ThreadCancelled, (thread_t &), (thread_t)) 65 65 66 forall( dtype T)66 forall(T &) 67 67 void copy(ThreadCancelled(T) * dst, ThreadCancelled(T) * src) { 68 68 dst->virtual_table = src->virtual_table; … … 71 71 } 72 72 73 forall( dtype T)73 forall(T &) 74 74 const char * msg(ThreadCancelled(T) *) { 75 75 return "ThreadCancelled"; 76 76 } 77 77 78 forall( dtype T)78 forall(T &) 79 79 static void default_thread_cancel_handler(ThreadCancelled(T) & ) { 80 80 abort( "Unhandled thread cancellation.\n" ); 81 81 } 82 82 83 forall( dtype T| is_thread(T) | IS_EXCEPTION(ThreadCancelled, (T)))83 forall(T & | is_thread(T) | IS_EXCEPTION(ThreadCancelled, (T))) 84 84 void ?{}( thread_dtor_guard_t & this, 85 T & thrd, void(* defaultResumptionHandler)(ThreadCancelled(T) &)) {86 $monitor * m = get_monitor(thrd);85 T & thrd, void(*cancelHandler)(ThreadCancelled(T) &)) { 86 $monitor * m = get_monitor(thrd); 87 87 $thread * desc = get_thread(thrd); 88 88 89 89 // Setup the monitor guard 90 90 void (*dtor)(T& mutex this) = ^?{}; 91 bool join = defaultResumptionHandler != (void(*)(ThreadCancelled(T)&))0;91 bool join = cancelHandler != (void(*)(ThreadCancelled(T)&))0; 92 92 (this.mg){&m, (void(*)())dtor, join}; 93 93 … … 103 103 } 104 104 desc->state = Cancelled; 105 if (!join) { 106 defaultResumptionHandler = default_thread_cancel_handler; 107 } 105 void(*defaultResumptionHandler)(ThreadCancelled(T) &) = 106 join ? cancelHandler : default_thread_cancel_handler; 108 107 109 108 ThreadCancelled(T) except; … … 125 124 //----------------------------------------------------------------------------- 126 125 // Starting and stopping threads 127 forall( dtype T| is_thread(T) )126 forall( T & | is_thread(T) ) 128 127 void __thrd_start( T & this, void (*main_p)(T &) ) { 129 128 $thread * this_thrd = get_thread(this); … … 141 140 //----------------------------------------------------------------------------- 142 141 // Support for threads that don't ues the thread keyword 143 forall( dtype T| sized(T) | is_thread(T) | { void ?{}(T&); } )142 forall( T & | sized(T) | is_thread(T) | { void ?{}(T&); } ) 144 143 void ?{}( scoped(T)& this ) with( this ) { 145 144 handle{}; … … 147 146 } 148 147 149 forall( dtype T, ttype P| sized(T) | is_thread(T) | { void ?{}(T&, P); } )148 forall( T &, P... | sized(T) | is_thread(T) | { void ?{}(T&, P); } ) 150 149 void ?{}( scoped(T)& this, P params ) with( this ) { 151 150 handle{ params }; … … 153 152 } 154 153 155 forall( dtype T| sized(T) | is_thread(T) )154 forall( T & | sized(T) | is_thread(T) ) 156 155 void ^?{}( scoped(T)& this ) with( this ) { 157 156 ^handle{}; … … 159 158 160 159 //----------------------------------------------------------------------------- 161 forall( dtype T| is_thread(T) | IS_RESUMPTION_EXCEPTION(ThreadCancelled, (T)))160 forall(T & | is_thread(T) | IS_RESUMPTION_EXCEPTION(ThreadCancelled, (T))) 162 161 T & join( T & this ) { 163 162 thread_dtor_guard_t guard = { this, defaultResumptionHandler }; -
libcfa/src/concurrency/thread.hfa
r92bfda0 rdafbde8 26 26 //----------------------------------------------------------------------------- 27 27 // thread trait 28 trait is_thread( dtype T) {28 trait is_thread(T &) { 29 29 void ^?{}(T& mutex this); 30 30 void main(T& this); … … 32 32 }; 33 33 34 FORALL_DATA_EXCEPTION(ThreadCancelled, ( dtype thread_t), (thread_t)) (34 FORALL_DATA_EXCEPTION(ThreadCancelled, (thread_t &), (thread_t)) ( 35 35 thread_t * the_thread; 36 36 exception_t * the_exception; 37 37 ); 38 38 39 forall( dtype T)39 forall(T &) 40 40 void copy(ThreadCancelled(T) * dst, ThreadCancelled(T) * src); 41 41 42 forall( dtype T)42 forall(T &) 43 43 const char * msg(ThreadCancelled(T) *); 44 44 … … 47 47 48 48 // Inline getters for threads/coroutines/monitors 49 forall( dtype T| is_thread(T) )49 forall( T & | is_thread(T) ) 50 50 static inline $coroutine* get_coroutine(T & this) __attribute__((const)) { return &get_thread(this)->self_cor; } 51 51 52 forall( dtype T| is_thread(T) )52 forall( T & | is_thread(T) ) 53 53 static inline $monitor * get_monitor (T & this) __attribute__((const)) { return &get_thread(this)->self_mon; } 54 54 … … 60 60 extern struct cluster * mainCluster; 61 61 62 forall( dtype T| is_thread(T) )62 forall( T & | is_thread(T) ) 63 63 void __thrd_start( T & this, void (*)(T &) ); 64 64 … … 82 82 }; 83 83 84 forall( dtype T| is_thread(T) | IS_EXCEPTION(ThreadCancelled, (T)) )84 forall( T & | is_thread(T) | IS_EXCEPTION(ThreadCancelled, (T)) ) 85 85 void ?{}( thread_dtor_guard_t & this, T & thrd, void(*)(ThreadCancelled(T) &) ); 86 86 void ^?{}( thread_dtor_guard_t & this ); … … 89 89 // thread runner 90 90 // Structure that actually start and stop threads 91 forall( dtype T| sized(T) | is_thread(T) )91 forall( T & | sized(T) | is_thread(T) ) 92 92 struct scoped { 93 93 T handle; 94 94 }; 95 95 96 forall( dtype T| sized(T) | is_thread(T) | { void ?{}(T&); } )96 forall( T & | sized(T) | is_thread(T) | { void ?{}(T&); } ) 97 97 void ?{}( scoped(T)& this ); 98 98 99 forall( dtype T, ttype P| sized(T) | is_thread(T) | { void ?{}(T&, P); } )99 forall( T &, P... | sized(T) | is_thread(T) | { void ?{}(T&, P); } ) 100 100 void ?{}( scoped(T)& this, P params ); 101 101 102 forall( dtype T| sized(T) | is_thread(T) )102 forall( T & | sized(T) | is_thread(T) ) 103 103 void ^?{}( scoped(T)& this ); 104 104 … … 115 115 void unpark( $thread * this ); 116 116 117 forall( dtype T| is_thread(T) )117 forall( T & | is_thread(T) ) 118 118 static inline void unpark( T & this ) { if(!&this) return; unpark( get_thread( this ) );} 119 119 … … 128 128 //---------- 129 129 // join 130 forall( dtype T| is_thread(T) | IS_RESUMPTION_EXCEPTION(ThreadCancelled, (T)) )130 forall( T & | is_thread(T) | IS_RESUMPTION_EXCEPTION(ThreadCancelled, (T)) ) 131 131 T & join( T & this ); 132 132 -
libcfa/src/containers/list.hfa
r92bfda0 rdafbde8 66 66 #define __DLISTED_MGD_JUSTIMPL(STRUCT) 67 67 68 forall( dtype tE) {68 forall( tE & ) { 69 69 struct $mgd_link { 70 70 tE *elem; … … 83 83 (this.is_terminator){ 1 }; 84 84 } 85 forall ( otypetInit | { void ?{}( $mgd_link(tE) &, tInit); } )85 forall ( tInit | { void ?{}( $mgd_link(tE) &, tInit); } ) 86 86 static inline void ?=?( $mgd_link(tE) &this, tInit i ) { 87 87 ^?{}( this ); … … 115 115 __DLISTED_MGD_COMMON(STRUCT, STRUCT, $links) 116 116 117 trait $dlistable( dtype Tnode, dtype Telem) {117 trait $dlistable(Tnode &, Telem &) { 118 118 $mgd_link(Telem) & $prev_link(Tnode &); 119 119 $mgd_link(Telem) & $next_link(Tnode &); … … 125 125 }; 126 126 127 forall ( dtype Tnode, dtype Telem| $dlistable(Tnode, Telem)) {127 forall (Tnode &, Telem & | $dlistable(Tnode, Telem)) { 128 128 129 129 // implemented as a sentinel item in an underlying cicrular list -
libcfa/src/containers/maybe.cfa
r92bfda0 rdafbde8 18 18 19 19 20 forall( otypeT)20 forall(T) 21 21 void ?{}(maybe(T) & this) { 22 22 this.has_value = false; 23 23 } 24 24 25 forall( otypeT)25 forall(T) 26 26 void ?{}(maybe(T) & this, T value) { 27 27 this.has_value = true; … … 29 29 } 30 30 31 forall( otypeT)31 forall(T) 32 32 void ?{}(maybe(T) & this, maybe(T) other) { 33 33 this.has_value = other.has_value; … … 37 37 } 38 38 39 forall( otypeT)39 forall(T) 40 40 maybe(T) ?=?(maybe(T) & this, maybe(T) that) { 41 41 if (this.has_value && that.has_value) { … … 51 51 } 52 52 53 forall( otypeT)53 forall(T) 54 54 void ^?{}(maybe(T) & this) { 55 55 if (this.has_value) { … … 58 58 } 59 59 60 forall( otypeT)60 forall(T) 61 61 bool ?!=?(maybe(T) this, zero_t) { 62 62 return this.has_value; 63 63 } 64 64 65 forall( otypeT)65 forall(T) 66 66 maybe(T) maybe_value(T value) { 67 67 return (maybe(T)){value}; 68 68 } 69 69 70 forall( otypeT)70 forall(T) 71 71 maybe(T) maybe_none() { 72 72 return (maybe(T)){}; 73 73 } 74 74 75 forall( otypeT)75 forall(T) 76 76 bool has_value(maybe(T) * this) { 77 77 return this->has_value; 78 78 } 79 79 80 forall( otypeT)80 forall(T) 81 81 T get(maybe(T) * this) { 82 82 assertf(this->has_value, "attempt to get from maybe without value"); … … 84 84 } 85 85 86 forall( otypeT)86 forall(T) 87 87 void set(maybe(T) * this, T value) { 88 88 if (this->has_value) { … … 94 94 } 95 95 96 forall( otypeT)96 forall(T) 97 97 void set_none(maybe(T) * this) { 98 98 if (this->has_value) { -
libcfa/src/containers/maybe.hfa
r92bfda0 rdafbde8 19 19 20 20 // DO NOT USE DIRECTLY! 21 forall( otypeT)21 forall(T) 22 22 struct maybe { 23 23 bool has_value; … … 26 26 27 27 28 forall( otypeT)28 forall(T) 29 29 void ?{}(maybe(T) & this); 30 30 31 forall( otypeT)31 forall(T) 32 32 void ?{}(maybe(T) & this, T value); 33 33 34 forall( otypeT)34 forall(T) 35 35 void ?{}(maybe(T) & this, maybe(T) other); 36 36 37 forall( otypeT)37 forall(T) 38 38 void ^?{}(maybe(T) & this); 39 39 40 forall( otypeT)40 forall(T) 41 41 maybe(T) ?=?(maybe(T) & this, maybe(T) other); 42 42 43 forall( otypeT)43 forall(T) 44 44 bool ?!=?(maybe(T) this, zero_t); 45 45 46 46 /* Waiting for bug#11 to be fixed. 47 forall( otypeT)47 forall(T) 48 48 maybe(T) maybe_value(T value); 49 49 50 forall( otypeT)50 forall(T) 51 51 maybe(T) maybe_none(); 52 52 */ 53 53 54 forall( otypeT)54 forall(T) 55 55 bool has_value(maybe(T) * this); 56 56 57 forall( otypeT)57 forall(T) 58 58 T get(maybe(T) * this); 59 59 60 forall( otypeT)60 forall(T) 61 61 void set(maybe(T) * this, T value); 62 62 63 forall( otypeT)63 forall(T) 64 64 void set_none(maybe(T) * this); 65 65 -
libcfa/src/containers/pair.cfa
r92bfda0 rdafbde8 13 13 #include <containers/pair.hfa> 14 14 15 forall( otype R, otypeS15 forall(R, S 16 16 | { int ?==?(R, R); int ?<?(R, R); int ?<?(S, S); }) 17 17 int ?<?(pair(R, S) p, pair(R, S) q) { … … 19 19 } 20 20 21 forall( otype R, otypeS21 forall(R, S 22 22 | { int ?==?(R, R); int ?<?(R, R); int ?<=?(S, S); }) 23 23 int ?<=?(pair(R, S) p, pair(R, S) q) { … … 25 25 } 26 26 27 forall( otype R, otypeS | { int ?==?(R, R); int ?==?(S, S); })27 forall(R, S | { int ?==?(R, R); int ?==?(S, S); }) 28 28 int ?==?(pair(R, S) p, pair(R, S) q) { 29 29 return p.first == q.first && p.second == q.second; 30 30 } 31 31 32 forall( otype R, otypeS | { int ?!=?(R, R); int ?!=?(S, S); })32 forall(R, S | { int ?!=?(R, R); int ?!=?(S, S); }) 33 33 int ?!=?(pair(R, S) p, pair(R, S) q) { 34 34 return p.first != q.first || p.second != q.second; 35 35 } 36 36 37 forall( otype R, otypeS37 forall(R, S 38 38 | { int ?==?(R, R); int ?>?(R, R); int ?>?(S, S); }) 39 39 int ?>?(pair(R, S) p, pair(R, S) q) { … … 41 41 } 42 42 43 forall( otype R, otypeS43 forall(R, S 44 44 | { int ?==?(R, R); int ?>?(R, R); int ?>=?(S, S); }) 45 45 int ?>=?(pair(R, S) p, pair(R, S) q) { -
libcfa/src/containers/pair.hfa
r92bfda0 rdafbde8 16 16 #pragma once 17 17 18 forall( otype R, otypeS) struct pair {18 forall(R, S) struct pair { 19 19 R first; 20 20 S second; 21 21 }; 22 22 23 forall( otype R, otypeS23 forall(R, S 24 24 | { int ?==?(R, R); int ?<?(R, R); int ?<?(S, S); }) 25 25 int ?<?(pair(R, S) p, pair(R, S) q); 26 26 27 forall( otype R, otypeS27 forall(R, S 28 28 | { int ?==?(R, R); int ?<?(R, R); int ?<=?(S, S); }) 29 29 int ?<=?(pair(R, S) p, pair(R, S) q); 30 30 31 forall( otype R, otypeS | { int ?==?(R, R); int ?==?(S, S); })31 forall(R, S | { int ?==?(R, R); int ?==?(S, S); }) 32 32 int ?==?(pair(R, S) p, pair(R, S) q); 33 33 34 forall( otype R, otypeS | { int ?!=?(R, R); int ?!=?(S, S); })34 forall(R, S | { int ?!=?(R, R); int ?!=?(S, S); }) 35 35 int ?!=?(pair(R, S) p, pair(R, S) q); 36 36 37 forall( otype R, otypeS37 forall(R, S 38 38 | { int ?==?(R, R); int ?>?(R, R); int ?>?(S, S); }) 39 39 int ?>?(pair(R, S) p, pair(R, S) q); 40 40 41 forall( otype R, otypeS41 forall(R, S 42 42 | { int ?==?(R, R); int ?>?(R, R); int ?>=?(S, S); }) 43 43 int ?>=?(pair(R, S) p, pair(R, S) q); -
libcfa/src/containers/result.cfa
r92bfda0 rdafbde8 18 18 19 19 20 forall( otype T, otypeE)20 forall(T, E) 21 21 void ?{}(result(T, E) & this) { 22 22 this.has_value = false; … … 24 24 } 25 25 26 forall( otype T, otypeE)26 forall(T, E) 27 27 void ?{}(result(T, E) & this, one_t, T value) { 28 28 this.has_value = true; … … 30 30 } 31 31 32 forall( otype T, otypeE)32 forall(T, E) 33 33 void ?{}(result(T, E) & this, zero_t, E error) { 34 34 this.has_value = false; … … 36 36 } 37 37 38 forall( otype T, otypeE)38 forall(T, E) 39 39 void ?{}(result(T, E) & this, result(T, E) other) { 40 40 this.has_value = other.has_value; … … 46 46 } 47 47 48 forall( otype T, otypeE)48 forall(T, E) 49 49 result(T, E) ?=?(result(T, E) & this, result(T, E) that) { 50 50 if (this.has_value && that.has_value) { … … 63 63 } 64 64 65 forall( otype T, otypeE)65 forall(T, E) 66 66 void ^?{}(result(T, E) & this) { 67 67 if (this.has_value) { … … 72 72 } 73 73 74 forall( otype T, otypeE)74 forall(T, E) 75 75 bool ?!=?(result(T, E) this, zero_t) { 76 76 return this.has_value; 77 77 } 78 78 79 forall( otype T, otypeE)79 forall(T, E) 80 80 result(T, E) result_value(T value) { 81 81 return (result(T, E)){1, value}; 82 82 } 83 83 84 forall( otype T, otypeE)84 forall(T, E) 85 85 result(T, E) result_error(E error) { 86 86 return (result(T, E)){0, error}; 87 87 } 88 88 89 forall( otype T, otypeE)89 forall(T, E) 90 90 bool has_value(result(T, E) * this) { 91 91 return this->has_value; 92 92 } 93 93 94 forall( otype T, otypeE)94 forall(T, E) 95 95 T get(result(T, E) * this) { 96 96 assertf(this->has_value, "attempt to get from result without value"); … … 98 98 } 99 99 100 forall( otype T, otypeE)100 forall(T, E) 101 101 E get_error(result(T, E) * this) { 102 102 assertf(!this->has_value, "attempt to get from result without error"); … … 104 104 } 105 105 106 forall( otype T, otypeE)106 forall(T, E) 107 107 void set(result(T, E) * this, T value) { 108 108 if (this->has_value) { … … 115 115 } 116 116 117 forall( otype T, otypeE)117 forall(T, E) 118 118 void set_error(result(T, E) * this, E error) { 119 119 if (this->has_value) { -
libcfa/src/containers/result.hfa
r92bfda0 rdafbde8 19 19 20 20 // DO NOT USE DIRECTLY! 21 forall( otype T, otypeE)21 forall(T, E) 22 22 union inner_result{ 23 23 T value; … … 25 25 }; 26 26 27 forall( otype T, otypeE)27 forall(T, E) 28 28 struct result { 29 29 bool has_value; … … 32 32 33 33 34 forall( otype T, otypeE)34 forall(T, E) 35 35 void ?{}(result(T, E) & this); 36 36 37 forall( otype T, otypeE)37 forall(T, E) 38 38 void ?{}(result(T, E) & this, one_t, T value); 39 39 40 forall( otype T, otypeE)40 forall(T, E) 41 41 void ?{}(result(T, E) & this, zero_t, E error); 42 42 43 forall( otype T, otypeE)43 forall(T, E) 44 44 void ?{}(result(T, E) & this, result(T, E) other); 45 45 46 forall( otype T, otypeE)46 forall(T, E) 47 47 void ^?{}(result(T, E) & this); 48 48 49 forall( otype T, otypeE)49 forall(T, E) 50 50 result(T, E) ?=?(result(T, E) & this, result(T, E) other); 51 51 52 forall( otype T, otypeE)52 forall(T, E) 53 53 bool ?!=?(result(T, E) this, zero_t); 54 54 55 55 /* Wating for bug#11 to be fixed. 56 forall( otype T, otypeE)56 forall(T, E) 57 57 result(T, E) result_value(T value); 58 58 59 forall( otype T, otypeE)59 forall(T, E) 60 60 result(T, E) result_error(E error); 61 61 */ 62 62 63 forall( otype T, otypeE)63 forall(T, E) 64 64 bool has_value(result(T, E) * this); 65 65 66 forall( otype T, otypeE)66 forall(T, E) 67 67 T get(result(T, E) * this); 68 68 69 forall( otype T, otypeE)69 forall(T, E) 70 70 E get_error(result(T, E) * this); 71 71 72 forall( otype T, otypeE)72 forall(T, E) 73 73 void set(result(T, E) * this, T value); 74 74 75 forall( otype T, otypeE)75 forall(T, E) 76 76 void set_error(result(T, E) * this, E error); 77 77 -
libcfa/src/containers/stackLockFree.hfa
r92bfda0 rdafbde8 17 17 #include <stdint.h> 18 18 19 forall( dtype T)19 forall( T & ) 20 20 union Link { 21 21 struct { // 32/64-bit x 2 … … 31 31 }; // Link 32 32 33 forall( otypeT | sized(T) | { Link(T) * ?`next( T * ); } ) {33 forall( T | sized(T) | { Link(T) * ?`next( T * ); } ) { 34 34 struct StackLF { 35 35 Link(T) stack; -
libcfa/src/containers/vector.cfa
r92bfda0 rdafbde8 18 18 #include <stdlib.hfa> 19 19 20 forall( otype T, otypeallocator_t | allocator_c(T, allocator_t))20 forall(T, allocator_t | allocator_c(T, allocator_t)) 21 21 void copy_internal(vector(T, allocator_t)* this, vector(T, allocator_t)* other); 22 22 23 23 //------------------------------------------------------------------------------ 24 24 //Initialization 25 forall( otype T, otypeallocator_t | allocator_c(T, allocator_t))25 forall(T, allocator_t | allocator_c(T, allocator_t)) 26 26 void ?{}(vector(T, allocator_t)& this) 27 27 { … … 30 30 } 31 31 32 forall( otype T, otypeallocator_t | allocator_c(T, allocator_t))32 forall(T, allocator_t | allocator_c(T, allocator_t)) 33 33 void ?{}(vector(T, allocator_t)& this, vector(T, allocator_t) rhs) 34 34 { … … 37 37 } 38 38 39 // forall( otype T, otypeallocator_t | allocator_c(T, allocator_t))39 // forall(T, allocator_t | allocator_c(T, allocator_t)) 40 40 // vector(T, allocator_t) ?=?(vector(T, allocator_t)* this, vector(T, allocator_t) rhs) 41 41 // { … … 45 45 // } 46 46 47 forall( otype T, otypeallocator_t | allocator_c(T, allocator_t))47 forall(T, allocator_t | allocator_c(T, allocator_t)) 48 48 void ^?{}(vector(T, allocator_t)& this) 49 49 { … … 54 54 //------------------------------------------------------------------------------ 55 55 //Modifiers 56 forall( otype T, otypeallocator_t | allocator_c(T, allocator_t))56 forall(T, allocator_t | allocator_c(T, allocator_t)) 57 57 void push_back(vector(T, allocator_t)* this, T value) 58 58 { … … 62 62 } 63 63 64 forall( otype T, otypeallocator_t | allocator_c(T, allocator_t))64 forall(T, allocator_t | allocator_c(T, allocator_t)) 65 65 void pop_back(vector(T, allocator_t)* this) 66 66 { … … 69 69 } 70 70 71 forall( otype T, otypeallocator_t | allocator_c(T, allocator_t))71 forall(T, allocator_t | allocator_c(T, allocator_t)) 72 72 void clear(vector(T, allocator_t)* this) 73 73 { … … 82 82 //Internal Helpers 83 83 84 forall( otype T, otypeallocator_t | allocator_c(T, allocator_t))84 forall(T, allocator_t | allocator_c(T, allocator_t)) 85 85 void copy_internal(vector(T, allocator_t)* this, vector(T, allocator_t)* other) 86 86 { … … 93 93 //------------------------------------------------------------------------------ 94 94 //Allocator 95 forall( otypeT)95 forall(T) 96 96 void ?{}(heap_allocator(T)& this) 97 97 { … … 100 100 } 101 101 102 forall( otypeT)102 forall(T) 103 103 void ?{}(heap_allocator(T)& this, heap_allocator(T) rhs) 104 104 { … … 107 107 } 108 108 109 forall( otypeT)109 forall(T) 110 110 heap_allocator(T) ?=?(heap_allocator(T)& this, heap_allocator(T) rhs) 111 111 { … … 115 115 } 116 116 117 forall( otypeT)117 forall(T) 118 118 void ^?{}(heap_allocator(T)& this) 119 119 { … … 121 121 } 122 122 123 forall( otypeT)123 forall(T) 124 124 inline void realloc_storage(heap_allocator(T)* this, size_t size) 125 125 { -
libcfa/src/containers/vector.hfa
r92bfda0 rdafbde8 20 20 //------------------------------------------------------------------------------ 21 21 //Allocator 22 forall( otypeT)22 forall(T) 23 23 struct heap_allocator 24 24 { … … 27 27 }; 28 28 29 forall( otypeT)29 forall(T) 30 30 void ?{}(heap_allocator(T)& this); 31 31 32 forall( otypeT)32 forall(T) 33 33 void ?{}(heap_allocator(T)& this, heap_allocator(T) rhs); 34 34 35 forall( otypeT)35 forall(T) 36 36 heap_allocator(T) ?=?(heap_allocator(T)& this, heap_allocator(T) rhs); 37 37 38 forall( otypeT)38 forall(T) 39 39 void ^?{}(heap_allocator(T)& this); 40 40 41 forall( otypeT)41 forall(T) 42 42 void realloc_storage(heap_allocator(T)* this, size_t size); 43 43 44 forall( otypeT)44 forall(T) 45 45 static inline T* data(heap_allocator(T)* this) 46 46 { … … 50 50 //------------------------------------------------------------------------------ 51 51 //Declaration 52 trait allocator_c( otype T, otypeallocator_t)52 trait allocator_c(T, allocator_t) 53 53 { 54 54 void realloc_storage(allocator_t*, size_t); … … 56 56 }; 57 57 58 forall( otype T, otypeallocator_t = heap_allocator(T) | allocator_c(T, allocator_t))58 forall(T, allocator_t = heap_allocator(T) | allocator_c(T, allocator_t)) 59 59 struct vector; 60 60 61 61 //------------------------------------------------------------------------------ 62 62 //Initialization 63 forall( otype T, otypeallocator_t | allocator_c(T, allocator_t))63 forall(T, allocator_t | allocator_c(T, allocator_t)) 64 64 void ?{}(vector(T, allocator_t)& this); 65 65 66 forall( otype T, otypeallocator_t | allocator_c(T, allocator_t))66 forall(T, allocator_t | allocator_c(T, allocator_t)) 67 67 void ?{}(vector(T, allocator_t)& this, vector(T, allocator_t) rhs); 68 68 69 forall( otype T, otypeallocator_t | allocator_c(T, allocator_t))69 forall(T, allocator_t | allocator_c(T, allocator_t)) 70 70 vector(T, allocator_t) ?=?(vector(T, allocator_t)& this, vector(T, allocator_t) rhs); 71 71 72 forall( otype T, otypeallocator_t | allocator_c(T, allocator_t))72 forall(T, allocator_t | allocator_c(T, allocator_t)) 73 73 void ^?{}(vector(T, allocator_t)& this); 74 74 75 forall( otype T, otypeallocator_t = heap_allocator(T) | allocator_c(T, allocator_t))75 forall(T, allocator_t = heap_allocator(T) | allocator_c(T, allocator_t)) 76 76 struct vector 77 77 { … … 82 82 //------------------------------------------------------------------------------ 83 83 //Capacity 84 forall( otype T, otypeallocator_t | allocator_c(T, allocator_t))84 forall(T, allocator_t | allocator_c(T, allocator_t)) 85 85 static inline bool empty(vector(T, allocator_t)* this) 86 86 { … … 88 88 } 89 89 90 forall( otype T, otypeallocator_t | allocator_c(T, allocator_t))90 forall(T, allocator_t | allocator_c(T, allocator_t)) 91 91 static inline size_t size(vector(T, allocator_t)* this) 92 92 { … … 94 94 } 95 95 96 forall( otype T, otypeallocator_t | allocator_c(T, allocator_t))96 forall(T, allocator_t | allocator_c(T, allocator_t)) 97 97 static inline void reserve(vector(T, allocator_t)* this, size_t size) 98 98 { … … 102 102 //------------------------------------------------------------------------------ 103 103 //Element access 104 forall( otype T, otypeallocator_t | allocator_c(T, allocator_t))104 forall(T, allocator_t | allocator_c(T, allocator_t)) 105 105 static inline T at(vector(T, allocator_t)* this, size_t index) 106 106 { … … 108 108 } 109 109 110 forall( otype T, otypeallocator_t | allocator_c(T, allocator_t))110 forall(T, allocator_t | allocator_c(T, allocator_t)) 111 111 static inline T ?[?](vector(T, allocator_t)* this, size_t index) 112 112 { … … 114 114 } 115 115 116 forall( otype T, otypeallocator_t | allocator_c(T, allocator_t))116 forall(T, allocator_t | allocator_c(T, allocator_t)) 117 117 static inline T front(vector(T, allocator_t)* this) 118 118 { … … 120 120 } 121 121 122 forall( otype T, otypeallocator_t | allocator_c(T, allocator_t))122 forall(T, allocator_t | allocator_c(T, allocator_t)) 123 123 static inline T back(vector(T, allocator_t)* this) 124 124 { … … 128 128 //------------------------------------------------------------------------------ 129 129 //Modifiers 130 forall( otype T, otypeallocator_t | allocator_c(T, allocator_t))130 forall(T, allocator_t | allocator_c(T, allocator_t)) 131 131 void push_back(vector(T, allocator_t)* this, T value); 132 132 133 forall( otype T, otypeallocator_t | allocator_c(T, allocator_t))133 forall(T, allocator_t | allocator_c(T, allocator_t)) 134 134 void pop_back(vector(T, allocator_t)* this); 135 135 136 forall( otype T, otypeallocator_t | allocator_c(T, allocator_t))136 forall(T, allocator_t | allocator_c(T, allocator_t)) 137 137 void clear(vector(T, allocator_t)* this); 138 138 139 139 //------------------------------------------------------------------------------ 140 140 //Iterators 141 forall( otype T, otypeallocator_t | allocator_c(T, allocator_t))141 forall(T, allocator_t | allocator_c(T, allocator_t)) 142 142 static inline T* begin(vector(T, allocator_t)* this) 143 143 { … … 145 145 } 146 146 147 // forall( otype T, otypeallocator_t | allocator_c(T, allocator_t))147 // forall(T, allocator_t | allocator_c(T, allocator_t)) 148 148 // static inline const T* cbegin(const vector(T, allocator_t)* this) 149 149 // { … … 151 151 // } 152 152 153 forall( otype T, otypeallocator_t | allocator_c(T, allocator_t))153 forall(T, allocator_t | allocator_c(T, allocator_t)) 154 154 static inline T* end(vector(T, allocator_t)* this) 155 155 { … … 157 157 } 158 158 159 // forall( otype T, otypeallocator_t | allocator_c(T, allocator_t))159 // forall(T, allocator_t | allocator_c(T, allocator_t)) 160 160 // static inline const T* cend(const vector(T, allocator_t)* this) 161 161 // { -
libcfa/src/exception.h
r92bfda0 rdafbde8 101 101 // implemented in the .c file either so they all have to be inline. 102 102 103 trait is_exception( dtype exceptT, dtype virtualT) {103 trait is_exception(exceptT &, virtualT &) { 104 104 /* The first field must be a pointer to a virtual table. 105 105 * That virtual table must be a decendent of the base exception virtual table. … … 109 109 }; 110 110 111 trait is_termination_exception( dtype exceptT, dtype virtualT| is_exception(exceptT, virtualT)) {111 trait is_termination_exception(exceptT &, virtualT & | is_exception(exceptT, virtualT)) { 112 112 void defaultTerminationHandler(exceptT &); 113 113 }; 114 114 115 trait is_resumption_exception( dtype exceptT, dtype virtualT| is_exception(exceptT, virtualT)) {115 trait is_resumption_exception(exceptT &, virtualT & | is_exception(exceptT, virtualT)) { 116 116 void defaultResumptionHandler(exceptT &); 117 117 }; 118 118 119 forall( dtype exceptT, dtype virtualT| is_termination_exception(exceptT, virtualT))119 forall(exceptT &, virtualT & | is_termination_exception(exceptT, virtualT)) 120 120 static inline void $throw(exceptT & except) { 121 121 __cfaehm_throw_terminate( … … 125 125 } 126 126 127 forall( dtype exceptT, dtype virtualT| is_resumption_exception(exceptT, virtualT))127 forall(exceptT &, virtualT & | is_resumption_exception(exceptT, virtualT)) 128 128 static inline void $throwResume(exceptT & except) { 129 129 __cfaehm_throw_resume( … … 133 133 } 134 134 135 forall( dtype exceptT, dtype virtualT| is_exception(exceptT, virtualT))135 forall(exceptT &, virtualT & | is_exception(exceptT, virtualT)) 136 136 static inline void cancel_stack(exceptT & except) __attribute__((noreturn)) { 137 137 __cfaehm_cancel_stack( (exception_t *)&except ); 138 138 } 139 139 140 forall( dtype exceptT, dtype virtualT| is_exception(exceptT, virtualT))140 forall(exceptT &, virtualT & | is_exception(exceptT, virtualT)) 141 141 static inline void defaultTerminationHandler(exceptT & except) { 142 142 return cancel_stack( except ); 143 143 } 144 144 145 forall( dtype exceptT, dtype virtualT| is_exception(exceptT, virtualT))145 forall(exceptT &, virtualT & | is_exception(exceptT, virtualT)) 146 146 static inline void defaultResumptionHandler(exceptT & except) { 147 147 throw except; -
libcfa/src/executor.cfa
r92bfda0 rdafbde8 7 7 #include <containers/list.hfa> 8 8 9 forall( dtype T| $dlistable(T, T) ) {9 forall( T & | $dlistable(T, T) ) { 10 10 monitor Buffer { // unbounded buffer 11 11 dlist( T, T ) queue; // unbounded list of work requests -
libcfa/src/gmp.hfa
r92bfda0 rdafbde8 255 255 256 256 // I/O 257 forall( dtype istype| istream( istype ) )257 forall( istype & | istream( istype ) ) 258 258 istype & ?|?( istype & is, Int & mp ) { 259 259 gmp_scanf( "%Zd", &mp ); … … 261 261 } // ?|? 262 262 263 forall( dtype ostype| ostream( ostype ) ) {263 forall( ostype & | ostream( ostype ) ) { 264 264 ostype & ?|?( ostype & os, Int mp ) { 265 265 if ( $sepPrt( os ) ) fmt( os, "%s", $sepGetCur( os ) ); -
libcfa/src/iostream.cfa
r92bfda0 rdafbde8 36 36 37 37 38 forall( dtype ostype| ostream( ostype ) ) {38 forall( ostype & | ostream( ostype ) ) { 39 39 ostype & ?|?( ostype & os, bool b ) { 40 40 if ( $sepPrt( os ) ) fmt( os, "%s", $sepGetCur( os ) ); … … 402 402 403 403 // tuples 404 forall( dtype ostype, otype T, ttype Params| writeable( T, ostype ) | { ostype & ?|?( ostype &, Params ); } ) {404 forall( ostype &, T, Params... | writeable( T, ostype ) | { ostype & ?|?( ostype &, Params ); } ) { 405 405 ostype & ?|?( ostype & os, T arg, Params rest ) { 406 406 (ostype &)(os | arg); // print first argument … … 421 421 422 422 // writes the range [begin, end) to the given stream 423 forall( dtype ostype, otype elt_type | writeable( elt_type, ostype ), otypeiterator_type | iterator( iterator_type, elt_type ) ) {423 forall( ostype &, elt_type | writeable( elt_type, ostype ), iterator_type | iterator( iterator_type, elt_type ) ) { 424 424 void write( iterator_type begin, iterator_type end, ostype & os ) { 425 425 void print( elt_type i ) { os | i; } … … 442 442 // Default prefix for non-decimal prints is 0b, 0, 0x. 443 443 #define IntegralFMTImpl( T, IFMTNP, IFMTP ) \ 444 forall( dtype ostype| ostream( ostype ) ) { \444 forall( ostype & | ostream( ostype ) ) { \ 445 445 ostype & ?|?( ostype & os, _Ostream_Manip(T) f ) { \ 446 446 if ( $sepPrt( os ) ) fmt( os, "%s", $sepGetCur( os ) ); \ … … 535 535 // Default prefix for non-decimal prints is 0b, 0, 0x. 536 536 #define IntegralFMTImpl128( T, SIGNED, CODE, IFMTNP, IFMTP ) \ 537 forall( dtype ostype| ostream( ostype ) ) \537 forall( ostype & | ostream( ostype ) ) \ 538 538 static void base10_128( ostype & os, _Ostream_Manip(T) f ) { \ 539 539 if ( f.val > UINT64_MAX ) { \ … … 552 552 } /* if */ \ 553 553 } /* base10_128 */ \ 554 forall( dtype ostype| ostream( ostype ) ) { \554 forall( ostype & | ostream( ostype ) ) { \ 555 555 ostype & ?|?( ostype & os, _Ostream_Manip(T) f ) { \ 556 556 if ( $sepPrt( os ) ) fmt( os, "%s", $sepGetCur( os ) ); \ … … 654 654 #if defined( __SIZEOF_INT128__ ) 655 655 // Default prefix for non-decimal prints is 0b, 0, 0x. 656 forall( dtype ostype| ostream( ostype ) )656 forall( ostype & | ostream( ostype ) ) 657 657 static inline void base_128( ostype & os, unsigned int128 val, unsigned int128 power, _Ostream_Manip(uint64_t) & f, unsigned int maxdig, unsigned int bits, unsigned int cnt = 0 ) { 658 658 int wd = 1; // f.wd is never 0 because 0 implies left-pad … … 719 719 720 720 #define IntegralFMTImpl128( T ) \ 721 forall( dtype ostype| ostream( ostype ) ) { \721 forall( ostype & | ostream( ostype ) ) { \ 722 722 ostype & ?|?( ostype & os, _Ostream_Manip(T) f ) { \ 723 723 _Ostream_Manip(uint64_t) fmt; \ … … 767 767 768 768 #define FloatingPointFMTImpl( T, DFMTNP, DFMTP ) \ 769 forall( dtype ostype| ostream( ostype ) ) { \769 forall( ostype & | ostream( ostype ) ) { \ 770 770 ostype & ?|?( ostype & os, _Ostream_Manip(T) f ) { \ 771 771 if ( $sepPrt( os ) ) fmt( os, "%s", $sepGetCur( os ) ); \ … … 801 801 // *********************************** character *********************************** 802 802 803 forall( dtype ostype| ostream( ostype ) ) {803 forall( ostype & | ostream( ostype ) ) { 804 804 ostype & ?|?( ostype & os, _Ostream_Manip(char) f ) { 805 805 if ( f.base != 'c' ) { // bespoke binary/octal/hex format … … 834 834 // *********************************** C string *********************************** 835 835 836 forall( dtype ostype| ostream( ostype ) ) {836 forall( ostype & | ostream( ostype ) ) { 837 837 ostype & ?|?( ostype & os, _Ostream_Manip(const char *) f ) { 838 838 if ( ! f.val ) return os; // null pointer ? … … 882 882 883 883 884 forall( dtype istype| istream( istype ) ) {884 forall( istype & | istream( istype ) ) { 885 885 istype & ?|?( istype & is, bool & b ) { 886 886 char val[6]; … … 1048 1048 // *********************************** manipulators *********************************** 1049 1049 1050 forall( dtype istype| istream( istype ) )1050 forall( istype & | istream( istype ) ) 1051 1051 istype & ?|?( istype & is, _Istream_Cstr f ) { 1052 1052 // skip xxx … … 1083 1083 } // ?|? 1084 1084 1085 forall( dtype istype| istream( istype ) )1085 forall( istype & | istream( istype ) ) 1086 1086 istype & ?|?( istype & is, _Istream_Char f ) { 1087 1087 fmt( is, "%*c" ); // argument variable unused … … 1090 1090 1091 1091 #define InputFMTImpl( T, CODE ) \ 1092 forall( dtype istype| istream( istype ) ) \1092 forall( istype & | istream( istype ) ) \ 1093 1093 istype & ?|?( istype & is, _Istream_Manip(T) f ) { \ 1094 1094 enum { size = 16 }; \ … … 1119 1119 InputFMTImpl( long double, "Lf" ) 1120 1120 1121 forall( dtype istype| istream( istype ) )1121 forall( istype & | istream( istype ) ) 1122 1122 istype & ?|?( istype & is, _Istream_Manip(float _Complex) fc ) { 1123 1123 float re, im; … … 1130 1130 } // ?|? 1131 1131 1132 forall( dtype istype| istream( istype ) )1132 forall( istype & | istream( istype ) ) 1133 1133 istype & ?|?( istype & is, _Istream_Manip(double _Complex) dc ) { 1134 1134 double re, im; … … 1141 1141 } // ?|? 1142 1142 1143 forall( dtype istype| istream( istype ) )1143 forall( istype & | istream( istype ) ) 1144 1144 istype & ?|?( istype & is, _Istream_Manip(long double _Complex) ldc ) { 1145 1145 long double re, im; -
libcfa/src/iostream.hfa
r92bfda0 rdafbde8 22 22 23 23 24 trait ostream( dtype ostype) {24 trait ostream( ostype & ) { 25 25 // private 26 26 bool $sepPrt( ostype & ); // get separator state (on/off) … … 56 56 }; // ostream 57 57 58 // trait writeable( otypeT ) {59 // forall( dtype ostype| ostream( ostype ) ) ostype & ?|?( ostype &, T );58 // trait writeable( T ) { 59 // forall( ostype & | ostream( ostype ) ) ostype & ?|?( ostype &, T ); 60 60 // }; // writeable 61 61 62 trait writeable( otype T, dtype ostype| ostream( ostype ) ) {62 trait writeable( T, ostype & | ostream( ostype ) ) { 63 63 ostype & ?|?( ostype &, T ); 64 64 }; // writeable … … 66 66 // implement writable for intrinsic types 67 67 68 forall( dtype ostype| ostream( ostype ) ) {68 forall( ostype & | ostream( ostype ) ) { 69 69 ostype & ?|?( ostype &, bool ); 70 70 void ?|?( ostype &, bool ); … … 140 140 141 141 // tuples 142 forall( dtype ostype, otype T, ttype Params| writeable( T, ostype ) | { ostype & ?|?( ostype &, Params ); } ) {142 forall( ostype &, T, Params... | writeable( T, ostype ) | { ostype & ?|?( ostype &, Params ); } ) { 143 143 ostype & ?|?( ostype & os, T arg, Params rest ); 144 144 void ?|?( ostype & os, T arg, Params rest ); … … 146 146 147 147 // writes the range [begin, end) to the given stream 148 forall( dtype ostype, otype elt_type | writeable( elt_type, ostype ), otypeiterator_type | iterator( iterator_type, elt_type ) ) {148 forall( ostype &, elt_type | writeable( elt_type, ostype ), iterator_type | iterator( iterator_type, elt_type ) ) { 149 149 void write( iterator_type begin, iterator_type end, ostype & os ); 150 150 void write_reverse( iterator_type begin, iterator_type end, ostype & os ); … … 153 153 // *********************************** manipulators *********************************** 154 154 155 forall( otypeT )155 forall( T ) 156 156 struct _Ostream_Manip { 157 157 T val; // polymorphic base-type … … 193 193 _Ostream_Manip(T) & sign( _Ostream_Manip(T) & fmt ) { fmt.flags.sign = true; return fmt; } \ 194 194 } /* distribution */ \ 195 forall( dtype ostype| ostream( ostype ) ) { \195 forall( ostype & | ostream( ostype ) ) { \ 196 196 ostype & ?|?( ostype & os, _Ostream_Manip(T) f ); \ 197 197 void ?|?( ostype & os, _Ostream_Manip(T) f ); \ … … 234 234 _Ostream_Manip(T) & nodp( _Ostream_Manip(T) & fmt ) { fmt.flags.nobsdp = true; return fmt; } \ 235 235 } /* distribution */ \ 236 forall( dtype ostype| ostream( ostype ) ) { \236 forall( ostype & | ostream( ostype ) ) { \ 237 237 ostype & ?|?( ostype & os, _Ostream_Manip(T) f ); \ 238 238 void ?|?( ostype & os, _Ostream_Manip(T) f ); \ … … 254 254 _Ostream_Manip(char) & nobase( _Ostream_Manip(char) & fmt ) { fmt.flags.nobsdp = true; return fmt; } 255 255 } // distribution 256 forall( dtype ostype| ostream( ostype ) ) {256 forall( ostype & | ostream( ostype ) ) { 257 257 ostype & ?|?( ostype & os, _Ostream_Manip(char) f ); 258 258 void ?|?( ostype & os, _Ostream_Manip(char) f ); … … 272 272 _Ostream_Manip(const char *) & nobase( _Ostream_Manip(const char *) & fmt ) { fmt.flags.nobsdp = true; return fmt; } 273 273 } // distribution 274 forall( dtype ostype| ostream( ostype ) ) {274 forall( ostype & | ostream( ostype ) ) { 275 275 ostype & ?|?( ostype & os, _Ostream_Manip(const char *) f ); 276 276 void ?|?( ostype & os, _Ostream_Manip(const char *) f ); … … 281 281 282 282 283 trait istream( dtype istype) {283 trait istream( istype & ) { 284 284 void nlOn( istype & ); // read newline 285 285 void nlOff( istype & ); // scan newline … … 294 294 }; // istream 295 295 296 trait readable( otypeT ) {297 forall( dtype istype| istream( istype ) ) istype & ?|?( istype &, T );296 trait readable( T ) { 297 forall( istype & | istream( istype ) ) istype & ?|?( istype &, T ); 298 298 }; // readable 299 299 300 forall( dtype istype| istream( istype ) ) {300 forall( istype & | istream( istype ) ) { 301 301 istype & ?|?( istype &, bool & ); 302 302 … … 363 363 _Istream_Cstr & wdi( unsigned int w, _Istream_Cstr & fmt ) { fmt.wd = w; return fmt; } 364 364 } // distribution 365 forall( dtype istype| istream( istype ) ) istype & ?|?( istype & is, _Istream_Cstr f );365 forall( istype & | istream( istype ) ) istype & ?|?( istype & is, _Istream_Cstr f ); 366 366 367 367 struct _Istream_Char { … … 373 373 _Istream_Char & ignore( _Istream_Char & fmt ) { fmt.ignore = true; return fmt; } 374 374 } // distribution 375 forall( dtype istype| istream( istype ) ) istype & ?|?( istype & is, _Istream_Char f );376 377 forall( dtype T| sized( T ) )375 forall( istype & | istream( istype ) ) istype & ?|?( istype & is, _Istream_Char f ); 376 377 forall( T & | sized( T ) ) 378 378 struct _Istream_Manip { 379 379 T & val; // polymorphic base-type … … 389 389 _Istream_Manip(T) & wdi( unsigned int w, _Istream_Manip(T) & fmt ) { fmt.wd = w; return fmt; } \ 390 390 } /* distribution */ \ 391 forall( dtype istype| istream( istype ) ) { \391 forall( istype & | istream( istype ) ) { \ 392 392 istype & ?|?( istype & is, _Istream_Manip(T) f ); \ 393 393 } // ?|? … … 418 418 #include <time_t.hfa> // Duration (constructors) / Time (constructors) 419 419 420 forall( dtype ostype| ostream( ostype ) ) {420 forall( ostype & | ostream( ostype ) ) { 421 421 ostype & ?|?( ostype & os, Duration dur ); 422 422 void ?|?( ostype & os, Duration dur ); -
libcfa/src/iterator.cfa
r92bfda0 rdafbde8 16 16 #include "iterator.hfa" 17 17 18 forall( otype iterator_type, otypeelt_type | iterator( iterator_type, elt_type ) )18 forall( iterator_type, elt_type | iterator( iterator_type, elt_type ) ) 19 19 void for_each( iterator_type begin, iterator_type end, void (* func)( elt_type ) ) { 20 20 for ( iterator_type i = begin; i != end; ++i ) { … … 23 23 } // for_each 24 24 25 forall( otype iterator_type, otypeelt_type | iterator( iterator_type, elt_type ) )25 forall( iterator_type, elt_type | iterator( iterator_type, elt_type ) ) 26 26 void for_each_reverse( iterator_type begin, iterator_type end, void (* func)( elt_type ) ) { 27 27 for ( iterator_type i = end; i != begin; ) { -
libcfa/src/iterator.hfa
r92bfda0 rdafbde8 17 17 18 18 // An iterator can be used to traverse a data structure. 19 trait iterator( otype iterator_type, otypeelt_type ) {19 trait iterator( iterator_type, elt_type ) { 20 20 // point to the next element 21 21 // iterator_type ?++( iterator_type & ); … … 31 31 }; 32 32 33 trait iterator_for( otype iterator_type, otype collection_type, otypeelt_type | iterator( iterator_type, elt_type ) ) {33 trait iterator_for( iterator_type, collection_type, elt_type | iterator( iterator_type, elt_type ) ) { 34 34 // [ iterator_type begin, iterator_type end ] get_iterators( collection_type ); 35 35 iterator_type begin( collection_type ); … … 37 37 }; 38 38 39 forall( otype iterator_type, otypeelt_type | iterator( iterator_type, elt_type ) )39 forall( iterator_type, elt_type | iterator( iterator_type, elt_type ) ) 40 40 void for_each( iterator_type begin, iterator_type end, void (* func)( elt_type ) ); 41 41 42 forall( otype iterator_type, otypeelt_type | iterator( iterator_type, elt_type ) )42 forall( iterator_type, elt_type | iterator( iterator_type, elt_type ) ) 43 43 void for_each_reverse( iterator_type begin, iterator_type end, void (* func)( elt_type ) ); 44 44 -
libcfa/src/math.hfa
r92bfda0 rdafbde8 286 286 unsigned long long int floor( unsigned long long int n, unsigned long long int align ) { return n / align * align; } 287 287 288 // forall( otypeT | { T ?/?( T, T ); T ?*?( T, T ); } )288 // forall( T | { T ?/?( T, T ); T ?*?( T, T ); } ) 289 289 // T floor( T n, T align ) { return n / align * align; } 290 290 … … 300 300 unsigned long long int ceiling_div( unsigned long long int n, unsigned long long int align ) { return (n + (align - 1)) / align; } 301 301 302 // forall( otypeT | { T ?+?( T, T ); T ?-?( T, T ); T ?%?( T, T ); } )302 // forall( T | { T ?+?( T, T ); T ?-?( T, T ); T ?%?( T, T ); } ) 303 303 // T ceiling_div( T n, T align ) { verify( is_pow2( align ) );return (n + (align - 1)) / align; } 304 304 … … 315 315 unsigned long long int ceiling( unsigned long long int n, unsigned long long int align ) { return floor( n + (n % align != 0 ? align - 1 : 0), align ); } 316 316 317 // forall( otypeT | { void ?{}( T &, one_t ); T ?+?( T, T ); T ?-?( T, T ); T ?/?( T, T ); } )317 // forall( T | { void ?{}( T &, one_t ); T ?+?( T, T ); T ?-?( T, T ); T ?/?( T, T ); } ) 318 318 // T ceiling( T n, T align ) { return return floor( n + (n % align != 0 ? align - 1 : 0), align ); *} 319 319 … … 414 414 415 415 static inline { 416 forall( otypeT | { void ?{}( T &, one_t ); T ?+?( T, T ); T ?-?( T, T );T ?*?( T, T ); } )416 forall( T | { void ?{}( T &, one_t ); T ?+?( T, T ); T ?-?( T, T );T ?*?( T, T ); } ) 417 417 T lerp( T x, T y, T a ) { return x * ((T){1} - a) + y * a; } 418 418 419 forall( otypeT | { void ?{}( T &, zero_t ); void ?{}( T &, one_t ); int ?<?( T, T ); } )419 forall( T | { void ?{}( T &, zero_t ); void ?{}( T &, one_t ); int ?<?( T, T ); } ) 420 420 T step( T edge, T x ) { return x < edge ? (T){0} : (T){1}; } 421 421 422 forall( otypeT | { void ?{}( T &, int ); T clamp( T, T, T ); T ?-?( T, T ); T ?*?( T, T ); T ?/?( T, T ); } )422 forall( T | { void ?{}( T &, int ); T clamp( T, T, T ); T ?-?( T, T ); T ?*?( T, T ); T ?/?( T, T ); } ) 423 423 T smoothstep( T edge0, T edge1, T x ) { T t = clamp( (x - edge0) / (edge1 - edge0), (T){0}, (T){1} ); return t * t * ((T){3} - (T){2} * t); } 424 424 } // distribution -
libcfa/src/memory.cfa
r92bfda0 rdafbde8 18 18 19 19 // Internal data object. 20 forall( dtype T | sized(T), ttype Args| { void ?{}(T &, Args); })20 forall(T & | sized(T), Args... | { void ?{}(T &, Args); }) 21 21 void ?{}(counter_data(T) & this, Args args) { 22 22 (this.counter){1}; … … 24 24 } 25 25 26 forall( dtype T| sized(T) | { void ^?{}(T &); })26 forall(T & | sized(T) | { void ^?{}(T &); }) 27 27 void ^?{}(counter_data(T) & this) { 28 28 assert(0 == this.counter); … … 31 31 32 32 // This is one of many pointers keeping this alive. 33 forall( dtype T| sized(T))33 forall(T & | sized(T)) 34 34 void ?{}(counter_ptr(T) & this) { 35 35 this.data = 0p; 36 36 } 37 37 38 forall( dtype T| sized(T))38 forall(T & | sized(T)) 39 39 void ?{}(counter_ptr(T) & this, zero_t) { 40 40 this.data = 0p; 41 41 } 42 42 43 forall( dtype T| sized(T) | { void ^?{}(T &); })43 forall(T & | sized(T) | { void ^?{}(T &); }) 44 44 static void internal_decrement(counter_ptr(T) & this) { 45 45 if (this.data && 0 == --this.data->counter) { … … 48 48 } 49 49 50 forall( dtype T| sized(T))50 forall(T & | sized(T)) 51 51 static void internal_copy(counter_ptr(T) & this, counter_ptr(T) & that) { 52 52 this.data = that.data; … … 56 56 } 57 57 58 forall( dtype T| sized(T) | { void ^?{}(T &); })58 forall(T & | sized(T) | { void ^?{}(T &); }) 59 59 void ?{}(counter_ptr(T) & this, counter_ptr(T) that) { 60 60 // `that` is a copy but it should have neither a constructor … … 64 64 } 65 65 66 forall( dtype T | sized(T), ttype Args| { void ?{}(T&, Args); })66 forall(T & | sized(T), Args... | { void ?{}(T&, Args); }) 67 67 void ?{}(counter_ptr(T) & this, Args args) { 68 68 this.data = (counter_data(T)*)new(args); 69 69 } 70 70 71 forall( dtype T| sized(T) | { void ^?{}(T &); })71 forall(T & | sized(T) | { void ^?{}(T &); }) 72 72 void ^?{}(counter_ptr(T) & this) { 73 73 internal_decrement(this); 74 74 } 75 75 76 forall( dtype T| sized(T))76 forall(T & | sized(T)) 77 77 T & *?(counter_ptr(T) & this) { 78 78 return *((this.data) ? &this.data->object : 0p); 79 79 } 80 80 81 forall( dtype T| sized(T) | { void ^?{}(T &); })81 forall(T & | sized(T) | { void ^?{}(T &); }) 82 82 void ?=?(counter_ptr(T) & this, counter_ptr(T) that) { 83 83 if (this.data != that.data) { … … 87 87 } 88 88 89 forall( dtype T| sized(T) | { void ^?{}(T &); })89 forall(T & | sized(T) | { void ^?{}(T &); }) 90 90 void ?=?(counter_ptr(T) & this, zero_t) { 91 91 internal_decrement(this); … … 93 93 } 94 94 95 forall( dtype T| sized(T))95 forall(T & | sized(T)) 96 96 int ?==?(counter_ptr(T) const & this, counter_ptr(T) const & that) { 97 97 return this.data == that.data; 98 98 } 99 99 100 forall( dtype T| sized(T))100 forall(T & | sized(T)) 101 101 int ?!=?(counter_ptr(T) const & this, counter_ptr(T) const & that) { 102 102 return !?==?(this, that); 103 103 } 104 104 105 forall( dtype T| sized(T))105 forall(T & | sized(T)) 106 106 int ?==?(counter_ptr(T) const & this, zero_t) { 107 107 return this.data == 0; 108 108 } 109 109 110 forall( dtype T| sized(T))110 forall(T & | sized(T)) 111 111 int ?!=?(counter_ptr(T) const & this, zero_t) { 112 112 return !?==?(this, (zero_t)0); … … 114 114 115 115 // This is the only pointer that keeps this alive. 116 forall( dtype T)116 forall(T &) 117 117 void ?{}(unique_ptr(T) & this) { 118 118 this.data = 0p; 119 119 } 120 120 121 forall( dtype T)121 forall(T &) 122 122 void ?{}(unique_ptr(T) & this, zero_t) { 123 123 this.data = 0p; 124 124 } 125 125 126 forall( dtype T | sized(T), ttype Args| { void ?{}(T &, Args); })126 forall(T & | sized(T), Args... | { void ?{}(T &, Args); }) 127 127 void ?{}(unique_ptr(T) & this, Args args) { 128 128 this.data = (T *)new(args); 129 129 } 130 130 131 forall( dtype T| { void ^?{}(T &); })131 forall(T & | { void ^?{}(T &); }) 132 132 void ^?{}(unique_ptr(T) & this) { 133 133 delete(this.data); 134 134 } 135 135 136 forall( dtype T)136 forall(T &) 137 137 T & *?(unique_ptr(T) & this) { 138 138 return *this.data; 139 139 } 140 140 141 forall( dtype T| { void ^?{}(T &); })141 forall(T & | { void ^?{}(T &); }) 142 142 void ?=?(unique_ptr(T) & this, zero_t) { 143 143 delete(this.data); … … 145 145 } 146 146 147 forall( dtype T| { void ^?{}(T &); })147 forall(T & | { void ^?{}(T &); }) 148 148 void move(unique_ptr(T) & this, unique_ptr(T) & that) { 149 149 delete(this.data); … … 152 152 } 153 153 154 forall( dtype T)154 forall(T &) 155 155 int ?==?(unique_ptr(T) const & this, unique_ptr(T) const & that) { 156 156 return this.data == that.data; 157 157 } 158 158 159 forall( dtype T)159 forall(T &) 160 160 int ?!=?(unique_ptr(T) const & this, unique_ptr(T) const & that) { 161 161 return !?==?(this, that); 162 162 } 163 163 164 forall( dtype T)164 forall(T &) 165 165 int ?==?(unique_ptr(T) const & this, zero_t) { 166 166 return this.data == 0; 167 167 } 168 168 169 forall( dtype T)169 forall(T &) 170 170 int ?!=?(unique_ptr(T) const & this, zero_t) { 171 171 return !?==?(this, (zero_t)0); -
libcfa/src/memory.hfa
r92bfda0 rdafbde8 17 17 18 18 // Internal data object. 19 forall( dtype T| sized(T)) {19 forall(T & | sized(T)) { 20 20 struct counter_data { 21 21 unsigned int counter; … … 23 23 }; 24 24 25 forall( ttype Args| { void ?{}(T &, Args); })25 forall(Args... | { void ?{}(T &, Args); }) 26 26 void ?{}(counter_data(T) & this, Args args); 27 27 … … 31 31 32 32 // This is one of many pointers keeping this alive. 33 forall( dtype T| sized(T)) {33 forall(T & | sized(T)) { 34 34 struct counter_ptr { 35 35 counter_data(T) * data; … … 40 40 forall( | { void ^?{}(T &); }) 41 41 void ?{}(counter_ptr(T) & this, counter_ptr(T) that); 42 forall( ttype Args| { void ?{}(T&, Args); })42 forall(Args... | { void ?{}(T&, Args); }) 43 43 void ?{}(counter_ptr(T) & this, Args args); 44 44 … … 60 60 61 61 // This is the only pointer that keeps this alive. 62 forall( dtype T) {62 forall(T &) { 63 63 struct unique_ptr { 64 64 T * data; … … 68 68 void ?{}(unique_ptr(T) & this, zero_t); 69 69 void ?{}(unique_ptr(T) & this, unique_ptr(T) that) = void; 70 forall( | sized(T), ttype Args| { void ?{}(T &, Args); })70 forall( | sized(T), Args... | { void ?{}(T &, Args); }) 71 71 void ?{}(unique_ptr(T) & this, Args args); 72 72 -
libcfa/src/parseargs.hfa
r92bfda0 rdafbde8 14 14 static inline void ?{}( cfa_option & this ) {} 15 15 16 forall( dtype T| { bool parse(const char *, T & ); })16 forall(T & | { bool parse(const char *, T & ); }) 17 17 static inline void ?{}( cfa_option & this, char short_name, const char * long_name, const char * help, T & variable ) { 18 18 this.val = 0; … … 24 24 } 25 25 26 forall( dtype T)26 forall(T &) 27 27 static inline void ?{}( cfa_option & this, char short_name, const char * long_name, const char * help, T & variable, bool (*parse)(const char *, T & )) { 28 28 this.val = 0; -
libcfa/src/rational.cfa
r92bfda0 rdafbde8 18 18 #include "stdlib.hfa" 19 19 20 forall( otypeRationalImpl | arithmetic( RationalImpl ) ) {20 forall( RationalImpl | arithmetic( RationalImpl ) ) { 21 21 // helper routines 22 22 … … 159 159 // I/O 160 160 161 forall( dtype istype| istream( istype ) | { istype & ?|?( istype &, RationalImpl & ); } )161 forall( istype & | istream( istype ) | { istype & ?|?( istype &, RationalImpl & ); } ) 162 162 istype & ?|?( istype & is, Rational(RationalImpl) & r ) { 163 163 is | r.numerator | r.denominator; … … 168 168 } // ?|? 169 169 170 forall( dtype ostype| ostream( ostype ) | { ostype & ?|?( ostype &, RationalImpl ); } ) {170 forall( ostype & | ostream( ostype ) | { ostype & ?|?( ostype &, RationalImpl ); } ) { 171 171 ostype & ?|?( ostype & os, Rational(RationalImpl) r ) { 172 172 return os | r.numerator | '/' | r.denominator; … … 179 179 } // distribution 180 180 181 forall( otypeRationalImpl | arithmetic( RationalImpl ) | { RationalImpl ?\?( RationalImpl, unsigned long ); } )181 forall( RationalImpl | arithmetic( RationalImpl ) | { RationalImpl ?\?( RationalImpl, unsigned long ); } ) 182 182 Rational(RationalImpl) ?\?( Rational(RationalImpl) x, long int y ) { 183 183 if ( y < 0 ) { … … 190 190 // conversion 191 191 192 forall( otypeRationalImpl | arithmetic( RationalImpl ) | { double convert( RationalImpl ); } )192 forall( RationalImpl | arithmetic( RationalImpl ) | { double convert( RationalImpl ); } ) 193 193 double widen( Rational(RationalImpl) r ) { 194 194 return convert( r.numerator ) / convert( r.denominator ); 195 195 } // widen 196 196 197 forall( otypeRationalImpl | arithmetic( RationalImpl ) | { double convert( RationalImpl ); RationalImpl convert( double ); } )197 forall( RationalImpl | arithmetic( RationalImpl ) | { double convert( RationalImpl ); RationalImpl convert( double ); } ) 198 198 Rational(RationalImpl) narrow( double f, RationalImpl md ) { 199 199 // http://www.ics.uci.edu/~eppstein/numth/frap.c -
libcfa/src/rational.hfa
r92bfda0 rdafbde8 20 20 #include "iostream.hfa" 21 21 22 trait scalar( otypeT ) {22 trait scalar( T ) { 23 23 }; 24 24 25 trait arithmetic( otypeT | scalar( T ) ) {25 trait arithmetic( T | scalar( T ) ) { 26 26 int !?( T ); 27 27 int ?==?( T, T ); … … 46 46 // implementation 47 47 48 forall( otypeRationalImpl | arithmetic( RationalImpl ) ) {48 forall( RationalImpl | arithmetic( RationalImpl ) ) { 49 49 struct Rational { 50 50 RationalImpl numerator, denominator; // invariant: denominator > 0 … … 89 89 90 90 // I/O 91 forall( dtype istype| istream( istype ) | { istype & ?|?( istype &, RationalImpl & ); } )91 forall( istype & | istream( istype ) | { istype & ?|?( istype &, RationalImpl & ); } ) 92 92 istype & ?|?( istype &, Rational(RationalImpl) & ); 93 93 94 forall( dtype ostype| ostream( ostype ) | { ostype & ?|?( ostype &, RationalImpl ); } ) {94 forall( ostype & | ostream( ostype ) | { ostype & ?|?( ostype &, RationalImpl ); } ) { 95 95 ostype & ?|?( ostype &, Rational(RationalImpl) ); 96 96 void ?|?( ostype &, Rational(RationalImpl) ); … … 98 98 } // distribution 99 99 100 forall( otypeRationalImpl | arithmetic( RationalImpl ) |{RationalImpl ?\?( RationalImpl, unsigned long );} )100 forall( RationalImpl | arithmetic( RationalImpl ) |{RationalImpl ?\?( RationalImpl, unsigned long );} ) 101 101 Rational(RationalImpl) ?\?( Rational(RationalImpl) x, long int y ); 102 102 103 103 // conversion 104 forall( otypeRationalImpl | arithmetic( RationalImpl ) | { double convert( RationalImpl ); } )104 forall( RationalImpl | arithmetic( RationalImpl ) | { double convert( RationalImpl ); } ) 105 105 double widen( Rational(RationalImpl) r ); 106 forall( otypeRationalImpl | arithmetic( RationalImpl ) | { double convert( RationalImpl ); RationalImpl convert( double );} )106 forall( RationalImpl | arithmetic( RationalImpl ) | { double convert( RationalImpl ); RationalImpl convert( double );} ) 107 107 Rational(RationalImpl) narrow( double f, RationalImpl md ); 108 108 -
libcfa/src/stdlib.cfa
r92bfda0 rdafbde8 28 28 // Cforall allocation/deallocation and constructor/destructor, array types 29 29 30 forall( dtype T | sized(T), ttype TT| { void ?{}( T &, TT ); } )30 forall( T & | sized(T), TT... | { void ?{}( T &, TT ); } ) 31 31 T * anew( size_t dim, TT p ) { 32 32 T * arr = alloc( dim ); … … 37 37 } // anew 38 38 39 forall( dtype T| sized(T) | { void ^?{}( T & ); } )39 forall( T & | sized(T) | { void ^?{}( T & ); } ) 40 40 void adelete( T arr[] ) { 41 41 if ( arr ) { // ignore null … … 48 48 } // adelete 49 49 50 forall( dtype T | sized(T) | { void ^?{}( T & ); }, ttype TT| { void adelete( TT ); } )50 forall( T & | sized(T) | { void ^?{}( T & ); }, TT... | { void adelete( TT ); } ) 51 51 void adelete( T arr[], TT rest ) { 52 52 if ( arr ) { // ignore null … … 97 97 //--------------------------------------- 98 98 99 forall( otypeE | { int ?<?( E, E ); } ) {99 forall( E | { int ?<?( E, E ); } ) { 100 100 E * bsearch( E key, const E * vals, size_t dim ) { 101 101 int cmp( const void * t1, const void * t2 ) { … … 156 156 157 157 158 forall( otype K, otypeE | { int ?<?( K, K ); K getKey( const E & ); } ) {158 forall( K, E | { int ?<?( K, K ); K getKey( const E & ); } ) { 159 159 E * bsearch( K key, const E * vals, size_t dim ) { 160 160 int cmp( const void * t1, const void * t2 ) { -
libcfa/src/stdlib.hfa
r92bfda0 rdafbde8 10 10 // Created On : Thu Jan 28 17:12:35 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sat Dec 12 13:52:34 202013 // Update Count : 5 3612 // Last Modified On : Sat Jan 16 09:07:10 2021 13 // Update Count : 568 14 14 // 15 15 … … 48 48 else return (T *)alignment( _Alignof(T), dim, sizeof(T) ) 49 49 50 static inline forall( dtype T| sized(T) ) {50 static inline forall( T & | sized(T) ) { 51 51 // CFA safe equivalents, i.e., implicit size specification 52 52 … … 108 108 109 109 1. Replace the current forall-block that contains defintions of S_fill and S_realloc with following: 110 forall( dtype T| sized(T) ) {110 forall( T & | sized(T) ) { 111 111 union U_fill { char c; T * a; T t; }; 112 112 struct S_fill { char tag; U_fill(T) fill; }; … … 151 151 typedef struct S_resize { inline void *; } T_resize; 152 152 153 forall( dtype T) {153 forall( T & ) { 154 154 struct S_fill { char tag; char c; size_t size; T * at; char t[50]; }; 155 155 struct S_realloc { inline T *; }; … … 159 159 static inline T_resize ?`resize ( void * a ) { return (T_resize){a}; } 160 160 161 static inline forall( dtype T| sized(T) ) {161 static inline forall( T & | sized(T) ) { 162 162 S_fill(T) ?`fill ( T t ) { 163 163 S_fill(T) ret = { 't' }; 164 164 size_t size = sizeof(T); 165 if(size > sizeof(ret.t)) { printf("ERROR: const object of size greater than 50 bytes given for dynamic memory fill\n"); exit(1); } 165 if ( size > sizeof(ret.t) ) { 166 abort( "ERROR: const object of size greater than 50 bytes given for dynamic memory fill\n" ); 167 } // if 166 168 memcpy( &ret.t, &t, size ); 167 169 return ret; … … 173 175 S_realloc(T) ?`realloc ( T * a ) { return (S_realloc(T)){a}; } 174 176 175 T * $alloc_internal( void * Resize, T * Realloc, size_t Align, size_t Dim, S_fill(T) Fill ) {177 T * $alloc_internal( void * Resize, T * Realloc, size_t Align, size_t Dim, S_fill(T) Fill ) { 176 178 T * ptr = NULL; 177 179 size_t size = sizeof(T); … … 181 183 ptr = (T*) (void *) resize( (void *)Resize, Align, Dim * size ); 182 184 } else if ( Realloc ) { 183 if ( Fill.tag != '0') copy_end = min(malloc_size( Realloc ), Dim * size);184 ptr = (T *) (void *) realloc( (void *)Realloc, Align, Dim * size );185 if ( Fill.tag != '0' ) copy_end = min(malloc_size( Realloc ), Dim * size ); 186 ptr = (T *) (void *) realloc( (void *)Realloc, Align, Dim * size ); 185 187 } else { 186 ptr = (T *) (void *) memalign( Align, Dim * size );187 } 188 189 if (Fill.tag == 'c') {188 ptr = (T *) (void *) memalign( Align, Dim * size ); 189 } 190 191 if ( Fill.tag == 'c' ) { 190 192 memset( (char *)ptr + copy_end, (int)Fill.c, Dim * size - copy_end ); 191 } else if (Fill.tag == 't') {193 } else if ( Fill.tag == 't' ) { 192 194 for ( int i = copy_end; i < Dim * size; i += size ) { 193 #pragma GCC diagnostic push 194 #pragma GCC diagnostic ignored "-Warray-bounds" 195 #pragma GCC diagnostic push 196 #pragma GCC diagnostic ignored "-Wstringop-overflow=" 197 memcpy( (char *)ptr + i, &Fill.t, size ); 198 #pragma GCC diagnostic pop 199 #pragma GCC diagnostic pop 195 #pragma GCC diagnostic push 196 #pragma GCC diagnostic ignored "-Wmaybe-uninitialized" 197 memcpy( (char *)ptr + i, &Fill.t, sizeof(Fill.t) ); 198 #pragma GCC diagnostic pop 200 199 } 201 } else if (Fill.tag == 'a') {200 } else if ( Fill.tag == 'a' ) { 202 201 memcpy( (char *)ptr + copy_end, Fill.at, min(Dim * size - copy_end, Fill.size) ); 203 } else if(Fill.tag == 'T') { 204 for ( int i = copy_end; i < Dim * size; i += size ) { 205 memcpy( (char *)ptr + i, Fill.at, size ); 206 } 202 } else if ( Fill.tag == 'T' ) { 203 memcpy( (char *)ptr + copy_end, Fill.at, Dim * size ); 207 204 } 208 205 … … 210 207 } // $alloc_internal 211 208 212 forall( ttype TT| { T * $alloc_internal( void *, T *, size_t, size_t, S_fill(T), TT ); } ) {209 forall( TT... | { T * $alloc_internal( void *, T *, size_t, size_t, S_fill(T), TT ); } ) { 213 210 214 211 T * $alloc_internal( void * , T * Realloc, size_t Align, size_t Dim, S_fill(T) Fill, T_resize Resize, TT rest) { … … 239 236 } // distribution T 240 237 241 static inline forall( dtype T| sized(T) ) {238 static inline forall( T & | sized(T) ) { 242 239 // CFA safe initialization/copy, i.e., implicit size specification, non-array types 243 240 T * memset( T * dest, char fill ) { … … 260 257 261 258 // CFA deallocation for multiple objects 262 static inline forall( dtype T) // FIX ME, problems with 0p in list259 static inline forall( T & ) // FIX ME, problems with 0p in list 263 260 void free( T * ptr ) { 264 261 free( (void *)ptr ); // C free 265 262 } // free 266 static inline forall( dtype T, ttype TT| { void free( TT ); } )263 static inline forall( T &, TT... | { void free( TT ); } ) 267 264 void free( T * ptr, TT rest ) { 268 265 free( ptr ); … … 271 268 272 269 // CFA allocation/deallocation and constructor/destructor, non-array types 273 static inline forall( dtype T | sized(T), ttype TT| { void ?{}( T &, TT ); } )270 static inline forall( T & | sized(T), TT... | { void ?{}( T &, TT ); } ) 274 271 T * new( TT p ) { 275 272 return &(*(T *)malloc()){ p }; // run constructor 276 273 } // new 277 274 278 static inline forall( dtype T| { void ^?{}( T & ); } )275 static inline forall( T & | { void ^?{}( T & ); } ) 279 276 void delete( T * ptr ) { 280 277 // special case for 0-sized object => always call destructor … … 284 281 free( ptr ); // always call free 285 282 } // delete 286 static inline forall( dtype T, ttype TT| { void ^?{}( T & ); void delete( TT ); } )283 static inline forall( T &, TT... | { void ^?{}( T & ); void delete( TT ); } ) 287 284 void delete( T * ptr, TT rest ) { 288 285 delete( ptr ); … … 291 288 292 289 // CFA allocation/deallocation and constructor/destructor, array types 293 forall( dtype T | sized(T), ttype TT| { void ?{}( T &, TT ); } ) T * anew( size_t dim, TT p );294 forall( dtype T| sized(T) | { void ^?{}( T & ); } ) void adelete( T arr[] );295 forall( dtype T | sized(T) | { void ^?{}( T & ); }, ttype TT| { void adelete( TT ); } ) void adelete( T arr[], TT rest );290 forall( T & | sized(T), TT... | { void ?{}( T &, TT ); } ) T * anew( size_t dim, TT p ); 291 forall( T & | sized(T) | { void ^?{}( T & ); } ) void adelete( T arr[] ); 292 forall( T & | sized(T) | { void ^?{}( T & ); }, TT... | { void adelete( TT ); } ) void adelete( T arr[], TT rest ); 296 293 297 294 //--------------------------------------- … … 333 330 //--------------------------------------- 334 331 335 forall( otypeE | { int ?<?( E, E ); } ) {332 forall( E | { int ?<?( E, E ); } ) { 336 333 E * bsearch( E key, const E * vals, size_t dim ); 337 334 size_t bsearch( E key, const E * vals, size_t dim ); … … 342 339 } // distribution 343 340 344 forall( otype K, otypeE | { int ?<?( K, K ); K getKey( const E & ); } ) {341 forall( K, E | { int ?<?( K, K ); K getKey( const E & ); } ) { 345 342 E * bsearch( K key, const E * vals, size_t dim ); 346 343 size_t bsearch( K key, const E * vals, size_t dim ); … … 351 348 } // distribution 352 349 353 forall( otypeE | { int ?<?( E, E ); } ) {350 forall( E | { int ?<?( E, E ); } ) { 354 351 void qsort( E * vals, size_t dim ); 355 352 } // distribution -
libcfa/src/time.cfa
r92bfda0 rdafbde8 31 31 32 32 33 forall( dtype ostype| ostream( ostype ) ) {33 forall( ostype & | ostream( ostype ) ) { 34 34 ostype & ?|?( ostype & os, Duration dur ) with( dur ) { 35 35 (ostype &)(os | tn / TIMEGRAN); // print seconds … … 136 136 } // strftime 137 137 138 forall( dtype ostype| ostream( ostype ) ) {138 forall( ostype & | ostream( ostype ) ) { 139 139 ostype & ?|?( ostype & os, Time time ) with( time ) { 140 140 char buf[32]; // at least 26 -
libcfa/src/vec/vec.hfa
r92bfda0 rdafbde8 18 18 #include <math.hfa> 19 19 20 trait fromint( otypeT) {20 trait fromint(T) { 21 21 void ?{}(T&, int); 22 22 }; 23 trait zeroinit( otypeT) {23 trait zeroinit(T) { 24 24 void ?{}(T&, zero_t); 25 25 }; 26 trait zero_assign( otypeT) {26 trait zero_assign(T) { 27 27 T ?=?(T&, zero_t); 28 28 }; 29 trait subtract( otypeT) {29 trait subtract(T) { 30 30 T ?-?(T, T); 31 31 }; 32 trait negate( otypeT) {32 trait negate(T) { 33 33 T -?(T); 34 34 }; 35 trait add( otypeT) {35 trait add(T) { 36 36 T ?+?(T, T); 37 37 }; 38 trait multiply( otypeT) {38 trait multiply(T) { 39 39 T ?*?(T, T); 40 40 }; 41 trait divide( otypeT) {41 trait divide(T) { 42 42 T ?/?(T, T); 43 43 }; 44 trait lessthan( otypeT) {44 trait lessthan(T) { 45 45 int ?<?(T, T); 46 46 }; 47 trait equality( otypeT) {47 trait equality(T) { 48 48 int ?==?(T, T); 49 49 }; 50 trait sqrt( otypeT) {50 trait sqrt(T) { 51 51 T sqrt(T); 52 52 }; … … 68 68 } 69 69 70 trait dottable( otype V, otypeT) {70 trait dottable(V, T) { 71 71 T dot(V, V); 72 72 }; … … 74 74 static inline { 75 75 76 forall( otype T | sqrt(T), otypeV | dottable(V, T))76 forall(T | sqrt(T), V | dottable(V, T)) 77 77 T length(V v) { 78 78 return sqrt(dot(v, v)); 79 79 } 80 80 81 forall( otype T, otypeV | dottable(V, T))81 forall(T, V | dottable(V, T)) 82 82 T length_squared(V v) { 83 83 return dot(v, v); 84 84 } 85 85 86 forall( otype T, otypeV | { T length(V); } | subtract(V))86 forall(T, V | { T length(V); } | subtract(V)) 87 87 T distance(V v1, V v2) { 88 88 return length(v1 - v2); 89 89 } 90 90 91 forall( otype T, otypeV | { T length(V); V ?/?(V, T); })91 forall(T, V | { T length(V); V ?/?(V, T); }) 92 92 V normalize(V v) { 93 93 return v / length(v); … … 95 95 96 96 // Project vector u onto vector v 97 forall( otype T, otypeV | dottable(V, T) | { V normalize(V); V ?*?(V, T); })97 forall(T, V | dottable(V, T) | { V normalize(V); V ?*?(V, T); }) 98 98 V project(V u, V v) { 99 99 V v_norm = normalize(v); … … 102 102 103 103 // Reflect incident vector v with respect to surface with normal n 104 forall( otype T | fromint(T), otypeV | { V project(V, V); V ?*?(T, V); V ?-?(V,V); })104 forall(T | fromint(T), V | { V project(V, V); V ?*?(T, V); V ?-?(V,V); }) 105 105 V reflect(V v, V n) { 106 106 return v - (T){2} * project(v, n); … … 111 111 // entering material (i.e., from air to water, eta = 1/1.33) 112 112 // v and n must already be normalized 113 forall( otypeT | fromint(T) | subtract(T) | multiply(T) | add(T) | lessthan(T) | sqrt(T),114 otypeV | dottable(V, T) | { V ?*?(T, V); V ?-?(V,V); void ?{}(V&, zero_t); })113 forall(T | fromint(T) | subtract(T) | multiply(T) | add(T) | lessthan(T) | sqrt(T), 114 V | dottable(V, T) | { V ?*?(T, V); V ?-?(V,V); void ?{}(V&, zero_t); }) 115 115 V refract(V v, V n, T eta) { 116 116 T dotValue = dot(n, v); … … 128 128 // i is the incident vector 129 129 // ng is the geometric normal of the surface 130 forall( otype T | lessthan(T) | zeroinit(T), otypeV | dottable(V, T) | negate(V))130 forall(T | lessthan(T) | zeroinit(T), V | dottable(V, T) | negate(V)) 131 131 V faceforward(V n, V i, V ng) { 132 132 return dot(ng, i) < (T){0} ? n : -n; -
libcfa/src/vec/vec2.hfa
r92bfda0 rdafbde8 19 19 #include "vec.hfa" 20 20 21 forall ( otypeT) {21 forall (T) { 22 22 struct vec2 { 23 23 T x, y; … … 25 25 } 26 26 27 forall ( otypeT) {27 forall (T) { 28 28 static inline { 29 29 … … 279 279 } 280 280 281 forall( dtype ostype, otypeT | writeable(T, ostype)) {281 forall(ostype &, T | writeable(T, ostype)) { 282 282 ostype & ?|?(ostype & os, vec2(T) v) with (v) { 283 283 return os | '<' | x | ',' | y | '>'; -
libcfa/src/vec/vec3.hfa
r92bfda0 rdafbde8 19 19 #include "vec.hfa" 20 20 21 forall ( otypeT) {21 forall (T) { 22 22 struct vec3 { 23 23 T x, y, z; … … 25 25 } 26 26 27 forall ( otypeT) {27 forall (T) { 28 28 static inline { 29 29 … … 288 288 } 289 289 290 forall( dtype ostype, otypeT | writeable(T, ostype)) {290 forall(ostype &, T | writeable(T, ostype)) { 291 291 ostype & ?|?(ostype & os, vec3(T) v) with (v) { 292 292 return os | '<' | x | ',' | y | ',' | z | '>'; -
libcfa/src/vec/vec4.hfa
r92bfda0 rdafbde8 19 19 #include "vec.hfa" 20 20 21 forall ( otypeT) {21 forall (T) { 22 22 struct vec4 { 23 23 T x, y, z, w; … … 25 25 } 26 26 27 forall ( otypeT) {27 forall (T) { 28 28 static inline { 29 29 … … 283 283 } 284 284 285 forall( dtype ostype, otypeT | writeable(T, ostype)) {285 forall(ostype &, T | writeable(T, ostype)) { 286 286 ostype & ?|?(ostype & os, vec4(T) v) with (v) { 287 287 return os | '<' | x | ',' | y | ',' | z | ',' | w | '>'; -
src/Parser/parser.yy
r92bfda0 rdafbde8 2441 2441 type_parameter: // CFA 2442 2442 type_class identifier_or_type_name 2443 { typedefTable.addToScope( *$2, TYPEDEFname, "9" ); } 2443 { typedefTable.addToScope( *$2, TYPEDEFname, "9" ); 2444 if ( $1 == TypeDecl::Otype ) { SemanticError( yylloc, "otype keyword is deprecated" ); } 2445 if ( $1 == TypeDecl::Dtype ) { SemanticError( yylloc, "dtype keyword is deprecated" ); } 2446 if ( $1 == TypeDecl::Ttype ) { SemanticError( yylloc, "ttype keyword is deprecated" ); } 2447 } 2444 2448 type_initializer_opt assertion_list_opt 2445 2449 { $$ = DeclarationNode::newTypeParam( $1, $2 )->addTypeInitializer( $4 )->addAssertions( $5 ); } -
src/ResolvExpr/PolyCost.cc
r92bfda0 rdafbde8 35 35 PassVisitor<PolyCost> coster( env, indexer ); 36 36 type->accept( coster ); 37 return coster.pass.result;37 return (coster.pass.result > 0) ? 1 : 0; 38 38 } 39 39 … … 87 87 ast::Pass<PolyCost_new> costing( symtab, env ); 88 88 type->accept( costing ); 89 return costing.core.result;89 return (costing.core.result > 0) ? 1 : 0; 90 90 } 91 91 -
src/ResolvExpr/SpecCost.cc
r92bfda0 rdafbde8 43 43 // mark specialization of base type 44 44 void postvisit(ReferenceType*) { if ( count >= 0 ) ++count; } 45 46 void postvisit(StructInstType*) { if ( count >= 0 ) ++count; } 47 void postvisit(UnionInstType*) { if ( count >= 0 ) ++count; } 45 48 46 49 private: … … 82 85 void previsit(StructInstType* sty) { 83 86 count = minover( sty->parameters ); 84 visit_children = false;85 87 } 86 88 … … 88 90 void previsit(UnionInstType* uty) { 89 91 count = minover( uty->parameters ); 90 visit_children = false;91 92 } 92 93 … … 174 175 void postvisit( const ast::ArrayType * ) { if ( count >= 0 ) ++count; } 175 176 void postvisit( const ast::ReferenceType * ) { if ( count >= 0 ) ++count; } 177 178 void postvisit( const ast::StructInstType * ) { if ( count >= 0 ) ++count; } 179 void postvisit( const ast::UnionInstType * ) { if ( count >= 0 ) ++count; } 176 180 177 181 // Use the minimal specialization value over returns and params. … … 189 193 void previsit( const ast::StructInstType * sty ) { 190 194 count = minimumPresent( sty->params, expr_result ); 191 visit_children = false;192 195 } 193 196 … … 195 198 void previsit( const ast::UnionInstType * uty ) { 196 199 count = minimumPresent( uty->params, expr_result ); 197 visit_children = false;198 200 } 199 201 -
tests/avltree/avl-private.cfa
r92bfda0 rdafbde8 11 11 // an AVL tree's height is easy to compute 12 12 // just follow path with the larger balance 13 forall( otype K | Comparable(K), otypeV)13 forall(K | Comparable(K), V) 14 14 int height(tree(K, V) * t){ 15 15 int helper(tree(K, V) * t, int ht){ … … 27 27 } 28 28 29 forall( otype K | Comparable(K), otypeV)29 forall(K | Comparable(K), V) 30 30 int calcBalance(tree(K, V) * t){ 31 31 int l = height(t->left); … … 36 36 37 37 // re-establish the link between parent and child 38 forall( otype K | Comparable(K), otypeV)38 forall(K | Comparable(K), V) 39 39 void relinkToParent(tree(K, V) * t){ 40 40 tree(K, V) * parent = t->parent; // FIX ME!! … … 49 49 50 50 // rotate left from t 51 forall( otype K | Comparable(K), otypeV)51 forall(K | Comparable(K), V) 52 52 tree(K, V) * rotateLeft(tree(K, V) * t){ 53 53 tree(K, V) * newRoot = t->right; … … 68 68 69 69 // rotate right from t 70 forall( otype K | Comparable(K), otypeV)70 forall(K | Comparable(K), V) 71 71 tree(K, V) * rotateRight(tree(K, V) * t){ 72 72 tree(K, V) * newRoot = t->left; … … 87 87 88 88 // balances a node that has balance factor -2 or 2 89 forall( otype K | Comparable(K), otypeV)89 forall(K | Comparable(K), V) 90 90 tree(K, V) * fix(tree(K, V) * t){ 91 91 // ensure that t's balance factor is one of … … 113 113 114 114 // attempt to fix the tree, if necessary 115 forall( otype K | Comparable(K), otypeV)115 forall(K | Comparable(K), V) 116 116 tree(K, V) * tryFix(tree(K, V) * t){ 117 117 int b = calcBalance(t); … … 126 126 127 127 // sets parent field of c to be p 128 forall( otype K | Comparable(K), otypeV)128 forall(K | Comparable(K), V) 129 129 void setParent(tree(K, V) * c, tree(K, V) * p){ 130 130 if (! empty(c)){ -
tests/avltree/avl-private.h
r92bfda0 rdafbde8 5 5 6 6 // attempt to fix the tree, if necessary 7 forall( otype K | Comparable(K), otypeV)7 forall(K | Comparable(K), V) 8 8 tree(K, V) * tryFix(tree(K, V) * t); 9 9 10 10 // sets parent field of c to be p 11 forall( otype K | Comparable(K), otypeV)11 forall(K | Comparable(K), V) 12 12 void setParent(tree(K, V) * c, tree(K, V) * p); 13 13 14 forall( otype K | Comparable(K), otypeV)14 forall(K | Comparable(K), V) 15 15 int height(tree(K, V) * t); -
tests/avltree/avl.h
r92bfda0 rdafbde8 9 9 // #include <lib.h> 10 10 11 trait Comparable( otypeT) {11 trait Comparable(T) { 12 12 int ?<?(T, T); 13 13 }; 14 14 15 forall( otypeT | Comparable(T))15 forall(T | Comparable(T)) 16 16 int ?==?(T t1, T t2); 17 17 18 forall( otypeT | Comparable(T))18 forall(T | Comparable(T)) 19 19 int ?>?(T t1, T t2); 20 20 … … 41 41 42 42 // temporary: need forward decl to get around typedef problem 43 forall( otype K | Comparable(K), otypeV)43 forall(K | Comparable(K), V) 44 44 struct tree; 45 45 46 forall( otype K | Comparable(K), otypeV)46 forall(K | Comparable(K), V) 47 47 struct tree { 48 48 K key; … … 54 54 }; 55 55 56 forall( otype K | Comparable(K), otypeV)56 forall(K | Comparable(K), V) 57 57 void ?{}(tree(K, V) &t, K key, V value); 58 58 59 forall( otype K, otypeV)59 forall(K | Comparable(K), V) 60 60 void ^?{}(tree(K, V) & t); 61 61 62 forall( otype K | Comparable(K), otypeV)62 forall(K | Comparable(K), V) 63 63 tree(K, V) * create(K key, V value); 64 64 65 forall( otype K | Comparable(K), otypeV)65 forall(K | Comparable(K), V) 66 66 V * find(tree(K, V) * t, K key); 67 67 68 forall( otype K | Comparable(K), otypeV)68 forall(K | Comparable(K), V) 69 69 int empty(tree(K, V) * t); 70 70 71 71 // returns the root of the tree 72 forall( otype K | Comparable(K), otypeV)72 forall(K | Comparable(K), V) 73 73 int insert(tree(K, V) ** t, K key, V value); 74 74 75 forall( otype K | Comparable(K), otypeV)75 forall(K | Comparable(K), V) 76 76 int remove(tree(K, V) ** t, K key); 77 77 78 forall( otype K | Comparable(K), otypeV)78 forall(K | Comparable(K), V) 79 79 void copy(tree(K, V) * src, tree(K, V) ** ret); 80 80 81 forall( otype K | Comparable(K), otypeV)81 forall(K | Comparable(K), V) 82 82 void for_each(tree(K, V) * t, void (*func)(V)); 83 83 -
tests/avltree/avl0.cfa
r92bfda0 rdafbde8 1 1 #include "avl.h" 2 2 3 forall( otypeT | Comparable(T))3 forall(T | Comparable(T)) 4 4 int ?==?(T t1, T t2) { 5 5 return !(t1 < t2) && !(t2 < t1); 6 6 } 7 7 8 forall( otypeT | Comparable(T))8 forall(T | Comparable(T)) 9 9 int ?>?(T t1, T t2) { 10 10 return t2 < t1; -
tests/avltree/avl1.cfa
r92bfda0 rdafbde8 3 3 #include <stdlib.hfa> 4 4 5 forall( otype K | Comparable(K), otypeV)5 forall(K | Comparable(K), V) 6 6 void ?{}(tree(K, V) &t, K key, V value){ 7 7 (t.key) { key }; … … 13 13 } 14 14 15 forall( otype K, otypeV)15 forall(K| Comparable(K), V) 16 16 void ^?{}(tree(K, V) & t){ 17 17 delete(t.left); … … 21 21 } 22 22 23 forall( otype K | Comparable(K), otypeV)23 forall(K | Comparable(K), V) 24 24 tree(K, V) * create(K key, V value) { 25 25 // infinite loop trying to resolve ... t = malloc(); -
tests/avltree/avl2.cfa
r92bfda0 rdafbde8 2 2 #include "avl-private.h" 3 3 4 forall( otype K | Comparable(K), otypeV)4 forall(K | Comparable(K), V) 5 5 V * find(tree(K, V) * t, K key){ 6 6 if (empty(t)){ … … 18 18 } 19 19 20 forall( otype K | Comparable(K), otypeV)20 forall(K | Comparable(K), V) 21 21 int empty(tree(K, V) * t){ 22 22 return t == NULL; … … 24 24 25 25 // returns the root of the tree 26 forall( otype K | Comparable(K), otypeV)26 forall(K | Comparable(K), V) 27 27 int insert(tree(K, V) ** t, K key, V value) { 28 28 // handles a non-empty tree -
tests/avltree/avl3.cfa
r92bfda0 rdafbde8 4 4 5 5 // swaps the data within two tree nodes 6 forall( otype K | Comparable(K), otypeV)6 forall(K | Comparable(K), V) 7 7 void node_swap(tree(K, V) * t, tree(K, V) * t2){ 8 8 swap( t->key, t2->key); … … 11 11 12 12 // go left as deep as possible from within the right subtree 13 forall( otype K | Comparable(K), otypeV)13 forall(K | Comparable(K), V) 14 14 tree(K, V) * find_successor(tree(K, V) * t){ 15 15 tree(K, V) * find_successor_helper(tree(K, V) * t){ … … 25 25 26 26 // cleanup - don't want to deep delete, so set children to NULL first. 27 forall( otype K | Comparable(K), otypeV)27 forall(K | Comparable(K), V) 28 28 void deleteSingleNode(tree(K, V) * t) { 29 29 t->left = NULL; … … 33 33 34 34 // does the actual remove operation once we've found the node in question 35 forall( otype K | Comparable(K), otypeV)35 forall(K | Comparable(K), V) 36 36 tree(K, V) * remove_node(tree(K, V) * t){ 37 37 // is the node a leaf? … … 85 85 86 86 // finds the node that needs to be removed 87 forall( otype K | Comparable(K), otypeV)87 forall(K | Comparable(K), V) 88 88 tree(K, V) * remove_helper(tree(K, V) * t, K key, int * worked){ 89 89 if (empty(t)){ … … 106 106 } 107 107 108 forall( otype K | Comparable(K), otypeV)108 forall(K | Comparable(K), V) 109 109 int remove(tree(K, V) ** t, K key){ 110 110 int worked = 0; -
tests/avltree/avl4.cfa
r92bfda0 rdafbde8 4 4 // Perform a shallow copy of src, return the 5 5 // new tree in ret 6 forall( otype K | Comparable(K), otypeV)6 forall(K | Comparable(K), V) 7 7 int copy(tree(K, V) * src, tree(K, V) ** ret){ 8 8 tree(K, V) * helper(tree(K, V) * t, int * worked){ … … 35 35 36 36 // Apply func to every value element in t, using an in order traversal 37 forall( otype K | Comparable(K), otypeV)37 forall(K | Comparable(K), V) 38 38 void for_each(tree(K, V) * t, int (*func)(V)) { 39 39 if (t == NULL) { -
tests/bugs/10.cfa
r92bfda0 rdafbde8 2 2 // https://cforall.uwaterloo.ca/trac/ticket/10 3 3 4 forall( otypeT)4 forall(T) 5 5 struct result { 6 6 union { -
tests/bugs/104.cfa
r92bfda0 rdafbde8 4 4 [ float, float ] modf_( float x ); 5 5 6 forall( otypeT | { [T, T] modf_(T); })6 forall(T | { [T, T] modf_(T); }) 7 7 void modf(T); 8 8 -
tests/bugs/194.cfa
r92bfda0 rdafbde8 2 2 // https://cforall.uwaterloo.ca/trac/ticket/194 3 3 4 forall( dtype T| sized(T) ) T * foo( void ) {4 forall( T & | sized(T) ) T * foo( void ) { 5 5 printf( "foo1\n" ); 6 6 return (T *)0; 7 7 } 8 forall( dtype T| sized(T) ) T & foo( void ) {8 forall( T & | sized(T) ) T & foo( void ) { 9 9 printf( "foo2\n" ); 10 10 return (T &)*(T *)0; -
tests/bugs/196.cfa
r92bfda0 rdafbde8 2 2 // https://cforall.uwaterloo.ca/trac/ticket/196 3 3 4 forall( dtype T)4 forall(T &) 5 5 struct link; 6 6 7 forall( dtype T)7 forall(T &) 8 8 struct link { 9 9 link(T) * next; … … 12 12 // ----- 13 13 14 forall( dtype T)14 forall(T &) 15 15 struct foo; 16 16 17 forall( dtype U)17 forall(U &) 18 18 struct bar { 19 19 foo(U) * data; 20 20 }; 21 21 22 forall( dtype T)22 forall(T &) 23 23 struct foo {}; 24 24 -
tests/bugs/203-2.cfa
r92bfda0 rdafbde8 1 1 // Trac ticket: https://cforall.uwaterloo.ca/trac/ticket/203 2 2 3 forall( dtype A)3 forall(A &) 4 4 struct empty { 5 5 // Nothing. 6 6 }; 7 7 8 forall( dtype C)8 forall(C &) 9 9 struct wrap_e { 10 10 empty(C) field; -
tests/bugs/203-7.cfa
r92bfda0 rdafbde8 1 1 // Trac ticket: https://cforall.uwaterloo.ca/trac/ticket/203 2 2 3 forall( dtype A)3 forall(A &) 4 4 struct empty { 5 5 // Nothing. 6 6 }; 7 7 8 forall( dtype C)8 forall(C &) 9 9 struct wrap_e { 10 10 empty(C) field; -
tests/bugs/203-9.cfa
r92bfda0 rdafbde8 1 1 // Trac ticket: https://cforall.uwaterloo.ca/trac/ticket/203 2 2 3 forall( dtype A)3 forall(A &) 4 4 struct empty { 5 5 // Nothing. 6 6 }; 7 7 8 forall( dtype C)8 forall(C &) 9 9 struct wrap_e { 10 10 empty(C) field; -
tests/bugs/7.cfa
r92bfda0 rdafbde8 8 8 9 9 // (Bug 1 unresolved as of this test.) 10 forall( otypeT)10 forall(T) 11 11 struct stack_node; 12 12 13 forall( otypeT)13 forall(T) 14 14 struct stack_node { 15 15 stack_node(T) * next; … … 17 17 }; 18 18 19 forall( otypeT)19 forall(T) 20 20 struct stack { 21 21 stack_node(T) * head; 22 22 }; 23 23 24 trait stack_errors( otypeT) {24 trait stack_errors(T) { 25 25 T emptyStackHandler (stack(T) * this); 26 26 }; 27 27 28 forall( otypeT | stack_errors(T))28 forall(T | stack_errors(T)) 29 29 T pop (stack(T) * this) { 30 30 return (T){}; -
tests/castError.cfa
r92bfda0 rdafbde8 14 14 // 15 15 16 forall( otypeT) struct S { T p; };16 forall(T) struct S { T p; }; 17 17 int f; 18 18 S(int) sint; -
tests/concurrent/examples/boundedBufferEXT.cfa
r92bfda0 rdafbde8 24 24 enum { BufferSize = 50 }; 25 25 26 forall( otypeT ) {26 forall( T ) { 27 27 monitor Buffer { 28 28 int front, back, count; -
tests/concurrent/examples/boundedBufferINT.cfa
r92bfda0 rdafbde8 24 24 enum { BufferSize = 50 }; 25 25 26 forall( otypeT ) {26 forall( T ) { 27 27 monitor Buffer { 28 28 condition full, empty; -
tests/concurrent/examples/quickSort.generic.cfa
r92bfda0 rdafbde8 21 21 #include <string.h> // strcmp 22 22 23 forall( otypeT | { int ?<?( T, T ); } ) {23 forall( T | { int ?<?( T, T ); } ) { 24 24 thread Quicksort { 25 25 T * values; // communication variables -
tests/concurrent/multi-monitor.cfa
r92bfda0 rdafbde8 38 38 } 39 39 40 forall( dtype T| sized(T) | { void ^?{}(T & mutex); })40 forall(T & | sized(T) | { void ^?{}(T & mutex); }) 41 41 void delete_mutex(T * x) { 42 42 ^(*x){}; -
tests/errors/completeType.cfa
r92bfda0 rdafbde8 1 1 void foo(int *) {} 2 2 void bar(void *) {} 3 forall( otypeT) void baz(T *);4 forall( dtype T) void qux(T *);5 forall( dtype T| sized(T)) void quux(T *);3 forall(T) void baz(T *); 4 forall(T &) void qux(T *); 5 forall(T & | sized(T)) void quux(T *); 6 6 7 7 struct A; // incomplete … … 39 39 40 40 41 forall( otypeT)41 forall(T) 42 42 void baz(T * x) { 43 43 // okay … … 49 49 } 50 50 51 forall( dtype T)51 forall(T &) 52 52 void qux(T * y) { 53 53 // okay … … 61 61 } 62 62 63 forall( dtype T| sized(T))63 forall(T & | sized(T)) 64 64 void quux(T * z) { 65 65 // okay -
tests/exceptions/defaults.cfa
r92bfda0 rdafbde8 55 55 56 56 void unhandled_test(void) { 57 forall( dtype T, dtype V| is_exception(T, V))57 forall(T &, V & | is_exception(T, V)) 58 58 void defaultTerminationHandler(T &) { 59 59 throw (unhandled_exception){}; -
tests/exceptions/polymorphic.cfa
r92bfda0 rdafbde8 3 3 #include <exception.hfa> 4 4 5 FORALL_TRIVIAL_EXCEPTION(proxy, ( otypeT), (T));6 FORALL_TRIVIAL_INSTANCE(proxy, ( otypeU), (U))5 FORALL_TRIVIAL_EXCEPTION(proxy, (T), (T)); 6 FORALL_TRIVIAL_INSTANCE(proxy, (U), (U)) 7 7 8 8 const char * msg(proxy(int) * this) { return "proxy(int)"; } … … 33 33 } 34 34 35 FORALL_DATA_EXCEPTION(cell, ( otypeT), (T))(35 FORALL_DATA_EXCEPTION(cell, (T), (T))( 36 36 T data; 37 37 ); 38 38 39 FORALL_DATA_INSTANCE(cell, ( otypeT), (T))39 FORALL_DATA_INSTANCE(cell, (T), (T)) 40 40 41 41 const char * msg(cell(int) * this) { return "cell(int)"; } -
tests/exceptions/virtual-poly.cfa
r92bfda0 rdafbde8 16 16 }; 17 17 18 forall( otypeT)18 forall(T) 19 19 struct mono_child_vtable { 20 20 mono_base_vtable const * const parent; 21 21 }; 22 22 23 forall( otypeT)23 forall(T) 24 24 struct mono_child { 25 25 mono_child_vtable(T) const * virtual_table; … … 37 37 } 38 38 39 forall( otypeU)39 forall(U) 40 40 struct poly_base_vtable { 41 41 poly_base_vtable(U) const * const parent; 42 42 }; 43 43 44 forall( otypeU)44 forall(U) 45 45 struct poly_base { 46 46 poly_base_vtable(U) const * virtual_table; 47 47 }; 48 48 49 forall( otypeV)49 forall(V) 50 50 struct poly_child_vtable { 51 51 poly_base_vtable(V) const * const parent; 52 52 }; 53 53 54 forall( otypeV)54 forall(V) 55 55 struct poly_child { 56 56 poly_child_vtable(V) const * virtual_table; -
tests/forall.cfa
r92bfda0 rdafbde8 15 15 16 16 void g1() { 17 forall( otypeT ) T f( T ) {};17 forall( T ) T f( T ) {}; 18 18 void f( int ) {}; 19 19 void h( void (*p)(void) ) {}; … … 32 32 33 33 void g2() { 34 forall( otypeT ) void f( T, T ) {}35 forall( otype T, otypeU ) void f( T, U ) {}34 forall( T ) void f( T, T ) {} 35 forall( T, U ) void f( T, U ) {} 36 36 37 37 int x; … … 45 45 } 46 46 47 typedef forall ( otypeT ) int (* f)( int );48 49 forall( otypeT )47 typedef forall ( T ) int (* f)( int ); 48 49 forall( T ) 50 50 void swap( T left, T right ) { 51 51 T temp = left; … … 54 54 } 55 55 56 trait sumable( otypeT ) {56 trait sumable( T ) { 57 57 void ?{}( T &, zero_t ); // 0 literal constructor 58 58 T ?+?( T, T ); // assortment of additions … … 62 62 }; // sumable 63 63 64 forall( otypeT | sumable( T ) ) // use trait64 forall( T | sumable( T ) ) // use trait 65 65 T sum( size_t size, T a[] ) { 66 66 T total = 0; // initialize by 0 constructor … … 70 70 } // sum 71 71 72 forall( otypeT | { T ?+?( T, T ); T ?++( T & ); [T] ?+=?( T &,T ); } )72 forall( T | { T ?+?( T, T ); T ?++( T & ); [T] ?+=?( T &,T ); } ) 73 73 T twice( T t ) { 74 74 return t + t; 75 75 } 76 76 77 forall( otypeT | { int ?<?(T, T); } )77 forall( T | { int ?<?(T, T); } ) 78 78 T min( T t1, T t2 ) { 79 79 return t1 < t2 ? t1 : t2; … … 91 91 92 92 // Multiple forall 93 forall( otype T ) forall( otypeS ) struct { int i; };94 forall( otype T ) struct { int i; } forall( otypeS );95 struct { int i; } forall( otype T ) forall( otypeS );96 forall( otype W ) struct { int i; } forall( otype T ) forall( otypeS );93 forall( T ) forall( S ) struct { int i; }; 94 forall( T ) struct { int i; } forall( S ); 95 struct { int i; } forall( T ) forall( S ); 96 forall( W ) struct { int i; } forall( T ) forall( S ); 97 97 98 98 // Distribution 99 99 struct P { int i; }; 100 forall( otypeT ) struct Q { T i; };101 forall( otypeT ) struct { int i; };100 forall( T ) struct Q { T i; }; 101 forall( T ) struct { int i; }; 102 102 struct KK { int i; }; 103 103 inline static { 104 104 void RT1() {} 105 105 } 106 forall( otypeT ) {106 forall( T ) { 107 107 T RT2( T ) { 108 108 typedef int TD1; 109 109 struct S1 { T t; }; 110 110 } 111 forall( otypeX ) {111 forall( X ) { 112 112 typedef int TD2; 113 113 struct S2 {}; … … 117 117 } 118 118 extern "C" { 119 forall( otypeW ) {119 forall( W ) { 120 120 W RT3( W ) {} 121 121 struct S3 {}; … … 123 123 } 124 124 void RT4() { 125 forall( otypeW ) struct S4 {};125 forall( W ) struct S4 {}; 126 126 typedef int TD3; 127 127 } … … 147 147 148 148 static inline { 149 forall( otypeT ) {149 forall( T ) { 150 150 int RT6( T p ); 151 151 } 152 forall( otype T, otypeU ) {152 forall( T, U ) { 153 153 int RT7( T, U ); 154 154 } 155 155 } 156 static forall( otypeT ) {156 static forall( T ) { 157 157 int RT8( T ); 158 158 } 159 forall( otypeT ) inline static {159 forall( T ) inline static { 160 160 int RT9( T ) { T t; return 3; } 161 161 } 162 162 163 forall( otypeT | { T ?+?( T, T ); } ) {164 forall( otypeS | { T ?+?( T, S ); } ) {165 forall( otypeW ) T bar( T t, S s ) { return t + s; }166 forall( otypeW | { W ?+?( T, W ); } ) W baz( T t, S s, W w ) { return t + s + w; }163 forall( T | { T ?+?( T, T ); } ) { 164 forall( S | { T ?+?( T, S ); } ) { 165 forall( W ) T bar( T t, S s ) { return t + s; } 166 forall( W | { W ?+?( T, W ); } ) W baz( T t, S s, W w ) { return t + s + w; } 167 167 struct W { T t; } (int,int) ww; 168 168 struct P pp; … … 170 170 } 171 171 172 forall( otype T | { T ?+?( T, T ); } ) forall( otypeS | { T ?+?( T, S ); } )172 forall( T | { T ?+?( T, T ); } ) forall( S | { T ?+?( T, S ); } ) 173 173 struct XW { T t; }; 174 174 XW(int,int) xww; 175 175 176 forall( otypeT ) struct S { T t; } (int) x, y, z;177 forall( otypeT ) struct { T t; } (int) a, b, c;178 179 forall( otype T ) static forall( otypeS ) {180 forall( otypeX ) struct U {176 forall( T ) struct S { T t; } (int) x, y, z; 177 forall( T ) struct { T t; } (int) a, b, c; 178 179 forall( T ) static forall( S ) { 180 forall( X ) struct U { 181 181 T x; 182 182 }; 183 183 } 184 184 185 forall( otypeT ) {185 forall( T ) { 186 186 extern "C" { 187 187 struct SS { T t; }; -
tests/function-operator.cfa
r92bfda0 rdafbde8 22 22 23 23 // STL-like Algorithms 24 trait Assignable( dtype T, dtype U) { T ?=?(T &, U); };25 trait Copyable( dtype T) { void ?{}(T &, T); };26 trait Destructable( dtype T) { void ^?{}(T &); };24 trait Assignable(T &, U &) { T ?=?(T &, U); }; 25 trait Copyable(T &) { void ?{}(T &, T); }; 26 trait Destructable(T &) { void ^?{}(T &); }; 27 27 28 trait Iterator( dtype iter | sized(iter) | Copyable(iter) | Destructable(iter), otypeT) {28 trait Iterator(iter & | sized(iter) | Copyable(iter) | Destructable(iter), T) { 29 29 T & *?(iter); 30 30 iter ++?(iter &); … … 32 32 }; 33 33 34 forall( otype Tin, dtype Input | Iterator(Input, Tin), otype Tout, dtype Output| Iterator(Output, Tout) | Assignable(Tout, Tin))34 forall(Tin, Input & | Iterator(Input, Tin), Tout, Output & | Iterator(Output, Tout) | Assignable(Tout, Tin)) 35 35 Output copy(Input first, Input last, Output result) { 36 36 while (first != last) { … … 42 42 43 43 // test ?()(T *, ...) -- ?() with function call-by-pointer 44 forall( otype Tin, dtype Input | Iterator(Input, Tin), otype Tout, dtype Output | Iterator(Output, Tout), otype FuncRet, dtype Func| { FuncRet ?()(Func *, Tin); } | Assignable(Tout, FuncRet))44 forall(Tin, Input & | Iterator(Input, Tin), Tout, Output & | Iterator(Output, Tout), FuncRet, Func & | { FuncRet ?()(Func *, Tin); } | Assignable(Tout, FuncRet)) 45 45 Output transform (Input first, Input last, Output result, Func * op) { 46 46 while (first != last) { … … 52 52 53 53 // test ?()(T, ...) -- ?() with function call-by-value 54 forall( dtype Iter, otype T | Iterator(Iter, T), otypePred | { int ?()(Pred, T); })54 forall(Iter &, T | Iterator(Iter, T), Pred | { int ?()(Pred, T); }) 55 55 Iter find_if (Iter first, Iter last, Pred pred) { 56 56 while (first != last) { … … 62 62 63 63 // test ?()(T, ...) -- ?() with function call-by-reference 64 forall( otype Generator, otype GenRet | { GenRet ?()(Generator &); }, dtype Iter, otypeT | Iterator(Iter, T) | Assignable(T, GenRet))64 forall(Generator, GenRet | { GenRet ?()(Generator &); }, Iter &, T | Iterator(Iter, T) | Assignable(T, GenRet)) 65 65 void generate(Iter first, Iter last, Generator & gen) { 66 66 int i = 0; … … 108 108 } 109 109 110 forall( otypeT | { int ?==?(T, T); })110 forall(T | { int ?==?(T, T); }) 111 111 struct Equals { 112 112 T val; 113 113 }; 114 114 115 forall( otypeT | { int ?==?(T, T); })115 forall(T | { int ?==?(T, T); }) 116 116 int ?()(Equals(T) eq, T x) { 117 117 return eq.val == x; 118 118 } 119 119 120 forall( otypeT | { T ?*?(T, T); })120 forall(T | { T ?*?(T, T); }) 121 121 struct Multiply { 122 122 T val; 123 123 }; 124 124 125 forall( otypeT | { T ?*?(T, T); })125 forall(T | { T ?*?(T, T); }) 126 126 T ?()(Multiply(T) * mult, T x) { 127 127 return mult->val * x; … … 130 130 // TODO: generalize to ttype return; doesn't work yet 131 131 // like std::function 132 forall( otype Return, ttype Args)132 forall(Return, Args...) 133 133 struct function { 134 134 Return (*f)(Args); -
tests/genericUnion.cfa
r92bfda0 rdafbde8 16 16 #include <limits.hfa> 17 17 18 forall( otypeT)18 forall(T) 19 19 union ByteView { 20 20 T val; … … 22 22 }; 23 23 24 forall( otypeT)24 forall(T) 25 25 void print(ByteView(T) x) { 26 26 for (int i = 0; i < sizeof(int); i++) { // want to change to sizeof(T) … … 29 29 } 30 30 31 forall( otypeT)31 forall(T) 32 32 void f(ByteView(T) x, T val) { 33 33 print(x); -
tests/global-monomorph.cfa
r92bfda0 rdafbde8 1 1 // Create monomorphic instances of polymorphic types at global scope. 2 2 3 forall( dtype T)3 forall(T &) 4 4 void poly0(T &) {} 5 5 6 forall( dtype T| sized(T))6 forall(T & | sized(T)) 7 7 void poly1(T &) {} 8 8 9 forall( otypeT)9 forall(T) 10 10 void poly2(T &) {} 11 11 -
tests/identity.cfa
r92bfda0 rdafbde8 16 16 #include <fstream.hfa> 17 17 18 forall( otypeT )18 forall( T ) 19 19 T identity( T t ) { 20 20 return t; -
tests/init1.cfa
r92bfda0 rdafbde8 120 120 } 121 121 122 forall ( dtype T, dtype S)122 forall (T &, S &) 123 123 T & anycvt( S & s ) { 124 124 return s; // mismatched referenced type 125 125 } 126 126 127 forall ( dtype T, dtype S)127 forall (T &, S &) 128 128 T * anycvt( S * s ) { 129 129 return s; // mismatched referenced type -
tests/nested-types.cfa
r92bfda0 rdafbde8 16 16 typedef int N; 17 17 struct A { 18 forall( otypeT)18 forall(T) 19 19 struct N { 20 20 T x; -
tests/poly-d-cycle.cfa
r92bfda0 rdafbde8 1 1 // Check that a cycle of polymorphic dtype structures can be instancated. 2 2 3 forall( dtype T)3 forall(T &) 4 4 struct func_table; 5 5 6 forall( dtype U)6 forall(U &) 7 7 struct object { 8 8 func_table(U) * virtual_table; 9 9 }; 10 10 11 forall( dtype T)11 forall(T &) 12 12 struct func_table { 13 13 void (*object_func)(object(T) *); -
tests/poly-o-cycle.cfa
r92bfda0 rdafbde8 1 1 // Check that a cycle of polymorphic otype structures can be instancated. 2 2 3 forall( otypeT)3 forall(T) 4 4 struct func_table; 5 5 6 forall( otypeU)6 forall(U) 7 7 struct object { 8 8 func_table(U) * virtual_table; 9 9 }; 10 10 11 forall( otypeT)11 forall(T) 12 12 struct func_table { 13 13 void (*object_func)(object(T) *); -
tests/polymorphism.cfa
r92bfda0 rdafbde8 18 18 #include <fstream.hfa> 19 19 20 forall( otypeT)20 forall(T) 21 21 T f(T x, T y) { 22 22 x = y; … … 24 24 } 25 25 26 forall( otypeT) T ident(T x) {26 forall(T) T ident(T x) { 27 27 return x; 28 28 } 29 29 30 forall( otype T, otypeU )30 forall( T, U ) 31 31 size_t struct_size( T i, U j ) { 32 32 struct S { T i; U j; }; … … 34 34 } 35 35 36 forall( otype T, otypeU )36 forall( T, U ) 37 37 size_t union_size( T i, U j ) { 38 38 union B { T i; U j; }; … … 41 41 42 42 // perform some simple operations on aggregates of T and U 43 forall( otype T | { void print(T); int ?==?(T, T); }, otypeU | { void print(U); U ?=?(U&, zero_t); } )43 forall( T | { void print(T); int ?==?(T, T); }, U | { void print(U); U ?=?(U&, zero_t); } ) 44 44 U foo(T i, U j) { 45 45 struct S { T i; U j; }; -
tests/raii/ctor-autogen.cfa
r92bfda0 rdafbde8 33 33 34 34 // dtype-static generic type is otype 35 forall( dtype T)35 forall(T &) 36 36 struct DtypeStaticStruct { 37 37 T * data; … … 39 39 }; 40 40 41 forall( dtype T)41 forall(T &) 42 42 union DtypeStaticUnion { 43 43 T * data; … … 46 46 47 47 // dynamic generic type is otype 48 forall( otypeT)48 forall(T) 49 49 struct DynamicStruct { 50 50 T x; 51 51 }; 52 52 53 forall( otypeT)53 forall(T) 54 54 union DynamicUnion { 55 55 T x; … … 80 80 81 81 82 forall( otypeT)82 forall(T) 83 83 T identity(T x) { return x; } 84 84 -
tests/simpleGenericTriple.cfa
r92bfda0 rdafbde8 14 14 // 15 15 16 forall( otypeT)16 forall(T) 17 17 struct T3 { 18 18 T f0, f1, f2; 19 19 }; 20 20 21 forall( otypeT | { T ?+?(T, T); })21 forall(T | { T ?+?(T, T); }) 22 22 T3(T) ?+?(T3(T) x, T3(T) y) { 23 23 T3(T) z = { x.f0+y.f0, x.f1+y.f1, x.f2+y.f2 }; -
tests/sum.cfa
r92bfda0 rdafbde8 18 18 #include <stdlib.hfa> 19 19 20 trait sumable( otypeT ) {20 trait sumable( T ) { 21 21 void ?{}( T &, zero_t ); // 0 literal constructor 22 22 T ?+?( T, T ); // assortment of additions … … 26 26 }; // sumable 27 27 28 forall( otypeT | sumable( T ) ) // use trait28 forall( T | sumable( T ) ) // use trait 29 29 T sum( size_t size, T a[] ) { 30 30 T total = 0; // initialize by 0 constructor … … 107 107 | sum( size, (S *)a ) | ", check" | (S)s; 108 108 109 forall( otypeImpl | sumable( Impl ) )109 forall( Impl | sumable( Impl ) ) 110 110 struct GS { 111 111 Impl * x, * y; … … 194 194 sum( size, (S *)a ).[i, j], s.[i, j] ); 195 195 196 forall( otypeImpl | sumable( Impl ) )196 forall( Impl | sumable( Impl ) ) 197 197 struct GS { 198 198 Impl * x, * y; -
tests/tuple/tuplePolymorphism.cfa
r92bfda0 rdafbde8 29 29 // ensure that f is a viable candidate for g, even though its parameter structure does not exactly match 30 30 [A] f([A, B] x, B y) { printf("%g %c %g %lld %c %lld %lld %c %lld\n", x.0.[x,y,z], x.1.[x,y,z], y.[x,y,z]); return x.0; } 31 forall( otype T, otypeU | { T f(T, U, U); })31 forall(T, U | { T f(T, U, U); }) 32 32 void g(T x, U y) { f(x, y, y); } 33 33 34 34 // add two triples 35 forall( otypeT | { T ?+?(T, T); })35 forall(T | { T ?+?(T, T); }) 36 36 [T, T, T] ?+?([T, T, T] x, [T, T, T] y) { 37 37 return [x.0+y.0, x.1+y.1, x.2+y.2]; … … 64 64 } 65 65 66 forall( otypeT)66 forall(T) 67 67 [T, T] foo([T, T] y) { 68 68 [T, T] x; -
tests/tuple/tupleVariadic.cfa
r92bfda0 rdafbde8 19 19 printf("called func(void)\n"); 20 20 } 21 forall( otype T, ttype Params| { void process(T); void func(Params); })21 forall(T, Params... | { void process(T); void func(Params); }) 22 22 void func(T arg1, Params p) { 23 23 process(arg1); … … 92 92 } 93 93 94 forall( otypeT)94 forall(T) 95 95 T * copy(T x) { 96 96 // test calling new inside a polymorphic function … … 98 98 } 99 99 100 forall( ttype T| { void foo(T); }) void bar(T x) {}100 forall(T... | { void foo(T); }) void bar(T x) {} 101 101 void foo(int) {} 102 102 -
tests/zombies/ArrayN.c
r92bfda0 rdafbde8 6 6 // } 7 7 8 forall( otypeindex_t)8 forall(index_t) 9 9 index_t offset_to_index(unsigned offset, index_t size) { 10 10 return [offset / size.0, offset % size.1]; -
tests/zombies/Members.c
r92bfda0 rdafbde8 2 2 int ?=?( int*, int ); 3 3 float ?=?( float*, float ); 4 forall( dtype DT) DT * ?=?( DT**, DT* );5 forall( otypeT) lvalue T *?( T* );4 forall( DT & ) DT * ?=?( DT**, DT* ); 5 forall(T) lvalue T *?( T* ); 6 6 char *__builtin_memcpy(); 7 7 -
tests/zombies/Rank2.c
r92bfda0 rdafbde8 1 1 int ?=?( int &, int ); 2 forall( dtype DT) DT * ?=?( DT *&, DT * );2 forall(DT &) DT * ?=?( DT *&, DT * ); 3 3 4 4 void a() { 5 forall( otypeT ) void f( T );6 void g( forall( otypeU ) void p( U ) );5 forall( T ) void f( T ); 6 void g( forall( U ) void p( U ) ); 7 7 g( f ); 8 8 } … … 10 10 void g() { 11 11 void h( int *null ); 12 forall( otypeT ) T id( T );12 forall( T ) T id( T ); 13 13 // forall( dtype T ) T *0; 14 14 // int 0; -
tests/zombies/abstype.c
r92bfda0 rdafbde8 21 21 } 22 22 23 forall( otypeT ) T *?( T * );23 forall( T ) T *?( T * ); 24 24 int ?++( int * ); 25 25 int ?=?( int *, int ); 26 forall( dtype DT) DT * ?=?( DT **, DT * );26 forall( DT & ) DT * ?=?( DT **, DT * ); 27 27 28 28 otype U = int *; -
tests/zombies/context.cfa
r92bfda0 rdafbde8 1 1 // trait declaration 2 2 3 trait has_q( otypeT ) {3 trait has_q( T ) { 4 4 T q( T ); 5 5 }; 6 6 7 forall( otypez | has_q( z ) ) void f() {8 trait has_r( otype T, otypeU ) {7 forall( z | has_q( z ) ) void f() { 8 trait has_r( T, U ) { 9 9 T r( T, T (T,U) ); 10 10 }; -
tests/zombies/gc_no_raii/bug-repro/blockers/explicit_cast.c
r92bfda0 rdafbde8 9 9 }; 10 10 11 forall( otypeT)11 forall(T) 12 12 struct gcpointer 13 13 { … … 15 15 }; 16 16 17 forall( otypeT)17 forall(T) 18 18 static inline gcpointer(T) gcmalloc() 19 19 { -
tests/zombies/gc_no_raii/bug-repro/blockers/recursive_realloc.c
r92bfda0 rdafbde8 3 3 #include <stdlib.hfa> 4 4 5 trait allocator_c( otype T, otypeallocator_t)5 trait allocator_c(T, allocator_t) 6 6 { 7 7 void realloc(allocator_t* const, size_t); 8 8 }; 9 9 10 forall( otypeT)10 forall(T) 11 11 struct heap_allocator 12 12 { … … 15 15 }; 16 16 17 forall( otypeT)17 forall(T) 18 18 inline void realloc(heap_allocator(T) *const this, size_t size) 19 19 { -
tests/zombies/gc_no_raii/bug-repro/deref.c
r92bfda0 rdafbde8 1 forall( otypeT)1 forall(T) 2 2 struct wrap 3 3 { … … 5 5 }; 6 6 7 forall( otypeT)7 forall(T) 8 8 T *? (wrap(T) rhs) 9 9 { -
tests/zombies/gc_no_raii/bug-repro/field.c
r92bfda0 rdafbde8 8 8 //------------------------------------------------------------------------------ 9 9 //Declaration 10 trait allocator_c( otype T, otypeallocator_t)10 trait allocator_c(T, allocator_t) 11 11 { 12 12 void ctor(allocator_t* const); … … 16 16 }; 17 17 18 forall( otype T, otypeallocator_t | allocator_c(T, allocator_t))18 forall(T, allocator_t | allocator_c(T, allocator_t)) 19 19 struct vector 20 20 { -
tests/zombies/gc_no_raii/bug-repro/malloc.c
r92bfda0 rdafbde8 1 forall( otypeT)1 forall(T) 2 2 struct wrapper 3 3 { … … 5 5 }; 6 6 7 forall( otypeT)7 forall(T) 8 8 void ctor(wrapper(T)* this) 9 9 { … … 11 11 } 12 12 13 forall( otypeT)13 forall(T) 14 14 wrapper(T) gcmalloc() 15 15 { … … 19 19 } 20 20 21 forall( otypeT)21 forall(T) 22 22 wrapper(T)* ?=? (wrapper(T)* lhs, wrapper(T)* rhs) 23 23 { -
tests/zombies/gc_no_raii/bug-repro/oddtype.c
r92bfda0 rdafbde8 1 forall( dtype T)1 forall(T &) 2 2 struct wrap { 3 3 int i; 4 4 }; 5 5 6 forall( otypeT) void ?{}(wrap(T)* this) {}7 forall( otypeT) void ?=?(wrap(T)* this) {}8 forall( otypeT) void ^?{}(wrap(T)* this) {}6 forall(T) void ?{}(wrap(T)* this) {} 7 forall(T) void ?=?(wrap(T)* this) {} 8 forall(T) void ^?{}(wrap(T)* this) {} 9 9 10 10 struct List_t { -
tests/zombies/gc_no_raii/bug-repro/push_back.h
r92bfda0 rdafbde8 1 1 //------------------------------------------------------------------------------ 2 2 //Declaration 3 trait allocator_c( otype T, otypeallocator_t) {3 trait allocator_c(T, allocator_t) { 4 4 void ctor(allocator_t* const); 5 5 void dtor(allocator_t* const); … … 8 8 }; 9 9 10 forall( otype T, otypeallocator_t | allocator_c(T, allocator_t))10 forall(T, allocator_t | allocator_c(T, allocator_t)) 11 11 struct vector 12 12 { … … 17 17 //------------------------------------------------------------------------------ 18 18 //Initialization 19 forall( otype T, otypeallocator_t | allocator_c(T, allocator_t))19 forall(T, allocator_t | allocator_c(T, allocator_t)) 20 20 void vector_ctor(vector(T, allocator_t) *const this); 21 21 22 forall( otype T, otypeallocator_t | allocator_c(T, allocator_t))22 forall(T, allocator_t | allocator_c(T, allocator_t)) 23 23 void dtor(vector(T, allocator_t) *const this); 24 24 25 25 //------------------------------------------------------------------------------ 26 26 //Allocator 27 forall( otypeT)27 forall(T) 28 28 struct heap_allocator 29 29 { … … 32 32 }; 33 33 34 forall( otypeT)34 forall(T) 35 35 void ctor(heap_allocator(T) *const this); 36 36 37 forall( otypeT)37 forall(T) 38 38 void dtor(heap_allocator(T) *const this); 39 39 40 forall( otypeT)40 forall(T) 41 41 void realloc(heap_allocator(T) *const this, size_t size); 42 42 43 forall( otypeT)43 forall(T) 44 44 inline T* data(heap_allocator(T) *const this) 45 45 { … … 49 49 //------------------------------------------------------------------------------ 50 50 //Capacity 51 forall( otype T, otypeallocator_t | allocator_c(T, allocator_t))51 forall(T, allocator_t | allocator_c(T, allocator_t)) 52 52 inline bool empty(vector(T, allocator_t) *const this) 53 53 { … … 55 55 } 56 56 57 forall( otype T, otypeallocator_t | allocator_c(T, allocator_t))57 forall(T, allocator_t | allocator_c(T, allocator_t)) 58 58 inline bool size(vector(T, allocator_t) *const this) 59 59 { … … 61 61 } 62 62 63 forall( otype T, otypeallocator_t | allocator_c(T, allocator_t))63 forall(T, allocator_t | allocator_c(T, allocator_t)) 64 64 inline void reserve(vector(T, allocator_t) *const this, size_t size) 65 65 { … … 69 69 //------------------------------------------------------------------------------ 70 70 //Modifiers 71 forall( otype T, otypeallocator_t | allocator_c(T, allocator_t))71 forall(T, allocator_t | allocator_c(T, allocator_t)) 72 72 void push_back(vector(T, allocator_t) *const this, T value); -
tests/zombies/gc_no_raii/bug-repro/realloc.c
r92bfda0 rdafbde8 1 1 void* realloc(void*, unsigned long int); 2 2 3 forall( otypeT)3 forall(T) 4 4 struct wrap 5 5 { … … 7 7 }; 8 8 9 forall( otypeT)9 forall(T) 10 10 static inline void realloc(wrap(T) *const this, unsigned long int size) 11 11 { -
tests/zombies/gc_no_raii/bug-repro/return.c
r92bfda0 rdafbde8 1 forall( otypeT)1 forall(T) 2 2 struct wrapper 3 3 { … … 5 5 }; 6 6 7 forall( otypeT)7 forall(T) 8 8 wrapper(T) create() 9 9 { … … 12 12 } 13 13 14 forall( otypeT)14 forall(T) 15 15 wrapper(T)* ?=?(wrapper(T)* lhs, wrapper(T)* rhs) 16 16 { -
tests/zombies/gc_no_raii/bug-repro/return_template.c
r92bfda0 rdafbde8 1 forall( otypeT)1 forall(T) 2 2 struct wrap 3 3 { … … 5 5 }; 6 6 7 forall( otypeT) void ?{}(wrap(T)* this);8 forall( otypeT) void ?{}(wrap(T)* this, wrap(T)* rhs);9 forall( otypeT) void ^?{}(wrap(T)* this);10 forall( otypeT) void ?=?(wrap(T)* this, wrap(T)* rhs);7 forall(T) void ?{}(wrap(T)* this); 8 forall(T) void ?{}(wrap(T)* this, wrap(T)* rhs); 9 forall(T) void ^?{}(wrap(T)* this); 10 forall(T) void ?=?(wrap(T)* this, wrap(T)* rhs); 11 11 12 forall( otypeT)12 forall(T) 13 13 wrap(T) test() 14 14 { -
tests/zombies/gc_no_raii/bug-repro/slow_malloc.c
r92bfda0 rdafbde8 1 1 #include <stdlib.hfa> 2 2 3 forall( otypeT)3 forall(T) 4 4 struct heap_allocator 5 5 { -
tests/zombies/gc_no_raii/bug-repro/zero.c
r92bfda0 rdafbde8 1 forall( otypeT)1 forall(T) 2 2 struct wrap 3 3 { … … 5 5 }; 6 6 7 forall( otypeT)7 forall(T) 8 8 int ?==? (wrap(T) lhs, wrap(T) rhs) 9 9 { … … 14 14 struct wrap(int) 0; 15 15 /*/ 16 forall( otypeT)16 forall(T) 17 17 struct wrap(T) 0; 18 18 //*/ -
tests/zombies/gc_no_raii/src/gc.h
r92bfda0 rdafbde8 13 13 // } 14 14 15 forall( otypeT)15 forall(T) 16 16 static inline void gcmalloc(gcpointer(T)* ptr) 17 17 { -
tests/zombies/gc_no_raii/src/gcpointers.c
r92bfda0 rdafbde8 113 113 #endif 114 114 115 forall( otypeT) void ?{}(gcpointer(T)* this) {115 forall(T) void ?{}(gcpointer(T)* this) { 116 116 (&this->internal) {}; 117 117 } 118 118 119 forall( otypeT) void ?{}(gcpointer(T)* this, void* address) {119 forall(T) void ?{}(gcpointer(T)* this, void* address) { 120 120 (&this->internal) { address }; 121 121 } 122 122 123 forall( otypeT) void ?{}(gcpointer(T)* this, gcpointer(T) other) {123 forall(T) void ?{}(gcpointer(T)* this, gcpointer(T) other) { 124 124 (&this->internal) { other.internal }; 125 125 } 126 126 127 forall( otypeT) void ^?{}(gcpointer(T)* this) {127 forall(T) void ^?{}(gcpointer(T)* this) { 128 128 ^?{}(&this->internal); 129 129 } 130 130 131 forall( otypeT) gcpointer(T) ?=?(gcpointer(T)* this, gcpointer(T) rhs) {131 forall(T) gcpointer(T) ?=?(gcpointer(T)* this, gcpointer(T) rhs) { 132 132 this->internal = rhs.internal; 133 133 return *this; … … 136 136 // forall(otype T) T *?(gcpointer(T) this); 137 137 138 forall( otypeT) T* get(gcpointer(T)* this) {138 forall(T) T* get(gcpointer(T)* this) { 139 139 return (T*)this->internal.ptr; 140 140 } 141 141 // 142 142 // //Logical operators 143 forall( otypeT) int ?!=?(gcpointer(T) this, int zero) {143 forall(T) int ?!=?(gcpointer(T) this, int zero) { 144 144 return this.internal.ptr != 0; 145 145 } -
tests/zombies/gc_no_raii/src/gcpointers.h
r92bfda0 rdafbde8 4 4 #include <stdint.h> 5 5 6 forall( dtype T)6 forall(T &) 7 7 struct gcpointer; 8 8 … … 29 29 #endif 30 30 31 forall( dtype T)31 forall(T &) 32 32 struct gcpointer 33 33 { … … 36 36 37 37 // 38 forall( otypeT) void ?{}(gcpointer(T)* this);39 forall( otypeT) void ?{}(gcpointer(T)* this, void* address);40 forall( otypeT) void ?{}(gcpointer(T)* this, gcpointer(T) other);41 forall( otypeT) void ^?{}(gcpointer(T)* this);42 forall( otypeT) gcpointer(T) ?=?(gcpointer(T)* this, gcpointer(T) rhs);38 forall(T) void ?{}(gcpointer(T)* this); 39 forall(T) void ?{}(gcpointer(T)* this, void* address); 40 forall(T) void ?{}(gcpointer(T)* this, gcpointer(T) other); 41 forall(T) void ^?{}(gcpointer(T)* this); 42 forall(T) gcpointer(T) ?=?(gcpointer(T)* this, gcpointer(T) rhs); 43 43 44 44 45 45 // forall(otype T) T *?(gcpointer(T) this); 46 forall( otypeT) T* get(gcpointer(T)* this);46 forall(T) T* get(gcpointer(T)* this); 47 47 48 48 //Logical operators 49 forall( otypeT) int ?!=?(gcpointer(T) this, int zero);50 forall( otypeT) int ?!=?(gcpointer(T) this, gcpointer(T) rhs);51 forall( otypeT) int ?==?(gcpointer(T) this, gcpointer(T) rhs);49 forall(T) int ?!=?(gcpointer(T) this, int zero); 50 forall(T) int ?!=?(gcpointer(T) this, gcpointer(T) rhs); 51 forall(T) int ?==?(gcpointer(T) this, gcpointer(T) rhs); -
tests/zombies/gc_no_raii/src/tools.h
r92bfda0 rdafbde8 12 12 // } 13 13 14 trait has_equal( otypeT)14 trait has_equal(T) 15 15 { 16 16 signed int ?==?(T a, T b); 17 17 }; 18 18 19 trait InputIterator_t( otype T, otypeInputIterator)19 trait InputIterator_t(T, InputIterator) 20 20 { 21 21 signed int ?==?(InputIterator a, InputIterator b); … … 26 26 }; 27 27 28 forall( otype T | has_equal(T), otypeInputIterator | InputIterator_t(T, InputIterator))28 forall(T | has_equal(T), InputIterator | InputIterator_t(T, InputIterator)) 29 29 static inline InputIterator find( InputIterator first, const InputIterator* const last, T val) 30 30 { -
tests/zombies/hashtable.cfa
r92bfda0 rdafbde8 14 14 15 15 16 trait has_hash( otypeK ) {16 trait has_hash( K ) { 17 17 size_t hash(K); 18 18 int ?==?( K, K ); 19 19 }; 20 20 21 trait hkey( otype K, dtype tN| has_hash(K) ) {21 trait hkey( K, tN & | has_hash(K) ) { 22 22 K key(tN &); 23 23 }; 24 24 25 forall( otype K, dtype tN, dtype tE| $dlistable(tN, tE) | hkey(K, tN) ) {25 forall( K, tN &, tE & | $dlistable(tN, tE) | hkey(K, tN) ) { 26 26 27 27 struct hashtable { … … 39 39 } 40 40 41 forall( otype K, dtype tN, dtype tE| $dlistable(tN, tE) | hkey(K, tN) | { void defaultResumptionHandler(ht_fill_limit_crossed &); } ) {41 forall( K, tN &, tE & | $dlistable(tN, tE) | hkey(K, tN) | { void defaultResumptionHandler(ht_fill_limit_crossed &); } ) { 42 42 43 43 void ?{}( hashtable(K, tN, tE) & this, size_t n_buckets, dlist(tN, tE) *buckets ) { … … 57 57 } 58 58 59 forall( otype K, dtype tN, dtype tE| $dlistable(tN, tE) | hkey(K, tN) ) {59 forall( K, tN &, tE & | $dlistable(tN, tE) | hkey(K, tN) ) { 60 60 61 61 float fill_frac( hashtable(K, tN, tE) & this ) with(this) { … … 124 124 125 125 126 trait heaped( dtype T) {126 trait heaped(T &) { 127 127 T * alloc( size_t ); 128 128 void free( void * ); … … 133 133 } 134 134 135 forall( otype K, dtype tN, dtype tE| $dlistable(tN, tE) | hkey(K, tN) | heaped( dlist(tN, tE) ) ) {135 forall( K, tN &, tE & | $dlistable(tN, tE) | hkey(K, tN) | heaped( dlist(tN, tE) ) ) { 136 136 137 137 struct hashtable_dynamic { -
tests/zombies/hashtable2.cfa
r92bfda0 rdafbde8 69 69 70 70 71 trait pretendsToMatter( dtype TTT) {71 trait pretendsToMatter( TTT & ) { 72 72 void actsmart(TTT &); 73 73 }; 74 74 75 forall( dtype TTTx)75 forall( TTTx & ) 76 76 void actsmart(TTTx &) {} 77 77 … … 86 86 // 2. shows up in -CFA output as hashtable_rbs(), which is bad C; expecting hashtable_rbs* 87 87 88 forall( otypeTt_unused | pretendsToMatter(Tt_unused) ) {88 forall( Tt_unused | pretendsToMatter(Tt_unused) ) { 89 89 90 90 // hashtable of request by source … … 104 104 } 105 105 106 forall( otypeTt_unused | pretendsToMatter(Tt_unused) | { void defaultResumptionHandler(ht_fill_limit_crossed &); } ) {106 forall( Tt_unused | pretendsToMatter(Tt_unused) | { void defaultResumptionHandler(ht_fill_limit_crossed &); } ) { 107 107 108 108 void ?{}( hashtable_rbs(Tt_unused) & this, size_t n_buckets, dlist(request_in_ht_by_src, request) *buckets, … … 135 135 void defaultResumptionHandler( ht_auto_resize_pending & ex ); 136 136 137 forall( otypeTt_unused | pretendsToMatter(Tt_unused) ) {137 forall( Tt_unused | pretendsToMatter(Tt_unused) ) { 138 138 139 139 float fill_frac( hashtable_rbs(Tt_unused) & this ) with(this) { … … 221 221 222 222 223 trait heaped( dtype T) {223 trait heaped(T &) { 224 224 T * alloc( size_t ); 225 225 void free( void * ); … … 228 228 void __dynamic_defaultResumptionHandler(ht_fill_limit_crossed &); 229 229 230 forall( otypeTt_unused ) {230 forall( Tt_unused ) { 231 231 232 232 struct hashtable_rbs_dynamic { … … 263 263 264 264 265 forall( otypeTt_unused | heaped( dlist(request_in_ht_by_src, request) ) ) {265 forall( Tt_unused | heaped( dlist(request_in_ht_by_src, request) ) ) { 266 266 267 267 void ?{}( hashtable_rbs_dynamic(Tt_unused).resize_policy & this, size_t nbuckets_floor ) { … … 325 325 } 326 326 327 forall( otypeTt_unused ) {327 forall( Tt_unused ) { 328 328 void rehashToLarger_STEP( hashtable_rbs_dynamic(Tt_unused) & this, size_t new_n_buckets ) with (this) { 329 329 rehashToLarger( this, new_n_buckets ); -
tests/zombies/huge.c
r92bfda0 rdafbde8 14 14 // 15 15 16 int huge( int n, forall( otypeT ) T (*f)( T ) ) {16 int huge( int n, forall( T ) T (*f)( T ) ) { 17 17 if ( n <= 0 ) 18 18 return f( 0 ); -
tests/zombies/it_out.c
r92bfda0 rdafbde8 16 16 typedef unsigned long streamsize_type; 17 17 18 trait ostream( dtype os_type) {18 trait ostream( os_type & ) { 19 19 os_type *write( os_type *, const char *, streamsize_type ); 20 20 int fail( os_type * ); 21 21 }; 22 22 23 trait writeable( otypeT ) {24 forall( dtype os_type| ostream( os_type ) ) os_type * ?<<?( os_type *, T );23 trait writeable( T ) { 24 forall( os_type & | ostream( os_type ) ) os_type * ?<<?( os_type *, T ); 25 25 }; 26 26 27 forall( dtype os_type| ostream( os_type ) ) os_type * ?<<?( os_type *, char );28 forall( dtype os_type| ostream( os_type ) ) os_type * ?<<?( os_type *, int );29 forall( dtype os_type| ostream( os_type ) ) os_type * ?<<?( os_type *, const char * );27 forall( os_type & | ostream( os_type ) ) os_type * ?<<?( os_type *, char ); 28 forall( os_type & | ostream( os_type ) ) os_type * ?<<?( os_type *, int ); 29 forall( os_type & | ostream( os_type ) ) os_type * ?<<?( os_type *, const char * ); 30 30 31 trait istream( dtype is_type) {31 trait istream( is_type & ) { 32 32 is_type *read( is_type *, char *, streamsize_type ); 33 33 is_type *unread( is_type *, char ); … … 36 36 }; 37 37 38 trait readable( otypeT ) {39 forall( dtype is_type| istream( is_type ) ) is_type * ?<<?( is_type *, T );38 trait readable( T ) { 39 forall( is_type & | istream( is_type ) ) is_type * ?<<?( is_type *, T ); 40 40 }; 41 41 42 forall( dtype is_type| istream( is_type ) ) is_type * ?>>?( is_type *, char* );43 forall( dtype is_type| istream( is_type ) ) is_type * ?>>?( is_type *, int* );42 forall( is_type & | istream( is_type ) ) is_type * ?>>?( is_type *, char* ); 43 forall( is_type & | istream( is_type ) ) is_type * ?>>?( is_type *, int* ); 44 44 45 trait iterator( otype iterator_type, otypeelt_type ) {45 trait iterator( iterator_type, elt_type ) { 46 46 iterator_type ?++( iterator_type* ); 47 47 iterator_type ++?( iterator_type* ); … … 52 52 }; 53 53 54 forall( otypeelt_type | writeable( elt_type ),55 otypeiterator_type | iterator( iterator_type, elt_type ),56 dtype os_type| ostream( os_type ) )54 forall( elt_type | writeable( elt_type ), 55 iterator_type | iterator( iterator_type, elt_type ), 56 os_type & | ostream( os_type ) ) 57 57 void write_all( iterator_type begin, iterator_type end, os_type *os ); 58 58 59 forall( otypeelt_type | writeable( elt_type ),60 otypeiterator_type | iterator( iterator_type, elt_type ),61 dtype os_type| ostream( os_type ) )59 forall( elt_type | writeable( elt_type ), 60 iterator_type | iterator( iterator_type, elt_type ), 61 os_type & | ostream( os_type ) ) 62 62 void write_all( elt_type begin, iterator_type end, os_type *os ) { 63 63 os << begin; -
tests/zombies/new.c
r92bfda0 rdafbde8 14 14 // 15 15 16 forall( otypeT )16 forall( T ) 17 17 void f( T *t ) { 18 18 t--; -
tests/zombies/occursError.cfa
r92bfda0 rdafbde8 1 forall( otypeT ) void f( void (*)( T, T * ) );2 forall( otypeU ) void g( U, U * );3 forall( otypeU ) void h( U *, U );1 forall( T ) void f( void (*)( T, T * ) ); 2 forall( U ) void g( U, U * ); 3 forall( U ) void h( U *, U ); 4 4 5 5 void test() { -
tests/zombies/prolog.c
r92bfda0 rdafbde8 25 25 void is_integer( int x ) {} 26 26 27 trait ArithmeticType( otypeT ) {27 trait ArithmeticType( T ) { 28 28 void is_arithmetic( T ); 29 29 }; 30 30 31 trait IntegralType( otypeT | ArithmeticType( T ) ) {31 trait IntegralType( T | ArithmeticType( T ) ) { 32 32 void is_integer( T ); 33 33 }; 34 34 35 forall( otypeT | IntegralType( T ) | { void printResult( T ); } )35 forall( T | IntegralType( T ) | { void printResult( T ); } ) 36 36 void hornclause( T param ) { 37 37 printResult( param ); -
tests/zombies/quad.c
r92bfda0 rdafbde8 16 16 #include <fstream.hfa> 17 17 18 forall( otypeT | { T ?*?( T, T ); } )18 forall( T | { T ?*?( T, T ); } ) 19 19 T square( T t ) { 20 20 return t * t; 21 21 } 22 22 23 forall( otypeU | { U square( U ); } )23 forall( U | { U square( U ); } ) 24 24 U quad( U u ) { 25 25 return square( square( u ) ); -
tests/zombies/scope.cfa
r92bfda0 rdafbde8 20 20 y p; 21 21 22 trait has_u( otypez ) {22 trait has_u( z ) { 23 23 z u(z); 24 24 }; 25 25 26 forall( otypet | has_u( t ) )26 forall( t | has_u( t ) ) 27 27 y q( t the_t ) { 28 28 t y = u( the_t ); -
tests/zombies/simplePoly.c
r92bfda0 rdafbde8 14 14 // 15 15 16 forall( otype T, otypeU | { T f( T, U ); } )16 forall( T, U | { T f( T, U ); } ) 17 17 T q( T t, U u ) { 18 18 return f( t, u ); -
tests/zombies/simpler.c
r92bfda0 rdafbde8 14 14 // 15 15 16 forall( otypeT ) T id( T, T );16 forall( T ) T id( T, T ); 17 17 18 18 int main() { -
tests/zombies/specialize.c
r92bfda0 rdafbde8 39 39 } 40 40 41 forall( otypeT ) T f( T t )41 forall( T ) T f( T t ) 42 42 { 43 43 printf( "in f; sizeof T is %d\n", sizeof( T ) ); -
tests/zombies/square.c
r92bfda0 rdafbde8 16 16 #include <fstream.hfa> 17 17 18 forall( otypeT | { T ?*?( T, T ); } )18 forall( T | { T ?*?( T, T ); } ) 19 19 T square( T t ) { 20 20 return t * t; -
tests/zombies/structMember.cfa
r92bfda0 rdafbde8 66 66 S.T; 67 67 .S.T; 68 forall( otype S, otypeT ) struct W {68 forall( S, T ) struct W { 69 69 struct X {}; 70 70 }; -
tests/zombies/subrange.cfa
r92bfda0 rdafbde8 1 1 // A small context defining the notion of an ordered otype. (The standard 2 2 // library should probably contain a context for this purpose.) 3 trait ordered( otypeT) {3 trait ordered(T) { 4 4 int ?<?(T, T), ?<=?(T, T); 5 5 }; … … 7 7 // A subrange otype resembling an Ada subotype with a base otype and a range 8 8 // constraint. 9 otype subrange( otypebase_t | ordered(base_t), base_t low = 0, base_t high = 8) = base_t;9 otype subrange(base_t | ordered(base_t), base_t low = 0, base_t high = 8) = base_t; 10 10 11 11 // Note that subrange() can be applied to floating-point and pointer otypes, not … … 28 28 29 29 // Convenient access to subrange bounds, for instance for iteration: 30 forall ( otypeT, T low, T high)30 forall (T, T low, T high) 31 31 T lbound( subrange(T, low, high) v) { 32 32 return low; 33 33 } 34 34 35 forall ( otypeT, T low, T high)35 forall (T, T low, T high) 36 36 T hbound( subrange(T, low, high) v) { 37 37 return high; … … 44 44 // of exception handling here. Inlining allows the compiler to eliminate 45 45 // bounds checks. 46 forall ( otypeT | ordered(T), T low, T high)46 forall (T | ordered(T), T low, T high) 47 47 inline subrange(T, low, high) ?=?(subrange(T, low, high)* target, T source) { 48 48 if (low <= source && source <= high) *((T*)target) = source; … … 54 54 // compares range bounds so that the compiler can optimize checks away when the 55 55 // ranges are known to overlap. 56 forall ( otypeT | ordered(T), T t_low, T t_high, T s_low, T s_high)56 forall (T | ordered(T), T t_low, T t_high, T s_low, T s_high) 57 57 inline subrange(T, t_low, t_high) ?=?(subrange(T, t_low, t_high)* target, 58 58 subrange(T, s_low, s_high) source) { -
tests/zombies/twice.c
r92bfda0 rdafbde8 16 16 #include <fstream.hfa> 17 17 18 forall( otypeT | { T ?+?( T, T ); } )18 forall( T | { T ?+?( T, T ); } ) 19 19 T twice( const T t ) { 20 20 return t + t; -
tests/zombies/typeGenerator.cfa
r92bfda0 rdafbde8 1 context addable( otypeT ) {1 context addable( T ) { 2 2 T ?+?( T,T ); 3 3 T ?=?( T*, T); 4 4 }; 5 5 6 otype List1( otypeT | addable( T ) ) = struct { T data; List1( T ) *next; } *;6 otype List1( T | addable( T ) ) = struct { T data; List1( T ) *next; } *; 7 7 typedef List1( int ) ListOfIntegers; 8 8 //List1( int ) li; … … 11 11 [int] h( * List1( int ) p ); // new declaration syntax 12 12 13 struct( otypeT ) S2 { T i; }; // actual definition13 struct( T ) S2 { T i; }; // actual definition 14 14 struct( int ) S3 v1, *p; // expansion and instantiation 15 struct( otypeT )( int ) S24 { T i; } v2; // actual definition, expansion and instantiation16 struct( otypeT )( int ) { T i; } v2; // anonymous actual definition, expansion and instantiation15 struct( T )( int ) S24 { T i; } v2; // actual definition, expansion and instantiation 16 struct( T )( int ) { T i; } v2; // anonymous actual definition, expansion and instantiation 17 17 18 struct( otypeT | addable( T ) ) node { T data; struct( T ) node *next; };19 otype List( otypeT ) = struct( T ) node *;18 struct( T | addable( T ) ) node { T data; struct( T ) node *next; }; 19 otype List( T ) = struct( T ) node *; 20 20 List( int ) my_list; 21 21 -
tests/zombies/withStatement.cfa
r92bfda0 rdafbde8 54 54 } 55 55 56 forall( otypeT )56 forall( T ) 57 57 struct Box { 58 58 T x; 59 59 }; 60 60 61 forall( otypeT )61 forall( T ) 62 62 void ?{}( Box(T) & this ) with( this ) { // with clause in polymorphic function 63 63 x{}; … … 66 66 void print( int i ) { sout | i; } 67 67 68 forall( otypeT | { void print( T ); })68 forall( T | { void print( T ); }) 69 69 void foo( T t ) { 70 70 Box( T ) b = { t }; -
tests/zombies/wrapper/src/pointer.h
r92bfda0 rdafbde8 8 8 // type safe malloc / free 9 9 10 forall( otypeT)10 forall(T) 11 11 T* new() 12 12 { … … 16 16 } 17 17 18 forall( otypeT)18 forall(T) 19 19 void delete(T* p) 20 20 {
Note:
See TracChangeset
for help on using the changeset viewer.