org.extex.ocpware.compiler.parser
Class State

java.lang.Object
  extended by org.extex.ocpware.compiler.parser.State

public class State
extends java.lang.Object

The class state represents a state in the ΩCP engine for the compiler.

Version:
$Revision:6007 $
Author:
Gerd Neugebauer

Constructor Summary
State()
          Creates a new object.
 
Method Summary
 void close()
          Close the state by adding some final instructions.
 void fillIn(java.util.List<java.lang.Integer> holes)
          Adjust some instructions by adding the current instruction pointer to them.
 int[] getInstructions()
          Getter for the array of instructions.
 int getNumberExpressions()
          Getter for the number of expressions.
 int getPointer()
          Getter for the current pointer to the end of the code.
 void incrExpressions()
          Increment the number of expressions contained in this state.
 int putInstruction(int opCode)
          Put an instruction of one op code and no argument into the store.
 int putInstruction(int opCode, int arg1)
          Put an instruction of one op code and one argument into the store.
 int putInstruction(int opCode, int arg1, int arg2)
          Put an instruction of one op code and two arguments into the store.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

State

public State()
Creates a new object.

Method Detail

close

public void close()
           throws ArgmentTooBigException,
                  java.io.IOException,
                  IllegalOpcodeException
Close the state by adding some final instructions.

Throws:
java.io.IOException - in case of an I/O error
ArgmentTooBigException - if the argument of the instruction exceeds the 16 bit value
IllegalOpcodeException - in case of an illegal op code

fillIn

public void fillIn(java.util.List<java.lang.Integer> holes)
Adjust some instructions by adding the current instruction pointer to them. Usually goto instructions do not know the position in the instructions to jump to when they are generated. Thus a hole is recorded. These holes are filled in at some time later.

The conditional gotos contain the jump position in the second argument. This is generated as 0. Adding the position fixes this hole.

The other gotos contain the jump position in the first argument. The instruction contains the op code only. Adding the position fixes this hole and leaves the op code intact.

Parameters:
holes - the instructions to adjust

getInstructions

public int[] getInstructions()
Getter for the array of instructions.

Returns:
the array of instructions

getNumberExpressions

public int getNumberExpressions()
Getter for the number of expressions.

Returns:
the number of expressions

getPointer

public int getPointer()
Getter for the current pointer to the end of the code.

Returns:
the current pointer to the end of the code

incrExpressions

public void incrExpressions()
Increment the number of expressions contained in this state.


putInstruction

public int putInstruction(int opCode)
                   throws java.io.IOException,
                          IllegalOpcodeException
Put an instruction of one op code and no argument into the store.

Parameters:
opCode - the op code
Returns:
the index of the next free position in the instruction array
Throws:
java.io.IOException - in case of an I/O error
IllegalOpcodeException - in case of an illegal op code

putInstruction

public int putInstruction(int opCode,
                          int arg1)
                   throws ArgmentTooBigException,
                          java.io.IOException,
                          IllegalOpcodeException
Put an instruction of one op code and one argument into the store.

Parameters:
opCode - the op code
arg1 - the first argument
Returns:
the index of the next free position in the instruction array
Throws:
java.io.IOException - in case of an I/O error
ArgmentTooBigException - if the argument of the instruction exceeds the 16 bit value
IllegalOpcodeException - in case of an illegal op code

putInstruction

public int putInstruction(int opCode,
                          int arg1,
                          int arg2)
                   throws ArgmentTooBigException,
                          java.io.IOException,
                          IllegalOpcodeException
Put an instruction of one op code and two arguments into the store.

Parameters:
opCode - the op code
arg1 - the first argument
arg2 - the second argument
Returns:
the index of the next free position in the instruction array
Throws:
java.io.IOException - in case of an I/O error
ArgmentTooBigException - if the argument of the instruction exceeds the 16 bit value
IllegalOpcodeException - in case of an illegal op code