Sign in Join
Wiki copytemporary

Frame: what changed

Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.

Title: Frame

OldNewLine
1+A **frame** (frequently also referred to as [[Block|block]]) is a language construct grouping a (possibly empty) sequence of [[statement|statements]] (or instructions in the case of `asm` frames).
2+
3+## available types
4+
5+All frames but [[Repeat|repeat … until]] are terminated by the word [[End|end]]. Frame types are distinguished by their corresponding opening words.
6+
7+- [[Pascal]]: These frames expect Pascal statements or may contain other frames.
8+ [[Begin|begin]]
9+ This frame begins a (possibly empty) sequence of statements. In the context of [[Routine|routine]] definitions or a [[Program|program]] it can delimit a [[Scope|scope]].
10+
11+ [[Else|else]]/`otherwise`
12+ This frame surrounds a “catch-all”-alternative as part of a [[Case|case statement]].
13+
14+ `repeat … until`
15+ `repeat` in conjunction with `until` is used to surround the loop body of a tail-controlled [[Loops|loop]]. It is the only frame type not ending with an `end`.
16+
17+ exception treatment
18+ If [[Exceptions|exceptions]] are supported in the current compiler mode, the following frames are available as well. These frames are in fact “double”-frames: They group *two* sequences at once. Neither of them can be used independently (e. g. writing `finally … end;` *without* a proper `try` is illegal).
19+
20+ [[Try|try]] … [[Except|except]] …
21+ Use this to install exception handlers.
22+
23+ `try` … [[Finally|finally]] …
24+ Use this to ensure a certain code fragment is executed despite any thrown exceptions.
25+
26+ [[Unit|unit]] overhead
27+
28+ :; [[Initialization|initialization]] … [[Finalization|finalization]]
29+
30+
31+
32+ This double-frame designates code being executed when the corresponding unit is loaded or unloaded. Either part of this frame is optional. This frame may also delimit a scope.
33+- [[Assembly language]]: Frames beginning with [[Asm|asm]] expect assembly language. In pure assembly routines, this kind of frame may delimit a scope, too. Note, you cannot nest other frames in `asm` frames.
34+
35+## style
36+
37+Although not mandatory, it is customary to indent all code surrounded by frame markers by one level.
38+
39+```delphi
40+try
41+ openJar;
42+except
43+ throwATantrum;
44+end;
45+```
46+
47+Some styles add another indentation level for nested or subordinate frame markers per se.
48+
49+``` pascal
50+if apples = oranges then
51+ begin
52+ protest;
53+ halt(123);
54+ end;
55+```
56+
57+As you can see from the examples above, it is customary to put frame delimiters *isolated* in their *own* line. Exempt of this guideline are of course frames accepting or requiring additional clauses to be syntactically complete:
58+
59+``` pascal
60+repeat
61+ write('Enter a non-negative integer: ');
62+ readLn(i);
63+until i >= 0;
64+```
65+
66+```delphi
67+asm
68+ rdrand eax
69+ mov n, eax
70+end ['eax'];
71+```
72+
73+## technical background
74+
75+Frames frequently, but not always, turn up to be (conditional) `jmp` targets. Some compile-time optimizations require code to be structured in a certain way, frames setting boundaries for that.
76+
77+---
78+*From the Free Pascal wiki, page "Frame", as it stood on 2021-02-06 after a change by Kai Burghardt, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*
79+Category: Glossary
80+Category: Pascal

Back to history