#include <fstream>
#include <coroutine>

coroutine Fibonacci {
      int fn; // used for communication
};

void ?{}(Fibonacci* this) {
      this->fn = 0;
}

void main(Fibonacci* this) {
      int fn1, fn2; 		// retained between resumes
      this->fn = 0;
      fn1 = this->fn;
      suspend(); 		// return to last resume

      this->fn = 1;
      fn2 = fn1;
      fn1 = this->fn;
      suspend(); 		// return to last resume

      for ( ;; ) {
            this->fn = fn1 + fn2;
            fn2 = fn1;
            fn1 = this->fn;
            suspend(); 	// return to last resume
      }
}

int next(Fibonacci* this) {
      resume(this); // transfer to last suspend
      return this->fn;
}

int main() {
      Fibonacci f1, f2;
      for ( int i = 1; i <= 10; i += 1 ) {
            sout | next(&f1) | ' ' | next(&f2) | endl;
      }

      return 0;
}
