Event-B specification templates for defining dynamic of DSLs Ulyana Tikhonova [email protected] Mark van den Brand, Tim Willemse, Tom Verhoeff, Maarten Manders

Language concepts (statements)

Semantic mapping

(SOS) • Variables/memory • Action semantics Semantic domain • Control flow • • Branching

Defining dynamic semantics of programming languages

2 Domain-Specific Languages (DSLs)

3 4 Language concepts (statements)

Semantic mapping

• Operational semantics (SOS) • Variables/memory • Action semantics Semantic domain • Control flow • Denotational semantics • Branching

Defining dynamic semantics of domain specific languages

5 Language concepts (statements)

Semantic mapping • Architecture layers Semantic domain • Design patterns • Synchronization protocols Semantic mapping

• Operational semantics (SOS) • Variables/memory • Action semantics Semantic domain • Control flow • Denotational semantics • Branching

Defining dynamic semantics of domain specific languages

6 Language concepts (statements)

Semantic mapping Architecture layers Specification • Semantic domain • Design patterns templates • Synchronization protocols Semantic mapping

• Simulation • Variables/memory • Formal analysis Semantic domain • Control flow • Visualization • Branching

Defining dynamic semantics of domain specific languages

7 8 9 VARIABLES curr_job, curr_la, la_input, ssa_output request_ssa (ssaction, occurence) INVARIANTS where la_input LogicalActions occurence curr_job ssa_output SSActions ∈ ℕ ⇸ occurence ssaction LALabelDef (curr_la) curr_job (SSAOccurences) ∈ ∈ ℕ ⇸ then curr_la LogicalActions ↦ ∈ ∈ ℙ curr_job ≔ curr_job \ {occurence} EVENTS ∈ Initialisation execute_ssa (ssaction, n) curr_la : LogicalActions where curr_job ≔ ∅ ∈ ssaction SSActions la_input ≔ ∅ n ssa_output ≔ ∅ ∈ ssa_output ≠ ∅ i · i dom(ssa_output) n > i request_la (la, n) ∈ ℕ then where ⇒ ∀ ∈ ⇒ ssa_output ≔ ssa_output { n ssaction } la LogicalActions

curr_job = ∅ ∪ ↦ ∈ END n la_input ≠ ∅ i · i dom(la_input) n > i ∈ ℕ then ⇒ ∀ ∈ ⇒ curr_job ≔ dom(LALabelDef(la)) curr_la ≔ la la_input ≔ la_input { n la }

∪ ↦ 10 static void MakeAtLeast(T[] list, T lowest) where T : IComparable { for (int i = 0; i < list.Length; i++) if (list[i].CompareTo(lowest) < 0) list[i] = lowest; } static void Main() { int[] array = { 0, 1, 2, 3 }; MakeAtLeast(array, 2); }

Generic programming: reuse of code

11 MACHINE queue_machine SEES queue_context VARIABLES queue INVARIANTS inv1: queue ElementTypeMyType EVENTS dequeue ∈ ℕ ⇸ ANY element, index INITIALISATION ≙ WHERE act1: queue ≙ grd1: element ElementTypeMyType END ≔ ∅ grd2: index ∈ enqueue grd3: queue ≠ ∈ ℕ ANY element, index ( i·i dom(queue) index > i) ≙ ∅ ⇒ WHERE grd4: {index element} ElementTypeMyType ∀ ∈ ⇒ grd1: element ElementTypeMyType grd5: index dom(queue) ↦ ∈ ℕ ⇸ grd2: index element queue THEN ∈ ∉ grd3: i·i dom(queue) index ≤ i act2: queue queue {index element} ↦ ∈ THEN END ∀ ∈ ⇒ ≔ ∪ ↦ act1: queue queue {index element} END END ≔ ∖ ↦

12 method1 Queue subscribe enqueue init_partial_order Listener method2 dequeue subscribe notify notify enqueue is_max_element Partial Order method3 init_partial_order dequeue remove_element is_max_element remove_element

Aspect Oriented Programming: cross cutting concerns

13 Listener Queue Partial Order method1 subscribe init_partial_order method2 notify enqueue is_max_element method3 dequeue remove_element

Specializations of specification templates from the generic library

14

15 demo Event-B/Rodin

Specification Event-B templates specification templates

DSL/Ecore Constelle Meta-model definition

Constelle-to-Event-B DSL model Event-B specification

16 Conclusions

• Constelle as a front-end – Reuse of Event-B code via generic programming – Clear design via composition/mapping of aspects – Intermediate layer for bridging different technological platforms • Event-B as a back-end – Generic instantiation – (Shared event) composition – Library of reusable specification templates

17