From 901bbaac8ae54ebc922e576c6830085d4759d48e Mon Sep 17 00:00:00 2001 From: Avril Date: Thu, 18 Mar 2021 20:00:45 +0000 Subject: [PATCH] starting --- include/state.h | 4 +++ src/main.cpp | 66 ----------------------------------------------- src/test/main.cpp | 11 ++++++++ 3 files changed, 15 insertions(+), 66 deletions(-) delete mode 100644 src/main.cpp create mode 100644 src/test/main.cpp diff --git a/include/state.h b/include/state.h index bd18b71..a389770 100644 --- a/include/state.h +++ b/include/state.h @@ -77,5 +77,9 @@ inline sm_yield sm_continue() { return (sm_yield)_sm_noop; } #define SM_YIELD(v) do { state->current->pc = __LINE__; return (sm_yield)(v); case __LINE__:; } while(0) +#define SM_GENERATOR(name) sm_yield name(sm_state* state) + +// --- + sm_state* sm_new_state(); void sm_free_state(sm_state* state); diff --git a/src/main.cpp b/src/main.cpp deleted file mode 100644 index 7a243a6..0000000 --- a/src/main.cpp +++ /dev/null @@ -1,66 +0,0 @@ -#include -#include - -#include - -struct _test { - int a, b; -}; - -sm_yield sm_test_2(sm_state* state) -{ - int* a = SM_VAR(-10); - - SM_BEGIN; - while( (*a) < 0 ) { - printf("(2) a = %d\n", *a); - SM_YIELD(sm_continue()); - (*a)+=1; - } - printf("Done!\n"); - SM_END; -} - -sm_yield sm_test(sm_state* state) -{ - int* a = SM_VAR(10); - - auto c = SM_SLOT(_test); - float* d = SM_SLOT(float); - - *c = { 200, 300 }; - *d = 10.f; - - SM_BEGIN; - *a = 5; - SM_YIELD(sm_continue()); - printf("a = %d\n", *a); - *a = 0; - SM_YIELD(sm_continue()); - printf("a = %d\n", *a); - printf("Starting function 2\n"); - SM_YIELD(sm_test_2); - printf("2 done\n"); - SM_END; -} - -int main() -{ - - auto state = sm_new_state(); - auto gen = sm_generate(&sm_test); - - while(sm_next(&gen, state)) (void)0; - - sm_free_generator(gen); - sm_free_state(state); - - /* - //TODO: `sm_state` creation/initialisation & freeing functions - //TODO: Test `sm_test` - - _test hi = { 0, 0 }; - auto _a = _sm_init(nullptr, hi); - */ - return 0; -} diff --git a/src/test/main.cpp b/src/test/main.cpp new file mode 100644 index 0000000..df602b1 --- /dev/null +++ b/src/test/main.cpp @@ -0,0 +1,11 @@ +#include + +SM_GENERATOR(read_number) +{ + +} + +int main() +{ + return 0; +}