Blocks

Another central concept when developing extensions is the concept of a block. In source code, a block contains both a set of local variables, and a sequence of expressions. In the abstract syntax tree, these two concepts are separate. The class lang:bs:Block is an expression that only contains a set of variables that are visible inside the block. This class therefore focuses on managing the variables and their lifetimes. Below is a summary of the most relevant members in the Block class:

Many of the control structures inherit from Block directly, since they need to scope variables created in the condition of an if statement or a while loop for example. Basic Storm also provides a class that simply contains other statement. This class is called lang:bs:ExprBlock, and it is the class used for ordinary blocks that appear in the Basic Storm source code. This class simply extends the Block with an array that stores the expressions contained in the block. When asked to generate code, it simply generates code for each of the expressions in turn, and any code required to pass the result of the last expression back to the parent expression. The ExprBlock also keeps track of unreachable code in the block and avoids generating dead code (e.g. after a return statement).

The ExprBlock class has the following members that are relevant when developing extensions: