From efee5ecf7cd3cd9cb229f3836e0b942aa0c87723 Mon Sep 17 00:00:00 2001 From: Oliver Kowalke Date: Mon, 22 May 2017 06:51:18 +0200 Subject: [PATCH] cleanup examples directory --- example/{callcc => }/Jamfile.v2 | 2 +- example/{callcc => }/backtrace.cpp | 0 example/{callcc => }/echosse.cpp | 0 example/ecv1/Jamfile.v2 | 51 --------- example/ecv1/fibonacci.cpp | 32 ------ example/ecv1/jump.cpp | 44 -------- example/ecv1/ontop.cpp | 45 -------- example/ecv1/parameter.cpp | 51 --------- example/ecv1/parser.cpp | 139 ------------------------- example/ecv1/segmented.cpp | 54 ---------- example/ecv2/Jamfile.v2 | 68 ------------ example/ecv2/backtrace.cpp | 58 ----------- example/ecv2/echosse.cpp | 43 -------- example/ecv2/fibonacci.cpp | 38 ------- example/ecv2/jump.cpp | 32 ------ example/ecv2/jump_void.cpp | 31 ------ example/ecv2/ontop.cpp | 42 -------- example/ecv2/ontop_void.cpp | 40 ------- example/ecv2/parameter.cpp | 62 ----------- example/ecv2/parser.cpp | 144 -------------------------- example/ecv2/throw.cpp | 45 -------- example/{callcc => }/endless_loop.cpp | 0 example/{callcc => }/fibonacci.cpp | 0 example/{callcc => }/jump.cpp | 0 example/{callcc => }/jump_mov.cpp | 0 example/{callcc => }/jump_ref.cpp | 0 example/{callcc => }/jump_void.cpp | 0 example/{callcc => }/ontop.cpp | 0 example/{callcc => }/ontop_void.cpp | 0 example/{callcc => }/parser.cpp | 0 example/{callcc => }/segmented.cpp | 0 example/{callcc => }/throw.cpp | 0 example/{callcc => }/types.cpp | 0 33 files changed, 1 insertion(+), 1020 deletions(-) rename example/{callcc => }/Jamfile.v2 (96%) rename example/{callcc => }/backtrace.cpp (100%) rename example/{callcc => }/echosse.cpp (100%) delete mode 100644 example/ecv1/Jamfile.v2 delete mode 100644 example/ecv1/fibonacci.cpp delete mode 100644 example/ecv1/jump.cpp delete mode 100644 example/ecv1/ontop.cpp delete mode 100644 example/ecv1/parameter.cpp delete mode 100644 example/ecv1/parser.cpp delete mode 100644 example/ecv1/segmented.cpp delete mode 100644 example/ecv2/Jamfile.v2 delete mode 100644 example/ecv2/backtrace.cpp delete mode 100644 example/ecv2/echosse.cpp delete mode 100644 example/ecv2/fibonacci.cpp delete mode 100644 example/ecv2/jump.cpp delete mode 100644 example/ecv2/jump_void.cpp delete mode 100644 example/ecv2/ontop.cpp delete mode 100644 example/ecv2/ontop_void.cpp delete mode 100644 example/ecv2/parameter.cpp delete mode 100644 example/ecv2/parser.cpp delete mode 100644 example/ecv2/throw.cpp rename example/{callcc => }/endless_loop.cpp (100%) rename example/{callcc => }/fibonacci.cpp (100%) rename example/{callcc => }/jump.cpp (100%) rename example/{callcc => }/jump_mov.cpp (100%) rename example/{callcc => }/jump_ref.cpp (100%) rename example/{callcc => }/jump_void.cpp (100%) rename example/{callcc => }/ontop.cpp (100%) rename example/{callcc => }/ontop_void.cpp (100%) rename example/{callcc => }/parser.cpp (100%) rename example/{callcc => }/segmented.cpp (100%) rename example/{callcc => }/throw.cpp (100%) rename example/{callcc => }/types.cpp (100%) diff --git a/example/callcc/Jamfile.v2 b/example/Jamfile.v2 similarity index 96% rename from example/callcc/Jamfile.v2 rename to example/Jamfile.v2 index 7059a76..6da224f 100644 --- a/example/callcc/Jamfile.v2 +++ b/example/Jamfile.v2 @@ -15,7 +15,7 @@ import os ; import toolset ; import architecture ; -project boost/context/example/execution_context +project boost/context/example : requirements /boost/context//boost_context gcc,on:-fsplit-stack diff --git a/example/callcc/backtrace.cpp b/example/backtrace.cpp similarity index 100% rename from example/callcc/backtrace.cpp rename to example/backtrace.cpp diff --git a/example/callcc/echosse.cpp b/example/echosse.cpp similarity index 100% rename from example/callcc/echosse.cpp rename to example/echosse.cpp diff --git a/example/ecv1/Jamfile.v2 b/example/ecv1/Jamfile.v2 deleted file mode 100644 index 3789fea..0000000 --- a/example/ecv1/Jamfile.v2 +++ /dev/null @@ -1,51 +0,0 @@ -# Boost.Context Library Examples Jamfile - -# Copyright Oliver Kowalke 2014. -# Distributed under the Boost Software License, Version 1.0. -# (See accompanying file LICENSE_1_0.txt or copy at -# http://www.boost.org/LICENSE_1_0.txt) - -# For more information, see http://www.boost.org/ - -import common ; -import feature ; -import indirect ; -import modules ; -import os ; -import toolset ; -import architecture ; - -project boost/context/example/execution_context - : requirements - /boost/context//boost_context - gcc,on:-fsplit-stack - gcc,on:-DBOOST_USE_SEGMENTED_STACKS - clang,on:-fsplit-stack - clang,on:-DBOOST_USE_SEGMENTED_STACKS - static - multi - ; - -exe jump - : jump.cpp - ; - -exe segmented - : segmented.cpp - ; - -exe parser - : parser.cpp - ; - -exe fibonacci - : fibonacci.cpp - ; - -exe parameter - : parameter.cpp - ; - -exe ontop - : ontop.cpp - ; diff --git a/example/ecv1/fibonacci.cpp b/example/ecv1/fibonacci.cpp deleted file mode 100644 index cee4fc4..0000000 --- a/example/ecv1/fibonacci.cpp +++ /dev/null @@ -1,32 +0,0 @@ - -// Copyright Oliver Kowalke 2014. -// Distributed under the Boost Software License, Version 1.0. -// (See accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt) - -#include -#include -#include - -#include - -int main() { - int n=35; - boost::context::execution_context sink( boost::context::execution_context::current() ); - boost::context::execution_context source( - [n,&sink](void*)mutable{ - int a=0; - int b=1; - while(n-->0){ - sink(&a); - auto next=a+b; - a=b; - b=next; - } - }); - for(int i=0;i<10;++i){ - std::cout<<*(int*)source()<<" "; - } - std::cout << "\nmain: done" << std::endl; - return EXIT_SUCCESS; -} diff --git a/example/ecv1/jump.cpp b/example/ecv1/jump.cpp deleted file mode 100644 index 030df08..0000000 --- a/example/ecv1/jump.cpp +++ /dev/null @@ -1,44 +0,0 @@ - -// Copyright Oliver Kowalke 2014. -// Distributed under the Boost Software License, Version 1.0. -// (See accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt) - -#include -#include - -#include - -boost::context::execution_context * ctx1 = nullptr; -boost::context::execution_context * ctx2 = nullptr; -boost::context::execution_context * ctx = nullptr; - -void f1( int i, void *) { - std::cout << "f1: entered" << std::endl; - std::cout << "i == " << i << std::endl; - ( * ctx2)(); - std::cout << "f1: re-entered" << std::endl; - ( * ctx2)(); -} - -void f2( void *) { - std::cout << "f2: entered" << std::endl; - ( * ctx1)(); - std::cout << "f2: re-entered" << std::endl; - ( * ctx)(); -} - -int main() { - { - boost::context::execution_context ctx1_( f1, 3); - ctx1 = & ctx1_; - boost::context::execution_context ctx2_( f2); - ctx2 = & ctx2_; - boost::context::execution_context ctx_( boost::context::execution_context::current() ); - ctx = & ctx_; - - ( * ctx1)(); - } - std::cout << "main: done" << std::endl; - return EXIT_SUCCESS; -} diff --git a/example/ecv1/ontop.cpp b/example/ecv1/ontop.cpp deleted file mode 100644 index 9498588..0000000 --- a/example/ecv1/ontop.cpp +++ /dev/null @@ -1,45 +0,0 @@ - -// Copyright Oliver Kowalke 2014. -// Distributed under the Boost Software License, Version 1.0. -// (See accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt) - -#include -#include - -#include - -boost::context::execution_context * ctx1 = nullptr; -boost::context::execution_context * ctx = nullptr; - -void f1( void *) { - std::cout << "f1: entered first time" << std::endl; - ( * ctx)(); - std::cout << "f1: entered second time" << std::endl; - ( * ctx)(); - std::cout << "f1: entered third time" << std::endl; - ( * ctx)(); -} - -void * f2( void * data) { - std::cout << "f2: entered" << std::endl; - return data; -} - -int main() { - boost::context::execution_context ctx1_( f1); - ctx1 = & ctx1_; - boost::context::execution_context ctx_( boost::context::execution_context::current() ); - ctx = & ctx_; - - ( * ctx1)(); - std::cout << "f1: returned first time" << std::endl; - ( * ctx1)(); - std::cout << "f1: returned second time" << std::endl; - ( * ctx1)( boost::context::exec_ontop_arg, f2); - std::cout << "f1: returned third time" << std::endl; - - std::cout << "main: done" << std::endl; - - return EXIT_SUCCESS; -} diff --git a/example/ecv1/parameter.cpp b/example/ecv1/parameter.cpp deleted file mode 100644 index 5923ba2..0000000 --- a/example/ecv1/parameter.cpp +++ /dev/null @@ -1,51 +0,0 @@ - -// Copyright Oliver Kowalke 2014. -// Distributed under the Boost Software License, Version 1.0. -// (See accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt) - -#include -#include -#include -#include -#include - -#include -#include - -class X{ -private: - std::exception_ptr excptr_; - boost::context::execution_context caller_; - boost::context::execution_context callee_; - -public: - X(): - excptr_(), - caller_(boost::context::execution_context::current()), - callee_( [this]( void * vp){ - try { - int i = * static_cast< int * >( vp); - std::string str = boost::lexical_cast(i); - caller_( & str); - } catch ( std::bad_cast const&) { - excptr_=std::current_exception(); - } - }) - {} - - std::string operator()(int i){ - void * ret = callee_( & i); - if(excptr_){ - std::rethrow_exception(excptr_); - } - return * static_cast< std::string * >( ret); - } -}; - -int main() { - X x; - std::cout< -#include -#include -#include -#include -#include - -#include - -/* - * grammar: - * P ---> E '\0' - * E ---> T {('+'|'-') T} - * T ---> S {('*'|'/') S} - * S ---> digit | '(' E ')' - */ -class Parser{ - char next; - std::istream& is; - std::function cb; - - char pull(){ - return std::char_traits::to_char_type(is.get()); - } - - void scan(){ - do{ - next=pull(); - } - while(isspace(next)); - } - -public: - Parser(std::istream& is_,std::function cb_) : - next(), is(is_), cb(cb_) - {} - - void run() { - scan(); - E(); - } - -private: - void E(){ - T(); - while (next=='+'||next=='-'){ - cb(next); - scan(); - T(); - } - } - - void T(){ - S(); - while (next=='*'||next=='/'){ - cb(next); - scan(); - S(); - } - } - - void S(){ - if (isdigit(next)){ - cb(next); - scan(); - } - else if(next=='('){ - cb(next); - scan(); - E(); - if (next==')'){ - cb(next); - scan(); - }else{ - throw std::runtime_error("parsing failed"); - } - } - else{ - throw std::runtime_error("parsing failed"); - } - } -}; - -int main() { - try { - std::istringstream is("1+1"); - bool done=false; - std::exception_ptr except; - - // create handle to main execution context - auto sink(boost::context::execution_context::current()); - // execute parser in new execution context - boost::context::execution_context source( - [&sink,&is,&done,&except](void*){ - // create parser with callback function - Parser p(is, - [&sink](char ch){ - // resume main execution context - sink(&ch); - }); - try { - // start recursive parsing - p.run(); - } catch (...) { - // store other exceptions in exception-pointer - except = std::current_exception(); - } - // set termination flag - done=true; - // resume main execution context - sink(); - }); - - // user-code pulls parsed data from parser - // invert control flow - void* vp = source(); - if (except) { - std::rethrow_exception(except); - } - while( ! done) { - printf("Parsed: %c\n",* static_cast(vp)); - vp = source(); - if (except) { - std::rethrow_exception(except); - } - } - std::cout << "main: done" << std::endl; - return EXIT_SUCCESS; - } catch ( std::exception const& e) { - std::cerr << "exception: " << e.what() << std::endl; - } - return EXIT_FAILURE; -} diff --git a/example/ecv1/segmented.cpp b/example/ecv1/segmented.cpp deleted file mode 100644 index ab640a2..0000000 --- a/example/ecv1/segmented.cpp +++ /dev/null @@ -1,54 +0,0 @@ - -// Copyright Oliver Kowalke 2014. -// Distributed under the Boost Software License, Version 1.0. -// (See accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt) - -#include -#include -#include - -#include - -#include - -#ifdef BOOST_MSVC //MS VisualStudio -__declspec(noinline) void access( char *buf); -#else // GCC -void access( char *buf) __attribute__ ((noinline)); -#endif -void access( char *buf) { - buf[0] = '\0'; -} - -void bar( int i) { - char buf[4 * 1024]; - if ( i > 0) { - access( buf); - std::cout << i << ". iteration" << std::endl; - bar( i - 1); - } -} - -int main() { - int count = 384; -#if defined(BOOST_USE_SEGMENTED_STACKS) - std::cout << "using segmented_stack stacks: allocates " << count << " * 4kB == " << 4 * count << "kB on stack, "; - std::cout << "initial stack size = " << boost::context::segmented_stack::traits_type::default_size() / 1024 << "kB" << std::endl; - std::cout << "application should not fail" << std::endl; -#else - std::cout << "using standard stacks: allocates " << count << " * 4kB == " << 4 * count << "kB on stack, "; - std::cout << "initial stack size = " << boost::context::fixedsize_stack::traits_type::default_size() / 1024 << "kB" << std::endl; - std::cout << "application might fail" << std::endl; -#endif - boost::context::execution_context main_ctx( - boost::context::execution_context::current() ); - boost::context::execution_context bar_ctx( - [& main_ctx, count]( void *){ - bar( count); - main_ctx(); - }); - bar_ctx(); - std::cout << "main: done" << std::endl; - return EXIT_SUCCESS; -} diff --git a/example/ecv2/Jamfile.v2 b/example/ecv2/Jamfile.v2 deleted file mode 100644 index 5f26a8a..0000000 --- a/example/ecv2/Jamfile.v2 +++ /dev/null @@ -1,68 +0,0 @@ -# Boost.Context Library Examples Jamfile - -# Copyright Oliver Kowalke 2014. -# Distributed under the Boost Software License, Version 1.0. -# (See accompanying file LICENSE_1_0.txt or copy at -# http://www.boost.org/LICENSE_1_0.txt) - -# For more information, see http://www.boost.org/ - -import common ; -import feature ; -import indirect ; -import modules ; -import os ; -import toolset ; -import architecture ; - -project boost/context/example/execution_context - : requirements - /boost/context//boost_context - gcc,on:-fsplit-stack - gcc,on:-DBOOST_USE_SEGMENTED_STACKS - clang,on:-fsplit-stack - clang,on:-DBOOST_USE_SEGMENTED_STACKS - static - multi - ; - -exe jump_void - : jump_void.cpp - ; - -exe jump - : jump.cpp - ; - -exe fibonacci - : fibonacci.cpp - ; - -exe parser - : parser.cpp - ; - -exe parameter - : parameter.cpp - ; - -exe ontop_void - : ontop_void.cpp - ; - -exe ontop - : ontop.cpp - ; - -exe throw - : throw.cpp - ; - -exe echosse - : echosse.cpp - ; - -#exe backtrace -# : backtrace.cpp -# : "-lunwind" -# ; diff --git a/example/ecv2/backtrace.cpp b/example/ecv2/backtrace.cpp deleted file mode 100644 index a855c25..0000000 --- a/example/ecv2/backtrace.cpp +++ /dev/null @@ -1,58 +0,0 @@ - -// Copyright Oliver Kowalke 2014. -// Distributed under the Boost Software License, Version 1.0. -// (See accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt) - -#define UNW_LOCAL_ONLY - -#include -#include - -#include - -#include - -namespace ctx = boost::context; - -void backtrace() { - unw_cursor_t cursor; - unw_context_t context; - unw_getcontext( & context); - unw_init_local( & cursor, & context); - while ( 0 < unw_step( & cursor) ) { - unw_word_t offset, pc; - unw_get_reg( & cursor, UNW_REG_IP, & pc); - if ( 0 == pc) { - break; - } - std::cout << "0x" << pc << ":"; - - char sym[256]; - if ( 0 == unw_get_proc_name( & cursor, sym, sizeof( sym), & offset) ) { - std::cout << " (" << sym << "+0x" << offset << ")" << std::endl; - } else { - std::cout << " -- error: unable to obtain symbol name for this frame" << std::endl; - } - } -} - -void bar() { - backtrace(); -} - -void foo() { - bar(); -} - -ctx::execution_context< void > f1( ctx::execution_context< void > && ctxm) { - foo(); - return std::move( ctxm); -} - -int main() { - ctx::execution_context< void > ctx1( f1); - ctx1 = ctx1(); - std::cout << "main: done" << std::endl; - return EXIT_SUCCESS; -} diff --git a/example/ecv2/echosse.cpp b/example/ecv2/echosse.cpp deleted file mode 100644 index 7252c15..0000000 --- a/example/ecv2/echosse.cpp +++ /dev/null @@ -1,43 +0,0 @@ - -// Copyright Oliver Kowalke 2009. -// Distributed under the Boost Software License, Version 1.0. -// (See accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt) - -#include -#include -#include -#include -#include - -#include - -void echoSSE( int i) { - __m128i xmm; - xmm = _mm_set_epi32( i, i + 1, i + 2, i + 3); - uint32_t v32[4]; - memcpy( & v32, & xmm, 16); - std::cout << v32[0]; - std::cout << v32[1]; - std::cout << v32[2]; - std::cout << v32[3]; -} - -boost::context::execution_context< int > echo( boost::context::execution_context< int > && ctx, int i) { - for (;;) { - std::cout << i; - echoSSE( i); - std::cout << " "; - std::tie( ctx, i) = ctx( 0); - } - return std::move( ctx); -} - -int main( int argc, char * argv[]) { - boost::context::execution_context< int > ctx( echo); - for ( int i = 0; i < 10; ++i) { - ctx = std::get< 0 >( ctx( i) ); - } - std::cout << "\nDone" << std::endl; - return EXIT_SUCCESS; -} diff --git a/example/ecv2/fibonacci.cpp b/example/ecv2/fibonacci.cpp deleted file mode 100644 index 56de1fe..0000000 --- a/example/ecv2/fibonacci.cpp +++ /dev/null @@ -1,38 +0,0 @@ - -// Copyright Oliver Kowalke 2014. -// Distributed under the Boost Software License, Version 1.0. -// (See accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt) - -#include -#include -#include - -#include - -namespace ctx = boost::context; - -int main() { - int n=35; - ctx::execution_context< int > source( - [n](ctx::execution_context< int > && sink, int) mutable { - int a=0; - int b=1; - while(n-->0){ - auto result=sink(a); - sink=std::move(std::get<0>(result)); - auto next=a+b; - a=b; - b=next; - } - return std::move( sink); - }); - for(int i=0;i<10;++i){ - auto result=source(i); - source=std::move(std::get<0>(result)); - std::cout<(result)<<" "; - } - std::cout< -#include - -#include - -namespace ctx = boost::context; - -ctx::execution_context< int > f1( ctx::execution_context< int > && ctxm, int data) { - std::cout << "f1: entered first time: " << data << std::endl; - std::tie( ctxm, data) = ctxm( data + 2); - std::cout << "f1: entered second time: " << data << std::endl; - return std::move( ctxm); -} - -int main() { - int data = 1; - ctx::execution_context< int > ctx1( f1); - std::tie( ctx1, data) = ctx1( data + 2); - std::cout << "f1: returned first time: " << data << std::endl; - std::tie( ctx1, data) = ctx1( data + 2); - std::cout << "f1: returned second time: " << data << std::endl; - - std::cout << "main: done" << std::endl; - - return EXIT_SUCCESS; -} diff --git a/example/ecv2/jump_void.cpp b/example/ecv2/jump_void.cpp deleted file mode 100644 index e95264b..0000000 --- a/example/ecv2/jump_void.cpp +++ /dev/null @@ -1,31 +0,0 @@ - -// Copyright Oliver Kowalke 2014. -// Distributed under the Boost Software License, Version 1.0. -// (See accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt) - -#include -#include - -#include - -namespace ctx = boost::context; - -ctx::execution_context< void > f1( ctx::execution_context< void > && ctxm) { - std::cout << "f1: entered first time" << std::endl; - ctxm = ctxm(); - std::cout << "f1: entered second time" << std::endl; - return std::move( ctxm); -} - -int main() { - ctx::execution_context< void > ctx1( f1); - ctx1 = ctx1(); - std::cout << "f1: returned first time" << std::endl; - ctx1 = ctx1(); - std::cout << "f1: returned second time" << std::endl; - - std::cout << "main: done" << std::endl; - - return EXIT_SUCCESS; -} diff --git a/example/ecv2/ontop.cpp b/example/ecv2/ontop.cpp deleted file mode 100644 index 8051e0b..0000000 --- a/example/ecv2/ontop.cpp +++ /dev/null @@ -1,42 +0,0 @@ - -// Copyright Oliver Kowalke 2014. -// Distributed under the Boost Software License, Version 1.0. -// (See accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt) - -#include -#include -#include - -#include - -namespace ctx = boost::context; - -ctx::execution_context< int > f1( ctx::execution_context< int > && ctx, int data) { - std::cout << "f1: entered first time: " << data << std::endl; - std::tie( ctx, data) = ctx( data + 1); - std::cout << "f1: entered second time: " << data << std::endl; - std::tie( ctx, data) = ctx( data + 1); - std::cout << "f1: entered third time: " << data << std::endl; - return std::move( ctx); -} - -int f2( int data) { - std::cout << "f2: entered: " << data << std::endl; - return -1; -} - -int main() { - int data = 0; - ctx::execution_context< int > ctx( f1); - std::tie( ctx, data) = ctx( data + 1); - std::cout << "f1: returned first time: " << data << std::endl; - std::tie( ctx, data) = ctx( data + 1); - std::cout << "f1: returned second time: " << data << std::endl; - std::tie( ctx, data) = ctx( ctx::exec_ontop_arg, f2, data + 1); - std::cout << "f1: returned third time" << std::endl; - - std::cout << "main: done" << std::endl; - - return EXIT_SUCCESS; -} diff --git a/example/ecv2/ontop_void.cpp b/example/ecv2/ontop_void.cpp deleted file mode 100644 index 20b9fc6..0000000 --- a/example/ecv2/ontop_void.cpp +++ /dev/null @@ -1,40 +0,0 @@ - -// Copyright Oliver Kowalke 2014. -// Distributed under the Boost Software License, Version 1.0. -// (See accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt) - -#include -#include -#include - -#include - -namespace ctx = boost::context; - -ctx::execution_context< void > f1( ctx::execution_context< void > && ctx) { - std::cout << "f1: entered first time" << std::endl; - ctx = ctx(); - std::cout << "f1: entered second time" << std::endl; - ctx = ctx(); - std::cout << "f1: entered third time" << std::endl; - return std::move( ctx); -} - -void f2() { - std::cout << "f2: entered" << std::endl; -} - -int main() { - ctx::execution_context< void > ctx( f1); - ctx = ctx(); - std::cout << "f1: returned first time" << std::endl; - ctx = ctx(); - std::cout << "f1: returned second time" << std::endl; - ctx = ctx( ctx::exec_ontop_arg, f2); - std::cout << "f1: returned third time" << std::endl; - - std::cout << "main: done" << std::endl; - - return EXIT_SUCCESS; -} diff --git a/example/ecv2/parameter.cpp b/example/ecv2/parameter.cpp deleted file mode 100644 index 7c4f459..0000000 --- a/example/ecv2/parameter.cpp +++ /dev/null @@ -1,62 +0,0 @@ - -// Copyright Oliver Kowalke 2014. -// Distributed under the Boost Software License, Version 1.0. -// (See accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt) - -#include -#include -#include -#include -#include - -#include -#include -#include - -typedef boost::variant variant_t; - -namespace ctx = boost::context; - -class X{ -private: - std::exception_ptr excptr_; - ctx::execution_context ctx_; - -public: - X(): - excptr_(), - ctx_( - [this](ctx::execution_context && ctx, variant_t data){ - try { - for (;;) { - int i = boost::get(data); - data = boost::lexical_cast(i); - auto result = ctx( data); - ctx = std::move( std::get<0>( result) ); - data = std::get<1>( result); - } - } catch ( std::bad_cast const&) { - excptr_=std::current_exception(); - } - return std::move( ctx); - }) - {} - - std::string operator()(int i){ - variant_t data = i; - auto result = ctx_( data); - ctx_ = std::move( std::get<0>( result) ); - data = std::get<1>( result); - if(excptr_){ - std::rethrow_exception(excptr_); - } - return boost::get(data); - } -}; - -int main() { - X x; - std::cout< -#include -#include -#include -#include -#include - -#include - -namespace ctx = boost::context; - -/* - * grammar: - * P ---> E '\0' - * E ---> T {('+'|'-') T} - * T ---> S {('*'|'/') S} - * S ---> digit | '(' E ')' - */ -class Parser{ - char next; - std::istream& is; - std::function cb; - - char pull(){ - return std::char_traits::to_char_type(is.get()); - } - - void scan(){ - do{ - next=pull(); - } - while(isspace(next)); - } - -public: - Parser(std::istream& is_,std::function cb_) : - next(), is(is_), cb(cb_) - {} - - void run() { - scan(); - E(); - } - -private: - void E(){ - T(); - while (next=='+'||next=='-'){ - cb(next); - scan(); - T(); - } - } - - void T(){ - S(); - while (next=='*'||next=='/'){ - cb(next); - scan(); - S(); - } - } - - void S(){ - if (isdigit(next)){ - cb(next); - scan(); - } - else if(next=='('){ - cb(next); - scan(); - E(); - if (next==')'){ - cb(next); - scan(); - }else{ - throw std::runtime_error("parsing failed"); - } - } - else{ - throw std::runtime_error("parsing failed"); - } - } -}; - -int main() { - try { - std::istringstream is("1+1"); - bool done=false; - std::exception_ptr except; - - // execute parser in new execution context - boost::context::execution_context source( - [&is,&done,&except](ctx::execution_context && sink,char){ - // create parser with callback function - Parser p( is, - [&sink](char ch){ - // resume main execution context - auto result = sink(ch); - sink = std::move(std::get<0>(result)); - }); - try { - // start recursive parsing - p.run(); - } catch (...) { - // store other exceptions in exception-pointer - except = std::current_exception(); - } - // set termination flag - done=true; - // resume main execution context - return std::move( sink); - }); - - // user-code pulls parsed data from parser - // invert control flow - auto result = source('\0'); - source = std::move(std::get<0>(result)); - char c = std::get<1>(result); - if ( except) { - std::rethrow_exception(except); - } - while( ! done) { - printf("Parsed: %c\n",c); - std::tie(source,c) = source('\0'); - if (except) { - std::rethrow_exception(except); - } - } - - std::cout << "main: done" << std::endl; - - return EXIT_SUCCESS; - } catch ( std::exception const& e) { - std::cerr << "exception: " << e.what() << std::endl; - } - return EXIT_FAILURE; -} diff --git a/example/ecv2/throw.cpp b/example/ecv2/throw.cpp deleted file mode 100644 index 6b0193e..0000000 --- a/example/ecv2/throw.cpp +++ /dev/null @@ -1,45 +0,0 @@ - -// Copyright Oliver Kowalke 2014. -// Distributed under the Boost Software License, Version 1.0. -// (See accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt) - -#include -#include -#include -#include -#include - -#include - -struct my_exception : public std::runtime_error { - my_exception( std::string const& what) : - std::runtime_error{ what } { - } -}; - -int main() { - boost::context::execution_context< void > ctx([](boost::context::execution_context && ctx) { - for (;;) { - try { - std::cout << "entered" << std::endl; - ctx = ctx(); - } catch ( boost::context::ontop_error const& e) { - try { - std::rethrow_if_nested( e); - } catch ( my_exception const& ex) { - std::cerr << "my_exception: " << ex.what() << std::endl; - } - return e.get_context< void >(); - } - } - return std::move( ctx); - }); - ctx = ctx(); - ctx = ctx(); - ctx = ctx( boost::context::exec_ontop_arg, []() { throw my_exception("abc"); }); - - std::cout << "main: done" << std::endl; - - return EXIT_SUCCESS; -} diff --git a/example/callcc/endless_loop.cpp b/example/endless_loop.cpp similarity index 100% rename from example/callcc/endless_loop.cpp rename to example/endless_loop.cpp diff --git a/example/callcc/fibonacci.cpp b/example/fibonacci.cpp similarity index 100% rename from example/callcc/fibonacci.cpp rename to example/fibonacci.cpp diff --git a/example/callcc/jump.cpp b/example/jump.cpp similarity index 100% rename from example/callcc/jump.cpp rename to example/jump.cpp diff --git a/example/callcc/jump_mov.cpp b/example/jump_mov.cpp similarity index 100% rename from example/callcc/jump_mov.cpp rename to example/jump_mov.cpp diff --git a/example/callcc/jump_ref.cpp b/example/jump_ref.cpp similarity index 100% rename from example/callcc/jump_ref.cpp rename to example/jump_ref.cpp diff --git a/example/callcc/jump_void.cpp b/example/jump_void.cpp similarity index 100% rename from example/callcc/jump_void.cpp rename to example/jump_void.cpp diff --git a/example/callcc/ontop.cpp b/example/ontop.cpp similarity index 100% rename from example/callcc/ontop.cpp rename to example/ontop.cpp diff --git a/example/callcc/ontop_void.cpp b/example/ontop_void.cpp similarity index 100% rename from example/callcc/ontop_void.cpp rename to example/ontop_void.cpp diff --git a/example/callcc/parser.cpp b/example/parser.cpp similarity index 100% rename from example/callcc/parser.cpp rename to example/parser.cpp diff --git a/example/callcc/segmented.cpp b/example/segmented.cpp similarity index 100% rename from example/callcc/segmented.cpp rename to example/segmented.cpp diff --git a/example/callcc/throw.cpp b/example/throw.cpp similarity index 100% rename from example/callcc/throw.cpp rename to example/throw.cpp diff --git a/example/callcc/types.cpp b/example/types.cpp similarity index 100% rename from example/callcc/types.cpp rename to example/types.cpp