104
return compileResult;
105
}
106
107
-function codegenReactiveFunction(
108
- fn: ReactiveFunction
107
+export function codegenReactiveFunction(
108
+ fn: ReactiveFunction,
109
+ parentContext: Context | null = null
110
): Result<CodegenFunction, CompilerError> {
110
- const cx = new Context(fn.env, fn.id ?? "[[ anonymous ]]");
111
+ const cx = new Context(
112
+ fn.env,
113
+ fn.id ?? "[[ anonymous ]]",
114
+ parentContext?.temp ?? null
115
+ );
116
for (const param of fn.params) {
117
if (param.kind === "Identifier") {
118
cx.temp.set(param.identifier.id, null);
189
fnName: string;
190
#nextCacheIndex: number = 0;
191
#declarations: Set<IdentifierId> = new Set();
187
- temp: Temporaries = new Map();
192
+ temp: Temporaries;
193
errors: CompilerError = new CompilerError();
194
objectMethods: Map<IdentifierId, ObjectMethod> = new Map();
195
191
- constructor(env: Environment, fnName: string) {
196
+ constructor(
197
+ env: Environment,
198
+ fnName: string,
199
+ temporaries: Temporaries | null = null
200
+ ) {
201
this.env = env;
202
this.fnName = fnName;
203
+ this.temp = temporaries !== null ? new Map(temporaries) : new Map();
204
}
205
get nextCacheIndex(): number {
206
return this.#nextCacheIndex++;
1525
pruneUnusedLabels(reactiveFunction);
1526
pruneUnusedLValues(reactiveFunction);
1527
renameVariables(reactiveFunction);
1518
- const fn = codegenReactiveFunction(reactiveFunction).unwrap();
1528
+ const fn = codegenReactiveFunction(reactiveFunction, cx).unwrap();
1529
if (instrValue.expr.type === "ArrowFunctionExpression") {
1530
let body: t.BlockStatement | t.Expression = fn.body;
1531
if (body.body.length === 1) {