blob: fdd81e3fa52347fe2445c8c9f6e7bf33f7114c60 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
Sized generics / opaque sized types
===================================
Size-constrained type parameters:
# interface
type List8<anyint8 T>
type List16<anyint16 T>
type List32<anyint32 T>
type List64<anyint64 T>
func List8.add(T elem)
func List16.add(T elem)
...
# implementation
func List8.add(T elem)
{
...
}
...
Note that arithmetic operations are NOT allowed on these types!
Avoiding repetition
-------------------
* Manually specifying that multi-sized types and code should be created?
* Implicit (internal) creation of the types/code?
Implicit creation of multi-sized types/code
-------------------------------------------
This would mean that for every generic type there would be 4-6 types under the
hood:
8 bit, 16 bit, 32 bit, 64 bit (and maybe larger types for ref/funcref).
But this can create combinatorial explosions:
type Map<K,V>
func Map.translate<K2,V2>(funcref (K oldkey, V oldvalue, out K2 newkey, out V2 newvalue) translator) -> Map<K2,V2>
This needs:
4^4 = 256 variants!!!
This can be reduced by only generating variants with equal types for the
parameters (but allow smaller types in the parameters, just not optimized
to the smaller types).
|