org.jawk.backend
Class AVM

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

public class AVM
extends java.lang.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 datastructure is the AwkParameters, which can contain options pertinent to the interpreter. For example, the interpreter must know about the -v command line arguments, as well as the file/variable list parameters (ARGC/ARGV) after the script on the command line. However, if programmatic access to the AVM is required, meaningful AwkParameters 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.


Field Summary
static int NULL_OFFSET
          The value of an address which is not yet assigned a tuple index.
 
Constructor Summary
AVM()
          Construct the interpreter.
AVM(AwkParameters parameters, java.util.Map<java.lang.String,JawkExtension> extensions)
          Construct the interpreter, accepting parameters which may have been set on the command-line arguments to the JVM.
 
Method Summary
 void assignVariable(java.lang.String name, java.lang.Object obj)
          Set the contents of a user-defined AWK variable.
 java.lang.Object getARGC()
          Retrieve the contents of the ARGC variable.
 java.lang.Object getARGV()
          Retrieve the contents of the ARGV variable.
 java.lang.Object getCONVFMT()
          Retrieve the contents of the CONVFMT variable.
 java.lang.Object getFS()
          Retrieve the contents of the FS variable.
 java.lang.Object getOFS()
          Retrieve the contents of the OFS variable.
 java.lang.Object getRS()
          Retrieve the contents of the RS variable.
 java.lang.Object getSUBSEP()
          Retrieve the contents of the SUBSEP variable.
 void incFNR()
          Increases the FNR variable by 1.
 void incNR()
          Increases the NR variable by 1.
 int interpret(AwkTuples tuples)
          Traverse the tuples, executing their associated opcodes to provide an execution platform for Jawk scripts.
 void resetFNR()
          Resets the FNR variable to 0.
 void setFILENAME(java.lang.String filename)
          Set the contents of the FILENAME variable.
 void setNF(java.lang.Integer I)
          Set the contents of the NF variable.
 void waitForIO()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NULL_OFFSET

public static final int NULL_OFFSET
The value of an address which is not yet assigned a tuple index.

See Also:
Constant Field Values
Constructor Detail

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(AwkParameters parameters,
           java.util.Map<java.lang.String,JawkExtension> extensions)
    throws java.lang.IllegalArgumentException
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.
Throws:
java.lang.IllegalArgumentException
Method Detail

interpret

public int interpret(AwkTuples tuples)
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 interpret.
Returns:
The return code (the value passed into the exit call).

waitForIO

public void waitForIO()

getRS

public final java.lang.Object getRS()
Description copied from interface: VariableManager
Retrieve the contents of the RS variable.

Specified by:
getRS in interface VariableManager
Returns:
The string value of the record separator.

getOFS

public final java.lang.Object getOFS()
Description copied from interface: VariableManager
Retrieve the contents of the OFS variable.

Specified by:
getOFS in interface VariableManager
Returns:
The string value of the output field separator.

getSUBSEP

public final java.lang.Object getSUBSEP()
Description copied from interface: VariableManager
Retrieve the contents of the SUBSEP variable.

Specified by:
getSUBSEP in interface VariableManager
Returns:
The string value of the SUBSEP variable.

assignVariable

public final void assignVariable(java.lang.String name,
                                 java.lang.Object obj)
Description copied from interface: VariableManager
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 java.lang.Object getFS()
Description copied from interface: VariableManager
Retrieve the contents of the FS variable.

Specified by:
getFS in interface VariableManager

getCONVFMT

public java.lang.Object getCONVFMT()
Description copied from interface: VariableManager
Retrieve the contents of the CONVFMT variable.

Specified by:
getCONVFMT in interface VariableManager

resetFNR

public void resetFNR()
Description copied from interface: VariableManager
Resets the FNR variable to 0.

Specified by:
resetFNR in interface VariableManager

incFNR

public void incFNR()
Description copied from interface: VariableManager
Increases the FNR variable by 1.

Specified by:
incFNR in interface VariableManager

incNR

public void incNR()
Description copied from interface: VariableManager
Increases the NR variable by 1.

Specified by:
incNR in interface VariableManager

setNF

public void setNF(java.lang.Integer I)
Description copied from interface: VariableManager
Set the contents of the NF variable.

Specified by:
setNF in interface VariableManager

setFILENAME

public void setFILENAME(java.lang.String filename)
Description copied from interface: VariableManager
Set the contents of the FILENAME variable.

Specified by:
setFILENAME in interface VariableManager

getARGV

public java.lang.Object getARGV()
Description copied from interface: VariableManager
Retrieve the contents of the ARGV variable.

Specified by:
getARGV in interface VariableManager

getARGC

public java.lang.Object getARGC()
Description copied from interface: VariableManager
Retrieve the contents of the ARGC variable.

Specified by:
getARGC in interface VariableManager