The Use of Theories in Code Generation: Difference between revisions
imported>Andy |
imported>Andy |
||
Line 20: | Line 20: | ||
= Adding new (implementation-level) Types = | = Adding new (implementation-level) Types = | ||
When we are working at abstraction levels close to the implementation level, we may decide that to make an implementation decision which requires the introduction of a new type to the development. We give an example of the approach where we add a new array type, shown in Figure 2, and then define its translation to code. | |||
<div id="fig:Extension with an Array Type"> | <div id="fig:Extension with an Array Type"> |
Revision as of 13:40, 15 May 2012
Defining Translations Using The Theory Plug-in
The theory plug-in is used to add mathematical extensions to Rodin. The theories are created, and deployed, and can then be used in any models in the workspace. When dealing with implementation level models, such as in Tasking Event-B, we need to consider how to translate newly added types and operators into code. We have augmented the theory interface with a Translation Rules section. This enables a user to define translation rules that map Event-B formulas to code.
Translation Rules
Figure 1 shows the interface, and some translations rules of the mapping to Ada.
The theory is given a name, and may import some other theories. Type parameters can be added, and we use them here to type the meta-variables. The meta-variable a is restricted to be an integer type, but meta-variable c can be any type. Meta-variables are used in the translator rules.
Translator rules are templates, which used for pattern matching. Event-B expressions and predicates are defined on the left hand side of the rule, and the code to be output (as text) appears on the right hand side of the matching rule.
Type Rules for Code Generation
The type rules section, shown in Figure 1, is where the relationship is defined, between Event-B types and the type system of the implementation.
Adding new (implementation-level) Types
When we are working at abstraction levels close to the implementation level, we may decide that to make an implementation decision which requires the introduction of a new type to the development. We give an example of the approach where we add a new array type, shown in Figure 2, and then define its translation to code.
The array operator notation is defined in the expression array(s: P(T)); and the semantics is defined in the direct definition. arrayN constrains the arrays to be of fixed length. Array lookup, update, and constructor operators are subsequently defined. In the next step we need to define any translations required to implement the array in code.