Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
with
106 additions
and 2 deletions.
- +23 −0 docs/ops/controlflow.toml
- +1 −0 module/config.mk
- +27 −0 src/every.c
- +15 −0 src/every.h
- +1 −0 src/match_token.rl
- +14 −0 src/ops/controlflow.c
- +1 −0 src/ops/controlflow.h
- +1 −1 src/ops/op.c
- +1 −0 src/ops/op_enum.h
- +13 −0 src/state.c
- +6 −0 src/state.h
- +2 −0 src/teletype.c
- +1 −1 tests/Makefile
| @@ -0,0 +1,27 @@ | ||
| #include <stdbool.h> | ||
| #include <stdint.h> | ||
| #include "every.h" | ||
|
|
||
| void every_tick(every_count_t *e) { | ||
| (e->count)++; | ||
| e->count %= e->mod; | ||
| } | ||
|
|
||
| bool every_is_now(every_count_t *e) { | ||
| return e->count == 0; | ||
| } | ||
|
|
||
| void every_set_count(every_count_t *e, int16_t count) { | ||
| if (count < 0) | ||
| count = 0; | ||
| e->count = count; | ||
| } | ||
|
|
||
| void every_set_mod(every_count_t *e, int16_t mod) { | ||
| if (mod < 0) | ||
| mod = -mod; | ||
| else if (mod == 0) | ||
| mod = 1; // lazy initialization | ||
| e->mod = mod; | ||
| e->count %= e->mod; | ||
| } |
| @@ -0,0 +1,15 @@ | ||
| #ifndef _EVERY_H | ||
| #define _EVERY_H | ||
|
|
||
| typedef struct { | ||
| int16_t count; | ||
| int16_t mod; | ||
| } every_count_t; | ||
|
|
||
|
|
||
| void every_tick(every_count_t*); | ||
| bool every_is_now(every_count_t*); | ||
| void every_set_count(every_count_t*, int16_t); | ||
| void every_set_mod(every_count_t*, int16_t); | ||
|
|
||
| #endif |