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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

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

int_set->iterate(e; ret : Integer = 0 | ret + e);<br />

As a reminder, e identifies <strong>the</strong> current element <strong>of</strong> <strong>the</strong> reference collection. ret : Integer = 0<br />

corresponds to <strong>the</strong> declaration and <strong>the</strong> initialization <strong>of</strong> <strong>the</strong> variable to be returned (ret). Finally, ret + e<br />

specifies <strong>the</strong> operation to be iteratively performed. This <strong>ATL</strong> instruction can be compiled into <strong>the</strong> following<br />

<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 />

Similarly to <strong>the</strong> previously described <strong>ATL</strong> iterative instructions, <strong>the</strong> first step consists in allocating and<br />

initializing <strong>the</strong> variable used to store <strong>the</strong> value to be returned. However, compared to <strong>the</strong> o<strong>the</strong>r iterative<br />

instructions, this variable can be here <strong>of</strong> any <strong>ATL</strong> types. In this example, this step consists in initializing <strong>the</strong><br />

integral value ret to 0. This is achieved by instruction 0. Initilialized value is <strong>the</strong>n stored in local variable 2<br />

(instruction 1). Assuming that <strong>the</strong> reference set is stored within local variable 1, it is <strong>the</strong>n loaded on top <strong>of</strong> <strong>the</strong><br />

operand stack (instruction 2). The iterate instruction (instruction 3) uses this set as its reference collection.<br />

A new element <strong>of</strong> <strong>the</strong> reference collection is implicitly pushed onto <strong>the</strong> operand stack at <strong>the</strong> beginning <strong>of</strong><br />

each iteration. It is saved into local variable 3 by instruction 4. Instructions 5 and 6 respectively load <strong>the</strong><br />

value to be returned and <strong>the</strong> current element on top <strong>of</strong> <strong>the</strong> operand stack. The operation + is <strong>the</strong>n called with<br />

<strong>the</strong> value to be returned as context and <strong>the</strong> current element <strong>of</strong> <strong>the</strong> reference collection as parameter<br />

(instruction 7). As a result, <strong>the</strong> operation pushes <strong>the</strong> computed value onto <strong>the</strong> operand stack. This value is<br />

stored in local variable 2 as <strong>the</strong> value to be returned (instruction 8). Once <strong>the</strong> iteration has completed, <strong>the</strong><br />

content <strong>of</strong> local variable 2 is loaded onto <strong>the</strong> operand stack (instruction 10).<br />

6.2.8 Receiving Arguments<br />

As opposed to Java, <strong>the</strong> <strong>ATL</strong> language does not define context-less operation calls facilities. Whereas<br />

static Java methods do not have any instance, all invoked operations in <strong>ATL</strong> are to be associated with a<br />

specific context. As a consequence, <strong>the</strong>re exist a one and only way to receive arguments for <strong>ATL</strong> operations.<br />

The n arguments that are passed to an invoked operation are stored in <strong>the</strong> localvariabletable structure<br />

<strong>of</strong> <strong>the</strong> stack frame created for <strong>the</strong> new operation. The table entry 0 is reserved to hold a reference to <strong>the</strong><br />

context in which <strong>the</strong> operation is called and <strong>the</strong> arguments are stored in local variables numbered from 1 to<br />

n. The arguments are received in <strong>the</strong> order <strong>the</strong>y were passed. As an example, consider <strong>the</strong> code <strong>of</strong> <strong>the</strong><br />

following <strong>ATL</strong> helper:<br />

helper<br />

def: firstOfTwo(i: Integer, j: Integer) : Integer = i;<br />

This helper is defined in <strong>the</strong> context <strong>of</strong> <strong>the</strong> <strong>ATL</strong> context module and simply returns <strong>the</strong> value <strong>of</strong> its first<br />

argument. It compiles to:<br />

Operation int firstOfTwo(int,int)<br />

0 <br />

The value <strong>of</strong> <strong>the</strong> operation first argument is loaded on top <strong>of</strong> <strong>the</strong> operand stack. This top value is <strong>the</strong> one to<br />

be returned when <strong>the</strong> operation completes.<br />

Page 50 / 62

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

Saved successfully!

Ooh no, something went wrong!