Ignore:
Timestamp:
Apr 9, 2021, 2:11:43 PM (10 months ago)
Author:
Andrew Beach <ajbeach@…>
Branches:
arm-eh, jacob/cs343-translation, master, new-ast-unique-expr
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/conditional.cfa

    re07b589 recfd758  
    66#include <exception.hfa>
    77
    8 VTABLE_DECLARATION(num_error)(
    9         int (*code)(num_error *this);
     8EHM_EXCEPTION(num_error)(
     9        int num;
    1010);
    1111
    12 struct num_error {
    13         VTABLE_FIELD(num_error);
    14     char * msg;
    15     int num;
    16 };
    17 
    18 const char * num_error_msg(num_error * this) {
    19     if ( ! this->msg ) {
    20         static const char * base = "Num Error with code: X";
    21         this->msg = (char *)malloc(22);
    22         for (int i = 0 ; (this->msg[i] = base[i]) ; ++i);
    23     }
    24     this->msg[21] = '0' + this->num;
    25     return this->msg;
    26 }
    27 void ?{}(num_error & this, int num) {
    28         VTABLE_INIT(this, num_error);
    29     this.msg = 0;
    30     this.num = num;
    31 }
    32 void ?{}(num_error & this, num_error & other) {
    33     this.virtual_table = other.virtual_table;
    34     this.msg = 0;
    35     this.num = other.num;
    36 }
    37 void ^?{}(num_error & this) {
    38     if( this.msg ) free( this.msg );
    39 }
    40 int num_error_code( num_error * this ) {
    41     return this->num;
    42 }
    43 
    44 VTABLE_INSTANCE(num_error)(
    45         num_error_msg,
    46         num_error_code,
    47 );
     12EHM_VIRTUAL_TABLE(num_error, num_error_vt);
    4813
    4914void caught_num_error(int expect, num_error * actual) {
     
    5217
    5318int main(int argc, char * argv[]) {
    54         num_error exc = 2;
     19        num_error exc = {&num_error_vt, 2};
    5520
    5621        try {
    5722                throw exc;
    58         } catch (num_error * error ; 3 == error->virtual_table->code( error )) {
     23        } catch (num_error * error ; 3 == error->num ) {
    5924                caught_num_error(3, error);
    60         } catch (num_error * error ; 2 == error->virtual_table->code( error )) {
     25        } catch (num_error * error ; 2 == error->num ) {
    6126                caught_num_error(2, error);
    6227        }
     
    6429        try {
    6530                throwResume exc;
    66         } catchResume (num_error * error ; 3 == error->virtual_table->code( error )) {
     31        } catchResume (num_error * error ; 3 == error->num ) {
    6732                caught_num_error(3, error);
    68         } catchResume (num_error * error ; 2 == error->virtual_table->code( error )) {
     33        } catchResume (num_error * error ; 2 == error->num ) {
    6934                caught_num_error(2, error);
    7035        }
Note: See TracChangeset for help on using the changeset viewer.