source: tests/exceptions/polymorphic.cfa @ 01f78e0

ADTast-experimentalenumforall-pointer-decayjacob/cs343-translationpthread-emulationqualifiedEnum
Last change on this file since 01f78e0 was d00d581, checked in by Henry Xue <y58xue@…>, 3 years ago

Update exception tests to use new syntax

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