From 557dfcbecf954c0733e3a73485b3885d29824ddc Mon Sep 17 00:00:00 2001 From: Devine Lu Linvega Date: Thu, 4 Apr 2024 14:48:04 -0700 Subject: [PATCH] * --- src/modal.c | 16 ++++++++++++++++ test.modal | 3 ++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/modal.c b/src/modal.c index ec16280..ee4ab26 100644 --- a/src/modal.c +++ b/src/modal.c @@ -1,4 +1,5 @@ #include +#include typedef struct { char *a, *b; @@ -56,6 +57,7 @@ static int rewrite(void) { char c, *p = prog; + printf("STEP ---------\n"); while((c = *p)) { int i, found = 0; for(i = 0; i < rules_len; i++) { @@ -63,6 +65,7 @@ rewrite(void) char *res = match(p, r); if(res != NULL) { char cc, *b = r->b; + printf("MATCH: %s -> %s\n", r->a, r->b); while((cc = *b++)) { if(cc == '?') writereg(*b++); @@ -78,6 +81,7 @@ rewrite(void) p++; } } + *outp_++ = 0; return 1; } @@ -143,6 +147,15 @@ parse(char *path) return 1; } +static void +save(void) +{ + int i, end = outp_ - outp; + for(i = 0; i < end; i++) + prog[i] = outp[i]; + prog[i] = 0; +} + int main(int argc, char **argv) { @@ -153,5 +166,8 @@ main(int argc, char **argv) parse(argv[1]); rewrite(); display(); + save(); + rewrite(); + display(); return 0; } \ No newline at end of file diff --git a/test.modal b/test.modal index 67aba8c..0c2e849 100644 --- a/test.modal +++ b/test.modal @@ -1,3 +1,4 @@ +<> (?x ?y swap) (?y ?x) <> (?x dup) (?x ?x) -foo (hey dup) \ No newline at end of file +foo ((A B swap) dup) \ No newline at end of file