-
-
Notifications
You must be signed in to change notification settings - Fork 670
/
Copy pathesm.ts
178 lines (143 loc) · 3.87 KB
/
esm.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
export const plainGlobal = 1;
export var plainMutableGlobal = 2;
export const stringGlobal = "a";
export var mutableStringGlobal = "b";
export enum Enum {
ONE = 1,
TWO = 2,
THREE
};
export const enum ConstEnum {
ONE = 1,
TWO = 2,
THREE
}
export function plainFunction(a: i32, b: i32): i32 {
return a + b;
}
export function plainFunction64(a: i64, b: i64): i64 {
return a + b;
}
export function getMaxUnsigned32(): u32 {
return u32.MAX_VALUE; // 4294967295
}
export function getMaxUnsigned64(): u64 {
return u64.MAX_VALUE; // 18446744073709551615
}
export function bufferFunction(a: ArrayBuffer, b: ArrayBuffer): ArrayBuffer {
var aByteLength = a.byteLength;
var bByteLength = b.byteLength;
var out = new ArrayBuffer(aByteLength + bByteLength);
memory.copy(changetype<usize>(out), changetype<usize>(a), <usize>aByteLength);
memory.copy(changetype<usize>(out) + <usize>aByteLength, changetype<usize>(b), <usize>bByteLength);
return out;
}
export function stringFunction(a: string, b: string): string {
return a + b;
}
export function stringFunctionOptional(a: string, b: string = "b"): string {
return a + b;
}
export function typedarrayFunction(a: Int16Array, b: Float32Array): Uint64Array {
var out = new Uint64Array(a.length + b.length);
for (let i = 0; i < a.length; ++i) {
out[i] = <u64>a[i];
}
for (let i = 0; i < b.length; ++i) {
out[a.length + i] = <u64>b[i];
}
return out;
}
export function staticarrayFunction(a: StaticArray<i32>, b: StaticArray<i32>): StaticArray<i32> {
var c = new StaticArray<i32>(a.length + b.length);
for (let i = 0; i < a.length; ++i) {
c[i] = a[i];
}
for (let i = 0; i < b.length; ++i) {
c[a.length + i] = b[i];
}
return c;
}
export function staticarrayU16(a: StaticArray<u16>): StaticArray<u16> {
return a;
}
export function staticarrayI64(a: StaticArray<i64>): StaticArray<i64> {
return a;
}
export function arrayFunction(a: Array<i32>, b: Array<i32>): Array<i32> {
var c = new Array<i32>(a.length + b.length);
for (let i = 0; i < a.length; ++i) {
c[i] = a[i];
}
for (let i = 0; i < b.length; ++i) {
c[a.length + i] = b[i];
}
return c;
}
export function arrayOfStringsFunction(a: Array<string>, b: Array<string>): Array<string> {
var c = new Array<string>(a.length + b.length);
for (let i = 0; i < a.length; ++i) {
c[i] = a[i];
}
for (let i = 0; i < b.length; ++i) {
c[a.length + i] = b[i];
}
return c;
}
class PlainObject {
a: i8;
b: i16;
c: i32;
d: i64;
e: u8;
f: u16;
g: u32;
h: u64;
i: isize;
j: usize;
k: bool;
l: f32;
m: f64;
n: string | null;
o: Uint8Array | null;
p: Array<string> | null;
}
export function objectFunction(a: PlainObject, b: PlainObject): PlainObject {
let ref = new PlainObject();
ref.a = a.a + b.a;
ref.b = a.b + b.b;
return ref;
}
class NonPlainObject {
constructor() {}
}
export function newInternref(): NonPlainObject {
return new NonPlainObject();
}
export function internrefFunction(a: NonPlainObject, b: NonPlainObject): NonPlainObject {
return a;
}
export function functionFunction(fn: () => void): () => void {
return fn;
}
export const fn = function(): void {};
trace("trace", 1, 42);
import { console, Math } from "bindings/dom";
console.log("42 from console.log");
Math.log(Math.E);
// @ts-ignore
@external("env", "globalThis") declare const immutableGlobal: externref;
immutableGlobal;
// @ts-ignore
@external("env", "globalThis.globalThis") declare const immutableGlobalNested: externref;
immutableGlobalNested;
// @ts-ignore
@external("env", "Date.getTimezoneOffset")
@external.js("return new Date().getTimezoneOffset();")
declare function Date_getTimezoneOffset(): i32;
Date_getTimezoneOffset();
// Not yet instrumented element kinds:
export class ExportedClass {}
export interface ExportedInterface {}
export type ExportedType = ExportedClass;
export namespace ExportedNamespace {}