Fixed rewrite count

This commit is contained in:
Devine Lu Linvega 2024-04-29 09:46:27 -07:00
parent d24af00098
commit c619581739
2 changed files with 16 additions and 9 deletions

View File

@ -127,9 +127,13 @@ nap tap (inline 1) test
?(?-) (Arithmetic) ?(?-) (Arithmetic)
?((?: ?0 ?1 ?2) (?:)) + 1 2 3 = 6 (Arithmetic 1) test ?((?: ?0 ?1 ?2) ?:) + 1 2 3 = 6 (Arithmetic 1) test
?((?0 ?: ?1) (?:)) 16 - 8 = 8 (Arithmetic 2) test ?((?0 ?: ?1) ?:) 16 - 8 = 8 (Arithmetic 2) test
?((?0 ?1 ?:) (?:)) 12 10 * = 120 (Arithmetic 3) test ?((?0 ?1 ?:) ?:) 12 10 * = 120 (Arithmetic 3) test
<> (?0 ?1 `?:) (?:)
(12 45 `+ -2 `+) = (55) (Arithmetic 4) test
?(?-) (Late Test Primitives) ?(?-) (Late Test Primitives)

View File

@ -291,7 +291,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, 28 Apr 2024.\n"); case 'v': /* version */ return !printf("Modal Interpreter, 29 Apr 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;
@ -318,12 +318,15 @@ main(int argc, char **argv)
if(!cycles--) return !fprintf(stderr, "Modal rewrites exceeded.\n"); if(!cycles--) return !fprintf(stderr, "Modal rewrites exceeded.\n");
if(!quiet) { if(!quiet) {
while(rules_-- > rules) { while(rules_-- > rules) {
if(!rules_->refs && rules_->a) if(rules_->a) {
fprintf(stderr, "-- Unused rule: %d <> (%s) (%s)\n", rules_->id, rules_->a, rules_->b); if(!rules_->refs)
if(debug && rules_->a) fprintf(stderr, "-- Unused rule: %d <> (%s) (%s)\n", rules_->id, rules_->a, rules_->b);
fprintf(stderr, " (%s) (%s), %d times.\n", rules_->a, rules_->b, rules_->refs); if(debug)
fprintf(stderr, " (%s) (%s), %d times.\n", rules_->a, rules_->b, rules_->refs);
}
} }
fprintf(stderr, ".. %s\nCompleted in %d rewrites.\n", src_, rw); if(rw)
fprintf(stderr, "Completed in %d rewrites.\n", rw - 1);
} }
return 0; return 0;
} }