-
-
Notifications
You must be signed in to change notification settings - Fork 670
/
Copy pathindex.ts
95 lines (75 loc) · 2.3 KB
/
index.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
export { memory };
export const COLOR: string = "red";
export function strlen(str: string): i32 {
return str.length;
}
export namespace math {
export function add(a: i32, b: i32): i32 {
return a + b;
}
}
export class Car {
static readonly MAX_DOORS: i32 = 5;
static readonly usualDoors: i32 = 3;
numDoors: i32;
private doorsOpen: bool = false;
get isDoorsOpen(): bool { return this.doorsOpen; }
set isDoorsOpen(value: bool) { this.doorsOpen = value; }
constructor(numDoors: i32) {
this.numDoors = numDoors;
}
openDoors(): bool {
if (this.doorsOpen) return false;
this.doorsOpen = true;
return true;
}
closeDoors(): bool {
if (!this.doorsOpen) return false;
this.doorsOpen = false;
return true;
}
}
export function sum(arr: Int32Array): i32 {
let v = 0;
for (let i = 0, k = arr.length; i < k; ++i) v += arr[i];
return v;
}
export function sumStatic(arr: StaticArray<i32>): i32 {
let v = 0;
for (let i = 0, k = arr.length; i < k; ++i) v += arr[i];
return v;
}
export function changeLength(arr: Array<i32>, length: i32): void {
arr.length = length;
}
export function varadd(a: i32 = 1, b: i32 = 2): i32 {
return a + b;
}
export const varadd_ref = varadd;
export function calladd(fn: (a: i32, b: i32) => i32, a: i32, b: i32): i32 {
return fn(a, b);
}
export function dotrace(num: f64): void {
trace("The answer is", 1, num);
}
export function getVaraddFunc(): (a: i32, b: i32) => i32 {
return varadd;
}
export const UINT8ARRAY_ID = idof<Uint8Array>();
export const INT16ARRAY_ID = idof<Int16Array>();
export const UINT16ARRAY_ID = idof<Uint16Array>();
export const INT32ARRAY_ID = idof<Int32Array>();
export const UINT32ARRAY_ID = idof<Uint32Array>();
export const FLOAT32ARRAY_ID = idof<Float32Array>();
export const ARRAYI32_ID = idof<Array<i32>>();
export const STATICARRAYI32_ID = idof<StaticArray<i32>>();
export const STATICARRAYU32_ID = idof<StaticArray<u32>>();
export const STATICARRAYU8_ID = idof<StaticArray<u8>>();
export const STATICARRAYI16_ID = idof<StaticArray<i16>>();
export const STATICARRAYF32_ID = idof<StaticArray<f32>>();
export function newFloat32Array(size: i32): Float32Array {
return new Float32Array(size);
}
export function modifyFloat32Array(array: Float32Array, index: i32, value: f32): void {
array[index] = value;
}