Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/tests/coroutine.c

    r5c81105 rd9c44c3  
    33
    44struct Fibonacci {
     5      coroutine c;
     6      coVtable v;
    57      int fn; // used for communication
    6       covptr_t v;
    7       coroutine c;
    88};
    99
     10coroutine* this_coroutine(Fibonacci* this);
    1011void co_main(Fibonacci* this);
    11 covptr_t* vtable(Fibonacci* this);
     12coVtable* vtable(Fibonacci* this);
    1213
    13 //GENERATED in proposal for virtuals
    1414void co_main_fib(void* this) {
    1515      co_main( (Fibonacci*) this );
    1616}
    1717
    18 //GENERATED in proposal for virtuals
    19 static coVtable_t FibonacciVtable = {
    20       co_main_fib,
    21       VPTR_OFFSET(Fibonacci, v, c),
    22       VPTR_OFFSET(Fibonacci, v, fn)     
    23 };
     18coroutine* this_coroutine_fib(void* this) {
     19      return this_coroutine( (Fibonacci*) this);
     20}
    2421
    2522void ?{}(Fibonacci* this) {
    2623      this->fn = 0;
    27       this->v = &FibonacciVtable;  //GENERATED in proposal for virtuals
    28       (&this->c) { &this->v };
     24      this->v.main = co_main_fib;
     25      this->v.this_coroutine = this_coroutine_fib;
     26      start(this);
    2927}
    3028
     
    3230#ifdef MORE_DEBUG
    3331      sout | "Starting main of coroutine " | this | endl;
    34       sout | "Started from " | this->c.last | endl;
     32      sout | "Started from " | this_coroutine(this)->last | endl;
    3533#endif
    3634      int fn1, fn2;             // retained between resumes
     
    5755}
    5856
    59 covptr_t* vtable(Fibonacci* this) {
     57coroutine* this_coroutine(Fibonacci* this) {
     58      return &this->c;
     59}
     60
     61coVtable* vtable(Fibonacci* this) {
    6062      return &this->v;
    6163}
     
    6466      Fibonacci f1, f2;
    6567#ifdef MORE_DEBUG     
    66       Fibonacci *pf1 = &f1, *pf2 = &f2;
    67       coroutine *cf1 = &f1.c, *cf2 = &f2.c;
    68       covptr_t  *vf1 = vtable(pf1), *vf2 = vtable(pf2);
    69       coroutine *cv1 = get_coroutine(vf1), *cv2 = get_coroutine(vf2);
    70       Fibonacci *ov1 = (Fibonacci *)get_object(vf1), *ov2 = (Fibonacci *)get_object(vf2);
    71 
    72       sout | "User coroutines : " | pf1 | ' ' | pf2 | endl;
    73       sout | "Coroutine data  : " | cf1 | ' ' | cf2 | endl;
    74       sout | "Vptr address    : " | vf1 | ' ' | vf2 | endl;
    75       sout | "Vptr obj data   : " | ov1 | ' ' | ov2 | endl;
    76       sout | "Vptr cor data   : " | cv1 | ' ' | cv2 | endl;
     68      sout | "User coroutines : " | &f1 | ' ' | &f1 | endl;
    7769#endif
    7870      for ( int i = 1; i <= 10; i += 1 ) {
Note: See TracChangeset for help on using the changeset viewer.