25.07.2014 Views

VDM-10 Language Manual

VDM-10 Language Manual

VDM-10 Language Manual

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.

Chapter 13. Statements<br />

✞<br />

op1 : nat ==> nat<br />

op1(m) ==<br />

duration (20) return m + 1;<br />

op2 : () ==> nat<br />

op2() ==<br />

( dcl n : nat := 3;<br />

duration(<strong>10</strong>) n := op1(1);<br />

return n)<br />

✡✝<br />

✆<br />

When executing op2, if the call to op1 is executed, the duration statement in op1 will be<br />

overridden by the duration statement in the environment of the call. Thus in op2 following<br />

execution of the statement n := op1(1); the internal clock is incremented by <strong>10</strong> time<br />

units only.<br />

13.17 The Cycles Statement (<strong>VDM</strong>-RT)<br />

Syntax: statement = . . .<br />

| cycles statement ;<br />

cycles statement = ‘cycles’, ‘(’, numeral, ‘)’,<br />

statement ;<br />

Semantics: The cycles statement is a runtime directive to the Toolbox interpreter telling it that<br />

when incrementing the internal clock for the enclosed statement, the value (a natural number)<br />

given in the cycles statement should be used as an indication of how many clock cycles<br />

that the enclosed statement should be incremented by instead of the increment which would<br />

normally be computed for that statement. Thus the cycles statement provides a mechanism to<br />

override the Toolbox’s default execution time computation similar to the duration statement<br />

but in a way that is relative to the speed of the CPU that the computation is carried out on.<br />

Example: First a simple example:<br />

✞<br />

✡✝<br />

while n < <strong>10</strong> do<br />

cycles(<strong>10</strong>00) n := n + 1;<br />

✆<br />

In this example, assuming that this loop is not executed in the context of an enclosing cycles<br />

statement, on each iteration of the loop the Toolbox will increment its internal clock by the<br />

time it will take to process <strong>10</strong>00 instructions on the given CPU (relative to its capacity), rather<br />

than computing the amount of time required to execute the statement n := n + 1.<br />

123

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

Saved successfully!

Ooh no, something went wrong!