26.12.2012 Views

ATL: Atlas Transformation Language Specification of the ... - Eclipse

ATL: Atlas Transformation Language Specification of the ... - Eclipse

ATL: Atlas Transformation Language Specification of the ... - Eclipse

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>Specification</strong> <strong>of</strong> <strong>the</strong> <strong>ATL</strong> Virtual Machine<br />

operand stack. Prior to each iteration, a new element <strong>of</strong> <strong>the</strong> reference collection is pushed onto <strong>the</strong> operand<br />

stack. The enditerate instruction only aims to mark <strong>the</strong> end <strong>of</strong> an iterative block (it is not associated with any<br />

particular treatment).<br />

The <strong>ATL</strong> language defines three main iterative instructions: select, collect and iterate. The select<br />

instruction enables to select a subset <strong>of</strong> <strong>the</strong> reference collection. Elements <strong>of</strong> this reference collection are<br />

filtered according to a boolean expression. A select instruction produces an output collection which size is<br />

equal or less than <strong>the</strong> one <strong>of</strong> <strong>the</strong> reference collection. These elements moreover have <strong>the</strong> same type that<br />

those <strong>of</strong> <strong>the</strong> reference collection. As opposed to <strong>the</strong> select one, <strong>the</strong> collect instruction produces a<br />

homogeneous Sequence <strong>of</strong> elements whose cardinal is equal to <strong>the</strong> reference collection one. Although <strong>the</strong><br />

returned sequence is to be homogeneous, <strong>the</strong> type <strong>of</strong> its elements may be different from <strong>the</strong> one <strong>of</strong><br />

reference collection elements. A collect may, for instance, be used on a model elements collection to<br />

compile <strong>the</strong> values <strong>of</strong> a given property <strong>of</strong> <strong>the</strong>se elements. It can also be used on any collection <strong>of</strong> cardinal n<br />

to easily produce a new Sequence composed <strong>of</strong> n identical constant values.<br />

We propose here to illustrate <strong>the</strong> compilation <strong>of</strong> both select and collect <strong>ATL</strong> instructions. We first<br />

consider an example making use <strong>of</strong> <strong>the</strong> select function. We introduce, in this scope, a set <strong>of</strong> integral<br />

values:<br />

let int_set: Set(Integer) = Set{8, 15, 6, 3, 19}<br />

It is now possible to operate a selection on int_set in order to build <strong>the</strong> subset <strong>of</strong> values that are greater<br />

than 10. This selection corresponds to <strong>the</strong> following <strong>ATL</strong> statement:<br />

int_set->select(e | e > 10);<br />

This simple <strong>ATL</strong> selection can be compiled into <strong>the</strong> following <strong>ATL</strong> virtual machine instructions set:<br />

0 <br />

1 <br />

2 <br />

3 <br />

4 <br />

5 <br />

6 <br />

7 <br />

8 <br />

9 <br />

10 <br />

11 <br />

12 <br />

13 <br />

Performing a select operation on an <strong>ATL</strong> set results in a new set that contains <strong>the</strong> only elements that fulfil<br />

<strong>the</strong> condition specified with <strong>the</strong> boolean expression. The first step <strong>the</strong>refore consists in instantiating a new<br />

empty set. This is achieved with instructions 0 to 2. Assuming that <strong>the</strong> reference set is stored within local<br />

variable 1, it can be <strong>the</strong>n loaded on top <strong>of</strong> <strong>the</strong> operand stack (instruction 3). The iterate instruction uses this<br />

set as its reference collection.<br />

Prior to each iteration, a new element <strong>of</strong> <strong>the</strong> collection is implicitly pushed onto <strong>the</strong> operand stack by <strong>the</strong> <strong>ATL</strong><br />

virtual machine. This element is saved into local variable 2 and made available again on top <strong>of</strong> <strong>the</strong> operand<br />

stack by instructions 5 and 6. Next step corresponds to <strong>the</strong> evaluation <strong>of</strong> <strong>the</strong> <strong>ATL</strong> boolean expression (e ><br />

10). For this purpose, <strong>the</strong> 10 integral constant is pushed onto <strong>the</strong> operand stack (instruction 7) and <strong>the</strong> ><br />

operation is called with <strong>the</strong> current element as context and <strong>the</strong> integral constant as parameter (instruction 8).<br />

This invocation returns a boolean value on top <strong>of</strong> <strong>the</strong> operand stack. Next instruction calls <strong>the</strong> not operation<br />

with <strong>the</strong> previously returned boolean value as context (instruction 9). This new invocation pushes a new<br />

boolean value onto <strong>the</strong> operand stack. This value is <strong>the</strong>n tested by a conditional branch (instruction 10). If<br />

<strong>the</strong> value is true (i.e. <strong>the</strong> <strong>ATL</strong> condition is not fulfilled), <strong>the</strong> execution flow is redirected to instruction 13<br />

which corresponds to <strong>the</strong> end <strong>of</strong> <strong>the</strong> current iteration. O<strong>the</strong>rwise, if <strong>the</strong> <strong>ATL</strong> condition is fulfilled, execution<br />

proceeds from <strong>the</strong> next instruction (instruction 11). This instruction loads <strong>the</strong> current collection element onto<br />

Page 48 / 62

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!