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.
This commit is contained in:
Joe Savona
2023-02-16 15:17:30 -08:00
parent 0c72eed413
commit 326e8c13f7
7 changed files with 14 additions and 0 deletions
+1
View File
@@ -442,6 +442,7 @@ export type InstructionData =
| { kind: "ComputedStore"; object: Place; property: Place; value: Place }
// load `object[index]` - like PropertyLoad but with a dynamic property
| { kind: "ComputedLoad"; object: Place; property: Place }
| { kind: "LoadGlobal"; name: string }
| FunctionExpression
| {
kind: "TaggedTemplateExpression";
+4
View File
@@ -381,6 +381,10 @@ export function printInstructionValue(instrValue: ReactiveValue): string {
value += instrValue.quasis.at(-1)!.raw + "`";
break;
}
case "LoadGlobal": {
value = `Global ${instrValue.name}`;
break;
}
default: {
assertExhaustive(
instrValue,
+2
View File
@@ -131,6 +131,7 @@ export function* eachInstructionValueOperand(
yield* instrValue.subexprs;
break;
}
case "LoadGlobal":
case "UnsupportedNode":
case "Primitive":
case "JSXText": {
@@ -259,6 +260,7 @@ export function mapInstructionOperands(
instrValue.subexprs = instrValue.subexprs.map(fn);
break;
}
case "LoadGlobal":
case "UnsupportedNode":
case "Primitive":
case "JSXText": {
@@ -640,6 +640,7 @@ function inferBlock(
effectKind = Effect.Read;
break;
}
case "LoadGlobal":
case "JSXText":
case "Primitive": {
valueKind = ValueKind.Immutable;
@@ -94,6 +94,7 @@ function pruneableValue(value: InstructionValue): boolean {
// Potentially safe to prune, since they should just be creating new values
return false;
}
case "LoadGlobal":
case "ArrayExpression":
case "BinaryExpression":
case "ComputedLoad":
@@ -788,6 +788,10 @@ function codegenInstructionValue(
);
break;
}
case "LoadGlobal": {
value = t.identifier(instrValue.name);
break;
}
default: {
assertExhaustive(
instrValue,
@@ -168,6 +168,7 @@ function isMutable({ id }: Instruction, place: Place): boolean {
function mayAllocate(value: InstructionValue): boolean {
switch (value.kind) {
case "LoadGlobal":
case "TypeCastExpression":
case "BinaryExpression":
case "Identifier":