
#ifndef CONTEXT_SWITCHER_ASSEMBLY_BINDINGS_H_
#define CONTEXT_SWITCHER_ASSEMBLY_BINDINGS_H_

/**
 * Low level bindings to the two assembly functions used to switch context.
 * Can be used standalone to build new control structures, but should be handled with care.
 *
 * Basic usage:
 * // Switch control to a new stack.
 * continuation_t cont = __cs_enter_context(my_stack, arg_pointer, callback_func, my_stack_limit);
 * // Will only be run when 'jumped back' by either returning the callback or an explicit jump.
 * // cont will then hold the context of the jump origin (or null if it was a return form a finished callback).
 * cont = __switch_context(cont);
 * // Re-Enter the context that jumped to us.
 */

namespace context_switcher {
namespace assembly_bindings {

using continuation_t = void *;
using stack_pointer_t = char *;
using callback_t = continuation_t (*)(continuation_t, void *);

extern "C" {
continuation_t __cs_enter_context(stack_pointer_t stack_base,
                                  void *callback_arg,
                                  callback_t callback,
                                  stack_pointer_t stack_limit);
continuation_t __cs_switch_context(continuation_t continuation);
}

}
}

#endif //CONTEXT_SWITCHER_ASSEMBLY_BINDINGS_H_
