Transformation of Applicative Specifications into Imperative ...

Transformation of Applicative Specifications into Imperative ... Transformation of Applicative Specifications into Imperative ...

26.09.2013 Views

CHAPTER 8. SPECIFICATIONS The FUNC Map The map, FUNC, is defined as follows: FUNC = Id →m FuncSpec, FuncSpec :: type_expr : TypeExpr value_expr : ValueExpr read_list : Access ∗ write_list : Access ∗ Access is defined in the RSL AST as follows: Access == AccessValueOrVariableName( variable_name : ValueOrVariableName), ValueOrVariableName :: id : Id, Id :: getText : Text The FUNC map maps function identifiers to the declared type of the function, the body value expression of the function declaration, a list of the types of interest that are read from during the evaluation of the function and a list of the types of interest that are written to during the evaluation of the function. The two access lists contain all types of interest accessed during execution of the function, even if these types of interest are accessed through function applications. These lists are established using the functions getAccessObs and getAccessGen, which recursively investigate the function and any other functions which may be applied in the function itself. The recursion stops when a function has already been evaluated. The FUNC map is used both during the check for transformability and during the transformation phase. It is used to decide whether application expressions are function application expression or map or list application expressions, it is used to determine the expected type of the arguments and results of function applications and it is used to establish access descriptors in the single typings of the functions. The FUNC map is established in the beginning of the transformation in the function TRClassExpr and does not change its value during the transformation. The ENV Map The map ENV is defined as follows: ENV = Id →m Binding 76

8.3. SPECIFICATION OF THE TRANSFORMER The ENV map maps types of interest to the value names under which they are known at a certain point of execution. The ENV map is related to a function and not to the entire specification . The initial value of the ENV map is computed both in CheckValueDef and TRValueDef when dealing with explicit function definitions, The ENV map is used to check if the special scope rules defined in Chapter 5 are fulfilled. Furthermore, it is used to decide which value names are of the type of interest and should be replaced with variables. When deciding if a value expression is transformable the following idea is pursued: A type identifier is mapped to a corresponding value name in ENV map, when the value name is in the scope. When the value name gets out of scope the entry is removed from the map. A value name can only be read from when it is in the scope, that is when it is in the range of the ENV map. When starting the check for transformability of the value expression of a function, the ENV map maps any type of interest occurring in the argument type of the function to the corresponding parameter name. During the check for transformability of let expressions the ENV map has to be updated according to the bindings in the let expressions to reflect the scopes of the value names. The content of the ENV map during a check for transformability is illustrated in Figure 8.1. By comparing this figure with Figure 5.1 on page 27 the connection between the scope rules and the ENV map should be obvious. type T value gen : ... → ... × T × ... f : T → ... f(t1) ≡ t1 + let t2 = t1 + gen(...) in t2 + gen(...) + ... end ↑ ↑ ↑ [ T ↦→ t1 ] [ T ↦→ t2 ] [ ] Figure 8.1: The ENV during transformability check The ENV map is a finite map, which means that it can hold at most one entry per type of interest. This conforms to the fact that there is only one placeholder for a variable, and that only one value name of a type of interest can be in scope at a certain point of execution. The most natural way to represent the ENV map is the reversed way, that is such that value names are mapped to type identifiers. But it turned 77

CHAPTER 8. SPECIFICATIONS<br />

The FUNC Map<br />

The map, FUNC, is defined as follows:<br />

FUNC = Id →m FuncSpec,<br />

FuncSpec ::<br />

type_expr : TypeExpr<br />

value_expr : ValueExpr<br />

read_list : Access ∗<br />

write_list : Access ∗<br />

Access is defined in the RSL AST as follows:<br />

Access ==<br />

AccessValueOrVariableName(<br />

variable_name : ValueOrVariableName),<br />

ValueOrVariableName :: id : Id,<br />

Id :: getText : Text<br />

The FUNC map maps function identifiers to the declared type <strong>of</strong> the function,<br />

the body value expression <strong>of</strong> the function declaration, a list <strong>of</strong> the<br />

types <strong>of</strong> interest that are read from during the evaluation <strong>of</strong> the function<br />

and a list <strong>of</strong> the types <strong>of</strong> interest that are written to during the evaluation<br />

<strong>of</strong> the function. The two access lists contain all types <strong>of</strong> interest accessed<br />

during execution <strong>of</strong> the function, even if these types <strong>of</strong> interest are accessed<br />

through function applications. These lists are established using the functions<br />

getAccessObs and getAccessGen, which recursively investigate the function<br />

and any other functions which may be applied in the function itself. The<br />

recursion stops when a function has already been evaluated.<br />

The FUNC map is used both during the check for transformability and<br />

during the transformation phase. It is used to decide whether application<br />

expressions are function application expression or map or list application<br />

expressions, it is used to determine the expected type <strong>of</strong> the arguments and<br />

results <strong>of</strong> function applications and it is used to establish access descriptors<br />

in the single typings <strong>of</strong> the functions.<br />

The FUNC map is established in the beginning <strong>of</strong> the transformation in<br />

the function TRClassExpr and does not change its value during the transformation.<br />

The ENV Map<br />

The map ENV is defined as follows:<br />

ENV = Id →m Binding<br />

76

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

Saved successfully!

Ooh no, something went wrong!