source: tests/exceptions/polymorphic.cfa @ 091011a

ADTarm-ehast-experimentalenumforall-pointer-decayjacob/cs343-translationnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since 091011a was ecfd758, checked in by Andrew Beach <ajbeach@…>, 4 years ago

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.

  • Property mode set to 100644
File size: 1.2 KB
Line 
1// Testing polymophic exception types.
2
3#include <exception.hfa>
4
5EHM_FORALL_EXCEPTION(proxy, (T&), (T))();
6
7EHM_FORALL_VIRTUAL_TABLE(proxy, (int), proxy_int);
8EHM_FORALL_VIRTUAL_TABLE(proxy, (char), proxy_char);
9
10void proxy_test(void) {
11        proxy(int) an_int = {&proxy_int};
12        proxy(char) a_char = {&proxy_char};
13
14    try {
15                throw an_int;
16        } catch (proxy(int) *) {
17                printf("terminate catch\n");
18        }
19
20        try {
21                throwResume a_char;
22        } catchResume (proxy(char) *) {
23                printf("resume catch\n");
24        }
25
26        try {
27                throw a_char;
28        } catch (proxy(int) *) {
29                printf("caught proxy(int)\n");
30        } catch (proxy(char) *) {
31                printf("caught proxy(char)\n");
32        }
33}
34
35EHM_FORALL_EXCEPTION(cell, (T), (T))(
36        T data;
37);
38
39EHM_FORALL_VIRTUAL_TABLE(cell, (int), int_cell);
40EHM_FORALL_VIRTUAL_TABLE(cell, (char), char_cell);
41EHM_FORALL_VIRTUAL_TABLE(cell, (bool), bool_cell);
42
43void cell_test(void) {
44        try {
45                cell(int) except = {&int_cell, -7};
46                throw except;
47        } catch (cell(int) * error) {
48                printf("%d\n", error->data);
49        }
50
51        try {
52                cell(bool) ball = {&bool_cell, false};
53                throwResume ball;
54                printf("%i\n", ball.data);
55        } catchResume (cell(bool) * error) {
56                printf("%i\n", error->data);
57                error->data = true;
58        }
59}
60
61int main(int argc, char * argv[]) {
62        proxy_test();
63        printf("\n");
64        cell_test();
65}
Note: See TracBrowser for help on using the repository browser.