Moved print out of write_tail

This commit is contained in:
Devine Lu Linvega 2024-05-02 16:02:33 -07:00
parent c440725559
commit e1f4641f69
1 changed files with 10 additions and 7 deletions

View File

@ -135,7 +135,7 @@ write_reg(char r, char *reg)
} }
static int static int
write_tail(char *s, Rule *r) write_tail(char *s)
{ {
while((*dst_++ = *s++)) while((*dst_++ = *s++))
; ;
@ -144,7 +144,6 @@ write_tail(char *s, Rule *r)
src_ = bank_b, dst_ = bank_a; src_ = bank_b, dst_ = bank_a;
else else
src_ = bank_a, dst_ = bank_b; src_ = bank_a, dst_ = bank_b;
if(!quiet && r) fprintf(stderr, "%02d %s\n", r->id, src_), ++r->refs;
return 1; return 1;
} }
@ -194,7 +193,8 @@ apply_rule(Rule *r, char *s)
while(*s == ' ') s++; while(*s == ' ') s++;
if(*s == ')' && *(dst_ - 1) == ' ') dst_--; if(*s == ')' && *(dst_ - 1) == ' ') dst_--;
} }
return write_tail(s, r); if(!quiet) fprintf(stderr, "%02d %s\n", r->id, src_), ++r->refs;
return write_tail(s);
} }
static char * static char *
@ -247,7 +247,7 @@ rewrite(void)
r->a = 0; r->a = 0;
} }
while(*cap == ' ') cap++; while(*cap == ' ') cap++;
return write_tail(cap, NULL); return write_tail(cap);
} }
/* phase: define */ /* phase: define */
if(c == '<' && s[1] == '>') { if(c == '<' && s[1] == '>') {
@ -258,7 +258,7 @@ rewrite(void)
rules_++; rules_++;
} }
while(*s == ' ') s++; while(*s == ' ') s++;
return write_tail(s, NULL); return write_tail(s);
} }
/* phase: lambda */ /* phase: lambda */
if(c == '?' && s[1] == '(') { if(c == '?' && s[1] == '(') {
@ -267,7 +267,10 @@ rewrite(void)
parse_frag(&r->b, parse_frag(&r->a, s + 2)); parse_frag(&r->b, parse_frag(&r->a, s + 2));
s = cap; s = cap;
while(*s == ' ') s++; while(*s == ' ') s++;
if(!apply_rule(&lambda, s)) write_tail(s, r); if(!apply_rule(&lambda, s)) {
if(!quiet) fprintf(stderr, "%02d %s\n", r->id, src_), ++r->refs;
write_tail(s);
}
return 1; return 1;
} }
/* phase: match */ /* phase: match */
@ -291,7 +294,7 @@ main(int argc, char **argv)
return !printf("usage: modal [-vqn] source.modal\n"); return !printf("usage: modal [-vqn] source.modal\n");
for(i = 1; i < argc && *argv[i] == '-'; i++) { for(i = 1; i < argc && *argv[i] == '-'; i++) {
switch(argv[i][1]) { switch(argv[i][1]) {
case 'v': /* version */ return !printf("Modal Interpreter, 29 Apr 2024.\n"); case 'v': /* version */ return !printf("Modal Interpreter, 2 May 2024.\n");
case 'q': /* quiet */ quiet = 1; break; case 'q': /* quiet */ quiet = 1; break;
case 'p': /* debug */ debug = 1; break; case 'p': /* debug */ debug = 1; break;
case 'n': /* infinite */ cycles = 0xffffffff; break; case 'n': /* infinite */ cycles = 0xffffffff; break;