From c61958173973e54d36990096dc7e1f93e991a825 Mon Sep 17 00:00:00 2001 From: Devine Lu Linvega Date: Mon, 29 Apr 2024 09:46:27 -0700 Subject: [PATCH] Fixed rewrite count --- examples/tests.modal | 10 +++++++--- src/modal.c | 15 +++++++++------ 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/examples/tests.modal b/examples/tests.modal index 845aa12..2c9d38e 100644 --- a/examples/tests.modal +++ b/examples/tests.modal @@ -127,9 +127,13 @@ nap tap (inline 1) test ?(?-) (Arithmetic) -?((?: ?0 ?1 ?2) (?:)) + 1 2 3 = 6 (Arithmetic 1) test -?((?0 ?: ?1) (?:)) 16 - 8 = 8 (Arithmetic 2) test -?((?0 ?1 ?:) (?:)) 12 10 * = 120 (Arithmetic 3) test +?((?: ?0 ?1 ?2) ?:) + 1 2 3 = 6 (Arithmetic 1) test +?((?0 ?: ?1) ?:) 16 - 8 = 8 (Arithmetic 2) test +?((?0 ?1 ?:) ?:) 12 10 * = 120 (Arithmetic 3) test + +<> (?0 ?1 `?:) (?:) + +(12 45 `+ -2 `+) = (55) (Arithmetic 4) test ?(?-) (Late Test Primitives) diff --git a/src/modal.c b/src/modal.c index 7bce9ef..2381ae0 100644 --- a/src/modal.c +++ b/src/modal.c @@ -291,7 +291,7 @@ main(int argc, char **argv) return !printf("usage: modal [-vqn] source.modal\n"); for(i = 1; i < argc && *argv[i] == '-'; i++) { 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 'p': /* debug */ debug = 1; 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(!quiet) { while(rules_-- > rules) { - if(!rules_->refs && rules_->a) - fprintf(stderr, "-- Unused rule: %d <> (%s) (%s)\n", rules_->id, rules_->a, rules_->b); - if(debug && rules_->a) - fprintf(stderr, " (%s) (%s), %d times.\n", rules_->a, rules_->b, rules_->refs); + if(rules_->a) { + if(!rules_->refs) + fprintf(stderr, "-- Unused rule: %d <> (%s) (%s)\n", rules_->id, rules_->a, rules_->b); + 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; }