1 | import type { PresentArray } from './array.js';
|
2 | import type { EncoderError } from './compile/encoder.js';
|
3 | import type { Operand, SerializedInlineBlock, SerializedTemplateBlock } from './compile/index.js';
|
4 | import type { Nullable } from './core.js';
|
5 | import type { InternalComponentCapabilities } from './managers/internal/component.js';
|
6 | import type { CompileTimeCompilationContext, ConstantPool, SerializedHeap } from './program.js';
|
7 | import type { Owner } from './runtime.js';
|
8 | import type { BlockSymbolTable, ProgramSymbolTable, SymbolTable } from './tier1/symbol-table.js';
|
9 |
|
10 | export interface CompilableProgram extends CompilableTemplate<ProgramSymbolTable> {
|
11 | moduleName: string;
|
12 | }
|
13 |
|
14 | export type CompilableBlock = CompilableTemplate<BlockSymbolTable>;
|
15 |
|
16 | export interface LayoutWithContext {
|
17 | readonly id: string;
|
18 | readonly block: SerializedTemplateBlock;
|
19 | readonly moduleName: string;
|
20 | readonly owner: Owner | null;
|
21 | readonly scope: (() => unknown[]) | undefined | null;
|
22 | readonly isStrictMode: boolean;
|
23 | }
|
24 |
|
25 | export interface BlockWithContext {
|
26 | readonly block: SerializedInlineBlock;
|
27 | readonly containingLayout: LayoutWithContext;
|
28 | }
|
29 |
|
30 | /**
|
31 | * Environment specific template.
|
32 | */
|
33 | export interface TemplateOk {
|
34 | result: 'ok';
|
35 |
|
36 | /**
|
37 | * Module name associated with the template, used for debugging purposes
|
38 | */
|
39 | moduleName: string;
|
40 |
|
41 | // internal casts, these are lazily created and cached
|
42 | asLayout(): CompilableProgram;
|
43 | asWrappedLayout(): CompilableProgram;
|
44 | }
|
45 |
|
46 | export interface TemplateError {
|
47 | result: 'error';
|
48 |
|
49 | problem: string;
|
50 | span: {
|
51 | start: number;
|
52 | end: number;
|
53 | };
|
54 | }
|
55 |
|
56 | export type Template = TemplateOk | TemplateError;
|
57 |
|
58 | export type TemplateFactory = (owner?: Owner) => Template;
|
59 |
|
60 | export interface STDLib {
|
61 | main: number;
|
62 | 'cautious-append': number;
|
63 | 'trusting-append': number;
|
64 | 'cautious-non-dynamic-append': number;
|
65 | 'trusting-non-dynamic-append': number;
|
66 | }
|
67 |
|
68 | export type SerializedStdlib = [number, number, number];
|
69 |
|
70 | export type STDLibName = keyof STDLib;
|
71 |
|
72 | export type CompilerBuffer = Array<Operand>;
|
73 |
|
74 | export interface ResolvedLayout {
|
75 | handle: number;
|
76 | capabilities: InternalComponentCapabilities;
|
77 | compilable: Nullable<CompilableProgram>;
|
78 | }
|
79 |
|
80 | export type OkHandle = number;
|
81 | export interface ErrHandle {
|
82 | handle: number;
|
83 | errors: PresentArray<EncoderError>;
|
84 | }
|
85 |
|
86 | export type HandleResult = OkHandle | ErrHandle;
|
87 |
|
88 | export interface NamedBlocks {
|
89 | get(name: string): Nullable<SerializedInlineBlock>;
|
90 | has(name: string): boolean;
|
91 | with(name: string, block: Nullable<SerializedInlineBlock>): NamedBlocks;
|
92 | hasAny: boolean;
|
93 | names: string[];
|
94 | }
|
95 |
|
96 | export interface ContainingMetadata {
|
97 | evalSymbols: Nullable<string[]>;
|
98 | upvars: Nullable<string[]>;
|
99 | scopeValues: unknown[] | null;
|
100 | isStrictMode: boolean;
|
101 | moduleName: string;
|
102 | owner: Owner | null;
|
103 | size: number;
|
104 | }
|
105 |
|
106 | export interface CompilerArtifacts {
|
107 | heap: SerializedHeap;
|
108 | constants: ConstantPool;
|
109 | }
|
110 |
|
111 | export interface CompilableTemplate<S extends SymbolTable = SymbolTable> {
|
112 | symbolTable: S;
|
113 | compile(context: CompileTimeCompilationContext): HandleResult;
|
114 | }
|