Class AVM
- All Implemented Interfaces:
VariableManager
- Direct Known Subclasses:
SandboxedAVM
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 Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe value of an address which is not yet assigned a tuple index. -
Constructor Summary
ConstructorsConstructorDescriptionAVM()Construct the interpreter.AVM(AwkSettings parameters, Map<String, JawkExtension> extensionInstances, Map<String, ExtensionFunction> extensionFunctions) Construct the interpreter, accepting parameters which may have been set on the command-line arguments to the JVM. -
Method Summary
Modifier and TypeMethodDescriptionfinal voidassignVariable(String name, Object obj) Set the contents of a user-defined AWK variable.Evaluate the provided tuples as an AWK expression.getARGC()getARGC.getARGV()getARGV.getCONVFMT.getFS()getFS.final ObjectgetOFS()getOFS.final ObjectgetORS()getORS.final ObjectgetRS()getRS.final ObjectgetSUBSEP.voidincFNR()Increases the FNR variable by 1.voidincNR()Increases the NR variable by 1.voidTraverse the tuples, executing their associated opcodes to provide an execution platform for Jawk scripts.voidresetFNR()Resets the FNR variable to 0.voidsetFILENAME(String filename) Set the contents of the FILENAME variable.voidSet the contents of the NF variable.voidClose all streams in the runtime
-
Field Details
-
NULL_OFFSET
public static final int NULL_OFFSETThe 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> extensionInstances, Map<String, ExtensionFunction> extensionFunctions) 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.extensionInstances- Map of the extensions to loadextensionFunctions- Map of extension functions available for parsing
-
-
Method Details
-
eval
Evaluate the provided tuples as an AWK expression.- Parameters:
tuples- Tuples representing the expressioninput- Optional input line used to populate $0 and related fields- Returns:
- The resulting value of the expression
- Throws:
IOException- if an IO error occurs during evaluation
-
interpret
Traverse the tuples, executing their associated opcodes to provide an execution platform for Jawk scripts.- Throws:
IOException- in case of I/O problems (with getline typically)ExitException
-
waitForIO
public void waitForIO()Close all streams in the runtime -
getRS
getRS.
- Specified by:
getRSin interfaceVariableManager- Returns:
- the contents of the RS variable.
-
getOFS
getOFS.
- Specified by:
getOFSin interfaceVariableManager- Returns:
- the contents of the OFS variable.
-
getORS
Description copied from interface:VariableManagergetORS.
- Specified by:
getORSin interfaceVariableManager- Returns:
- the contents of the ORS variable.
-
getSUBSEP
getSUBSEP.
- Specified by:
getSUBSEPin interfaceVariableManager- Returns:
- the contents of the SUBSEP variable.
-
assignVariable
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:
assignVariablein interfaceVariableManager- Parameters:
name- The AWK variable name.obj- The new contents of the variable.
-
getFS
getFS.
- Specified by:
getFSin interfaceVariableManager- Returns:
- the contents of the FS variable.
-
getCONVFMT
getCONVFMT.
- Specified by:
getCONVFMTin interfaceVariableManager- Returns:
- the contents of the CONVFMT variable.
-
resetFNR
public void resetFNR()Resets the FNR variable to 0.- Specified by:
resetFNRin interfaceVariableManager
-
incFNR
public void incFNR()Increases the FNR variable by 1.- Specified by:
incFNRin interfaceVariableManager
-
incNR
public void incNR()Increases the NR variable by 1.- Specified by:
incNRin interfaceVariableManager
-
setNF
Set the contents of the NF variable.- Specified by:
setNFin interfaceVariableManager- Parameters:
newNf- Value for NF
-
setFILENAME
Set the contents of the FILENAME variable.- Specified by:
setFILENAMEin interfaceVariableManager- Parameters:
filename- File name
-
getARGV
getARGV.
- Specified by:
getARGVin interfaceVariableManager- Returns:
- the contents of the ARGV variable.
-
getARGC
getARGC.
- Specified by:
getARGCin interfaceVariableManager- Returns:
- the contents of the ARGC variable.
-