aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2023-12-02 19:47:35 +0000
committerMichael Williamson <mike@zwobble.org>2023-12-02 19:47:35 +0000
commit07d62885c5150fe6eadfa9372a190dd73fd754cc (patch)
tree17959fa67c7ab5d375f3966003358afc0715b210 /src/main/java
parent0ad5be30c1d301942f8cec567d0719fd9ff18f3f (diff)
Rename stack IR to Shid
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/org/shedlang/compiler/ShedCompiler.java10
-rw-r--r--src/main/java/org/shedlang/compiler/backends/Backend.java4
-rw-r--r--src/main/java/org/shedlang/compiler/backends/GenerateInstructionsBackend.java6
-rw-r--r--src/main/java/org/shedlang/compiler/backends/PatioBackend.java4
-rw-r--r--src/main/java/org/shedlang/compiler/backends/llvm/LlvmBackend.java4
-rw-r--r--src/main/java/org/shedlang/compiler/backends/wasm/WasmBackend.java4
-rw-r--r--src/main/java/org/shedlang/compiler/patio/PatioCodeGen.java204
-rw-r--r--src/main/java/org/shedlang/compiler/patio/PatioCodeGenClosures.java22
-rw-r--r--src/main/java/org/shedlang/compiler/patio/PatioCodeGenContext.java102
-rw-r--r--src/main/java/org/shedlang/compiler/patio/PatioCodeGenEffects.java10
-rw-r--r--src/main/java/org/shedlang/compiler/patio/PatioCodeGenStructs.java10
-rw-r--r--src/main/java/org/shedlang/compiler/shid/InstructionSerializer.java (renamed from src/main/java/org/shedlang/compiler/stackir/InstructionSerializer.java)82
-rw-r--r--src/main/java/org/shedlang/compiler/shid/ShidCodeGen.java (renamed from src/main/java/org/shedlang/compiler/stackir/StackCompiler.java)152
-rw-r--r--src/main/java/org/shedlang/compiler/shid/ShidNamespace.java12
-rw-r--r--src/main/java/org/shedlang/compiler/shid/instructions/ShidCall.java (renamed from src/main/java/org/shedlang/compiler/stackir/instructions/CallInstruction.java)6
-rw-r--r--src/main/java/org/shedlang/compiler/shid/instructions/ShidDefineEffect.java (renamed from src/main/java/org/shedlang/compiler/stackir/instructions/DefineEffectInstruction.java)6
-rw-r--r--src/main/java/org/shedlang/compiler/shid/instructions/ShidDefineFunction.java (renamed from src/main/java/org/shedlang/compiler/stackir/instructions/DefineFunctionInstruction.java)16
-rw-r--r--src/main/java/org/shedlang/compiler/shid/instructions/ShidDefineStruct.java (renamed from src/main/java/org/shedlang/compiler/stackir/instructions/DefineStructInstruction.java)6
-rw-r--r--src/main/java/org/shedlang/compiler/shid/instructions/ShidDiscard.java9
-rw-r--r--src/main/java/org/shedlang/compiler/shid/instructions/ShidDuplicate.java9
-rw-r--r--src/main/java/org/shedlang/compiler/shid/instructions/ShidFieldLoad.java (renamed from src/main/java/org/shedlang/compiler/stackir/instructions/FieldLoadInstruction.java)6
-rw-r--r--src/main/java/org/shedlang/compiler/shid/instructions/ShidIf.java (renamed from src/main/java/org/shedlang/compiler/stackir/instructions/IfInstruction.java)10
-rw-r--r--src/main/java/org/shedlang/compiler/shid/instructions/ShidInstruction.java9
-rw-r--r--src/main/java/org/shedlang/compiler/shid/instructions/ShidIntAdd.java (renamed from src/main/java/org/shedlang/compiler/stackir/instructions/IntAddInstruction.java)4
-rw-r--r--src/main/java/org/shedlang/compiler/shid/instructions/ShidIntEquals.java (renamed from src/main/java/org/shedlang/compiler/stackir/instructions/IntEqualsInstruction.java)4
-rw-r--r--src/main/java/org/shedlang/compiler/shid/instructions/ShidIntNotEqual.java (renamed from src/main/java/org/shedlang/compiler/stackir/instructions/IntNotEqualInstruction.java)4
-rw-r--r--src/main/java/org/shedlang/compiler/shid/instructions/ShidIntSub.java (renamed from src/main/java/org/shedlang/compiler/stackir/instructions/IntSubInstruction.java)4
-rw-r--r--src/main/java/org/shedlang/compiler/shid/instructions/ShidLocalLoad.java (renamed from src/main/java/org/shedlang/compiler/stackir/instructions/LocalLoadInstruction.java)4
-rw-r--r--src/main/java/org/shedlang/compiler/shid/instructions/ShidLocalStore.java (renamed from src/main/java/org/shedlang/compiler/stackir/instructions/LocalStoreInstruction.java)4
-rw-r--r--src/main/java/org/shedlang/compiler/shid/instructions/ShidLoop.java (renamed from src/main/java/org/shedlang/compiler/stackir/instructions/LoopInstruction.java)8
-rw-r--r--src/main/java/org/shedlang/compiler/shid/instructions/ShidLoopBreak.java (renamed from src/main/java/org/shedlang/compiler/stackir/instructions/LoopBreakInstruction.java)4
-rw-r--r--src/main/java/org/shedlang/compiler/shid/instructions/ShidLoopContinue.java (renamed from src/main/java/org/shedlang/compiler/stackir/instructions/LoopContinueInstruction.java)4
-rw-r--r--src/main/java/org/shedlang/compiler/shid/instructions/ShidNamespaceFieldStore.java (renamed from src/main/java/org/shedlang/compiler/stackir/instructions/NamespaceFieldStoreInstruction.java)6
-rw-r--r--src/main/java/org/shedlang/compiler/shid/instructions/ShidNamespaceImport.java (renamed from src/main/java/org/shedlang/compiler/stackir/instructions/NamespaceImportInstruction.java)6
-rw-r--r--src/main/java/org/shedlang/compiler/shid/instructions/ShidPushBool.java (renamed from src/main/java/org/shedlang/compiler/stackir/instructions/PushBoolInstruction.java)6
-rw-r--r--src/main/java/org/shedlang/compiler/shid/instructions/ShidPushInt.java11
-rw-r--r--src/main/java/org/shedlang/compiler/shid/instructions/ShidPushString.java9
-rw-r--r--src/main/java/org/shedlang/compiler/shid/instructions/ShidPushUnit.java9
-rw-r--r--src/main/java/org/shedlang/compiler/shid/instructions/ShidResume.java (renamed from src/main/java/org/shedlang/compiler/stackir/instructions/ResumeInstruction.java)4
-rw-r--r--src/main/java/org/shedlang/compiler/shid/instructions/ShidReturn.java (renamed from src/main/java/org/shedlang/compiler/stackir/instructions/ReturnInstruction.java)4
-rw-r--r--src/main/java/org/shedlang/compiler/shid/instructions/ShidStringAdd.java (renamed from src/main/java/org/shedlang/compiler/stackir/instructions/StringAddInstruction.java)4
-rw-r--r--src/main/java/org/shedlang/compiler/shid/instructions/ShidSwitch.java (renamed from src/main/java/org/shedlang/compiler/stackir/instructions/SwitchInstruction.java)8
-rw-r--r--src/main/java/org/shedlang/compiler/shid/instructions/ShidTry.java (renamed from src/main/java/org/shedlang/compiler/stackir/instructions/TryInstruction.java)8
-rw-r--r--src/main/java/org/shedlang/compiler/shid/instructions/ShidTupleCreate.java (renamed from src/main/java/org/shedlang/compiler/stackir/instructions/TupleCreateInstruction.java)6
-rw-r--r--src/main/java/org/shedlang/compiler/shid/instructions/ShidTupleGet.java (renamed from src/main/java/org/shedlang/compiler/stackir/instructions/TupleGetInstruction.java)6
-rw-r--r--src/main/java/org/shedlang/compiler/shid/instructions/ShidVarLoad.java (renamed from src/main/java/org/shedlang/compiler/stackir/instructions/VarLoadInstruction.java)4
-rw-r--r--src/main/java/org/shedlang/compiler/shid/instructions/ShidVarStore.java (renamed from src/main/java/org/shedlang/compiler/stackir/instructions/VarStoreInstruction.java)4
-rw-r--r--src/main/java/org/shedlang/compiler/stackir/StackIrNamespace.java12
-rw-r--r--src/main/java/org/shedlang/compiler/stackir/instructions/DiscardInstruction.java9
-rw-r--r--src/main/java/org/shedlang/compiler/stackir/instructions/DuplicateInstruction.java9
-rw-r--r--src/main/java/org/shedlang/compiler/stackir/instructions/Instruction.java9
-rw-r--r--src/main/java/org/shedlang/compiler/stackir/instructions/PushIntInstruction.java11
-rw-r--r--src/main/java/org/shedlang/compiler/stackir/instructions/PushStringInstruction.java9
-rw-r--r--src/main/java/org/shedlang/compiler/stackir/instructions/PushUnitInstruction.java9
54 files changed, 453 insertions, 453 deletions
diff --git a/src/main/java/org/shedlang/compiler/ShedCompiler.java b/src/main/java/org/shedlang/compiler/ShedCompiler.java
index 325383ae..f07ead28 100644
--- a/src/main/java/org/shedlang/compiler/ShedCompiler.java
+++ b/src/main/java/org/shedlang/compiler/ShedCompiler.java
@@ -6,8 +6,8 @@ import org.shedlang.compiler.config.ConfigChecker;
import org.shedlang.compiler.config.ProjectConfig;
import org.shedlang.compiler.parser.Parser;
import org.shedlang.compiler.sources.Sources;
-import org.shedlang.compiler.stackir.StackCompiler;
-import org.shedlang.compiler.stackir.StackIrNamespace;
+import org.shedlang.compiler.shid.ShidCodeGen;
+import org.shedlang.compiler.shid.ShidNamespace;
import org.shedlang.compiler.typechecker.TypeChecker;
import org.shedlang.compiler.typechecker.TypeCheckerContext;
import org.shedlang.compiler.types.*;
@@ -36,7 +36,7 @@ public class ShedCompiler {
var untypedNamespaceNodes = parseSource(sourceRoot, sourceFilePaths);
- var namespaces = new ArrayList<StackIrNamespace>();
+ var namespaces = new ArrayList<ShidNamespace>();
var typeCheckerContext = TypeCheckerContext.EMPTY
.addNamespaceTypeInfo(
@@ -59,8 +59,8 @@ public class ShedCompiler {
var typeCheckNamespaceResult = TypeChecker.typeCheckNamespace(untypedNamespaceNode, typeCheckerContext);
typeCheckerContext = typeCheckNamespaceResult.context();
- var stackIrNamespace = StackCompiler.compileNamespace(typeCheckNamespaceResult.value());
- namespaces.add(stackIrNamespace);
+ var shidNamespace = ShidCodeGen.compileNamespace(typeCheckNamespaceResult.value());
+ namespaces.add(shidNamespace);
}
var typeInfos = typeCheckerContext.toTypeInfos();
diff --git a/src/main/java/org/shedlang/compiler/backends/Backend.java b/src/main/java/org/shedlang/compiler/backends/Backend.java
index 42938d34..40a00fbf 100644
--- a/src/main/java/org/shedlang/compiler/backends/Backend.java
+++ b/src/main/java/org/shedlang/compiler/backends/Backend.java
@@ -1,7 +1,7 @@
package org.shedlang.compiler.backends;
import org.shedlang.compiler.config.ProjectConfig;
-import org.shedlang.compiler.stackir.StackIrNamespace;
+import org.shedlang.compiler.shid.ShidNamespace;
import org.shedlang.compiler.typechecker.TypeInfos;
import java.io.IOException;
@@ -13,7 +13,7 @@ public interface Backend {
void compile(
ProjectConfig config,
- List<StackIrNamespace> namespaces,
+ List<ShidNamespace> namespaces,
TypeInfos typeInfos,
Path targetDir
) throws IOException, InterruptedException;
diff --git a/src/main/java/org/shedlang/compiler/backends/GenerateInstructionsBackend.java b/src/main/java/org/shedlang/compiler/backends/GenerateInstructionsBackend.java
index dd33ae89..c2a6ea23 100644
--- a/src/main/java/org/shedlang/compiler/backends/GenerateInstructionsBackend.java
+++ b/src/main/java/org/shedlang/compiler/backends/GenerateInstructionsBackend.java
@@ -1,8 +1,8 @@
package org.shedlang.compiler.backends;
import org.shedlang.compiler.config.ProjectConfig;
-import org.shedlang.compiler.stackir.InstructionSerializer;
-import org.shedlang.compiler.stackir.StackIrNamespace;
+import org.shedlang.compiler.shid.InstructionSerializer;
+import org.shedlang.compiler.shid.ShidNamespace;
import org.shedlang.compiler.typechecker.TypeInfos;
import java.nio.file.Path;
@@ -11,7 +11,7 @@ import java.util.List;
public class GenerateInstructionsBackend implements Backend {
public void compile(
ProjectConfig config,
- List<StackIrNamespace> namespaces,
+ List<ShidNamespace> namespaces,
TypeInfos typeInfos,
Path targetDir
) {
diff --git a/src/main/java/org/shedlang/compiler/backends/PatioBackend.java b/src/main/java/org/shedlang/compiler/backends/PatioBackend.java
index 9e444cee..f9ae1695 100644
--- a/src/main/java/org/shedlang/compiler/backends/PatioBackend.java
+++ b/src/main/java/org/shedlang/compiler/backends/PatioBackend.java
@@ -4,7 +4,7 @@ import org.shedlang.compiler.config.ProjectConfig;
import org.shedlang.compiler.patio.PatioCodeGen;
import org.shedlang.compiler.patio.PatioCodeGenContext;
import org.shedlang.compiler.patio.ast.PatioSerializer;
-import org.shedlang.compiler.stackir.StackIrNamespace;
+import org.shedlang.compiler.shid.ShidNamespace;
import org.shedlang.compiler.typechecker.TypeInfos;
import java.nio.file.Path;
@@ -13,7 +13,7 @@ import java.util.List;
public class PatioBackend implements Backend {
public void compile(
ProjectConfig config,
- List<StackIrNamespace> namespaces,
+ List<ShidNamespace> namespaces,
TypeInfos typeInfos,
Path targetDir
) {
diff --git a/src/main/java/org/shedlang/compiler/backends/llvm/LlvmBackend.java b/src/main/java/org/shedlang/compiler/backends/llvm/LlvmBackend.java
index c1575a31..97e1917f 100644
--- a/src/main/java/org/shedlang/compiler/backends/llvm/LlvmBackend.java
+++ b/src/main/java/org/shedlang/compiler/backends/llvm/LlvmBackend.java
@@ -15,7 +15,7 @@ import org.shedlang.compiler.filesystem.ShedCompilerFiles;
import org.shedlang.compiler.patio.PatioCodeGen;
import org.shedlang.compiler.patio.PatioCodeGenContext;
import org.shedlang.compiler.sources.Sources;
-import org.shedlang.compiler.stackir.StackIrNamespace;
+import org.shedlang.compiler.shid.ShidNamespace;
import org.shedlang.compiler.typechecker.TypeInfos;
import org.shedlang.compiler.types.NamespaceName;
import org.shedlang.compiler.util.processes.ProcessError;
@@ -42,7 +42,7 @@ public class LlvmBackend implements Backend {
@Override
public void compile(
ProjectConfig config,
- List<StackIrNamespace> namespaces,
+ List<ShidNamespace> namespaces,
TypeInfos typeInfos,
Path targetDir
) throws IOException, InterruptedException {
diff --git a/src/main/java/org/shedlang/compiler/backends/wasm/WasmBackend.java b/src/main/java/org/shedlang/compiler/backends/wasm/WasmBackend.java
index a0074d28..17b5c1ff 100644
--- a/src/main/java/org/shedlang/compiler/backends/wasm/WasmBackend.java
+++ b/src/main/java/org/shedlang/compiler/backends/wasm/WasmBackend.java
@@ -10,7 +10,7 @@ import org.shedlang.compiler.filesystem.ShedCompilerFiles;
import org.shedlang.compiler.patio.PatioCodeGen;
import org.shedlang.compiler.patio.PatioCodeGenContext;
import org.shedlang.compiler.sources.Sources;
-import org.shedlang.compiler.stackir.StackIrNamespace;
+import org.shedlang.compiler.shid.ShidNamespace;
import org.shedlang.compiler.typechecker.TypeInfos;
import org.shedlang.compiler.types.NamespaceName;
import org.shedlang.compiler.util.processes.ProcessError;
@@ -35,7 +35,7 @@ public class WasmBackend implements Backend {
@Override
public void compile(
ProjectConfig config,
- List<StackIrNamespace> namespaces,
+ List<ShidNamespace> namespaces,
TypeInfos typeInfos,
Path targetDir
) throws IOException, InterruptedException {
diff --git a/src/main/java/org/shedlang/compiler/patio/PatioCodeGen.java b/src/main/java/org/shedlang/compiler/patio/PatioCodeGen.java
index e2f1b6ba..b5b3aa0b 100644
--- a/src/main/java/org/shedlang/compiler/patio/PatioCodeGen.java
+++ b/src/main/java/org/shedlang/compiler/patio/PatioCodeGen.java
@@ -13,8 +13,8 @@ import org.shedlang.compiler.patio.ast.types.PatioDataLayouts;
import org.shedlang.compiler.patio.ast.types.PatioTypes;
import org.shedlang.compiler.sources.Source;
import org.shedlang.compiler.sources.Sources;
-import org.shedlang.compiler.stackir.StackIrNamespace;
-import org.shedlang.compiler.stackir.instructions.*;
+import org.shedlang.compiler.shid.ShidNamespace;
+import org.shedlang.compiler.shid.instructions.*;
import org.shedlang.compiler.types.NamespaceName;
import org.shedlang.compiler.util.P;
@@ -100,19 +100,19 @@ public class PatioCodeGen {
}
public static PatioCompilationUnit generateNamespace(
- StackIrNamespace stackIrNamespace,
+ ShidNamespace shidNamespace,
PatioCodeGenContext context
) {
context = PatioCodeGenNamespaces.define(
- stackIrNamespace.namespaceName(),
+ shidNamespace.namespaceName(),
initContext -> {
- initContext = declareStackIrLocals(
- stackIrNamespace.instructions(),
+ initContext = declareShidLocals(
+ shidNamespace.instructions(),
FreeVariables.empty(),
initContext
);
- return generateInstructions(stackIrNamespace.instructions(), initContext);
+ return generateInstructions(shidNamespace.instructions(), initContext);
},
context
);
@@ -122,22 +122,22 @@ public class PatioCodeGen {
}
public static PatioCodeGenContext generateInstructions(
- List<Instruction> stackIrInstructions,
+ List<ShidInstruction> shidInstructions,
PatioCodeGenContext context
) {
- for (var stackIrInstruction : stackIrInstructions) {
- context = generateInstruction(stackIrInstruction, context);
+ for (var shidInstruction : shidInstructions) {
+ context = generateInstruction(shidInstruction, context);
}
return context;
}
public static PatioCodeGenContext generateInstruction(
- Instruction stackIrInstruction,
+ ShidInstruction shidInstruction,
PatioCodeGenContext context
) {
- return switch (stackIrInstruction) {
- case CallInstruction call -> {
+ return switch (shidInstruction) {
+ case ShidCall call -> {
var namedArgsByName = new ArrayList<Map.Entry<String, PatioLocalRef>>();
for (var argName : call.namedArgNames().reversed()) {
var argResult = context.allocateVal(
@@ -150,7 +150,7 @@ public class PatioCodeGen {
context = context.temporaryPopIntoLocal(
arg,
- stackIrInstruction.source()
+ shidInstruction.source()
);
namedArgsByName.add(Map.entry(argName, arg));
@@ -168,7 +168,7 @@ public class PatioCodeGen {
context = context.temporaryPopIntoLocal(
arg,
- stackIrInstruction.source()
+ shidInstruction.source()
);
positionalArgs.add(arg);
@@ -184,7 +184,7 @@ public class PatioCodeGen {
context = context.temporaryPopIntoLocal(
receiver,
- stackIrInstruction.source()
+ shidInstruction.source()
);
var targetResult = context.allocateVal(
@@ -199,12 +199,12 @@ public class PatioCodeGen {
receiver,
positionalArgs,
namedArgsByName,
- stackIrInstruction.source(),
+ shidInstruction.source(),
context
).temporaryPush(target);
}
- case DefineEffectInstruction defineEffect -> {
+ case ShidDefineEffect defineEffect -> {
var targetResult = context.allocateVal(
PatioCodeGenLocalSpace.USER_DEFINED_EFFECT,
defineEffect.effect().name(),
@@ -225,7 +225,7 @@ public class PatioCodeGen {
yield context;
}
- case DefineFunctionInstruction defineFunction -> {
+ case ShidDefineFunction defineFunction -> {
var targetResult = context.allocateVal(
PatioCodeGenLocalSpace.CLOSURE,
defineFunction.name(),
@@ -243,7 +243,7 @@ public class PatioCodeGen {
functionContext -> {
// TODO: explicitly store locals on a function?
- functionContext = declareStackIrLocals(
+ functionContext = declareShidLocals(
defineFunction.body(),
defineFunction.freeVariables(),
functionContext
@@ -260,7 +260,7 @@ public class PatioCodeGen {
yield context;
}
- case DefineStructInstruction defineStruct -> {
+ case ShidDefineStruct defineStruct -> {
var targetResult = context.allocateVal(
PatioCodeGenLocalSpace.STRUCT_TYPE,
defineStruct.type().name(),
@@ -282,10 +282,10 @@ public class PatioCodeGen {
yield context;
}
- case DiscardInstruction discard ->
+ case ShidDiscard discard ->
context.temporaryPop().context();
- case DuplicateInstruction duplicate -> {
+ case ShidDuplicate duplicate -> {
var valueResult = context.temporaryPop();
var value = valueResult.value();
context = valueResult.context();
@@ -293,7 +293,7 @@ public class PatioCodeGen {
yield context.temporaryPush(value).temporaryPush(value);
}
- case FieldLoadInstruction fieldLoad -> {
+ case ShidFieldLoad fieldLoad -> {
var receiverResult = context.temporaryPop();
var receiver = receiverResult.value();
context = receiverResult.context();
@@ -307,7 +307,7 @@ public class PatioCodeGen {
context = targetResult.context();
switch (fieldLoad.receiver()) {
- case FieldLoadInstruction.Receiver.Effect receiverEffect -> {
+ case ShidFieldLoad.Receiver.Effect receiverEffect -> {
context = PatioCodeGenEffects.fieldLoad(
target,
receiver,
@@ -318,7 +318,7 @@ public class PatioCodeGen {
);
}
- case FieldLoadInstruction.Receiver.Namespace receiverNamespace -> {
+ case ShidFieldLoad.Receiver.Namespace receiverNamespace -> {
context = PatioCodeGenNamespaces.fieldLoad(
target,
receiver,
@@ -329,7 +329,7 @@ public class PatioCodeGen {
);
}
- case FieldLoadInstruction.Receiver.Struct receiverStruct -> {
+ case ShidFieldLoad.Receiver.Struct receiverStruct -> {
context = PatioCodeGenStructs.fieldLoad(
target,
receiver,
@@ -346,7 +346,7 @@ public class PatioCodeGen {
yield context;
}
- case IfInstruction if_ -> {
+ case ShidIf if_ -> {
var conditionBoolResult = generateCondition(if_.source(), context);
var conditionBool = conditionBoolResult.value();
context = conditionBoolResult.context();
@@ -387,7 +387,7 @@ public class PatioCodeGen {
yield context;
}
- case IntAddInstruction intAdd ->
+ case ShidIntAdd intAdd ->
generateBinaryOperation(
(target, left, right, operationContext) ->
operationContext.addInstruction(new PatioIntAdd(
@@ -399,7 +399,7 @@ public class PatioCodeGen {
context
);
- case IntEqualsInstruction intEquals ->
+ case ShidIntEquals intEquals ->
generateComparison(
(target, left, right, operationContext) ->
operationContext.addInstruction(new PatioIntEquals(
@@ -412,7 +412,7 @@ public class PatioCodeGen {
context
);
- case IntNotEqualInstruction intNotEqual ->
+ case ShidIntNotEqual intNotEqual ->
generateComparison(
(target, left, right, operationContext) ->
operationContext.addInstruction(new PatioIntNotEqual(
@@ -425,7 +425,7 @@ public class PatioCodeGen {
context
);
- case IntSubInstruction intSub ->
+ case ShidIntSub intSub ->
generateBinaryOperation(
(target, left, right, operationContext) ->
operationContext.addInstruction(new PatioIntSub(
@@ -437,30 +437,30 @@ public class PatioCodeGen {
context
);
- case LocalLoadInstruction localLoad -> {
- var local = context.stackIrLocalNameToLocal(localLoad.name());
+ case ShidLocalLoad localLoad -> {
+ var local = context.shidLocalNameToLocal(localLoad.name());
yield context.temporaryPush(local);
}
- case LocalStoreInstruction localStore -> {
+ case ShidLocalStore localStore -> {
context = context.temporaryPopIntoLocal(
- context.stackIrLocalNameToLocal(localStore.name()),
+ context.shidLocalNameToLocal(localStore.name()),
localStore.source()
);
- context = context.initStackIrLocal(localStore.name());
+ context = context.initShidLocal(localStore.name());
yield context;
}
- case LoopBreakInstruction loopBreak ->
+ case ShidLoopBreak loopBreak ->
context.addInstruction(new PatioLoopBreak(loopBreak.source()));
- case LoopContinueInstruction loopContinue ->
+ case ShidLoopContinue loopContinue ->
context.addInstruction(new PatioLoopContinue(loopContinue.source()));
- case LoopInstruction loop -> {
+ case ShidLoop loop -> {
context = context.enterBlock();
context = generateInstructions(loop.body(), context);
@@ -473,7 +473,7 @@ public class PatioCodeGen {
yield context;
}
- case NamespaceFieldStoreInstruction namespaceFieldStore -> {
+ case ShidNamespaceFieldStore namespaceFieldStore -> {
var fieldValueResult = context.temporaryPop();
var fieldValue = fieldValueResult.value();
context = fieldValueResult.context();
@@ -489,7 +489,7 @@ public class PatioCodeGen {
yield context;
}
- case NamespaceImportInstruction namespaceImport -> {
+ case ShidNamespaceImport namespaceImport -> {
var namespaceValueResult = context.allocateVal(
PatioCodeGenLocalSpace.NAMESPACE_VALUE,
PatioCodeGenNamespaces.NAMESPACE_VALUE_TYPE
@@ -509,13 +509,13 @@ public class PatioCodeGen {
yield context;
}
- case PushBoolInstruction pushBool ->
+ case ShidPushBool pushBool ->
pushValue(pushBool.value() ? 1 : 0, pushBool.source(), context);
- case PushIntInstruction pushInt ->
+ case ShidPushInt pushInt ->
pushValue(pushInt.value().intValueExact(), pushInt.source(), context);
- case PushStringInstruction pushString -> {
+ case ShidPushString pushString -> {
var stringPtrOperandResult = PatioCodeGenStrings.define(
pushString.value(),
pushString.source(),
@@ -542,10 +542,10 @@ public class PatioCodeGen {
yield context;
}
- case PushUnitInstruction pushUnit ->
+ case ShidPushUnit pushUnit ->
pushValue(0, pushUnit.source(), context);
- case ResumeInstruction resume -> {
+ case ShidResume resume -> {
var valueResult = context.temporaryPop();
var value = valueResult.value();
context = valueResult.context();
@@ -553,7 +553,7 @@ public class PatioCodeGen {
yield context.addInstruction(new PatioResume(value, resume.source()));
}
- case ReturnInstruction return_ -> {
+ case ShidReturn return_ -> {
var valueResult = context.temporaryPop();
var value = valueResult.value();
context = valueResult.context();
@@ -561,7 +561,7 @@ public class PatioCodeGen {
yield context.addInstruction(new PatioReturn(value, return_.source()));
}
- case StringAddInstruction stringAdd ->
+ case ShidStringAdd stringAdd ->
generateBinaryOperation(
(target, left, right, operationContext) ->
PatioCodeGenStrings.add(
@@ -574,7 +574,7 @@ public class PatioCodeGen {
context
);
- case SwitchInstruction switch_ -> {
+ case ShidSwitch switch_ -> {
var targetResult = context.allocateVal(
PatioCodeGenLocalSpace.TEMPORARY,
PatioCodeGenTypes.VALUE_TYPE
@@ -602,20 +602,20 @@ public class PatioCodeGen {
var cases = new ArrayList<PatioSwitch.Case>();
- for (var stackIrCase : switch_.cases()) {
+ for (var shidCase : switch_.cases()) {
var bodyResult = generateBlock(
1,
- stackIrCase.body(),
- stackIrCase.source(),
+ shidCase.body(),
+ shidCase.source(),
context
);
var body = bodyResult.value();
context = bodyResult.context();
cases.add(new PatioSwitch.Case(
- context.structTag(stackIrCase.caseType()),
+ context.structTag(shidCase.caseType()),
body,
- stackIrCase.source()
+ shidCase.source()
));
}
@@ -638,7 +638,7 @@ public class PatioCodeGen {
yield context;
}
- case TryInstruction try_ -> {
+ case ShidTry try_ -> {
var handlerMethodsByName = new HashMap<String, PatioOperand>();
for (var handlerMethodName : try_.handlerMethodNames().reversed()) {
@@ -661,7 +661,7 @@ public class PatioCodeGen {
yield context;
}
- case TupleCreateInstruction tupleCreate -> {
+ case ShidTupleCreate tupleCreate -> {
var elements = new ArrayList<PatioOperand>();
for (var elementIndex = tupleCreate.elementCount(); elementIndex --> 0;) {
@@ -687,7 +687,7 @@ public class PatioCodeGen {
yield context.temporaryPush(tuple);
}
- case TupleGetInstruction tupleGet -> {
+ case ShidTupleGet tupleGet -> {
var tupleResult = context.temporaryPop();
var tuple = tupleResult.value();
context = tupleResult.context();
@@ -705,7 +705,7 @@ public class PatioCodeGen {
yield context.temporaryPush(target);
}
- case VarLoadInstruction varLoad -> {
+ case ShidVarLoad varLoad -> {
var varValueResult = context.allocateVal(
PatioCodeGenLocalSpace.VAR_VALUE,
varLoad.name(),
@@ -716,7 +716,7 @@ public class PatioCodeGen {
context = context.addInstruction(new PatioMemoryLoad(
varValue,
- context.stackIrLocalNameToLocal(varLoad.name()),
+ context.shidLocalNameToLocal(varLoad.name()),
PatioDataLayouts.fromType(PatioCodeGenTypes.VALUE_TYPE),
List.of(),
varLoad.source()
@@ -727,13 +727,13 @@ public class PatioCodeGen {
yield context;
}
- case VarStoreInstruction varStore -> {
+ case ShidVarStore varStore -> {
var valueResult = context.temporaryPop();
var value = valueResult.value();
context = valueResult.context();
context = context.addInstruction(new PatioMemoryStore(
- context.stackIrLocalNameToLocal(varStore.name()),
+ context.shidLocalNameToLocal(varStore.name()),
PatioDataLayouts.fromType(PatioCodeGenTypes.VALUE_TYPE),
List.of(),
value,
@@ -816,12 +816,12 @@ public class PatioCodeGen {
private static PatioCodeGenResult<PatioBlock> generateBlock(
int resultCount,
- List<Instruction> stackIrInstructions,
+ List<ShidInstruction> shidInstructions,
Source source,
PatioCodeGenContext context
) {
context = context.enterBlock();
- context = generateInstructions(stackIrInstructions, context);
+ context = generateInstructions(shidInstructions, context);
var targets = new ArrayList<PatioOperand>();
for (var i = 0; i < resultCount; i++) {
@@ -875,8 +875,8 @@ public class PatioCodeGen {
return context.toResult(conditionBool);
}
- private static PatioCodeGenContext declareStackIrLocals(
- List<Instruction> body,
+ private static PatioCodeGenContext declareShidLocals(
+ List<ShidInstruction> body,
FreeVariables freeVariables,
PatioCodeGenContext context
) {
@@ -890,7 +890,7 @@ public class PatioCodeGen {
if (freeVariableNames.contains(boundVariable.name())) {
// This is a terrible hack. Another reason to collect variables up-front.
} else if (boundVariable.isMutable()) {
- var patioLocalResult = context.declareStackIrVal(
+ var patioLocalResult = context.declareShidVal(
boundVariable.name(),
PatioTypes.DATA_POINTER
);
@@ -904,9 +904,9 @@ public class PatioCodeGen {
Sources.NULL
));
- context = context.initStackIrLocal(boundVariable.name());
+ context = context.initShidLocal(boundVariable.name());
} else {
- context = context.declareStackIrVal(
+ context = context.declareShidVal(
boundVariable.name(),
PatioCodeGenTypes.VALUE_TYPE
).context();
@@ -916,82 +916,82 @@ public class PatioCodeGen {
}
private static OrderedPSet<BoundVariable> findAssignedVariables(
- List<Instruction> body,
+ List<ShidInstruction> body,
OrderedPSet<BoundVariable> boundVariables
) {
for (var bodyInstruction : body) {
switch (bodyInstruction) {
- case CallInstruction callInstruction -> {
+ case ShidCall callInstruction -> {
}
- case DefineEffectInstruction defineEffectInstruction -> {
+ case ShidDefineEffect defineEffectInstruction -> {
}
- case DefineFunctionInstruction defineFunctionInstruction -> {
+ case ShidDefineFunction defineFunctionInstruction -> {
}
- case DefineStructInstruction defineStructInstruction -> {
+ case ShidDefineStruct defineStructInstruction -> {
}
- case DiscardInstruction discardInstruction -> {
+ case ShidDiscard discardInstruction -> {
}
- case DuplicateInstruction duplicateInstruction -> {
+ case ShidDuplicate duplicateInstruction -> {
}
- case FieldLoadInstruction fieldLoadInstruction -> {
+ case ShidFieldLoad fieldLoadInstruction -> {
}
- case IfInstruction ifInstruction -> {
+ case ShidIf ifInstruction -> {
boundVariables = findAssignedVariables(ifInstruction.trueBody(), boundVariables);
boundVariables = findAssignedVariables(ifInstruction.falseBody(), boundVariables);
}
- case IntAddInstruction intAddInstruction -> {
+ case ShidIntAdd intAddInstruction -> {
}
- case IntEqualsInstruction intEqualsInstruction -> {
+ case ShidIntEquals intEqualsInstruction -> {
}
- case IntNotEqualInstruction intNotEqualInstruction -> {
+ case ShidIntNotEqual intNotEqualInstruction -> {
}
- case IntSubInstruction intSubInstruction -> {
+ case ShidIntSub intSubInstruction -> {
}
- case LocalLoadInstruction localLoadInstruction -> {
+ case ShidLocalLoad localLoadInstruction -> {
}
- case LocalStoreInstruction localStoreInstruction -> {
+ case ShidLocalStore localStoreInstruction -> {
boundVariables = boundVariables.plus(BoundVariable.immutable(localStoreInstruction.name()));
}
- case LoopBreakInstruction loopBreakInstruction -> {
+ case ShidLoopBreak loopBreakInstruction -> {
}
- case LoopContinueInstruction loopContinueInstruction -> {
+ case ShidLoopContinue loopContinueInstruction -> {
}
- case LoopInstruction loopInstruction -> {
+ case ShidLoop loopInstruction -> {
boundVariables = findAssignedVariables(loopInstruction.body(), boundVariables);
}
- case NamespaceFieldStoreInstruction namespaceFieldStoreInstruction -> {
+ case ShidNamespaceFieldStore namespaceFieldStoreInstruction -> {
}
- case NamespaceImportInstruction namespaceImportInstruction -> {
+ case ShidNamespaceImport namespaceImportInstruction -> {
}
- case PushBoolInstruction pushBoolInstruction -> {
+ case ShidPushBool pushBoolInstruction -> {
}
- case PushIntInstruction pushIntInstruction -> {
+ case ShidPushInt pushIntInstruction -> {
}
- case PushStringInstruction pushStringInstruction -> {
+ case ShidPushString pushStringInstruction -> {
}
- case PushUnitInstruction pushUnitInstruction -> {
+ case ShidPushUnit pushUnitInstruction -> {
}
- case ResumeInstruction resumeInstruction -> {
+ case ShidResume resumeInstruction -> {
}
- case ReturnInstruction returnInstruction -> {
+ case ShidReturn returnInstruction -> {
}
- case StringAddInstruction stringAddInstruction -> {
+ case ShidStringAdd stringAddInstruction -> {
}
- case SwitchInstruction switchInstruction -> {
+ case ShidSwitch switchInstruction -> {
for (var switchCase : switchInstruction.cases()) {
boundVariables = findAssignedVariables(switchCase.body(), boundVariables);
}
}
- case TryInstruction tryInstruction -> {
+ case ShidTry tryInstruction -> {
boundVariables = findAssignedVariables(tryInstruction.body(), boundVariables);
}
- case TupleCreateInstruction tupleCreateInstruction -> {
+ case ShidTupleCreate tupleCreateInstruction -> {
}
- case TupleGetInstruction tupleGetInstruction -> {
+ case ShidTupleGet tupleGetInstruction -> {
}
- case VarLoadInstruction varLoadInstruction -> {
+ case ShidVarLoad varLoadInstruction -> {
}
- case VarStoreInstruction varStoreInstruction -> {
+ case ShidVarStore varStoreInstruction -> {
boundVariables = boundVariables.plus(BoundVariable.mutable(varStoreInstruction.name()));
}
}
diff --git a/src/main/java/org/shedlang/compiler/patio/PatioCodeGenClosures.java b/src/main/java/org/shedlang/compiler/patio/PatioCodeGenClosures.java
index 961eeef0..abc89e10 100644
--- a/src/main/java/org/shedlang/compiler/patio/PatioCodeGenClosures.java
+++ b/src/main/java/org/shedlang/compiler/patio/PatioCodeGenClosures.java
@@ -9,7 +9,7 @@ import org.shedlang.compiler.patio.ast.operands.PatioLocalRef;
import org.shedlang.compiler.patio.ast.operands.PatioOperand;
import org.shedlang.compiler.patio.ast.types.*;
import org.shedlang.compiler.sources.Source;
-import org.shedlang.compiler.stackir.instructions.DefineFunctionInstruction;
+import org.shedlang.compiler.shid.instructions.ShidDefineFunction;
import java.util.ArrayList;
import java.util.List;
@@ -53,7 +53,7 @@ class PatioCodeGenClosures {
FreeVariable freeVariable,
PatioCodeGenContext context
) {
- var local = context.stackIrLocalNameToLocal(freeVariable.name());
+ var local = context.shidLocalNameToLocal(freeVariable.name());
return context.localType(local);
}
@@ -64,8 +64,8 @@ class PatioCodeGenClosures {
public static PatioCodeGenContext create(
PatioLocalRef target,
String name,
- List<DefineFunctionInstruction.Param> positionalParams,
- List<DefineFunctionInstruction.Param> namedParams,
+ List<ShidDefineFunction.Param> positionalParams,
+ List<ShidDefineFunction.Param> namedParams,
FreeVariables freeVariables,
Function<PatioCodeGenContext, PatioCodeGenContext> generateBody,
Source source,
@@ -90,14 +90,14 @@ class PatioCodeGenClosures {
bodyContext = closurePointerResult.context();
var orderedNamedParams = sortedBy(namedParams, param -> param.name());
- var stackIrParams = Stream.concat(positionalParams.stream(), orderedNamedParams.stream()).toList();
+ var shidParams = Stream.concat(positionalParams.stream(), orderedNamedParams.stream()).toList();
- for (var stackIrParam : stackIrParams) {
- bodyContext = bodyContext.defineStackIrParam(stackIrParam.name());
+ for (var shidParam : shidParams) {
+ bodyContext = bodyContext.defineShidParam(shidParam.name());
}
for (var freeVariable : freeVariables) {
- var freeVariableLocalResult = bodyContext.declareStackIrVal(
+ var freeVariableLocalResult = bodyContext.declareShidVal(
freeVariable.name(),
freeVariableType(freeVariable, bodyContextParent)
);
@@ -112,7 +112,7 @@ class PatioCodeGenClosures {
source
));
- bodyContext = bodyContext.initStackIrLocal(freeVariable.name());
+ bodyContext = bodyContext.initShidLocal(freeVariable.name());
}
bodyContext = generateBody.apply(bodyContext);
@@ -145,13 +145,13 @@ class PatioCodeGenClosures {
));
for (var freeVariable : freeVariables) {
- context = context.onceStackIrLocalDefined(
+ context = context.onceShidLocalDefined(
freeVariable.name(),
c -> c.addInstruction(new PatioMemoryStore(
closurePointer,
layout,
freeVariableOffset(freeVariable),
- c.stackIrLocalNameToLocal(freeVariable.name()),
+ c.shidLocalNameToLocal(freeVariable.name()),
source
))
);
diff --git a/src/main/java/org/shedlang/compiler/patio/PatioCodeGenContext.java b/src/main/java/org/shedlang/compiler/patio/PatioCodeGenContext.java
index cfb075c3..545a198f 100644
--- a/src/main/java/org/shedlang/compiler/patio/PatioCodeGenContext.java
+++ b/src/main/java/org/shedlang/compiler/patio/PatioCodeGenContext.java
@@ -184,8 +184,8 @@ public record PatioCodeGenContext(
PStack<PatioLocalRef> temporaryStack,
PVector<PatioInstruction> instructions,
OrderedPMap<String, PatioLocal> localsByName,
- PMap<String, PatioLocalRef> stackIrNameToLocal,
- PMap<String, PVector<Function<PatioCodeGenContext, PatioCodeGenContext>>> waitingForStackIrLocal
+ PMap<String, PatioLocalRef> shidNameToLocal,
+ PMap<String, PVector<Function<PatioCodeGenContext, PatioCodeGenContext>>> waitingForShidLocal
) {
public static final FunctionContext EMPTY = new FunctionContext(
P.stack(),
@@ -201,8 +201,8 @@ public record PatioCodeGenContext(
this.temporaryStack.minus(0),
this.instructions,
this.localsByName,
- this.stackIrNameToLocal,
- this.waitingForStackIrLocal
+ this.shidNameToLocal,
+ this.waitingForShidLocal
).toResult(this.temporaryStack.get(0));
}
@@ -212,8 +212,8 @@ public record PatioCodeGenContext(
this.temporaryStack.plus(value),
this.instructions,
this.localsByName,
- this.stackIrNameToLocal,
- this.waitingForStackIrLocal
+ this.shidNameToLocal,
+ this.waitingForShidLocal
);
}
@@ -223,8 +223,8 @@ public record PatioCodeGenContext(
this.temporaryStack,
this.instructions.plus(instruction),
this.localsByName,
- this.stackIrNameToLocal,
- this.waitingForStackIrLocal
+ this.shidNameToLocal,
+ this.waitingForShidLocal
);
}
@@ -244,22 +244,22 @@ public record PatioCodeGenContext(
this.temporaryStack,
this.instructions,
this.localsByName.plus(fullName, createLocal.apply(fullName)),
- this.stackIrNameToLocal,
- this.waitingForStackIrLocal
+ this.shidNameToLocal,
+ this.waitingForShidLocal
).toResult(new PatioLocalRef(fullName));
}
@CheckReturnValue
- public FunctionContext.Result<PatioLocalRef> declareStackIrLocal(
+ public FunctionContext.Result<PatioLocalRef> declareShidLocal(
String name,
PatioType type,
PatioLocalType localType
) {
var context = this;
- if (this.stackIrNameToLocal.containsKey(name)) {
+ if (this.shidNameToLocal.containsKey(name)) {
// TODO: better error
- throw new RuntimeException("Stack IR local already exists: " + name);
+ throw new RuntimeException("Shid local already exists: " + name);
}
var fullName = NameAllocator.allocateFixedName(
@@ -278,48 +278,48 @@ public record PatioCodeGenContext(
new PatioLocal(fullName, type, localType)
),
// TODO: the mapping is redundant given we fix the mapping
- this.stackIrNameToLocal.plus(name, localRef),
- this.waitingForStackIrLocal.plus(name, P.vector())
+ this.shidNameToLocal.plus(name, localRef),
+ this.waitingForShidLocal.plus(name, P.vector())
);
return context.toResult(localRef);
}
@CheckReturnValue
- public FunctionContext.Result<PVector<Function<PatioCodeGenContext, PatioCodeGenContext>>> initStackIrLocal(String name) {
+ public FunctionContext.Result<PVector<Function<PatioCodeGenContext, PatioCodeGenContext>>> initShidLocal(String name) {
var context = new FunctionContext(
this.temporaryStack,
this.instructions,
this.localsByName,
- this.stackIrNameToLocal,
- this.waitingForStackIrLocal.minus(name)
+ this.shidNameToLocal,
+ this.waitingForShidLocal.minus(name)
);
- return context.toResult(this.waitingForStackIrLocal.getOrDefault(name, P.vector()));
+ return context.toResult(this.waitingForShidLocal.getOrDefault(name, P.vector()));
}
@CheckReturnValue
- public PatioLocalRef stackIrLocalNameToLocal(String name) {
- var local = this.stackIrNameToLocal.get(name);
+ public PatioLocalRef shidLocalNameToLocal(String name) {
+ var local = this.shidNameToLocal.get(name);
if (local == null) {
// TODO: better error
- throw new RuntimeException("Unknown stack IR local: " + name);
+ throw new RuntimeException("Unknown Shid local: " + name);
}
return local;
}
@CheckReturnValue
- public Optional<PatioLocalRef> stackIrLocalNameToLocalOrNone(String name) {
- var local = this.stackIrNameToLocal.get(name);
+ public Optional<PatioLocalRef> shidLocalNameToLocalOrNone(String name) {
+ var local = this.shidNameToLocal.get(name);
return Optional.ofNullable(local);
}
@CheckReturnValue
- public boolean isStackIrLocalDefined(String name) {
- return !this.waitingForStackIrLocal.containsKey(name);
+ public boolean isShidLocalDefined(String name) {
+ return !this.waitingForShidLocal.containsKey(name);
}
@CheckReturnValue
@@ -329,7 +329,7 @@ public record PatioCodeGenContext(
}
@CheckReturnValue
- public FunctionContext addWaitingForShedLocal(
+ public FunctionContext addWaitingForShidLocal(
String name,
Function<PatioCodeGenContext, PatioCodeGenContext> func
) {
@@ -337,10 +337,10 @@ public record PatioCodeGenContext(
this.temporaryStack,
this.instructions,
this.localsByName,
- this.stackIrNameToLocal,
- this.waitingForStackIrLocal.plus(
+ this.shidNameToLocal,
+ this.waitingForShidLocal.plus(
name,
- this.waitingForStackIrLocal.getOrDefault(name, P.vector()).plus(func)
+ this.waitingForShidLocal.getOrDefault(name, P.vector()).plus(func)
)
);
}
@@ -514,13 +514,13 @@ public record PatioCodeGenContext(
}
@CheckReturnValue
- public PatioCodeGenContext defineStackIrParam(String name) {
- return declareStackIrParam(name).initStackIrLocal(name);
+ public PatioCodeGenContext defineShidParam(String name) {
+ return declareShidParam(name).initShidLocal(name);
}
@CheckReturnValue
- private PatioCodeGenContext declareStackIrParam(String name) {
- return declareStackIrLocal(
+ private PatioCodeGenContext declareShidParam(String name) {
+ return declareShidLocal(
name,
PatioCodeGenTypes.VALUE_TYPE,
PatioLocalType.PARAM
@@ -528,8 +528,8 @@ public record PatioCodeGenContext(
}
@CheckReturnValue
- public PatioCodeGenResult<PatioLocalRef> declareStackIrVal(String name, PatioType type) {
- return declareStackIrLocal(
+ public PatioCodeGenResult<PatioLocalRef> declareShidVal(String name, PatioType type) {
+ return declareShidLocal(
name,
type,
PatioLocalType.VAL
@@ -537,12 +537,12 @@ public record PatioCodeGenContext(
}
@CheckReturnValue
- public PatioCodeGenResult<PatioLocalRef> declareStackIrLocal(
+ public PatioCodeGenResult<PatioLocalRef> declareShidLocal(
String name,
PatioType type,
PatioLocalType patioLocalType
) {
- return withFunctionContextResult(this.functionContext.declareStackIrLocal(
+ return withFunctionContextResult(this.functionContext.declareShidLocal(
name,
type,
patioLocalType
@@ -550,8 +550,8 @@ public record PatioCodeGenContext(
}
@CheckReturnValue
- public PatioCodeGenContext initStackIrLocal(String name) {
- var result = this.functionContext.initStackIrLocal(name);
+ public PatioCodeGenContext initShidLocal(String name) {
+ var result = this.functionContext.initShidLocal(name);
var context = withFunctionContext(result.context);
for (var func : result.value) {
@@ -562,18 +562,18 @@ public record PatioCodeGenContext(
}
@CheckReturnValue
- public PatioCodeGenContext onceStackIrLocalDefined(
+ public PatioCodeGenContext onceShidLocalDefined(
String name,
Function<PatioCodeGenContext, PatioCodeGenContext> func
) {
- var local = this.functionContext.stackIrLocalNameToLocalOrNone(name);
+ var local = this.functionContext.shidLocalNameToLocalOrNone(name);
if (local.isEmpty()) {
// TODO: better error
- throw new RuntimeException("Unknown stack IR local: " + name);
- } else if (!this.functionContext.isStackIrLocalDefined(name)) {
+ throw new RuntimeException("Unknown Shid local: " + name);
+ } else if (!this.functionContext.isShidLocalDefined(name)) {
return withFunctionContext(
- this.functionContext.addWaitingForShedLocal(name, func)
+ this.functionContext.addWaitingForShidLocal(name, func)
);
} else {
return func.apply(this);
@@ -581,8 +581,8 @@ public record PatioCodeGenContext(
}
@CheckReturnValue
- public PatioLocalRef stackIrLocalNameToLocal(String name) {
- return this.functionContext.stackIrLocalNameToLocal(name);
+ public PatioLocalRef shidLocalNameToLocal(String name) {
+ return this.functionContext.shidLocalNameToLocal(name);
}
@CheckReturnValue
@@ -634,8 +634,8 @@ public record PatioCodeGenContext(
P.stack(),
P.vector(),
this.functionContext.localsByName,
- this.functionContext.stackIrNameToLocal,
- this.functionContext.waitingForStackIrLocal
+ this.functionContext.shidNameToLocal,
+ this.functionContext.waitingForShidLocal
)
);
}
@@ -654,8 +654,8 @@ public record PatioCodeGenContext(
this.blockStack.get(0).temporaryStack,
this.blockStack.get(0).instructions,
this.functionContext.localsByName,
- this.functionContext.stackIrNameToLocal,
- this.functionContext.waitingForStackIrLocal
+ this.functionContext.shidNameToLocal,
+ this.functionContext.waitingForShidLocal
)
).toResult(this.functionContext.instructions);
}
diff --git a/src/main/java/org/shedlang/compiler/patio/PatioCodeGenEffects.java b/src/main/java/org/shedlang/compiler/patio/PatioCodeGenEffects.java
index 4eb842b2..5f32e90e 100644
--- a/src/main/java/org/shedlang/compiler/patio/PatioCodeGenEffects.java
+++ b/src/main/java/org/shedlang/compiler/patio/PatioCodeGenEffects.java
@@ -13,7 +13,7 @@ import org.shedlang.compiler.patio.ast.types.PatioType;
import org.shedlang.compiler.patio.ast.types.PatioTypes;
import org.shedlang.compiler.sources.Source;
import org.shedlang.compiler.sources.Sources;
-import org.shedlang.compiler.stackir.instructions.DefineFunctionInstruction;
+import org.shedlang.compiler.shid.instructions.ShidDefineFunction;
import org.shedlang.compiler.types.UserDefinedEffect;
import org.shedlang.compiler.util.Lists;
@@ -104,7 +104,7 @@ public class PatioCodeGenEffects {
var positionalParams = IntStream.range(0, method.type().positionalParams().size())
// TODO: ensure names of positional params doesn't clash with named params
- .mapToObj(paramIndex -> new DefineFunctionInstruction.Param("arg" + paramIndex, source))
+ .mapToObj(paramIndex -> new ShidDefineFunction.Param("arg" + paramIndex, source))
.toList();
context = PatioCodeGenClosures.create(
@@ -112,7 +112,7 @@ public class PatioCodeGenEffects {
method.name(),
positionalParams,
method.type().namedParams().stream()
- .map(namedParam -> new DefineFunctionInstruction.Param(namedParam.name(), source))
+ .map(namedParam -> new ShidDefineFunction.Param(namedParam.name(), source))
.toList(),
FreeVariables.empty(),
bodyContext -> {
@@ -147,12 +147,12 @@ public class PatioCodeGenEffects {
returnValue,
handlerMethod,
positionalParams.stream()
- .map(param -> bodyContextArgs.stackIrLocalNameToLocal(param.name()))
+ .map(param -> bodyContextArgs.shidLocalNameToLocal(param.name()))
.toList(),
method.type().namedParams().stream()
.map(param -> Map.entry(
param.name(),
- bodyContextArgs.stackIrLocalNameToLocal(param.name())
+ bodyContextArgs.shidLocalNameToLocal(param.name())
))
.toList(),
source,
diff --git a/src/main/java/org/shedlang/compiler/patio/PatioCodeGenStructs.java b/src/main/java/org/shedlang/compiler/patio/PatioCodeGenStructs.java
index 92081325..6ef49080 100644
--- a/src/main/java/org/shedlang/compiler/patio/PatioCodeGenStructs.java
+++ b/src/main/java/org/shedlang/compiler/patio/PatioCodeGenStructs.java
@@ -8,8 +8,8 @@ import org.shedlang.compiler.patio.ast.types.PatioDataLayout;
import org.shedlang.compiler.patio.ast.types.PatioDataLayouts;
import org.shedlang.compiler.patio.ast.types.PatioTypes;
import org.shedlang.compiler.sources.Source;
-import org.shedlang.compiler.stackir.instructions.DefineFunctionInstruction;
-import org.shedlang.compiler.stackir.instructions.DefineStructInstruction;
+import org.shedlang.compiler.shid.instructions.ShidDefineFunction;
+import org.shedlang.compiler.shid.instructions.ShidDefineStruct;
import org.shedlang.compiler.types.StructType;
import org.shedlang.compiler.util.Lists;
@@ -22,7 +22,7 @@ public class PatioCodeGenStructs {
public static PatioCodeGenContext createType(
PatioLocalRef target,
StructType type,
- List<DefineStructInstruction.Field> fields,
+ List<ShidDefineStruct.Field> fields,
Source source,
PatioCodeGenContext context
) {
@@ -31,7 +31,7 @@ public class PatioCodeGenStructs {
type.name(),
List.of(),
fields.stream()
- .map(field -> new DefineFunctionInstruction.Param(field.name(), field.source()))
+ .map(field -> new ShidDefineFunction.Param(field.name(), field.source()))
.toList(),
FreeVariables.empty(),
bodyContext -> {
@@ -67,7 +67,7 @@ public class PatioCodeGenStructs {
valuePointer,
structDataLayout,
List.of(1, fieldIndex),
- bodyContext.stackIrLocalNameToLocal(field.name()),
+ bodyContext.shidLocalNameToLocal(field.name()),
source
));
}
diff --git a/src/main/java/org/shedlang/compiler/stackir/InstructionSerializer.java b/src/main/java/org/shedlang/compiler/shid/InstructionSerializer.java
index 2cf812c4..afbccf6c 100644
--- a/src/main/java/org/shedlang/compiler/stackir/InstructionSerializer.java
+++ b/src/main/java/org/shedlang/compiler/shid/InstructionSerializer.java
@@ -1,6 +1,6 @@
-package org.shedlang.compiler.stackir;
+package org.shedlang.compiler.shid;
-import org.shedlang.compiler.stackir.instructions.*;
+import org.shedlang.compiler.shid.instructions.*;
import org.shedlang.compiler.treetext.Tree;
import org.shedlang.compiler.types.StructType;
import org.shedlang.compiler.types.UserDefinedEffect;
@@ -14,17 +14,17 @@ public class InstructionSerializer {
private InstructionSerializer() {
}
- public static void serializeInstructions(List<Instruction> instructions, StringBuilder builder) {
+ public static void serializeInstructions(List<ShidInstruction> instructions, StringBuilder builder) {
var tree = instructionsToTree(instructions);
serializeTree(tree, builder, 0);
}
- public static void serializeInstruction(Instruction instruction, StringBuilder builder) {
+ public static void serializeInstruction(ShidInstruction instruction, StringBuilder builder) {
var tree = instructionToTree(instruction);
serializeTree(tree, builder, 0);
}
- private static Tree instructionsToTree(List<? extends Instruction> instructions) {
+ private static Tree instructionsToTree(List<? extends ShidInstruction> instructions) {
return treeListIndented(
instructions.stream()
.map(instruction -> instructionToTree(instruction))
@@ -32,9 +32,9 @@ public class InstructionSerializer {
);
}
- private static Tree instructionToTree(Instruction instruction) {
+ private static Tree instructionToTree(ShidInstruction instruction) {
return switch (instruction) {
- case CallInstruction callInstruction ->
+ case ShidCall callInstruction ->
treeList(
treeIdentifier("call"),
treeNamed(
@@ -51,13 +51,13 @@ public class InstructionSerializer {
)
);
- case DefineEffectInstruction defineEffectInstruction ->
+ case ShidDefineEffect defineEffectInstruction ->
treeList(
treeIdentifier("define-effect"),
userDefinedEffectToTree(defineEffectInstruction.effect())
);
- case DefineFunctionInstruction defineFunctionInstruction ->
+ case ShidDefineFunction defineFunctionInstruction ->
treeListIndented(
treeIdentifier("define-function"),
treeNamed("name", treeString(defineFunctionInstruction.name())),
@@ -79,7 +79,7 @@ public class InstructionSerializer {
treeNamed("body", instructionsToTree(defineFunctionInstruction.body()))
);
- case DefineStructInstruction defineStructInstruction ->
+ case ShidDefineStruct defineStructInstruction ->
treeListIndented(
treeIdentifier("define-struct"),
treeNamed("type", structTypeToTree(defineStructInstruction.type())),
@@ -90,33 +90,33 @@ public class InstructionSerializer {
))
);
- case DiscardInstruction discardInstruction ->
+ case ShidDiscard discardInstruction ->
treeList(
treeIdentifier("discard")
);
- case DuplicateInstruction duplicate ->
+ case ShidDuplicate duplicate ->
treeList(
treeIdentifier("duplicate")
);
- case FieldLoadInstruction fieldLoad ->
+ case ShidFieldLoad fieldLoad ->
treeList(
treeIdentifier("field-load"),
switch (fieldLoad.receiver()) {
- case FieldLoadInstruction.Receiver.Effect effect ->
+ case ShidFieldLoad.Receiver.Effect effect ->
treeList(
treeIdentifier("effect"),
userDefinedEffectToTree(effect.effect())
);
- case FieldLoadInstruction.Receiver.Namespace namespace ->
+ case ShidFieldLoad.Receiver.Namespace namespace ->
treeList(
treeIdentifier("namespace"),
treeString(namespace.name().toString())
);
- case FieldLoadInstruction.Receiver.Struct struct ->
+ case ShidFieldLoad.Receiver.Struct struct ->
treeList(
treeIdentifier("struct"),
structTypeToTree(struct.type())
@@ -125,7 +125,7 @@ public class InstructionSerializer {
treeString(fieldLoad.fieldName())
);
- case IfInstruction if_ ->
+ case ShidIf if_ ->
treeListIndented(
treeIdentifier("if"),
treeNamed("result-count", treeInt(if_.resultCount())),
@@ -133,92 +133,92 @@ public class InstructionSerializer {
instructionsToTree(if_.falseBody())
);
- case IntAddInstruction intAdd ->
+ case ShidIntAdd intAdd ->
treeList(treeIdentifier("int-add"));
- case IntEqualsInstruction intEquals ->
+ case ShidIntEquals intEquals ->
treeList(treeIdentifier("int-eq"));
- case IntNotEqualInstruction intNotEqual ->
+ case ShidIntNotEqual intNotEqual ->
treeList(treeIdentifier("int-ne"));
- case IntSubInstruction intSub ->
+ case ShidIntSub intSub ->
treeList(treeIdentifier("int-sub"));
- case LocalLoadInstruction localLoadInstruction ->
+ case ShidLocalLoad localLoadInstruction ->
treeList(
treeIdentifier("local-load"),
treeString(localLoadInstruction.name())
);
- case LocalStoreInstruction localStoreInstruction ->
+ case ShidLocalStore localStoreInstruction ->
treeList(
treeIdentifier("local-store"),
treeString(localStoreInstruction.name())
);
- case LoopInstruction loop ->
+ case ShidLoop loop ->
treeListIndented(
treeIdentifier("loop"),
instructionsToTree(loop.body())
);
- case LoopBreakInstruction loopBreak ->
+ case ShidLoopBreak loopBreak ->
treeList(treeIdentifier("break"));
- case LoopContinueInstruction loopContinue ->
+ case ShidLoopContinue loopContinue ->
treeList(treeIdentifier("continue"));
- case NamespaceFieldStoreInstruction namespaceFieldStore ->
+ case ShidNamespaceFieldStore namespaceFieldStore ->
treeList(
treeIdentifier("namespace-field-store"),
treeString(namespaceFieldStore.namespaceName().toString()),
treeString(namespaceFieldStore.fieldName())
);
- case NamespaceImportInstruction namespaceImport ->
+ case ShidNamespaceImport namespaceImport ->
treeList(
treeIdentifier("namespace-import"),
treeString(namespaceImport.namespaceName().toString())
);
- case PushBoolInstruction pushBoolInstruction ->
+ case ShidPushBool pushBoolInstruction ->
treeList(
treeIdentifier("push-bool"),
treeIdentifier(Boolean.toString(pushBoolInstruction.value()))
);
- case PushIntInstruction pushIntInstruction ->
+ case ShidPushInt pushIntInstruction ->
treeList(
treeIdentifier("push-int"),
treeIdentifier(pushIntInstruction.value().toString())
);
- case PushStringInstruction pushStringInstruction ->
+ case ShidPushString pushStringInstruction ->
treeList(
treeIdentifier("push-string"),
treeString(pushStringInstruction.value())
);
- case PushUnitInstruction pushUnitInstruction ->
+ case ShidPushUnit pushUnitInstruction ->
treeList(
treeIdentifier("push-unit")
);
- case ResumeInstruction resumeInstruction ->
+ case ShidResume resumeInstruction ->
treeList(
treeIdentifier("resume")
);
- case ReturnInstruction returnInstruction ->
+ case ShidReturn returnInstruction ->
treeList(
treeIdentifier("return")
);
- case StringAddInstruction stringAddInstruction ->
+ case ShidStringAdd stringAddInstruction ->
treeList(treeIdentifier("string-add"));
- case SwitchInstruction switchInstruction ->
+ case ShidSwitch switchInstruction ->
treeListIndented(
treeIdentifier("switch"),
treeListIndented(
@@ -231,7 +231,7 @@ public class InstructionSerializer {
)
);
- case TryInstruction tryInstruction ->
+ case ShidTry tryInstruction ->
treeListIndented(
treeIdentifier("try"),
userDefinedEffectToTree(tryInstruction.handledEffect()),
@@ -243,26 +243,26 @@ public class InstructionSerializer {
instructionsToTree(tryInstruction.body())
);
- case TupleCreateInstruction tupleCreateInstruction ->
+ case ShidTupleCreate tupleCreateInstruction ->
treeList(
treeIdentifier("tuple-create"),
treeInt(tupleCreateInstruction.elementCount())
);
- case TupleGetInstruction tupleGetInstruction ->
+ case ShidTupleGet tupleGetInstruction ->
treeList(
treeIdentifier("tuple-get"),
treeInt(tupleGetInstruction.elementIndex()),
treeInt(tupleGetInstruction.elementCount())
);
- case VarLoadInstruction varLoadInstruction ->
+ case ShidVarLoad varLoadInstruction ->
treeList(
treeIdentifier("var-load"),
treeString(varLoadInstruction.name())
);
- case VarStoreInstruction varStoreInstruction ->
+ case ShidVarStore varStoreInstruction ->
treeList(
treeIdentifier("var-store"),
treeString(varStoreInstruction.name())
diff --git a/src/main/java/org/shedlang/compiler/stackir/StackCompiler.java b/src/main/java/org/shedlang/compiler/shid/ShidCodeGen.java
index 2e2b43b7..47190813 100644
--- a/src/main/java/org/shedlang/compiler/stackir/StackCompiler.java
+++ b/src/main/java/org/shedlang/compiler/shid/ShidCodeGen.java
@@ -1,10 +1,10 @@
-package org.shedlang.compiler.stackir;
+package org.shedlang.compiler.shid;
import org.pcollections.*;
import org.shedlang.compiler.ShedBuiltins;
import org.shedlang.compiler.ast.typed.*;
import org.shedlang.compiler.sources.Source;
-import org.shedlang.compiler.stackir.instructions.*;
+import org.shedlang.compiler.shid.instructions.*;
import org.shedlang.compiler.types.*;
import org.shedlang.compiler.util.Iterables;
import org.shedlang.compiler.util.P;
@@ -12,8 +12,8 @@ import org.shedlang.compiler.util.P;
import java.util.ArrayList;
import java.util.List;
-public class StackCompiler {
- private StackCompiler() {
+public class ShidCodeGen {
+ private ShidCodeGen() {
}
private static Context compileAssign(TypedAssignNode node, Context context) {
@@ -32,15 +32,15 @@ public class StackCompiler {
context = context.addInstruction(switch (node.operator()) {
case INT_ADD ->
- new IntAddInstruction(node.source());
+ new ShidIntAdd(node.source());
case INT_EQUALS ->
- new IntEqualsInstruction(node.source());
+ new ShidIntEquals(node.source());
case INT_NOT_EQUAL ->
- new IntNotEqualInstruction(node.source());
+ new ShidIntNotEqual(node.source());
case INT_SUB ->
- new IntSubInstruction(node.source());
+ new ShidIntSub(node.source());
case STRING_ADD ->
- new StringAddInstruction(node.source());
+ new ShidStringAdd(node.source());
});
return context;
@@ -55,7 +55,7 @@ public class StackCompiler {
case TypedFunctionStatementBehaviour.BlockReturn blockReturn -> {
}
case TypedFunctionStatementBehaviour.Continue continue_ -> {
- context = context.addInstruction(new PushUnitInstruction(node.source()));
+ context = context.addInstruction(new ShidPushUnit(node.source()));
}
case TypedFunctionStatementBehaviour.Terminate terminate -> {
}
@@ -71,7 +71,7 @@ public class StackCompiler {
switch (node.behaviour()) {
case TypedFunctionStatementBehaviour.BlockReturn blockReturn -> {
- context = context.addInstruction(new DiscardInstruction(node.source()));
+ context = context.addInstruction(new ShidDiscard(node.source()));
}
case TypedFunctionStatementBehaviour.Continue continue_ -> {
}
@@ -87,7 +87,7 @@ public class StackCompiler {
}
private static Context compileBoolLiteral(TypedBoolLiteralNode node, Context context) {
- return context.addInstruction(new PushBoolInstruction(node.value(), node.source()));
+ return context.addInstruction(new ShidPushBool(node.value(), node.source()));
}
private static Context compileCall(TypedCallNode node, Context context) {
@@ -101,7 +101,7 @@ public class StackCompiler {
context = compileExpression(arg.expression(), context);
}
- var callInstruction = new CallInstruction(
+ var callInstruction = new ShidCall(
node.args().positional().size(),
node.args().named().stream()
.map(arg -> arg.name())
@@ -121,8 +121,8 @@ public class StackCompiler {
var localName = context.shedVariableToLocal(node.effect().name());
return context
- .addInstruction(new DefineEffectInstruction(node.effect(), node.source()))
- .addInstruction(new LocalStoreInstruction(localName, node.source()));
+ .addInstruction(new ShidDefineEffect(node.effect(), node.source()))
+ .addInstruction(new ShidLocalStore(localName, node.source()));
}
public static Context compileExpression(TypedExpressionNode node, Context context) {
@@ -173,7 +173,7 @@ public class StackCompiler {
Context context
) {
context = compileExpression(node.expression(), context);
- context = context.addInstruction(new DiscardInstruction(node.source()));
+ context = context.addInstruction(new ShidDiscard(node.source()));
return context;
}
@@ -185,14 +185,14 @@ public class StackCompiler {
// TODO: handle not a type with fields
var receiver = switch (node.receiver().type()) {
case NamespaceType namespaceType ->
- new FieldLoadInstruction.Receiver.Namespace(namespaceType.namespaceName());
+ new ShidFieldLoad.Receiver.Namespace(namespaceType.namespaceName());
case StructType structType ->
- new FieldLoadInstruction.Receiver.Struct(structType);
+ new ShidFieldLoad.Receiver.Struct(structType);
case TypeLevelValueType typeLevelValueType -> {
if (typeLevelValueType.value() instanceof UserDefinedEffect effect) {
- yield new FieldLoadInstruction.Receiver.Effect(effect);
+ yield new ShidFieldLoad.Receiver.Effect(effect);
} else {
throw new RuntimeException("not a type with fields");
}
@@ -202,7 +202,7 @@ public class StackCompiler {
throw new RuntimeException("not a type with fields");
};
- context = context.addInstruction(new FieldLoadInstruction(
+ context = context.addInstruction(new ShidFieldLoad(
receiver,
node.fieldName(),
node.source()
@@ -222,14 +222,14 @@ public class StackCompiler {
var c = context;
var positionalParams = params.positional().stream()
- .map(param -> new DefineFunctionInstruction.Param(
+ .map(param -> new ShidDefineFunction.Param(
c.shedVariableToLocal(param.name()),
param.source()
))
.toList();
var namedParams = params.named().stream()
- .map(param -> new DefineFunctionInstruction.Param(
+ .map(param -> new ShidDefineFunction.Param(
c.shedVariableToLocal(param.name()),
param.source()
))
@@ -239,10 +239,10 @@ public class StackCompiler {
switch (body.behaviour()) {
case TypedFunctionStatementBehaviour.BlockReturn blockReturn -> {
- context = context.addInstruction(new ReturnInstruction(body.source()));
+ context = context.addInstruction(new ShidReturn(body.source()));
}
case TypedFunctionStatementBehaviour.Continue continue_ -> {
- context = context.addInstruction(new ReturnInstruction(body.source()));
+ context = context.addInstruction(new ShidReturn(body.source()));
}
case TypedFunctionStatementBehaviour.Terminate terminate -> {
}
@@ -263,7 +263,7 @@ public class StackCompiler {
}
}
- var defineFunctionInstruction = new DefineFunctionInstruction(
+ var defineFunctionInstruction = new ShidDefineFunction(
name,
positionalParams,
namedParams,
@@ -288,7 +288,7 @@ public class StackCompiler {
);
var localName = context.shedVariableToLocal(node.name());
- var storeInstruction = new LocalStoreInstruction(localName, node.source());
+ var storeInstruction = new ShidLocalStore(localName, node.source());
return context.addInstruction(storeInstruction);
}
@@ -312,7 +312,7 @@ public class StackCompiler {
Context context
) {
context = compileExpression(node.expression(), context);
- context = context.addInstruction(new ReturnInstruction(node.source()));
+ context = context.addInstruction(new ShidReturn(node.source()));
return context;
}
@@ -380,7 +380,7 @@ public class StackCompiler {
var ifFalseInstructions = context.instructions;
context = context.exitBlock();
- context = context.addInstruction(new IfInstruction(
+ context = context.addInstruction(new ShidIf(
1,
ifTrueInstructions,
ifFalseInstructions,
@@ -392,23 +392,23 @@ public class StackCompiler {
}
private static Context compileIntLiteral(TypedIntLiteralNode node, Context context) {
- return context.addInstruction(new PushIntInstruction(node.value(), node.source()));
+ return context.addInstruction(new ShidPushInt(node.value(), node.source()));
}
- public static StackIrNamespace compileNamespace(TypedNamespaceNode node) {
+ public static ShidNamespace compileNamespace(TypedNamespaceNode node) {
var context = Context.EMPTY;
context = context.addShedVal(ShedBuiltins.PRINT_NAME);
var printLocalName = context.shedVariableToLocal(ShedBuiltins.PRINT_NAME);
context = context
- .addInstruction(new NamespaceImportInstruction(ShedBuiltins.NAMESPACE_NAME, node.source()))
- .addInstruction(new FieldLoadInstruction(
- new FieldLoadInstruction.Receiver.Namespace(ShedBuiltins.NAMESPACE_NAME),
+ .addInstruction(new ShidNamespaceImport(ShedBuiltins.NAMESPACE_NAME, node.source()))
+ .addInstruction(new ShidFieldLoad(
+ new ShidFieldLoad.Receiver.Namespace(ShedBuiltins.NAMESPACE_NAME),
ShedBuiltins.PRINT_NAME,
node.source()
))
- .addInstruction(new LocalStoreInstruction(printLocalName, node.source()));
+ .addInstruction(new ShidLocalStore(printLocalName, node.source()));
for (var boundVariable : node.boundVariables()) {
context = context.addShedVariable(boundVariable);
@@ -417,11 +417,11 @@ public class StackCompiler {
for (var importNode : node.imports()) {
var localName = context.shedVariableToLocal(importNode.variableName());
context = context
- .addInstruction(new NamespaceImportInstruction(
+ .addInstruction(new ShidNamespaceImport(
importNode.namespaceName(),
importNode.source()
))
- .addInstruction(new LocalStoreInstruction(
+ .addInstruction(new ShidLocalStore(
localName,
importNode.source()
));
@@ -452,15 +452,15 @@ public class StackCompiler {
var localName = context.shedVariableToLocal(fieldName);
context = context
- .addInstruction(new LocalLoadInstruction(localName, node.source()))
- .addInstruction(new NamespaceFieldStoreInstruction(
+ .addInstruction(new ShidLocalLoad(localName, node.source()))
+ .addInstruction(new ShidNamespaceFieldStore(
node.namespaceName(),
fieldName,
node.source()
));
}
- return new StackIrNamespace(node.namespaceName(), context.instructions);
+ return new ShidNamespace(node.namespaceName(), context.instructions);
}
public static Context compileNamespaceStatement(TypedNamespaceStatementNode node, Context context) {
@@ -486,13 +486,13 @@ public class StackCompiler {
var shedVariable = context.shedVariable(node.name());
if (shedVariable.isVar) {
- return context.addInstruction(new VarLoadInstruction(
- shedVariable.stackIrLocalName,
+ return context.addInstruction(new ShidVarLoad(
+ shedVariable.shidLocalName,
node.source()
));
} else {
- return context.addInstruction(new LocalLoadInstruction(
- shedVariable.stackIrLocalName,
+ return context.addInstruction(new ShidLocalLoad(
+ shedVariable.shidLocalName,
node.source()
));
}
@@ -500,7 +500,7 @@ public class StackCompiler {
private static Context compileResume(TypedResumeNode node, Context context) {
context = compileExpression(node.expression(), context);
- context = context.addInstruction(new ResumeInstruction(node.source()));
+ context = context.addInstruction(new ShidResume(node.source()));
return context;
}
@@ -508,7 +508,7 @@ public class StackCompiler {
TypedStringLiteralNode node,
Context context
) {
- var instruction = new PushStringInstruction(node.value(), node.source());
+ var instruction = new ShidPushString(node.value(), node.source());
return context.addInstruction(instruction);
}
@@ -516,16 +516,16 @@ public class StackCompiler {
TypedStructDefinitionNode node,
Context context
) {
- var defineStructInstruction = new DefineStructInstruction(
+ var defineStructInstruction = new ShidDefineStruct(
node.type(),
node.fields().stream()
- .map(field -> new DefineStructInstruction.Field(field.name(), field.source()))
+ .map(field -> new ShidDefineStruct.Field(field.name(), field.source()))
.toList(),
node.source()
);
var localName = context.shedVariableToLocal(node.type().name());
- var storeInstruction = new LocalStoreInstruction(localName, node.source());
+ var storeInstruction = new ShidLocalStore(localName, node.source());
return context
.addInstruction(defineStructInstruction)
@@ -536,10 +536,10 @@ public class StackCompiler {
TypedSumTypeDefinitionNode node,
Context context
) {
- var defineSumTypeInstruction = new PushUnitInstruction(node.source());
+ var defineSumTypeInstruction = new ShidPushUnit(node.source());
var localName = context.shedVariableToLocal(node.type().name());
- var storeInstruction = new LocalStoreInstruction(localName, node.source());
+ var storeInstruction = new ShidLocalStore(localName, node.source());
return context
.addInstruction(defineSumTypeInstruction)
@@ -552,12 +552,12 @@ public class StackCompiler {
) {
return switch (target) {
case TypedTargetNode.Ignore ignore -> {
- yield context.addInstruction(new DiscardInstruction(ignore.source()));
+ yield context.addInstruction(new ShidDiscard(ignore.source()));
}
case TypedTargetNode.Reassign reassign -> {
context = context.addInstruction(
- new VarStoreInstruction(
+ new ShidVarStore(
context.shedVariableToLocal(reassign.name()),
reassign.source()
)
@@ -568,17 +568,17 @@ public class StackCompiler {
case TypedTargetNode.Tuple tuple -> {
if (tuple.elements().size() == 0) {
- context = context.addInstruction(new DiscardInstruction(tuple.source()));
+ context = context.addInstruction(new ShidDiscard(tuple.source()));
}
for (var elementIndex = 0; elementIndex < tuple.elements().size(); elementIndex++) {
if (elementIndex < tuple.elements().size() - 1) {
context = context
- .addInstruction(new DuplicateInstruction(tuple.source()));
+ .addInstruction(new ShidDuplicate(tuple.source()));
}
context = context
- .addInstruction(new TupleGetInstruction(
+ .addInstruction(new ShidTupleGet(
elementIndex,
tuple.elements().size(),
tuple.source()
@@ -592,7 +592,7 @@ public class StackCompiler {
case TypedTargetNode.Val val -> {
context = context.addInstruction(
- new LocalStoreInstruction(
+ new ShidLocalStore(
context.shedVariableToLocal(val.name()),
val.source()
)
@@ -603,7 +603,7 @@ public class StackCompiler {
case TypedTargetNode.Var var -> {
context = context.addInstruction(
- new VarStoreInstruction(
+ new ShidVarStore(
context.shedVariableToLocal(var.name()),
var.source()
)
@@ -624,7 +624,7 @@ public class StackCompiler {
var bodyInstructions = context.instructions;
context = context.exitBlock();
- var instruction = new TryInstruction(
+ var instruction = new ShidTry(
node.handledEffect().value(),
node.handlerMethods().stream()
.map(methodNode -> methodNode.name())
@@ -654,7 +654,7 @@ public class StackCompiler {
context = compileExpression(elementNode, context);
}
- var instruction = new TupleCreateInstruction(node.elements().size(), node.source());
+ var instruction = new ShidTupleCreate(node.elements().size(), node.source());
return context.addInstruction(instruction);
}
@@ -662,13 +662,13 @@ public class StackCompiler {
TypedUnitLiteralNode node,
Context context
) {
- return context.addInstruction(new PushUnitInstruction(node.source()));
+ return context.addInstruction(new ShidPushUnit(node.source()));
}
private static Context compileWhen(TypedWhenNode node, Context context) {
context = compileExpression(node.expression(), context);
- var switchCases = new ArrayList<SwitchInstruction.Case>();
+ var switchCases = new ArrayList<ShidSwitch.Case>();
for (var whenCase : node.cases()) {
context = context.enterBlock(whenCase.body().boundVariables());
@@ -676,7 +676,7 @@ public class StackCompiler {
var caseBodyInstructions = context.instructions;
context = context.exitBlock();
- var switchCase = new SwitchInstruction.Case(
+ var switchCase = new ShidSwitch.Case(
whenCase.caseType().value(),
caseBodyInstructions,
whenCase.source()
@@ -684,7 +684,7 @@ public class StackCompiler {
switchCases.add(switchCase);
}
- context = context.addInstruction(new SwitchInstruction(
+ context = context.addInstruction(new ShidSwitch(
switchCases,
node.source()
));
@@ -701,23 +701,23 @@ public class StackCompiler {
context = context.enterBlock(List.of());
context = compileExpression(node.condition(), context);
- context = context.addInstruction(new IfInstruction(
+ context = context.addInstruction(new ShidIf(
0,
List.of(),
List.of(
- new LoopBreakInstruction(node.source())
+ new ShidLoopBreak(node.source())
),
node.source()
));
context = context.addInstructions(ifTrueInstructions);
- context = context.addInstruction(new LoopContinueInstruction(node.source()));
+ context = context.addInstruction(new ShidLoopContinue(node.source()));
var bodyInstructions = context.instructions;
context = context.exitBlock();
- context = context.addInstruction(new LoopInstruction(bodyInstructions, node.source()));
+ context = context.addInstruction(new ShidLoop(bodyInstructions, node.source()));
return context;
}
@@ -731,15 +731,15 @@ public class StackCompiler {
P.map()
);
- private final PStack<PVector<Instruction>> instructionsStack;
- private final PVector<Instruction> instructions;
+ private final PStack<PVector<ShidInstruction>> instructionsStack;
+ private final PVector<ShidInstruction> instructions;
private final PSet<String> localNames;
private final PStack<PMap<String, ShedVariable>> shedVariablesByNameStack;
private final PMap<String, ShedVariable> shedVariablesByName;
private Context(
- PStack<PVector<Instruction>> instructionsStack,
- PVector<Instruction> instructions,
+ PStack<PVector<ShidInstruction>> instructionsStack,
+ PVector<ShidInstruction> instructions,
PSet<String> localNames,
PStack<PMap<String, ShedVariable>> shedVariablesByNameStack,
PMap<String, ShedVariable> shedVariablesByName
@@ -777,7 +777,7 @@ public class StackCompiler {
);
}
- private Context addInstruction(Instruction instruction) {
+ private Context addInstruction(ShidInstruction instruction) {
return new Context(
this.instructionsStack,
this.instructions.plus(instruction),
@@ -787,7 +787,7 @@ public class StackCompiler {
);
}
- public Context addInstructions(PVector<Instruction> instructions) {
+ public Context addInstructions(PVector<ShidInstruction> instructions) {
return new Context(
this.instructionsStack,
this.instructions.plusAll(instructions),
@@ -798,7 +798,7 @@ public class StackCompiler {
}
public String shedVariableToLocal(String variableName) {
- return shedVariable(variableName).stackIrLocalName;
+ return shedVariable(variableName).shidLocalName;
}
public ShedVariable shedVariable(String variableName) {
@@ -839,10 +839,10 @@ public class StackCompiler {
}
}
- public List<Instruction> instructions() {
+ public List<ShidInstruction> instructions() {
return this.instructions;
}
}
- private record ShedVariable(String stackIrLocalName, boolean isVar) {}
+ private record ShedVariable(String shidLocalName, boolean isVar) {}
}
diff --git a/src/main/java/org/shedlang/compiler/shid/ShidNamespace.java b/src/main/java/org/shedlang/compiler/shid/ShidNamespace.java
new file mode 100644
index 00000000..4c5f134f
--- /dev/null
+++ b/src/main/java/org/shedlang/compiler/shid/ShidNamespace.java
@@ -0,0 +1,12 @@
+package org.shedlang.compiler.shid;
+
+import org.shedlang.compiler.shid.instructions.ShidInstruction;
+import org.shedlang.compiler.types.NamespaceName;
+
+import java.util.List;
+
+public record ShidNamespace(
+ NamespaceName namespaceName,
+ List<ShidInstruction> instructions
+) {
+}
diff --git a/src/main/java/org/shedlang/compiler/stackir/instructions/CallInstruction.java b/src/main/java/org/shedlang/compiler/shid/instructions/ShidCall.java
index a84c4af1..bb720696 100644
--- a/src/main/java/org/shedlang/compiler/stackir/instructions/CallInstruction.java
+++ b/src/main/java/org/shedlang/compiler/shid/instructions/ShidCall.java
@@ -1,4 +1,4 @@
-package org.shedlang.compiler.stackir.instructions;
+package org.shedlang.compiler.shid.instructions;
import org.shedlang.compiler.sources.Source;
@@ -17,9 +17,9 @@ import java.util.List;
* <li>The named arguments, in the same order as <code>namedArgNames</code>.</li>
* </ul>
*/
-public record CallInstruction(
+public record ShidCall(
int positionalArgCount,
List<String> namedArgNames,
Source source
-) implements Instruction {
+) implements ShidInstruction {
}
diff --git a/src/main/java/org/shedlang/compiler/stackir/instructions/DefineEffectInstruction.java b/src/main/java/org/shedlang/compiler/shid/instructions/ShidDefineEffect.java
index d87a6412..cbd24307 100644
--- a/src/main/java/org/shedlang/compiler/stackir/instructions/DefineEffectInstruction.java
+++ b/src/main/java/org/shedlang/compiler/shid/instructions/ShidDefineEffect.java
@@ -1,4 +1,4 @@
-package org.shedlang.compiler.stackir.instructions;
+package org.shedlang.compiler.shid.instructions;
import org.shedlang.compiler.sources.Source;
import org.shedlang.compiler.types.UserDefinedEffect;
@@ -7,8 +7,8 @@ import org.shedlang.compiler.types.UserDefinedEffect;
* Push an effect value onto the temporary value stack with the given
* definition.
*/
-public record DefineEffectInstruction(
+public record ShidDefineEffect(
UserDefinedEffect effect,
Source source
-) implements Instruction {
+) implements ShidInstruction {
}
diff --git a/src/main/java/org/shedlang/compiler/stackir/instructions/DefineFunctionInstruction.java b/src/main/java/org/shedlang/compiler/shid/instructions/ShidDefineFunction.java
index 6ca40775..16561049 100644
--- a/src/main/java/org/shedlang/compiler/stackir/instructions/DefineFunctionInstruction.java
+++ b/src/main/java/org/shedlang/compiler/shid/instructions/ShidDefineFunction.java
@@ -1,4 +1,4 @@
-package org.shedlang.compiler.stackir.instructions;
+package org.shedlang.compiler.shid.instructions;
import org.pcollections.PVector;
import org.shedlang.compiler.ast.typed.FreeVariables;
@@ -12,14 +12,14 @@ import java.util.List;
* Push a function value onto the temporary value stack with the given
* definition.
*/
-public record DefineFunctionInstruction(
+public record ShidDefineFunction(
String name,
List<Param> positionalParams,
List<Param> namedParams,
FreeVariables freeVariables,
- List<Instruction> body,
+ List<ShidInstruction> body,
Source source
-) implements Instruction {
+) implements ShidInstruction {
public record Param(String name, Source source) {
}
@@ -39,10 +39,10 @@ public record DefineFunctionInstruction(
PVector<Param> positionalParams,
PVector<Param> namedParams,
FreeVariables.Builder freeVariables,
- PVector<Instruction> body
+ PVector<ShidInstruction> body
) {
- public DefineFunctionInstruction build() {
- return new DefineFunctionInstruction(
+ public ShidDefineFunction build() {
+ return new ShidDefineFunction(
name,
positionalParams,
namedParams,
@@ -92,7 +92,7 @@ public record DefineFunctionInstruction(
);
}
- public Builder addBodyInstruction(Instruction instruction) {
+ public Builder addBodyInstruction(ShidInstruction instruction) {
return new Builder(
this.name,
this.positionalParams,
diff --git a/src/main/java/org/shedlang/compiler/stackir/instructions/DefineStructInstruction.java b/src/main/java/org/shedlang/compiler/shid/instructions/ShidDefineStruct.java
index 098c9245..82d165e6 100644
--- a/src/main/java/org/shedlang/compiler/stackir/instructions/DefineStructInstruction.java
+++ b/src/main/java/org/shedlang/compiler/shid/instructions/ShidDefineStruct.java
@@ -1,4 +1,4 @@
-package org.shedlang.compiler.stackir.instructions;
+package org.shedlang.compiler.shid.instructions;
import org.shedlang.compiler.sources.Source;
import org.shedlang.compiler.types.StructType;
@@ -9,12 +9,12 @@ import java.util.List;
* Push a struct type value onto the temporary value stack with the given
* definition.
*/
-public record DefineStructInstruction(
+public record ShidDefineStruct(
StructType type,
// TODO: remove fields? We should have fields from the type info.
List<Field> fields,
Source source
-) implements Instruction {
+) implements ShidInstruction {
public record Field(String name, Source source) {
}
diff --git a/src/main/java/org/shedlang/compiler/shid/instructions/ShidDiscard.java b/src/main/java/org/shedlang/compiler/shid/instructions/ShidDiscard.java
new file mode 100644
index 00000000..ac5940d2
--- /dev/null
+++ b/src/main/java/org/shedlang/compiler/shid/instructions/ShidDiscard.java
@@ -0,0 +1,9 @@
+package org.shedlang.compiler.shid.instructions;
+
+import org.shedlang.compiler.sources.Source;
+
+/**
+ * Pop a value from the temporary value stack and discard it.
+ */
+public record ShidDiscard(Source source) implements ShidInstruction {
+}
diff --git a/src/main/java/org/shedlang/compiler/shid/instructions/ShidDuplicate.java b/src/main/java/org/shedlang/compiler/shid/instructions/ShidDuplicate.java
new file mode 100644
index 00000000..29714cd3
--- /dev/null
+++ b/src/main/java/org/shedlang/compiler/shid/instructions/ShidDuplicate.java
@@ -0,0 +1,9 @@
+package org.shedlang.compiler.shid.instructions;
+
+import org.shedlang.compiler.sources.Source;
+
+/**
+ * Duplicates the value on top of the temporary value stack.
+ */
+public record ShidDuplicate(Source source) implements ShidInstruction {
+}
diff --git a/src/main/java/org/shedlang/compiler/stackir/instructions/FieldLoadInstruction.java b/src/main/java/org/shedlang/compiler/shid/instructions/ShidFieldLoad.java
index 53dc1ee8..0df10550 100644
--- a/src/main/java/org/shedlang/compiler/stackir/instructions/FieldLoadInstruction.java
+++ b/src/main/java/org/shedlang/compiler/shid/instructions/ShidFieldLoad.java
@@ -1,4 +1,4 @@
-package org.shedlang.compiler.stackir.instructions;
+package org.shedlang.compiler.shid.instructions;
import org.shedlang.compiler.sources.Source;
import org.shedlang.compiler.types.NamespaceName;
@@ -9,11 +9,11 @@ import org.shedlang.compiler.types.UserDefinedEffect;
* Pop a value from the temporary value stack, get the given field from the
* popped value, and push the field's value onto the temporary value stack.
*/
-public record FieldLoadInstruction(
+public record ShidFieldLoad(
Receiver receiver,
String fieldName,
Source source
-) implements Instruction {
+) implements ShidInstruction {
public sealed interface Receiver {
record Effect(UserDefinedEffect effect) implements Receiver {}
record Namespace(NamespaceName name) implements Receiver {}
diff --git a/src/main/java/org/shedlang/compiler/stackir/instructions/IfInstruction.java b/src/main/java/org/shedlang/compiler/shid/instructions/ShidIf.java
index a6636b91..408ccbef 100644
--- a/src/main/java/org/shedlang/compiler/stackir/instructions/IfInstruction.java
+++ b/src/main/java/org/shedlang/compiler/shid/instructions/ShidIf.java
@@ -1,4 +1,4 @@
-package org.shedlang.compiler.stackir.instructions;
+package org.shedlang.compiler.shid.instructions;
import org.shedlang.compiler.sources.Source;
@@ -13,10 +13,10 @@ import java.util.List;
* Each branch body should push <code>resultCount</code> values onto the
* temporary value stack.
*/
-public record IfInstruction(
+public record ShidIf(
int resultCount,
- List<Instruction> trueBody,
- List<Instruction> falseBody,
+ List<ShidInstruction> trueBody,
+ List<ShidInstruction> falseBody,
Source source
-) implements Instruction {
+) implements ShidInstruction {
}
diff --git a/src/main/java/org/shedlang/compiler/shid/instructions/ShidInstruction.java b/src/main/java/org/shedlang/compiler/shid/instructions/ShidInstruction.java
new file mode 100644
index 00000000..308fe739
--- /dev/null
+++ b/src/main/java/org/shedlang/compiler/shid/instructions/ShidInstruction.java
@@ -0,0 +1,9 @@
+package org.shedlang.compiler.shid.instructions;
+
+import org.shedlang.compiler.sources.Source;
+
+public sealed interface ShidInstruction
+ permits ShidCall, ShidDefineEffect, ShidDefineFunction, ShidDefineStruct, ShidDiscard, ShidDuplicate, ShidFieldLoad, ShidIf, ShidIntAdd, ShidIntEquals, ShidIntNotEqual, ShidIntSub, ShidLocalLoad, ShidLocalStore, ShidLoop, ShidLoopBreak, ShidLoopContinue, ShidNamespaceFieldStore, ShidNamespaceImport, ShidPushBool, ShidPushInt, ShidPushString, ShidPushUnit, ShidResume, ShidReturn, ShidStringAdd, ShidSwitch, ShidTry, ShidTupleCreate, ShidTupleGet, ShidVarLoad, ShidVarStore {
+
+ Source source();
+}
diff --git a/src/main/java/org/shedlang/compiler/stackir/instructions/IntAddInstruction.java b/src/main/java/org/shedlang/compiler/shid/instructions/ShidIntAdd.java
index 55a4fb1c..ed570cef 100644
--- a/src/main/java/org/shedlang/compiler/stackir/instructions/IntAddInstruction.java
+++ b/src/main/java/org/shedlang/compiler/shid/instructions/ShidIntAdd.java
@@ -1,4 +1,4 @@
-package org.shedlang.compiler.stackir.instructions;
+package org.shedlang.compiler.shid.instructions;
import org.shedlang.compiler.sources.Source;
@@ -6,5 +6,5 @@ import org.shedlang.compiler.sources.Source;
* Pop two values from the temporary value stack, assumed to be Ints, add them
* together, and push the result onto the temporary value stack.
*/
-public record IntAddInstruction(Source source) implements Instruction {
+public record ShidIntAdd(Source source) implements ShidInstruction {
}
diff --git a/src/main/java/org/shedlang/compiler/stackir/instructions/IntEqualsInstruction.java b/src/main/java/org/shedlang/compiler/shid/instructions/ShidIntEquals.java
index 7f0c97cf..f5543143 100644
--- a/src/main/java/org/shedlang/compiler/stackir/instructions/IntEqualsInstruction.java
+++ b/src/main/java/org/shedlang/compiler/shid/instructions/ShidIntEquals.java
@@ -1,4 +1,4 @@
-package org.shedlang.compiler.stackir.instructions;
+package org.shedlang.compiler.shid.instructions;
import org.shedlang.compiler.sources.Source;
@@ -6,5 +6,5 @@ import org.shedlang.compiler.sources.Source;
* Pop two values from the temporary value stack, compare them as Ints, and push
* a Bool onto the temporary value stack: true if equal, false if not equal.
*/
-public record IntEqualsInstruction(Source source) implements Instruction {
+public record ShidIntEquals(Source source) implements ShidInstruction {
}
diff --git a/src/main/java/org/shedlang/compiler/stackir/instructions/IntNotEqualInstruction.java b/src/main/java/org/shedlang/compiler/shid/instructions/ShidIntNotEqual.java
index 6b155f67..60eea7c5 100644
--- a/src/main/java/org/shedlang/compiler/stackir/instructions/IntNotEqualInstruction.java
+++ b/src/main/java/org/shedlang/compiler/shid/instructions/ShidIntNotEqual.java
@@ -1,4 +1,4 @@
-package org.shedlang.compiler.stackir.instructions;
+package org.shedlang.compiler.shid.instructions;
import org.shedlang.compiler.sources.Source;
@@ -6,5 +6,5 @@ import org.shedlang.compiler.sources.Source;
* Pop two values from the temporary value stack, compare them as Ints, and push
* a Bool onto the temporary value stack: true if not equal, false if equal.
*/
-public record IntNotEqualInstruction(Source source) implements Instruction {
+public record ShidIntNotEqual(Source source) implements ShidInstruction {
}
diff --git a/src/main/java/org/shedlang/compiler/stackir/instructions/IntSubInstruction.java b/src/main/java/org/shedlang/compiler/shid/instructions/ShidIntSub.java
index e2fa09b6..3fbd3e09 100644
--- a/src/main/java/org/shedlang/compiler/stackir/instructions/IntSubInstruction.java
+++ b/src/main/java/org/shedlang/compiler/shid/instructions/ShidIntSub.java
@@ -1,4 +1,4 @@
-package org.shedlang.compiler.stackir.instructions;
+package org.shedlang.compiler.shid.instructions;
import org.shedlang.compiler.sources.Source;
@@ -7,5 +7,5 @@ import org.shedlang.compiler.sources.Source;
* from the temporary value stack, calculate the left operand minus the right
* operand, then push the result onto the temporary value stack.
*/
-public record IntSubInstruction(Source source) implements Instruction {
+public record ShidIntSub(Source source) implements ShidInstruction {
}
diff --git a/src/main/java/org/shedlang/compiler/stackir/instructions/LocalLoadInstruction.java b/src/main/java/org/shedlang/compiler/shid/instructions/ShidLocalLoad.java
index d0753609..a1de23fe 100644
--- a/src/main/java/org/shedlang/compiler/stackir/instructions/LocalLoadInstruction.java
+++ b/src/main/java/org/shedlang/compiler/shid/instructions/ShidLocalLoad.java
@@ -1,4 +1,4 @@
-package org.shedlang.compiler.stackir.instructions;
+package org.shedlang.compiler.shid.instructions;
import org.shedlang.compiler.sources.Source;
@@ -6,5 +6,5 @@ import org.shedlang.compiler.sources.Source;
* Load the local with the given name and push it onto the temporary value
* stack.
*/
-public record LocalLoadInstruction(String name, Source source) implements Instruction {
+public record ShidLocalLoad(String name, Source source) implements ShidInstruction {
}
diff --git a/src/main/java/org/shedlang/compiler/stackir/instructions/LocalStoreInstruction.java b/src/main/java/org/shedlang/compiler/shid/instructions/ShidLocalStore.java
index 880c91f8..003aaf40 100644
--- a/src/main/java/org/shedlang/compiler/stackir/instructions/LocalStoreInstruction.java
+++ b/src/main/java/org/shedlang/compiler/shid/instructions/ShidLocalStore.java
@@ -1,4 +1,4 @@
-package org.shedlang.compiler.stackir.instructions;
+package org.shedlang.compiler.shid.instructions;
import org.shedlang.compiler.sources.Source;
@@ -6,5 +6,5 @@ import org.shedlang.compiler.sources.Source;
* Pop a value from the temporary value stack and store it as the local with the
* given name.
*/
-public record LocalStoreInstruction(String name, Source source) implements Instruction {
+public record ShidLocalStore(String name, Source source) implements ShidInstruction {
}
diff --git a/src/main/java/org/shedlang/compiler/stackir/instructions/LoopInstruction.java b/src/main/java/org/shedlang/compiler/shid/instructions/ShidLoop.java
index 119d9a52..bfa7a1fa 100644
--- a/src/main/java/org/shedlang/compiler/stackir/instructions/LoopInstruction.java
+++ b/src/main/java/org/shedlang/compiler/shid/instructions/ShidLoop.java
@@ -1,4 +1,4 @@
-package org.shedlang.compiler.stackir.instructions;
+package org.shedlang.compiler.shid.instructions;
import org.shedlang.compiler.sources.Source;
@@ -10,8 +10,8 @@ import java.util.List;
* start of the body. The <code>break</code> instruction can jump to the end of
* the body.
*/
-public record LoopInstruction(
- List<Instruction> body,
+public record ShidLoop(
+ List<ShidInstruction> body,
Source source
-) implements Instruction {
+) implements ShidInstruction {
}
diff --git a/src/main/java/org/shedlang/compiler/stackir/instructions/LoopBreakInstruction.java b/src/main/java/org/shedlang/compiler/shid/instructions/ShidLoopBreak.java
index 60a1d056..6e2e70d7 100644
--- a/src/main/java/org/shedlang/compiler/stackir/instructions/LoopBreakInstruction.java
+++ b/src/main/java/org/shedlang/compiler/shid/instructions/ShidLoopBreak.java
@@ -1,9 +1,9 @@
-package org.shedlang.compiler.stackir.instructions;
+package org.shedlang.compiler.shid.instructions;
import org.shedlang.compiler.sources.Source;
/**
* Jump to the end of the enclosing <code>loop</code> instruction's body.
*/
-public record LoopBreakInstruction(Source source) implements Instruction {
+public record ShidLoopBreak(Source source) implements ShidInstruction {
}
diff --git a/src/main/java/org/shedlang/compiler/stackir/instructions/LoopContinueInstruction.java b/src/main/java/org/shedlang/compiler/shid/instructions/ShidLoopContinue.java
index d7111ea9..d6ee6c3d 100644
--- a/src/main/java/org/shedlang/compiler/stackir/instructions/LoopContinueInstruction.java
+++ b/src/main/java/org/shedlang/compiler/shid/instructions/ShidLoopContinue.java
@@ -1,9 +1,9 @@
-package org.shedlang.compiler.stackir.instructions;
+package org.shedlang.compiler.shid.instructions;
import org.shedlang.compiler.sources.Source;
/**
* Jump to the start of the enclosing <code>loop</code> instruction's body.
*/
-public record LoopContinueInstruction(Source source) implements Instruction {
+public record ShidLoopContinue(Source source) implements ShidInstruction {
}
diff --git a/src/main/java/org/shedlang/compiler/stackir/instructions/NamespaceFieldStoreInstruction.java b/src/main/java/org/shedlang/compiler/shid/instructions/ShidNamespaceFieldStore.java
index b83964a1..583dbb5f 100644
--- a/src/main/java/org/shedlang/compiler/stackir/instructions/NamespaceFieldStoreInstruction.java
+++ b/src/main/java/org/shedlang/compiler/shid/instructions/ShidNamespaceFieldStore.java
@@ -1,4 +1,4 @@
-package org.shedlang.compiler.stackir.instructions;
+package org.shedlang.compiler.shid.instructions;
import org.shedlang.compiler.sources.Source;
import org.shedlang.compiler.types.NamespaceName;
@@ -7,9 +7,9 @@ import org.shedlang.compiler.types.NamespaceName;
* Pop a value from the temporary value stack and store it as the field with the
* given name on the given namespace.
*/
-public record NamespaceFieldStoreInstruction(
+public record ShidNamespaceFieldStore(
NamespaceName namespaceName,
String fieldName,
Source source
-) implements Instruction {
+) implements ShidInstruction {
}
diff --git a/src/main/java/org/shedlang/compiler/stackir/instructions/NamespaceImportInstruction.java b/src/main/java/org/shedlang/compiler/shid/instructions/ShidNamespaceImport.java
index cc600d5b..9e93a95f 100644
--- a/src/main/java/org/shedlang/compiler/stackir/instructions/NamespaceImportInstruction.java
+++ b/src/main/java/org/shedlang/compiler/shid/instructions/ShidNamespaceImport.java
@@ -1,4 +1,4 @@
-package org.shedlang.compiler.stackir.instructions;
+package org.shedlang.compiler.shid.instructions;
import org.shedlang.compiler.sources.Source;
import org.shedlang.compiler.types.NamespaceName;
@@ -6,8 +6,8 @@ import org.shedlang.compiler.types.NamespaceName;
/**
* Import the given namespace and push it onto the temporary value stack.
*/
-public record NamespaceImportInstruction(
+public record ShidNamespaceImport(
NamespaceName namespaceName,
Source source
-) implements Instruction {
+) implements ShidInstruction {
}
diff --git a/src/main/java/org/shedlang/compiler/stackir/instructions/PushBoolInstruction.java b/src/main/java/org/shedlang/compiler/shid/instructions/ShidPushBool.java
index c732a390..c92e8959 100644
--- a/src/main/java/org/shedlang/compiler/stackir/instructions/PushBoolInstruction.java
+++ b/src/main/java/org/shedlang/compiler/shid/instructions/ShidPushBool.java
@@ -1,12 +1,12 @@
-package org.shedlang.compiler.stackir.instructions;
+package org.shedlang.compiler.shid.instructions;
import org.shedlang.compiler.sources.Source;
/**
* Push a boolean onto the temporary value stack.
*/
-public record PushBoolInstruction(
+public record ShidPushBool(
boolean value,
Source source
-) implements Instruction {
+) implements ShidInstruction {
}
diff --git a/src/main/java/org/shedlang/compiler/shid/instructions/ShidPushInt.java b/src/main/java/org/shedlang/compiler/shid/instructions/ShidPushInt.java
new file mode 100644
index 00000000..e4673e9b
--- /dev/null
+++ b/src/main/java/org/shedlang/compiler/shid/instructions/ShidPushInt.java
@@ -0,0 +1,11 @@
+package org.shedlang.compiler.shid.instructions;
+
+import org.shedlang.compiler.sources.Source;
+
+import java.math.BigInteger;
+
+/**
+ * Push an integer onto the temporary value stack.
+ */
+public record ShidPushInt(BigInteger value, Source source) implements ShidInstruction {
+}
diff --git a/src/main/java/org/shedlang/compiler/shid/instructions/ShidPushString.java b/src/main/java/org/shedlang/compiler/shid/instructions/ShidPushString.java
new file mode 100644
index 00000000..b0fa0183
--- /dev/null
+++ b/src/main/java/org/shedlang/compiler/shid/instructions/ShidPushString.java
@@ -0,0 +1,9 @@
+package org.shedlang.compiler.shid.instructions;
+
+import org.shedlang.compiler.sources.Source;
+
+/**
+ * Push a string onto the temporary value stack.
+ */
+public record ShidPushString(String value, Source source) implements ShidInstruction {
+}
diff --git a/src/main/java/org/shedlang/compiler/shid/instructions/ShidPushUnit.java b/src/main/java/org/shedlang/compiler/shid/instructions/ShidPushUnit.java
new file mode 100644
index 00000000..85e5363e
--- /dev/null
+++ b/src/main/java/org/shedlang/compiler/shid/instructions/ShidPushUnit.java
@@ -0,0 +1,9 @@
+package org.shedlang.compiler.shid.instructions;
+
+import org.shedlang.compiler.sources.Source;
+
+/**
+ * Push the unit value onto the temporary value stack.
+ */
+public record ShidPushUnit(Source source) implements ShidInstruction {
+}
diff --git a/src/main/java/org/shedlang/compiler/stackir/instructions/ResumeInstruction.java b/src/main/java/org/shedlang/compiler/shid/instructions/ShidResume.java
index 836b5bac..12eaac48 100644
--- a/src/main/java/org/shedlang/compiler/stackir/instructions/ResumeInstruction.java
+++ b/src/main/java/org/shedlang/compiler/shid/instructions/ShidResume.java
@@ -1,4 +1,4 @@
-package org.shedlang.compiler.stackir.instructions;
+package org.shedlang.compiler.shid.instructions;
import org.shedlang.compiler.sources.Source;
@@ -6,5 +6,5 @@ import org.shedlang.compiler.sources.Source;
* Pop a value from the temporary value stack and return with that value from
* the current effect handler method back to the effect call.
*/
-public record ResumeInstruction(Source source) implements Instruction {
+public record ShidResume(Source source) implements ShidInstruction {
}
diff --git a/src/main/java/org/shedlang/compiler/stackir/instructions/ReturnInstruction.java b/src/main/java/org/shedlang/compiler/shid/instructions/ShidReturn.java
index 1b9e4213..fd0228fe 100644
--- a/src/main/java/org/shedlang/compiler/stackir/instructions/ReturnInstruction.java
+++ b/src/main/java/org/shedlang/compiler/shid/instructions/ShidReturn.java
@@ -1,4 +1,4 @@
-package org.shedlang.compiler.stackir.instructions;
+package org.shedlang.compiler.shid.instructions;
import org.shedlang.compiler.sources.Source;
@@ -6,5 +6,5 @@ import org.shedlang.compiler.sources.Source;
* Pop a value from the temporary value stack and return with that value from
* the current function.
*/
-public record ReturnInstruction(Source source) implements Instruction {
+public record ShidReturn(Source source) implements ShidInstruction {
}
diff --git a/src/main/java/org/shedlang/compiler/stackir/instructions/StringAddInstruction.java b/src/main/java/org/shedlang/compiler/shid/instructions/ShidStringAdd.java
index 5114beff..fea26d1e 100644
--- a/src/main/java/org/shedlang/compiler/stackir/instructions/StringAddInstruction.java
+++ b/src/main/java/org/shedlang/compiler/shid/instructions/ShidStringAdd.java
@@ -1,4 +1,4 @@
-package org.shedlang.compiler.stackir.instructions;
+package org.shedlang.compiler.shid.instructions;
import org.shedlang.compiler.sources.Source;
@@ -8,5 +8,5 @@ import org.shedlang.compiler.sources.Source;
* the left and right operands, then push the result onto the temporary value
* stack.
*/
-public record StringAddInstruction(Source source) implements Instruction {
+public record ShidStringAdd(Source source) implements ShidInstruction {
}
diff --git a/src/main/java/org/shedlang/compiler/stackir/instructions/SwitchInstruction.java b/src/main/java/org/shedlang/compiler/shid/instructions/ShidSwitch.java
index 880349de..00126f3c 100644
--- a/src/main/java/org/shedlang/compiler/stackir/instructions/SwitchInstruction.java
+++ b/src/main/java/org/shedlang/compiler/shid/instructions/ShidSwitch.java
@@ -1,4 +1,4 @@
-package org.shedlang.compiler.stackir.instructions;
+package org.shedlang.compiler.shid.instructions;
import org.shedlang.compiler.sources.Source;
import org.shedlang.compiler.types.StructType;
@@ -12,10 +12,10 @@ import java.util.List;
* <p>
* Each case body should push exactly one value onto the temporary value stack.
*/
-public record SwitchInstruction(
+public record ShidSwitch(
List<Case> cases,
Source source
-) implements Instruction {
- public record Case(StructType caseType, List<Instruction> body, Source source) {
+) implements ShidInstruction {
+ public record Case(StructType caseType, List<ShidInstruction> body, Source source) {
}
}
diff --git a/src/main/java/org/shedlang/compiler/stackir/instructions/TryInstruction.java b/src/main/java/org/shedlang/compiler/shid/instructions/ShidTry.java
index 0b5051df..ef763eda 100644
--- a/src/main/java/org/shedlang/compiler/stackir/instructions/TryInstruction.java
+++ b/src/main/java/org/shedlang/compiler/shid/instructions/ShidTry.java
@@ -1,4 +1,4 @@
-package org.shedlang.compiler.stackir.instructions;
+package org.shedlang.compiler.shid.instructions;
import org.shedlang.compiler.sources.Source;
@@ -17,10 +17,10 @@ import java.util.List;
* If the body runs to completion, it should leave a single value on the
* temporary value stack.
*/
-public record TryInstruction(
+public record ShidTry(
UserDefinedEffect handledEffect,
List<String> handlerMethodNames,
- List<Instruction> body,
+ List<ShidInstruction> body,
Source source
-) implements Instruction {
+) implements ShidInstruction {
}
diff --git a/src/main/java/org/shedlang/compiler/stackir/instructions/TupleCreateInstruction.java b/src/main/java/org/shedlang/compiler/shid/instructions/ShidTupleCreate.java
index fa331d1c..3559be91 100644
--- a/src/main/java/org/shedlang/compiler/stackir/instructions/TupleCreateInstruction.java
+++ b/src/main/java/org/shedlang/compiler/shid/instructions/ShidTupleCreate.java
@@ -1,4 +1,4 @@
-package org.shedlang.compiler.stackir.instructions;
+package org.shedlang.compiler.shid.instructions;
import org.shedlang.compiler.sources.Source;
@@ -7,8 +7,8 @@ import org.shedlang.compiler.sources.Source;
* tuple from those elements, and push the tuple onto the temporary value stack.
* Elements should have been pushed onto the stack in index order.
*/
-public record TupleCreateInstruction(
+public record ShidTupleCreate(
int elementCount,
Source source
-) implements Instruction {
+) implements ShidInstruction {
}
diff --git a/src/main/java/org/shedlang/compiler/stackir/instructions/TupleGetInstruction.java b/src/main/java/org/shedlang/compiler/shid/instructions/ShidTupleGet.java
index ed52cc29..a8a12b1d 100644
--- a/src/main/java/org/shedlang/compiler/stackir/instructions/TupleGetInstruction.java
+++ b/src/main/java/org/shedlang/compiler/shid/instructions/ShidTupleGet.java
@@ -1,4 +1,4 @@
-package org.shedlang.compiler.stackir.instructions;
+package org.shedlang.compiler.shid.instructions;
import org.shedlang.compiler.sources.Source;
@@ -6,9 +6,9 @@ import org.shedlang.compiler.sources.Source;
* Pop a tuple from the temporary value stack, get the element at the given
* index, and push it onto the temporary value stack.
*/
-public record TupleGetInstruction(
+public record ShidTupleGet(
int elementIndex,
int elementCount,
Source source
-) implements Instruction {
+) implements ShidInstruction {
}
diff --git a/src/main/java/org/shedlang/compiler/stackir/instructions/VarLoadInstruction.java b/src/main/java/org/shedlang/compiler/shid/instructions/ShidVarLoad.java
index fe35db14..ad0ae2ca 100644
--- a/src/main/java/org/shedlang/compiler/stackir/instructions/VarLoadInstruction.java
+++ b/src/main/java/org/shedlang/compiler/shid/instructions/ShidVarLoad.java
@@ -1,4 +1,4 @@
-package org.shedlang.compiler.stackir.instructions;
+package org.shedlang.compiler.shid.instructions;
import org.shedlang.compiler.sources.Source;
@@ -6,5 +6,5 @@ import org.shedlang.compiler.sources.Source;
* Load the value stored in the var with the given name and push it onto the
* temporary value stack.
*/
-public record VarLoadInstruction(String name, Source source) implements Instruction {
+public record ShidVarLoad(String name, Source source) implements ShidInstruction {
}
diff --git a/src/main/java/org/shedlang/compiler/stackir/instructions/VarStoreInstruction.java b/src/main/java/org/shedlang/compiler/shid/instructions/ShidVarStore.java
index 33a3ab45..f9d2fb51 100644
--- a/src/main/java/org/shedlang/compiler/stackir/instructions/VarStoreInstruction.java
+++ b/src/main/java/org/shedlang/compiler/shid/instructions/ShidVarStore.java
@@ -1,4 +1,4 @@
-package org.shedlang.compiler.stackir.instructions;
+package org.shedlang.compiler.shid.instructions;
import org.shedlang.compiler.sources.Source;
@@ -6,5 +6,5 @@ import org.shedlang.compiler.sources.Source;
* Pop a value from the temporary value stack and store it in the var with the
* given name.
*/
-public record VarStoreInstruction(String name, Source source) implements Instruction {
+public record ShidVarStore(String name, Source source) implements ShidInstruction {
}
diff --git a/src/main/java/org/shedlang/compiler/stackir/StackIrNamespace.java b/src/main/java/org/shedlang/compiler/stackir/StackIrNamespace.java
deleted file mode 100644
index 65fd41d3..00000000
--- a/src/main/java/org/shedlang/compiler/stackir/StackIrNamespace.java
+++ /dev/null
@@ -1,12 +0,0 @@
-package org.shedlang.compiler.stackir;
-
-import org.shedlang.compiler.stackir.instructions.Instruction;
-import org.shedlang.compiler.types.NamespaceName;
-
-import java.util.List;
-
-public record StackIrNamespace(
- NamespaceName namespaceName,
- List<Instruction> instructions
-) {
-}
diff --git a/src/main/java/org/shedlang/compiler/stackir/instructions/DiscardInstruction.java b/src/main/java/org/shedlang/compiler/stackir/instructions/DiscardInstruction.java
deleted file mode 100644
index 503ecc53..00000000
--- a/src/main/java/org/shedlang/compiler/stackir/instructions/DiscardInstruction.java
+++ /dev/null
@@ -1,9 +0,0 @@
-package org.shedlang.compiler.stackir.instructions;
-
-import org.shedlang.compiler.sources.Source;
-
-/**
- * Pop a value from the temporary value stack and discard it.
- */
-public record DiscardInstruction(Source source) implements Instruction {
-}
diff --git a/src/main/java/org/shedlang/compiler/stackir/instructions/DuplicateInstruction.java b/src/main/java/org/shedlang/compiler/stackir/instructions/DuplicateInstruction.java
deleted file mode 100644
index 03685e54..00000000
--- a/src/main/java/org/shedlang/compiler/stackir/instructions/DuplicateInstruction.java
+++ /dev/null
@@ -1,9 +0,0 @@
-package org.shedlang.compiler.stackir.instructions;
-
-import org.shedlang.compiler.sources.Source;
-
-/**
- * Duplicates the value on top of the temporary value stack.
- */
-public record DuplicateInstruction(Source source) implements Instruction {
-}
diff --git a/src/main/java/org/shedlang/compiler/stackir/instructions/Instruction.java b/src/main/java/org/shedlang/compiler/stackir/instructions/Instruction.java
deleted file mode 100644
index f84de210..00000000
--- a/src/main/java/org/shedlang/compiler/stackir/instructions/Instruction.java
+++ /dev/null
@@ -1,9 +0,0 @@
-package org.shedlang.compiler.stackir.instructions;
-
-import org.shedlang.compiler.sources.Source;
-
-public sealed interface Instruction
- permits CallInstruction, DefineEffectInstruction, DefineFunctionInstruction, DefineStructInstruction, DiscardInstruction, DuplicateInstruction, FieldLoadInstruction, IfInstruction, IntAddInstruction, IntEqualsInstruction, IntNotEqualInstruction, IntSubInstruction, LocalLoadInstruction, LocalStoreInstruction, LoopBreakInstruction, LoopContinueInstruction, LoopInstruction, NamespaceFieldStoreInstruction, NamespaceImportInstruction, PushBoolInstruction, PushIntInstruction, PushStringInstruction, PushUnitInstruction, ResumeInstruction, ReturnInstruction, StringAddInstruction, SwitchInstruction, TryInstruction, TupleCreateInstruction, TupleGetInstruction, VarLoadInstruction, VarStoreInstruction {
-
- Source source();
-}
diff --git a/src/main/java/org/shedlang/compiler/stackir/instructions/PushIntInstruction.java b/src/main/java/org/shedlang/compiler/stackir/instructions/PushIntInstruction.java
deleted file mode 100644
index cba3f217..00000000
--- a/src/main/java/org/shedlang/compiler/stackir/instructions/PushIntInstruction.java
+++ /dev/null
@@ -1,11 +0,0 @@
-package org.shedlang.compiler.stackir.instructions;
-
-import org.shedlang.compiler.sources.Source;
-
-import java.math.BigInteger;
-
-/**
- * Push an integer onto the temporary value stack.
- */
-public record PushIntInstruction(BigInteger value, Source source) implements Instruction {
-}
diff --git a/src/main/java/org/shedlang/compiler/stackir/instructions/PushStringInstruction.java b/src/main/java/org/shedlang/compiler/stackir/instructions/PushStringInstruction.java
deleted file mode 100644
index e33051e5..00000000
--- a/src/main/java/org/shedlang/compiler/stackir/instructions/PushStringInstruction.java
+++ /dev/null
@@ -1,9 +0,0 @@
-package org.shedlang.compiler.stackir.instructions;
-
-import org.shedlang.compiler.sources.Source;
-
-/**
- * Push a string onto the temporary value stack.
- */
-public record PushStringInstruction(String value, Source source) implements Instruction {
-}
diff --git a/src/main/java/org/shedlang/compiler/stackir/instructions/PushUnitInstruction.java b/src/main/java/org/shedlang/compiler/stackir/instructions/PushUnitInstruction.java
deleted file mode 100644
index 998624e1..00000000
--- a/src/main/java/org/shedlang/compiler/stackir/instructions/PushUnitInstruction.java
+++ /dev/null
@@ -1,9 +0,0 @@
-package org.shedlang.compiler.stackir.instructions;
-
-import org.shedlang.compiler.sources.Source;
-
-/**
- * Push the unit value onto the temporary value stack.
- */
-public record PushUnitInstruction(Source source) implements Instruction {
-}