From b0499fad18a3d21603cd8d8d90206790f32d7b70 Mon Sep 17 00:00:00 2001 From: Devine Lu Linvega Date: Thu, 4 Apr 2024 20:38:45 -0700 Subject: [PATCH] Housekeeping --- examples/test.modal | 5 +++-- src/modal.c | 19 ++++++++----------- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/examples/test.modal b/examples/test.modal index 9438b4b..1e92471 100644 --- a/examples/test.modal +++ b/examples/test.modal @@ -1,3 +1,4 @@ -<> (copy ?x) (?x ?x) +<> (?x dup) (?x ?x) +<> (?x ?y swap) (?y ?x) -(copy ABC) \ No newline at end of file +(A B swap) dup \ No newline at end of file diff --git a/src/modal.c b/src/modal.c index b6b8203..ec1ca27 100644 --- a/src/modal.c +++ b/src/modal.c @@ -74,7 +74,6 @@ save(void) static int rewrite(void) { - char c, *p = prog; while((c = *p)) { int i; @@ -107,10 +106,8 @@ static void print_rules(void) { int i; - for(i = 0; i < rules_len; i++) { - Rule *r = &rules[i]; - printf("Rule #%d: %s -> %s\n", i, r->a, r->b); - } + for(i = 0; i < rules_len; i++) + printf("Rule #%d: %s -> %s\n", i, rules[i].a, rules[i].b); printf("\n"); } @@ -158,19 +155,19 @@ static int parse(char *path) { FILE *f; - char c, token[0x40], *tokptr; + char c, token[0x40], *token_; if(!(f = fopen(path, "r"))) return !printf("Invalid file: %s\n", path); - tokptr = token; + token_ = token; while(f && fread(&c, 1, 1, f)) { if(c < 0x21) - *tokptr++ = 0x00, tokenize(token, f), tokptr = token; - else if(tokptr - token < 0x3f) - *tokptr++ = c; + *token_++ = 0x00, tokenize(token, f), token_ = token; + else if(token_ - token < 0x3f) + *token_++ = c; else return printf("Token too long: %s\n", token); } - *tokptr++ = 0x00, tokenize(token, f), tokptr = token; + *token_++ = 0x00, tokenize(token, f), token_ = token; fclose(f); return 1; }