Ignore:
Timestamp:
Apr 9, 2021, 2:11:43 PM (3 years ago)
Author:
Andrew Beach <ajbeach@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
b91bfde
Parents:
e07b589
Message:

Major exception update, seperating type-ids from virtual tables. The major interface changes are done. There is a regression of ?Cancelled(T) to Some?Cancelled. There is some bits of code for the new verion of the ?Cancelled(T) interface already there. Not connected yet but I just reached the limit of what I wanted to do in one commit and then spent over a day cleaning up, so it will replace Some?Cancelled in a future commit.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tests/exceptions/defaults.cfa

    re07b589 recfd758  
    44#include <exception.hfa>
    55
    6 DATA_EXCEPTION(log_message)(
     6EHM_EXCEPTION(log_message)(
    77        char * msg;
    88);
    99
    10 void ?{}(log_message & this, char * msg) {
    11         VTABLE_INIT(this, log_message);
    12         this.msg = msg;
    13 }
    14 
    15 const char * get_log_message(log_message * this) {
     10_EHM_DEFINE_COPY(log_message, )
     11const char * msg(log_message * this) {
    1612        return this->msg;
    1713}
    18 
    19 VTABLE_INSTANCE(log_message)(get_log_message);
     14_EHM_VIRTUAL_TABLE(log_message, , log_vt);
    2015
    2116// Logging messages don't have to be handled.
     
    2823        // We can catch log:
    2924        try {
    30                 throwResume (log_message){"Should be printed.\n"};
     25                throwResume (log_message){&log_vt, "Should be printed.\n"};
    3126        } catchResume (log_message * this) {
    3227                printf("%s", this->virtual_table->msg(this));
    3328        }
    3429        // But we don't have to:
    35         throwResume (log_message){"Should not be printed.\n"};
     30        throwResume (log_message){&log_vt, "Should not be printed.\n"};
    3631}
    3732
    3833// I don't have a good use case for doing the same with termination.
    39 TRIVIAL_EXCEPTION(jump);
     34EHM_EXCEPTION(jump)();
    4035void defaultTerminationHandler(jump &) {
    4136        printf("jump default handler.\n");
    4237}
    4338
     39EHM_VIRTUAL_TABLE(jump, jump_vt);
     40
    4441void jump_test(void) {
    4542        try {
    46                 throw (jump){};
     43                throw (jump){&jump_vt};
    4744        } catch (jump * this) {
    4845                printf("jump catch handler.\n");
    4946        }
    50         throw (jump){};
     47        throw (jump){&jump_vt};
    5148}
    5249
    53 TRIVIAL_EXCEPTION(first);
    54 TRIVIAL_EXCEPTION(unhandled_exception);
     50EHM_EXCEPTION(first)();
     51EHM_VIRTUAL_TABLE(first, first_vt);
     52
     53EHM_EXCEPTION(unhandled_exception)();
     54EHM_VIRTUAL_TABLE(unhandled_exception, unhandled_vt);
    5555
    5656void unhandled_test(void) {
    5757        forall(T &, V & | is_exception(T, V))
    5858        void defaultTerminationHandler(T &) {
    59                 throw (unhandled_exception){};
     59                throw (unhandled_exception){&unhandled_vt};
    6060        }
    6161        void defaultTerminationHandler(unhandled_exception &) {
     
    6363        }
    6464        try {
    65                 throw (first){};
     65                throw (first){&first_vt};
    6666        } catch (unhandled_exception * t) {
    6767                printf("Catch unhandled_exception.\n");
     
    6969}
    7070
    71 TRIVIAL_EXCEPTION(second);
     71EHM_EXCEPTION(second)();
     72EHM_VIRTUAL_TABLE(second, second_vt);
    7273
    7374void cross_test(void) {
    7475        void defaultTerminationHandler(first &) {
    7576                printf("cross terminate default\n");
    76                 throw (second){};
     77                throw (second){&second_vt};
    7778        }
    7879        void defaultResumptionHandler(first &) {
    7980                printf("cross resume default\n");
    80                 throwResume (second){};
     81                throwResume (second){&second_vt};
    8182        }
    8283        try {
    8384                printf("cross terminate throw\n");
    84                 throw (first){};
     85                throw (first){&first_vt};
    8586        } catch (second *) {
    8687                printf("cross terminate catch\n");
     
    8889        try {
    8990                printf("cross resume throw\n");
    90                 throwResume (first){};
     91                throwResume (first){&first_vt};
    9192        } catchResume (second *) {
    9293                printf("cross resume catch\n");
Note: See TracChangeset for help on using the changeset viewer.