From: plugd Date: Sat, 28 Dec 2019 21:54:45 +0000 (+1100) Subject: Option to disable visualization in run-mars. X-Git-Url: https://thelambdalab.xyz/gitweb/index.cgi?a=commitdiff_plain;h=b6d6c8632eadb09da87707a3e911d9d59c1779e4;p=jars.git Option to disable visualization in run-mars. --- diff --git a/Makefile b/Makefile index 883a6b4..3a8ff85 100644 --- a/Makefile +++ b/Makefile @@ -1,10 +1,13 @@ +all : koth run-mars + %.so : %.scm csc -s $< -J -run-mars: run-mars.scm mars.so parser.so visualizer.so +run-mars : run-mars.scm mars.so parser.so visualizer.so csc run-mars.scm -clean: - rm run-mars *.so +koth : koth.scm mars.so parser.so + csc koth.scm -all: run-mars +clean : + rm koth run-mars *.so diff --git a/run-mars.scm b/run-mars.scm index 63daf47..7919e4d 100644 --- a/run-mars.scm +++ b/run-mars.scm @@ -1,3 +1,6 @@ +;; run-mars: command-line utility for running redcode programs +;; + (import (chicken io) (chicken process-context) matchable @@ -15,43 +18,51 @@ (cdr progs-left) (cdr colors-left)))))) -(define (run-mars-with-vis files iters core-size) - (print "Iters: " iters ", core size: " core-size "\n") +(define (mars-runner files iters core-size visualization) + (print "Iters: " iters ", core size: " core-size) (let* ((progs (map (lambda (fname) (string->prog (with-input-from-file fname read-string))) files)) - (colors '("red" "blue" "green" "magenta" "cyan")) - (color-map (make-color-map progs colors)) - (vis (make-vis 640 480 core-size color-map)) - (core (make-core 8000 (make-instr 'DAT 'F 'immediate 0 'immediate 0) - (lambda (i n) - (vis 'update-owner i n)))) + (empty-instr (make-instr 'DAT 'F 'immediate 0 'immediate 0)) + (core (if visualization + (let* ((colors '("red" "blue" "green" "magenta" "cyan")) + (color-map (make-color-map progs colors)) + (vis (make-vis 640 480 core-size color-map))) + (make-core 8000 empty-instr (lambda (i n) + (vis 'update-owner i n)))) + (make-core 8000 empty-instr))) (queues (run-mars core (install-progs core progs) iters))) (for-each (lambda (q) + (print) (print "Final queue for " (queue-owner q) ":") - (dump-queue q core) - (print)) + (dump-queue q core)) queues) - (print* "Press enter to finish...") - (read-line))) - + (when visualization + (print* "Press enter to finish...") + (read-line)))) (define (print-usage) (print "Usage: run-mars [-h|--help]\n" - " run-mars [-c|--core size] [-i|--iterations n] warrior1.red [warrior2.red [...]]")) + " run-mars [-c|--core size]\n" + " [-i|--iterations iters]\n" + " [-n|--no-visualization]\n" + " warrior1.red [warrior2.red [...]]")) (define (main) (let loop ((args (cdr (argv))) (iters 10000) - (core-size 8000)) + (core-size 8000) + (visualization #t)) (match args ((or () ((or "-h" "--help"))) (print-usage)) (((or "-i" "--iterations") istr rest ...) - (loop rest (string->number istr) core-size)) + (loop rest (string->number istr) core-size visualization)) (((or "-c" "--core-size") cstr rest ...) - (loop rest iters (string->number cstr))) + (loop rest iters (string->number cstr) visualization)) + (((or "-n" "--no-visualization") rest ...) + (loop rest iters core-size #f)) ((files ...) - (run-mars-with-vis files iters core-size))))) + (mars-runner files iters core-size visualization))))) (main)