Scaffolding for LoadGlobal instruction
Adds a new `LoadGlobal` InstructionValue variant which will be used to represent identifiers that refer to globals. We don't construct this value type yet.
Joe Savona committed
Feb 16, 2023 at 15:17 UTC
326e8c13f777ca6583f11e1be39a3025eec08cf4
7 files changed
+14
compiler/forget/src/HIR/HIR.ts
+1
@@ -442,6 +442,7 @@ export type InstructionData =
442
| { kind: "ComputedStore"; object: Place; property: Place; value: Place }
443
// load `object[index]` - like PropertyLoad but with a dynamic property
444
| { kind: "ComputedLoad"; object: Place; property: Place }
445
+ | { kind: "LoadGlobal"; name: string }
446
| FunctionExpression
447
| {
448
kind: "TaggedTemplateExpression";
compiler/forget/src/HIR/PrintHIR.ts
+4
@@ -381,6 +381,10 @@ export function printInstructionValue(instrValue: ReactiveValue): string {
381
value += instrValue.quasis.at(-1)!.raw + "`";
382
break;
383
}
384
+ case "LoadGlobal": {
385
+ value = `Global ${instrValue.name}`;
386
+ break;
387
+ }
388
default: {
389
assertExhaustive(
390
instrValue,
compiler/forget/src/HIR/visitors.ts
+2
@@ -131,6 +131,7 @@ export function* eachInstructionValueOperand(
131
yield* instrValue.subexprs;
132
break;
133
}
134
+ case "LoadGlobal":
135
case "UnsupportedNode":
136
case "Primitive":
137
case "JSXText": {
@@ -259,6 +260,7 @@ export function mapInstructionOperands(
260
instrValue.subexprs = instrValue.subexprs.map(fn);
261
break;
262
}
263
+ case "LoadGlobal":
264
case "UnsupportedNode":
265
case "Primitive":
266
case "JSXText": {
compiler/forget/src/Inference/InferReferenceEffects.ts
+1
@@ -640,6 +640,7 @@ function inferBlock(
640
effectKind = Effect.Read;
641
break;
642
}
643
+ case "LoadGlobal":
644
case "JSXText":
645
case "Primitive": {
646
valueKind = ValueKind.Immutable;
compiler/forget/src/Optimization/DeadCodeElimination.ts
+1
@@ -94,6 +94,7 @@ function pruneableValue(value: InstructionValue): boolean {
94
// Potentially safe to prune, since they should just be creating new values
95
return false;
96
}
97
+ case "LoadGlobal":
98
case "ArrayExpression":
99
case "BinaryExpression":
100
case "ComputedLoad":
compiler/forget/src/ReactiveScopes/CodegenReactiveFunction.ts
+4
@@ -788,6 +788,10 @@ function codegenInstructionValue(
788
);
789
break;
790
}
791
+ case "LoadGlobal": {
792
+ value = t.identifier(instrValue.name);
793
+ break;
794
+ }
795
default: {
796
assertExhaustive(
797
instrValue,
compiler/forget/src/ReactiveScopes/InferReactiveScopeVariables.ts
+1
@@ -168,6 +168,7 @@ function isMutable({ id }: Instruction, place: Place): boolean {
168
169
function mayAllocate(value: InstructionValue): boolean {
170
switch (value.kind) {
171
+ case "LoadGlobal":
172
case "TypeCastExpression":
173
case "BinaryExpression":
174
case "Identifier":