Statements

This unit contains files that process each Pascal statement: If, While, For, Repeat, Case, With, GoTo, Inline, Asm block, or system procedure.

Processing statements is more simpler than processing expressions. Consequently, majority of the code is generated by expressions and not by statements themselves. Statements in Turbo Pascal are organized into an object that contains methods for each Pascal statement and statement intermediate code – offset to the intermediate code subrutine for each statement.

This procedure processes blocks of statements between two tokens. It is used to process begin – end and Repeat – end blocks.

This procedure processes Asm – end blocks of assembler instructions. It creates a temporary symbol table for assembler identifiers, indirectly checks for end token and processes assembler instructions.

This procedure processes assignment statements and procedure/function calls. It first checks for variable expression, then if the token is procedure or function it generates code to call procedure (or function), for functions it processes qualifiers in a loop and stops if it finds assignment token.

This procedure processes Inline statement  and generates intermediate code for inline records. Inline records are storend into the main symbol table but are removed after the intermediate code has been generated.

This procedure processes If statement. Both then and else statements are processed recursively. If condition expression is constant at compile time only then or else statement is generated.

This procedure processes Repeat statement. It calls routine to process statements between tokens Repeat and until. Loop statements Break and Continue are also taken into account.

This procedure processes While statement. If condition expression is constant at compile time and evaluates to False, no code is generated. All jumps out of the loop (Break, Continue) are also taken into account.

This procedure processes For statement. It expects assignable variable and loop limits. It generates intermediate code to assign lower limit to control variable, code to increment control variable and code to check for upper limit taking into account Break and Continue jumps.

This procedure processes Case statement. It expects ordinal expression, processes Case constants and constant ranges and generates comparison intermediate code.

This procedure processes With statement. It expects Record or Object variable and stores its data to a linked list. The calculated address is stored on the stack frame for further use. Turbo Pascal generates intermediate code which can be optimized for redundant ES:DI address loadings. Therefore, this procedure generates appropriate instructions to mark the address …

This procedure processes GoTo statement. It expects already declared numeric label that should be in the in the current block and adds GoTo record to a linked list.

This procedure processes Port and PortW statements. This stetement accesses I/O address space and generates OUT instruction. Reading from Port and PortW is done at expression processing.