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