forked from AssemblyScript/assemblyscript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.d.ts
280 lines (244 loc) · 9.32 KB
/
index.d.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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
/**
* @fileoverview Definitions for asc.
* @license Apache-2.0
*/
import { OptionDescription } from "../util/options";
export { OptionDescription };
/** AssemblyScript version. */
export const version: string;
/** Available CLI options. */
export const options: { [key: string]: OptionDescription };
/** Prefix used for library files. */
export const libraryPrefix: string;
/** Bundled library files. */
export const libraryFiles: { [key: string]: string };
/** Bundled definition files. */
export const definitionFiles: { assembly: string, portable: string };
/** Default Binaryen optimization level. */
export const defaultOptimizeLevel: number;
/** Default Binaryen shrink level. */
export const defaultShrinkLevel: number;
/** A compatible output stream. */
export interface OutputStream {
/** Writes a chunk of data to the stream. */
write(chunk: Uint8Array | string): void;
}
/** An in-memory output stream. */
export interface MemoryStream extends OutputStream {
/** Resets the stream to offset zero. */
reset(): void;
/** Converts the output to a buffer. */
toBuffer(): Uint8Array;
/** Converts the output to a string. */
toString(): string;
}
/** Relevant subset of the Source class for diagnostic reporting. */
export interface Source {
/** Normalized path with file extension. */
normalizedPath: string;
}
/** Relevant subset of the Range class for diagnostic reporting. */
export interface Range {
/** Start offset within the source file. */
start: number;
/** End offset within the source file. */
end: number;
/** Respective source file. */
source: Source;
}
/** Relevant subset of the DiagnosticMessage class for diagnostic reporting. */
export interface DiagnosticMessage {
/** Message code. */
code: number;
/** Message category. */
category: number;
/** Message text. */
message: string;
/** Respective source range, if any. */
range: Range | null;
/** Related range, if any. */
relatedRange: Range | null;
}
/** A function handling diagnostic messages. */
type DiagnosticReporter = (diagnostic: DiagnosticMessage) => void;
/** Compiler options. */
export interface CompilerOptions {
/** Prints just the compiler's version and exits. */
version?: boolean;
/** Prints the help message and exits. */
help?: boolean;
/** Optimizes the module. */
optimize?: boolean;
/** How much to focus on optimizing code. */
optimizeLevel?: number;
/** How much to focus on shrinking code size. */
shrinkLevel?: number;
/** Re-optimizes until no further improvements can be made. */
converge?: boolean;
/** Specifies the base directory of input and output files. */
baseDir?: string;
/** Specifies the WebAssembly output file (.wasm). */
outFile?: string;
/** Specifies the WebAssembly text output file (.wat). */
textFile?: string;
/** Specified the bindings to generate. */
bindings?: string[];
/** Enables source map generation. Optionally takes the URL. */
sourceMap?: boolean | string;
/** Specifies the runtime variant to include in the program. */
runtime?: string;
/** Disallows the use of unsafe features in user code. */
noUnsafe?: boolean;
/** Enables debug information in emitted binaries. */
debug?: boolean;
/** Replaces assertions with just their value without trapping. */
noAssert?: boolean;
/** Performs compilation as usual but does not emit code. */
noEmit?: boolean;
/** Imports the memory provided as 'env.memory'. */
importMemory?: boolean;
/** Does not export the memory as 'memory'. */
noExportMemory?: boolean;
/** Sets the initial memory size in pages. */
initialMemory?: number;
/** Sets the maximum memory size in pages. */
maximumMemory?: number;
/** Declare memory as shared. Requires maximumMemory. */
sharedMemory?: boolean;
/** Assume that imported memory is zero filled. Requires importMemory. */
zeroFilledMemory?: boolean;
/** Sets the start offset of compiler-generated static memory. */
memoryBase?: number;
/** Imports the function table provided as 'env.table'. */
importTable?: boolean;
/** Exports the function table as 'table'. */
exportTable?: boolean;
/** Exports the start function instead of calling it implicitly. */
exportStart?: string;
/** "Adds one or multiple paths to custom library components. */
lib?: string | string[];
/** Adds one or multiple paths to package resolution. */
path?: string | string[];
/** Aliases a global object under another name. */
use?: string | string[];
/** Sets the trap mode to use. */
trapMode?: "allow" | "clamp" | "js";
/** Specifies additional Binaryen passes to run. */
runPasses?: string | string[];
/** Skips validating the module using Binaryen. */
noValidate?: boolean;
/** Enables WebAssembly features that are disabled by default. */
enable?: string | string[];
/** Disables WebAssembly features that are enabled by default. */
disable?: string | string[];
/** Specifies the path to a custom transform to 'require'. */
transform?: string | string[];
/** Make yourself sad for no good reason. */
pedantic?: boolean;
/** Prints measuring information on I/O and compile times. */
stats?: boolean;
/** Disables terminal colors. */
noColors?: boolean;
}
/** Compiler API options. */
export interface APIOptions {
/** Standard output stream to use. */
stdout?: OutputStream;
/** Standard error stream to use. */
stderr?: OutputStream;
/** Reads a file from disk (or memory). */
readFile?: (filename: string, baseDir: string) => (string | null) | Promise<string | null>;
/** Writes a file to disk (or memory). */
writeFile?: (filename: string, contents: Uint8Array | string, baseDir: string) => void | Promise<void>;
/** Lists all files within a directory. */
listFiles?: (dirname: string, baseDir: string) => (string[] | null) | Promise<string[] | null>;
/** Handler for diagnostic messages. */
reportDiagnostic?: DiagnosticReporter;
/** Additional transforms to apply. */
transforms?: Transform[];
}
/** Compiler API result. */
export interface APIResult {
/** Encountered error, if any. */
error: Error | null;
/** Standard output stream. */
stdout: OutputStream;
/** Standard error stream. */
stderr: OutputStream;
/** Statistics. */
stats: Stats;
}
/** Runs the command line utility using the specified arguments array. */
export function main(argv: string[] | CompilerOptions, options?: APIOptions): Promise<APIResult>;
/** Convenience function that parses and compiles source strings directly. */
export function compileString(sources: { [key: string]: string } | string, options?: CompilerOptions): Promise<APIResult & {
/** Emitted binary. */
binary: Uint8Array | null,
/** Emitted text format. */
text: string | null
}>;
/** Checks diagnostics emitted so far for errors. */
export function checkDiagnostics(emitter: Record<string,unknown>, stderr?: OutputStream, reportDiagnostic?: DiagnosticReporter, useColors?: boolean): boolean;
/** Statistics for the current task. */
export class Stats {
/** Number of files read. */
readCount: number;
/** Number of files written. */
writeCount: number;
/** Time taken to parse files. */
parseTime: number;
/** Number of files parsed. */
parseCount: number;
/** Time taken to compile programs. */
compileTime: number;
/** Number of programs compiled. */
compileCount: number;
/** Time taken to emit files. */
emitTime: number;
/** Number of emitted files. */
emitCount: number;
/** Time taken to validate modules. */
validateTime: number;
/** Number of modules validated. */
validateCount: number;
/** Time taken to optimize modules. */
optimizeTime: number;
/** Number of modules optimized. */
optimizeCount: number;
/** Begins measuring execution time. */
begin(): number;
/** Ends measuring execution time since `begin`. */
end(begin: number): number;
/** Returns a string representation. */
toString(): string;
}
/** Creates a memory stream that can be used in place of stdout/stderr. */
export function createMemoryStream(fn?: (chunk: Uint8Array | string) => void): MemoryStream;
/** Compatible TypeScript compiler options for syntax highlighting etc. */
export const tscOptions: Record<string,unknown>;
import { Program, Parser, Module } from "../src";
/** Compiler transform base class. */
export abstract class Transform {
/** Program reference. */
readonly program: Program;
/** Base directory. */
readonly baseDir: string;
/** Output stream used by the compiler. */
readonly stdout: OutputStream;
/** Error stream used by the compiler. */
readonly stderr: OutputStream;
/** Logs a message to console. */
readonly log: typeof console.log;
/** Reads a file from disk. */
readFile(filename: string, baseDir: string): (string | null) | Promise<string | null>;
/** Writes a file to disk. */
writeFile(filename: string, contents: string | Uint8Array, baseDir: string): void | Promise<void>;
/** Lists all files in a directory. */
listFiles(dirname: string, baseDir: string): (string[] | null) | Promise<string[] | null>;
/** Called when parsing is complete, before a program is instantiated from the AST. */
afterParse?(parser: Parser): void | Promise<void>;
/** Called after the program is instantiated. */
afterInitialize?(program: Program): void | Promise<void>;
/** Called when compilation is complete, before the module is being validated. */
afterCompile?(module: Module): void | Promise<void>;
}