Class Program1

All Implemented Interfaces:
Program, ProgramKernel, Standard<Program>

public class Program1 extends ProgramSecondary
Program represented as a String, Map, and Statement in the obvious way with implementations of primary methods.
Representation Invariant (concrete invariant of $this):
[$this.name is an IDENTIFIER] and [$this.context is a CONTEXT]
            and [$this.body is a BLOCK statement]
Abstraction Relation (interpretation mapping between $this and this):
this = ($this.name, $this.context, $this.body)
  • Constructor Details

    • Program1

      public Program1()
      No-argument constructor.
  • Method Details

    • newInstance

      public final Program newInstance()
      Description copied from interface: Standard
      Returns a new object with the same dynamic type as this, having an initial value. If the type T has a no-argument constructor, then the value of the new returned object satisfies the contract of the no-argument constructor for T. If T does not have a no-argument constructor, then the value of the new returned object satisfies the contract of the constructor call that was used to initialize this .
      Returns:
      new object "like" this with an initial value
    • clear

      public final void clear()
      Description copied from interface: Standard
      Resets this to an initial value. If the type T has a no-argument constructor, then this satisfies the contract of the no-argument constructor for T. If T does not have a no-argument constructor, then this satisfies the contract of the constructor call that was used to initialize #this.
    • transferFrom

      public final void transferFrom(Program source)
      Description copied from interface: Standard
      Sets this to the incoming value of source, and resets source to an initial value; the declaration notwithstanding, the dynamic type of source must be the same as the dynamic type of this. If the type T has a no-argument constructor, then source satisfies the contract of the no-argument constructor for T. If T does not have a no-argument constructor, then source satisfies the contract of the constructor call that was used to initialize #source.
      Parameters:
      source - object whose value is to be transferred
    • name

      public final String name()
      Description copied from interface: ProgramKernel
      Returns the name of this.
      Returns:
      the name of this
    • setName

      public final void setName(String n)
      Description copied from interface: ProgramKernel
      Replaces the name of this with n.
      Parameters:
      n - the name replacing the old one
    • newContext

      public final Map<String,Statement> newContext()
      Description copied from interface: ProgramKernel
      Creates and returns an empty Map<String, Statement> of the dynamic type needed in swapContext.
      Returns:
      a new empty Map<String, Statement>
    • swapContext

      public final void swapContext(Map<String,Statement> c)
      Description copied from interface: ProgramKernel
      Exchanges the context of this with c; c must have the dynamic type returned by newContext.
      Parameters:
      c - the context to be exchanged with that of this
    • newBody

      public final Statement newBody()
      Description copied from interface: ProgramKernel
      Creates and returns a Statement with a default initial value, of the dynamic type needed in swapBody.
      Returns:
      a new Statement
    • swapBody

      public final void swapBody(Statement b)
      Description copied from interface: ProgramKernel
      Exchanges the body of this with b; b must have the dynamic type returned by newBody.
      Parameters:
      b - the body to be exchanged with that of this
    • disassembleProgram

      public static void disassembleProgram(SimpleWriter out, int[] cp)
      Disassembles and outputs to out the given program cp.
      Parameters:
      out - the output stream
      cp - the compiled program
      Updates:
      out.content
      Requires:
      out.is_open and [cp is a valid compiled BL program]
      Ensures:
      out.content = #out.content * [disassembled cp]
    • disassembleProgram

      public static void disassembleProgram(SimpleWriter out, Sequence<Integer> cp)
      Disassembles and outputs to out the given program cp.
      Parameters:
      out - the output stream
      cp - the compiled program
      Updates:
      out.content
      Requires:
      out.is_open and [cp is a valid compiled BL program]
      Ensures:
      out.content = #out.content * [disassembled cp]
    • disassembleProgram

      public static void disassembleProgram(SimpleWriter out, int[] cp, int pc)
      Disassembles and outputs to out the given program cp marking the location of the program counter pc.
      Parameters:
      out - the output stream
      cp - the compiled program
      pc - the program counter
      Updates:
      out.content
      Requires:
      out.is_open  and  [cp is a valid compiled BL program]  and
      0 <= pc < cp.length  and
      [pc is the location of an instruction byte code in cp, that is, pc
       cannot be the location of an address]
      
      Ensures:
      out.content =
       #out.content * [disassembled cp with pc marked by an asterisk]