ADT
        ast-experimental
        enum
        forall-pointer-decay
        jacob/cs343-translation
        new-ast-unique-expr
        pthread-emulation
        qualifiedEnum
      
      
        
          | 
            Last change
 on this file since 47e413b was             b583113, checked in by Andrew Beach <ajbeach@…>, 5 years ago           | 
        
        
          | 
             
Recovered the polymorphic CoroutineCancelled exception. The interface might need a bit of polish. 
 
           | 
        
        
          
            
              - 
Property                 mode
 set to                 
100644
               
             
           | 
        
        
          | 
            File size:
            682 bytes
           | 
        
      
      
| Line |   | 
|---|
| 1 | // Try cancelling a coroutine.
 | 
|---|
| 2 | 
 | 
|---|
| 3 | #include <coroutine.hfa>
 | 
|---|
| 4 | #include <exception.hfa>
 | 
|---|
| 5 | 
 | 
|---|
| 6 | EHM_EXCEPTION(internal_error)();
 | 
|---|
| 7 | EHM_VIRTUAL_TABLE(internal_error, internal_vt);
 | 
|---|
| 8 | 
 | 
|---|
| 9 | coroutine WillCancel {};
 | 
|---|
| 10 | 
 | 
|---|
| 11 | const char * msg(CoroutineCancelled(WillCancel) * this) {
 | 
|---|
| 12 |         return "CoroutineCancelled(WillCancel)";
 | 
|---|
| 13 | }
 | 
|---|
| 14 | 
 | 
|---|
| 15 | void main(WillCancel & wc) {
 | 
|---|
| 16 |         printf("1");
 | 
|---|
| 17 |         cancel_stack((internal_error){&internal_vt});
 | 
|---|
| 18 |         printf("!");
 | 
|---|
| 19 | }
 | 
|---|
| 20 | 
 | 
|---|
| 21 | int 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.