1 | import { Operand, SerializedTemplateBlock, SerializedInlineBlock, BlockOperand } from './compile';
|
2 | import { EncoderError } from './compile/encoder';
|
3 | import { Option } from './core';
|
4 | import { InternalComponentCapabilities } from './managers/internal/component';
|
5 | import { ConstantPool, SerializedHeap, CompileTimeCompilationContext } from './program';
|
6 | import { Owner } from './runtime';
|
7 | import { BlockSymbolTable, ProgramSymbolTable, SymbolTable } from './tier1/symbol-table';
|
8 |
|
9 | export interface CompilableProgram extends CompilableTemplate<ProgramSymbolTable> {
|
10 | moduleName: string;
|
11 | }
|
12 |
|
13 | export type CompilableBlock = CompilableTemplate<BlockSymbolTable>;
|
14 |
|
15 | export interface LayoutWithContext {
|
16 | readonly id: string;
|
17 | readonly block: SerializedTemplateBlock;
|
18 | readonly moduleName: string;
|
19 | readonly owner: Owner | null;
|
20 | readonly scope: (() => unknown[]) | undefined | null;
|
21 | readonly isStrictMode: boolean;
|
22 | readonly asPartial: 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 | asPartial(): CompilableProgram;
|
44 | asWrappedLayout(): CompilableProgram;
|
45 | }
|
46 |
|
47 | export interface TemplateError {
|
48 | result: 'error';
|
49 |
|
50 | problem: string;
|
51 | span: {
|
52 | start: number;
|
53 | end: number;
|
54 | };
|
55 | }
|
56 |
|
57 | export type Template = TemplateOk | TemplateError;
|
58 |
|
59 | export type TemplateFactory = (owner?: Owner) => Template;
|
60 |
|
61 | export interface STDLib {
|
62 | main: number;
|
63 | 'cautious-append': number;
|
64 | 'trusting-append': number;
|
65 | 'cautious-non-dynamic-append': number;
|
66 | 'trusting-non-dynamic-append': number;
|
67 | }
|
68 |
|
69 | export type SerializedStdlib = [number, number, number];
|
70 |
|
71 | export type STDLibName = keyof STDLib;
|
72 |
|
73 | export type CompilerBuffer = Array<Operand>;
|
74 |
|
75 | export interface ResolvedLayout {
|
76 | handle: number;
|
77 | capabilities: InternalComponentCapabilities;
|
78 | compilable: Option<CompilableProgram>;
|
79 | }
|
80 |
|
81 | export type OkHandle = number;
|
82 | export interface ErrHandle {
|
83 | handle: number;
|
84 | errors: EncoderError[];
|
85 | }
|
86 |
|
87 | export type HandleResult = OkHandle | ErrHandle;
|
88 |
|
89 | export interface NamedBlocks {
|
90 | get(name: string): Option<SerializedInlineBlock>;
|
91 | has(name: string): boolean;
|
92 | with(name: string, block: Option<SerializedInlineBlock>): NamedBlocks;
|
93 | hasAny: boolean;
|
94 | names: string[];
|
95 | }
|
96 |
|
97 | export interface ContainingMetadata {
|
98 | asPartial: boolean;
|
99 | evalSymbols: Option<string[]>;
|
100 | upvars: Option<string[]>;
|
101 | scopeValues: unknown[] | null;
|
102 | isStrictMode: boolean;
|
103 | moduleName: string;
|
104 | owner: Owner | null;
|
105 | size: number;
|
106 | }
|
107 |
|
108 | export interface CompilerArtifacts {
|
109 | heap: SerializedHeap;
|
110 | constants: ConstantPool;
|
111 | }
|
112 |
|
113 | export interface CompilableTemplate<S extends SymbolTable = SymbolTable> {
|
114 | symbolTable: S;
|
115 | compile(context: CompileTimeCompilationContext): HandleResult;
|
116 | }
|