diff options
author | Stefan Radomski <sradomski@mintwerk.de> | 2016-01-26 08:32:56 (GMT) |
---|---|---|
committer | Stefan Radomski <sradomski@mintwerk.de> | 2016-01-26 08:32:56 (GMT) |
commit | 18bca76b4f4d81db962e97cfe79611461a8b7e61 (patch) | |
tree | 5131964dc562082fc3274cea8de3aa25ec0d455e /test/src/test-c-machine.machine.c | |
parent | 762eb95910cd4dfad6a84f97332b7549b2fdbd69 (diff) | |
download | uscxml-18bca76b4f4d81db962e97cfe79611461a8b7e61.zip uscxml-18bca76b4f4d81db962e97cfe79611461a8b7e61.tar.gz uscxml-18bca76b4f4d81db962e97cfe79611461a8b7e61.tar.bz2 |
Some code beautifications
Diffstat (limited to 'test/src/test-c-machine.machine.c')
-rw-r--r-- | test/src/test-c-machine.machine.c | 398 |
1 files changed, 131 insertions, 267 deletions
diff --git a/test/src/test-c-machine.machine.c b/test/src/test-c-machine.machine.c index 09e7703..2b991ff 100644 --- a/test/src/test-c-machine.machine.c +++ b/test/src/test-c-machine.machine.c @@ -1,9 +1,9 @@ #include <stdint.h> // explicit types #include <stddef.h> // NULL -#define IS_SET(idx, bitset) ((bitset[idx >> 3] & (1 << (idx & 7))) != 0) -#define SET_BIT(idx, bitset) bitset[idx >> 3] |= (1 << (idx & 7)); -#define CLEARBIT(idx, bitset) bitset[idx >> 3] &= (1 << (idx & 7)) ^ 0xFF; +#define BIT_HAS(idx, bitset) ((bitset[idx >> 3] & (1 << (idx & 7))) != 0) +#define BIT_SET_AT(idx, bitset) bitset[idx >> 3] |= (1 << (idx & 7)); +#define BIT_CLEAR(idx, bitset) bitset[idx >> 3] &= (1 << (idx & 7)) ^ 0xFF; #ifdef __GNUC__ #define likely(x) (__builtin_expect(!!(x), 1)) @@ -25,8 +25,8 @@ #define SCXML_ERR_UNSUPPORTED 8 #define SCXML_MACHINE_NAME "" -#define SCXML_NUMBER_STATES 10 -#define SCXML_NUMBER_TRANSITIONS 5 +#define SCXML_NUMBER_STATES 5 +#define SCXML_NUMBER_TRANSITIONS 1 #define SCXML_TRANS_SPONTANEOUS 0x01 #define SCXML_TRANS_TARGETLESS 0x02 @@ -99,22 +99,22 @@ struct scxml_state { const exec_content_t on_entry; // on entry handlers const exec_content_t on_exit; // on exit handlers const invoke_t invoke; // invocations - const char children[2]; // all children - const char completion[2]; // default completion - const char ancestors[2]; // all ancestors + const char children[1]; // all children + const char completion[1]; // default completion + const char ancestors[1]; // all ancestors const scxml_elem_data* data; const uint8_t type; // atomic, parallel, compound, final, history }; struct scxml_transition { const uint8_t source; - const char target[2]; + const char target[1]; const char* event; const char* condition; const exec_content_t on_transition; const uint8_t type; const char conflicts[1]; - const char exit_set[2]; + const char exit_set[1]; }; struct scxml_elem_foreach { @@ -171,10 +171,10 @@ struct scxml_elem_send { struct scxml_ctx { uint8_t flags; - char config[2]; - char history[2]; - char pending_invokes[2]; - char initialized_data[2]; + char config[1]; + char history[1]; + char pending_invokes[1]; + char initialized_data[1]; void* user_data; void* event; @@ -198,12 +198,6 @@ struct scxml_ctx { invoke_t invoke; }; -static const scxml_elem_data scxml_elem_datas[2] = { - /* id, src, expr, content */ - { "Var1", NULL, "0", NULL }, - { NULL, NULL, NULL, NULL } -}; - static const scxml_elem_donedata scxml_elem_donedatas[1] = { /* source, content, contentexpr, params */ { 0, NULL, NULL, NULL } @@ -213,47 +207,17 @@ static int global_script(const scxml_ctx* ctx, const scxml_state* state, const v return SCXML_ERR_OK; } -static int s0_0_0_on_entry_0(const scxml_ctx* ctx, const scxml_state* state, const void* event) { - int err = SCXML_ERR_OK; - if likely(ctx->exec_content_assign != NULL) { - if ((ctx->exec_content_assign(ctx, "Var1", "Var1 + 1")) != SCXML_ERR_OK) return err; - } else { - return SCXML_ERR_MISSING_CALLBACK; - } - return SCXML_ERR_OK; -} - -static int s0_0_0_on_entry(const scxml_ctx* ctx, const scxml_state* state, const void* event) { - s0_0_0_on_entry_0(ctx, state, event); - return SCXML_ERR_OK; -} - -static int s1_on_entry_0(const scxml_ctx* ctx, const scxml_state* state, const void* event) { - int err = SCXML_ERR_OK; - if likely(ctx->exec_content_assign != NULL) { - if ((ctx->exec_content_assign(ctx, "Var1", "Var1 + 1")) != SCXML_ERR_OK) return err; - } else { - return SCXML_ERR_MISSING_CALLBACK; - } - return SCXML_ERR_OK; -} - -static int s1_on_entry(const scxml_ctx* ctx, const scxml_state* state, const void* event) { - s1_on_entry_0(ctx, state, event); - return SCXML_ERR_OK; -} - -static const scxml_state scxml_states[10] = { +static const scxml_state scxml_states[5] = { { /* state number 0 */ /* name */ NULL, /* parent */ 0, /* onentry */ NULL, /* onexit */ NULL, /* invoke */ NULL, - /* children */ { 0x82, 0x03 /* 0100000111, 1 7 8 9 */ }, - /* completion */ { 0x02, 0x00 /* 0100000000, 1 */ }, - /* ancestors */ { 0x00, 0x00 /* 0000000000, */ }, - /* data */ &scxml_elem_datas[0], + /* children */ { 0x1a /* 01011, 1 3 4 */ }, + /* completion */ { 0x02 /* 01000, 1 */ }, + /* ancestors */ { 0x00 /* 00000, */ }, + /* data */ NULL, /* type */ SCXML_STATE_COMPOUND, }, { /* state number 1 */ @@ -262,170 +226,62 @@ static const scxml_state scxml_states[10] = { /* onentry */ NULL, /* onexit */ NULL, /* invoke */ NULL, - /* children */ { 0x0c, 0x00 /* 0011000000, 2 3 */ }, - /* completion */ { 0x08, 0x00 /* 0001000000, 3 */ }, - /* ancestors */ { 0x01, 0x00 /* 1000000000, 0 */ }, + /* children */ { 0x04 /* 00100, 2 */ }, + /* completion */ { 0x04 /* 00100, 2 */ }, + /* ancestors */ { 0x01 /* 10000, 0 */ }, /* data */ NULL, - /* type */ SCXML_STATE_COMPOUND | SCXML_STATE_HAS_HISTORY, + /* type */ SCXML_STATE_COMPOUND, }, { /* state number 2 */ - /* name */ "h0", - /* parent */ 1, - /* onentry */ NULL, - /* onexit */ NULL, - /* invoke */ NULL, - /* children */ { 0x00, 0x00 /* 0000000000, */ }, - /* completion */ { 0x08, 0x00 /* 0001000000, 3 */ }, - /* ancestors */ { 0x03, 0x00 /* 1100000000, 0 1 */ }, - /* data */ NULL, - /* type */ SCXML_STATE_HISTORY_DEEP | SCXML_STATE_HAS_HISTORY, - }, - { /* state number 3 */ /* name */ "s0.0", /* parent */ 1, /* onentry */ NULL, /* onexit */ NULL, /* invoke */ NULL, - /* children */ { 0x70, 0x00 /* 0000111000, 4 5 6 */ }, - /* completion */ { 0x20, 0x00 /* 0000010000, 5 */ }, - /* ancestors */ { 0x03, 0x00 /* 1100000000, 0 1 */ }, - /* data */ NULL, - /* type */ SCXML_STATE_COMPOUND | SCXML_STATE_HAS_HISTORY, - }, - { /* state number 4 */ - /* name */ "h1", - /* parent */ 3, - /* onentry */ NULL, - /* onexit */ NULL, - /* invoke */ NULL, - /* children */ { 0x00, 0x00 /* 0000000000, */ }, - /* completion */ { 0x60, 0x00 /* 0000011000, 5 6 */ }, - /* ancestors */ { 0x0b, 0x00 /* 1101000000, 0 1 3 */ }, - /* data */ NULL, - /* type */ SCXML_STATE_HISTORY_DEEP, - }, - { /* state number 5 */ - /* name */ "s0.0.0", - /* parent */ 3, - /* onentry */ s0_0_0_on_entry, - /* onexit */ NULL, - /* invoke */ NULL, - /* children */ { 0x00, 0x00 /* 0000000000, */ }, - /* completion */ { 0x00, 0x00 /* 0000000000, */ }, - /* ancestors */ { 0x0b, 0x00 /* 1101000000, 0 1 3 */ }, - /* data */ NULL, - /* type */ SCXML_STATE_ATOMIC, - }, - { /* state number 6 */ - /* name */ "s0.0.1", - /* parent */ 3, - /* onentry */ NULL, - /* onexit */ NULL, - /* invoke */ NULL, - /* children */ { 0x00, 0x00 /* 0000000000, */ }, - /* completion */ { 0x00, 0x00 /* 0000000000, */ }, - /* ancestors */ { 0x0b, 0x00 /* 1101000000, 0 1 3 */ }, - /* data */ NULL, - /* type */ SCXML_STATE_ATOMIC, - }, - { /* state number 7 */ - /* name */ "s1", - /* parent */ 0, - /* onentry */ s1_on_entry, - /* onexit */ NULL, - /* invoke */ NULL, - /* children */ { 0x00, 0x00 /* 0000000000, */ }, - /* completion */ { 0x00, 0x00 /* 0000000000, */ }, - /* ancestors */ { 0x01, 0x00 /* 1000000000, 0 */ }, + /* children */ { 0x00 /* 00000, */ }, + /* completion */ { 0x00 /* 00000, */ }, + /* ancestors */ { 0x03 /* 11000, 0 1 */ }, /* data */ NULL, /* type */ SCXML_STATE_ATOMIC, }, - { /* state number 8 */ + { /* state number 3 */ /* name */ "pass", /* parent */ 0, /* onentry */ NULL, /* onexit */ NULL, /* invoke */ NULL, - /* children */ { 0x00, 0x00 /* 0000000000, */ }, - /* completion */ { 0x00, 0x00 /* 0000000000, */ }, - /* ancestors */ { 0x01, 0x00 /* 1000000000, 0 */ }, + /* children */ { 0x00 /* 00000, */ }, + /* completion */ { 0x00 /* 00000, */ }, + /* ancestors */ { 0x01 /* 10000, 0 */ }, /* data */ NULL, /* type */ SCXML_STATE_FINAL, }, - { /* state number 9 */ + { /* state number 4 */ /* name */ "fail", /* parent */ 0, /* onentry */ NULL, /* onexit */ NULL, /* invoke */ NULL, - /* children */ { 0x00, 0x00 /* 0000000000, */ }, - /* completion */ { 0x00, 0x00 /* 0000000000, */ }, - /* ancestors */ { 0x01, 0x00 /* 1000000000, 0 */ }, + /* children */ { 0x00 /* 00000, */ }, + /* completion */ { 0x00 /* 00000, */ }, + /* ancestors */ { 0x01 /* 10000, 0 */ }, /* data */ NULL, /* type */ SCXML_STATE_FINAL, } }; -static const scxml_transition scxml_transitions[5] = { +static const scxml_transition scxml_transitions[1] = { { /* transition number 0 with priority 0 - target: s0.0.1 - */ - /* name */ 5, - /* target */ { 0x40, 0x00 /* 0000001000, 6 */ }, - /* event */ NULL, - /* condition */ "Var1 == 1", - /* ontrans */ NULL, - /* type */ SCXML_TRANS_SPONTANEOUS, - /* conflicts */ { 0x0f /* 11110, 0 1 2 3 */ }, - /* exit set */ { 0x70, 0x00 /* 0000111000, 4 5 6 */ } - }, - { /* transition number 1 with priority 1 - target: s1 - */ - /* name */ 6, - /* target */ { 0x80, 0x00 /* 0000000100, 7 */ }, - /* event */ NULL, - /* condition */ "Var1 == 1", - /* ontrans */ NULL, - /* type */ SCXML_TRANS_SPONTANEOUS, - /* conflicts */ { 0x0f /* 11110, 0 1 2 3 */ }, - /* exit set */ { 0xfe, 0x03 /* 0111111111, 1 2 3 4 5 6 7 8 9 */ } - }, - { /* transition number 2 with priority 2 - target: pass - */ - /* name */ 1, - /* target */ { 0x00, 0x01 /* 0000000010, 8 */ }, - /* event */ NULL, - /* condition */ "Var1 == 2", - /* ontrans */ NULL, - /* type */ SCXML_TRANS_SPONTANEOUS, - /* conflicts */ { 0x0f /* 11110, 0 1 2 3 */ }, - /* exit set */ { 0xfe, 0x03 /* 0111111111, 1 2 3 4 5 6 7 8 9 */ } - }, - { /* transition number 3 with priority 3 - target: fail + target: */ - /* name */ 1, - /* target */ { 0x00, 0x02 /* 0000000001, 9 */ }, + /* source */ 2, + /* target */ { NULL }, /* event */ NULL, /* condition */ NULL, /* ontrans */ NULL, - /* type */ SCXML_TRANS_SPONTANEOUS, - /* conflicts */ { 0x0f /* 11110, 0 1 2 3 */ }, - /* exit set */ { 0xfe, 0x03 /* 0111111111, 1 2 3 4 5 6 7 8 9 */ } - }, - { /* transition number 4 with priority 4 - target: h0 - */ - /* name */ 7, - /* target */ { 0x04, 0x00 /* 0010000000, 2 */ }, - /* event */ NULL, - /* condition */ "Var1 == 2", - /* ontrans */ NULL, - /* type */ SCXML_TRANS_SPONTANEOUS, - /* conflicts */ { 0x10 /* 00001, 4 */ }, - /* exit set */ { 0x00, 0x00 /* 0000000000, */ } + /* type */ SCXML_TRANS_TARGETLESS | SCXML_TRANS_SPONTANEOUS, + /* conflicts */ { 0x01 /* 1, 0 */ }, + /* exit set */ { 0x00 /* 00000, */ } } }; @@ -433,7 +289,7 @@ static const scxml_transition scxml_transitions[5] = { static void printStateNames(const char* a) { const char* seperator = ""; for (size_t i = 0; i < SCXML_NUMBER_STATES; i++) { - if (IS_SET(i, a)) { + if (BIT_HAS(i, a)) { printf("%s%s", seperator, (scxml_states[i].name != NULL ? scxml_states[i].name : "UNK")); seperator = ", "; } @@ -444,7 +300,7 @@ static void printStateNames(const char* a) { static void printBitsetIndices(const char* a, size_t length) { const char* seperator = ""; for (size_t i = 0; i < length; i++) { - if (IS_SET(i, a)) { + if (BIT_HAS(i, a)) { printf("%s%lu", seperator, i); seperator = ", "; } @@ -453,44 +309,44 @@ static void printBitsetIndices(const char* a, size_t length) { } #endif -static void bit_or(char* dest, const char* mask, size_t i) { +static int bit_has_and(const char* a, const char* b, size_t i) { do { - dest[i - 1] |= mask[i - 1]; + if (a[i - 1] & b[i - 1]) + return true; } while(--i); + return false; } -static void bit_copy(char* dest, const char* source, size_t i) { +static int bit_has_any(const char* a, size_t i) { do { - dest[i - 1] = source[i - 1]; + if (a[i - 1] > 0) + return true; } while(--i); + return false; } -static int bit_has_and(const char* a, const char* b, size_t i) { +static void bit_or(char* dest, const char* mask, size_t i) { do { - if (a[i - 1] & b[i - 1]) - return true; + dest[i - 1] |= mask[i - 1]; } while(--i); - return false; } -static void bit_and_not(char* dest, const char* mask, size_t i) { +static void bit_copy(char* dest, const char* source, size_t i) { do { - dest[i - 1] &= ~mask[i - 1]; + dest[i - 1] = source[i - 1]; } while(--i); } -static void bit_and(char* dest, const char* mask, size_t i) { +static void bit_and_not(char* dest, const char* mask, size_t i) { do { - dest[i - 1] &= mask[i - 1]; + dest[i - 1] &= ~mask[i - 1]; } while(--i); } -static int bit_any_set(const char* a, size_t i) { +static void bit_and(char* dest, const char* mask, size_t i) { do { - if (a[i - 1] > 0) - return true; + dest[i - 1] &= mask[i - 1]; } while(--i); - return false; } int scxml_step(scxml_ctx* ctx) { @@ -501,21 +357,21 @@ int scxml_step(scxml_ctx* ctx) { #endif // MACRO_STEP: - ctx->flags &= ~SCXML_CTX_TRANSITION_FOUND; if (ctx->flags & SCXML_CTX_TOP_LEVEL_FINAL) return SCXML_ERR_DONE; int err = SCXML_ERR_OK; char conflicts[1] = {0}; - char target_set[2] = {0, 0}; - char exit_set[2] = {0, 0}; + char target_set[1] = {0}; + char exit_set[1] = {0}; char trans_set[1] = {0}; - char entry_set[2] = {0, 0}; + char entry_set[1] = {0}; + char tmp_states[1] = {0}; if unlikely(ctx->flags == SCXML_CTX_PRISTINE) { global_script(ctx, &scxml_states[0], NULL); - bit_or(target_set, scxml_states[0].completion, 2); + bit_or(target_set, scxml_states[0].completion, 1); ctx->flags |= SCXML_CTX_SPONTANEOUS | SCXML_CTX_INITIALIZED; goto ESTABLISH_ENTRY_SET; } @@ -538,9 +394,9 @@ SELECT_TRANSITIONS: continue; // is the transition active? - if (IS_SET(scxml_transitions[i].source, ctx->config)) { + if (BIT_HAS(scxml_transitions[i].source, ctx->config)) { // is it non-conflicting? - if (!IS_SET(i, conflicts)) { + if (!BIT_HAS(i, conflicts)) { // is it enabled? if (ctx->is_enabled(ctx, &scxml_transitions[i], ctx->event) > 0) { // remember that we found a transition @@ -550,20 +406,21 @@ SELECT_TRANSITIONS: bit_or(conflicts, scxml_transitions[i].conflicts, 1); // states that are directly targeted (resolve as entry-set later) - bit_or(target_set, scxml_transitions[i].target, 2); + bit_or(target_set, scxml_transitions[i].target, 1); // states that will be left - bit_or(exit_set, scxml_transitions[i].exit_set, 2); + bit_or(exit_set, scxml_transitions[i].exit_set, 1); - SET_BIT(i, trans_set); + BIT_SET_AT(i, trans_set); } } } } - bit_and(exit_set, ctx->config, 2); + bit_and(exit_set, ctx->config, 1); if (ctx->flags & SCXML_CTX_TRANSITION_FOUND) { ctx->flags |= SCXML_CTX_SPONTANEOUS; + ctx->flags &= ~SCXML_CTX_TRANSITION_FOUND; } else { ctx->flags &= ~SCXML_CTX_SPONTANEOUS; } @@ -588,72 +445,79 @@ SELECT_TRANSITIONS: if unlikely(SCXML_STATE_MASK(scxml_states[i].type) == SCXML_STATE_HISTORY_SHALLOW || SCXML_STATE_MASK(scxml_states[i].type) == SCXML_STATE_HISTORY_DEEP) { // a history state whose parent is about to be exited - if unlikely(IS_SET(scxml_states[i].parent, exit_set)) { - char history[2] = {0, 0}; - bit_copy(history, scxml_states[i].completion, 2); + if unlikely(BIT_HAS(scxml_states[i].parent, exit_set)) { + bit_copy(tmp_states, scxml_states[i].completion, 1); // set those states who were enabled - bit_and(history, ctx->config, 2); + bit_and(tmp_states, ctx->config, 1); - // clear current history with completion mask - TODO: errornously clears nested history - bit_and_not(ctx->history, scxml_states[i].completion, 2); + // clear current history with completion mask + bit_and_not(ctx->history, scxml_states[i].completion, 1); // set history - bit_or(ctx->history, history, 2); + bit_or(ctx->history, tmp_states, 1); } } } ESTABLISH_ENTRY_SET: // calculate new entry set - bit_copy(entry_set, target_set, 2); + bit_copy(entry_set, target_set, 1); // iterate for ancestors for (size_t i = 0; i < SCXML_NUMBER_STATES; i++) { - if (IS_SET(i, entry_set)) { - bit_or(entry_set, scxml_states[i].ancestors, 2); + if (BIT_HAS(i, entry_set)) { + bit_or(entry_set, scxml_states[i].ancestors, 1); } } // iterate for descendants for (size_t i = 0; i < SCXML_NUMBER_STATES; i++) { - if (IS_SET(i, entry_set)) { + if (BIT_HAS(i, entry_set)) { switch (SCXML_STATE_MASK(scxml_states[i].type)) { case SCXML_STATE_PARALLEL: { - bit_or(entry_set, scxml_states[i].completion, 2); + bit_or(entry_set, scxml_states[i].completion, 1); break; } case SCXML_STATE_HISTORY_SHALLOW: case SCXML_STATE_HISTORY_DEEP: { - char history_targets[2] = {0, 0}; - if (!bit_has_and(scxml_states[i].completion, ctx->history, 2) && - !IS_SET(scxml_states[i].parent, ctx->config)) { - // nothing set for history, look for a default transition or enter parents completion + if (!bit_has_and(scxml_states[i].completion, ctx->history, 1) && + !BIT_HAS(scxml_states[i].parent, ctx->config)) { + // nothing set for history, look for a default transition for (size_t j = 0; j < SCXML_NUMBER_TRANSITIONS; j++) { if unlikely(scxml_transitions[j].source == i) { - bit_or(entry_set, scxml_transitions[j].target, 2); - SET_BIT(j, trans_set); + bit_or(entry_set, scxml_transitions[j].target, 1); + if(SCXML_STATE_MASK(scxml_states[i].type) == SCXML_STATE_HISTORY_DEEP && + !bit_has_and(scxml_transitions[j].target, scxml_states[i].children, 1)) { + for (size_t k = i + 1; k < SCXML_NUMBER_STATES; k++) { + if (BIT_HAS(k, scxml_transitions[j].target)) { + bit_or(entry_set, scxml_states[k].ancestors, 1); + break; + } + } + } + BIT_SET_AT(j, trans_set); break; } // Note: SCXML mandates every history to have a transition! } } else { - bit_copy(history_targets, scxml_states[i].completion, 2); - bit_and(history_targets, ctx->history, 2); - bit_or(entry_set, history_targets, 2); + bit_copy(tmp_states, scxml_states[i].completion, 1); + bit_and(tmp_states, ctx->history, 1); + bit_or(entry_set, tmp_states, 1); if (scxml_states[i].type == (SCXML_STATE_HAS_HISTORY | SCXML_STATE_HISTORY_DEEP)) { // a deep history state with nested histories -> more completion for (size_t j = i + 1; j < SCXML_NUMBER_STATES; j++) { - if (IS_SET(j, scxml_states[i].completion) && - IS_SET(j, entry_set) && + if (BIT_HAS(j, scxml_states[i].completion) && + BIT_HAS(j, entry_set) && (scxml_states[j].type & SCXML_STATE_HAS_HISTORY)) { for (size_t k = j + 1; k < SCXML_NUMBER_STATES; k++) { // add nested history to entry_set if ((SCXML_STATE_MASK(scxml_states[k].type) == SCXML_STATE_HISTORY_DEEP || SCXML_STATE_MASK(scxml_states[k].type) == SCXML_STATE_HISTORY_SHALLOW) && - IS_SET(k, scxml_states[j].children)) { + BIT_HAS(k, scxml_states[j].children)) { // a nested history state - SET_BIT(k, entry_set); + BIT_SET_AT(k, entry_set); } } } @@ -665,12 +529,12 @@ ESTABLISH_ENTRY_SET: case SCXML_STATE_INITIAL: { for (size_t j = 0; j < SCXML_NUMBER_TRANSITIONS; j++) { if (scxml_transitions[j].source == i) { - SET_BIT(j, trans_set); - CLEARBIT(i, entry_set); - bit_or(entry_set, scxml_transitions[j].target, 2); + BIT_SET_AT(j, trans_set); + BIT_CLEAR(i, entry_set); + bit_or(entry_set, scxml_transitions[j].target, 1); for (size_t k = i + 1; k < SCXML_NUMBER_STATES; k++) { - if (IS_SET(k, scxml_transitions[j].target)) { - bit_or(entry_set, scxml_states[k].ancestors, 2); + if (BIT_HAS(k, scxml_transitions[j].target)) { + bit_or(entry_set, scxml_states[k].ancestors, 1); } } } @@ -678,16 +542,16 @@ ESTABLISH_ENTRY_SET: break; } case SCXML_STATE_COMPOUND: { // we need to check whether one child is already in entry_set - if (!bit_has_and(entry_set, scxml_states[i].children, 2) && - (!bit_has_and(ctx->config, scxml_states[i].children, 2) || - bit_has_and(exit_set, scxml_states[i].children, 2))) + if (!bit_has_and(entry_set, scxml_states[i].children, 1) && + (!bit_has_and(ctx->config, scxml_states[i].children, 1) || + bit_has_and(exit_set, scxml_states[i].children, 1))) { - bit_or(entry_set, scxml_states[i].completion, 2); - if (!bit_has_and(scxml_states[i].completion, scxml_states[i].children, 2)) { + bit_or(entry_set, scxml_states[i].completion, 1); + if (!bit_has_and(scxml_states[i].completion, scxml_states[i].children, 1)) { // deep completion for (size_t j = i + 1; j < SCXML_NUMBER_STATES; j++) { - if (IS_SET(j, scxml_states[i].completion)) { - bit_or(entry_set, scxml_states[j].ancestors, 2); + if (BIT_HAS(j, scxml_states[i].completion)) { + bit_or(entry_set, scxml_states[j].ancestors, 1); break; // completion of compound is single state } } @@ -707,19 +571,19 @@ ESTABLISH_ENTRY_SET: // EXIT_STATES: size_t i = SCXML_NUMBER_STATES; while(i-- > 0) { - if (IS_SET(i, exit_set) && IS_SET(i, ctx->config)) { + if (BIT_HAS(i, exit_set) && BIT_HAS(i, ctx->config)) { // call all on exit handlers if (scxml_states[i].on_exit != NULL) { if unlikely((err = scxml_states[i].on_exit(ctx, &scxml_states[i], ctx->event)) != SCXML_ERR_OK) return err; } - CLEARBIT(i, ctx->config); + BIT_CLEAR(i, ctx->config); } } // TAKE_TRANSITIONS: for (size_t i = 0; i < SCXML_NUMBER_TRANSITIONS; i++) { - if (IS_SET(i, trans_set) && (scxml_transitions[i].type & (SCXML_TRANS_HISTORY | SCXML_TRANS_INITIAL)) == 0) { + if (BIT_HAS(i, trans_set) && (scxml_transitions[i].type & (SCXML_TRANS_HISTORY | SCXML_TRANS_INITIAL)) == 0) { // call executable content in transition if (scxml_transitions[i].on_transition != NULL) { if unlikely((err = scxml_transitions[i].on_transition(ctx, @@ -737,21 +601,21 @@ ESTABLISH_ENTRY_SET: // ENTER_STATES: for (size_t i = 0; i < SCXML_NUMBER_STATES; i++) { - if (IS_SET(i, entry_set) && !IS_SET(i, ctx->config)) { + if (BIT_HAS(i, entry_set) && !BIT_HAS(i, ctx->config)) { // these are no proper states if unlikely(SCXML_STATE_MASK(scxml_states[i].type) == SCXML_STATE_HISTORY_DEEP || SCXML_STATE_MASK(scxml_states[i].type) == SCXML_STATE_HISTORY_SHALLOW || SCXML_STATE_MASK(scxml_states[i].type) == SCXML_STATE_INITIAL) continue; - SET_BIT(i, ctx->config); + BIT_SET_AT(i, ctx->config); // initialize data - if (!IS_SET(i, ctx->initialized_data)) { + if (!BIT_HAS(i, ctx->initialized_data)) { if unlikely(scxml_states[i].data != NULL && ctx->exec_content_init != NULL) { ctx->exec_content_init(ctx, scxml_states[i].data); } - SET_BIT(i, ctx->initialized_data); + BIT_SET_AT(i, ctx->initialized_data); } if (scxml_states[i].on_entry != NULL) { @@ -761,7 +625,7 @@ ESTABLISH_ENTRY_SET: // take history and initial transitions for (size_t j = 0; j < SCXML_NUMBER_TRANSITIONS; j++) { - if unlikely(IS_SET(j, trans_set) && + if unlikely(BIT_HAS(j, trans_set) && (scxml_transitions[j].type & (SCXML_TRANS_HISTORY | SCXML_TRANS_INITIAL)) && scxml_states[scxml_transitions[j].source].parent == i) { // call executable content in transition @@ -797,20 +661,20 @@ ESTABLISH_ENTRY_SET: * 4. If a state remains, not all children of a parallel are final */ for (size_t j = 0; j < SCXML_NUMBER_STATES; j++) { - if unlikely(SCXML_STATE_MASK(scxml_states[j].type) == SCXML_STATE_PARALLEL) { - char parallel_children[2] = {0, 0}; - size_t parallel = j; + if unlikely(SCXML_STATE_MASK(scxml_states[j].type) == SCXML_STATE_PARALLEL && + BIT_HAS(j, scxml_states[i].ancestors)) { + bit_and_not(tmp_states, tmp_states, 1); for (size_t k = 0; k < SCXML_NUMBER_STATES; k++) { - if unlikely(IS_SET(parallel, scxml_states[k].ancestors) && IS_SET(k, ctx->config)) { + if unlikely(BIT_HAS(j, scxml_states[k].ancestors) && BIT_HAS(k, ctx->config)) { if (SCXML_STATE_MASK(scxml_states[k].type) == SCXML_STATE_FINAL) { - bit_and_not(parallel_children, scxml_states[k].ancestors, 2); + bit_and_not(tmp_states, scxml_states[k].ancestors, 1); } else { - SET_BIT(k, parallel_children); + BIT_SET_AT(k, tmp_states); } } } - if unlikely(!bit_any_set(parallel_children, 2)) { - ctx->raise_done_event(ctx, &scxml_states[parallel], NULL); + if unlikely(!bit_has_any(tmp_states, 1)) { + ctx->raise_done_event(ctx, &scxml_states[j], NULL); } } } |