Class AVM

java.lang.Object
org.sentrysoftware.jawk.backend.AVM
All Implemented Interfaces:
AwkInterpreter, VariableManager

public class AVM extends Object implements AwkInterpreter, VariableManager
The Jawk interpreter.

It takes tuples constructed by the intermediate step and executes each tuple in accordance to their instruction semantics. The tuples correspond to the Awk script compiled by the parser. The interpreter consists of an instruction processor (interpreter), a runtime stack, and machinery to support the instruction set contained within the tuples.

The interpreter runs completely independent of the frontend/intermediate step. In fact, an intermediate file produced by Jawk is sufficient to execute on this interpreter. The binding data-structure is the AwkSettings, which can contain options pertinent to the interpreter. For example, the interpreter must know about the -v command line argument values, as well as the file/variable list parameter values (ARGC/ARGV) after the script on the command line. However, if programmatic access to the AVM is required, meaningful AwkSettings are not required.

Semantic analysis has occurred prior to execution of the interpreter. Therefore, the interpreter throws AwkRuntimeExceptions upon most errors/conditions. It can also throw a java.lang.Error if an interpreter error is encountered.

Author:
Danny Daglas
  • Field Details

    • NULL_OFFSET

      public static final int NULL_OFFSET
      The value of an address which is not yet assigned a tuple index.
      See Also:
  • Constructor Details

    • AVM

      public AVM()
      Construct the interpreter.

      Provided to allow programmatic construction of the interpreter outside of the framework which is used by Jawk.

    • AVM

      public AVM(AwkSettings parameters, Map<String,JawkExtension> extensions)
      Construct the interpreter, accepting parameters which may have been set on the command-line arguments to the JVM.
      Parameters:
      parameters - The parameters affecting the behavior of the interpreter.
      extensions - Map of the extensions to load
  • Method Details

    • interpret

      public void interpret(AwkTuples tuples) throws ExitException, IOException
      Traverse the tuples, interpreting tuple opcodes and arguments and acting on them accordingly. Traverse the tuples, executing their associated opcodes to provide an execution platform for Jawk scripts.
      Specified by:
      interpret in interface AwkInterpreter
      Parameters:
      tuples - The tuples to compile.
      Throws:
      IOException - in case of I/O problems (with getline typically)
      ExitException - indicates that the interpreter would like the application to exit.
    • waitForIO

      public void waitForIO()
      Close all streams in the runtime
    • getRS

      public final Object getRS()

      getRS.

      Specified by:
      getRS in interface VariableManager
      Returns:
      the contents of the RS variable.
    • getOFS

      public final Object getOFS()

      getOFS.

      Specified by:
      getOFS in interface VariableManager
      Returns:
      the contents of the OFS variable.
    • getORS

      public final Object getORS()
      Description copied from interface: VariableManager

      getORS.

      Specified by:
      getORS in interface VariableManager
      Returns:
      the contents of the ORS variable.
    • getSUBSEP

      public final Object getSUBSEP()

      getSUBSEP.

      Specified by:
      getSUBSEP in interface VariableManager
      Returns:
      the contents of the SUBSEP variable.
    • assignVariable

      public final void assignVariable(String name, Object obj)
      Set the contents of a user-defined AWK variable. Used when processing name=value command-line arguments (either via -v or via ARGV).
      Specified by:
      assignVariable in interface VariableManager
      Parameters:
      name - The AWK variable name.
      obj - The new contents of the variable.
    • getFS

      public Object getFS()

      getFS.

      Specified by:
      getFS in interface VariableManager
      Returns:
      the contents of the FS variable.
    • getCONVFMT

      public Object getCONVFMT()

      getCONVFMT.

      Specified by:
      getCONVFMT in interface VariableManager
      Returns:
      the contents of the CONVFMT variable.
    • resetFNR

      public void resetFNR()
      Resets the FNR variable to 0.
      Specified by:
      resetFNR in interface VariableManager
    • incFNR

      public void incFNR()
      Increases the FNR variable by 1.
      Specified by:
      incFNR in interface VariableManager
    • incNR

      public void incNR()
      Increases the NR variable by 1.
      Specified by:
      incNR in interface VariableManager
    • setNF

      public void setNF(Integer I)
      Set the contents of the NF variable.
      Specified by:
      setNF in interface VariableManager
      Parameters:
      I - Value for NF
    • setFILENAME

      public void setFILENAME(String filename)
      Set the contents of the FILENAME variable.
      Specified by:
      setFILENAME in interface VariableManager
      Parameters:
      filename - File name
    • getARGV

      public Object getARGV()

      getARGV.

      Specified by:
      getARGV in interface VariableManager
      Returns:
      the contents of the ARGV variable.
    • getARGC

      public Object getARGC()

      getARGC.

      Specified by:
      getARGC in interface VariableManager
      Returns:
      the contents of the ARGC variable.