Changeset e68d092 for tests


Ignore:
Timestamp:
May 7, 2020, 11:25:15 AM (4 years ago)
Author:
Andrew Beach <ajbeach@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
8e16177, af7acb9
Parents:
d6566c1
Message:

Replaced my exception patch macros with a (hopefully temporary) addition to the standard libary, the same macros just cleaned up. See the exception tests for some example uses.

Location:
tests/exceptions
Files:
2 added
1 deleted
5 edited

Legend:

Unmodified
Added
Removed
  • tests/exceptions/conditional.cfa

    rd6566c1 re68d092  
    44// up the non-trivial exception is reasonable to do.
    55
    6 #include "except-mac.hfa"
     6#include <exception.hfa>
    77#include <stdio.h>
    88
    9 DECLARE_EXCEPT(num_error, BASE_EXCEPT,
     9VTABLE_DECLARATION(num_error)(
    1010        int (*code)(num_error *this);
    1111);
     
    3636    this.num = other.num;
    3737}
    38 void copy(num_error * this, num_error * other) {
    39         *this = *other;
    40 }
    4138void ^?{}(num_error & this) {
    4239    if( this.msg ) free( this.msg );
     
    4643}
    4744
    48 VTABLE_INSTANCE(num_error, BASE_EXCEPT, copy, ^?{},
    49         num_error_msg, num_error_code
     45VTABLE_INSTANCE(num_error)(
     46        num_error_msg,
     47        num_error_code,
    5048);
    5149
     
    5856
    5957        try {
    60                 THROW(&exc);
     58                throw &exc;
    6159        } catch (num_error * error ; 3 == error->virtual_table->code( error )) {
    6260                caught_num_error(3, error);
     
    6664
    6765        try {
    68                 THROW_RESUME(&exc);
     66                throwResume &exc;
    6967        } catchResume (num_error * error ; 3 == error->virtual_table->code( error )) {
    7068                caught_num_error(3, error);
  • tests/exceptions/finally.cfa

    rd6566c1 re68d092  
    11// Finally Clause Tests
    22
    3 #include "except-mac.hfa"
     3#include <exception.hfa>
    44#include "except-io.hfa"
    55
     
    1212                try {
    1313                        printf("termination throw\n");
    14                         THROW(&exc);
     14                        throw &exc;
    1515                } finally {
    1616                        loud_exit a = "termination inner finally";
     
    2828                try {
    2929                        printf("resumption throw\n");
    30                         THROW_RESUME(&exc);
     30                        throwResume &exc;
    3131                } finally {
    3232                        loud_exit a = "resumption inner finally";
  • tests/exceptions/interact.cfa

    rd6566c1 re68d092  
    11// Testing Interactions Between Termination and Resumption
    22
    3 #include "except-mac.hfa"
     3#include <exception.hfa>
    44#include "except-io.hfa"
    55
     
    1010        // Resume falls back to terminate.
    1111        try {
    12                 THROW_RESUME(&(star){});
     12                throwResume &(star){};
    1313        } catch (star *) {
    1414                printf("caught as termination\n");
     
    1717        try {
    1818                loud_region a = "try block with resume throw";
    19                 THROW_RESUME(&(star){});
     19                throwResume &(star){};
    2020        } catch (star *) {
    2121                printf("caught as termination\n");
     
    2929        try {
    3030                try {
    31                         THROW(&(star){});
     31                        throw &(star){};
    3232                } catchResume (star *) {
    3333                        printf("resume catch on terminate\n");
     
    4343        try {
    4444                try {
    45                         THROW_RESUME(&(star){});
     45                        throwResume &(star){};
    4646                } catch (star *) {
    4747                        printf("terminate catch on resume\n");
     
    5858                try {
    5959                        try {
    60                                 THROW(&(star){});
     60                                throw &(star){};
    6161                        } catchResume (star *) {
    6262                                printf("inner resume catch (error)\n");
     
    6464                } catch (star * error) {
    6565                        printf("termination catch, will resume\n");
    66                         THROW_RESUME(error);
     66                        throwResume error;
    6767                }
    6868        } catchResume (star *) {
     
    7575                try {
    7676                        try {
    77                                 THROW_RESUME(&(star){});
     77                                throwResume &(star){};
    7878                        } catch (star *) {
    7979                                printf("inner termination catch\n");
     
    8181                } catchResume (star * error) {
    8282                        printf("resumption catch, will terminate\n");
    83                         THROW(error);
     83                        throw error;
    8484                }
    8585        } catch (star *) {
     
    9494                                try {
    9595                                        printf("throwing resume moon\n");
    96                                         THROW_RESUME(&(moon){});
     96                                        throwResume &(moon){};
    9797                                } catch (star *) {
    9898                                        printf("termination catch\n");
    9999                                }
    100100                                printf("throwing resume star\n");
    101                                 THROW_RESUME(&(star){});
     101                                throwResume &(star){};
    102102                        } catchResume (star *) {
    103103                                printf("resumption star catch\n");
     
    105105                } catchResume (moon *) {
    106106                        printf("resumption moon catch, will terminate\n");
    107                         THROW(&(star){});
     107                        throw &(star){};
    108108                }
    109109        } catchResume (star *) {
  • tests/exceptions/resume.cfa

    rd6566c1 re68d092  
    11// Resumption Exception Tests
    22
    3 #include "except-mac.hfa"
     3#include <exception.hfa>
    44#include "except-io.hfa"
    55
     
    1414                loud_exit a = "simple try clause";
    1515                printf("simple throw\n");
    16                 THROW_RESUME(&(zen){});
     16                throwResume &(zen){};
    1717                printf("end of try clause\n");
    1818        } catchResume (zen * error) {
     
    2525        try {
    2626                printf("throwing child exception\n");
    27                 THROW_RESUME(&(moment_of){});
     27                throwResume &(moment_of){};
    2828        } catchResume (zen *) {
    2929                printf("inner parent match\n");
     
    3636        try {
    3737                try {
    38                         THROW_RESUME(&(yin){});
     38                        throwResume &(yin){};
    3939                } catchResume (zen *) {
    4040                        printf("caught yin as zen\n");
     
    5252                        loud_exit a = "rethrow inner try";
    5353                        printf("rethrow inner try\n");
    54                         THROW_RESUME(&(zen){});
     54                        throwResume &(zen){};
    5555                } catchResume (zen *) {
    5656                        loud_exit a = "rethrowing catch clause";
     
    6767        try {
    6868                try {
    69                         THROW_RESUME(&(yin){});
     69                        throwResume &(yin){};
    7070                } catchResume (yin *) {
    7171                        printf("caught yin, will throw yang\n");
    72                         THROW_RESUME(&(yang){});
     72                        throwResume &(yang){};
    7373                } catchResume (yang *) {
    7474                        printf("caught exception from same try\n");
     
    8383                try {
    8484                        printf("throwing first exception\n");
    85                         THROW_RESUME(&(yin){});
     85                        throwResume &(yin){};
    8686                } catchResume (yin *) {
    8787                        printf("caught first exception\n");
    8888                        try {
    8989                                printf("throwing second exception\n");
    90                                 THROW_RESUME(&(yang){});
     90                                throwResume &(yang){};
    9191                        } catchResume (yang *) {
    9292                                printf("caught second exception\n");
     
    104104        try {
    105105                try {
    106                         THROW_RESUME(&(zen){});
    107                         THROW_RESUME(&(zen){});
     106                        throwResume &(zen){};
     107                        throwResume &(zen){};
    108108                } catchResume (zen *) {
    109109                        printf("inner catch\n");
    110110                }
    111                 THROW_RESUME(&(zen){});
     111                throwResume &(zen){};
    112112        } catchResume (zen *) {
    113113                printf("outer catch\n");
  • tests/exceptions/terminate.cfa

    rd6566c1 re68d092  
    11// Termination Exception Tests
    22
    3 #include "except-mac.hfa"
     3#include <exception.hfa>
    44#include "except-io.hfa"
    55
     
    1414                loud_exit a = "simple try clause";
    1515                printf("simple throw\n");
    16                 THROW(&(zen){});
     16                throw &(zen){};
    1717                printf("end of try clause\n");
    1818        } catch (zen * error) {
     
    2525        try {
    2626                printf("throwing child exception\n");
    27                 THROW(&(moment_of){});
     27                throw &(moment_of){};
    2828        } catch (zen *) {
    2929                printf("inner parent match\n");
     
    3636        try {
    3737                try {
    38                         THROW(&(yin){});
     38                        throw &(yin){};
    3939                } catch (zen *) {
    4040                        printf("caught yin as zen\n");
     
    5252                        loud_exit a = "rethrow inner try";
    5353                        printf("rethrow inner try\n");
    54                         THROW(&(zen){});
     54                        throw &(zen){};
    5555                } catch (zen *) {
    5656                        loud_exit a = "rethrowing catch clause";
     
    6767        try {
    6868                try {
    69                         THROW(&(yin){});
     69                        throw &(yin){};
    7070                } catch (yin *) {
    7171                        printf("caught yin, will throw yang\n");
    72                         THROW(&(yang){});
     72                        throw &(yang){};
    7373                } catch (yang *) {
    7474                        printf("caught exception from same try\n");
     
    8383                try {
    8484                        printf("throwing first exception\n");
    85                         THROW(&(yin){});
     85                        throw &(yin){};
    8686                } catch (yin *) {
    8787                        printf("caught first exception\n");
    8888                        try {
    8989                                printf("throwing second exception\n");
    90                                 THROW(&(yang){});
     90                                throw &(yang){};
    9191                        } catch (yang *) {
    9292                                printf("caught second exception\n");
     
    104104        try {
    105105                try {
    106                         THROW(&(zen){});
    107                         THROW(&(zen){});
     106                        throw &(zen){};
     107                        throw &(zen){};
    108108                } catch (zen *) {
    109109                        printf("inner catch\n");
    110110                }
    111                 THROW(&(zen){});
     111                throw &(zen){};
    112112        } catch (zen *) {
    113113                printf("outer catch\n");
Note: See TracChangeset for help on using the changeset viewer.