Child pages
  • Dataflow
Skip to end of metadata
Go to start of metadata

This cookbook should give you quick answers and guidelines when designing dataflow for your languages. For in-depth description of the typesystem please refer to the Dataflow section of the user guide.

Reading a value

The read operation instructs the dataflow engine that a particular value is read:

Writing a value

Similarly the write operation indicates that a value gets written to. In the example, a variable declaration with an initializer first executes the initializer through the code for command and then marks the node as being written the result of the initializer:

Code for

As seen above in the LocalVariableDeclaration dataflow or below in the DotExpression dataflow, the code for command indicates nodes that get executed and when. In the DotExpression, for example, code for the operand runs before the actual dot operation:


Dataflow for the TernaryOperatorExpression is a very straightforward example of using both conditional and unconditional jumps. Once the condition gets evaluated we can optionally jump to the ifFalse branch. Similarly, once the ifTrue branch is completed we unconditionally jump out of the scope of the node:


The WhileStatement shows a more involved usage of the dataflow language. Not also the built-in detection of boolean constants. Trying to use while(false) will thus be correctly reported by MPS as a while-loop with unreachable body. This is thanks to the unconditional jump to after node if the constant is false.

Inserting instructions

The TryStatement has even more needs from the dataflow language. It must insert extra ifjump instructions to jump to a catch clause wherever the particular exception can be thrown in the code:

Notice, we're using a few other helper methods and commands here - get code for to retrieve the dataflow instruction set for a node, isRet, isJump and isNop to exclude certain types of instructions (returns, jumps and no-operations respectively), label to create named places in the dataflow instruction set that we can jump to from elsewhere, and finally the insert command to insert a new command into an existing dataflow instruction set.

  • No labels