source: tests/exceptions/cancel/coroutine.cfa @ 1c01c58

arm-ehjacob/cs343-translationnew-ast-unique-expr
Last change on this file since 1c01c58 was 1c01c58, checked in by Andrew Beach <ajbeach@…>, 14 months ago

Rather large commit to get coroutine cancellation working.

This includes what you would expect, like new code in exceptions and a new
test, but it also includes a bunch of other things.

New coroutine state, currently just marks that the stack was cancelled. New
helpers for checking code structure and generating vtables. Changes to the
coroutine interface so resume may throw exceptions on cancellation, plus the
exception type that is thrown. Changes to the coroutine keyword generation to
generate exception code for each type of coroutine.

  • Property mode set to 100644
File size: 643 bytes
Line 
1// Try cancelling a coroutine.
2
3#include <stdio.h>
4#include <coroutine.hfa>
5#include <exception.hfa>
6
7TRIVIAL_EXCEPTION(internal_error);
8
9coroutine WillCancel {};
10
11const char * msg(CoroutineCancelled(WillCancel) * this) {
12        return "CoroutineCancelled(WillCancel)";
13}
14
15void main(WillCancel & wc) {
16        printf("1");
17        cancel_stack((internal_error){});
18        printf("!");
19}
20
21int main(int argc, char * argv[]) {
22        WillCancel cancel;
23        try {
24                printf("0");
25                resume(cancel);
26                printf("4");
27        } catchResume (CoroutineCancelled(WillCancel) * error) {
28                printf("2");
29                if ((virtual internal_error *)error->the_exception) {
30                        printf("3");
31                }
32        }
33        printf("5\n");
34}
Note: See TracBrowser for help on using the repository browser.