forked from torch2424/as-bind
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.ts
189 lines (149 loc) · 5.29 KB
/
test.ts
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
// The entry file of your WebAssembly module.
// User submitted issues
// Learned from this, you must use a TypedArray, and not something like: Array<f64>
export function issue28(arr: Float64Array): f64 {
let sum: f64 = 2.0;
for (let i = 0; i < 3; ++i) {
sum += arr[i];
}
return arr.length;
}
// Basic value Passing
export function helloWorld(world: string): string {
return "Hello " + world + "!";
}
export function helloWorldTwo(world: string, worldTwo: string): string {
return "Hello " + world + " and " + worldTwo + "!";
}
export function refAndNumberArgsReturnsRef(ref: string, num: i32): string {
return "Ref: " + ref + " Number: " + num.toString();
}
export function numberAndRefArgsReturnsRef(num: i32, ref: string): string {
return "Ref: " + ref + " Number: " + num.toString();
}
export function numberAndRefArgsReturnsNumber(num: i32, ref: string): i32 {
return ref.length + num;
}
export function Int32Support(value: i32): i32 {
return value + 1;
}
export function Float32Support(value: f32): f32 {
return value + 1.0;
}
export function Float64Support(value: f64): f64 {
return value + 1.0;
}
export function mapInt8Array(array: Int8Array): Int8Array {
return array.map((value: i8) => value * 2);
}
export function mapUint8Array(array: Uint8Array): Uint8Array {
return array.map((value: u8) => value * 2);
}
export function mapInt16Array(array: Int16Array): Int16Array {
return array.map((value: i16) => value * 2);
}
export function mapUint16Array(array: Uint16Array): Uint16Array {
return array.map((value: u16) => value * 2);
}
export function mapInt32Array(array: Int32Array): Int32Array {
return array.map((value: i32) => value * 2);
}
export function mapUint32Array(array: Uint32Array): Uint32Array {
return array.map((value: u32) => value * 2);
}
export function mapFloat32Array(array: Float32Array): Float32Array {
return array.map((value: f32) => value * 2);
}
export function mapFloat64Array(array: Float64Array): Float64Array {
return array.map((value: f64) => value * 2);
}
export function mapBigInt64Array(array: Int64Array): Int64Array {
return array.map((value: i64) => value * 2);
}
export function mapBigUint64Array(array: Uint64Array): Uint64Array {
return array.map((value: u64) => value * 2);
}
export function mapI32Array(array: Array<i32>): Array<i32> {
return array.map<i32>((value: i32) => value * 2);
}
export function mapI64Array(array: Array<i64>): Array<i64> {
return array.map<i64>((value: i64) => value * 2);
}
export function mapStringArray(array: Array<string>): Array<string> {
return array.map<string>((value: string) => "#" + value);
}
export function mapBoolArray(array: Array<bool>): Array<bool> {
return array.map<bool>((value: bool) => !value);
}
export function mapI32ArrayArray(array: Array<Array<i32>>): Array<Array<i32>> {
return array.map<Array<i32>>((value: Array<i32>) =>
value.map<i32>((v: i32) => v * 2)
);
}
export function mapI64ArrayArray(array: Array<Array<i64>>): Array<Array<i64>> {
return array.map<Array<i64>>((value: Array<i64>) =>
value.map<i64>((v: i64) => v * 2)
);
}
export function mapStringArrayArray(
array: Array<Array<string>>
): Array<Array<string>> {
return array.map<Array<string>>((value: Array<string>) =>
value.map<string>((v: string) => "#" + v)
);
}
export function mapBoolArrayArray(
array: Array<Array<bool>>
): Array<Array<bool>> {
return array.map<Array<bool>>((value: Array<bool>) =>
value.map<bool>((v: bool) => !v)
);
}
declare function testImportString(value: string): void;
export function callTestImportString(value: string): void {
testImportString(value);
}
declare function testImportTwoStrings(valueOne: string, valueTwo: string): void;
export function callTestImportTwoStrings(
valueOne: string,
valueTwo: string
): void {
testImportTwoStrings(valueOne, valueTwo);
}
declare function testImportReturnNumber(): i32;
export function callTestImportReturnNumber(): i32 {
let response: i32 = testImportReturnNumber();
return response;
}
declare function testImportInt8Array(value: Int8Array): void;
export function callTestImportInt8Array(value: Int8Array): void {
testImportInt8Array(value);
}
declare function testImportUint8Array(value: Uint8Array): void;
export function callTestImportUint8Array(value: Uint8Array): void {
testImportUint8Array(value);
}
declare function testImportInt16Array(value: Int16Array): void;
export function callTestImportInt16Array(value: Int16Array): void {
testImportInt16Array(value);
}
declare function testImportUint16Array(value: Uint16Array): void;
export function callTestImportUint16Array(value: Uint16Array): void {
testImportUint16Array(value);
}
declare function testImportInt32Array(value: Int32Array): void;
export function callTestImportInt32Array(value: Int32Array): void {
testImportInt32Array(value);
}
declare function testImportUint32Array(value: Uint32Array): void;
export function callTestImportUint32Array(value: Uint32Array): void {
testImportUint32Array(value);
}
declare function testImportFloat32Array(value: Float32Array): void;
export function callTestImportFloat32Array(value: Float32Array): void {
testImportFloat32Array(value);
}
declare function testImportFloat64Array(value: Float64Array): void;
export function callTestImportFloat64Array(value: Float64Array): void {
testImportFloat64Array(value);
}