Class Instruction
- Namespace
- RDCore.SDK.Semantics.Instructions
- Assembly
- RDCore.SDK.dll
One entry of an InstructionList — RD-VBAL §3.5. Offset is both the entry's index into Items and the program-counter value that fetches it.
public sealed record Instruction : IEquatable<Instruction>
- Inheritance
-
Instruction
- Implements
- Inherited Members
Constructors
Instruction(int, StatementNode?, InstructionKind, int?, ImmutableArray<int?>, int?, int?, int?, int?)
One entry of an InstructionList — RD-VBAL §3.5. Offset is both the entry's index into Items and the program-counter value that fetches it.
public Instruction(int Offset, StatementNode? Node, InstructionKind Kind, int? Target, ImmutableArray<int?> Targets, int? Else, int? End, int? Matching, int? EnclosingWith)
Parameters
OffsetintThe entry's index into the owning Items.
NodeStatementNodeThe StatementNode this instruction was lowered from, or
nullfor an instruction lowering synthesized — a block statement's closer, or the unconditional jump a branch's body ends with — which no source statement corresponds to.KindInstructionKindThe control-flow shape of this instruction.
Targetint?For Jump, GoSub, LoopBack, ForNext, ForEachNext, ExitLoop, OnErrorGoTo, and ResumeLabel: the resolved offset to branch to.
nullfor a Jump lowered fromGoTo/On…GoTo, a GoSub lowered fromGoSub, or an OnErrorGoTo/ResumeLabel, whose operand did not resolve to a label the procedure defines (lowering already reported the LabelNotDefined diagnostic for it), or for an ExitLoop lowering found no matching enclosing loop for. Unused otherwise.TargetsImmutableArray<int?>For JumpTable and GoSubTable: the resolved offset for each label in source order, with a
nullentry wherever the corresponding label did not resolve. Empty otherwise.Elseint?For ConditionalBranch: the offset to branch to when the condition is false, or the case does not match — the next header in the same
If/ElseIf/Casechain, or the offset right past the whole construct when there is no next branch to try. Unused otherwise.Endint?On a block's own opening instruction (an
If's first header, a pre-test loop's header, a ForOpener/ForEachOpener/ With/Select): the offset right past the whole construct.nullon every other instruction, including a construct's own inner headers (anElseIfor aCase) and constructs with no single opening instruction (a bareDo…Loop, a post-test loop, an inlineIf).Matchingint?The offset of the enclosing block-opening instruction whose own per-activation hidden state this instruction reads back. For a
Select CaseCaseheader (ConditionalBranch lowered from aCaseExpressionStatementNode): the enclosing Select instruction whose hidden selector value this header's range clauses are matched against (nullon aCase Else, which never reads it). For a ForNext/ForEachNext closer: its own ForOpener/ForEachOpener, whose stashed counter/end/step (or enumerator) this closer advances and tests — aGoTolanding directly on the closer without that opener having run this activation is MS-VBAL §5.4.2.3 error 92, "For loop not initialized", detected the same way an unresolved with-target would be: no state stashed for the offset this instruction names.nullon every other instruction kind.EnclosingWithint?The offset of the innermost With instruction lexically enclosing this one, so a
.Member/!memberwith-expression reads the right hidden target however control arrived here — aGoTointo or out of aWithblock leaves no stale stack to unwind.nullwhen this instruction is not inside anyWithblock.
Properties
Else
For ConditionalBranch: the offset to branch to when the condition is
false, or the case does not match — the next header in the same If/ElseIf/Case
chain, or the offset right past the whole construct when there is no next branch to try. Unused
otherwise.
public int? Else { get; init; }
Property Value
- int?
EnclosingWith
The offset of the innermost With instruction lexically enclosing this
one, so a .Member/!member with-expression reads the right hidden target however
control arrived here — a GoTo into or out of a With block leaves no stale stack to
unwind. null when this instruction is not inside any With block.
public int? EnclosingWith { get; init; }
Property Value
- int?
End
On a block's own opening instruction (an If's first header, a pre-test loop's header, a
ForOpener/ForEachOpener/
With/Select): the offset right past the
whole construct. null on every other instruction, including a construct's own inner headers
(an ElseIf or a Case) and constructs with no single opening instruction (a bare
Do…Loop, a post-test loop, an inline If).
public int? End { get; init; }
Property Value
- int?
Kind
The control-flow shape of this instruction.
public InstructionKind Kind { get; init; }
Property Value
Matching
The offset of the enclosing block-opening instruction whose own per-activation hidden state this
instruction reads back. For a Select Case Case header
(ConditionalBranch lowered from a CaseExpressionStatementNode):
the enclosing Select instruction whose hidden selector value this
header's range clauses are matched against (null on a Case Else, which never reads it).
For a ForNext/ForEachNext closer: its own
ForOpener/ForEachOpener, whose stashed
counter/end/step (or enumerator) this closer advances and tests — a GoTo landing directly on
the closer without that opener having run this activation is MS-VBAL §5.4.2.3 error
92, "For loop not initialized", detected the same way an unresolved with-target would be: no state
stashed for the offset this instruction names. null on every other instruction kind.
public int? Matching { get; init; }
Property Value
- int?
Node
The StatementNode this instruction was lowered from, or null for an instruction
lowering synthesized — a block statement's closer, or the unconditional jump a branch's body ends
with — which no source statement corresponds to.
public StatementNode? Node { get; init; }
Property Value
Offset
The entry's index into the owning Items.
public int Offset { get; init; }
Property Value
Target
For Jump, GoSub,
LoopBack, ForNext,
ForEachNext, ExitLoop,
OnErrorGoTo, and ResumeLabel: the
resolved offset to branch to. null for a Jump lowered from
GoTo/On…GoTo, a GoSub lowered from GoSub, or an
OnErrorGoTo/ResumeLabel, whose operand did
not resolve to a label the procedure defines (lowering already reported the
LabelNotDefined diagnostic for it), or for an
ExitLoop lowering found no matching enclosing loop for. Unused
otherwise.
public int? Target { get; init; }
Property Value
- int?
Targets
For JumpTable and GoSubTable: the
resolved offset for each label in source order, with a null entry wherever the corresponding
label did not resolve. Empty otherwise.
public ImmutableArray<int?> Targets { get; init; }