Continuous evaluation

This commit is contained in:
Devine Lu Linvega 2024-04-04 15:10:25 -07:00
parent 81a995090f
commit 41f7807cd6
1 changed files with 9 additions and 9 deletions

View File

@ -55,16 +55,15 @@ static void
save(void) save(void)
{ {
int i, end = outp_ - outp; int i, end = outp_ - outp;
for(i = 0; i < end; i++) prog[i] = outp[i]; for(i = 0; i <= end; i++) prog[i] = outp[i];
prog[i] = 0; prog_ = prog, outp_ = outp;
prog_ = prog;
outp_ = outp;
printf(".. %s\n", prog); printf(".. %s\n", prog);
} }
static int static int
rewrite(void) rewrite(void)
{ {
int success = 0;
char c, *p = prog; char c, *p = prog;
while((c = *p)) { while((c = *p)) {
int i, found = 0; int i, found = 0;
@ -78,7 +77,7 @@ rewrite(void)
writereg(*b++); writereg(*b++);
else else
*outp_++ = cc; *outp_++ = cc;
found = 1; found = success = 1;
p = res; p = res;
} }
} }
@ -88,8 +87,9 @@ rewrite(void)
} }
} }
*outp_++ = 0; *outp_++ = 0;
if(success)
save(); save();
return 1; return success;
} }
static void static void
@ -165,7 +165,7 @@ main(int argc, char **argv)
parse(argv[1]); parse(argv[1]);
print_rules(); print_rules();
printf(".. %s\n", prog); printf(".. %s\n", prog);
rewrite(); while(rewrite())
rewrite(); ;
return 0; return 0;
} }