Class AVM
- All Implemented Interfaces:
AwkInterpreter
,VariableManager
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
Modifier and TypeFieldDescriptionstatic final int
The value of an address which is not yet assigned a tuple index. -
Constructor Summary
ConstructorDescriptionAVM()
Construct the interpreter.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. -
Method Summary
Modifier and TypeMethodDescriptionfinal void
assignVariable
(String name, Object obj) Set the contents of a user-defined AWK variable.getARGC()
getARGC.getARGV()
getARGV.getCONVFMT.getFS()
getFS.final Object
getOFS()
getOFS.final Object
getORS()
getORS.final Object
getRS()
getRS.final Object
getSUBSEP.void
incFNR()
Increases the FNR variable by 1.void
incNR()
Increases the NR variable by 1.void
Traverse the tuples, interpreting tuple opcodes and arguments and acting on them accordingly.void
resetFNR()
Resets the FNR variable to 0.void
setFILENAME
(String filename) Set the contents of the FILENAME variable.void
Set the contents of the NF variable.void
Close 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
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
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 interfaceAwkInterpreter
- 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
getRS.
- Specified by:
getRS
in interfaceVariableManager
- Returns:
- the contents of the RS variable.
-
getOFS
getOFS.
- Specified by:
getOFS
in interfaceVariableManager
- Returns:
- the contents of the OFS variable.
-
getORS
Description copied from interface:VariableManager
getORS.
- Specified by:
getORS
in interfaceVariableManager
- Returns:
- the contents of the ORS variable.
-
getSUBSEP
getSUBSEP.
- Specified by:
getSUBSEP
in 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:
assignVariable
in interfaceVariableManager
- Parameters:
name
- The AWK variable name.obj
- The new contents of the variable.
-
getFS
getFS.
- Specified by:
getFS
in interfaceVariableManager
- Returns:
- the contents of the FS variable.
-
getCONVFMT
getCONVFMT.
- Specified by:
getCONVFMT
in interfaceVariableManager
- Returns:
- the contents of the CONVFMT variable.
-
resetFNR
public void resetFNR()Resets the FNR variable to 0.- Specified by:
resetFNR
in interfaceVariableManager
-
incFNR
public void incFNR()Increases the FNR variable by 1.- Specified by:
incFNR
in interfaceVariableManager
-
incNR
public void incNR()Increases the NR variable by 1.- Specified by:
incNR
in interfaceVariableManager
-
setNF
Set the contents of the NF variable.- Specified by:
setNF
in interfaceVariableManager
- Parameters:
I
- Value for NF
-
setFILENAME
Set the contents of the FILENAME variable.- Specified by:
setFILENAME
in interfaceVariableManager
- Parameters:
filename
- File name
-
getARGV
getARGV.
- Specified by:
getARGV
in interfaceVariableManager
- Returns:
- the contents of the ARGV variable.
-
getARGC
getARGC.
- Specified by:
getARGC
in interfaceVariableManager
- Returns:
- the contents of the ARGC variable.
-