• No se han encontrado resultados

VI. EUROPA CREATIVA

2. CIUDADES CULTURALES, CIUDADES CREATIVAS

Based on the SOS rules given in the two previous sections, we are now able to implement an interpreter for causally correct Quartz programs. Figure4.8es-

// preparation phase

Enew= ReadInputs();

Enew= Enew∪ {(x, [⊥]) | x ∈ Vout∪ Vloc};

~init= {(x, 0) | x ∈ Vin∪ Vout∪ Vloc};

// perform delayed actions of previous macro step for (x, v) ∈ Dprvdo

Enew= [Enew]v(x,0); end;

// start fixpoint iteration to incrementally complete Enew do

Eold= Enew;

// compute must/can components

h~new, Dmust, Dcan, tmust, tcani " hEold, ~init, Si; // react to absence of actions on event variables for x ∈ Vevent

out ∪ Vloceventdo

H = {~(x) | (x = τ, ~) ∈ Dcan}; if 0 6∈ H ∧JxK

0

Enew= ⊥then Enew= [Enew]

default(x) (x,0) ; end;

// react to absence of actions on memorized variables for x ∈ Vmem

out ∪ Vlocmemdo

H = {~(x) | (x = τ, ~) ∈ Dcan}; if 0 6∈ H ∧JxK

0

Enew= ⊥then Enew= [Enew]

JxK

0 Eprv

(x,0) ; end;

// react to absence of actions on incarnated local variables for x ∈ Vevent loc ∪ V mem loc do for i = 1 . . . ~new(x) do H = {~(x) | (x = τ, ~) ∈ Dcan}; if i 6∈ H ∧JxK0

Enew= ⊥then Enew= [Enew]

default(x) (x,i) ; end

end;

// execute immediate actions of Dmust for (x = τ, ~) ∈ Dmustdo

Enew= [Enew] Jτ K~Enew (x,~(x)); end;

while (Eold6= Enew);

// transfer value of highest reincarnated value to the depth for x ∈ Vevent

loc ∪ Vlocmemdo

Enew= [Enew] JxK ~new (x) Enew (x,0) ; end;

// compute next statement

h~0

, S0, D, ti  hEnew, ~init, Si; return (Enew, S0, D, t); end

sentially gives the implementation of our interpreter that we explain in detail below.

The function MacroStep given in Figure4.8performs the computation of a macro step for a given statement S. In addition to the statement S, the func- tion receives as arguments the environment Eprv of the previous macro step

and the set of delayed actions Dprv that have been computed in the previous

macro step (which is initially the empty set). The outputs of the function are the current environment Enew, the residual statement S0, the set of delayed

actions D that are executed in the current macro step, and the termination flag t that tells us whether the program terminated or not.

The notation [E]v(x,h)means that the environment function E is changed for variable x so that the h-th value in the list E(x) is replaced with v. Moreover, we simply write 0 for the incarnation level function ~ that maps every variable to 0. Thus,JxK

0

E is the first value of E(x), i.e., x’s the value in the depth.

In the preparation phase, we read in the new inputs and reset the values of all output and local variables to the unknown value ⊥. The incarnation level of all variables is set to zero in the initial incarnation level function ~initthat

will be used in each iteration (since we start in the depth and climb up some surfaces of scopes). Hence, every variable is mapped to a list of values that has the length 1. After this, we ‘perform’ the delayed assignments that have been executed in the previous macro step. This means we change the value of each variable y at level 0 to the value v for each pair (y, v) that occurs in Dprv.

With the obtained environment Enew, we now start the fixpoint iteration

whose task is to compute the reaction of the program S. To this end, we use the SOS reaction rules given in Figure4.6and Figure4.7to compute the tuple h~new, Dmust, Dcan, tmust, tcani from the tuple hEnew, ~init, Si. The flags tmust and

tcan are no longer of interest here; they have only been used to be able to

perform the recursive computation of Dmustand Dcan.

Using the can-approximation Dcan we now first compute the reaction to absence. Intuitively, this means that we give every local/output event variable

its default value if that variable has not yet a known value and if the variable can not be modified by an immediate action in the current macro step. Simi- larly, we assign to every memorized variable its previous value if that variable has not yet a known value and if the variable can not be modified by an im- mediate action in the current macro step. Third, we compute the reaction to absence for the reincarnations of local variables. These are treated as event type variables, since they only live for the current macro step, and therefore they are initialized with the default values unless an immediate action deter- mines another value.

After the reaction to absence, some variables may already have changed their value from ⊥ to a known value in the updated environment Enew. Us-

ing this updated environment Enew, we now evaluate the expressions τ in all

immediate actions y = τ that we collected in the previous computation of the set Dmust. This enables us to finally execute the immediate actions which

incarnation level function that refers to the scopes where the assignment x=τ has been executed to be able to evaluate τ correctly. Alternatively, we could have evaluated τ during the computation of the SOS reaction rules, but then we could not benefit from the above reaction to absence, so that a further iteration would be required for some programs that is not necessary for the algorithm in Figure4.8.

Finally, we check whether a progress in the fixpoint iteration has been obtained, i.e., if Enew differs from Eold. If this is the case, we repeat the itera-

tion in order to further approximate the fixpoint. In addition, we may check whether the environment Enew is already complete, i.e., if all variables are

mapped to values different to ⊥. If this should be the case, we know that a further iteration can not update Enew furthermore, so that we can also stop

the computation.

After the termination of the fixpoint iteration, we have determined the complete environment Enew of the current reaction, i.e., in particular all val-

ues of the local and output variables in this macro step. Using Enew and the

initial incarnation level function ~init, we now compute the tuple h~0, S0, D, ti

from the tuple hEnew, ~init, Si according to the rules given in Figures4.1-4.3.

Depending on t, we may then invoke the computation of the next macro step or terminate the interpretation due to termination of the Quartz program.

The function whose fixpoint is computed is only implicitely given. It is a function from environments to environments and is used to compute the new value of Enew from the previous value of Enew. It is easily seen that this

function is monotonic, since during the fixpoint iteration only changes in the environments are done for variables that currently have the value ⊥, which increases the environment.

The termination of the fixpoint iteration that is done in function MacroStep is obvious, since our lattice of environments has only finite increasing chains. The reason for this is that every statement has only finitely many variables, and therefore every environment (E, ~) is also defined for only these finitely many variables. In every fixpoint iteration, one of the local or output vari- ables must change its value from ⊥ to a known value. Hence, this can only happen finitely often: The number of iterations is bounded by the number of local/output variables that have initially a value ⊥.

It may be the case that the fixpoint iteration ends with an environment that still contains unknown values ⊥ for some local/output variables. In this case, the program is not constructive and an error must be reported by the interpreter. Note that only constructive programs are considered to be se- mantically sound, and nonconstructive programs, even if they should have a unique behavior are viewed as not correct.

4.5 Symbolic SOS Transition Rules: The Control Flow

Documento similar