Documentation

LeanPool.MRiscX.AbstractSyntax.MState

Everything is now brought together in a single structure called MState, which represents the machine's MState This structure holds the memory, registers, the code, a program counter (PC), and a termination flag. The program counter points to the next instruction to be executed, while the termination flag indicates whether the machine state has halted or if further evaluation should continue.

structure MState :

The state of the abstract machine: its memory, registers, program counter, loaded code, and termination flag.

  • memory : Memory

    The data memory of the machine.

  • registers : Registers

    The register file of the machine.

  • The program counter, pointing at the next instruction to execute.

  • code : Code

    The program (code) loaded into the machine.

  • terminated : Bool

    Whether the machine has halted.

Instances For

    The initial machine state: empty memory and registers, program counter 0, not terminated, and the default code.

    Equations
    Instances For

      The instruction at the current program counter.

      Equations
      Instances For

        Increment the program counter by one.

        Equations
        Instances For
          def MState.setPc (ms : MState) (p : UInt64) :

          Set the program counter to p.

          Equations
          Instances For

            Replace the register file with r.

            Equations
            Instances For

              Set register i to value v.

              Equations
              Instances For

                Read the value of register i.

                Equations
                Instances For

                  Replace the memory with m.

                  Equations
                  Instances For
                    def MState.addMemory (ms : MState) (i v : UInt64) :

                    Set memory address i to value v.

                    Equations
                    Instances For

                      Read the value at memory address i.

                      Equations
                      Instances For

                        Replace the instruction map of the loaded code.

                        Equations
                        • One or more equations did not get rendered due to their size.
                        Instances For
                          def MState.setCode (ms : MState) (code : Code) :

                          Replace the loaded code with code.

                          Equations
                          Instances For

                            Replace the label map of the loaded code.

                            Equations
                            • One or more equations did not get rendered due to their size.
                            Instances For
                              def MState.setTerminated (ms : MState) (bool : Bool) :

                              Set the termination flag.

                              Equations
                              Instances For

                                Look up the target index of label s, if present.

                                Equations
                                Instances For

                                  Build a fresh machine state running the code c.

                                  Equations
                                  Instances For
                                    def MState.jump (ms : MState) (s : String) :

                                    This creates a Machine state with the pointer which the label [s] points to. If there is no label [s] in code.labels, terminated is set to true.

                                    Equations
                                    • One or more equations did not get rendered due to their size.
                                    Instances For