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