12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- #include "logic.h"
-
- #include "pileInt.h"
-
- static struct PileInt loops;
-
- void initLogic() {
- initPileI(&loops);
- }
-
- void ifCmd(struct State* state) {
- if (state->mode == EXECUTE) {
- struct NumContainer cond;
- cond = top(&state->pile);
- pop(&state->pile);
- if (cond.t == INT && cond.n.vali == 0) {
- state->mode = IGNORE;
- } else if (cond.t == FLOAT && cond.n.valf == 0.0 ) {
- state->mode = IGNORE;
- }
- }
- }
-
- void elseCmd(struct State* state) {
- if (state->mode == EXECUTE) {
- state->mode = WAIT_FOR_ENDIF;
- } else if (state->mode == IGNORE) {
- state->mode = EXECUTE;
- }
- }
-
- void thenCmd(struct State* state) {
- if (state->mode == IGNORE || state->mode == WAIT_FOR_ENDIF) {
- state->mode = EXECUTE;
- }
- }
-
- void beginCmd(struct State* state) {
- if (state->mode == EXECUTE) {
- if (evalasBool(top(&state->pile))) {
- pushPileI(&loops, state->instructionPointer);
- } else {
- state->mode = WAIT_FOR_UNTIL;
- }
- }
- }
-
- void untilCmd(struct State* state) {
- if (state->mode == WAIT_FOR_UNTIL) {
- state->mode = EXECUTE;
- } else if (state->mode == EXECUTE) {
- if (evalasBool(top(&state->pile))) {
- state->instructionPointer = topPileI(&loops);
- } else {
- popPileI(&loops);
- }
- }
- }
|