-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathinlining.ts
74 lines (61 loc) · 1.22 KB
/
inlining.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
// Constant inlining
const constantGlobal = 1;
export function test(): i32 {
const constantLocal = 2;
return constantGlobal + constantLocal;
}
assert(test() == 3);
// Function inlining
@inline
function func_ii(a: i32): i32 {
if (a == 42) return 1;
return a < 42 ? 2 : 3;
}
@inline
function func_ii_opt(a: i32 = 0): i32 {
return a;
}
@inline
function func_ii_loc(a: i32): i32 {
var b = a;
var e: i32;
if (true) {
let c = b;
let d = c;
e = d + 1;
}
return e;
}
@inline
function func_iv(a: i32): void {
}
@inline
function func_fe(): (a: i32) => i32 {
return (a: i32): i32 => a;
}
class Foo {
@inline
static method_static(a: i32, b: i32 = 2): i32 {
return a + b;
}
@inline
method_this(a: i32, b: i32 = 3): Foo {
return this;
}
}
function test_funcs(): void {
var a: f32 = -1, b: f64 = -2;
assert(func_ii(42) == 1);
assert(func_ii(41) == 2);
assert(func_ii(43) == 3);
assert(func_ii_opt() == 0);
assert(func_ii_opt(1) == 1);
assert(func_ii_loc(2) == 3);
assert(func_ii_loc(3) == 4);
func_iv(0);
assert(func_fe()(2) == 2);
assert(Foo.method_static(42) == 44);
var foo = changetype<Foo>(123);
assert(changetype<usize>(foo.method_this(43)) == 123);
}
test_funcs();