#include <utility>
#include <cstdio>

#include "context_switcher/context_switcher.h"
using namespace context_switcher;
using namespace std;

// Memory for custom stack and continuation semantics
const size_t STACK_SIZE = 512 * 16;
const size_t NUM_STACKS = 4;
char custom_stacks[NUM_STACKS][STACK_SIZE];

volatile int result;

int main() {
  context_switcher::continuation outer_cont = enter_context(custom_stacks[0], STACK_SIZE, [](continuation &&main_cont) {
    enter_context(custom_stacks[1], STACK_SIZE, [&main_cont](continuation &&middle_cont) {
      enter_context(custom_stacks[2], STACK_SIZE, [&main_cont](continuation &&inner_cont) {
        for (int i = 0; i < 10; i++) {
          printf("Inner %d\n", i);
          main_cont = context_switcher::switch_context(std::move(main_cont));
        }

        return std::move(inner_cont);
      });

      return std::move(middle_cont);
    });

    return std::move(main_cont);
  });

  for (int i = 0; i < 10; i++) {
    printf("Outer %d\n", i);
    outer_cont = context_switcher::switch_context(std::move(outer_cont));
  }

  return 0;
}
