Feature #141
openStructured goto with blocks
0%
Description
Rationale¶
For a low-level systems programming language it is important to have an escape from the structured flow. The escape route proposed here are named blocks with the support of break statements to exit the block.
Syntax¶
- The new keyword
blockis followed by an identifier, its name. The body of the block is a statement list ending with theendkeyword. - The new statement "break identifier" can be used everywhere in the block to jump to the end of the block with the named identifier.
- The block name in the block statement itself and in the break statement is mandatory.
Usage¶
- a
blockinside the loop gives "continue". - a
blockwrapping the loop gives "break".
Symbol table¶
Labels can use their own namespace since their usage doesn't conflict with any other symbols. Labels cannot be exported, their maximal scope is always a single procedure. The lookup is bottom-up as for other symbols. Labels name is only valid inside the block it is attached to. Label names cannot be shadowed by the nested blocks.
GENERIC generation¶
A block opens a new scope, as any other block-statement, since it is required to handle try…finally correctly. At the end of the block an artificial label should be generated, that is used to jump to it if a break-statement breaks that block.
A break runs the defers of the scopes it leaves.