Table of Contents

Class InstructionListLowering

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

Lowers a procedure body into an InstructionList — RD-VBAL §3.5. This is the statement-tree analogue of StatementStaticSemanticsEvaluator: where that walker recurses through the whole tree checking types and label references, lowering produces the flat, offset-addressable list a future interpreter drives with a program counter, because GoTo/ GoSub/On…GoTo/Resume can jump anywhere in the procedure and a recursive tree walk cannot express that.

public static class InstructionListLowering
Inheritance
InstructionListLowering
Inherited Members

Remarks

Scope of this pass. Every statement lexically inside body — at any nesting depth, through If/ElseIf/inline If/Select Case/a loop/ With — is lowered. Structured statements stay instructions; block closers (a loop's back-edge, an If/Case branch's trailing jump) are synthesized, carry no source StatementNode (Node is null), and are never keyed in ByNode. An unconditional "else" branch (Else, Case Else) gets no header instruction of its own — it has no condition to evaluate, so its chain's previous header branches straight to its body's first instruction. Any statement kind this pass does not recognize as one of the control-flow shapes above — an ordinary data-manipulation statement (Let/Set-assignment, a Call) chiefly — falls through as Simple.

What is wrong with a body is not lowering's to find out: the Errors it reports are those of CheckStructure(StatementBlock, StaticSemanticsOptions, MemberKind?), which is the one place the rules are written - every label a jump names must be defined exactly once in the procedure (MS-VBAL §5.4.1.1), an Exit statement must be where it may be (ExitStatementStaticSemantics), and a statement must exist in the language. Lowering only has to act on the outcome: a jump whose target does not resolve gets a null Target/Targets entry, a repeated label definition keeps its first offset, and an Exit that is where it may not be, or a bare Print in a language that has none, gets no instruction.

A statement (or label) lexically inside a dead #If/#ElseIf/#Else branch — a Lower call's own deadRanges argument, from RDCore.Runtime.Semantics.Precompiler.PrecompilerLiveBranchEvaluator — is skipped entirely: no instruction, no ByNode entry, no label definition, exactly as if the excluded text had never been there.

Methods

Lower(StatementBlock, InstructionLoweringOptions, MemberKind?)

Lowers body — a procedure's top-level statement list — into an InstructionList.

public static InstructionListLoweringResult Lower(StatementBlock body, InstructionLoweringOptions options = default, MemberKind? procedure = null)

Parameters

body StatementBlock

A procedure body: a MemberDeclarationNode's own Children, wrapped in a StatementBlock. A label is scoped to the whole procedure, so passing a nested block on its own would under-resolve every jump into or out of it.

options InstructionLoweringOptions

What the build being lowered for decides: which conditional-compilation branches are dead, and whether Debug statements are lowered at all. The default is a debug build of a body with no conditional compilation in it.

procedure MemberKind?

The kind of the procedure body belongs to, which the Exit Sub, Exit Function and Exit Property statements are checked against. null - the default - when it is not known: those statements are not checked then.

Returns

InstructionListLoweringResult