Changeset 4e107bf


Ignore:
Timestamp:
Aug 3, 2024, 3:48:58 PM (14 months ago)
Author:
JiadaL <j82liang@…>
Branches:
master
Children:
1571e4d
Parents:
a9ae5ca (diff), 433e2c3 (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.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

Files:
14 edited

Legend:

Unmodified
Added
Removed
  • doc/theses/jiada_liang_MMath/intro.tex

    ra9ae5ca r4e107bf  
    11\chapter{Introduction}
    22
    3 All types in a programming language have a set of constants (symbols), and these constants represent values, \eg integer types have constants @-1@, @17@, @0xff@ representing whole numbers, floating-point types have constants @5.3@, @2.3E-5@, @0xff.ffp0@ representing  real numbers, character types have constants @'a'@, @"abc\n"@, \mbox{\lstinline{u8"}\texttt{\guillemotleft{na\"{i}ve}\guillemotright}\lstinline{"}} representing (human readable) text, \etc.
     3All basic types in a programming language have a set of constants (symbols), and these constants represent computable values, \eg integer types have constants @-1@, @17@, @0xff@ representing whole numbers, floating-point types have constants @5.3@, @2.3E-5@, @0xff.ffp0@ representing  real numbers, character types have constants @'a'@, @"abc\n"@, \mbox{\lstinline{u8"}\texttt{\guillemotleft{na\"{i}ve}\guillemotright}\lstinline{"}} representing (human readable) text, \etc.
    44Constants can be overloaded among types, \eg @0@ is a null pointer for all pointer types, and the value zero for integer and floating-point types.
    55(In \CFA, the constants @0@ and @1@ can be overloaded for any type.)
     6Higher-level types compose constants from the basic constants.
     7\begin{cfa}
     8struct S { int i, j, k; } s;
     9s = (S){ 1, 2, 3 };                             $\C[2in]{// structure constant}$
     10int x[5] = { 1, 2, 3, 4, 5 };   $\C{// array constant}\CRT$
     11\end{cfa}
    612A constant's symbolic name is dictated by language syntax related to types, \eg @5.@ (double), @5.0f@ (float), @5l@ (long double).
    7 In general, the representation of a constant's value is \newterm{opaque}, so the internal representation can be chosen arbitrarily.
     13In general, the representation of a constant's value is \newterm{opaque}, so the internal representation can be chosen arbitrarily, \eg two's complement, IEEE floating-point.
    814In theory, there are an infinite set of constant names per type representing an infinite set of values.
    915
     
    1319
    1420Many programming languages capture this important software-engineering capability through a mechanism called \newterm{constant} or \newterm{literal} naming, where a new constant is aliased to an existing constant.
    15 Its purpose is for readability: replacing a constant name that directly represents a value with a name that is more symbolic and meaningful in the context of the program.
    16 Thereafter, changing the aliasing of the new constant to another constant automatically distributes the rebinding, preventing errors.
    17 % and only equality operations are available, \eg @O_RDONLY@, @O_WRONLY@, @O_CREAT@, @O_TRUNC@, @O_APPEND@.
     21Its purpose is for readability: replacing constant values in a program with symbolic names that are more meaningful to programmers in the context of the application.
     22Thereafter, associating a name to a different value automatically distributes this rebinding, preventing errors.
    1823Because an aliased name is a constant, it cannot appear in a mutable context, \eg \mbox{$\pi$ \lstinline{= 42}} is meaningless, and a constant has no address, \ie it is an \newterm{rvalue}\footnote{
    1924The term rvalue defines an expression that can only appear on the right-hand side of an assignment expression.}.
     
    3944for ( cursor in Mon, Wed, Fri, Sun } ...                $\C{// every second day of week}\CRT$
    4045\end{cfa}
    41 A set can have a partial or total ordering, making it possible to compare set elements, \eg Monday is before Friday and Friday is after.
     46A set can have a partial or total ordering, making it possible to compare set elements, \eg Monday is before Tuesday and Tuesday is after.
    4247Ordering allows iterating among the enumeration set using relational operators and advancement, \eg:
    4348\begin{cfa}
    44 for ( cursor = Monday; cursor @<=@ Friday; cursor = @succ@( cursor ) ) ...
     49for ( cursor = Monday; cursor @<=@ Friday; cursor = @succ@( cursor ) ) ... // weekdays
    4550\end{cfa}
    4651Here the values for the set names are logically \emph{generated} rather than listing a subset of names.
     
    5055\item
    5156\begin{sloppypar}
    52 It provides a finite set of new constants, which are implicitly or explicitly assigned values that must be appropriate for any set operations.
     57It provides a finite set of new constants, which are implicitly or explicitly assigned values that must be appropriate for any set operations, \eg increasing order.
    5358This aspect differentiates an enumeration from general types with an infinite set of constants.
    5459\end{sloppypar}
     
    106111\label{s:Aliasing}
    107112
    108 Some languages provide simple aliasing (renaming), \eg:
     113Some languages provide simple aliasing (renaming).
    109114\begin{cfa}
    110115const Size = 20, Pi = 3.14159, Name = "Jane";
     
    113118It is possible to compare aliases, if the constants allow it, \eg @Size < Pi@, whereas @Pi < Name@ might be disallowed depending on the language.
    114119
    115 Aliasing is not macro substitution, \eg @#define Size 20@, where a name is replaced by its value \emph{before} compilation, so the name is invisible to the programming language.
     120Aliasing is \emph{not} macro substitution, \eg @#define Size 20@, where a name is replaced by its value \emph{before} compilation, so the name is invisible to the programming language.
    116121With aliasing, each new name is part of the language, and hence, participates fully, such as name overloading in the type system.
    117 Aliasing is not an immutable variable, \eg:
     122Aliasing is not an immutable variable.
    118123\begin{cfa}
    119124extern @const@ int Size = 20;
     
    123128Taking the address of an immutable variable makes it an \newterm{lvalue}, which implies it has storage.
    124129With separate compilation, it is necessary to choose one translation unit to perform the initialization.
    125 If aliasing does require storage, its address and initialization are opaque (compiler only), similar to \CC rvalue reference @&&@.
     130If aliasing requires storage, its address and initialization are opaque (compiler only), similar to \CC rvalue reference @&&@.
    126131
    127132Aliasing does provide readability and automatic resubstitution.
     
    151156baz = C S{ i = 7, d = 7.5 }
    152157\end{haskell}
    153 the ADT has three variants (constructors), @A@, @B@, @C@ with associated types @Int@, @Double@, and @S@.
     158the ADT has three variants (constructors), @A@, @B@, @C@, with associated types @Int@, @Double@, and @S@.
    154159The constructors create an initialized value of the specific type that is bound to the immutable variables @foo@, @bar@, and @baz@.
    155160Hence, the ADT @Foo@ is like a union containing values of the associated types, and a constructor name is used to intialize and access the value using dynamic pattern-matching.
    156161\begin{cquote}
    157 \setlength{\tabcolsep}{15pt}
     162\setlength{\tabcolsep}{20pt}
    158163\begin{tabular}{@{}ll@{}}
    159164\begin{haskell}
    160165prtfoo val = -- function
    161     -- pattern match on constructor
    162     case val of
    163       @A@ a -> print a
    164       @B@ b -> print b
    165       @C@ (S i d) -> do
    166           print i
    167           print d
     166        -- pattern match on constructor
     167        case val of
     168          @A@ a -> print a
     169          @B@ b -> print b
     170          @C@ (S i d) -> do
     171                print i
     172                print d
    168173\end{haskell}
    169174&
    170175\begin{haskell}
    171176main = do
    172     prtfoo foo
    173     prtfoo bar
    174     prtfoo baz
     177        prtfoo foo
     178        prtfoo bar
     179        prtfoo baz
    1751803
    1761813.5
     
    193198Note, the term \newterm{variant} is often associated with ADTs.
    194199However, there are multiple languages with a @variant@ type that is not an ADT \see{Algol68~\cite{Algol68} or \CC \lstinline{variant}}.
    195 In these languages, the variant is often a union using RTTI tags for discrimination, which cannot be used to simulate an enumeration.
     200Here, the type (and possibly the position for equivalent types) is used to discriminant the specific \emph{variant} within the variant instance.
     201For example, \VRef[Figure]{f:C++variant} shows the \CC equivalent of the two Haskell ADT types using variant types.
     202In these languages, the variant cannot be used to simulate an enumeration.
    196203Hence, in this work the term variant is not a synonym for ADT.
     204
     205\begin{figure}
     206\begin{c++}
     207struct S { char s[32]; };
     208variant< int, double, S > vd;
     209variant< int, int, int > vs;
     210
     211// discrimination based on type
     212vd = 3;
     213if ( holds_alternative<int>(vd) ) cout << "int " << get<int>(vd ) << endl;
     214vd = 3.5;
     215if ( holds_alternative<double>(vd) ) cout << "double " << get<double>(vd) << endl;
     216vd = (S){ "abc" };
     217if ( holds_alternative<S>(vd) ) cout << "S.s " << get<S>(vd).s << endl;
     218
     219// discrimination based on type and position within type
     220vs = (variant<int,int,int>){ in_place_index<0>, 12 };
     221if ( vs.index() == 0 ) cout << "posn 0 " << get<0>(vs) << endl;
     222vs = (variant<int,int,int>){ in_place_index<1>, 4 };
     223if ( vs.index() == 1 ) cout << "posn 1 " << get<1>(vs) << endl;
     224vs = (variant<int,int,int>){ in_place_index<2>, 5 };
     225if ( vs.index() == 2 ) cout << "posn 2 " << get<2>(vs) << endl;
     226\end{c++}
     227\caption{\CC \lstinline[language=C++]{variant} Discrimination Using RTTI/Position}
     228\label{f:C++variant}
     229\end{figure}
    197230
    198231% https://downloads.haskell.org/ghc/latest/docs/libraries/base-4.19.1.0-179c/GHC-Enum.html
     
    200233
    201234The association between ADT and enumeration occurs if all the constructors have a unit (empty) type, \eg @struct unit {}@.
    202 Note, the unit type is not the same as \lstinline{void}, \eg:
     235Note, the unit type is not the same as \lstinline{void}.
    203236\begin{cfa}
    204237void foo( void );
    205238struct unit {} u;       $\C[1.5in]{// empty type}$
    206239unit bar( unit );
    207 foo( foo() );           $\C{// void argument does not match with void parameter}$
     240foo( @foo()@ );         $\C{// void argument does not match with void parameter}$
    208241bar( bar( u ) );        $\C{// unit argument does match with unit parameter}\CRT$
    209242\end{cfa}
     
    214247\end{haskell}
    215248the default type for each constructor is the unit type, and deriving from @Enum@ enforces no other associated types, @Eq@ allows equality comparison, and @Show@ is for printing.
    216 The nullary constructors for the unit types are numbered left-to-right from $0$ to @maxBound@$- 1$, and provides enumerating operations @succ@, @pred@, @enumFrom@ @enumFromTo@.
     249The nullary constructors for the unit types are numbered left-to-right from $0$ to @maxBound@$- 1$, and provides enumerating operations @succ@, @pred@, @enumFrom@, @enumFromTo@.
    217250\VRef[Figure]{f:HaskellEnumeration} shows enumeration comparison and iterating (enumerating).
    218251
    219252\begin{figure}
    220253\begin{cquote}
    221 \setlength{\tabcolsep}{15pt}
     254\setlength{\tabcolsep}{40pt}
    222255\begin{tabular}{@{}ll@{}}
    223256\begin{haskell}
    224257day = Tue
    225258main = do
    226     if day == Tue then
    227         print day
    228     else
    229         putStr "not Tue"
    230     print (enumFrom Mon)            -- week
    231     print (enumFromTo Mon Fri)   -- weekday
    232     print (enumFromTo Sat Sun)  -- weekend
     259        if day == Tue then
     260                print day
     261        else
     262                putStr "not Tue"
     263        print (enumFrom Mon)            $\C[2.25in]{-- week}$
     264        print (enumFromTo Mon Fri)      $\C{-- weekday}$
     265        print (enumFromTo Sat Sun)      $\C{-- weekend}\CRT$
    233266\end{haskell}
    234267&
     
    251284
    252285The key observation is the dichotomy between an ADT and enumeration: the ADT uses the associated type resulting in a union-like data structure, and the enumeration does not use the associated type, and hence, is not a union.
    253 While an enumeration is constructed using the ADT mechanism, it is so restricted it is not an ADT.
     286In contrast, an enumeration may be constructed using the ADT mechanism, but it is so restricted it is not an ADT.
    254287Furthermore, a general ADT cannot be an enumeration because the constructors generate different values making enumerating meaningless.
    255288While functional programming languages regularly repurpose the ADT type into an enumeration type, this process seems contrived and confusing.
     
    266299\begin{enumerate}
    267300\item
    268 overloading
     301overloading:
    269302\item
    270303scoping
  • doc/theses/jiada_liang_MMath/uw-ethesis-frontpgs.tex

    ra9ae5ca r4e107bf  
    131131\begin{center}\textbf{Abstract}\end{center}
    132132
    133 % An enumeration is a type defining an ordered set of named constant values, where a name abstracts a value, \eg @PI@ versus @3.145159@.
    134 % C restrict an enumeration type to the integral type @signed int@, which \CC support, meaning enumeration names bind to integer constants.
    135 % \CFA extends C enumerations to allow all basic and custom types for the enumeration type, like other modern programming languages.
    136 % Furthermore, \CFA adds other useful features for enumerations to support better software-engineering practices and simplify program development.
    137 The \CFA (C-for-all) programming language is an evolutionary refinement of C programing language. One of its distinctive feature is the generic
    138 types. But legacy data type from C, such as enumerations, does not adapt well into the \CFA generic type system.
    139 
    140 This thesis presents an adaptation of enumerated types, in a way that integrates naturallly with the generic type feature of \CFA while being
    141 backward-compatiable to C. This thesis also presents a number of smaller refinement to the \CFA overload resolution rules for enumerated types,
    142 each of which improves the intuitive nature of enumerations.
    143 The enumeration types improvement has been implemented into \CFA compiler and run-time environment. The root ideas behinds the change of
    144 enumeration is to discover the approach of C data types working with \CFA generic types in order to improve the language expressiveity and safety.
     133An \emph{enumeration} is a type defining a (ordered) set of named constant values.
     134\begin{cfa}
     135enum Week { Mon, Tue, Wed, Thu, Fri, Sat, Sun };
     136enum Math { PI = 3.14159, Tau = 6.28318, Phi = 1.61803 };
     137enum RGB { Red = 100b, Green = 010b, Blue = 001b };
     138\end{cfa}
     139Its purpose is for readability: replacing constant values in a program with symbolic names that are more meaningful to programmers in the context of the application.
     140Thereafter, associating a name to a different value automatically distributes this rebinding, preventing errors.
     141One of the key properties of an enumeration is the ability to enumerate (iterate) through the constants, and hence, access their values, if present.
     142C restricts an enumeration to the integral type @signed int@, while \CC extends enumerations to all integral types, meaning enumeration names must bind to integer constants.
     143Other modern programming languages provide bindings to any type and additional features to extend enumeration capabilities for better software-engineering practices.
     144
     145The \CFA (C-for-all) programming language is an evolutionary refinement of the C programing language.
     146One of its distinctive feature is a parametric-polymorphic generic type.
     147However, legacy data types from C, such as enumerations, do not adapt well into the \CFA generic type-system.
     148
     149This thesis extends the simple and unsafe enumeration type in the C programming language into a complex and safe enumeration type in the \CFA programming-language, while maintaining backwards compatibility with C.
     150The major contribution is an adaptation of enumerated types with the \CFA type-system in a way that integrates naturally with the generic types.
     151This thesis also presents a number of smaller refinement to the \CFA overload resolution rules for enumerated types, each of which improves the intuitive nature of enumeration name resolution by the compiler.
     152Finally, this work adds other useful features to enumerations that better support software-engineering practices and simplify program development.
     153
    145154\cleardoublepage
    146155\phantomsection    % allows hyperref to link to the correct page
     
    151160\begin{center}\textbf{Acknowledgements}\end{center}
    152161
    153 To begin, I would like to thank my supervisor Proferssor Peter Buhr. Thank you for your guidance and
    154 support throughout my study and research. I would not be here without you.
    155 
    156 Thanks Gregor Richards and Yzihou Zhang for reading my thesis.
     162To begin, I would like to thank my supervisor Professor Peter Buhr.
     163Thank you for your guidance and support throughout my study and research.
     164I would not be here without you.
     165
     166Thanks to Gregor Richards and Yzihou Zhang for reading my thesis.
    157167
    158168Special thanks to Andrew James Beach for your insight on the theory development on the thesis.
    159169
    160170Thanks to Michael Brooks, Fangran Yu, Colby Parsons, Thierry Delisle, Mubeen Zulifiqar,
    161  and entire Cforall team for development of the \CFA language, making it the best language it can be.
     171and the entire \CFA team for development of the \CFA language, making it the best language it can be.
    162172
    163173Finally, a special thank you to Huawei Canada for funding this work.
  • libcfa/src/enum.cfa

    ra9ae5ca r4e107bf  
    117117                return os | label( e );
    118118        }
    119         OSTYPE_VOID_IMPL( E )
     119        OSTYPE_VOID_IMPL( os, E )
    120120}
  • libcfa/src/gmp.hfa

    ra9ae5ca r4e107bf  
    1010// Created On       : Tue Apr 19 08:43:43 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Jul 18 11:04:54 2023
    13 // Update Count     : 35
     12// Last Modified On : Fri Aug  2 07:41:25 2024
     13// Update Count     : 36
    1414//
    1515
     
    268268                        return os;
    269269                } // ?|?
    270                 OSTYPE_VOID_IMPL( Int )
     270                OSTYPE_VOID_IMPL( os, Int )
    271271        } // distribution
    272272} // distribution
  • libcfa/src/interpose.cfa

    ra9ae5ca r4e107bf  
    1010// Created On       : Wed Mar 29 16:10:31 2017
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Jan 19 16:47:35 2024
    13 // Update Count     : 219
     12// Last Modified On : Sun Jul 28 08:54:31 2024
     13// Update Count     : 220
    1414//
    1515
     
    264264        }
    265265
    266         int len = snprintf( abort_text, abort_text_size, "Cforall Runtime error (UNIX pid:%ld) ", (long int)getpid() ); // use UNIX pid (versus getPid)
     266        int len = snprintf( abort_text, abort_text_size, "Cforall Runtime error (UNIX pid:%ld): ", (long int)getpid() ); // use UNIX pid (versus getPid)
    267267        __cfaabi_bits_write( STDERR_FILENO, abort_text, len );
    268268
  • libcfa/src/iostream.cfa

    ra9ae5ca r4e107bf  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Jul 15 08:16:48 2024
    13 // Update Count     : 2020
     12// Last Modified On : Fri Aug  2 07:38:44 2024
     13// Update Count     : 2021
    1414//
    1515
     
    4747                return os;
    4848        } // ?|?
    49         OSTYPE_VOID_IMPL( bool )
     49        OSTYPE_VOID_IMPL( os, bool )
    5050
    5151        ostype & ?|?( ostype & os, char c ) {
     
    5454                return nosep( os );
    5555        } // ?|?
    56         OSTYPE_VOID_IMPL( char )
     56        OSTYPE_VOID_IMPL( os, char )
    5757
    5858        ostype & ?|?( ostype & os, signed char sc ) {
     
    6161                return os;
    6262        } // ?|?
    63         OSTYPE_VOID_IMPL( signed char )
     63        OSTYPE_VOID_IMPL( os, signed char )
    6464
    6565        ostype & ?|?( ostype & os, unsigned char usc ) {
     
    6868                return os;
    6969        } // ?|?
    70         OSTYPE_VOID_IMPL( unsigned char )
     70        OSTYPE_VOID_IMPL( os, unsigned char )
    7171
    7272        ostype & ?|?( ostype & os, short int si ) {
     
    7575                return os;
    7676        } // ?|?
    77         OSTYPE_VOID_IMPL( short int )
     77        OSTYPE_VOID_IMPL( os, short int )
    7878
    7979        ostype & ?|?( ostype & os, unsigned short int usi ) {
     
    8282                return os;
    8383        } // ?|?
    84         OSTYPE_VOID_IMPL( unsigned short int )
     84        OSTYPE_VOID_IMPL( os, unsigned short int )
    8585
    8686        ostype & ?|?( ostype & os, int i ) {
     
    8989                return os;
    9090        } // ?|?
    91         OSTYPE_VOID_IMPL( int )
     91        OSTYPE_VOID_IMPL( os, int )
    9292
    9393        ostype & ?|?( ostype & os, unsigned int ui ) {
     
    9696                return os;
    9797        } // ?|?
    98         OSTYPE_VOID_IMPL( unsigned int )
     98        OSTYPE_VOID_IMPL( os, unsigned int )
    9999
    100100        ostype & ?|?( ostype & os, long int li ) {
     
    103103                return os;
    104104        } // ?|?
    105         OSTYPE_VOID_IMPL( long int )
     105        OSTYPE_VOID_IMPL( os, long int )
    106106
    107107        ostype & ?|?( ostype & os, unsigned long int uli ) {
     
    110110                return os;
    111111        } // ?|?
    112         OSTYPE_VOID_IMPL( unsigned long int )
     112        OSTYPE_VOID_IMPL( os, unsigned long int )
    113113
    114114        ostype & ?|?( ostype & os, long long int lli ) {
     
    117117                return os;
    118118        } // ?|?
    119         OSTYPE_VOID_IMPL( long long int )
     119        OSTYPE_VOID_IMPL( os, long long int )
    120120
    121121        ostype & ?|?( ostype & os, unsigned long long int ulli ) {
     
    124124                return os;
    125125        } // ?|?
    126         OSTYPE_VOID_IMPL( unsigned long long int )
     126        OSTYPE_VOID_IMPL( os, unsigned long long int )
    127127
    128128        #if defined( __SIZEOF_INT128__ )
     
    156156                return os;
    157157        } // ?|?
    158         OSTYPE_VOID_IMPL( int128 )
     158        OSTYPE_VOID_IMPL( os, int128 )
    159159
    160160        ostype & ?|?( ostype & os, unsigned int128 ullli ) {
     
    163163                return os;
    164164        } // ?|?
    165         OSTYPE_VOID_IMPL( unsigned int128 )
     165        OSTYPE_VOID_IMPL( os, unsigned int128 )
    166166        #endif // __SIZEOF_INT128__
    167167
     
    186186                return os;
    187187        } // ?|?
    188         OSTYPE_VOID_IMPL( float )
     188        OSTYPE_VOID_IMPL( os, float )
    189189
    190190        ostype & ?|?( ostype & os, double d ) {
     
    193193                return os;
    194194        } // ?|?
    195         OSTYPE_VOID_IMPL( double )
     195        OSTYPE_VOID_IMPL( os, double )
    196196
    197197        ostype & ?|?( ostype & os, long double ld ) {
     
    200200                return os;
    201201        } // ?|?
    202         OSTYPE_VOID_IMPL( long double )
     202        OSTYPE_VOID_IMPL( os, long double )
    203203
    204204        ostype & ?|?( ostype & os, float _Complex fc ) {
     
    210210                return os;
    211211        } // ?|?
    212         OSTYPE_VOID_IMPL( float _Complex )
     212        OSTYPE_VOID_IMPL( os, float _Complex )
    213213
    214214        ostype & ?|?( ostype & os, double _Complex dc ) {
     
    220220                return os;
    221221        } // ?|?
    222         OSTYPE_VOID_IMPL( double _Complex )
     222        OSTYPE_VOID_IMPL( os, double _Complex )
    223223
    224224        ostype & ?|?( ostype & os, long double _Complex ldc ) {
     
    230230                return os;
    231231        } // ?|?
    232         OSTYPE_VOID_IMPL( long double _Complex )
     232        OSTYPE_VOID_IMPL( os, long double _Complex )
    233233
    234234        ostype & ?|?( ostype & os, const char s[] ) {
     
    273273//              return write( os, s, len );
    274274        } // ?|?
    275         OSTYPE_VOID_IMPL( const char * )
     275        OSTYPE_VOID_IMPL( os, const char * )
    276276
    277277//      ostype & ?|?( ostype & os, const char16_t s[] ) {
     
    300300                return os;
    301301        } // ?|?
    302         OSTYPE_VOID_IMPL( const void * )
     302        OSTYPE_VOID_IMPL( os, const void * )
    303303
    304304        // manipulators
     
    487487                return os; \
    488488        } /* ?|? */ \
    489         OSTYPE_VOID_IMPL( _Ostream_Manip(T) ) \
     489        OSTYPE_VOID_IMPL( os, _Ostream_Manip(T) ) \
    490490} // distribution
    491491
     
    585585                return os; \
    586586        } /* ?|? */ \
    587         OSTYPE_VOID_IMPL( _Ostream_Manip(T) ) \
     587        OSTYPE_VOID_IMPL( os, _Ostream_Manip(T) ) \
    588588} // distribution
    589589
     
    683683        } /* ?|? */ \
    684684\
    685         OSTYPE_VOID_IMPL( _Ostream_Manip(T) ) \
     685        OSTYPE_VOID_IMPL( os, _Ostream_Manip(T) ) \
    686686} // distribution
    687687
     
    718718                return os;
    719719        } // ?|?
    720         OSTYPE_VOID_IMPL( _Ostream_Manip(char) )
     720        OSTYPE_VOID_IMPL( os, _Ostream_Manip(char) )
    721721} // distribution
    722722
     
    765765                return os;
    766766        } // ?|?
    767         OSTYPE_VOID_IMPL( _Ostream_Manip(const char *) )
     767        OSTYPE_VOID_IMPL( os, _Ostream_Manip(const char *) )
    768768} // distribution
    769769
  • libcfa/src/iostream.hfa

    ra9ae5ca r4e107bf  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Jul 12 05:45:48 2024
    13 // Update Count     : 759
     12// Last Modified On : Fri Aug  2 07:37:57 2024
     13// Update Count     : 760
    1414//
    1515
     
    7575
    7676#define OSTYPE_VOID( T ) void ?|?( ostype &, T )
    77 #define OSTYPE_VOID_IMPL( T ) \
     77#define OSTYPE_VOID_IMPL( os, T ) \
    7878        void ?|?( ostype & os, T t ) { \
    7979                (ostype &)(os | t); ends( os ); \
  • libcfa/src/rational.cfa

    ra9ae5ca r4e107bf  
    1010// Created On       : Wed Apr  6 17:54:28 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Oct  6 07:52:13 2023
    13 // Update Count     : 198
     12// Last Modified On : Fri Aug  2 07:41:25 2024
     13// Update Count     : 199
    1414//
    1515
     
    206206                        return os | r.numerator | '/' | r.denominator;
    207207                } // ?|?
    208                 OSTYPE_VOID_IMPL( rational(T) )
     208                OSTYPE_VOID_IMPL( os, rational(T) )
    209209        } // distribution
    210210} // distribution
  • libcfa/src/time.cfa

    ra9ae5ca r4e107bf  
    1010// Created On       : Tue Mar 27 13:33:14 2018
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Jul 18 10:55:01 2023
    13 // Update Count     : 71
     12// Last Modified On : Fri Aug  2 07:41:24 2024
     13// Update Count     : 72
    1414//
    1515
     
    4343                return os;
    4444        } // ?|?
    45         OSTYPE_VOID_IMPL( Duration )
     45        OSTYPE_VOID_IMPL( os, Duration )
    4646} // distribution
    4747
     
    152152                return os;
    153153        } // ?|?
    154         OSTYPE_VOID_IMPL( Time )
     154        OSTYPE_VOID_IMPL( os, Time )
    155155} // distribution
    156156
  • libcfa/src/vec/vec2.hfa

    ra9ae5ca r4e107bf  
    283283        return os | '<' | x | ',' | y | '>';
    284284    }
    285         OSTYPE_VOID_IMPL( vec2(T) )
     285        OSTYPE_VOID_IMPL( os, vec2(T) )
    286286}
  • libcfa/src/vec/vec3.hfa

    ra9ae5ca r4e107bf  
    292292        return os | '<' | x | ',' | y | ',' | z | '>';
    293293    }
    294         OSTYPE_VOID_IMPL( vec3(T) )
     294        OSTYPE_VOID_IMPL( os, vec3(T) )
    295295}
  • libcfa/src/vec/vec4.hfa

    ra9ae5ca r4e107bf  
    287287        return os | '<' | x | ',' | y | ',' | z | ',' | w | '>';
    288288    }
    289         OSTYPE_VOID_IMPL( vec4(T) )
     289        OSTYPE_VOID_IMPL( os, vec4(T) )
    290290}
    291291
  • tests/ctrl-flow/.expect/loopctrl.txt

    ra9ae5ca r4e107bf  
    6161(10 10)(9 9)(8 8)(7 7)(6 6)(5 5)(4 4)(3 3)(2 2)(1 1)(0 0)
    6262
     633 4 5 6 7 8 9
     643 4 5 6 7 8 9
     6510 9 8 7 6 5 4
     663.5 4.5 5.5 6.5 7.5 8.5 9.5
     67abcde
     68edcba
     69(0 0)(1 1)(2 2)(3 3)(4 4)(5 5)(6 6)
     70(1 1)(2 2)(3 3)(4 4)(5 5)(6 6)
     71(3 0)(4 1)(5 2)(6 3)
     72(7 0)(6 -1)(5 -2)(4 -3)
     73
    6374A A A A A A A A A A
    6475B B B B B B B B B B B
     
    1081190 -2 -4 -6 -8
    1091200 1 2 3 4 5 6 7 8 9
     121A B C D
     122D C B A
  • tests/ctrl-flow/loopctrl.cfa

    ra9ae5ca r4e107bf  
    1010// Created On       : Wed Aug  8 18:32:59 2018
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Jun 27 11:00:09 2024
    13 // Update Count     : 161
     12// Last Modified On : Fri Aug  2 08:42:55 2024
     13// Update Count     : 185
    1414//
    1515
    1616#include <fstream.hfa>
     17#include <enum.hfa>
    1718
    1819void fred() {
     
    8182        for ( int j; s ~ @ ~ @ ) { if ( j == 10 ) break; sout | j; j += 1; } sout | nl;
    8283
    83         // enum E { A, B, C, D };
    84         // for ( e; A ~= C ) { sout | j; }
    85         // for ( e; A ~= D ) { sout | j; }
    86         // for ( e; A -~= D ~ 2 ) { sout | j; }
    87         // for ( e; E ) { sout | j; }
    88         // for ( e; -~ E ) { sout | j; }
     84        enum(int) E { A, B, C, D };
     85//      for ( E e; A ~= C ) { sout | e; } sout | nl;
     86//      for ( e; A ~= D ) { sout | e; } sout | nl;
     87//      for ( e; A -~= D ~ 2 ) { sout | e; } sout | nl;
     88        for ( e; E ) { sout | e; } sout | nl;
     89        for ( e; -~= E ) { sout | e; } sout | nl;
    8990}
    9091
     
    9596void ?{}( S & s, zero_t ) { s.[i, j] = 0; }
    9697void ?{}( S & s, one_t ) { s.[i, j] = 1; }
    97 int ?<?( S t1, S t2 ) { return t1.i < t2.i && t1.j < t2.j; }
    98 int ?<=?( S t1, S t2 ) { return t1.i <= t2.i && t1.j <= t2.j; }
    99 int ?>?( S t1, S t2 ) { return t1.i > t2.i && t1.j > t2.j; }
    100 int ?>=?( S t1, S t2 ) { return t1.i >= t2.i && t1.j >= t2.j; }
    101 S ?+=?( S & t1, S t2 ) { t1.i += t2.i; t1.j += t2.j; return t1; }
    102 S ?+=?( S & t, one_t ) { t.i += 1; t.j += 1; return t; }
    103 S ?-=?( S & t1, S t2 ) { t1.i -= t2.i; t1.j -= t2.j; return t1; }
    104 S ?-=?( S & t, one_t ) { t.i -= 1; t.j -= 1; return t; }
    105 ofstream & ?|?( ofstream & os, S v ) { return os | '(' | v.i | v.j | ')'; }
    106 void & ?|?( ofstream & os, S v ) { (ofstream &)(os | v); ends( os ); }
     98int ?<?( S s1, S s2 ) { return s1.i < s2.i || s1.j < s2.j; }
     99int ?<=?( S s1, S s2 ) { return s1.i <= s2.i || s1.j <= s2.j; }
     100int ?>?( S s1, S s2 ) { return s1.i > s2.i || s1.j > s2.j; }
     101int ?>=?( S s1, S s2 ) { return s1.i >= s2.i || s1.j >= s2.j; }
     102S ?+=?( S & s1, S s2 ) { s1.i += s2.i; s1.j += s2.j; return s1; }
     103S ?+=?( S & s, one_t ) { s.i += 1; s.j += 1; return s; }
     104S ?-=?( S & s1, S s2 ) { s1.i -= s2.i; s1.j -= s2.j; return s1; }
     105S ?-=?( S & s, one_t ) { s.i -= 1; s.j -= 1; return s; }
     106ofstream & ?|?( ofstream & os, S s ) { return os | '(' | s.i | s.j | ')'; }
     107void & ?|?( ofstream & os, S s ) { (ofstream &)(os | s); ends( os ); }
    107108
    108109int main() {
     
    183184        for ( k; 1.5 ~ @ : j; @ -~ -5 ~ 2 : i; 10 ) { sout | i | j | k; } sout | nl;
    184185
    185         for ( S s = (S){0}; s < (S){10,10}; s += (S){1} ) { sout | s; } sout | nl;
     186        for ( S s = (S){0}; s < (S){10,10}; s += (S){1} ) { sout | s; } sout | nl; // 0 does not work
    186187        for ( s; (S){10,10} ) { sout | s; } sout | nl;
    187188        sout | nl;
     
    196197        for ( s; (S){0} -~= (S){10,10} ~ (S){1} ) { sout | s; } sout | nl | nl;
    197198
     199        int i = 10;
     200        double d = 10.;
     201        char c = 'e';
     202        S s = { 7 };
     203
     204        for ( anon; 3 ~ i ) sout | anon;                                        sout | nl;
     205        for ( anon; 3 ~ i ) sout | anon;                                        sout | nl;
     206        for ( anon; 3 -~ i ) sout | anon;                                       sout | nl;
     207        for ( anon; 3.5 ~ d ) sout | anon;                                      sout | nl;
     208        for ( anon; 'a' ~= c ) sout | anon;                                     sout | nl;
     209        for ( anon; 'a' -~= c ) sout | anon;                            sout | nl;
     210        for ( anon; (S){0} ~ s ) sout | anon;                           sout | nl; // 0 does not work
     211        for ( anon; (S){1} ~ s ) sout | anon;                           sout | nl; // 1 does not work
     212        for ( anon; (S){3} ~ s ) sout | anon;                           sout | nl;
     213        for ( anon; (S){3} -~ s ) sout | anon;                          sout | nl | nl;
     214
    198215        fred();
    199216}
Note: See TracChangeset for help on using the changeset viewer.