Transformation of Applicative Specifications into Imperative ...
Transformation of Applicative Specifications into Imperative ... Transformation of Applicative Specifications into Imperative ...
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
- Page 42 and 43: CHAPTER 5. TRANSFORMABILITY scheme
- Page 44 and 45: CHAPTER 5. TRANSFORMABILITY 28
- Page 46 and 47: CHAPTER 6. TRANSFORMATIONS 6.2.1 Tr
- Page 48 and 49: CHAPTER 6. TRANSFORMATIONS Example
- Page 50 and 51: CHAPTER 6. TRANSFORMATIONS Applicat
- Page 52 and 53: CHAPTER 6. TRANSFORMATIONS object A
- Page 54 and 55: CHAPTER 6. TRANSFORMATIONS type T =
- Page 56 and 57: CHAPTER 6. TRANSFORMATIONS where ge
- Page 58 and 59: CHAPTER 6. TRANSFORMATIONS Ranged s
- Page 60 and 61: CHAPTER 6. TRANSFORMATIONS ✄ end
- Page 62 and 63: CHAPTER 6. TRANSFORMATIONS Value In
- Page 64 and 65: CHAPTER 6. TRANSFORMATIONS ✄ sche
- Page 66 and 67: CHAPTER 6. TRANSFORMATIONS A case e
- Page 68 and 69: CHAPTER 6. TRANSFORMATIONS is due t
- Page 70 and 71: CHAPTER 6. TRANSFORMATIONS 6.4.4 Tr
- Page 72 and 73: CHAPTER 6. TRANSFORMATIONS 56
- Page 74 and 75: CHAPTER 7. CORRECTNESS OF TRANSFORM
- Page 76 and 77: CHAPTER 7. CORRECTNESS OF TRANSFORM
- Page 78 and 79: CHAPTER 7. CORRECTNESS OF TRANSFORM
- Page 80 and 81: CHAPTER 7. CORRECTNESS OF TRANSFORM
- Page 82 and 83: CHAPTER 7. CORRECTNESS OF TRANSFORM
- Page 84 and 85: CHAPTER 7. CORRECTNESS OF TRANSFORM
- Page 86 and 87: CHAPTER 7. CORRECTNESS OF TRANSFORM
- Page 88 and 89: CHAPTER 8. SPECIFICATIONS The rewri
- Page 90 and 91: CHAPTER 8. SPECIFICATIONS RSL speci
- Page 94 and 95: CHAPTER 8. SPECIFICATIONS out, that
- Page 96 and 97: CHAPTER 8. SPECIFICATIONS construct
- Page 98 and 99: CHAPTER 8. SPECIFICATIONS 8.4.1 Mor
- Page 100 and 101: CHAPTER 8. SPECIFICATIONS PRECOND_T
- Page 102 and 103: CHAPTER 8. SPECIFICATIONS if length
- Page 104 and 105: CHAPTER 8. SPECIFICATIONS subtypes.
- Page 106 and 107: CHAPTER 8. SPECIFICATIONS 8.5.2 Cha
- Page 108 and 109: CHAPTER 8. SPECIFICATIONS axiom [ m
- Page 110 and 111: CHAPTER 8. SPECIFICATIONS Specifica
- Page 112 and 113: CHAPTER 8. SPECIFICATIONS the lack
- Page 114 and 115: CHAPTER 9. IMPLEMENTATION OF THE TR
- Page 116 and 117: CHAPTER 9. IMPLEMENTATION OF THE TR
- Page 118 and 119: CHAPTER 9. IMPLEMENTATION OF THE TR
- Page 120 and 121: CHAPTER 9. IMPLEMENTATION OF THE TR
- Page 122 and 123: CHAPTER 9. IMPLEMENTATION OF THE TR
- Page 124 and 125: CHAPTER 9. IMPLEMENTATION OF THE TR
- Page 126 and 127: CHAPTER 10. EXAMPLES OF TRANSFORMAT
- Page 128 and 129: CHAPTER 10. EXAMPLES OF TRANSFORMAT
- Page 130 and 131: CHAPTER 10. EXAMPLES OF TRANSFORMAT
- Page 132 and 133: CHAPTER 10. EXAMPLES OF TRANSFORMAT
- Page 134 and 135: CHAPTER 10. EXAMPLES OF TRANSFORMAT
- Page 136 and 137: CHAPTER 11. TEST 11.1.1 Lexer and P
- Page 138 and 139: CHAPTER 11. TEST An overview of the
- Page 140 and 141: CHAPTER 12. POSSIBLE EXTENSIONS OF
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