Table of Contents

Class InstructionList

Namespace
RDCore.SDK.Semantics.Instructions
Assembly
RDCore.SDK.dll

The ordered, keyed instruction list of one procedure body — RD-VBAL §3.5 (MS-VBAL §2.3.1: "sequentially evaluate each instruction in the frame"). Built by InstructionListLowering; immutable.

public sealed class InstructionList
Inheritance
InstructionList
Inherited Members

Remarks

Items is dense: index i is offset i, and every offset a program counter can hold names an entry. A label may resolve to Items.Length itself (a label with nothing after it) — that offset is valid to hold, and a fetch there completes as if execution had reached the end of the body.

Properties

Items

Every instruction, in program-counter order. Items[i].Offset == i for every i.

public ImmutableArray<Instruction> Items { get; }

Property Value

ImmutableArray<Instruction>

Methods

LabelAt(int)

The name of the label that is at offset, the way it was written: where a handler begins is told by its label.

public string? LabelAt(int offset)

Parameters

offset int

A program-counter offset into Items.

Returns

string

The first label defined there, or null when there is none.

TryGetLabelOffset(string, out int)

Looks up the offset a line label or line number defines, by name (MS-VBAL §5.4.1.1). Case-insensitive, like every VBA identifier.

public bool TryGetLabelOffset(string label, out int offset)

Parameters

label string

The label name, or a line number's decimal string form.

offset int

Returns

bool

false when this procedure defines no such label.

TryGetLineNumber(int, out long)

The line number in effect at offset: the nearest line-number label at or before it. This is what Erl reports for an error raised there.

public bool TryGetLineNumber(int offset, out long lineNumber)

Parameters

offset int

A program-counter offset into Items.

lineNumber long

The line number in effect there, or 0 when no line number precedes it.

Returns

bool

false when no line number is in effect at offset.

Remarks

A line number is sticky - it labels every statement after it until the next one - which is why this searches backwards rather than requiring the faulting statement to carry a label of its own. A named label never sets it; only a label spelled as decimal digits does.

🎯 long, deliberately. MS-VBA reports Erl with ushort resolution and wraps around on anything that does not fit, so a program numbered past 65535 is told it faulted somewhere it did not. RD-VBA widens it instead, so every legal line number label is representable.

TryGetOffset(SyntaxNodeId, out int)

Looks up the offset a source StatementNode lowered to, by its stable SyntaxNodeId — the fault-statement identity a breakpoint or a runtime error anchors to.

public bool TryGetOffset(SyntaxNodeId nodeId, out int offset)

Parameters

nodeId SyntaxNodeId
offset int

Returns

bool

false when nodeId is not a statement of this body.

TryGetOffsetAtLine(int, out int)

Looks up the first instruction a statement of the source line line lowered to, or else the first of the lines after it that has one: where a breakpoint on a line, or a move of the program counter to it, lands.

public bool TryGetOffsetAtLine(int line, out int offset)

Parameters

line int

A zero-based line of the source.

offset int

The offset of that instruction.

Returns

bool

false when no statement of this body begins at that line or after it.

Remarks

A statement is where it begins: a line inside a block statement belongs to the statement written on it, and not to the block that opened above it. Several instructions may begin on a line (If x Then y, a: b), and the first of them in program order is the one.