@@ -24,12 +24,26 @@ A *value* is one of the following:
24
24
25
25
* A struct value
26
26
27
- Every value belongs to exactly one type.
27
+ Every value _v_ belongs to exactly one <<Types_Canonical-Types,canonical type>>
28
+ _T_ , except as follows:
29
+
30
+ * Every string value belongs to the type `string` and to
31
+ all types `string` _n_ , for any _n_ .
32
+
33
+ * Every value that belongs to type _T_ also belongs to every
34
+ <<Types_Alias-Types,alias type>> whose
35
+ <<Types_Underlying-Types,underlying type>> is _T_ .
36
+
37
+ When a value _v_ belongs to a type _T_ , we say that _v_ is a value
38
+ *of type _T_* .
39
+
40
+ In the following subsections, we describe each kind of value and
41
+ its associated canonical types.
28
42
29
43
=== Primitive Integer Values
30
44
31
45
A *primitive integer value* is an ordinary (mathematical) integer value
32
- together with a
46
+ together with its canonical type, which is a
33
47
<<Types_Primitive-Integer-Types,primitive integer type>>. Formally, the set of
34
48
primitive integer values
35
49
is the disjoint union over the integer types of the values
@@ -43,14 +57,15 @@ stem:[[0, 255\]].
43
57
stem:[[-2^(w-1), 2^(w-1)-1\]]. For example, `I8` represents the integers
44
58
stem:[[-128, 127\]].
45
59
46
- We represent a primitive integer value as an expression followed by a colon and a type.
60
+ We represent a primitive integer value as an expression followed by a colon and
61
+ a primitive integer type.
47
62
For example, we write the value 1 at type `U32` as `1: U32`. The value `1:
48
63
U32` is distinct from the value `1: U8`.
49
64
50
65
=== Integer Values
51
66
52
67
An *integer value* is an ordinary (mathematical) integer value.
53
- It has type _Integer_.
68
+ Its canonical type is _Integer_.
54
69
We represent an integer value as an integer number, with no explicit type.
55
70
For example, `1` is an integer value.
56
71
@@ -66,25 +81,34 @@ over the types `F32` and `F64` of the values represented by each type:
66
81
67
82
We write a floating-point values analogously to primitive integer values. For
68
83
example, we write the value 1.0 at type `F32` as `1.0: F32`.
84
+ The canonical type of a floating-point value is `F32` or `F64`.
69
85
70
86
=== Boolean Values
71
87
72
88
A *Boolean value* is one of the values `true` and `false`.
73
- Its type is `bool`.
89
+ Its canonical type is `bool`.
74
90
75
91
=== String Values
76
92
77
93
A *string value* is a sequence of characters that can be
78
94
represented as a <<Expressions_String-Literals,string literal expression>>.
79
95
It is written in the same way as a string literal expression,
80
96
e.g., `"abc"`.
81
- Its type is `string`.
97
+ A string value belongs to the following canonical types:
98
+
99
+ * `string`
100
+
101
+ * `string` _n_ for any _n_
82
102
83
103
=== Abstract Type Values
84
104
85
105
An *abstract type value* is a value associated with an abstract
86
106
type.
87
- There is one value associated with each abstract type stem:[T].
107
+ For each abstract type stem:[T], there is one
108
+ value with canonical type stem:[T].
109
+ This value is not represented explicitly in the model, but it
110
+ may be represented in the generated code, e.g., as an object
111
+ with default initialization.
88
112
We write the value `value of type` stem:[T].
89
113
90
114
=== Anonymous Array Values
@@ -93,10 +117,17 @@ An *anonymous array value* is a value associated with an anonymous
93
117
array type.
94
118
We write an anonymous array value similarly to an
95
119
<<Expressions_Array-Expressions,array expression>>:
96
- an anonymous array value has the form `[` stem:[v_1] `,` stem:[...] `,`
120
+ an anonymous array value stem:[v] has the form `[` stem:[v_1] `,` stem:[...]
121
+ `,`
97
122
stem:[v_n] `]`, where for each stem:[i in [1,n]], stem:[v_i] is a value of type
98
- stem:[T] for some stem:[T].
99
- The type of the value is _[_ stem:[n] _]_ stem:[T].
123
+ stem:[T] for some <<Types_Canonical-Types,canonical type>> stem:[T].
124
+ The canonical type of stem:[v] is _[_ stem:[n] _]_ stem:[T].
125
+
126
+ Note that for an anonymous array value stem:[v] to be well-formed, the member
127
+ values must have identical types.
128
+ If an array expression appearing in the source syntax has
129
+ member values with non-identical types, then one or more members must be
130
+ converted to a different type before forming stem:[v].
100
131
101
132
=== Array Values
102
133
@@ -116,16 +147,20 @@ that refers to a
116
147
with member type stem:[T].
117
148
118
149
. For each stem:[i in [1,n]], stem:[v_i] is a value of type stem:[T].
150
+ Note that stem:[T] need not be a canonical type.
151
+ For example, it is permissible for stem:[T] to be `T`, for
152
+ `T` to be an alias of `U32`, and for stem:[v] to be the value `[ 1: U32, 2: U32 ]`.
153
+ In this case `1: U32` and `2: U32` are values of type `T`, as required.
119
154
120
- The type of the value is stem:[Q].
155
+ The canonical type of the value is stem:[Q].
121
156
122
157
=== Enumeration Values
123
158
124
159
An *enumeration value* is a value associated with an
125
160
<<Definitions_Enumerated-Constant-Definitions,enumerated constant definition>>.
126
161
It is a pair consisting of the name and the integer value
127
162
specified in the enumerated constant definition.
128
- Its type is the type associated with the
163
+ Its canonical type is the type associated with the
129
164
<<Definitions_Enum-Definitions,enum definition>> in which
130
165
the enumerated constant definition appears.
131
166
@@ -139,8 +174,9 @@ We write an anonymous struct value stem:[v] similarly to a
139
174
a struct value has the form `{` stem:[m_1] `=` stem:[v_1] `,` stem:[...] `,`
140
175
stem:[m_n] `=` stem:[v_n] `}`,
141
176
where for each stem:[i in [1,n]], stem:[v_i] is a value of type stem:[T_i].
142
- The type of stem:[v] is _{_ stem:[m_1] _:_ stem:[T_1] _,_ stem:[...] _,_
143
- stem:[m_n] _:_ stem:[T_n] _}_.
177
+ Each type stem:[T_i] must be a <<Types_Canonical-Types,canonical type>>.
178
+ The canonical type of the value is _{_ stem:[m_1] _:_ stem:[T_1] _,_ stem:[...]
179
+ _,_ stem:[m_n] _:_ stem:[T_n] _}_.
144
180
145
181
=== Struct Values
146
182
@@ -161,8 +197,13 @@ that refers to a
161
197
. The members of stem:[Q] are stem:[m_i] `:` stem:[T_i] for stem:[i in [1,n\]].
162
198
163
199
. For each stem:[i in [1,n]], stem:[v_i] is a value of type stem:[T_i].
200
+ Note that stem:[T_i] need not be a canonical type.
201
+ For example, it is permissible for stem:[T_1] to be `T`, for
202
+ `T` to be an alias of `U32`, and for stem:[v_1] to be the value `1: U32`.
203
+ In this case `1: U32` is a value of type `T`, as required.
164
204
165
- All the members must be explicitly assigned values.
205
+ Each member of the struct value must have an explicit value.
206
+ The canonical type of the struct value is stem:[Q].
166
207
167
208
=== Serialized Sizes
168
209
@@ -200,3 +241,7 @@ the sum of the serialized sizes of the members of _v_
200
241
* If _T_ is an
201
242
<<Types_Abstract-Types,abstract type>>, then _s_ is not specified in FPP. It
202
243
is up to the implementer of _T_ to provide the serialized size.
244
+
245
+ * If _T_ is a
246
+ <<Types_Alias-Types,alias type>>, then apply these rules to its
247
+ <<Types_Underlying-Types,underlying type>>.
0 commit comments