Changes in / [5541ea3d:0640189e]


Ignore:
Files:
1 added
7 deleted
50 edited

Legend:

Unmodified
Added
Removed
  • doc/theses/andrew_beach_MMath/code/ThrowFinally.java

    r5541ea3d r0640189e  
    77                        throws EmptyException {
    88                if (0 < frames) {
    9                         try {
    10                                 unwind_finally(frames - 1);
    11                         } finally {
    12                                 // ...
    13                         }
     9                        unwind_finally(frames - 1);
    1410                } else {
    1511                        throw new EmptyException();
  • doc/theses/andrew_beach_MMath/code/ThrowOther.java

    r5541ea3d r0640189e  
    1616                                // ...
    1717                        }
    18                 } else if (should_throw) {
    19                         throw new NotRaisedException();
    2018                } else {
     19                        if (should_throw) {
     20                                throw new NotRaisedException();
     21                        }
    2122                        throw new EmptyException();
    2223                }
  • doc/theses/andrew_beach_MMath/code/cond-catch.cfa

    r5541ea3d r0640189e  
    1919                throw_exception();
    2020        } catch (empty_exception * exc ; should_catch) {
    21                 asm volatile ("# catch block (conditional)");
     21                // ...
    2222        }
    2323}
     
    3737                        cond_catch();
    3838                } catch (empty_exception * exc) {
    39                         asm volatile ("# catch block (unconditional)");
     39                        // ...
    4040                }
    4141        }
  • doc/theses/andrew_beach_MMath/code/cond-catch.cpp

    r5541ea3d r0640189e  
    2222                        throw;
    2323                }
    24                 asm volatile ("# catch block (conditional)");
    2524        }
    2625}
     
    4039                        cond_catch();
    4140                } catch (EmptyException &) {
    42                         asm volatile ("# catch block (unconditional)");
     41                        // ...
    4342                }
    4443    }
  • doc/theses/andrew_beach_MMath/code/cond-fixup.cfa

    r5541ea3d r0640189e  
    1212
    1313void throw_exception() {
    14         throwResume (empty_exception){&empty_vt};
     14        throw (empty_exception){&empty_vt};
    1515}
    1616
     
    1818        try {
    1919                throw_exception();
    20         } catchResume (empty_exception * exc ; should_catch) {
    21                 asm volatile ("# fixup block (conditional)");
     20        } catch (empty_exception * exc ; should_catch) {
     21                // ...
    2222        }
    2323}
     
    3636                try {
    3737                        cond_catch();
    38                 } catchResume (empty_exception * exc) {
    39                         asm volatile ("# fixup block (unconditional)");
     38                } catch (empty_exception * exc) {
     39                        // ...
    4040                }
    4141        }
  • doc/theses/andrew_beach_MMath/code/cross-catch.cfa

    r5541ea3d r0640189e  
    77EHM_EXCEPTION(not_raised_exception)();
    88
    9 EHM_VIRTUAL_TABLE(not_raised_exception, not_vt);
    10 
    119int main(int argc, char * argv[]) {
    1210        unsigned int times = 1;
    13         volatile bool should_throw = false;
     11        unsigned int total_frames = 1;
    1412        if (1 < argc) {
    1513                times = strtol(argv[1], 0p, 10);
     14        }
     15        if (2 < argc) {
     16                total_frames = strtol(argv[2], 0p, 10);
    1617        }
    1718
     
    1920        for (unsigned int count = 0 ; count < times ; ++count) {
    2021                try {
    21                         asm volatile ("# try block");
    22                         if (should_throw) {
    23                                 throw (not_raised_exception){&not_vt};
    24                         }
     22                        // ...
    2523                } catch (not_raised_exception *) {
    26                         asm volatile ("# catch block");
     24                        // ...
    2725                }
    2826        }
  • doc/theses/andrew_beach_MMath/code/cross-catch.cpp

    r5541ea3d r0640189e  
    1111int main(int argc, char * argv[]) {
    1212        unsigned int times = 1;
    13         volatile bool should_throw = false;
    1413        if (1 < argc) {
    1514                times = strtol(argv[1], nullptr, 10);
     
    1918        for (unsigned int count = 0 ; count < times ; ++count) {
    2019                try {
    21                         asm volatile ("# try block");
    22                         if (should_throw) {
    23                                 throw NotRaisedException();
    24                         }
     20                        // ...
    2521                } catch (NotRaisedException &) {
    26                         asm volatile ("# catch block");
     22                        // ...
    2723                }
    2824        }
  • doc/theses/andrew_beach_MMath/code/cross-finally.cfa

    r5541ea3d r0640189e  
    55#include <stdlib.hfa>
    66
    7 EHM_EXCEPTION(not_raised_exception)();
    8 
    9 EHM_VIRTUAL_TABLE(not_raised_exception, not_vt);
    10 
    117int main(int argc, char * argv[]) {
    128        unsigned int times = 1;
    13         volatile bool should_throw = false;
     9        unsigned int total_frames = 1;
    1410        if (1 < argc) {
    1511                times = strtol(argv[1], 0p, 10);
     12        }
     13        if (2 < argc) {
     14                total_frames = strtol(argv[2], 0p, 10);
    1615        }
    1716
    1817        Time start_time = timeHiRes();
    1918        for (unsigned int count = 0 ; count < times ; ++count) {
    20                 try {
    21                         asm volatile ("# try block");
    22                         if (should_throw) {
    23                                 throw (not_raised_exception){&not_vt};
    24                         }
     19                 try {
     20                        // ...
    2521                } finally {
    26                         asm volatile ("# finally block");
     22                        // ...
    2723                }
    2824        }
  • doc/theses/andrew_beach_MMath/code/cross-resume.cfa

    r5541ea3d r0640189e  
    2020        for (unsigned int count = 0 ; count < times ; ++count) {
    2121                try {
    22                         asm volatile ("");
     22                        // ...
    2323                } catchResume (not_raised_exception *) {
    24                         asm volatile ("");
     24                        // ...
    2525                }
    2626        }
  • doc/theses/andrew_beach_MMath/code/resume-detor.cfa

    r5541ea3d r0640189e  
    1212
    1313void ^?{}(WithDestructor & this) {
    14         asm volatile ("# destructor body");
     14    // ...
    1515}
    1616
    1717void unwind_destructor(unsigned int frames) {
    18         if (frames) {
     18    if (frames) {
    1919
    20                 WithDestructor object;
    21                 unwind_destructor(frames - 1);
    22         } else {
    23                 throwResume (empty_exception){&empty_vt};
    24         }
     20        WithDestructor object;
     21        unwind_destructor(frames - 1);
     22    } else {
     23        throwResume (empty_exception){&empty_vt};
     24    }
    2525}
    2626
     
    3636
    3737        Time start_time = timeHiRes();
    38         for (int count = 0 ; count < times ; ++count) {
    39                 try {
    40                         unwind_destructor(total_frames);
    41                 } catchResume (empty_exception *) {
    42                         asm volatile ("# fixup block");
    43                 }
    44         }
     38    for (int count = 0 ; count < times ; ++count) {
     39        try {
     40            unwind_destructor(total_frames);
     41        } catchResume (empty_exception *) {
     42            // ...
     43        }
     44    }
    4545        Time end_time = timeHiRes();
    4646        sout | "Run-Time (ns): " | (end_time - start_time)`ns;
  • doc/theses/andrew_beach_MMath/code/resume-empty.cfa

    r5541ea3d r0640189e  
    1313                unwind_empty(frames - 1);
    1414        } else {
    15                 throwResume (empty_exception){&empty_vt};
     15                throw (empty_exception){&empty_vt};
    1616        }
    1717}
     
    3131                try {
    3232                        unwind_empty(total_frames);
    33                 } catchResume (empty_exception *) {
    34                         asm volatile ("# fixup block");
     33                } catch (empty_exception *) {
     34                        // ...
    3535                }
    3636        }
  • doc/theses/andrew_beach_MMath/code/resume-finally.cfa

    r5541ea3d r0640189e  
    1414                        unwind_finally(frames - 1);
    1515                } finally {
    16                         asm volatile ("# finally block");
     16                        // ...
    1717                }
    1818        } else {
     
    3636                        unwind_finally(total_frames);
    3737                } catchResume (empty_exception *) {
    38                         asm volatile ("# fixup block");
     38                        // ...
    3939                }
    4040        }
  • doc/theses/andrew_beach_MMath/code/resume-other.cfa

    r5541ea3d r0640189e  
    1616                        unwind_other(frames - 1);
    1717                } catchResume (not_raised_exception *) {
    18                         asm volatile ("# fixup block (stack)");
     18                        // ...
    1919                }
    2020        } else {
     
    3838                        unwind_other(total_frames);
    3939                } catchResume (empty_exception *) {
    40                         asm volatile ("# fixup block (base)");
     40                        // ...
    4141                }
    4242        }
  • doc/theses/andrew_beach_MMath/code/test.sh

    r5541ea3d r0640189e  
    11#!/usr/bin/env bash
    22
    3 # Usage:
    4 # test.sh LANGUAGE TEST
    5 #   Run the TEST in LANGUAGE.
    6 # test.sh -b SOURCE_FILE...
    7 #   Build a test from SOURCE_FILE(s).
    8 # test.sh -v LANGUAGE TEST FILE
    9 #   View the result from TEST in LANGUAGE stored in FILE.
     3# Usage: LANGUAGE TEST | -b SOURCE_FILE
    104
    115readonly ITERATIONS=1000000 # 1 000 000, one million
     
    4438        done
    4539        exit 0
    46 elif [ "-v" = "$1" -a 4 = "$#" ]; then
    47     TEST_LANG="$2"
    48     TEST_CASE="$3"
    49     VIEW_FILE="$4"
    5040elif [ 2 -eq "$#" ]; then
    5141        TEST_LANG="$1"
     
    126116
    127117case "$TEST_LANG" in
    128 cfa-t) CALL="$CFAT";;
    129 cfa-r) CALL="$CFAR";;
    130 cpp) CALL="$CPP";;
    131 java) CALL="$JAVA";;
    132 python) CALL="$PYTHON";;
     118cfa-t) echo $CFAT; $CFAT;;
     119cfa-r) echo $CFAR; $CFAR;;
     120cpp) echo $CPP; $CPP;;
     121java) echo $JAVA; $JAVA;;
     122python) echo $PYTHON; $PYTHON;;
    133123*)
    134124        echo "No such language: $TEST_LANG" >&2
     
    136126        ;;
    137127esac
    138 
    139 echo $CALL
    140 
    141 if [ -n "$VIEW_FILE" ]; then
    142     grep -A 1 -B 0 "$CALL" "$VIEW_FILE" | sed -n -e 's!Run-Time (ns): !!;T;p'
    143     exit
    144 fi
    145 
    146 $CALL
  • doc/theses/andrew_beach_MMath/code/throw-detor.cfa

    r5541ea3d r0640189e  
    1212
    1313void ^?{}(WithDestructor & this) {
    14         asm volatile ("# destructor body");
     14        // ...
    1515}
    1616
     
    3939                        unwind_destructor(total_frames);
    4040                } catch (empty_exception *) {
    41                         asm volatile ("# catch block");
     41                        // ...
    4242                }
    4343        }
  • doc/theses/andrew_beach_MMath/code/throw-detor.cpp

    r5541ea3d r0640189e  
    1010
    1111struct WithDestructor {
    12         ~WithDestructor() {
    13                 asm volatile ("# destructor body");
    14         }
     12        ~WithDestructor() {}
    1513};
    1614
     
    3937                        unwind_destructor(total_frames);
    4038                } catch (EmptyException &) {
    41                         asm volatile ("# catch block");
     39                        // ...
    4240                }
    4341        }
  • doc/theses/andrew_beach_MMath/code/throw-empty.cfa

    r5541ea3d r0640189e  
    3232                        unwind_empty(total_frames);
    3333                } catch (empty_exception *) {
    34                         asm volatile ("# catch block");
     34                        // ...
    3535                }
    3636        }
  • doc/theses/andrew_beach_MMath/code/throw-empty.cpp

    r5541ea3d r0640189e  
    3232                        unwind_empty(total_frames);
    3333                } catch (EmptyException &) {
    34                         asm volatile ("# catch block");
     34                        // ...
    3535                }
    3636        }
  • doc/theses/andrew_beach_MMath/code/throw-finally.cfa

    r5541ea3d r0640189e  
    1414                        unwind_finally(frames - 1);
    1515                } finally {
    16                         asm volatile ("# finally block");
     16                        // ...
    1717                }
    1818        } else {
     
    3636                        unwind_finally(total_frames);
    3737                } catch (empty_exception *) {
    38                         asm volatile ("# catch block");
     38                        // ...
    3939                }
    4040        }
  • doc/theses/andrew_beach_MMath/code/throw-other.cfa

    r5541ea3d r0640189e  
    1616                        unwind_other(frames - 1);
    1717                } catch (not_raised_exception *) {
    18                         asm volatile ("# catch block (stack)");
     18                        // ...
    1919                }
    2020        } else {
     
    3838                        unwind_other(total_frames);
    3939                } catch (empty_exception *) {
    40                         asm volatile ("# catch block (base)");
     40                        // ...
    4141                }
    4242        }
  • doc/theses/andrew_beach_MMath/code/throw-other.cpp

    r5541ea3d r0640189e  
    1616                        unwind_other(frames - 1);
    1717                } catch (NotRaisedException &) {
    18                         asm volatile ("# catch block (stack)");
     18                        // ...
    1919                }
    2020        } else {
     
    3838                        unwind_other(total_frames);
    3939                } catch (EmptyException &) {
    40                         asm volatile ("# catch block (base)");
     40                        // ...
    4141                }
    4242        }
  • doc/theses/andrew_beach_MMath/existing.tex

    r5541ea3d r0640189e  
    1010
    1111Only those \CFA features pertaining to this thesis are discussed.
    12 % Also, only new features of \CFA will be discussed,
    13 A familiarity with
     12Also, only new features of \CFA will be discussed, a familiarity with
    1413C or C-like languages is assumed.
    1514
     
    1716\CFA has extensive overloading, allowing multiple definitions of the same name
    1817to be defined~\cite{Moss18}.
    19 \begin{lstlisting}[language=CFA,{moredelim=**[is][\color{red}]{@}{@}}]
    20 char @i@; int @i@; double @i@;
    21 int @f@(); double @f@();
    22 void @g@( int ); void @g@( double );
    23 \end{lstlisting}
     18\begin{cfa}
     19char i; int i; double i;
     20int f(); double f();
     21void g( int ); void g( double );
     22\end{cfa}
    2423This feature requires name mangling so the assembly symbols are unique for
    2524different overloads. For compatibility with names in C, there is also a syntax
     
    6362int && rri = ri;
    6463rri = 3;
    65 &ri = &j; // rebindable
     64&ri = &j;
    6665ri = 5;
    6766\end{cfa}
     
    7978\end{minipage}
    8079
    81 References are intended for pointer situations where dereferencing is the common usage,
    82 \ie the value is more important than the pointer.
     80References are intended to be used when you would use pointers but would
     81be dereferencing them (almost) every usage.
    8382Mutable references may be assigned to by converting them to a pointer
    8483with a @&@ and then assigning a pointer to them, as in @&ri = &j;@ above
     
    8685\section{Operators}
    8786
    88 \CFA implements operator overloading by providing special names, where
    89 operator usages are translated into function calls using these names.
    90 An operator name is created by taking the operator symbols and joining them with
     87\CFA implements operator overloading by providing special names.
     88Operator uses are translated into function calls using these names.
     89These names are created by taking the operator symbols and joining them with
    9190@?@s to show where the arguments go.
    9291For example,
    93 infixed multiplication is @?*?@, while prefix dereference is @*?@.
     92infixed multiplication is @?*?@ while prefix dereference is @*?@.
    9493This syntax make it easy to tell the difference between prefix operations
    9594(such as @++?@) and post-fix operations (@?++@).
    96 For example, plus and equality operators are defined for a point type.
     95
    9796\begin{cfa}
    9897point ?+?(point a, point b) { return point{a.x + b.x, a.y + b.y}; }
    99 int ?==?(point a, point b) { return a.x == b.x && a.y == b.y; }
     98bool ?==?(point a, point b) { return a.x == b.x && a.y == b.y; }
    10099{
    101100        assert(point{1, 2} + point{3, 4} == point{4, 6});
    102101}
    103102\end{cfa}
    104 Note these special names are not limited to builtin
    105 operators, and hence, may be used with arbitrary types.
    106 \begin{cfa}
    107 double ?+?( int x, point y ); // arbitrary types
    108 \end{cfa}
    109 % Some ``near misses", that are that do not match an operator form but looks like
    110 % it may have been supposed to, will generate warning but otherwise they are
    111 % left alone.
     103Note that these special names are not limited to just being used for these
     104operator functions, and may be used name other declarations.
     105Some ``near misses", that will not match an operator form but looks like
     106it may have been supposed to, will generate wantings but otherwise they are
     107left alone.
     108
     109%\subsection{Constructors and Destructors}
     110
     111Both constructors and destructors are operators, which means they are
     112functions with special operator names rather than type names in \Cpp. The
     113special operator names may be used to call the functions explicitly.
     114% Placement new means that this is actually equivant to C++.
     115
     116The special name for a constructor is @?{}@, which comes from the
     117initialization syntax in C, \eg @Example e = { ... }@.
     118\CFA will generate a constructor call each time a variable is declared,
     119passing the initialization arguments to the constructort.
     120\begin{cfa}
     121struct Example { ... };
     122void ?{}(Example & this) { ... }
     123{
     124        Example a;
     125        Example b = {};
     126}
     127void ?{}(Example & this, char first, int num) { ... }
     128{
     129        Example c = {'a', 2};
     130}
     131\end{cfa}
     132Both @a@ and @b@ will be initalized with the first constructor,
     133while @c@ will be initalized with the second.
     134Currently, there is no general way to skip initialation.
     135
     136% I don't like the \^{} symbol but $^\wedge$ isn't better.
     137Similarly destructors use the special name @^?{}@ (the @^@ has no special
     138meaning).
     139These are a normally called implicitly called on a variable when it goes out
     140of scope. They can be called explicitly as well.
     141\begin{cfa}
     142void ^?{}(Example & this) { ... }
     143{
     144        Example d;
     145} // <- implicit destructor call
     146\end{cfa}
     147
     148Whenever a type is defined, \CFA will create a default zero-argument
     149constructor, a copy constructor, a series of argument-per-field constructors
     150and a destructor. All user constructors are defined after this.
    112151Because operators are never part of the type definition they may be added
    113152at any time, including on built-in types.
    114 
    115 %\subsection{Constructors and Destructors}
    116 
    117 \CFA also provides constructors and destructors as operators, which means they
    118 are functions with special operator names rather than type names in \Cpp.
    119 While constructors and destructions are normally called implicitly by the compiler,
    120 the special operator names, allow explicit calls.
    121 
    122 % Placement new means that this is actually equivalent to C++.
    123 
    124 The special name for a constructor is @?{}@, which comes from the
    125 initialization syntax in C, \eg @Example e = { ... }@.
    126 \CFA generates a constructor call each time a variable is declared,
    127 passing the initialization arguments to the constructor.
    128 \begin{cfa}
    129 struct Example { ... };
    130 void ?{}(Example & this) { ... }
    131 void ?{}(Example & this, char first, int num) { ... }
    132 Example a;              // implicit constructor calls
    133 Example b = {};
    134 Example c = {'a', 2};
    135 \end{cfa}
    136 Both @a@ and @b@ are initialized with the first constructor,
    137 while @c@ is initialized with the second.
    138 Constructor calls can be replaced with C initialization using special operator \lstinline{@=}.
    139 \begin{cfa}
    140 Example d @= {42};
    141 \end{cfa}
    142 % I don't like the \^{} symbol but $^\wedge$ isn't better.
    143 Similarly, destructors use the special name @^?{}@ (the @^@ has no special
    144 meaning).
    145 % These are a normally called implicitly called on a variable when it goes out
    146 % of scope. They can be called explicitly as well.
    147 \begin{cfa}
    148 void ^?{}(Example & this) { ... }
    149 {
    150         Example e;      // implicit constructor call
    151         ^?{}(e);                // explicit destructor call
    152         ?{}(e);         // explicit constructor call
    153 } // implicit destructor call
    154 \end{cfa}
    155 
    156 Whenever a type is defined, \CFA creates a default zero-argument
    157 constructor, a copy constructor, a series of argument-per-field constructors
    158 and a destructor. All user constructors are defined after this.
    159153
    160154\section{Polymorphism}
     
    208202Note, a function named @do_once@ is not required in the scope of @do_twice@ to
    209203compile it, unlike \Cpp template expansion. Furthermore, call-site inferencing
    210 allows local replacement of the specific parametric functions needs for a
     204allows local replacement of the most specific parametric functions needs for a
    211205call.
    212206\begin{cfa}
     
    224218to @do_twice@ and called within it.
    225219The global definition of @do_once@ is ignored, however if quadruple took a
    226 @double@ argument, then the global definition would be used instead as it
    227 is a better match.
     220@double@ argument then the global definition would be used instead as it
     221would be a better match.
    228222% Aaron's thesis might be a good reference here.
    229223
    230224To avoid typing long lists of assertions, constraints can be collect into
    231 convenient package called a @trait@, which can then be used in an assertion
     225convenient packages called a @trait@, which can then be used in an assertion
    232226instead of the individual constraints.
    233227\begin{cfa}
     
    245239functionality, like @sumable@, @listable@, \etc.
    246240
    247 Polymorphic structures and unions are defined by qualifying an aggregate type
     241Polymorphic structures and unions are defined by qualifying the aggregate type
    248242with @forall@. The type variables work the same except they are used in field
    249243declarations instead of parameters, returns, and local variable declarations.
     
    291285coroutine CountUp {
    292286        unsigned int next;
    293 };
     287}
    294288CountUp countup;
    295 for (10) sout | resume(countup).next; // print 10 values
    296289\end{cfa}
    297290Each coroutine has a @main@ function, which takes a reference to a coroutine
    298291object and returns @void@.
    299292%[numbers=left] Why numbers on this one?
    300 \begin{cfa}[numbers=left,numberstyle=\scriptsize\sf]
     293\begin{cfa}
    301294void main(CountUp & this) {
    302         for (unsigned int up = 0;; ++up) {
    303                 this.next = up;
     295        for (unsigned int next = 0 ; true ; ++next) {
     296                next = up;
    304297                suspend;$\label{suspend}$
    305298        }
     
    307300\end{cfa}
    308301In this function, or functions called by this function (helper functions), the
    309 @suspend@ statement is used to return execution to the coroutine's resumer
    310 without terminating the coroutine's function(s).
     302@suspend@ statement is used to return execution to the coroutine's caller
     303without terminating the coroutine's function.
    311304
    312305A coroutine is resumed by calling the @resume@ function, \eg @resume(countup)@.
     
    330323exclusion on a monitor object by qualifying an object reference parameter with
    331324@mutex@.
    332 \begin{lstlisting}[language=CFA,{moredelim=**[is][\color{red}]{@}{@}}]
    333 void example(MonitorA & @mutex@ argA, MonitorB & @mutex@ argB);
    334 \end{lstlisting}
     325\begin{cfa}
     326void example(MonitorA & mutex argA, MonitorB & mutex argB);
     327\end{cfa}
    335328When the function is called, it implicitly acquires the monitor lock for all of
    336329the mutex parameters without deadlock.  This semantics means all functions with
     
    362355{
    363356        StringWorker stringworker; // fork thread running in "main"
    364 } // implicitly join with thread / wait for completion
     357} // <- implicitly join with thread / wait for completion
    365358\end{cfa}
    366359The thread main is where a new thread starts execution after a fork operation
  • doc/theses/andrew_beach_MMath/intro.tex

    r5541ea3d r0640189e  
    22
    33% The highest level overview of Cforall and EHMs. Get this done right away.
    4 This thesis covers the design and implementation of the exception handling
     4This thesis goes over the design and implementation of the exception handling
    55mechanism (EHM) of
    66\CFA (pronounced sea-for-all and may be written Cforall or CFA).
    7 \CFA is a new programming language that extends C, which maintains
     7\CFA is a new programming language that extends C, that maintains
    88backwards-compatibility while introducing modern programming features.
    99Adding exception handling to \CFA gives it new ways to handle errors and
    10 make large control-flow jumps.
     10make other large control-flow jumps.
    1111
    1212% Now take a step back and explain what exceptions are generally.
    13 A language's EHM is a combination of language syntax and run-time
    14 components that are used to construct, raise, and handle exceptions,
    15 including all control flow.
    16 Exceptions are an active mechanism for replacing passive error/return codes and return unions (Go and Rust).
    1713Exception handling provides dynamic inter-function control flow.
    1814There are two forms of exception handling covered in this thesis:
    1915termination, which acts as a multi-level return,
    2016and resumption, which is a dynamic function call.
    21 % PAB: Maybe this sentence was suppose to be deleted?
    2217Termination handling is much more common,
    23 to the extent that it is often seen as the only form of handling.
    24 % PAB: I like this sentence better than the next sentence.
    25 % This separation is uncommon because termination exception handling is so
    26 % much more common that it is often assumed.
     18to the extent that it is often seen
     19This seperation is uncommon because termination exception handling is so
     20much more common that it is often assumed.
    2721% WHY: Mention other forms of continuation and \cite{CommonLisp} here?
    28 
    29 Exception handling relies on the concept of nested functions to create handlers that deal with exceptions.
     22A language's EHM is the combination of language syntax and run-time
     23components that are used to construct, raise and handle exceptions,
     24including all control flow.
     25
     26Termination exception handling allows control to return to any previous
     27function on the stack directly, skipping any functions between it and the
     28current function.
    3029\begin{center}
    31 \begin{tabular}[t]{ll}
    32 \begin{lstlisting}[aboveskip=0pt,belowskip=0pt,language=CFA,{moredelim=**[is][\color{red}]{@}{@}}]
    33 void f( void (*hp)() ) {
    34         hp();
    35 }
    36 void g( void (*hp)() ) {
    37         f( hp );
    38 }
    39 void h( int @i@, void (*hp)() ) {
    40         void @handler@() { // nested
    41                 printf( "%d\n", @i@ );
    42         }
    43         if ( i == 1 ) hp = handler;
    44         if ( i > 0 ) h( i - 1, hp );
    45         else g( hp );
    46 }
    47 h( 2, 0 );
    48 \end{lstlisting}
    49 &
    50 \raisebox{-0.5\totalheight}{\input{handler}}
    51 \end{tabular}
     30\input{callreturn}
    5231\end{center}
    53 The nested function @handler@ in the second stack frame is explicitly passed to function @f@.
    54 When this handler is called in @f@, it uses the parameter @i@ in the second stack frame, which is accessible by an implicit lexical-link pointer.
    55 Setting @hp@ in @h@ at different points in the recursion, results in invoking a different handler.
    56 Exception handling extends this idea by eliminating explicit handler passing, and instead, performing a stack search for a handler that matches some criteria (conditional dynamic call), and calls the handler at the top of the stack.
    57 It is the runtime search $O(N)$ that differentiates an EHM call (raise) from normal dynamic call $O(1)$ via a function or virtual-member pointer.
    58 
    59 Termination exception handling searches the stack for a handler, unwinds the stack to the frame containing the matching handler, and calling the handler at the top of the stack.
    60 \begin{center}
    61 \input{termination}
    62 \end{center}
    63 Note, since the handler can reference variables in @h@, @h@ must remain on the stack for the handler call.
    64 After the handler returns, control continues after the lexical location of the handler in @h@ (static return)~\cite[p.~108]{Tennent77}.
    65 Unwinding allows recover to any previous
    66 function on the stack, skipping any functions between it and the
    67 function containing the matching handler.
    68 
    69 Resumption exception handling searches the stack for a handler, does \emph{not} unwind the stack to the frame containing the matching handler, and calls the handler at the top of the stack.
    70 \begin{center}
    71 \input{resumption}
    72 \end{center}
    73 After the handler returns, control continues after the resume in @f@ (dynamic return).
    74 Not unwinding allows fix up of the problem in @f@ by any previous function on the stack, without disrupting the current set of stack frames.
     32
     33Resumption exception handling seaches the stack for a handler and then calls
     34it without adding or removing any other stack frames.
     35\todo{Add a diagram showing control flow for resumption.}
    7536
    7637Although a powerful feature, exception handling tends to be complex to set up
    7738and expensive to use
    78 so it is often limited to unusual or ``exceptional" cases.
    79 The classic example is error handling, where exceptions are used to
    80 remove error handling logic from the main execution path, while paying
     39so they are often limited to unusual or ``exceptional" cases.
     40The classic example of this is error handling, exceptions can be used to
     41remove error handling logic from the main execution path and while paying
    8142most of the cost only when the error actually occurs.
    8243
     
    8849some of the underlying tools used to implement and express exception handling
    8950in other languages are absent in \CFA.
    90 Still the resulting basic syntax resembles that of other languages:
    91 \begin{lstlisting}[language=CFA,{moredelim=**[is][\color{red}]{@}{@}}]
    92 @try@ {
     51Still the resulting syntax resembles that of other languages:
     52\begin{cfa}
     53try {
    9354        ...
    9455        T * object = malloc(request_size);
    9556        if (!object) {
    96                 @throw@ OutOfMemory{fixed_allocation, request_size};
     57                throw OutOfMemory{fixed_allocation, request_size};
    9758        }
    9859        ...
    99 } @catch@ (OutOfMemory * error) {
     60} catch (OutOfMemory * error) {
    10061        ...
    10162}
    102 \end{lstlisting}
     63\end{cfa}
     64
    10365% A note that yes, that was a very fast overview.
    10466The design and implementation of all of \CFA's EHM's features are
     
    10769
    10870% The current state of the project and what it contributes.
    109 The majority of the \CFA EHM is implemented in \CFA, except for a small amount of assembler code.
    110 In addition,
    111 a suite of tests and performance benchmarks were created as part of this project.
    112 The \CFA implementation techniques are generally applicable in other programming
     71All of these features have been implemented in \CFA, along with
     72a suite of test cases as part of this project.
     73The implementation techniques are generally applicable in other programming
    11374languages and much of the design is as well.
    114 Some parts of the EHM use features unique to \CFA, and hence,
    115 are harder to replicate in other programming languages.
     75Some parts of the EHM use other features unique to \CFA and these would be
     76harder to replicate in other programming languages.
     77
    11678% Talk about other programming languages.
    117 Three well known programming languages with EHMs, %/exception handling
    118 C++, Java and Python are examined in the performance work. However, these languages focus on termination
    119 exceptions, so there is no comparison with resumption.
     79Some existing programming languages that include EHMs/exception handling
     80include C++, Java and Python. All three examples focus on termination
     81exceptions which unwind the stack as part of the
     82Exceptions also can replace return codes and return unions.
    12083
    12184The contributions of this work are:
    12285\begin{enumerate}
    12386\item Designing \CFA's exception handling mechanism, adapting designs from
    124 other programming languages, and creating new features.
    125 \item Implementing stack unwinding for the \CFA EHM, including updating
    126 the \CFA compiler and run-time environment to generate and execute the EHM code.
    127 \item Designing and implementing a prototype virtual system.
     87other programming languages and the creation of new features.
     88\item Implementing stack unwinding and the EHM in \CFA, including updating
     89the compiler and the run-time environment.
     90\item Designed and implemented a prototype virtual system.
    12891% I think the virtual system and per-call site default handlers are the only
    12992% "new" features, everything else is a matter of implementation.
    130 \item Creating tests and performance benchmarks to compare with EHM's in other languages.
    13193\end{enumerate}
    13294
    133 %\todo{I can't figure out a good lead-in to the roadmap.}
    134 The thesis is organization as follows.
    135 The next section and parts of \autoref{c:existing} cover existing EHMs.
    136 New \CFA EHM features are introduced in \autoref{c:features},
    137 covering their usage and design.
    138 That is followed by the implementation of these features in
     95\todo{I can't figure out a good lead-in to the roadmap.}
     96The next section covers the existing state of exceptions.
     97The existing state of \CFA is also covered in \autoref{c:existing}.
     98The new features are introduced in \autoref{c:features},
     99which explains their usage and design.
     100That is followed by the implementation of those features in
    139101\autoref{c:implement}.
    140 Performance results are presented in \autoref{c:performance}.
    141 Summing up and possibilities for extending this project are discussed in \autoref{c:future}.
     102The performance results are examined in \autoref{c:performance}.
     103Possibilities to extend this project are discussed in \autoref{c:future}.
    142104
    143105\section{Background}
    144106\label{s:background}
    145107
    146 Exception handling is a well examined area in programming languages,
    147 with papers on the subject dating back the 70s~\cite{Goodenough75}.
    148 Early exceptions were often treated as signals, which carried no information
    149 except their identity. Ada~\cite{Ada} still uses this system.
    150 
    151 The modern flag-ship for termination exceptions is \Cpp,
     108Exception handling is not a new concept,
     109with papers on the subject dating back 70s.
     110
     111Their were popularised by \Cpp,
    152112which added them in its first major wave of non-object-orientated features
    153113in 1990.
    154114% https://en.cppreference.com/w/cpp/language/history
    155 While many EHMs have special exception types,
    156 \Cpp has the ability to use any type as an exception.
    157 However, this generality is not particularly useful, and has been pushed aside for classes, with a convention of inheriting from
    158 \code{C++}{std::exception}.
    159 While \Cpp has a special catch-all syntax @catch(...)@, there is no way to discriminate its exception type, so nothing can
    160 be done with the caught value because nothing is known about it.
    161 Instead the base exception-type \code{C++}{std::exception} is defined with common functionality (such as
    162 the ability to print a message when the exception is raised but not caught) and all
    163 exceptions have this functionality.
    164 Having a root exception-type seems to be the standard now, as the guaranteed functionality is worth
    165 any lost in flexibility from limiting exceptions types to classes.
    166 
    167 Java~\cite{Java} was the next popular language to use exceptions.
    168 Its exception system largely reflects that of \Cpp, except it requires
    169 exceptions to be a subtype of \code{Java}{java.lang.Throwable}
    170 and it uses checked exceptions.
    171 Checked exceptions are part of a function's interface defining all exceptions it or its called functions raise.
    172 Using this information, it is possible to statically verify if a handler exists for all raised exception, \ie no uncaught exceptions.
    173 Making exception information explicit, improves clarity and
     115
     116Java was the next popular language to use exceptions. It is also the most
     117popular language with checked exceptions.
     118Checked exceptions are part of the function interface they are raised from.
     119This includes functions they propogate through, until a handler for that
     120type of exception is found.
     121This makes exception information explicit, which can improve clarity and
    174122safety, but can slow down programming.
    175 For example, programming complexity increases when dealing with high-order methods or an overly specified
    176 throws clause. However some of the issues are more
    177 programming annoyances, such as writing/updating many exception signatures after adding or remove calls.
    178 Java programmers have developed multiple programming ``hacks'' to circumvent checked exceptions negating the robustness it is suppose to provide.
    179 For example, the ``catch-and-ignore" pattern, where the handler is empty because the exception does not appear relevant to the programmer versus
    180 repairing or recovering from the exception.
    181 
    182 %\subsection
    183 Resumption exceptions are less popular,
    184 although resumption is as old as termination;
    185 hence, few
    186 programming languages have implemented them.
     123Some of these, such as dealing with high-order methods or an overly specified
     124throws clause, are technical. However some of the issues are much more
     125human, in that writing/updating all the exception signatures can be enough
     126of a burden people will hack the system to avoid them.
     127Including the ``catch-and-ignore" pattern where a catch block is used without
     128anything to repair or recover from the exception.
     129
     130%\subsection
     131Resumption exceptions have been much less popular.
     132Although resumption has a history as old as termination's, very few
     133programming languages have implement them.
    187134% http://bitsavers.informatik.uni-stuttgart.de/pdf/xerox/parc/techReports/
    188135%   CSL-79-3_Mesa_Language_Manual_Version_5.0.pdf
    189 Mesa~\cite{Mesa} is one programming languages that did. Experience with Mesa
    190 is quoted as being one of the reasons resumptions are not
     136Mesa is one programming languages that did and experiance with that
     137languages is quoted as being one of the reasons resumptions were not
    191138included in the \Cpp standard.
    192139% https://en.wikipedia.org/wiki/Exception_handling
    193 As a result, resumption has ignored in main-stream programming languages.
    194 However, ``what goes around comes around'' and resumption is being revisited now (like user-level threading).
    195 While rejecting resumption might have been the right decision in the past, there are decades
    196 of developments in computer science that have changed the situation.
    197 Some of these developments, such as functional programming's resumption
    198 equivalent, algebraic effects\cite{Zhang19}, are enjoying significant success.
    199 A complete reexamination of resumptions is beyond this thesis, but their re-emergence is
    200 enough to try them in \CFA.
    201 % Especially considering how much easier they are to implement than
    202 % termination exceptions.
    203 
    204 %\subsection
    205 Functional languages tend to use other solutions for their primary EHM,
    206 but exception-like constructs still appear.
    207 Termination appears in error construct, which marks the result of an
    208 expression as an error; thereafter, the result of any expression that tries to use it is also an
    209 error, and so on until an appropriate handler is reached.
    210 Resumption appears in algebraic effects, where a function dispatches its
    211 side-effects to its caller for handling.
    212 
    213 %\subsection
    214 Some programming languages have moved to a restricted kind of EHM
    215 called ``panic".
    216 In Rust~\cite{Rust}, a panic is just a program level abort that may be implemented by
    217 unwinding the stack like in termination exception handling.
     140\todo{A comment about why we did include them when they are so unpopular
     141might be approprate.}
     142
     143%\subsection
     144Functional languages, tend to use solutions like the return union, but some
     145exception-like constructs still appear.
     146
     147For instance Haskell's built in error mechanism can make the result of any
     148expression, including function calls. Any expression that examines an
     149error value will in-turn produce an error. This continues until the main
     150function produces an error or until it is handled by one of the catch
     151functions.
     152
     153%\subsection
     154More recently exceptions seem to be vanishing from newer programming
     155languages.
     156Rust and Go reduce this feature to panics.
     157Panicing is somewhere between a termination exception and a program abort.
     158Notably in Rust a panic can trigger either, a panic may unwind the stack or
     159simply kill the process.
    218160% https://doc.rust-lang.org/std/panic/fn.catch_unwind.html
    219 In Go~\cite{Go}, a panic is very similar to a termination, except it only supports
    220 a catch-all by calling \code{Go}{recover()}, simplifying the interface at
    221 the cost of flexibility.
    222 
    223 %\subsection
    224 While exception handling's most common use cases are in error handling,
    225 here are other ways to handle errors with comparisons to exceptions.
     161Go's panic is much more similar to a termination exception but there is
     162only a catch-all function with \code{Go}{recover()}.
     163So exceptions still are appearing, just in reduced forms.
     164
     165%\subsection
     166Exception handling's most common use cases are in error handling.
     167Here are some other ways to handle errors and comparisons with exceptions.
    226168\begin{itemize}
    227169\item\emph{Error Codes}:
    228 This pattern has a function return an enumeration (or just a set of fixed values) to indicate
    229 if an error occurred and possibly which error it was.
    230 
    231 Error codes mix exceptional and normal values, artificially enlarging the type and/or value range.
    232 Some languages address this issue by returning multiple values or a tuple, separating the error code from the function result.
    233 However, the main issue with error codes is forgetting to checking them,
    234 which leads to an error being quietly and implicitly ignored.
    235 Some new languages have tools that issue warnings, if the error code is
    236 discarded to avoid this problem.
    237 Checking error codes also results in bloating the main execution path, especially if an error is not dealt with locally and has to be cascaded down the call stack to a higher-level function..
    238 
     170This pattern uses an enumeration (or just a set of fixed values) to indicate
     171that an error has occured and which error it was.
     172
     173There are some issues if a function wants to return an error code and another
     174value. The main issue is that it can be easy to forget checking the error
     175code, which can lead to an error being quitely and implicitly ignored.
     176Some new languages have tools that raise warnings if the return value is
     177discarded to avoid this.
     178It also puts more code on the main execution path.
    239179\item\emph{Special Return with Global Store}:
    240 Some functions only return a boolean indicating success or failure
    241 and store the exact reason for the error in a fixed global location.
    242 For example, many C routines return non-zero or -1, indicating success or failure,
    243 and write error details into the C standard variable @errno@.
    244 
    245 This approach avoids the multiple results issue encountered with straight error codes
    246 but otherwise has many (if not more) of the disadvantages.
    247 For example, everything that uses the global location must agree on all possible errors and global variable are unsafe with concurrency.
    248 
     180A function that encounters an error returns some value indicating that it
     181encountered a value but store which error occured in a fixed global location.
     182
     183Perhaps the C standard @errno@ is the most famous example of this,
     184where some standard library functions will return some non-value (often a
     185NULL pointer) and set @errno@.
     186
     187This avoids the multiple results issue encountered with straight error codes
     188but otherwise many of the same advantages and disadvantages.
     189It does however introduce one other major disadvantage:
     190Everything that uses that global location must agree on all possible errors.
    249191\item\emph{Return Union}:
    250 This pattern replaces error codes with a tagged union.
     192Replaces error codes with a tagged union.
    251193Success is one tag and the errors are another.
    252194It is also possible to make each possible error its own tag and carry its own
     
    254196so that one type can be used everywhere in error handling code.
    255197
    256 This pattern is very popular in functional or any semi-functional language with
    257 primitive support for tagged unions (or algebraic data types).
     198This pattern is very popular in functional or semi-functional language,
     199anything with primitive support for tagged unions (or algebraic data types).
    258200% We need listing Rust/rust to format code snipits from it.
    259201% Rust's \code{rust}{Result<T, E>}
    260 The main advantage is providing for more information about an
    261 error, other than one of a fix-set of ids.
    262 While some languages use checked union access to force error-code checking,
    263 it is still possible to bypass the checking.
    264 The main disadvantage is again significant error code on the main execution path and cascading through called functions.
    265 
     202
     203The main disadvantage is again it puts code on the main execution path.
     204This is also the first technique that allows for more information about an
     205error, other than one of a fix-set of ids, to be sent.
     206They can be missed but some languages can force that they are checked.
     207It is also implicitly forced in any languages with checked union access.
    266208\item\emph{Handler Functions}:
    267 This pattern implicitly associates functions with errors.
    268 On error, the function that produced the error implicitly calls another function to
     209On error the function that produced the error calls another function to
    269210handle it.
    270211The handler function can be provided locally (passed in as an argument,
    271212either directly as as a field of a structure/object) or globally (a global
    272213variable).
    273 C++ uses this approach as its fallback system if exception handling fails, \eg
     214
     215C++ uses this as its fallback system if exception handling fails.
    274216\snake{std::terminate_handler} and for a time \snake{std::unexpected_handler}
    275217
    276 Handler functions work a lot like resumption exceptions, without the dynamic handler search.
    277 Therefore, setting setting up the handler can be more complex/expensive, especially if the handle must be passed through multiple function calls, but cheaper to call $O(1)$, and hence,
    278 are more suited to frequent exceptional situations.
    279 % The exception being global handlers if they are rarely change as the time
    280 % in both cases shrinks towards zero.
     218Handler functions work a lot like resumption exceptions.
     219The difference is they are more expencive to set up but cheaper to use, and
     220so are more suited to more fequent errors.
     221The exception being global handlers if they are rarely change as the time
     222in both cases strinks towards zero.
    281223\end{itemize}
    282224
    283225%\subsection
    284 Because of their cost, exceptions are rarely used for hot paths of execution.
    285 Therefore, there is an element of self-fulfilling prophecy for implementation
    286 techniques to make exceptions cheap to set-up at the cost
    287 of expensive usage.
    288 This cost differential is less important in higher-level scripting languages, where use of exceptions for other tasks is more common.
    289 An iconic example is Python's @StopIteration@ exception that is thrown by
    290 an iterator to indicate that it is exhausted, especially when combined with Python's heavy
    291 use of the iterator-based for-loop.
     226Because of their cost exceptions are rarely used for hot paths of execution.
     227There is an element of self-fulfilling prophocy here as implementation
     228techniques have been designed to make exceptions cheap to set-up at the cost
     229of making them expencive to use.
     230Still, use of exceptions for other tasks is more common in higher-level
     231scripting languages.
     232An iconic example is Python's StopIteration exception which is thrown by
     233an iterator to indicate that it is exausted. Combined with Python's heavy
     234use of the iterator based for-loop.
    292235% https://docs.python.org/3/library/exceptions.html#StopIteration
  • doc/theses/andrew_beach_MMath/performance.tex

    r5541ea3d r0640189e  
    11\chapter{Performance}
    22\label{c:performance}
     3
     4\textbf{Just because of the stage of testing there are design notes for
     5the tests as well as commentary on them.}
    36
    47Performance has been of secondary importance for most of this project.
     
    811
    912\section{Test Set-Up}
    10 Tests will be run in \CFA, C++, Java and Python.
    11 In addition there are two sets of tests for \CFA,
    12 one for termination exceptions and once with resumption exceptions.
     13Tests will be run on \CFA, C++ and Java.
    1314
    1415C++ is the most comparable language because both it and \CFA use the same
     
    1718comparison. \CFA's EHM has had significantly less time to be optimized and
    1819does not generate its own assembly. It does have a slight advantage in that
    19 there are some features it does not handle, through utility functions,
    20 but otherwise \Cpp has a significant advantage.
     20there are some features it does not handle.
    2121
    2222Java is another very popular language with similar termination semantics.
     
    2525It also implements the finally clause on try blocks allowing for a direct
    2626feature-to-feature comparison.
    27 As with \Cpp, Java's implementation is more mature, has more optimizations
    28 and more extra features.
    29 
    30 Python was used as a point of comparison because of the \CFA EHM's
    31 current performance goals, which is not be prohibitively slow while the
    32 features are designed and examined. Python has similar performance goals for
    33 creating quick scripts and its wide use suggests it has achieved those goals.
    34 
    35 Unfortunately there are no notable modern programming languages with
    36 resumption exceptions. Even the older programming languages with resumptions
    37 seem to be notable only for having resumptions.
    38 So instead resumptions are compared to a less similar but much more familiar
    39 feature, termination exceptions.
    4027
    4128All tests are run inside a main loop which will perform the test
    4229repeatedly. This is to avoids start-up or tear-down time from
    4330affecting the timing results.
    44 Most test were run 1 000 000 (a million) times.
    45 The Java versions of the test also run this loop an extra 1000 times before
    46 beginning to time the results to ``warm-up" the JVM.
    47 
    48 Timing is done internally, with time measured immediately before and
    49 immediately after the test loop. The difference is calculated and printed.
    50 
    51 The loop structure and internal timing means it is impossible to test
    52 unhandled exceptions in \Cpp and Java as that would cause the process to
    53 terminate.
    54 Luckily, performance on the ``give-up and kill the process" path is not
    55 critical.
     31A consequence of this is that tests cannot terminate the program,
     32which does limit how tests can be implemented.
     33There are catch-alls to keep unhandled
     34exceptions from terminating tests.
    5635
    5736The exceptions used in these tests will always be a exception based off of
    5837the base exception. This requirement minimizes performance differences based
    59 on the object model used to repersent the exception.
     38on the object model.
     39Catch-alls are done by catching the root exception type (not using \Cpp's
     40\code{C++}{catch(...)}).
    6041
    61 All tests were designed to be as minimal as possible while still preventing
    62 exessive optimizations.
    63 For example, empty inline assembly blocks are used in \CFA and \Cpp to
    64 prevent excessive optimizations while adding no actual work.
    65 
    66 % We don't use catch-alls but if we did:
    67 % Catch-alls are done by catching the root exception type (not using \Cpp's
    68 % \code{C++}{catch(...)}).
     42Tests run in Java were not warmed because exception code paths should not be
     43hot.
    6944
    7045\section{Tests}
     
    7247components of the exception system.
    7348The should provide a guide as to where the EHM's costs can be found.
     49
     50Tests are run in \CFA, \Cpp and Java.
     51Not every test is run in every language, if the feature under test is missing
     52the test is skipped. These cases will be noted.
     53In addition to the termination tests for every language,
     54\CFA has a second set of tests that test resumption. These are the same
     55except that the raise statements and handler clauses are replaced with the
     56resumption variants.
    7457
    7558\paragraph{Raise and Handle}
     
    7962start-up and shutdown on the results.
    8063Each iteration of the main loop
    81 \begin{itemize}[nosep]
     64\begin{itemize}
    8265\item Empty Function:
    8366The repeating function is empty except for the necessary control code.
     
    8568The repeating function creates an object with a destructor before calling
    8669itself.
     70(Java is skipped as it does not destructors.)
    8771\item Finally:
    8872The repeating function calls itself inside a try block with a finally clause
    8973attached.
     74(\Cpp is skipped as it does not have finally clauses.)
    9075\item Other Handler:
    9176The repeating function calls itself inside a try block with a handler that
     
    9984In each iteration, a try statement is executed. Entering and leaving a loop
    10085is all the test wants to do.
    101 \begin{itemize}[nosep]
     86\begin{itemize}
    10287\item Handler:
    10388The try statement has a handler (of the matching kind).
     
    11095Only \CFA implements the language level conditional match,
    11196the other languages must mimic with an ``unconditional" match (it still
    112 checks the exception's type) and conditional re-raise if it was not supposed
    113 to handle that exception.
    114 \begin{itemize}[nosep]
    115 \item Match All:
     97checks the exception's type) and conditional re-raise.
     98\begin{itemize}
     99\item Catch All:
    116100The condition is always true. (Always matches or never re-raises.)
    117 \item Match None:
     101\item Catch None:
    118102The condition is always false. (Never matches or always re-raises.)
    119103\end{itemize}
     
    129113%related to -fexceptions.)
    130114
    131 \section{Results}
    132 Each test is was run five times, the best and worst result were discarded and
    133 the remaining values were averaged.
     115% Some languages I left out:
     116% Python: Its a scripting language, different
     117% uC++: Not well known and should the same results as C++, except for
     118%   resumption which should be the same.
    134119
    135 In cases where a feature is not supported by a language the test is skipped
    136 for that language. Similarly, if a test is does not change between resumption
    137 and termination in \CFA, then only one test is written and the result
    138 was put into the termination column.
    139 
    140 \begin{tabular}{|l|c c c c c|}
    141 \hline
    142               & \CFA (Terminate) & \CFA (Resume) & \Cpp & Java & Python \\
    143 \hline
    144 Raise Empty   & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 \\
    145 Raise D'tor   & 0.0 & 0.0 & 0.0 & N/A & N/A \\
    146 Raise Finally & 0.0 & 0.0 & N/A & 0.0 & 0.0 \\
    147 Raise Other   & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 \\
    148 Cross Handler & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 \\
    149 Cross Finally & 0.0 & N/A & N/A & 0.0 & 0.0 \\
    150 Match All     & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 \\
    151 Match None    & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 \\
    152 \hline
    153 \end{tabular}
     120%\section{Resumption Comparison}
     121\todo{Can we find a good language to compare resumptions in.}
  • doc/theses/andrew_beach_MMath/uw-ethesis.tex

    r5541ea3d r0640189e  
    210210\lstMakeShortInline@
    211211\lstset{language=CFA,style=cfacommon,basicstyle=\linespread{0.9}\tt}
    212 % PAB causes problems with inline @=
    213 %\lstset{moredelim=**[is][\protect\color{red}]{@}{@}}
     212\lstset{moredelim=**[is][\protect\color{red}]{@}{@}}
    214213% Annotations from Peter:
    215214\newcommand{\PAB}[1]{{\color{blue}PAB: #1}}
  • doc/theses/mubeen_zulfiqar_MMath/allocator.tex

    r5541ea3d r0640189e  
    111111%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    112112
    113 \section{Added Features and Methods}
    114 To improve the UHeapLmmm allocator (FIX ME: cite uHeapLmmm) interface and make it more user friendly, we added a few more routines to the C allocator. Also, we built a CFA (FIX ME: cite cforall) interface on top of C interface to increase the usability of the allocator.
     113\section{Added Features}
    115114
    116 \subsection{C Interface}
    117 We added a few more features and routines to the allocator's C interface that can make the allocator more usable to the programmers. THese features will programmer more control on the dynamic memory allocation.
    118115
    119 \subsubsection void * aalloc( size_t dim, size_t elemSize )
    120 aalloc is an extension of malloc. It allows programmer to allocate a dynamic array of objects without calculating the total size of array explicitly. The only alternate of this routine in the other allocators is calloc but calloc also fills the dynamic memory with 0 which makes it slower for a programmer who only wants to dynamically allocate an array of objects without filling it with 0.
    121 \paragraph{Usage}
    122 aalloc takes two parameters.
    123 \begin{itemize}
    124 \item
    125 dim: number of objects in the array
    126 \item
    127 elemSize: size of the object in the array.
    128 \end{itemize}
    129 It returns address of dynamic object allocatoed on heap that can contain dim number of objects of the size elemSize. On failure, it returns NULL pointer.
     116\subsection{Methods}
     117Why did we need it?
     118The added benefits.
    130119
    131 \subsubsection void * resize( void * oaddr, size_t size )
    132 resize is an extension of relloc. It allows programmer to reuse a cuurently allocated dynamic object with a new size requirement. Its alternate in the other allocators is realloc but relloc also copy the data in old object to the new object which makes it slower for the programmer who only wants to reuse an old dynamic object for a new size requirement but does not want to preserve the data in the old object to the new object.
    133 \paragraph{Usage}
    134 resize takes two parameters.
    135 \begin{itemize}
    136 \item
    137 oaddr: the address of the old object that needs to be resized.
    138 \item
    139 size: the new size requirement of the to which the old object needs to be resized.
    140 \end{itemize}
    141 It returns an object that is of the size given but it does not preserve the data in the old object. On failure, it returns NULL pointer.
    142 
    143 \subsubsection void * resize( void * oaddr, size_t nalign, size_t size )
    144 This resize is an extension of the above resize (FIX ME: cite above resize). In addition to resizing the size of of an old object, it can also realign the old object to a new alignment requirement.
    145 \paragraph{Usage}
    146 This resize takes three parameters. It takes an additional parameter of nalign as compared to the above resize (FIX ME: cite above resize).
    147 \begin{itemize}
    148 \item
    149 oaddr: the address of the old object that needs to be resized.
    150 \item
    151 nalign: the new alignment to which the old object needs to be realigned.
    152 \item
    153 size: the new size requirement of the to which the old object needs to be resized.
    154 \end{itemize}
    155 It returns an object with the size and alignment given in the parameters. On failure, it returns a NULL pointer.
    156 
    157 \subsubsection void * amemalign( size_t alignment, size_t dim, size_t elemSize )
    158 amemalign is a hybrid of memalign and aalloc. It allows programmer to allocate an aligned dynamic array of objects without calculating the total size of the array explicitly. It frees the programmer from calculating the total size of the array.
    159 \paragraph{Usage}
    160 amemalign takes three parameters.
    161 \begin{itemize}
    162 \item
    163 alignment: the alignment to which the dynamic array needs to be aligned.
    164 \item
    165 dim: number of objects in the array
    166 \item
    167 elemSize: size of the object in the array.
    168 \end{itemize}
    169 It returns a dynamic array of objects that has the capacity to contain dim number of objects of the size of elemSize. The returned dynamic array is aligned to the given alignment. On failure, it returns NULL pointer.
    170 
    171 \subsubsection void * cmemalign( size_t alignment, size_t dim, size_t elemSize )
    172 cmemalign is a hybrid of amemalign and calloc. It allows programmer to allocate an aligned dynamic array of objects that is 0 filled. The current way to do this in other allocators is to allocate an aligned object with memalign and then fill it with 0 explicitly. This routine provides both features of aligning and 0 filling, implicitly.
    173 \paragraph{Usage}
    174 cmemalign takes three parameters.
    175 \begin{itemize}
    176 \item
    177 alignment: the alignment to which the dynamic array needs to be aligned.
    178 \item
    179 dim: number of objects in the array
    180 \item
    181 elemSize: size of the object in the array.
    182 \end{itemize}
    183 It returns a dynamic array of objects that has the capacity to contain dim number of objects of the size of elemSize. The returned dynamic array is aligned to the given alignment and is 0 filled. On failure, it returns NULL pointer.
    184 
    185 \subsubsection size_t malloc_alignment( void * addr )
    186 malloc_alignment returns the alignment of a currently allocated dynamic object. It allows the programmer in memory management and personal bookkeeping. It helps the programmer in verofying the alignment of a dynamic object especially in a scenerio similar to prudcer-consumer where a producer allocates a dynamic object and the consumer needs to assure that the dynamic object was allocated with the required alignment.
    187 \paragraph{Usage}
    188 malloc_alignment takes one parameters.
    189 \begin{itemize}
    190 \item
    191 addr: the address of the currently allocated dynamic object.
    192 \end{itemize}
    193 malloc_alignment returns the alignment of the given dynamic object. On failure, it return the value of default alignment of the uHeapLmmm allocator.
    194 
    195 \subsubsection bool malloc_zero_fill( void * addr )
    196 malloc_zero_fill returns whether a currently allocated dynamic object was initially zero filled at the time of allocation. It allows the programmer in memory management and personal bookkeeping. It helps the programmer in verifying the zero filled property of a dynamic object especially in a scenerio similar to prudcer-consumer where a producer allocates a dynamic object and the consumer needs to assure that the dynamic object was zero filled at the time of allocation.
    197 \paragraph{Usage}
    198 malloc_zero_fill takes one parameters.
    199 \begin{itemize}
    200 \item
    201 addr: the address of the currently allocated dynamic object.
    202 \end{itemize}
    203 malloc_zero_fill returns true if the dynamic object was initially zero filled and return false otherwise. On failure, it returns false.
    204 
    205 \subsubsection size_t malloc_size( void * addr )
    206 malloc_size returns the allocation size of a currently allocated dynamic object. It allows the programmer in memory management and personal bookkeeping. It helps the programmer in verofying the alignment of a dynamic object especially in a scenerio similar to prudcer-consumer where a producer allocates a dynamic object and the consumer needs to assure that the dynamic object was allocated with the required size. Its current alternate in the other allocators is malloc_usable_size. But, malloc_size is different from malloc_usable_size as malloc_usabe_size returns the total data capacity of dynamic object including the extra space at the end of the dynamic object. On the other hand, malloc_size returns the size that was given to the allocator at the allocation of the dynamic object. This size is updated when an object is realloced, resized, or passed through a similar allocator routine.
    207 \paragraph{Usage}
    208 malloc_size takes one parameters.
    209 \begin{itemize}
    210 \item
    211 addr: the address of the currently allocated dynamic object.
    212 \end{itemize}
    213 malloc_size returns the allocation size of the given dynamic object. On failure, it return zero.
    214 
    215 \subsubsection void * realloc( void * oaddr, size_t nalign, size_t size )
    216 This realloc is an extension of the default realloc (FIX ME: cite default realloc). In addition to reallocating an old object and preserving the data in old object, it can also realign the old object to a new alignment requirement.
    217 \paragraph{Usage}
    218 This realloc takes three parameters. It takes an additional parameter of nalign as compared to the default realloc.
    219 \begin{itemize}
    220 \item
    221 oaddr: the address of the old object that needs to be reallocated.
    222 \item
    223 nalign: the new alignment to which the old object needs to be realigned.
    224 \item
    225 size: the new size requirement of the to which the old object needs to be resized.
    226 \end{itemize}
    227 It returns an object with the size and alignment given in the parameters that preserves the data in the old object. On failure, it returns a NULL pointer.
    228 
    229 \subsection{CFA Malloc Interface}
    230 We added some routines to the malloc interface of CFA. These routines can only be used in CFA and not in our standalone uHeapLmmm allocator as these routines use some features that are only provided by CFA and not by C. It makes the allocator even more usable to the programmers.
    231 CFA provides the liberty to know the returned type of a call to the allocator. So, mainly in these added routines, we removed the object size parameter from the routine as allocator can calculate the size of the object from the returned type.
    232 
    233 \subsubsection T * malloc( void )
    234 This malloc is a simplified polymorphic form of defualt malloc (FIX ME: cite malloc). It does not take any parameter as compared to default malloc that takes one parameter.
    235 \paragraph{Usage}
    236 This malloc takes no parameters.
    237 It returns a dynamic object of the size of type T. On failure, it return NULL pointer.
    238 
    239 \subsubsection T * aalloc( size_t dim )
    240 This aalloc is a simplified polymorphic form of above aalloc (FIX ME: cite aalloc). It takes one parameter as compared to the above aalloc that takes two parameters.
    241 \paragraph{Usage}
    242 aalloc takes one parameters.
    243 \begin{itemize}
    244 \item
    245 dim: required number of objects in the array.
    246 \end{itemize}
    247 It returns a dynamic object that has the capacity to contain dim number of objects, each of the size of type T. On failure, it return NULL pointer.
    248 
    249 \subsubsection T * calloc( size_t dim )
    250 This calloc is a simplified polymorphic form of defualt calloc (FIX ME: cite calloc). It takes one parameter as compared to the default calloc that takes two parameters.
    251 \paragraph{Usage}
    252 This calloc takes one parameter.
    253 \begin{itemize}
    254 \item
    255 dim: required number of objects in the array.
    256 \end{itemize}
    257 It returns a dynamic object that has the capacity to contain dim number of objects, each of the size of type T. On failure, it return NULL pointer.
    258 
    259 \subsubsection T * resize( T * ptr, size_t size )
    260 This resize is a simplified polymorphic form of above resize (FIX ME: cite resize with alignment). It takes two parameters as compared to the above resize that takes three parameters. It frees the programmer from explicitly mentioning the alignment of the allocation as CFA provides gives allocator the liberty to get the alignment of the returned type.
    261 \paragraph{Usage}
    262 This resize takes two parameters.
    263 \begin{itemize}
    264 \item
    265 ptr: address of the old object.
    266 \item
    267 size: the required size of the new object.
    268 \end{itemize}
    269 It returns a dynamic object of the size given in paramters. The returned object is aligned to the alignemtn of type T. On failure, it return NULL pointer.
    270 
    271 \subsubsection T * realloc( T * ptr, size_t size )
    272 This realloc is a simplified polymorphic form of defualt realloc (FIX ME: cite realloc with align). It takes two parameters as compared to the above realloc that takes three parameters. It frees the programmer from explicitly mentioning the alignment of the allocation as CFA provides gives allocator the liberty to get the alignment of the returned type.
    273 \paragraph{Usage}
    274 This realloc takes two parameters.
    275 \begin{itemize}
    276 \item
    277 ptr: address of the old object.
    278 \item
    279 size: the required size of the new object.
    280 \end{itemize}
    281 It returns a dynamic object of the size given in paramters that preserves the data in the given object. The returned object is aligned to the alignemtn of type T. On failure, it return NULL pointer.
    282 
    283 \subsubsection T * memalign( size_t align )
    284 This memalign is a simplified polymorphic form of defualt memalign (FIX ME: cite memalign). It takes one parameters as compared to the default memalign that takes two parameters.
    285 \paragraph{Usage}
    286 memalign takes one parameters.
    287 \begin{itemize}
    288 \item
    289 align: the required alignment of the dynamic object.
    290 \end{itemize}
    291 It returns a dynamic object of the size of type T that is aligned to given parameter align. On failure, it return NULL pointer.
    292 
    293 \subsubsection T * amemalign( size_t align, size_t dim )
    294 This amemalign is a simplified polymorphic form of above amemalign (FIX ME: cite amemalign). It takes two parameter as compared to the above amemalign that takes three parameters.
    295 \paragraph{Usage}
    296 amemalign takes two parameters.
    297 \begin{itemize}
    298 \item
    299 align: required alignment of the dynamic array.
    300 \item
    301 dim: required number of objects in the array.
    302 \end{itemize}
    303 It returns a dynamic object that has the capacity to contain dim number of objects, each of the size of type T. The returned object is aligned to the given parameter align. On failure, it return NULL pointer.
    304 
    305 \subsubsection T * cmemalign( size_t align, size_t dim  )
    306 This cmemalign is a simplified polymorphic form of above cmemalign (FIX ME: cite cmemalign). It takes two parameter as compared to the above cmemalign that takes three parameters.
    307 \paragraph{Usage}
    308 cmemalign takes two parameters.
    309 \begin{itemize}
    310 \item
    311 align: required alignment of the dynamic array.
    312 \item
    313 dim: required number of objects in the array.
    314 \end{itemize}
    315 It returns a dynamic object that has the capacity to contain dim number of objects, each of the size of type T. The returned object is aligned to the given parameter align and is zero filled. On failure, it return NULL pointer.
    316 
    317 \subsubsection T * aligned_alloc( size_t align )
    318 This aligned_alloc is a simplified polymorphic form of defualt aligned_alloc (FIX ME: cite aligned_alloc). It takes one parameter as compared to the default aligned_alloc that takes two parameters.
    319 \paragraph{Usage}
    320 This aligned_alloc takes one parameter.
    321 \begin{itemize}
    322 \item
    323 align: required alignment of the dynamic object.
    324 \end{itemize}
    325 It returns a dynamic object of the size of type T that is aligned to the given parameter. On failure, it return NULL pointer.
    326 
    327 \subsubsection int posix_memalign( T ** ptr, size_t align )
    328 This posix_memalign is a simplified polymorphic form of defualt posix_memalign (FIX ME: cite posix_memalign). It takes two parameters as compared to the default posix_memalign that takes three parameters.
    329 \paragraph{Usage}
    330 This posix_memalign takes two parameter.
    331 \begin{itemize}
    332 \item
    333 ptr: variable address to store the address of the allocated object.
    334 \item
    335 align: required alignment of the dynamic object.
    336 \end{itemize}
    337 It stores address of the dynamic object of the size of type T in given parameter ptr. This object is aligned to the given parameter. On failure, it return NULL pointer.
    338 
    339 \subsubsection T * valloc( void )
    340 This valloc is a simplified polymorphic form of defualt valloc (FIX ME: cite valloc). It takes no parameters as compared to the default valloc that takes one parameter.
    341 \paragraph{Usage}
    342 valloc takes no parameters.
    343 It returns a dynamic object of the size of type T that is aligned to the page size. On failure, it return NULL pointer.
    344 
    345 \subsubsection T * pvalloc( void )
    346 This pcvalloc is a simplified polymorphic form of defualt pcvalloc (FIX ME: cite pcvalloc). It takes no parameters as compared to the default pcvalloc that takes one parameter.
    347 \paragraph{Usage}
    348 pvalloc takes no parameters.
    349 It returns a dynamic object of the size that is calcutaed by rouding the size of type T. The returned object is also aligned to the page size. On failure, it return NULL pointer.
    350120
    351121\subsection{Alloc Interface}
    352 In addition to improve allocator interface both for CFA and our standalone allocator uHeapLmmm in C. We also added a new alloc interface in CFA that increases usability of dynamic memory allocation.
    353 This interface helps programmers in three major ways.
    354 \begin{itemize}
    355 \item
    356 Routine Name: alloc interfce frees programmers from remmebring different routine names for different kind of dynamic allocations.
    357 \item
    358 Parametre Positions: alloc interface frees programmers from remembering parameter postions in call to routines.
    359 \item
    360 Object Size: alloc interface does not require programmer to mention the object size as CFA allows allocator to determince the object size from returned type of alloc call.
    361 \end{itemize}
    362 
    363 Alloc interface uses polymorphism, backtick routines (FIX ME: cite backtick) and ttype parameters of CFA (FIX ME: cite ttype) to provide a very simple dynamic memory allocation interface to the programmers. The new interfece has just one routine name alloc that can be used to perform a wide range of dynamic allocations. The parameters use backtick functions to provide a similar-to named parameters feature for our alloc interface so that programmers do not have to remember parameter positions in alloc call except the position of dimension (dim) parameter.
    364 
    365 \subsubsection{Routine: T * alloc( ... )}
    366 Call to alloc wihout any parameter returns one object of size of type T allocated dynamically.
    367 Only the dimension (dim) parameter for array allocation has the fixed position in the alloc routine. If programmer wants to allocate an array of objects that the required number of members in the array has to be given as the first parameter to the alloc routine.
    368 alocc routine accepts six kinds of arguments. Using different combinations of tha parameters, different kind of allocations can be performed. Any combincation of parameters can be used together except `realloc and `resize that should not be used simultanously in one call to routine as it creates ambiguity about whether to reallocate or resize a currently allocated dynamic object. If both `resize and `realloc are used in a call to alloc then the latter one will take effect or unexpected resulted might be produced.
    369 
    370 \paragraph{Dim}
    371 This is the only parameter in the alloc routine that has a fixed-position and it is also the only parameter that does not use a backtick function. It has to be passed at the first position to alloc call in-case of an array allocation of objects of type T.
    372 It represents the required number of members in the array allocation as in CFA's aalloc (FIX ME: cite aalloc).
    373 This parameter should be of type size_t.
    374 
    375 Example: int a = alloc( 5 )
    376 This call will return a dynamic array of five integers.
    377 
    378 \paragraph{Align}
    379 This parameter is position-free and uses a backtick routine align (`align). The parameter passed with `align should be of type size_t. If the alignment parameter is not a power of two or is less than the default alignment of the allocator (that can be found out using routine libAlign in CFA) then the passed alignment parameter will be rejected and the default alignment will be used.
    380 
    381 Example: int b = alloc( 5 , 64`align )
    382 This call will return a dynamic array of five integers. It will align the allocated object to 64.
    383 
    384 \paragraph{Fill}
    385 This parameter is position-free and uses a backtick routine fill (`fill). In case of realloc, only the extra space after copying the data in the old object will be filled with given parameter.
    386 Three types of parameters can be passed using `fill.
    387 \begin{itemize}
    388 \item
    389 char: A char can be passed with `fill to fill the whole dynamic allocation with the given char recursively till the end of required allocation.
    390 \item
    391 Object of returned type: An object of type of returned type can be passed with `fill to fill the whole dynamic allocation with the given object recursively till the end of required allocation.
    392 \item
    393 Dynamic object of returned type: A dynamic object of type of returned type can be passed with `fill to fill the dynamic allocation with the given dynamic object. In this case, the allocated memory is not filled recursively till the end of allocation. The filling happen untill the end object passed to `fill or the end of requested allocation reaches.
    394 \end{itemize}
    395 
    396 Example: int b = alloc( 5 , 'a'`fill )
    397 This call will return a dynamic array of five integers. It will fill the allocated object with character 'a' recursively till the end of requested allocation size.
    398 
    399 Example: int b = alloc( 5 , 4`fill )
    400 This call will return a dynamic array of five integers. It will fill the allocated object with integer 4 recursively till the end of requested allocation size.
    401 
    402 Example: int b = alloc( 5 , a`fill ) where a is a pointer of int type
    403 This call will return a dynamic array of five integers. It will copy data in a to the returned object non-recursively untill end of a or the newly allocated object is reached.
    404 
    405 \paragraph{Resize}
    406 This parameter is position-free and uses a backtick routine resize (`resize). It represents the old dynamic object (oaddr) that the programmer wants to
    407 \begin{itemize}
    408 \item
    409 resize to a new size.
    410 \item
    411 realign to a new alignment
    412 \item
    413 fill with something.
    414 \end{itemize}
    415 The data in old dynamic object will not be preserved in the new object. The type of object passed to `resize and the returned type of alloc call can be different.
    416 
    417 Example: int b = alloc( 5 , a`resize )
    418 This call will resize object a to a dynamic array that can contain 5 integers.
    419 
    420 Example: int b = alloc( 5 , a`resize , 32`align )
    421 This call will resize object a to a dynamic array that can contain 5 integers. The returned object will also be aligned to 32.
    422 
    423 Example: int b = alloc( 5 , a`resize , 32`align , 2`fill)
    424 This call will resize object a to a dynamic array that can contain 5 integers. The returned object will also be aligned to 32 and will be filled with 2.
    425 
    426 \paragraph{Realloc}
    427 This parameter is position-free and uses a backtick routine realloc (`realloc). It represents the old dynamic object (oaddr) that the programmer wants to
    428 \begin{itemize}
    429 \item
    430 realloc to a new size.
    431 \item
    432 realign to a new alignment
    433 \item
    434 fill with something.
    435 \end{itemize}
    436 The data in old dynamic object will be preserved in the new object. The type of object passed to `realloc and the returned type of alloc call cannot be different.
    437 
    438 Example: int b = alloc( 5 , a`realloc )
    439 This call will realloc object a to a dynamic array that can contain 5 integers.
    440 
    441 Example: int b = alloc( 5 , a`realloc , 32`align )
    442 This call will realloc object a to a dynamic array that can contain 5 integers. The returned object will also be aligned to 32.
    443 
    444 Example: int b = alloc( 5 , a`realloc , 32`align , 2`fill)
    445 This call will resize object a to a dynamic array that can contain 5 integers. The returned object will also be aligned to 32. The extra space after copying data of a to the returned object will be filled with 2.
     122Why did we need it?
     123The added benefits.
  • doc/theses/mubeen_zulfiqar_MMath/benchmarks.tex

    r5541ea3d r0640189e  
    149149*** FIX ME: Insert a figure of above benchmark with description
    150150
    151 \paragrpah{Relevant Knobs}
     151\subsubsection{Relevant Knobs}
    152152*** FIX ME: Insert Relevant Knobs
    153153
     
    202202\paragraph{Relevant Knobs}
    203203*** FIX ME: Insert Relevant Knobs
     204
     205\section{Results}
     206*** FIX ME: add configuration details of memory allocators
     207
     208\subsection{Memory Benchmark}
     209
     210\subsubsection{Relevant Knobs}
     211
     212\subsection{Speed Benchmark}
     213
     214\subsubsection{Speed Time}
     215
     216\paragraph{Relevant Knobs}
     217
     218\subsubsection{Speed Workload}
     219
     220\paragraph{Relevant Knobs}
     221
     222\subsection{Cache Scratch}
     223
     224\subsubsection{Cache Scratch Time}
     225
     226\paragraph{Relevant Knobs}
     227
     228\subsubsection{Cache Scratch Layout}
     229
     230\paragraph{Relevant Knobs}
     231
     232\subsection{Cache Thrash}
     233
     234\subsubsection{Cache Thrash Time}
     235
     236\paragraph{Relevant Knobs}
     237
     238\subsubsection{Cache Thrash Layout}
     239
     240\paragraph{Relevant Knobs}
  • doc/theses/mubeen_zulfiqar_MMath/intro.tex

    r5541ea3d r0640189e  
    2424\noindent
    2525====================
    26 
    27 \section{Introduction}
    28 Dynamic memory allocation and management is one of the core features of C. It gives programmer the freedom to allocate, free, use, and manage dynamic memory himself. The programmer is not given the complete control of the dynamic memory management instead an interface of memory allocator is given to the progrmmer that can be used to allocate/free dynamic memory for the application's use.
    29 
    30 Memory allocator is a layer between thr programmer and the system. Allocator gets dynamic memory from the system in heap/mmap area of application storage and manages it for programmer's use.
    31 
    32 GNU C Library (FIX ME: cite this) provides an interchangeable memory allocator that can be replaced with a custom memory allocator that supports required features and fulfills application's custom needs. It also allows others to innovate in memory allocation and design their own memory allocator. GNU C Library has set guidelines that should be followed when designing a standalone memory allocator. GNU C Library requires new memory allocators to have atlease following set of functions in their allocator's interface:
    33 
    34 \begin{itemize}
    35 \item
    36 malloc: it allocates and returns a chunk of dynamic memory of requested size (FIX ME: cite man page).
    37 \item
    38 calloc: it allocates and returns an array in dynamic memory of requested size (FIX ME: cite man page).
    39 \item
    40 realloc: it reallocates and returns an already allocated chunk of dynamic memory to a new size (FIX ME: cite man page).
    41 \item
    42 free: it frees an already allocated piece of dynamic memory (FIX ME: cite man page).
    43 \end{itemize}
    44 
    45 In addition to the above functions, GNU C Library also provides some more functions to increase the usability of the dynamic memory allocator. Most standalone allocators also provide all or some of the above additional functions.
    46 
    47 \begin{itemize}
    48 \item
    49 aligned_alloc
    50 \item
    51 malloc_usable_size
    52 \item
    53 memalign
    54 \item
    55 posix_memalign
    56 \item
    57 pvalloc
    58 \item
    59 valloc
    60 \end{itemize}
    61 
    62 With the rise of concurrent applications, memory allocators should be able to fulfill dynamic memory requests from multiple threads in parallel without causing contention on shared resources. There needs to be a set of a standard benchmarks that can be used to evaluate an allocator's performance in different scenerios.
    63 
    64 \section{Background}
    65 
    66 \subsection{Memory Allocation}
    67 With dynamic allocation being an important feature of C, there are many standalone memory allocators that have been designed for different purposes. For this thesis, we chose 7 of the most popular and widely used memory allocators.
    68 
    69 \paragraph{dlmalloc}
    70 dlmalloc (FIX ME: cite allocator) is a thread-safe allocator that is single threaded and single heap. dlmalloc maintains free-lists of different sizes to store freed dynamic memory. (FIX ME: cite wasik)
    71 
    72 \paragraph{hoard}
    73 Hoard (FIX ME: cite allocator) is a thread-safe allocator that is multi-threaded and using a heap layer framework. It has per-thred heaps that have thread-local free-lists, and a gloabl shared heap. (FIX ME: cite wasik)
    74 
    75 \paragraph{jemalloc}
    76 jemalloc (FIX ME: cite allocator) is a thread-safe allocator that uses multiple arenas. Each thread is assigned an arena. Each arena has chunks that contain contagious memory regions of same size. An arena has multiple chunks that contain regions of multiple sizes.
    77 
    78 \paragraph{ptmalloc}
    79 ptmalloc (FIX ME: cite allocator) is a modification of dlmalloc. It is a thread-safe multi-threaded memory allocator that uses multiple heaps. ptmalloc heap has similar design to dlmalloc's heap.
    80 
    81 \paragraph{rpmalloc}
    82 rpmalloc (FIX ME: cite allocator) is a thread-safe allocator that is multi-threaded and uses per-thread heap. Each heap has multiple size-classes and each size-calss contains memory regions of the relevant size.
    83 
    84 \paragraph{tbb malloc}
    85 tbb malloc (FIX ME: cite allocator) is a thread-safe allocator that is multi-threaded and uses private heap for each thread. Each private-heap has multiple bins of different sizes. Each bin contains free regions of the same size.
    86 
    87 \paragraph{tc malloc}
    88 tcmalloc (FIX ME: cite allocator) is a thread-safe allocator. It uses per-thread cache to store free objects that prevents contention on shared resources in multi-threaded application. A central free-list is used to refill per-thread cache when it gets empty.
    89 
    90 \subsection{Benchmarks}
    91 There are multiple benchmarks that are built individually and evaluate different aspects of a memory allocator. But, there is not standard set of benchamrks that can be used to evaluate multiple aspects of memory allocators.
    92 
    93 \paragraph{threadtest}
    94 (FIX ME: cite benchmark and hoard) Each thread repeatedly allocates and then deallocates 100,000 objects. Runtime of the benchmark evaluates its efficiency.
    95 
    96 \paragraph{shbench}
    97 (FIX ME: cite benchmark and hoard) Each thread allocates and randomly frees a number of random-sized objects. It is a stress test that also uses runtime to determine efficiency of the allocator.
    98 
    99 \paragraph{larson}
    100 (FIX ME: cite benchmark and hoard) Larson simulates a server environment. Multiple threads are created where each thread allocator and free a number of objects within a size range. Some objects are passed from threads to the child threads to free. It caluculates memory operations per second as an indicator of memory allocator's performance.
    101 
    102 \section{Research Objectives}
    103 Our research objective in this thesis is to:
    104 
    105 \begin{itemize}
    106 \item
    107 Design a lightweight concurrent memory allocator with added features and usability that are currently not present in the other memory allocators.
    108 \item
    109 Design a suite of benchmarks to evalute multiple aspects of a memory allocator.
    110 \end{itemize}
    111 
    112 \section{An outline of the thesis}
    113 LAST FIX ME: add outline at the end
  • doc/theses/mubeen_zulfiqar_MMath/performance.tex

    r5541ea3d r0640189e  
    11\chapter{Performance}
    2 
    3 \noindent
    4 ====================
    5 
    6 Writing Points:
    7 \begin{itemize}
    8 \item
    9 Machine Specification
    10 \item
    11 Allocators and their details
    12 \item
    13 Benchmarks and their details
    14 \item
    15 Results
    16 \end{itemize}
    17 
    18 \noindent
    19 ====================
    20 
    21 \section{Memory Allocators}
    22 For these experiments, we used 7 memory allocators excluding our standalone memory allocator uHeapLmmm.
    23 
    24 \begin{tabularx}{0.8\textwidth} {
    25         | >{\raggedright\arraybackslash}X
    26         | >{\centering\arraybackslash}X
    27         | >{\raggedleft\arraybackslash}X |
    28 }
    29 \hline
    30 Memory Allocator & Version     & Configurations \\
    31 \hline
    32 dl               &             &  \\
    33 \hline
    34 hoard            &             &  \\
    35 \hline
    36 je               &             &  \\
    37 \hline
    38 pt3              &             &  \\
    39 \hline
    40 rp               &             &  \\
    41 \hline
    42 tbb              &             &  \\
    43 \hline
    44 tc               &             &  \\
    45 \end{tabularx}
    46 (FIX ME: complete table)
    47 
    48 \section{Experiment Environment}
    49 We conducted these experiments ... (FIX ME: what machine and which specifications to add).
    50 
    51 We used our micro becnhmark suite (FIX ME: cite mbench) to evaluate other memory allocators (FIX ME: cite above memory allocators) and our uHeapLmmm.
    52 
    53 \section{Results}
    54 
    55 \subsection{Memory Benchmark}
    56 FIX ME: add experiment, knobs, graphs, and description
    57 
    58 \subsection{Speed Benchmark}
    59 FIX ME: add experiment, knobs, graphs, and description
    60 
    61 \subsubsection{Speed Time}
    62 FIX ME: add experiment, knobs, graphs, and description
    63 
    64 \subsubsection{Speed Workload}
    65 FIX ME: add experiment, knobs, graphs, and description
    66 
    67 \subsection{Cache Scratch}
    68 FIX ME: add experiment, knobs, graphs, and description
    69 
    70 \subsubsection{Cache Scratch Time}
    71 FIX ME: add experiment, knobs, graphs, and description
    72 
    73 \subsubsection{Cache Scratch Layout}
    74 FIX ME: add experiment, knobs, graphs, and description
    75 
    76 \subsection{Cache Thrash}
    77 FIX ME: add experiment, knobs, graphs, and description
    78 
    79 \subsubsection{Cache Thrash Time}
    80 FIX ME: add experiment, knobs, graphs, and description
    81 
    82 \subsubsection{Cache Thrash Layout}
    83 FIX ME: add experiment, knobs, graphs, and description
  • driver/cc1.cc

    r5541ea3d r0640189e  
    1010// Created On       : Fri Aug 26 14:23:51 2005
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Jul 21 09:46:24 2021
    13 // Update Count     : 419
     12// Last Modified On : Wed Jul 14 15:42:08 2021
     13// Update Count     : 418
    1414//
    1515
     
    587587                Stage2( argc, argv );
    588588        } else {
    589                 cerr << "Usage: " << argv[0] << " [-E input-file [output-file] ] | [-fpreprocessed input-file output-file] [options]" << endl;
     589                cerr << "Usage: " << argv[0] << " input-file [output-file] [options]" << endl;
    590590                exit( EXIT_FAILURE );
    591591        } // if
  • libcfa/prelude/builtins.c

    r5541ea3d r0640189e  
    1010// Created On       : Fri Jul 21 16:21:03 2017
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Jul 21 13:31:34 2021
    13 // Update Count     : 129
     12// Last Modified On : Tue Apr 13 17:26:32 2021
     13// Update Count     : 117
    1414//
    1515
     
    7777// implicit increment, decrement if += defined, and implicit not if != defined
    7878
    79 // C11 reference manual Section 6.5.16 (page101): "An assignment expression has the value of the left operand after the
    80 // assignment, but is not an lvalue." Hence, return a value not a reference.
    8179static inline {
    82         forall( T | { T ?+=?( T &, one_t ); } )
    83         T ++?( T & x ) { return x += 1; }
     80        forall( DT & | { DT & ?+=?( DT &, one_t ); } )
     81        DT & ++?( DT & x ) { return x += 1; }
    8482
    85         forall( T | { T ?+=?( T &, one_t ); } )
    86         T ?++( T & x ) { T tmp = x; x += 1; return tmp; }
     83        forall( DT & | sized(DT) | { void ?{}( DT &, DT ); void ^?{}( DT & ); DT & ?+=?( DT &, one_t ); } )
     84        DT & ?++( DT & x ) { DT tmp = x; x += 1; return tmp; }
    8785
    88         forall( T | { T ?-=?( T &, one_t ); } )
    89         T --?( T & x ) { return x -= 1; }
     86        forall( DT & | { DT & ?-=?( DT &, one_t ); } )
     87        DT & --?( DT & x ) { return x -= 1; }
    9088
    91         forall( T | { T ?-=?( T &, one_t ); } )
    92         T ?--( T & x ) { T tmp = x; x -= 1; return tmp; }
     89        forall( DT & | sized(DT) | { void ?{}( DT &, DT ); void ^?{}( DT & ); DT & ?-=?( DT &, one_t ); } )
     90        DT & ?--( DT & x ) { DT tmp = x; x -= 1; return tmp; }
    9391
    94         forall( T | { int ?!=?( T, zero_t ); } )
    95         int !?( T & x ) { return !( x != 0 ); }
     92        forall( DT & | { int ?!=?( const DT &, zero_t ); } )
     93        int !?( const DT & x ) { return !( x != 0 ); }
    9694} // distribution
    9795
  • libcfa/src/Makefile.am

    r5541ea3d r0640189e  
    1111## Created On       : Sun May 31 08:54:01 2015
    1212## Last Modified By : Peter A. Buhr
    13 ## Last Modified On : Fri Jul 16 16:00:40 2021
    14 ## Update Count     : 255
     13## Last Modified On : Sat Apr 24 09:09:56 2021
     14## Update Count     : 254
    1515###############################################################################
    1616
     
    4545        exception.h \
    4646        gmp.hfa \
    47         math.trait.hfa \
    4847        math.hfa \
    4948        time_t.hfa \
  • libcfa/src/concurrency/locks.cfa

    r5541ea3d r0640189e  
    120120        owner = t;
    121121        recursion_count = ( t ? 1 : 0 );
    122         if ( t ) wait_count--;
     122        wait_count--;
    123123        unpark( t );
    124124}
  • libcfa/src/fstream.cfa

    r5541ea3d r0640189e  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Jul 29 22:34:10 2021
    13 // Update Count     : 454
     12// Last Modified On : Wed Apr 28 20:37:53 2021
     13// Update Count     : 445
    1414//
    1515
     
    142142
    143143        if ( fclose( (FILE *)(os.file$) ) == EOF ) {
    144                 throw (Close_Failure){ os };
    145                 // abort | IO_MSG "close output" | nl | strerror( errno );
     144                abort | IO_MSG "close output" | nl | strerror( errno );
    146145        } // if
    147146        os.file$ = 0p;
     
    150149ofstream & write( ofstream & os, const char data[], size_t size ) {
    151150        if ( fail( os ) ) {
    152                 throw (Write_Failure){ os };
    153                 // abort | IO_MSG "attempt write I/O on failed stream";
     151                abort | IO_MSG "attempt write I/O on failed stream";
    154152        } // if
    155153
    156154        if ( fwrite( data, 1, size, (FILE *)(os.file$) ) != size ) {
    157                 throw (Write_Failure){ os };
    158                 // abort | IO_MSG "write" | nl | strerror( errno );
     155                abort | IO_MSG "write" | nl | strerror( errno );
    159156        } // if
    160157        return os;
     
    280277
    281278        if ( fclose( (FILE *)(is.file$) ) == EOF ) {
    282                 throw (Close_Failure){ is };
    283                 // abort | IO_MSG "close input" | nl | strerror( errno );
     279                abort | IO_MSG "close input" | nl | strerror( errno );
    284280        } // if
    285281        is.file$ = 0p;
     
    288284ifstream & read( ifstream & is, char data[], size_t size ) {
    289285        if ( fail( is ) ) {
    290                 throw (Read_Failure){ is };
    291                 // abort | IO_MSG "attempt read I/O on failed stream";
     286                abort | IO_MSG "attempt read I/O on failed stream";
    292287        } // if
    293288
    294289        if ( fread( data, size, 1, (FILE *)(is.file$) ) == 0 ) {
    295                 throw (Read_Failure){ is };
    296                 // abort | IO_MSG "read" | nl | strerror( errno );
     290                abort | IO_MSG "read" | nl | strerror( errno );
    297291        } // if
    298292        return is;
     
    344338
    345339
    346 static vtable(Open_Failure) Open_Failure_vt;
    347 
    348 // exception I/O constructors
     340EHM_VIRTUAL_TABLE(Open_Failure, Open_Failure_main_table);
    349341void ?{}( Open_Failure & this, ofstream & ostream ) {
    350         this.virtual_table = &Open_Failure_vt;
     342        this.virtual_table = &Open_Failure_main_table;
    351343        this.ostream = &ostream;
    352344        this.tag = 1;
    353 } // ?{}
    354 
     345}
    355346void ?{}( Open_Failure & this, ifstream & istream ) {
    356         this.virtual_table = &Open_Failure_vt;
     347        this.virtual_table = &Open_Failure_main_table;
    357348        this.istream = &istream;
    358349        this.tag = 0;
    359 } // ?{}
    360 
    361 
    362 static vtable(Close_Failure) Close_Failure_vt;
    363 
    364 // exception I/O constructors
    365 void ?{}( Close_Failure & this, ofstream & ostream ) {
    366         this.virtual_table = &Close_Failure_vt;
    367         this.ostream = &ostream;
    368         this.tag = 1;
    369 } // ?{}
    370 
    371 void ?{}( Close_Failure & this, ifstream & istream ) {
    372         this.virtual_table = &Close_Failure_vt;
    373         this.istream = &istream;
    374         this.tag = 0;
    375 } // ?{}
    376 
    377 
    378 static vtable(Write_Failure) Write_Failure_vt;
    379 
    380 // exception I/O constructors
    381 void ?{}( Write_Failure & this, ofstream & ostream ) {
    382         this.virtual_table = &Write_Failure_vt;
    383         this.ostream = &ostream;
    384         this.tag = 1;
    385 } // ?{}
    386 
    387 void ?{}( Write_Failure & this, ifstream & istream ) {
    388         this.virtual_table = &Write_Failure_vt;
    389         this.istream = &istream;
    390         this.tag = 0;
    391 } // ?{}
    392 
    393 
    394 static vtable(Read_Failure) Read_Failure_vt;
    395 
    396 // exception I/O constructors
    397 void ?{}( Read_Failure & this, ofstream & ostream ) {
    398         this.virtual_table = &Read_Failure_vt;
    399         this.ostream = &ostream;
    400         this.tag = 1;
    401 } // ?{}
    402 
    403 void ?{}( Read_Failure & this, ifstream & istream ) {
    404         this.virtual_table = &Read_Failure_vt;
    405         this.istream = &istream;
    406         this.tag = 0;
    407 } // ?{}
    408 
    409 // void throwOpen_Failure( ofstream & ostream ) {
    410 //      Open_Failure exc = { ostream };
    411 // }
    412 
    413 // void throwOpen_Failure( ifstream & istream ) {
    414 //      Open_Failure exc = { istream };
    415 // }
     350}
     351void throwOpen_Failure( ofstream & ostream ) {
     352        Open_Failure exc = { ostream };
     353}
     354void throwOpen_Failure( ifstream & istream ) {
     355        Open_Failure exc = { istream };
     356}
    416357
    417358// Local Variables: //
  • libcfa/src/fstream.hfa

    r5541ea3d r0640189e  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Jul 28 07:35:50 2021
    13 // Update Count     : 234
     12// Last Modified On : Wed Apr 28 20:37:57 2021
     13// Update Count     : 230
    1414//
    1515
     
    148148
    149149
    150 exception Open_Failure {
     150EHM_EXCEPTION(Open_Failure)(
    151151        union {
    152152                ofstream * ostream;
     
    155155        // TEMPORARY: need polymorphic exceptions
    156156        int tag;                                                                                        // 1 => ostream; 0 => istream
    157 };
     157);
    158158
    159159void ?{}( Open_Failure & this, ofstream & );
    160160void ?{}( Open_Failure & this, ifstream & );
    161 
    162 exception Close_Failure {
    163         union {
    164                 ofstream * ostream;
    165                 ifstream * istream;
    166         };
    167         // TEMPORARY: need polymorphic exceptions
    168         int tag;                                                                                        // 1 => ostream; 0 => istream
    169 };
    170 
    171 void ?{}( Close_Failure & this, ofstream & );
    172 void ?{}( Close_Failure & this, ifstream & );
    173 
    174 exception Write_Failure {
    175         union {
    176                 ofstream * ostream;
    177                 ifstream * istream;
    178         };
    179         // TEMPORARY: need polymorphic exceptions
    180         int tag;                                                                                        // 1 => ostream; 0 => istream
    181 };
    182 
    183 void ?{}( Write_Failure & this, ofstream & );
    184 void ?{}( Write_Failure & this, ifstream & );
    185 
    186 exception Read_Failure {
    187         union {
    188                 ofstream * ostream;
    189                 ifstream * istream;
    190         };
    191         // TEMPORARY: need polymorphic exceptions
    192         int tag;                                                                                        // 1 => ostream; 0 => istream
    193 };
    194 
    195 void ?{}( Read_Failure & this, ofstream & );
    196 void ?{}( Read_Failure & this, ifstream & );
    197161
    198162// Local Variables: //
  • libcfa/src/rational.cfa

    r5541ea3d r0640189e  
    1010// Created On       : Wed Apr  6 17:54:28 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Jul 20 16:30:06 2021
    13 // Update Count     : 193
     12// Last Modified On : Sat Feb  8 17:56:36 2020
     13// Update Count     : 187
    1414//
    1515
     
    1818#include "stdlib.hfa"
    1919
    20 forall( T | Arithmetic( T ) ) {
     20forall( RationalImpl | arithmetic( RationalImpl ) ) {
    2121        // helper routines
    2222
    2323        // Calculate greatest common denominator of two numbers, the first of which may be negative. Used to reduce
    2424        // rationals.  alternative: https://en.wikipedia.org/wiki/Binary_GCD_algorithm
    25         static T gcd( T a, T b ) {
     25        static RationalImpl gcd( RationalImpl a, RationalImpl b ) {
    2626                for ( ;; ) {                                                                    // Euclid's algorithm
    27                         T r = a % b;
    28                   if ( r == (T){0} ) break;
     27                        RationalImpl r = a % b;
     28                  if ( r == (RationalImpl){0} ) break;
    2929                        a = b;
    3030                        b = r;
     
    3333        } // gcd
    3434
    35         static T simplify( T & n, T & d ) {
    36                 if ( d == (T){0} ) {
     35        static RationalImpl simplify( RationalImpl & n, RationalImpl & d ) {
     36                if ( d == (RationalImpl){0} ) {
    3737                        abort | "Invalid rational number construction: denominator cannot be equal to 0.";
    3838                } // exit
    39                 if ( d < (T){0} ) { d = -d; n = -n; } // move sign to numerator
     39                if ( d < (RationalImpl){0} ) { d = -d; n = -n; } // move sign to numerator
    4040                return gcd( abs( n ), d );                                              // simplify
    4141        } // Rationalnumber::simplify
     
    4343        // constructors
    4444
    45         void ?{}( Rational(T) & r, zero_t ) {
    46                 r{ (T){0}, (T){1} };
    47         } // rational
    48 
    49         void ?{}( Rational(T) & r, one_t ) {
    50                 r{ (T){1}, (T){1} };
    51         } // rational
    52 
    53         void ?{}( Rational(T) & r ) {
    54                 r{ (T){0}, (T){1} };
    55         } // rational
    56 
    57         void ?{}( Rational(T) & r, T n ) {
    58                 r{ n, (T){1} };
    59         } // rational
    60 
    61         void ?{}( Rational(T) & r, T n, T d ) {
    62                 T t = simplify( n, d );                         // simplify
     45        void ?{}( Rational(RationalImpl) & r ) {
     46                r{ (RationalImpl){0}, (RationalImpl){1} };
     47        } // rational
     48
     49        void ?{}( Rational(RationalImpl) & r, RationalImpl n ) {
     50                r{ n, (RationalImpl){1} };
     51        } // rational
     52
     53        void ?{}( Rational(RationalImpl) & r, RationalImpl n, RationalImpl d ) {
     54                RationalImpl t = simplify( n, d );                              // simplify
    6355                r.[numerator, denominator] = [n / t, d / t];
    6456        } // rational
    6557
     58        void ?{}( Rational(RationalImpl) & r, zero_t ) {
     59                r{ (RationalImpl){0}, (RationalImpl){1} };
     60        } // rational
     61
     62        void ?{}( Rational(RationalImpl) & r, one_t ) {
     63                r{ (RationalImpl){1}, (RationalImpl){1} };
     64        } // rational
     65
    6666        // getter for numerator/denominator
    6767
    68         T numerator( Rational(T) r ) {
     68        RationalImpl numerator( Rational(RationalImpl) r ) {
    6969                return r.numerator;
    7070        } // numerator
    7171
    72         T denominator( Rational(T) r ) {
     72        RationalImpl denominator( Rational(RationalImpl) r ) {
    7373                return r.denominator;
    7474        } // denominator
    7575
    76         [ T, T ] ?=?( & [ T, T ] dest, Rational(T) src ) {
     76        [ RationalImpl, RationalImpl ] ?=?( & [ RationalImpl, RationalImpl ] dest, Rational(RationalImpl) src ) {
    7777                return dest = src.[ numerator, denominator ];
    7878        } // ?=?
     
    8080        // setter for numerator/denominator
    8181
    82         T numerator( Rational(T) r, T n ) {
    83                 T prev = r.numerator;
    84                 T t = gcd( abs( n ), r.denominator ); // simplify
     82        RationalImpl numerator( Rational(RationalImpl) r, RationalImpl n ) {
     83                RationalImpl prev = r.numerator;
     84                RationalImpl t = gcd( abs( n ), r.denominator ); // simplify
    8585                r.[numerator, denominator] = [n / t, r.denominator / t];
    8686                return prev;
    8787        } // numerator
    8888
    89         T denominator( Rational(T) r, T d ) {
    90                 T prev = r.denominator;
    91                 T t = simplify( r.numerator, d );       // simplify
     89        RationalImpl denominator( Rational(RationalImpl) r, RationalImpl d ) {
     90                RationalImpl prev = r.denominator;
     91                RationalImpl t = simplify( r.numerator, d );    // simplify
    9292                r.[numerator, denominator] = [r.numerator / t, d / t];
    9393                return prev;
     
    9696        // comparison
    9797
    98         int ?==?( Rational(T) l, Rational(T) r ) {
     98        int ?==?( Rational(RationalImpl) l, Rational(RationalImpl) r ) {
    9999                return l.numerator * r.denominator == l.denominator * r.numerator;
    100100        } // ?==?
    101101
    102         int ?!=?( Rational(T) l, Rational(T) r ) {
     102        int ?!=?( Rational(RationalImpl) l, Rational(RationalImpl) r ) {
    103103                return ! ( l == r );
    104104        } // ?!=?
    105105
    106         int ?!=?( Rational(T) l, zero_t ) {
    107                 return ! ( l == (Rational(T)){ 0 } );
    108         } // ?!=?
    109 
    110         int ?<?( Rational(T) l, Rational(T) r ) {
     106        int ?<?( Rational(RationalImpl) l, Rational(RationalImpl) r ) {
    111107                return l.numerator * r.denominator < l.denominator * r.numerator;
    112108        } // ?<?
    113109
    114         int ?<=?( Rational(T) l, Rational(T) r ) {
     110        int ?<=?( Rational(RationalImpl) l, Rational(RationalImpl) r ) {
    115111                return l.numerator * r.denominator <= l.denominator * r.numerator;
    116112        } // ?<=?
    117113
    118         int ?>?( Rational(T) l, Rational(T) r ) {
     114        int ?>?( Rational(RationalImpl) l, Rational(RationalImpl) r ) {
    119115                return ! ( l <= r );
    120116        } // ?>?
    121117
    122         int ?>=?( Rational(T) l, Rational(T) r ) {
     118        int ?>=?( Rational(RationalImpl) l, Rational(RationalImpl) r ) {
    123119                return ! ( l < r );
    124120        } // ?>=?
     
    126122        // arithmetic
    127123
    128         Rational(T) +?( Rational(T) r ) {
    129                 return (Rational(T)){ r.numerator, r.denominator };
     124        Rational(RationalImpl) +?( Rational(RationalImpl) r ) {
     125                return (Rational(RationalImpl)){ r.numerator, r.denominator };
    130126        } // +?
    131127
    132         Rational(T) -?( Rational(T) r ) {
    133                 return (Rational(T)){ -r.numerator, r.denominator };
     128        Rational(RationalImpl) -?( Rational(RationalImpl) r ) {
     129                return (Rational(RationalImpl)){ -r.numerator, r.denominator };
    134130        } // -?
    135131
    136         Rational(T) ?+?( Rational(T) l, Rational(T) r ) {
     132        Rational(RationalImpl) ?+?( Rational(RationalImpl) l, Rational(RationalImpl) r ) {
    137133                if ( l.denominator == r.denominator ) {                 // special case
    138                         return (Rational(T)){ l.numerator + r.numerator, l.denominator };
     134                        return (Rational(RationalImpl)){ l.numerator + r.numerator, l.denominator };
    139135                } else {
    140                         return (Rational(T)){ l.numerator * r.denominator + l.denominator * r.numerator, l.denominator * r.denominator };
     136                        return (Rational(RationalImpl)){ l.numerator * r.denominator + l.denominator * r.numerator, l.denominator * r.denominator };
    141137                } // if
    142138        } // ?+?
    143139
    144         Rational(T) ?+=?( Rational(T) & l, Rational(T) r ) {
    145                 l = l + r;
    146                 return l;
    147         } // ?+?
    148 
    149         Rational(T) ?+=?( Rational(T) & l, one_t ) {
    150                 l = l + (Rational(T)){ 1 };
    151                 return l;
    152         } // ?+?
    153 
    154         Rational(T) ?-?( Rational(T) l, Rational(T) r ) {
     140        Rational(RationalImpl) ?-?( Rational(RationalImpl) l, Rational(RationalImpl) r ) {
    155141                if ( l.denominator == r.denominator ) {                 // special case
    156                         return (Rational(T)){ l.numerator - r.numerator, l.denominator };
     142                        return (Rational(RationalImpl)){ l.numerator - r.numerator, l.denominator };
    157143                } else {
    158                         return (Rational(T)){ l.numerator * r.denominator - l.denominator * r.numerator, l.denominator * r.denominator };
     144                        return (Rational(RationalImpl)){ l.numerator * r.denominator - l.denominator * r.numerator, l.denominator * r.denominator };
    159145                } // if
    160146        } // ?-?
    161147
    162         Rational(T) ?-=?( Rational(T) & l, Rational(T) r ) {
    163                 l = l - r;
    164                 return l;
    165         } // ?-?
    166 
    167         Rational(T) ?-=?( Rational(T) & l, one_t ) {
    168                 l = l - (Rational(T)){ 1 };
    169                 return l;
    170         } // ?-?
    171 
    172         Rational(T) ?*?( Rational(T) l, Rational(T) r ) {
    173                 return (Rational(T)){ l.numerator * r.numerator, l.denominator * r.denominator };
     148        Rational(RationalImpl) ?*?( Rational(RationalImpl) l, Rational(RationalImpl) r ) {
     149                return (Rational(RationalImpl)){ l.numerator * r.numerator, l.denominator * r.denominator };
    174150        } // ?*?
    175151
    176         Rational(T) ?*=?( Rational(T) & l, Rational(T) r ) {
    177                 return l = l * r;
    178         } // ?*?
    179 
    180         Rational(T) ?/?( Rational(T) l, Rational(T) r ) {
    181                 if ( r.numerator < (T){0} ) {
     152        Rational(RationalImpl) ?/?( Rational(RationalImpl) l, Rational(RationalImpl) r ) {
     153                if ( r.numerator < (RationalImpl){0} ) {
    182154                        r.[numerator, denominator] = [-r.numerator, -r.denominator];
    183155                } // if
    184                 return (Rational(T)){ l.numerator * r.denominator, l.denominator * r.numerator };
     156                return (Rational(RationalImpl)){ l.numerator * r.denominator, l.denominator * r.numerator };
    185157        } // ?/?
    186158
    187         Rational(T) ?/=?( Rational(T) & l, Rational(T) r ) {
    188                 return l = l / r;
    189         } // ?/?
    190 
    191159        // I/O
    192160
    193         forall( istype & | istream( istype ) | { istype & ?|?( istype &, T & ); } )
    194         istype & ?|?( istype & is, Rational(T) & r ) {
     161        forall( istype & | istream( istype ) | { istype & ?|?( istype &, RationalImpl & ); } )
     162        istype & ?|?( istype & is, Rational(RationalImpl) & r ) {
    195163                is | r.numerator | r.denominator;
    196                 T t = simplify( r.numerator, r.denominator );
     164                RationalImpl t = simplify( r.numerator, r.denominator );
    197165                r.numerator /= t;
    198166                r.denominator /= t;
     
    200168        } // ?|?
    201169
    202         forall( ostype & | ostream( ostype ) | { ostype & ?|?( ostype &, T ); } ) {
    203                 ostype & ?|?( ostype & os, Rational(T) r ) {
     170        forall( ostype & | ostream( ostype ) | { ostype & ?|?( ostype &, RationalImpl ); } ) {
     171                ostype & ?|?( ostype & os, Rational(RationalImpl) r ) {
    204172                        return os | r.numerator | '/' | r.denominator;
    205173                } // ?|?
    206174
    207                 void ?|?( ostype & os, Rational(T) r ) {
     175                void ?|?( ostype & os, Rational(RationalImpl) r ) {
    208176                        (ostype &)(os | r); ends( os );
    209177                } // ?|?
     
    211179} // distribution
    212180
    213 forall( T | Arithmetic( T ) | { T ?\?( T, unsigned long ); } ) {
    214         Rational(T) ?\?( Rational(T) x, long int y ) {
    215                 if ( y < 0 ) {
    216                         return (Rational(T)){ x.denominator \ -y, x.numerator \ -y };
    217                 } else {
    218                         return (Rational(T)){ x.numerator \ y, x.denominator \ y };
    219                 } // if
    220         } // ?\?
    221 
    222         Rational(T) ?\=?( Rational(T) & x, long int y ) {
    223                 return x = x \ y;
    224         } // ?\?
    225 } // distribution
     181forall( RationalImpl | arithmetic( RationalImpl ) | { RationalImpl ?\?( RationalImpl, unsigned long ); } )
     182Rational(RationalImpl) ?\?( Rational(RationalImpl) x, long int y ) {
     183        if ( y < 0 ) {
     184                return (Rational(RationalImpl)){ x.denominator \ -y, x.numerator \ -y };
     185        } else {
     186                return (Rational(RationalImpl)){ x.numerator \ y, x.denominator \ y };
     187        } // if
     188}
    226189
    227190// conversion
    228191
    229 forall( T | Arithmetic( T ) | { double convert( T ); } )
    230 double widen( Rational(T) r ) {
     192forall( RationalImpl | arithmetic( RationalImpl ) | { double convert( RationalImpl ); } )
     193double widen( Rational(RationalImpl) r ) {
    231194        return convert( r.numerator ) / convert( r.denominator );
    232195} // widen
    233196
    234 forall( T | Arithmetic( T ) | { double convert( T ); T convert( double ); } )
    235 Rational(T) narrow( double f, T md ) {
     197forall( RationalImpl | arithmetic( RationalImpl ) | { double convert( RationalImpl ); RationalImpl convert( double ); } )
     198Rational(RationalImpl) narrow( double f, RationalImpl md ) {
    236199        // http://www.ics.uci.edu/~eppstein/numth/frap.c
    237         if ( md <= (T){1} ) {                                   // maximum fractional digits too small?
    238                 return (Rational(T)){ convert( f ), (T){1}}; // truncate fraction
     200        if ( md <= (RationalImpl){1} ) {                                        // maximum fractional digits too small?
     201                return (Rational(RationalImpl)){ convert( f ), (RationalImpl){1}}; // truncate fraction
    239202        } // if
    240203
    241204        // continued fraction coefficients
    242         T m00 = {1}, m11 = { 1 }, m01 = { 0 }, m10 = { 0 };
    243         T ai, t;
     205        RationalImpl m00 = {1}, m11 = { 1 }, m01 = { 0 }, m10 = { 0 };
     206        RationalImpl ai, t;
    244207
    245208        // find terms until denom gets too big
     
    258221          if ( f > (double)0x7FFFFFFF ) break;                          // representation failure
    259222        } // for
    260         return (Rational(T)){ m00, m10 };
     223        return (Rational(RationalImpl)){ m00, m10 };
    261224} // narrow
    262225
  • libcfa/src/rational.hfa

    r5541ea3d r0640189e  
    1212// Created On       : Wed Apr  6 17:56:25 2016
    1313// Last Modified By : Peter A. Buhr
    14 // Last Modified On : Tue Jul 20 17:45:29 2021
    15 // Update Count     : 118
     14// Last Modified On : Tue Mar 26 23:16:10 2019
     15// Update Count     : 109
    1616//
    1717
     
    1919
    2020#include "iostream.hfa"
    21 #include "math.trait.hfa"                                                               // Arithmetic
     21
     22trait scalar( T ) {
     23};
     24
     25trait arithmetic( T | scalar( T ) ) {
     26        int !?( T );
     27        int ?==?( T, T );
     28        int ?!=?( T, T );
     29        int ?<?( T, T );
     30        int ?<=?( T, T );
     31        int ?>?( T, T );
     32        int ?>=?( T, T );
     33        void ?{}( T &, zero_t );
     34        void ?{}( T &, one_t );
     35        T +?( T );
     36        T -?( T );
     37        T ?+?( T, T );
     38        T ?-?( T, T );
     39        T ?*?( T, T );
     40        T ?/?( T, T );
     41        T ?%?( T, T );
     42        T ?/=?( T &, T );
     43        T abs( T );
     44};
    2245
    2346// implementation
    2447
    25 forall( T | Arithmetic( T ) ) {
     48forall( RationalImpl | arithmetic( RationalImpl ) ) {
    2649        struct Rational {
    27                 T numerator, denominator;                                               // invariant: denominator > 0
     50                RationalImpl numerator, denominator;                    // invariant: denominator > 0
    2851        }; // Rational
    2952
    3053        // constructors
    3154
    32         void ?{}( Rational(T) & r );
    33         void ?{}( Rational(T) & r, zero_t );
    34         void ?{}( Rational(T) & r, one_t );
    35         void ?{}( Rational(T) & r, T n );
    36         void ?{}( Rational(T) & r, T n, T d );
     55        void ?{}( Rational(RationalImpl) & r );
     56        void ?{}( Rational(RationalImpl) & r, RationalImpl n );
     57        void ?{}( Rational(RationalImpl) & r, RationalImpl n, RationalImpl d );
     58        void ?{}( Rational(RationalImpl) & r, zero_t );
     59        void ?{}( Rational(RationalImpl) & r, one_t );
    3760
    3861        // numerator/denominator getter
    3962
    40         T numerator( Rational(T) r );
    41         T denominator( Rational(T) r );
    42         [ T, T ] ?=?( & [ T, T ] dest, Rational(T) src );
     63        RationalImpl numerator( Rational(RationalImpl) r );
     64        RationalImpl denominator( Rational(RationalImpl) r );
     65        [ RationalImpl, RationalImpl ] ?=?( & [ RationalImpl, RationalImpl ] dest, Rational(RationalImpl) src );
    4366
    4467        // numerator/denominator setter
    4568
    46         T numerator( Rational(T) r, T n );
    47         T denominator( Rational(T) r, T d );
     69        RationalImpl numerator( Rational(RationalImpl) r, RationalImpl n );
     70        RationalImpl denominator( Rational(RationalImpl) r, RationalImpl d );
    4871
    4972        // comparison
    5073
    51         int ?==?( Rational(T) l, Rational(T) r );
    52         int ?!=?( Rational(T) l, Rational(T) r );
    53         int ?!=?( Rational(T) l, zero_t );                                      // => !
    54         int ?<?( Rational(T) l, Rational(T) r );
    55         int ?<=?( Rational(T) l, Rational(T) r );
    56         int ?>?( Rational(T) l, Rational(T) r );
    57         int ?>=?( Rational(T) l, Rational(T) r );
     74        int ?==?( Rational(RationalImpl) l, Rational(RationalImpl) r );
     75        int ?!=?( Rational(RationalImpl) l, Rational(RationalImpl) r );
     76        int ?<?( Rational(RationalImpl) l, Rational(RationalImpl) r );
     77        int ?<=?( Rational(RationalImpl) l, Rational(RationalImpl) r );
     78        int ?>?( Rational(RationalImpl) l, Rational(RationalImpl) r );
     79        int ?>=?( Rational(RationalImpl) l, Rational(RationalImpl) r );
    5880
    5981        // arithmetic
    6082
    61         Rational(T) +?( Rational(T) r );
    62         Rational(T) -?( Rational(T) r );
    63         Rational(T) ?+?( Rational(T) l, Rational(T) r );
    64         Rational(T) ?+=?( Rational(T) & l, Rational(T) r );
    65         Rational(T) ?+=?( Rational(T) & l, one_t );                     // => ++?, ?++
    66         Rational(T) ?-?( Rational(T) l, Rational(T) r );
    67         Rational(T) ?-=?( Rational(T) & l, Rational(T) r );
    68         Rational(T) ?-=?( Rational(T) & l, one_t );                     // => --?, ?--
    69         Rational(T) ?*?( Rational(T) l, Rational(T) r );
    70         Rational(T) ?*=?( Rational(T) & l, Rational(T) r );
    71         Rational(T) ?/?( Rational(T) l, Rational(T) r );
    72         Rational(T) ?/=?( Rational(T) & l, Rational(T) r );
     83        Rational(RationalImpl) +?( Rational(RationalImpl) r );
     84        Rational(RationalImpl) -?( Rational(RationalImpl) r );
     85        Rational(RationalImpl) ?+?( Rational(RationalImpl) l, Rational(RationalImpl) r );
     86        Rational(RationalImpl) ?-?( Rational(RationalImpl) l, Rational(RationalImpl) r );
     87        Rational(RationalImpl) ?*?( Rational(RationalImpl) l, Rational(RationalImpl) r );
     88        Rational(RationalImpl) ?/?( Rational(RationalImpl) l, Rational(RationalImpl) r );
    7389
    7490        // I/O
    75         forall( istype & | istream( istype ) | { istype & ?|?( istype &, T & ); } )
    76         istype & ?|?( istype &, Rational(T) & );
     91        forall( istype & | istream( istype ) | { istype & ?|?( istype &, RationalImpl & ); } )
     92        istype & ?|?( istype &, Rational(RationalImpl) & );
    7793
    78         forall( ostype & | ostream( ostype ) | { ostype & ?|?( ostype &, T ); } ) {
    79                 ostype & ?|?( ostype &, Rational(T) );
    80                 void ?|?( ostype &, Rational(T) );
     94        forall( ostype & | ostream( ostype ) | { ostype & ?|?( ostype &, RationalImpl ); } ) {
     95                ostype & ?|?( ostype &, Rational(RationalImpl) );
     96                void ?|?( ostype &, Rational(RationalImpl) );
    8197        } // distribution
    8298} // distribution
    8399
    84 forall( T | Arithmetic( T ) | { T ?\?( T, unsigned long ); } ) {
    85         Rational(T) ?\?( Rational(T) x, long int y );
    86         Rational(T) ?\=?( Rational(T) & x, long int y );
    87 } // distribution
     100forall( RationalImpl | arithmetic( RationalImpl ) |{RationalImpl ?\?( RationalImpl, unsigned long );} )
     101Rational(RationalImpl) ?\?( Rational(RationalImpl) x, long int y );
    88102
    89103// conversion
    90 forall( T | Arithmetic( T ) | { double convert( T ); } )
    91 double widen( Rational(T) r );
    92 forall( T | Arithmetic( T ) | { double convert( T );  T convert( double );} )
    93 Rational(T) narrow( double f, T md );
     104forall( RationalImpl | arithmetic( RationalImpl ) | { double convert( RationalImpl ); } )
     105double widen( Rational(RationalImpl) r );
     106forall( RationalImpl | arithmetic( RationalImpl ) | { double convert( RationalImpl );  RationalImpl convert( double );} )
     107Rational(RationalImpl) narrow( double f, RationalImpl md );
    94108
    95109// Local Variables: //
  • src/CompilationState.cc

    r5541ea3d r0640189e  
    99// Author           : Rob Schluntz
    1010// Created On       : Mon Ju1 30 10:47:01 2018
    11 // Last Modified By : Henry Xue
    12 // Last Modified On : Tue Jul 20 04:27:35 2021
    13 // Update Count     : 5
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Fri May  3 13:45:23 2019
     13// Update Count     : 4
    1414//
    1515
     
    2323        ctorinitp = false,
    2424        declstatsp = false,
    25         exdeclp = false,
    2625        exprp = false,
    2726        expraltp = false,
  • src/CompilationState.h

    r5541ea3d r0640189e  
    99// Author           : Rob Schluntz
    1010// Created On       : Mon Ju1 30 10:47:01 2018
    11 // Last Modified By : Henry Xue
    12 // Last Modified On : Tue Jul 20 04:27:35 2021
    13 // Update Count     : 5
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Fri May  3 13:43:21 2019
     13// Update Count     : 4
    1414//
    1515
     
    2222        ctorinitp,
    2323        declstatsp,
    24         exdeclp,
    2524        exprp,
    2625        expraltp,
  • src/ControlStruct/ExceptTranslate.cc

    r5541ea3d r0640189e  
    99// Author           : Andrew Beach
    1010// Created On       : Wed Jun 14 16:49:00 2017
    11 // Last Modified By : Henry Xue
    12 // Last Modified On : Tue Aug 03 10:05:51 2021
    13 // Update Count     : 18
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Wed Jun 24 11:18:00 2020
     13// Update Count     : 17
    1414//
    1515
     
    320320                                static_cast<ObjectDecl *>( handler->get_decl() );
    321321                        ObjectDecl * local_except = handler_decl->clone();
    322                         VirtualCastExpr * vcex = new VirtualCastExpr(
    323                                 nameOf( except_obj ),
    324                                 local_except->get_type()
     322                        local_except->set_init(
     323                                new ListInit({ new SingleInit(
     324                                        new VirtualCastExpr( nameOf( except_obj ),
     325                                                local_except->get_type()
     326                                                )
     327                                        ) })
    325328                                );
    326                         vcex->location = handler->location;
    327                         local_except->set_init( new ListInit({ new SingleInit( vcex ) }) );
    328329                        block->push_back( new DeclStmt( local_except ) );
    329330
     
    391392
    392393                // Check for type match.
    393                 VirtualCastExpr * vcex = new VirtualCastExpr(
    394                         nameOf( except_obj ),
    395                         local_except->get_type()->clone()
    396                         );
    397                 vcex->location = modded_handler->location;
    398                 Expression * cond = UntypedExpr::createAssign(
    399                         nameOf( local_except ), vcex );
     394                Expression * cond = UntypedExpr::createAssign( nameOf( local_except ),
     395                        new VirtualCastExpr( nameOf( except_obj ),
     396                                local_except->get_type()->clone() ) );
    400397
    401398                // Add the check on the conditional if it is provided.
  • src/ControlStruct/module.mk

    r5541ea3d r0640189e  
    1010## Author           : Richard C. Bilson
    1111## Created On       : Mon Jun  1 17:49:17 2015
    12 ## Last Modified By : Henry Xue
    13 ## Last Modified On : Tue Jul 20 04:10:50 2021
    14 ## Update Count     : 5
     12## Last Modified By : Andrew Beach
     13## Last Modified On : Wed Jun 28 16:15:00 2017
     14## Update Count     : 4
    1515###############################################################################
    1616
    1717SRC_CONTROLSTRUCT = \
    18         ControlStruct/ExceptDecl.cc \
    19         ControlStruct/ExceptDecl.h \
    2018        ControlStruct/ForExprMutator.cc \
    2119        ControlStruct/ForExprMutator.h \
  • src/Parser/TypeData.cc

    r5541ea3d r0640189e  
    99// Author           : Rodolfo G. Esteves
    1010// Created On       : Sat May 16 15:12:51 2015
    11 // Last Modified By : Henry Xue
    12 // Last Modified On : Tue Jul 20 04:10:50 2021
    13 // Update Count     : 673
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Wed Jul 14 18:57:31 2021
     13// Update Count     : 672
    1414//
    1515
     
    778778          case AggregateDecl::Struct:
    779779          case AggregateDecl::Coroutine:
    780           case AggregateDecl::Exception:
    781780          case AggregateDecl::Generator:
    782781          case AggregateDecl::Monitor:
  • src/Parser/parser.yy

    r5541ea3d r0640189e  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Jul 20 22:03:04 2021
    13 // Update Count     : 5031
     12// Last Modified On : Wed Jul 14 17:27:54 2021
     13// Update Count     : 5030
    1414//
    1515
     
    19231923
    19241924vtable:
    1925         VTABLE '(' type_name ')' default_opt
     1925        VTABLE '(' typedef_name ')' default_opt
    19261926                { $$ = DeclarationNode::newVtableType( $3 ); }
    19271927                // { SemanticError( yylloc, "vtable is currently unimplemented." ); $$ = nullptr; }
  • src/SynTree/Declaration.h

    r5541ea3d r0640189e  
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Henry Xue
    12 // Last Modified On : Tue Jul 20 04:10:50 2021
    13 // Update Count     : 160
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Fri Mar 12 18:35:36 2021
     13// Update Count     : 159
    1414//
    1515
     
    300300
    301301        bool is_coroutine() { return kind == Coroutine; }
    302         bool is_exception() { return kind == Exception; }
    303302        bool is_generator() { return kind == Generator; }
    304303        bool is_monitor  () { return kind == Monitor  ; }
  • src/main.cc

    r5541ea3d r0640189e  
    99// Author           : Peter Buhr and Rob Schluntz
    1010// Created On       : Fri May 15 23:12:02 2015
    11 // Last Modified By : Henry Xue
    12 // Last Modified On : Tue Jul 20 04:27:35 2021
    13 // Update Count     : 658
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Sat Mar  6 15:49:00 2021
     13// Update Count     : 656
    1414//
    1515
     
    4949#include "Common/utility.h"                 // for deleteAll, filter, printAll
    5050#include "Concurrency/Waitfor.h"            // for generateWaitfor
    51 #include "ControlStruct/ExceptDecl.h"       // for translateExcept
    5251#include "ControlStruct/ExceptTranslate.h"  // for translateEHM
    5352#include "ControlStruct/Mutate.h"           // for mutate
     
    306305                CodeTools::fillLocations( translationUnit );
    307306                Stats::Time::StopBlock();
    308 
    309                 PASS( "Translate Exception Declarations", ControlStruct::translateExcept( translationUnit ) );
    310                 if ( exdeclp ) {
    311                         dump( translationUnit );
    312                         return EXIT_SUCCESS;
    313                 } // if
    314307
    315308                // add the assignment statement after the initialization of a type parameter
     
    556549        // code dumps
    557550        { "ast", astp, true, "print AST after parsing" },
    558         { "exdecl", exdeclp, true, "print AST after translating exception decls" },
    559551        { "symevt", symtabp, true, "print AST after symbol table events" },
    560552        { "altexpr", expraltp, true, "print alternatives for expressions" },
  • tests/.expect/counter.txt

    r5541ea3d r0640189e  
    1 inc 45
    2 dec 42
     145
     242
  • tests/.expect/rational.txt

    r5541ea3d r0640189e  
    11constructor
    2 a : 3/1 b : 4/1 c : 0/1 d : 0/1 e : 1/1
    3 a : 1/2 b : 5/7
    4 a : 2/3 b : -3/2
    5 a : -2/3 b : 3/2
    6 
    7 comparison
    8 a : -2/1 b : -3/2
    9 a == 0 : 0
    10 a == 1 : 0
    11 a != 0 : 1
    12 ! a : 0
    13 a != b : 1
    14 a <  b : 1
    15 a <=  b : 1
    16 a >  b : 0
    17 a >=  b : 0
    18 
     23/1 4/1 0/1 0/1 1/1
     31/2 5/7
     42/3 -3/2
     5-2/3 3/2
     6logical
     7-2/1 -3/2
     81
     91
     101
     110
     120
    1913arithmetic
    20 a : -2/1 b : -3/2
    21 a + b : -7/2
    22 a += b : -7/2
    23 ++a : -5/2
    24 a++ : -5/2
    25 a : -3/2
    26 a - b : 0/1
    27 a -= b : 0/1
    28 --a : -1/1
    29 a-- : -1/1
    30 a : -2/1
    31 a * b : 3/1
    32 a / b : 4/3
    33 a \ 2 : 4/1 b \ 2 : 9/4
    34 a \ -2 : 1/4 b \ -2 : 4/9
    35 
     14-2/1 -3/2
     15-7/2
     16-1/2
     173/1
     184/3
    3619conversion
    37200.75
     
    41241/7
    4225355/113
    43 
     26decompose
    4427more tests
    4528-3/2
  • tests/counter.cfa

    r5541ea3d r0640189e  
    1010// Created On       : Thu Feb 22 15:27:00 2018
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Jul 20 21:25:30 2021
    13 // Update Count     : 4
     12// Last Modified On : Tue Nov  6 17:50:23 2018
     13// Update Count     : 2
    1414//
    15 
    16 #include <fstream.hfa>
    1715
    1816// Tests unified increment/decrement builtin functions.
     
    2119struct counter { int x; };
    2220
    23 counter ?+=?( counter & c, one_t ) { ++c.x; return c; }
    24 counter ?-=?( counter & c, one_t ) { --c.x; return c; }
     21counter& ?+=?( counter& c, one_t ) { ++c.x; return c; }
     22
     23counter& ?-=?( counter& c, one_t ) { --c.x; return c; }
    2524
    2625int main() {
     
    2928    ++c;
    3029    c++;
    31     sout | "inc" | c.x;
     30    printf("%d\n", c.x);
    3231    c -= 1;
    3332    --c;
    3433    c--;
    35     sout | "dec" | c.x;
     34    printf("%d\n", c.x);
    3635}
    3736
  • tests/polymorphism.cfa

    r5541ea3d r0640189e  
    7171                printf("  offset of inner float:  %ld\n", ((char *) & x_inner_float ) - ((char *) & x) );
    7272
    73         void showStatic( thing(long long int) & x ) {
     73        void showStatic( thing(int) & x ) {
    7474                printf("static:\n");
    7575                SHOW_OFFSETS
     
    8585
    8686        printf("=== checkPlan9offsets\n");
    87         thing(long long int) x;
     87        thing(int) x;
    8888        showStatic(x);
    8989        showDynamic(x);
  • tests/rational.cfa

    r5541ea3d r0640189e  
    1010// Created On       : Mon Mar 28 08:43:12 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Jul 20 18:13:40 2021
    13 // Update Count     : 107
     12// Last Modified On : Sat Feb  8 18:46:23 2020
     13// Update Count     : 86
    1414//
    1515
     
    2626        sout | "constructor";
    2727        RatInt a = { 3 }, b = { 4 }, c, d = 0, e = 1;
    28         sout | "a : " | a | "b : " | b | "c : " | c | "d : " | d | "e : " | e;
     28        sout | a | b | c | d | e;
    2929
    3030        a = (RatInt){ 4, 8 };
    3131        b = (RatInt){ 5, 7 };
    32         sout | "a : " | a | "b : " | b;
     32        sout | a | b;
    3333        a = (RatInt){ -2, -3 };
    3434        b = (RatInt){ 3, -2 };
    35         sout | "a : " | a | "b : " | b;
     35        sout | a | b;
    3636        a = (RatInt){ -2, 3 };
    3737        b = (RatInt){ 3, 2 };
    38         sout | "a : " | a | "b : " | b;
    39         sout | nl;
     38        sout | a | b;
    4039
    41         sout | "comparison";
     40        sout | "logical";
    4241        a = (RatInt){ -2 };
    4342        b = (RatInt){ -3, 2 };
    44         sout | "a : " | a | "b : " | b;
    45         sout | "a == 0 : " | a == (Rational(int)){0}; // FIX ME
    46         sout | "a == 1 : " | a == (Rational(int)){1}; // FIX ME
    47         sout | "a != 0 : " | a != 0;
    48         sout | "! a : " | ! a;
    49         sout | "a != b : " | a != b;
    50         sout | "a <  b : " | a <  b;
    51         sout | "a <=  b : " | a <= b;
    52         sout | "a >  b : " | a >  b;
    53         sout | "a >=  b : " | a >= b;
    54         sout | nl;
     43        sout | a | b;
     44//      sout | a == 1; // FIX ME
     45        sout | a != b;
     46        sout | a <  b;
     47        sout | a <= b;
     48        sout | a >  b;
     49        sout | a >= b;
    5550
    5651        sout | "arithmetic";
    57         sout | "a : " | a | "b : " | b;
    58         sout | "a + b : " | a + b;
    59         sout | "a += b : " | (a += b);
    60         sout | "++a : " | ++a;
    61         sout | "a++ : " | a++;
    62         sout | "a : " | a;
    63         sout | "a - b : " | a - b;
    64         sout | "a -= b : " | (a -= b);
    65         sout | "--a : " | --a;
    66         sout | "a-- : " | a--;
    67         sout | "a : " | a;
    68         sout | "a * b : " | a * b;
    69         sout | "a / b : " | a / b;
    70         sout | "a \\ 2 : " | a \ 2u | "b \\ 2 : " | b \ 2u;
    71         sout | "a \\ -2 : " | a \ -2 | "b \\ -2 : " | b \ -2;
    72         sout | nl;
     52        sout | a | b;
     53        sout | a + b;
     54        sout | a - b;
     55        sout | a * b;
     56        sout | a / b;
     57//      sout | a \ 2 | b \ 2; // FIX ME
     58//      sout | a \ -2 | b \ -2;
    7359
    7460        sout | "conversion";
     
    8268        sout | narrow( 0.14285714285714, 16 );
    8369        sout | narrow( 3.14159265358979, 256 );
    84         sout | nl;
    8570
    86         // sout | "decompose";
    87         // int n, d;
    88         // [n, d] = a;
    89         // sout | a | n | d;
     71        sout | "decompose";
     72        int n, d;
     73//      [n, d] = a;
     74//      sout | a | n | d;
    9075
    9176        sout | "more tests";
Note: See TracChangeset for help on using the changeset viewer.