You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
**Hint: `// Wasmnizer-ts: @WASMArray@ ` is necessary, and `<Not_Packed, Mutable, Nullable>` is optional. The latter shows that `if the array element is packed`, `if the array element is mutable`, `if the array is nullable`. The default value is `Not_Packed`, `Mutable` and `Nullable`.**
32
+
33
+
2. For `struct`, we use `comment + tuple type alias` to represent the raw wasm struct type.
**Hint: `// Wasmnizer-ts: @WASMStruct@ ` is necessary, and `<[Not_Packed, ...], [Mutable, ...], Nullable, BaseTypeName>` is optional. The latter shows that `if the struct fields are packed`, `if the struct fields are mutable`, `if the struct is nullable`, `the struct's base type name`. The default value is `[Not_Packed, ...]`, `[Mutable, ...]`, `Nullable` and `NULL`.**
44
+
45
+
The comments' optional attributes can be one of these enum value:
46
+
```ts
47
+
exportenumPackedTypeKind {
48
+
Not_Packed='Not_Packed',
49
+
I8='I8',
50
+
I16='I16',
51
+
}
52
+
53
+
exportenumMutabilityKind {
54
+
Immutable='Immutable',
55
+
Mutable='Mutable',
56
+
}
57
+
58
+
exportenumNullabilityKind {
59
+
NonNullable='NonNullable',
60
+
Nullable='Nullable',
61
+
}
62
+
```
63
+
64
+
## Example
65
+
### Used as basic type
10
66
If we define the wasmtype for variables, and the right value is LiteralValue or variables with the same wasmtype, the **no cast** will be generated.
11
67
```ts
12
68
const a:i32=100;
@@ -32,6 +88,27 @@ const a: f64 = 100;
32
88
(f64.const100)
33
89
```
34
90
91
+
```ts
92
+
// Wasmnizer-ts: @WASMArray@
93
+
typearrayType2=i32[];
94
+
const a:arrayType2= [100];
95
+
-->
96
+
(array.new_fixed$array01
97
+
(i32.const100)
98
+
)
99
+
```
100
+
101
+
```ts
102
+
// Wasmnizer-ts: @WASMStruct@
103
+
typestructType2= [i64, i32];
104
+
const a:structType2= [100, 200]
105
+
--->
106
+
(struct.new$45
107
+
(i64.const100)
108
+
(i32.const200)
109
+
)
110
+
```
111
+
35
112
If we don't define the wasmtype explicitly, then the variable will be regard as `number` type, **one cast** will be occurs.
36
113
```ts
37
114
const a =100asi32;
@@ -42,12 +119,21 @@ const a = 100 as i32;
42
119
```
43
120
44
121
45
-
### For array type
122
+
### Used as array element type
46
123
The array type should be explicitly specified too.
0 commit comments