protected class CodeUnit.BranchData
extends java.lang.Object
A BranchData
object provides a bridge between the current
code unit and a destination code unit. At the time the code unit
containing this object is being assembled, the destination code unit
typically has not yet been created. BranchData
therefore
stores an ExtraAst
instance which represents the logical
destination of the branch. This target AST acts as a placeholder for
the destination code unit. After the assembly of all code units in a
compiled expression's execute
method
has been completed, a fixup is performed to calculate the required
offest necessary for this object's branch instruction to jump to the
beginning of the destination code unit.
Modifier and Type | Field and Description |
---|---|
private Instruction |
instruction
Instruction which will cause the branch to occur.
|
private NumericArgument |
offsetArg
Offset to the destination address from the current instruction.
|
private ExtraAst |
target
Code unit which is the destination of the branch.
|
Modifier | Constructor and Description |
---|---|
protected |
BranchData(boolean condition,
ExtraAst target,
int type,
boolean binary)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
protected void |
addBranchInstruction()
This method returns the instruction which performs the branch.
|
protected void |
fixupOffset()
This method sets the offset value of the argument to the branch
instruction.
|
private ExtraAst target
private NumericArgument offsetArg
private Instruction instruction
protected BranchData(boolean condition, ExtraAst target, int type, boolean binary) throws ExpressionException
condition
, creates a branch
instruction and its offset argument. The final value of the
offset cannot be determined until the code array is laid out
and all branch instructions are fixed up, so an offset of 0 is
used as a temporary placeholder.condition
- Condition under which code unit branches to
target
's code unit. This may be ignored,
depending upon the type
specified. For
instance, a type GOTO
branch is unconditional,
and therefore does not use condition
as a
branch trigger.target
- An AST which contains information about the destination of
the branch instruction implied by type
and
condition
. This AST will eventually have a
CodeUnit
object stored in its
extra
field, which represents the destination
of the branch instruction.type
- Type of branch logic; indicates which bytecode instruction
is used, depending also on condition
.binary
- true
if this code unit manages a binary
operation (i.e., requires two operands from the runtime
stack). If false
, the branch will only
consider a single stack operand (unary), or no operands
(unconditional), depending upon the type
parameter.ExpressionException
- if an invalid branching condition is detected.protected void addBranchInstruction()
protected void fixupOffset()