Calculator
This unit is used by the Expressions unit and contains functions that process calculations with one or two operands and calculation operation. This unit actually generates the code for addition, subtraction, multiplication, division, shifts, etc.
Turbo Pascal generates code for all mathemathical operations with two operands by the following procedure. The input of this procedure are left and right expression and the operation.
This procedure checks if operation is PChar ± Integer or PChar ± PChar. If so, it generates code and returns True otherwise it returns False.
Constant sets are located into temprary buffer and expression Value holds offset to this buffer. Non-constant sets are always expanded to the stack frame. This procedure calculates operation between two constant sets.
Constant strings are added in the temporary buffer, while all non-constant string operations are performed in stack frame.
Constant Extended values are always stored in expression Value, while for non-constant expressions numeric constants are stored in code block and FPU instructions are used for calculation. This procedure calculates operation between two constant Extended values.
For Real operations code is always generated. This procedure generates code for operations on Real values. If 80×87 instructions are enabled, it converts both expressions to Extended and generates FPU code otherwise it generates code to call system function.
Boolean operations are similar to integer operations. Constant Boolean operations are performed with boolean expressions converted to boolean bytes (0 or 1) and using procedures for integer calculation.
Pointer operations are similar to Integer operations. However, only extended Turbo Pascal syntax allows pointer operations other than equality check.
Many operations in Turbo Pascal can be calculated as integer operations. This applies to pointers, Boolean values, enumerated values and Char values. Constant integer operations are checked for possible overflow.
This procedure generates code to compare two LongInt values. Again, for some special cases shorter code is generated.
This procedure generates code for integer division with constant. Special code is generated if divisor is power of 2.
This procedure generates code to multiply integer with integer. Multiplication with power of 2 is translated to shift, other special cases (0, 1, 3, 5, 6) are also treated separately. Result is stored in specified Register if possible.