Next: , Previous: , Up: Scheme functions reference   [Contents][Index]


8.2.1 mixvm command wrappers

For each of the mixvm commands listed in Commands, there is a corresponding Scheme function named by prefixing the command name with mix- (e.g., mix-load, mix-run and so on). These command wrappers are implemented using a generic command dispatching function:

Function: mixvm-cmd command argument

Dispatches the given command to the MIX virtual machine appending the provided argument. Both command and argument must be strings. The net result is as writing "command argument" at the mixvm or gmixvm command prompt.

For instance, you can invoke the run command at the mixvm prompt in three equivalent ways:

MIX > run hello
MIX > (mix-run "hello")
MIX > (mixvm-cmd "run" "hello")

(only the two last forms can be used at the mixguile prompt or inside a Scheme script).

The mix- functions evaluate to a unspecified value. If you want to check the result of the last mixvm command invocation, use the mix-last-result function:

Function: mix-last-result

Returns #t if the last mixvm command invocation was successful, #f otherwise.

Using this function, we could improve the script for running a program presented in the previous section by adding error checking:

#! /usr/bin/mixguile \
-e main -s
!#

;;; Execute a given program and print the registers.

(define main
  (lambda (args)
    ;; load the file provided as a command line argument
    (mix-load (cadr args))
    ;; execute it if mix-load succeeded
    (if (mix-last-result) (mix-run))
    ;; print the contents of registers if the above commands succeeded
    (if (mix-last-result) (mix-pall))))

Please, refer to Commands for a list of available commands. Given the description of a mixvm, it is straightforward to use its Scheme counterpart and, therefore, we shall not give a complete description of these functions here. Instead, we will only mention those wrappers that exhibit a treatment of their differing from that of their command counterpart.

Function: mix-preg [register]
Function: mix-sreg register value

The argument register of these functions can be either a string or a symbol representing the desired register. For instance, the following invocations are equivalent:

(mix-preg 'I1)
(mix-preg "I1")
Function: mix-pmem from [to]

The command pmem takes a single argument which can be either a cell number or a range of the form FROM-TO. This function takes one argument to ask for a single memory cell contents, or two parameters to ask for a range. For instance, the following commands are equivalent:

MIX > pmem 10-12
0010: + 00 00 00 00 00 (0000000000)
0011: + 00 00 00 00 00 (0000000000)
0012: + 00 00 00 00 00 (0000000000)
MIX > (mix-pmem 10 12)
0010: + 00 00 00 00 00 (0000000000)
0011: + 00 00 00 00 00 (0000000000)
0012: + 00 00 00 00 00 (0000000000)
MIX >
Function: mix-sover #t|#f

The command sover takes as argument either the string T or the string F, to set, respectively, the overflow toggle to true or false. Its Scheme counterpart, mix-sover, takes as argument a Scheme boolean value: #t (true) or #f.

For the remaining functions, you simply must take into account that when the command arguments are numerical, the corresponding Scheme function takes as arguments Scheme number literals. On the other hand, when the command argument is a string, the argument of its associated Scheme function will be a Scheme string. By way of example, the following invocations are pairwise equivalent:

MIX > load ../samples/hello
MIX > (mix-load "../samples/hello")

MIX > next 5
MIX > (mix-next 5)

Next: , Previous: , Up: Scheme functions reference   [Contents][Index]