Previous: Hook functions, Up: Using mixguile


3.4.5 Scheme scripts

Another useful way of using mixguile is writing executable scripts that perform a set of commands for you. This is done using the mixguile switch -s (being a Guile shell, mixguile accepts all the command options of guile; type mixguile -h for a list of all available command options). For instance, if you have a very useful MIX program foo.mix which you want to run often, you don't have to fire a MIX virtual machine, load and run it every time; you can write a Scheme script instead:

     #! /usr/bin/mixguile -s
     !#
     ;;; runprimes: execute the primes.mix program
     
     ;; load the file you want to run
     (mix-load "../samples/primes")
     ;; execute it
     (mix-run)
     ;; print the contents of registers
     (mix-pall)
     ;; ...

Just save the above script to a file named, say, runtest, make it executable (chmod +x runtest), and, well, execute it from the Unix shell:

     $ ./runtest
     Program loaded. Start address: 3000
     Running ...
     ... done
     Elapsed time: 190908 /Total program time: 190908 (Total uptime: 190908)
     rA: + 30 30 30 30 30 (0511305630)
     rX: + 30 30 32 32 39 (0511313959)
     rJ: + 47 18 (3026)
     rI1: + 00 00 (0000)     rI2: + 55 51 (3571)
     rI3: + 00 19 (0019)     rI4: + 31 51 (2035)
     rI5: + 00 00 (0000)     rI6: + 00 00 (0000)
     Overflow: F
     Cmp: L
     $

Note that this is far more flexible that running programs non-interactively using mixvm (see Non-interactive mode), for you can execute any combination of commands you want from a Scheme script (not just running and dumping the registers). For additional mixguile command line options, see Invoking mixguile.