1 | import type { Encoder } from './compile/index.js';
|
2 | import type { ComponentDefinition, ComponentDefinitionState } from './components.js';
|
3 | import type { HelperDefinitionState } from './runtime.js';
|
4 | import type { ModifierDefinitionState } from './runtime/modifier.js';
|
5 | import type { CompileTimeResolver, ResolvedComponentDefinition } from './serialize.js';
|
6 | import type { ContainingMetadata, STDLib, Template } from './template.js';
|
7 | import type { SomeVmOp, VmMachineOp, VmOp } from './vm-opcodes.js';
|
8 |
|
9 | export type CreateRuntimeOp = (heap: CompileTimeHeap) => RuntimeOp;
|
10 |
|
11 | export interface RuntimeOp {
|
12 | offset: number;
|
13 | type: SomeVmOp;
|
14 | op1: number;
|
15 | op2: number;
|
16 | op3: number;
|
17 | size: number;
|
18 | isMachine: 0 | 1;
|
19 | }
|
20 |
|
21 | export interface SerializedHeap {
|
22 | buffer: ArrayBuffer;
|
23 | table: number[];
|
24 | handle: number;
|
25 | }
|
26 |
|
27 | export interface OpcodeHeap {
|
28 | getbyaddr(address: number): number;
|
29 | }
|
30 |
|
31 | export interface CompileTimeHeap extends OpcodeHeap {
|
32 | pushRaw(value: number): void;
|
33 | pushOp(name: VmOp, op1?: number, op2?: number, op3?: number): void;
|
34 | pushMachine(name: VmMachineOp, op1?: number, op2?: number, op3?: number): void;
|
35 | malloc(): number;
|
36 | finishMalloc(handle: number, scopeSize: number): void;
|
37 | capture(offset?: number): SerializedHeap;
|
38 | offset: number;
|
39 |
|
40 |
|
41 | getaddr(handle: number): number;
|
42 | sizeof(handle: number): number;
|
43 | getbyaddr(address: number): number;
|
44 | setbyaddr(address: number, value: number): void;
|
45 | }
|
46 |
|
47 | export interface RuntimeHeap extends OpcodeHeap {
|
48 | getaddr(handle: number): number;
|
49 | sizeof(handle: number): number;
|
50 | }
|
51 |
|
52 | export interface CompileTimeCompilationContext {
|
53 |
|
54 | readonly stdlib: STDLib;
|
55 |
|
56 | readonly createOp: CreateRuntimeOp;
|
57 |
|
58 |
|
59 | readonly constants: CompileTimeConstants & ResolutionTimeConstants;
|
60 |
|
61 |
|
62 | readonly resolver: CompileTimeResolver;
|
63 |
|
64 |
|
65 | readonly heap: CompileTimeHeap;
|
66 | }
|
67 |
|
68 |
|
69 |
|
70 |
|
71 |
|
72 |
|
73 | export interface TemplateCompilationContext {
|
74 | readonly program: CompileTimeCompilationContext;
|
75 | readonly encoder: Encoder;
|
76 | readonly meta: ContainingMetadata;
|
77 | }
|
78 |
|
79 | export type EMPTY_ARRAY = Array<ReadonlyArray<never>>;
|
80 |
|
81 | export type ConstantPool = unknown[];
|
82 |
|
83 |
|
84 |
|
85 |
|
86 |
|
87 |
|
88 | export interface CompileTimeConstants {
|
89 | value(value: unknown): number;
|
90 | array(values: unknown[] | readonly unknown[]): number;
|
91 | toPool(): ConstantPool;
|
92 | }
|
93 |
|
94 |
|
95 |
|
96 |
|
97 |
|
98 | export interface ResolutionTimeConstants {
|
99 |
|
100 |
|
101 |
|
102 | defaultTemplate: Template;
|
103 |
|
104 | helper(
|
105 | definitionState: HelperDefinitionState,
|
106 | resolvedName: string | null,
|
107 | isOptional: true
|
108 | ): number | null;
|
109 | helper(definitionState: HelperDefinitionState, resolvedName?: string | null): number;
|
110 |
|
111 | modifier(
|
112 | definitionState: ModifierDefinitionState,
|
113 | resolvedName: string | null,
|
114 | isOptional: true
|
115 | ): number | null;
|
116 | modifier(definitionState: ModifierDefinitionState, resolvedName?: string | null): number;
|
117 |
|
118 | component(
|
119 | definitionState: ComponentDefinitionState,
|
120 | owner: object,
|
121 | isOptional?: false
|
122 | ): ComponentDefinition;
|
123 | component(
|
124 | definitionState: ComponentDefinitionState,
|
125 | owner: object,
|
126 | isOptional?: boolean
|
127 | ): ComponentDefinition | null;
|
128 |
|
129 | resolvedComponent(
|
130 | definitionState: ResolvedComponentDefinition,
|
131 | resolvedName: string
|
132 | ): ComponentDefinition;
|
133 | }
|
134 |
|
135 | export interface RuntimeConstants {
|
136 | getValue<T>(handle: number): T;
|
137 | getArray<T>(handle: number): T[];
|
138 | }
|
139 |
|
140 | export interface CompileTimeArtifacts {
|
141 | heap: CompileTimeHeap;
|
142 | constants: CompileTimeConstants & ResolutionTimeConstants;
|
143 | }
|